Search
Search

# General programming question.

Hi all,

For example:

I have an internal table itab, shown below:

```TANUM		VLTYP	SINGL	MULTI
0000002627	CR3		X
0000002627	MRK		X
0000002627	MRK		X
0000002627	TTY		X
0000002627	MRK		X
```

What the program I wish to have is:

1) Sort the itab by TANUM, VLTYP

```TANUM		VLTYP	SINGL	MULTI
0000002627	CR3		X
0000002627	TTY		X
0000002627	MRK		X
0000002627	MRK		X
0000002627	MRK		X
```

2) If the TANUM and VLTYP is more than one, then X will more from MULTI to SINGL

```TANUM		VLTYP	SINGL	MULTI
0000002627	CR3	X
0000002627	TTY	X
0000002627	MRK		X
0000002627	MRK		X
0000002627	MRK		X
```

So far this is what I have done, but it is incorrect.

```        SORT XRLDRI BY TANUM VLTYP.
LOOP at XRLDRI.
IF lv_tanum IS INITIAL AND lv_vltyp IS INITIAL.
lv_tanum = XRLDRI-tanum.
lv_vltyp = XRLDRI-vltyp.
*          ELSE.
IF lv_tanum <> XRLDRI-tanum OR lv_vltyp <> XRLDRI-vltyp.
XRLDRI-SINGL = 'X'.
XRLDRI-MULTI = ''.
MODIFY XRLDRI.
ELSE.
CLEAR: lv_tanum, lv_vltyp.
ENDIF.
ENDIF.
ENDLOOP.
```

What should I do, to get the above result?

##### Former Memberreplied
```TYPES: BEGIN OF ty_totals,
tanum TYPE tanum,
vltyp TYPE vltyp,
total TYPE i,
END OF ty_totals.
DATA: it_totals TYPE STANDARD TABLE OF ty_totals,
wa_totals TYPE ty_totals,

FIELD-SYMBOLS: <fs> like XRLDRI. "the line type of XRLDRI.

LOOP AT XRLDRI.
CLEAR wa_totals.
wa_totals-tanum = XRLDRI-tanum.
wa_totals-vltyp = XRLDRI-vltyp.
wa_totals-total = 1.
COLLECT wa_totals INTO ti_totals.
ENDLOOP.

LOOP AT XRLDRI ASSIGNING <fs>.
WITH KEY tanum = <fs>-tanum
vltyp = <fs>-vltyp.
IF wa_totals-total EQ 1.
<fs>-singl = 'X'.
<fs>-multi = space.
ENDIF.
ENDLOOP.
```

Regards,

Valter Oliveira.

0 View this answer in context
View more on this topic or