06-22-2006 12:09 PM
Dear Friends
I wish to know how i perform the date operations in internal table... I am looking for the most recent record from the internal table for that i am supposed to look at chdate and chtime fields gives me the information on most corrently changed record... if in the case of the record which is there but not changed to determin the its most currentness i must look at the crdate and crtime..so i have the code for that which works perfectly nice without the crdate and crtime... if i insert the crdate and crtime it gives me the only those records which are most currently chnaged according to chdate and chtime...would you like to help me in this regards, I am giving you the code here.. any suggestion or changes will be great help of mine... thanking you,,,,
regards naim... the code:
TYPES: BEGIN OF itab_type,
id TYPE i,
idnumber TYPE i,
chdate LIKE sy-datum,
chtime LIKE sy-uzeit,
crdate LIKE sy-datum,
crtime LIKE sy-uzeit.
TYPES: END OF itab_type.
DATA: itab TYPE TABLE OF itab_type WITH HEADER LINE,
itab_new TYPE TABLE OF itab_type WITH HEADER LINE,
prev_rec TYPE itab_type.
DATA: v_id TYPE i.
START-OF-SELECTION.
itab-id = 1.
itab-idnumber = 123456.
itab-chdate = '20060606'.
itab-chtime = '135312'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 2.
itab-idnumber = 123456.
itab-chdate = '20060606'.
itab-chtime = '135900'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 3.
itab-idnumber = 123456.
itab-chdate = '00000000'.
itab-chtime = '000000'.
itab-crtime = '20060622'.
itab-crdate = '125412'.
APPEND itab. CLEAR itab.
itab-id = 4.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '140000'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 5.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '142500'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 6.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '135312'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 7.
itab-idnumber = 123457.
itab-chdate = '00000000'.
itab-chtime = '000000'.
itab-crdate = '20060601'.
itab-crtime = '150000'.
APPEND itab. CLEAR itab.
itab_new[] = itab[].
SORT itab_new BY idnumber ASCENDING
chdate DESCENDING
chtime DESCENDING
crdate Descending
crtime Descending.
DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber.
LOOP AT itab.
WRITE:/ itab-id,
itab-idnumber,
itab-chdate,
itab-chtime,
itab-crdate,
itab-crtime.
ENDLOOP.
skip 5.
write: '_______________________________________________________________________________________'.
LOOP AT itab_new.
WRITE:/ itab_new-id,
itab_new-idnumber,
itab_new-chdate,
itab_new-chtime,
itab_new-crdate,
itab_new-crtime.
ENDLOOP.
06-22-2006 12:15 PM
SORT itab_new BY idnumber ASCENDING
chdate DESCENDING
chtime DESCENDING
crdate Descending
crtime Descending.
DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber<b> chdate chtime crdate crtime</b>.
you need chdate and chtime , crdate and crtime also .
Regards
vijay
06-22-2006 12:15 PM
SORT itab_new BY idnumber ASCENDING
chdate DESCENDING
chtime DESCENDING
crdate Descending
crtime Descending.
DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber<b> chdate chtime crdate crtime</b>.
you need chdate and chtime , crdate and crtime also .
Regards
vijay
06-22-2006 12:26 PM
Hi,
SORT itab_new BY idnumber ASCENDING
chdate DESCENDING
chtime DESCENDING
crdate Descending
crtime Descending.
DELETE ADJACENT DUPLICATES FROM itab_new.
Sameena
06-22-2006 12:47 PM
Dear Vijay and Sameena...
thank you very much for your prescious reply.. i wish to tell you that i have implemented your suggestions it gave me the same results which i am accessing please have look at the results...
ID IDNUMBER CHDATE CHTIME CRDATE CRTIME
1 123.456 06.06.2006 13:53:12 00.00.0000 00:00:00
2 123.456 06.06.2006 13:59:00 00.00.0000 00:00:00
3 123.456 00.00.0000 00:00:00 22.06.2006 12:54:12
4 123.457 06.06.2006 14:00:00 00.00.0000 00:00:00
5 123.457 06.06.2006 14:25:00 00.00.0000 00:00:00
6 123.457 06.06.2006 13:53:12 00.00.0000 00:00:00
7 123.457 00.00.0000 00:00:00 01.06.2006 15:00:00
_________________________________________________________
2 123.456 06.06.2006 13:59:00 00.00.0000 00:00:00
5 123.457 06.06.2006 14:25:00 00.00.0000 00:00:00
here it gave me the wrong results instead of id number 2 it should be 3 as it is most current record... respect to id 2 so please help in this scenario....
thanking you,....
regards
Naim
06-22-2006 12:52 PM
if your aim is based on date then don't sort it on idnumber.
SORT itab_new BY
chdate DESCENDING
chtime DESCENDING
crdate Descending
crtime Descending.
DELETE ADJACENT DUPLICATES FROM itab_new COMPARING chdate chtime crdate crtime.
Now check it.
Regards
vijay
06-22-2006 1:01 PM
thanx...
well why i am sorting by id number because i want the records in the group of idnumbers as you have notice that the i have two idnumber series and i am looking the most currently idnumbers from the group of idnumbers... that is why i am sorting it... now it gave me the result this way....
_____________________________________________________________
5 123.457 06.06.2006 14:25:00 00.00.0000 00:00:00
4 123.457 06.06.2006 14:00:00 00.00.0000 00:00:00
2 123.456 06.06.2006 13:59:00 00.00.0000 00:00:00
1 123.456 06.06.2006 13:53:12 00.00.0000 00:00:00
3 123.456 00.00.0000 00:00:00 22.06.2006 12:54:12
7 123.457 00.00.0000 00:00:00 01.06.2006 15:00:00
would you like to tell me some new way to do it...
thank you
regards
Naim
06-22-2006 1:04 PM
The output of modified code is..
1 123,456 06/06/2006 13:53:12 00/00/0000 00:00:00
2 123,456 06/06/2006 13:59:00 00/00/0000 00:00:00
3 123,456 00/00/0000 00:00:00 06/22/2006 12:54:12
4 123,457 06/06/2006 14:00:00 00/00/0000 00:00:00
5 123,457 06/06/2006 14:25:00 00/00/0000 00:00:00
6 123,457 06/06/2006 13:53:12 00/00/0000 00:00:00
7 123,457 00/00/0000 00:00:00 06/01/2006 15:00:00
3 123,456 00/00/0000 00:00:00 06/22/2006 12:54:12
1 123,456 06/06/2006 13:53:12 00/00/0000 00:00:00
7 123,457 00/00/0000 00:00:00 06/01/2006 15:00:00
5 123,457 06/06/2006 14:25:00 00/00/0000 00:00:00
06-22-2006 1:31 PM
Dear vijay
thank you for your valuable reply, well you are right here... but now how i elemenate those records which are smaller in the value compare to bigger one here... I have the correct results but i need to elemenate those record which are on high index of the correct record
3 123,456 00/00/0000 00:00:00 06/22/2006 12:54:12 <- it shouldnt be here... as 1 is bigger than 3
1 123,456 06/06/2006 13:53:12 00/00/0000 00:00:00
7 123,457 00/00/0000 00:00:00 06/01/2006 15:00:00 <- it shouldnt be here... as the 5 is bigger than 7
5 123,457 06/06/2006 14:25:00 00/00/0000 00:00:00
thank you...
regards,
Naim
06-22-2006 2:25 PM
Now check it..
REPORT ZTESTT .
TYPES: BEGIN OF itab_type,
id TYPE i,
idnumber TYPE i,
chdate LIKE sy-datum,
chtime LIKE sy-uzeit,
crdate LIKE sy-datum,
crtime LIKE sy-uzeit.
TYPES: END OF itab_type.
DATA: itab TYPE TABLE OF itab_type WITH HEADER LINE,
itab_new TYPE TABLE OF itab_type WITH HEADER LINE,
prev_rec TYPE itab_type.
DATA: v_id TYPE i.
START-OF-SELECTION.
itab-id = 1.
itab-idnumber = 123456.
itab-chdate = '20060606'.
itab-chtime = '135312'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 2.
itab-idnumber = 123456.
itab-chdate = '20060606'.
itab-chtime = '135900'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 3.
itab-idnumber = 123456.
itab-chdate = '00000000'.
itab-chtime = '000000'.
itab-crdate = '20060622'.
itab-crtime = '125412'.
APPEND itab. CLEAR itab.
itab-id = 4.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '140000'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 5.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '142500'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 6.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '135312'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 7.
itab-idnumber = 123457.
itab-chdate = '00000000'.
itab-chtime = '000000'.
itab-crdate = '20060601'.
itab-crtime = '150000'.
APPEND itab. CLEAR itab.
itab_new[] = itab[].
SORT itab_new BY
idnumber
crdate Descending
crtime Descending.
DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber crdate
crtime.
SORT itab_new BY
idnumber
chdate Descending
chtime Descending.
LOOP AT itab.
WRITE:/ itab-id,
itab-idnumber,
itab-chdate,
itab-chtime,
itab-crdate,
itab-crtime.
ENDLOOP.
skip 5.
LOOP AT itab_new.
WRITE:/ itab_new-id,
itab_new-idnumber,
itab_new-chdate,
itab_new-chtime,
itab_new-crdate,
itab_new-crtime.
ENDLOOP.
06-22-2006 1:02 PM
Hi,
i modifed your code now see...,Copy paste and see...
REPORT ZTESTT .
TYPES: BEGIN OF itab_type,
id TYPE i,
idnumber TYPE i,
chdate LIKE sy-datum,
chtime LIKE sy-uzeit,
crdate LIKE sy-datum,
crtime LIKE sy-uzeit.
TYPES: END OF itab_type.
DATA: itab TYPE TABLE OF itab_type WITH HEADER LINE,
itab_new TYPE TABLE OF itab_type WITH HEADER LINE,
prev_rec TYPE itab_type.
DATA: v_id TYPE i.
START-OF-SELECTION.
itab-id = 1.
itab-idnumber = 123456.
itab-chdate = '20060606'.
itab-chtime = '135312'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 2.
itab-idnumber = 123456.
itab-chdate = '20060606'.
itab-chtime = '135900'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 3.
itab-idnumber = 123456.
itab-chdate = '00000000'.
itab-chtime = '000000'.
<b>itab-crdate = '20060622'. "here you intechanged the data
itab-crtime = '125412'.</b>
APPEND itab. CLEAR itab.
itab-id = 4.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '140000'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 5.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '142500'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 6.
itab-idnumber = 123457.
itab-chdate = '20060606'.
itab-chtime = '135312'.
itab-crdate = '00000000'.
itab-crtime = '000000'.
APPEND itab. CLEAR itab.
itab-id = 7.
itab-idnumber = 123457.
itab-chdate = '00000000'.
itab-chtime = '000000'.
itab-crdate = '20060601'.
itab-crtime = '150000'.
APPEND itab. CLEAR itab.
itab_new[] = itab[].
SORT itab_new BY
idnumber
*chdate DESCENDING
*chtime DESCENDING
crdate Descending
crtime Descending.
DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber crdate
crtime.
*DELETE ADJACENT DUPLICATES FROM itab_new COMPARING idnumber.
LOOP AT itab.
WRITE:/ itab-id,
itab-idnumber,
itab-chdate,
itab-chtime,
itab-crdate,
itab-crtime.
ENDLOOP.
skip 5.
LOOP AT itab_new.
WRITE:/ itab_new-id,
itab_new-idnumber,
itab_new-chdate,
itab_new-chtime,
itab_new-crdate,
itab_new-crtime.
ENDLOOP.
Regards
vijay