DATE_CHECK_PLAUSIBILITY: ABAP FM to Check Whether Date is Valid

Some FM/BAPIs will not check whether date is valid or not and it will update whatever values you pass to it.

abap-check-date-validity-1

Then how can we check whether date is valid? Just use the function module
DATE_CHECK_PLAUSIBILITY to check the date is valid or not.

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: g_date TYPE sy-datum.
*&---------------------------------------------------------------------*
*& Start Of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  g_date = '99999999'.

*Check whether Date is valid
  CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
    EXPORTING
      date                      = g_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.

Output

abap-check-date-validity-2

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: g_date TYPE sy-datum.
*&---------------------------------------------------------------------*
*& Start Of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  g_date = 'abcd'.

*Check whether Date is valid
  CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
    EXPORTING
      date                      = g_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.

Output

abap-check-date-validity-3


Be the first to comment

Leave a Reply

Your email address will not be published.


*