SAP for Utilities Discussions
Connect with fellow SAP users to share best practices, troubleshoot challenges, and collaborate on building a sustainable energy future. Join the discussion.
cancel
Showing results for 
Search instead for 
Did you mean: 

Sort Date and Time Fields

Former Member
0 Kudos

Hi Everyone,

I have requirement to sort date and time fiields in an internal table.

The internal table looks something like this during runtime.

Line Objectclass UDATE UTIME OBJECTID CHANGENR CHANGE_IND

8 ISU_EEIN 20080305 144814 000000000111 0000035262 I

9 ISU_EEIN 20080305 145735 000000000112 0000035281 I

10 ISU_EEIN 20080305 151418 000000000113 0000035319 I

11 ISU_EEIN 20080305 154931 000000000114 0000035378 I

12 ISU_EEIN 20080305 155002 000000000115 0000035389 I

13 ISU_EEIN 20080305 162803 000000000116 0000035400 I

14 ISU_EEIN 20080306 095028 000000000113 0000035450 U

15 ISU_EEIN 20080306 123835 000000000117 0000035613 I

16 ISU_EEIN 20080306 133532 000000000118 0000035628 I

Now if you observe Line 10 and Line 14.

OBJECT ID has two entries. One with Change_Ind 'I' on 05.03.2008 and 'U' on 06.03.2008.

After sorting and deleting ,I need to have only ie... Line 14 for objectid 113.

The current sort stmt which i am using is not solving the purpose,

Can you guys help me as how to achieve the result?

Awaiting your replies.

Regards,

Vinay

2 REPLIES 2

RonnyF
Advisor
Advisor
0 Kudos

Hi Vinay,

you could use the statement SORT itab BY objectid udate utime. Afterwards it's possible to delete duplicate entries with statement DELETE ADJACENT DUPLICATES FROM itab. You could also define which fields should not be twice with the addition COMPARING objectid. In the online help you'll find further information about this topic.

Best regards,

Ronny

Former Member
0 Kudos

Hi vinay,

If you want to keep the latest record based on the Object ID in the internal table, do sort in the following way : SORT <itab-name> BY OBJECTID UDATE DESCENDING UTIME DESCENDING. Then do DELETE ADJACENT DUPLICATES FROM <itab-name> COMPARING OBJECTID.

Regards,

Sourav Nandi.