2008 Mar 07 4:50 PM
In my ABAP Program, I have to use a select statement to retrieve the last record from the database table with the same key. In other words, the Program will get more than one hit on the database table for the selected keys and I need to retrieve values from only the last record and not the first. I know I can use an internal table to sort the records first and then retrieve the right value. But to make things easier, is there a SELECT statement keyword than I can use to do this in one single step? Thanks!
In my ABAP Program, I have to use a select statement to retrieve the last record from the database table with the same key. In other words, the Program will get more than one hit on the database table for the selected keys and I need to retrieve values from only the last record and not the first. I know I can use an internal table to sort the records first and then retrieve the right value. But to make things easier, is there a SELECT statement keyword than I can use to do this in one single step? Thanks!
2008 Mar 07 4:54 PM
May be this way
select single * from mara
....
....
....
order by matnr descending.
a®
2008 Mar 07 4:55 PM
Hi,
take sy-tfill or decribe table stmt, then u will get total no of records,
then read it with index sy-tfill.
Regards
2008 Mar 07 5:07 PM
Try:
SELECT * FROM (table)
UP TO 1 ROWS
ORDER BY (key fields) DESCENDING.
ENDSELECT.Rob
2008 Mar 07 5:12 PM
Hi,
can u say one thing u want the last record after sorting your table or u want it after just selecting the table
Regards
2008 Mar 07 5:21 PM
hi,
tables:mara.
data: begin of it_mara occurs 0,
matnr like mara-matnr,
meins like mara-meins,
mtart like mara-mtart,
end of it_mara.
select-options:s_matnr for mara-matnr.
select matnr
meins
mtart
from mara
into table it_mara
where matnr in s_matnr.
if not it_mara[] is initial.
sort it_mara by matnr descending.
read table it_mara index 1.
endif.
then you get the last record of the select statement.
reward points if useful,
venkat.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |