Application Development 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: 

Latest date

Former Member
0 Kudos

I have the following requirement. Create a custom table that will contain among other things the date and time created. Then every time a certain program runs, it will need to find the table entry with the latest created date. The date is not part of the table key. The table could be quite large.

I'm wondering if anyone has had a similary requirement and how they went about it.

I see a three possible solutions two of which have problems:

1) Read the date into an internal table, sort it and find the latest date/time.

Problem, the table could be quite large therefore possibly running into memory problems (thrashing perhaps) and the time it would take to sort the internal table.

2) Select statement with "order by"

Problem, similar to 1) above, table would be read sequentually, which could be a performance problem.

3) Index the table with date/time

Your feedback will be much appreciated.

Nic

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Try creating an index but remember that it may slow down your inserts and updates to the table. But index is the best option available to you.

11 REPLIES 11

Former Member
0 Kudos

Try creating an index but remember that it may slow down your inserts and updates to the table. But index is the best option available to you.

0 Kudos

Is that latest created date or latest run date??

-Kriss

0 Kudos

the latest created date/time. i.e., when entries are added to the table, they will have the current date/time as the created date/time.

0 Kudos

For the above logic if the date is found pull all those records into internal table and sort it and pull the latest date and time

Former Member
0 Kudos

Hi Nic

you can read the table based on current date.

If no read the table with (date - 1).

if no read the table with (date - 2) and so on......

Hope this help you if your table is always fed with the latest dates.........

Reward points if this helps you

0 Kudos

Sateesh,

If you mean read the database table, since the date is not part of the key, this would generate a sequential read of the table each time, though it would work ok if the table were indexed by date/time created.

Nic

Former Member
0 Kudos

I'm with #3 as well. Is there any reason not to create the index?

Rob

Former Member
0 Kudos

Nic, One simple solution to this is write the latest date to ABAP memory and rather than reading whole table you can read that date from ABAP memory (using EXPORT/ IMPORT )

Regards,

PV

0 Kudos

P V,

Hmmmmmm, you maybe on to something there, however if I remember correctly, EXPORTed data is not retained beyond a session. The program that creates entries in the table and the program that reads the table could be run hours apart from each other and could be run as part of separate batch jobs.

On the other hand, perhaps the latest date/time could be written to INDX or to TVARV as the entries are created. Something to look into. Thanks for the "slap upside the head"

Nic

Former Member
0 Kudos

Hi Nic,

Do with updation of the table as you are feeling.. try to take a timestamp kind of field in your table..

whenever a record is added or updated in the table, the timestamp field should be updated with the current date and time.

While fetching the latesh record from the table, just add the MAX function in your select query.. Like..

SELECT xxx

yyy

MAX(timestamp)

FROM dbtab

INTO e_dbtab

WHERE contions..

Thanks and Best Regards,

Vikas Bittera.

**Points for useful answers**

Former Member
0 Kudos

*The below code will help you to find out the last entry made

REPORT ZTRIP_TEST.

tables: ztable.

data:

w_date like ztable-date,

w_time like ztable-time.

select max( date )

from ztable

into w_date.

if sy-subrc eq 0.

select max( time )

from ztable

into w_time

where date eq w_date.

if sy-subrc eq 0.

select single *

from ztable

where date eq w_date and time eq w_time.

if sy-subrc eq 0.

write: ztable-date,ztable-time.

endif.

endif.

endif.

Reward points if useful, get back in case of query...

Cheers!!!

Message was edited by:

Tripat Pal Singh