10-02-2008 5:45 PM
Hi Experts,
I need a logic in internal table loop.
Ex:
vbeln matnr werks quantity
1234 AAAA 0001 10.000
2345 AAAA 0001 20.000
2345 BBBB 0001 30.000
3456 AAAA 0001 35.000
I need a logic that for every new Material i need to know how many records are there in internal table for that material.
like...
sort itab ascending by matnr.
loop at itab.
at new matnr.
i need no: of records for that matnr ( AAAA) i.e. 3..
endloop.
i am confused where to use this at new...
can anyone provide the best logic in terns of performance?
Giri
10-02-2008 5:51 PM
One method with MATNR as the first field in the internal table
matnr vbeln werks quantity
AAAA 1234 0001 10.000
AAAA 2345 0001 20.000
BBBB 2345 0001 30.000
AAAA 3456 0001 35.000
one internal table with fields
MATNR COUNT
Sort tb_data by matnr.
loop at tb_data.
at new matnr.
clear wf_count.
endat.
wf_count = wf_count +1 .
at end of matnr.
tb_summary-matnr = tb_data-matnr.
tb_summary-count = wf_count.
append tb_summary.
endat.
endloop.
10-02-2008 5:50 PM
10-02-2008 5:51 PM
One method with MATNR as the first field in the internal table
matnr vbeln werks quantity
AAAA 1234 0001 10.000
AAAA 2345 0001 20.000
BBBB 2345 0001 30.000
AAAA 3456 0001 35.000
one internal table with fields
MATNR COUNT
Sort tb_data by matnr.
loop at tb_data.
at new matnr.
clear wf_count.
endat.
wf_count = wf_count +1 .
at end of matnr.
tb_summary-matnr = tb_data-matnr.
tb_summary-count = wf_count.
append tb_summary.
endat.
endloop.
10-02-2008 5:54 PM
Since you have to get the number of material in the AT NEW, you should fill the number of material in some temporary table and than you it inside in the LOOP to read the material number.
Like:
DATA: BEGIN OF ITC OCCURS 0,
MATNR TYPE MATNR,
COUNT TYPE I.
END OF ITC.
LOOP AT ITAB.
ITC-MATNR = ITAB-MATNR.
ITC-COUNT = 1.
COLLECT ITC.
ENDLOOP.
loop at itab.
at new matnr.
READ TABLE ITC WITH KEY MATNR = ITAB-MATNR.
* ITC-COUNT WILL GIVE THE NUMBER OF MATERIAL
ENDAT.
endloop.
Regards,
Naimesh Patel
10-16-2008 4:25 PM
10-16-2008 5:06 PM
Hi Giri,
I think Naimesh Patels logic would work fine. Let us know if you have tried it. If yes, do the performance analysis and let us know.
Regards.
Vamshi.