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: 

how to validate future date ?

0 Kudos

I need a validation for, example if user enter a future date that should be catched in error table.? Below is my code.

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; }

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; }

PARAMETERS : P_DATE LIKE SY-DATUM.
data: lv_date type sy-datum.

lv_date = p_date + 1.
if p_date > lv_date.
MESSAGE 'you entered a future date' type 'E'.
else.
MESSAGE 'you entered acorrect date' type 'I'.
ENDIF.

3 REPLIES 3

matt
Active Contributor
0 Kudos

Run it in debug to see what you did wrong. And why are you using the L in your variable name, when it clearly isn't local?

raymond_giuseppi
Active Contributor
0 Kudos

Read again you source code, the error is obvious; Are you aware of existence of system fields such as SY-DATLO or SY-DATUM?

Jelena
Active Contributor

As raymond.giuseppi mentioned, the problem is quite obvious: it's adding 1 to a variable and the comparing the result with the original variable. When Y = X + 1 then the condition IF Y > X will always be true. This code does not validate whether the date is in future, it's really just meaningless.

To determine if the date is in future you need to establish first what exactly is the definition of "future". What time zone and what date do you want to use as a base for comparison? When the criteria is clear then you can simply compare two date fields.