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: 

internal table

Former Member
0 Kudos

Hi .

i have internal table having BELNR in one column and WRBTR in another column. now i want to append these records in another internal table but i want that till BELNR contain same value , WRBTR should be placed in next column on same row. when BELNR changes then new row should be started.

i am stuck here..

thanks..

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hello Puru,

Please find below sample code according to the way I understand your problem.

Data: begin of itab1 occurs 0,

belnr like bseg-belnr,

wrbtr like bseg-wrbtr,

end of itab1.

Data: itab2 like itab1 occurs 0 with header line.

Data: switch(1) type c.

  • Consider you have all records in itab1 and u want to append itab2 when there is a new belnr.

loop at itab1.

at new belnr.

switch = 'X'.

endat.

if switch = 'X'.

itab2-belnr = itab1-belnr.

itab2-wrbtr = itab1-wrbtr.

append itab2.

else.

itab2-wrbtr = itab1-wrbtr.

modify itab2 where belnr = itab1-belnr tansporting wrbtr.

endif.

clear switch.

endloop.

Note: Please reward points if the solution is helpful.

Thanks

Harish

5 REPLIES 5

former_member632991
Active Contributor
0 Kudos

Hi,

u have to append the record at new belnr only..

otherwise modify that record..

Regards,

Sonika

0 Kudos

Hi sonika..

suppose i have 4 same records in BELNR & so in WRBTR. now i want that on same row as..

BELNR WRBTR1 WRBTR2 WRBTR3 WRBTR4

Thanks

Former Member
0 Kudos

U can use the below soln but the assumption is there the final internal table has finite number of columns wof wrbtr for each belnr. Lets they are named as wrbtr1...wrbtr20.

sort itab.

Loop at itab.

at new belnr.

lindx = 0.

endat.

lindx = lindx + 1.

move itab-belnr to iout-belnr.

concatenate 'IOUT-WRBTR' lindx into lfield.

assign (lfield) to <FS>.

<FS> = itab-wrbtr.

modify iout.

endloop.

Former Member
0 Kudos

Hello Puru,

Please find below sample code according to the way I understand your problem.

Data: begin of itab1 occurs 0,

belnr like bseg-belnr,

wrbtr like bseg-wrbtr,

end of itab1.

Data: itab2 like itab1 occurs 0 with header line.

Data: switch(1) type c.

  • Consider you have all records in itab1 and u want to append itab2 when there is a new belnr.

loop at itab1.

at new belnr.

switch = 'X'.

endat.

if switch = 'X'.

itab2-belnr = itab1-belnr.

itab2-wrbtr = itab1-wrbtr.

append itab2.

else.

itab2-wrbtr = itab1-wrbtr.

modify itab2 where belnr = itab1-belnr tansporting wrbtr.

endif.

clear switch.

endloop.

Note: Please reward points if the solution is helpful.

Thanks

Harish

0 Kudos
l_tabix type sy-tabix.
LOOP AT itab1 into wa.
l_tabix = l_tabix + 1.
ASSIGN COMPONENT l_tabix OF STRUCTURE itab2 TO <fs1>.
IF sy-subrc = 0.
<fs1> = wa-filed1.
ENDIF.
APPEND itab2.
ENDLOOP.