Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[ABAP] Validate date

CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
  EXPORTING
    date                      = '20250231' " invalid 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 you’re not interested in a specific error message, you can also use the following method to get the result as boolean.

DATA(date_is_valid) = cl_rs_time_service=>is_valid_date( '20250231' ).

Leave a Reply

Your email address will not be published. Required fields are marked *