‎2006 Dec 04 4:02 PM
I have database Z-table
ZPRCTR ZGJAHR ZMONAT RPT_LOC
0000000330 2006 01 0330
0000000330 2006 02 0330
0000000330 2006 03 0330
0000000330 2006 04 0330
If I give ZPRCTR = '0000000330'
then I need to get the record
0000000330 2006 04 0330 which is latest one...because of ZMONAT = '04'.
Right now by using select single or select up to 1 rows
i am getting the oldest record.
0000000330 2006 <b>01</b> 0330
How can I achieve this ?
‎2006 Dec 04 4:05 PM
Hi,
When you use the SELECT ..
GIve ORDER BY ZMONAT DESCENDING in your select statement.
Example..
TABLES: BKPF.
SELECT * UP TO 1 ROWS
FROM BKPF
WHERE GJAHR = '2006'
ORDER BY MONAT DESCENDING.
ENDSELECT.
Thanks,
Naren
‎2006 Dec 04 4:05 PM
Hi,
When you use the SELECT ..
GIve ORDER BY ZMONAT DESCENDING in your select statement.
Example..
TABLES: BKPF.
SELECT * UP TO 1 ROWS
FROM BKPF
WHERE GJAHR = '2006'
ORDER BY MONAT DESCENDING.
ENDSELECT.
Thanks,
Naren
‎2006 Dec 04 4:05 PM
Hi,
Select Single of Select Upto one rows will give you the first record that is obtained by the where condition. It does not go further.
I think in this case, you need to select all and then sort descending and then delete adjacent duplicates comparing ZPRCTR ZGAHR ZMONAT.
Hope this helps....
Regards,
Shahu
‎2006 Dec 04 4:06 PM
select * from <table> into itab.
sort itab descending zmonat.
delete adjacent duplicates from itab comparing zmonat.
‎2006 Dec 04 4:06 PM
hi Sam,
do this way ..
sort itab by <field> <b>descending</b>.and now use select single or upto 1 rows statement ..
Regards,
Santosh
‎2006 Dec 04 4:10 PM
‎2006 Dec 04 4:10 PM
Hi Sam,
Please try this.
SELECT * UP TO 1 ROWS
FROM ZTABLE
WHERE ZGJAHR = '2006'
<b>ORDER BY ZPRCTR ZMONAT DESCENDING.</b>
ENDSELECT.
Hope this will help.
Regards,
Ferry Lianto
‎2006 Dec 04 4:14 PM
Hi,
i think you want to select the record with the maximum value of the field month, means the "oldest record".
Use the "max" Statement in your select:
select field1 field1 .... max (zmonat)
into structure
where field1 = ....
You will find description of max-statement in abap-online help.
regards!
‎2006 Dec 04 6:02 PM
Hi,
select * from <table> into itab.
sort itab by zprctr descending zmonat.
delete adjacent duplicates from itab comparing zprctr zmonat.
Then there will be only one entry(Recent entry) with perticular profit center.
Then read the Internal table by passing the profit center
Ex: read table itab with key zprctr = '0000000330'
-Sreenivas Reddy Maddi