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 base select for latest record?

Former Member
0 Likes
959

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 ?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
915

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

8 REPLIES 8
Read only

Former Member
0 Likes
916

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

Read only

Former Member
0 Likes
915

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

Read only

Former Member
0 Likes
915

select * from <table> into itab.

sort itab descending zmonat.

delete adjacent duplicates from itab comparing zmonat.

Read only

Former Member
0 Likes
915

hi Sam,

do this way ..

sort itab by <field> <b>descending</b>.

and now use select single or upto 1 rows statement ..

Regards,

Santosh

Read only

Former Member
0 Likes
915

Hi,

SORT ITAB BY FIELD_NAME DESCENDING.

Cheers.

Read only

ferry_lianto
Active Contributor
0 Likes
915

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

Read only

Former Member
0 Likes
915

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!

Read only

Former Member
0 Likes
915

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