06-29-2019 7:02 AM
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.
06-29-2019 8:07 AM
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?
07-01-2019 7:49 AM
Read again you source code, the error is obvious; Are you aware of existence of system fields such as SY-DATLO or SY-DATUM?
07-01-2019 7:57 PM
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.