11-09-2006 10:30 AM
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..
11-09-2006 10:48 AM
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
11-09-2006 10:35 AM
Hi,
u have to append the record at new belnr only..
otherwise modify that record..
Regards,
Sonika
11-09-2006 10:43 AM
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
11-09-2006 10:46 AM
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.
11-09-2006 10:48 AM
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
11-09-2006 10:51 AM
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.