Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

DATA DISPLAY

Former Member
0 Likes
556

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
524

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

4 REPLIES 4
Read only

gopi_narendra
Active Contributor
0 Likes
524

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

Read only

Former Member
0 Likes
525

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

Read only

0 Likes
524

Hi Eswar,

Thanks a lot for your help and my problem is solved.

Thanks,

Raj.

Read only

0 Likes
524

Glad could help you Raj.

Kind Regards

Eswar