2006 Jun 15 8:39 AM
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
2006 Jun 15 8:51 AM
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.
2006 Jun 15 8:50 AM
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.
2006 Jun 15 8:51 AM
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.
2006 Jun 15 9:07 AM
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.