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

Selecting most recent record using UZEIT

Former Member
0 Likes
984

Hi folks,

I have a select statement that fetches multiple records for same combinations where only UZEIT (time) is different. I would like to pick up the most recent record for each combination. Please advise.

Here is an example using 3 fields. This is the table to pick up the data from.

ZPROD1 11.11.2010 1:00 pm

ZPROD1 11.11.2010 2:00 pm

ZPROD1 11.11.2010 3:00 pm

ZPROD2 11.11.2010 1:00 pm

ZPROD2 11.11.2010 1:30 pm

These are the records that should get picked up (so the ones with the latest time).

ZPROD1 11.11.2010 3:00 pm

ZPROD2 11.11.2010 1:30 pm

Thanks in advance!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
659

Hi,

You can try as :



"Say your data is in is IT_FINAL with fileds ZPROD DATE TIME

SORT IT_FINAL BY ZPROD DATE TIME DESCENDING.
DELETE ADJECENT DUPLICATES FROM IT_FINAL COMPARING ZPROD DATE.

LOOP AT IT_FINAL INTO WA_FINAL.
"Write your logic here
ENDLOOP.

Thanks & Regards,

Faheem.

4 REPLIES 4
Read only

Former Member
0 Likes
659

Hi,

I think you can use MAX keyword in your query.

like


select fld1 fld2 fld3 max(uziet) from .......

else if you want the latest record, then make use of the result of the mensioned query.

Thanks,

Anmol.

Read only

0 Likes
659

Hi Anmol,

Thanks for the response but i should clarify that the data is stored in the internal table. I can't use the MAX keyword at the time of dumping data into this internal table since using the FOR ALL ENTRIES statement there.

To clarify, in my original post, the 1st set of contents are staged in an internal table and then I would like to get the max (or most recent in my case) time for each of those unique records.

Cheers!

Read only

Former Member
0 Likes
660

Hi,

You can try as :



"Say your data is in is IT_FINAL with fileds ZPROD DATE TIME

SORT IT_FINAL BY ZPROD DATE TIME DESCENDING.
DELETE ADJECENT DUPLICATES FROM IT_FINAL COMPARING ZPROD DATE.

LOOP AT IT_FINAL INTO WA_FINAL.
"Write your logic here
ENDLOOP.

Thanks & Regards,

Faheem.

Read only

0 Likes
659

Awesome. Thank you folks!