‎2009 Apr 16 4:02 PM
Hi there,
I would like to know how to check the validity of a date ?
By validity I does not mean "format" but the existence of the date in daily calendar (no need to check in enterprises calendars).
For example 12
Do you have any idea ?
thanks a lot
Regards
Morgan
‎2009 Apr 16 4:24 PM
REPORT ZTEST MESSAGE-ID Z1.
data: lv_date type sy-datum,
lv_msg(50) type c.
lv_date = '20051232'.
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
DATE = lv_date
EXCEPTIONS
PLAUSIBILITY_CHECK_FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 into lv_msg.
write: lv_msg.
ENDIF.
‎2009 Apr 16 4:09 PM
PARAMETER: p_date TYPE sy-datum.its being checked if its declared as sy-datum.
‎2009 Apr 16 4:16 PM
Hello Morgan,
I will like to add to J@y's post if you declare the date as TYPE datum compiler automatically performs the check for you.
Hope i am clear.
BR,
Suhas
‎2009 Apr 16 4:19 PM
Hi,
thanks but I never tell that the dat was a parameter ... it's just a variable filled in from a file.
If I try to fill on a variable of type datum, it works but the date is not consistant ...
‎2009 Apr 16 4:26 PM
‎2009 Apr 16 4:28 PM
‎2009 Apr 16 4:24 PM
REPORT ZTEST MESSAGE-ID Z1.
data: lv_date type sy-datum,
lv_msg(50) type c.
lv_date = '20051232'.
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
DATE = lv_date
EXCEPTIONS
PLAUSIBILITY_CHECK_FAILED = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 into lv_msg.
write: lv_msg.
ENDIF.
‎2009 Apr 16 4:37 PM
DATE_CHECK_PLAUSIBILITY :Check for the invalid date.
This function module checks if the date is in valid format for sap.
It also check if it is valid calender date or no.
So this should work for your requirement.
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING
DATE = p_date
EXCEPTIONS
PLAUSIBILITY_CHECK_FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.If the value of Sy-subrc is 0 that means the date field has a valid value.
If the input is 01/01/2008 then the output of the above program is as follows.
Validate the date 0
If the input is 31/31/2008 then the output is as follows.
Validate the date 1
Regards,
Lalit Mohan Gupta.