‎2006 Oct 25 4:23 AM
Hi,
Here i want to display first and second data of each material no which i was sort decending by material no and date.but i could not get the data for the multile material nos.below is the coding i used.for each matl no i want to display the first and second data.
SORT ITAB DESCENDING BY ZMATNR ZCHARG.
LOOP AT ITAB.
AT FIRST.
IF SY-SUBRC EQ 0.
READ TABLE ITAB INDEX 1.
MOVE ITAB-ZMATKL TO ITAB_S-ZMATKL.
MOVE ITAB-ZMATNR TO ITAB_S-ZMATNR.
MOVE ITAB-ZMAKTX TO ITAB_S-ZMAKTX.
MOVE ITAB-ZAMEND TO ITAB_S-ZAMEND.
MOVE ITAB-ZWEEKS TO ITAB_S-ZWEEKS.
MOVE ITAB-ZAMEND TO ITAB_S-ZAMENDR.
READ TABLE ITAB INDEX 2.
MOVE ITAB-ZAMEND TO ITAB_S-ZAMENDL.
APPEND ITAB_S.
CLEAR ITAB_S.
ENDIF.
ENDAT.
EXIT.
ENDLOOP.
Pls help to solve the issues.
Thanks,
Raj.
‎2006 Oct 25 4:44 AM
Hi Rajendra
Hope below code can give you some idea on handling the same.
types: begin of t_tab,
matnr like mara-matnr,
date like sy-datum,
end of t_tab.
data: itab type standard table of t_tab,
wa type t_tab.
data: l_tabix like sy-tabix.
wa-matnr = 'AB2'.
wa-date = sy-datum - 20.
append wa to itab.
wa-date = sy-datum.
append wa to itab.
wa-matnr = 'AB1'.
wa-date = sy-datum - 10.
append wa to itab.
wa-date = sy-datum.
append wa to itab.
sort itab by matnr date descending.
loop at itab into wa.
l_tabix = sy-tabix.
at new matnr.
read table itab into wa index l_tabix.
write:/ wa-matnr,
20 wa-date.
l_tabix = l_tabix + 1.
read table itab into wa index l_tabix.
write:/ wa-matnr,
20 wa-date.
endat.
endloop.In the above example, SORT statement sorts the data by MATNR ASCENDING and DATE DESCENDING to get the 2 latest dates for each material.
However if you need both desending, the statement should be as below:
sort itab by matnr descending date descending.
Kind Regards
Eswar
‎2006 Oct 25 4:34 AM
data : itab1 like line of itab.
data : itab2 like line of itab.
loop at itab.
read table itab index 1.
if sy-subrc = 0.
move itab to itab1.
clear itab.
endif.
read table itab index 2.
if sy-subrc = 0.
move itab to itab2.
clear itab.
endif.
endloop.
Regards
- Gopi
‎2006 Oct 25 4:44 AM
Hi Rajendra
Hope below code can give you some idea on handling the same.
types: begin of t_tab,
matnr like mara-matnr,
date like sy-datum,
end of t_tab.
data: itab type standard table of t_tab,
wa type t_tab.
data: l_tabix like sy-tabix.
wa-matnr = 'AB2'.
wa-date = sy-datum - 20.
append wa to itab.
wa-date = sy-datum.
append wa to itab.
wa-matnr = 'AB1'.
wa-date = sy-datum - 10.
append wa to itab.
wa-date = sy-datum.
append wa to itab.
sort itab by matnr date descending.
loop at itab into wa.
l_tabix = sy-tabix.
at new matnr.
read table itab into wa index l_tabix.
write:/ wa-matnr,
20 wa-date.
l_tabix = l_tabix + 1.
read table itab into wa index l_tabix.
write:/ wa-matnr,
20 wa-date.
endat.
endloop.In the above example, SORT statement sorts the data by MATNR ASCENDING and DATE DESCENDING to get the 2 latest dates for each material.
However if you need both desending, the statement should be as below:
sort itab by matnr descending date descending.
Kind Regards
Eswar
‎2006 Oct 25 6:24 AM
Hi Eswar,
Thanks a lot for your help and my problem is solved.
Thanks,
Raj.
‎2006 Oct 25 6:35 AM