Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

General programming question.

Former Member
0 Kudos

Hi all,

I am very dizzy of thinking the solution for this. Really out if idea. Please help.

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?

Thanks in advance.

1 ACCEPTED SOLUTION

valter_oliveira
Active Contributor
0 Kudos

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>.
  READ TABLE ti_totals INTO wa_totals
      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.

2 REPLIES 2

valter_oliveira
Active Contributor
0 Kudos

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>.
  READ TABLE ti_totals INTO wa_totals
      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 Kudos

Hi Valter Oliveira,

Really thanks for your input. I have tried your code, and it is working perfectly for me.

Thank you so much.