To check the validity of a date field you can use the following function module.
DATE_CHECK_PLAUSIBILITY
Please see the example given below.REPORT ZEX_DATEVALIDATE .
Parameters p_date like sy-datum.
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.
Write:/ sy-subrc.
Parameters p_date like sy-datum.
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.
Write:/ sy-subrc.
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
0
If the input is 31/31/2008 then the output is as follows.
Validate the date
1
1
No comments:
Post a Comment