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: 

problem in comparison date

Former Member
0 Kudos

hallow

i doing loop that check if tmp_begda < v_date1.

1.in the first time tmp_begda = 01012006 and v_date1 = 01012007

and if go to the end if (o.k.)

2.in the second time tmp_begda = <b>01022006</b> and v_date1 = 01012007

and i go to the else statment and do modify.

why tmp begda is less then v_date?

<b>tmp_begda and v_date type sy-datum.</b>

<b>i reward</b>

this is my code

loop....

IF tmp_begda < v_date1.

ELSE.

MOVE tmp_begda TO wa_period-date1.

MODIFY period_tbl FROM wa_period TRANSPORTING date1.

ENDIF.

ENDLOOP.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

when you are comparing the dates should be of type sy-datum and should be in the format YYYYMMDD,

chk these 2 programs

REPORT ZTEST.

DATA : V_DATE1 LIKE SY-DATUM,
       V_DATE2 LIKE SY-DATUM..

V_DATE1 = '01022006'.
V_DATE2 = '01012007'.

IF V_DATE1 LE V_DATE2.
  WRITE : 'yes'.
ELSE.
  WRITE : 'no'.
ENDIF.

<b>Output : No.</b>

REPORT ZTEST.

DATA : V_DATE1 LIKE SY-DATUM,
       V_DATE2 LIKE SY-DATUM..

V_DATE1 = '20060201'.
V_DATE2 = '20070101'.

IF V_DATE1 LE V_DATE2.
  WRITE : 'yes'.
ELSE.
  WRITE : 'no'.
ENDIF.

<b>Output : Yes</b>

3 REPLIES 3

Former Member
0 Kudos

Hi!

SAP handles date in the following internal format: YYYYMMDD

If you are filling dynamically those fields, try using this format.

Regards

Tamá

Former Member
0 Kudos

when you are comparing the dates should be of type sy-datum and should be in the format YYYYMMDD,

chk these 2 programs

REPORT ZTEST.

DATA : V_DATE1 LIKE SY-DATUM,
       V_DATE2 LIKE SY-DATUM..

V_DATE1 = '01022006'.
V_DATE2 = '01012007'.

IF V_DATE1 LE V_DATE2.
  WRITE : 'yes'.
ELSE.
  WRITE : 'no'.
ENDIF.

<b>Output : No.</b>

REPORT ZTEST.

DATA : V_DATE1 LIKE SY-DATUM,
       V_DATE2 LIKE SY-DATUM..

V_DATE1 = '20060201'.
V_DATE2 = '20070101'.

IF V_DATE1 LE V_DATE2.
  WRITE : 'yes'.
ELSE.
  WRITE : 'no'.
ENDIF.

<b>Output : Yes</b>

Former Member
0 Kudos

Hi Tal,

If you pass any value to the variable to date field then it should be in the format YYYYMMDD and it will stored in the internal format as MMYYDDDD.

Check whether you are passing value to V_DATE1 as YYYYMMDD??

Thanks,

Vinay