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: 

date operations with internal table

naimkhans_babi
Active Participant
0 Kudos
86

Dear friends

would you like to tell me. how i determine the most recent date and time from internal table i am not supposed to sort the table by date and time... I must check date and time with other records date and time to determine which record is most recently changed...

here the scenario is.

id idnumber chdate chtime

1 123456 20060606 135312

2 123456 20060606 135900

3 123456 20060606 132300

4 123457 20060606 140000

5 123457 20060606 142500

in the above scenario i must keep in my mind that the most recently changed record is identical to its idnumber i can say that:

the record should be fetched this way

id idnumber chdate chtime

3 123456 20060606 132300

5 123457 20060606 142500

because here the id 3 is the most recently changed in the idnumber 123456

where id 5 is the most recently changed in the idnumber 123457

please help me to determin how i am supposed to carry out this task any suggestion, code will be great help of mine.

regards

Naim

1 ACCEPTED SOLUTION

Former Member
0 Kudos
57

very simple.

change the sequence of field declaration in your internal table which is holding this data so that IDNUMBER becomes first field.

idnumber id chdate chtime

123456 1 20060606 135312

123456 2 20060606 135900

123456 3 20060606 132300

123457 4 20060606 140000

123457 5 20060606 142500

Now SORT <TABLE> BY IDNUMBER ASCENDING CHDATE DESCENDING CHTIME DESCENDING.

DATA : WORKAREA LIKE <TABLE>

Loop at <TABLE>.

WORKAREA = <TABLE>.

AT END OF IDNUMBER.

WRITE: / WORKAREA-ID.

*C-- Here you will get the latest id.

ENDAT.

endloop.

3 REPLIES 3

Former Member
0 Kudos
57

Just a quick reply. Perhaps you could use this logic.

1. Group by IDNUMBER

2. Loop by IDNUMBER.

3. Subtract the CHDATE from DATENOW(Current Date SY-DATUM), CHTIME from TIMENOW(Current SY-TIMLO).

4. At each loop hold the previous value from and compare the current.

Or you could make use of another Internal Table. Fill the other internal table by IDNUMBER and sort by chtime and chdate.

Former Member
0 Kudos
58

very simple.

change the sequence of field declaration in your internal table which is holding this data so that IDNUMBER becomes first field.

idnumber id chdate chtime

123456 1 20060606 135312

123456 2 20060606 135900

123456 3 20060606 132300

123457 4 20060606 140000

123457 5 20060606 142500

Now SORT <TABLE> BY IDNUMBER ASCENDING CHDATE DESCENDING CHTIME DESCENDING.

DATA : WORKAREA LIKE <TABLE>

Loop at <TABLE>.

WORKAREA = <TABLE>.

AT END OF IDNUMBER.

WRITE: / WORKAREA-ID.

*C-- Here you will get the latest id.

ENDAT.

endloop.

Former Member
0 Kudos
57

Hi Naim,

For example if ur select statement is like this..

select id idnumber chdate chtime from xtable into table itab where ...<condn>..

sort itab by idnumber chdate chtime descending.

delete adjacent duplicates from itab comparing idnumber .

Code like above statement..

You can get result...

id idnumber chdate chtime

3 123456 20060606 132300

5 123457 20060606 142500

Reward the points if it helps.