03-07-2009 10:22 AM
Hi Guys,
My ITAB looks like below.
PN SN MATNR BRGEW VOLUM
1 11 D1 100 10
1 11 D1 150 25
1 11 D2 50 10
2 11 F1 100 10
2 11 F2 150 25
2 11 F2 50 10
My requirement is for same PN & SN if MATNR is same ADD BRGEW and VOLUM along with the details of PN SN MATNR BRGEW VOLUM and store it in another internal table.
My final Table should look like below
PN SN MATNR BRGEW VOLUM
1 11 D1 250 35
1 11 D2 50 10
2 11 F1 100 10
2 11 F2 200 35
Thanks in Advance,
Prasad.
03-07-2009 10:24 AM
Use:
Collect Statement
Itab --->Key Fields --> PN ,SN, MATNR(Declare these as key Fileds of itab)
Itab2
Sort itab.
Loop at Itab.
Collect Itab to Itab1.
Endloop.
ITAB1 Will give you required output.
Regards,
Gurpreet
03-07-2009 10:24 AM
Use:
Collect Statement
Itab --->Key Fields --> PN ,SN, MATNR(Declare these as key Fileds of itab)
Itab2
Sort itab.
Loop at Itab.
Collect Itab to Itab1.
Endloop.
ITAB1 Will give you required output.
Regards,
Gurpreet
03-07-2009 11:07 AM
Guys can you give it in brief.
My Internal tables have work area.
Thanks,
Prasad.
03-07-2009 11:13 AM
Hi,
Test the following code here i am using Work Area in fact when you create internal table with OCCURS it automatically create an Work Area with the Same name as internal table and when you use WITH HEADER LINE it do the same, you can't do loop on internal table with out work area.
Let me know if any problem,
LOOP AT it into wa_it_final.
COLLECT wa_it_final into it_final.
ENDLOOP.
Kind Regards,
Faisal
03-07-2009 11:17 AM
Hi Faisal ,
My problem here is
LOOP AT it into wa_it_final.
COLLECT wa_it_final into it_final.
ENDLOOP.
my wa_it_final has 4 fileds.
But my It_final has 3 fileds.
Its saying that the work area and the Internal table is incompatible.
How to do this.
03-07-2009 11:21 AM
Hi,
Test the following Sample Code this time it will solve out your problem. use MOVE-CORRESPONDING
DATA: BEGIN OF it OCCURS 10,
m(10),
amount1 TYPE i,
amount2 TYPE i,
END OF it.
DATA: BEGIN OF it_final OCCURS 10,
m(10),
amount1 TYPE i,
END OF it_final.
it-m = 'AAA'. it-amount1 = 10. it-amount2 = 20. APPEND it.
it-m = 'AAA'. it-amount1 = 10. it-amount2 = 20. APPEND it.
it-m = 'BBB'. it-amount1 = 10. it-amount2 = 20. APPEND it.
it-m = 'AAA'. it-amount1 = 10. it-amount2 = 20. APPEND it.
it-m = 'BBB'. it-amount1 = 10. it-amount2 = 20. APPEND it.
SORT it BY m.
LOOP AT it into it.
MOVE-CORRESPONDING it to it_final.
COLLECT it_final into it_final.
ENDLOOP.
LOOP AT it_final.
WRITE: / it_final-m, it_final-amount1.
ENDLOOP.
Please Reply if any Issue,
Kind Regards,
Faisal
03-07-2009 11:28 AM
Hi, Dheeru
Use the WorkArea of 4 field when do loop and inside the loop body MOVE-CORRESPONDING field of 4 Field workarea to 3 Field work area remember one think that the final table where you are going to collect the Values must be of 3 Field like your WorkArea of 3 Field,
Waiting for your Reply,
Kind Regards,
Faisal
03-07-2009 11:47 AM
03-07-2009 10:31 AM
Hi,
Test the following Sample Code Hope will Help you to solve out your problem,
DATA: BEGIN OF it OCCURS 10,
m(10),
amount1 TYPE i,
amount2 TYPE i,
END OF it.
DATA: it_final LIKE STANDARD TABLE OF it WITH HEADER LINE.
it-m = 'AAA'. it-amount1 = 10. it-amount2 = 20. APPEND it.
it-m = 'AAA'. it-amount1 = 10. it-amount2 = 20. APPEND it.
it-m = 'BBB'. it-amount1 = 10. it-amount2 = 20. APPEND it.
it-m = 'AAA'. it-amount1 = 10. it-amount2 = 20. APPEND it.
it-m = 'BBB'. it-amount1 = 10. it-amount2 = 20. APPEND it.
LOOP AT it.
COLLECT it INTO it_final.
ENDLOOP.
LOOP AT it_final.
WRITE: / it_final-m, it_final-amount1, it_final-amount2.
ENDLOOP.
Please Reply if any Issue,
Kind Regards,
Faisal
03-07-2009 10:34 AM
look at this example....
REPORT ztest .
data: begin of itab occurs 0,
i type i,
j type i,
k type i,
end of itab.
data: begin of itab1 occurs 0,
k type i,
end of itab1.
itab-i = 1.
itab-j = 1.
itab-k = 2.
append itab.
itab-i = 1.
itab-j = 1.
itab-k = 4.
append itab.
itab-i = 1.
itab-j = 2.
itab-k = 6.
append itab.
itab-i = 1.
itab-j = 3.
itab-k = 8.
append itab.
loop at itab .
if itab-i = itab-j.
itab1-k = itab-k.
append itab1.
endif.
write:/ itab-i, itab-j, itab-k.
endloop.
uline.
loop at itab1.
write:/ itab1-k.
endloop.