cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Abap Routine for Comparing Dates by sy-datum and sy-uzeit

tnecnivo
Active Contributor
0 Kudos
4,370

Hi BI/ABAP gurus,

I am trying to compare the fields DUE_TS.

DUE_TS consist of Timestamp of Due Date. (e.g. 20160130223025)


I then split DUE_TS timestamp into 2 parts, dates and times

My condition as below:-

If DUE_TS(dates) is Greater/Equal than system date and DUE_TS(time) is greater/equal than system time.

then show 'X'.

Else show '<blank>'.

My routine below doesn't seems to work.

Can anyone point out where the mistake might be?


DATA: date like sy-datum,

       time like sy-uzeit.

date = SOURCE_FIELDS-DUEDT+0(8).

time = SOURCE_FIELDS-DUEDT+8(6).

IF date GT sy-datum or

    date = sy-datum and time GT sy-uzeit.

RESULT = 'X'.

ELSE.

RESULT = ''.

ENDIF.


Many thanks.

Accepted Solutions (1)

Accepted Solutions (1)

RafkeMagic
Active Contributor
0 Kudos

try using brackets...


IF date GT sy-datum

OR ( date = sy-datum and time GT sy-uzeit ).

  RESULT = 'X'.

ELSE.

  RESULT = ''.

ENDIF.

tnecnivo
Active Contributor
0 Kudos

Hi Raf,

Thanks, your code works, and actually my initial codes works too, I just didn't scroll down and check thoroughly.

Kind regards

Answers (1)

Answers (1)

anindya_bose
Active Contributor
0 Kudos

Try this

IF date GT sy-datum.

   RESULT = 'X' .


ELSEIF date EQ. sy-datum  and time GT sy-uzeit.


RESULT = 'X' .

ENDIF .


ELSE


RESULT = ''.

ENDIF.


Just check the nesting, I did not type it in ABAP editor, might have missed some endif.


You might call the method if available in your system.

CALL METHOD cl_abap_tstmp=>compare

  EXPORTING

    tstmp1                     = timestamp1

    tstmp2                     = timestamp2

  receiving

    comp                       = result1.

result1 =   -1/,0,/1   lower, equal , greater . Accordingly calculate ur result.

Regards

Anindya




Regards

Anindya

RafkeMagic
Active Contributor
0 Kudos

there's 1 ENDIF too many in the above code...

tnecnivo
Active Contributor
0 Kudos

Hi Anindya,

Yup, an extra ENDIF.

Please amend.

anindya_bose
Active Contributor
0 Kudos

Yup, just compiled the code . There were some other problem as well.

Method 1 :

IF date GT sy-datum.

    RESULT = 'X' .

ELSEIF date EQ sy-datum  and time GT sy-uzeit.

RESULT = 'X' .

ELSE.

RESULT = ''.

ENDIF.


Method 2 :


data temp type I .

CALL METHOD cl_abap_tstmp=>compare

   EXPORTING

     tstmp1                     = 20160310093701   "was checking with constant values.

     tstmp2                     = 20160310093700

   receiving

     comp                       = temp.


Based on  temp, you can calculate Result .


Documentation available here. ABAP Keyword Documentation


Regards

Anindya