Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata


Easy way to validate a given DATE?

validation of date playes a major role in DATA MIGRATION in SAP.
This is the easy way to validate a given date .

This method  makes use of the TYPE CONVERSION.
D to I.

Usually when we convert a variable of type d to type i,and if the value of the
variable d is a VALID date,then this conversion will give the number of days
from the initial date (00010101).
If the value of the variable d is an INVALID date,then the result of this conversion will be ZERO.
You can use this functionality of TYPES to validate a given date.

Example.
If the given date is a valid date.
data:
w_d type d value  '20090212',
w_i type i.
move w_d to w_i.
write:/ w_i.

Result:

Example.

If the given date is an in valid date.

data:
w_d type d value  '20091412',
w_i type i.
move w_d to w_i.
write:/ w_i.

Result.

How to change the date format to user date format?

If you hard code the date format when you upload data from any file to SAP
,it will work at that point of time.But later if the user format has been changed
by someone ,your program will give you a wrong result.

Below given is a simple way to avoid this problem.
This code will convert the date format to the user format ,whatever the user
format is.

data:
w_c(8) value '20091202',
w_d type sy-datum.
write w_c to w_d.
write:
w_d.

Result:

  • No labels

1 Comment

  1. Guest

    Nice approach to validate user given date format . Saved my day :)