2008 Jul 31 12:33 PM
Hi Experts,
I am having an internal table
itab 1 with fields
pernr
id(1,2,)
amount
Contents of itab
pernr id amount
100 1 200
100 2 300
But here each pernr can have around two id's (id1,id2)
But in the output table I have to give output as
pernr id1 amount. id2 amount.
100 1 200 2 300
Thanks in Advance,
IFF
2008 Jul 31 12:44 PM
Hi!
Check this code
REPORT z_sdn.
DATA:
BEGIN OF fs_tab,
pernr(4) TYPE n,
id(2) TYPE n,
amt TYPE i,
END OF fs_tab.
DATA:
t_tab LIKE
TABLE OF
fs_tab.
fs_tab-pernr = '100'.
fs_tab-id = '1'.
fs_tab-amt = 200.
APPEND fs_tab TO t_tab.
CLEAR fs_tab.
fs_tab-pernr = '100'.
fs_tab-id = '2'.
fs_tab-amt = 300.
APPEND fs_tab TO t_tab.
LOOP AT t_tab INTO fs_tab.
AT NEW pernr.
WRITE: / fs_tab-pernr.
ENDAT.
WRITE: / fs_tab-id,
fs_tab-amt.
ENDLOOP.
Regards
Abhijeet
2008 Jul 31 12:36 PM
Hi,
Try below Code:
LOOP AT itab.
AT NEW pernr.
write:
/ itab-pernr.
ENDAT.
write:
itab-id,
itab-amount.
ENDLOOP.Best Regards,
Sunil.
2008 Jul 31 12:36 PM
Hi,
Loop at itab into wa.
At new pernr.
write:
wa-pernr.
end at.
write:
wa-id,
wa-amoutn.
Endloop.
2008 Jul 31 12:37 PM
data:begin of itab occurs 0,
pernr type n,
id type i,
amt type i,
end of itab .
itab-pernr = '001'.
itab-id = 1.
itab-amt = 1000.
append itab .
itab-pernr = '001'.
itab-id = 2.
itab-amt = 1000.
append itab .
itab-pernr = '002'.
itab-id = 1.
itab-amt = 1000.
append itab .
loop at itab .
at end of pernr .
write:/ itab-pernr .
loop at itab where pernr = itab-pernr .
write: itab-id, itab-amt.
endloop.
endat .
endloop.
2008 Jul 31 12:38 PM
loop at itab.
v_count = v_count + 1.
at new pernr.
write : itab-pernr , itab-id , itab-amount.
endat.
at end of pernr.
if v_count > 1.
write 😕 itab-id , itab-amount.
endif.
clear : v_count.
endat.
endloop.
2008 Jul 31 12:39 PM
Hi....
Declare one more internal table with additional fields and populate into that...
you can display the internal table as you wish...
and this can create no problem if you down load outputlist into excel sheet or any!
To suggest the detailed logic....
you must clear IDs are always 2 or not?
Thanks,
Naveen.I
2008 Jul 31 12:44 PM
Hi!
Check this code
REPORT z_sdn.
DATA:
BEGIN OF fs_tab,
pernr(4) TYPE n,
id(2) TYPE n,
amt TYPE i,
END OF fs_tab.
DATA:
t_tab LIKE
TABLE OF
fs_tab.
fs_tab-pernr = '100'.
fs_tab-id = '1'.
fs_tab-amt = 200.
APPEND fs_tab TO t_tab.
CLEAR fs_tab.
fs_tab-pernr = '100'.
fs_tab-id = '2'.
fs_tab-amt = 300.
APPEND fs_tab TO t_tab.
LOOP AT t_tab INTO fs_tab.
AT NEW pernr.
WRITE: / fs_tab-pernr.
ENDAT.
WRITE: / fs_tab-id,
fs_tab-amt.
ENDLOOP.
Regards
Abhijeet