Google Search - Blog...........

ABAP - Catch Last Records From The Table & Display Them.

report zcatch_last_records.


data: begin of itab occurs 0,
lifnr type lfa1-lifnr,
pydat type sy-datum,
end of itab.

data: begin of itab2 occurs 0,
lifnr type lfa1-lifnr,
pydat type sy-datum,
end of itab2.

data: wa like line of itab.

itab-lifnr = '1'.
itab-pydat = '20050709'.
append itab.

itab-lifnr = '1'.
itab-pydat = '20050708'.
append itab.

itab-lifnr = '1'.
itab-pydat = '20050707'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050712'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050711'.
append itab.

itab-lifnr = '2'.
itab-pydat = '20050710'.
append itab.


sort itab by lifnr ascending
pydat descending.

loop at itab.
wa = itab.
at new lifnr.
move-corresponding wa to itab2.
append itab2.
endat.
endloop.


loop at itab2.
write:/ itab2-lifnr, itab2-pydat.
endloop.

No comments:

Post a Comment