SAP ABAP DATE_CHECK_PLAUSIBILITY 检查日期合法性 源码

FUNCTION DATE_CHECK_PLAUSIBILITY.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"       IMPORTING
*"              DATE LIKE  SY-DATUM
*"       EXCEPTIONS
*"              PLAUSIBILITY_CHECK_FAILED
*"----------------------------------------------------------------------

  DATA: CHECK_YEAR_1 TYPE P.
  DATA: CHECK_YEAR_2 TYPE P.

  IF DATE CN '0123456789'.
    MESSAGE S011 WITH DATE RAISING PLAUSIBILITY_CHECK_FAILED.
  ENDIF.

  IF DATE+4(2) LT '01'
  OR DATE+4(2) GT '12'.
    MESSAGE S003 WITH DATE+4(2) RAISING PLAUSIBILITY_CHECK_FAILED.
  ENDIF.

  IF DATE+6(2) LT '01'
  OR DATE+6(2) GT '31'.
    MESSAGE S006 WITH DATE+6(2) RAISING PLAUSIBILITY_CHECK_FAILED.
  ENDIF.

  IF DATE+4(2) EQ '01'
  OR DATE+4(2) EQ '03'
  OR DATE+4(2) EQ '05'
  OR DATE+4(2) EQ '07'
  OR DATE+4(2) EQ '08'
  OR DATE+4(2) EQ '10'
  OR DATE+4(2) EQ '12'.
    IF DATE+6(2) GT '31'.
      MESSAGE S004 WITH DATE+6(2) DATE+4(2)
                   RAISING PLAUSIBILITY_CHECK_FAILED.
    ENDIF.
  ELSEIF DATE+4(2) EQ '04'
  OR     DATE+4(2) EQ '06'
  OR     DATE+4(2) EQ '09'
  OR     DATE+4(2) EQ '11'.
    IF DATE+6(2) GT '30'.
      MESSAGE S004 WITH DATE+6(2) DATE+4(2)
                   RAISING PLAUSIBILITY_CHECK_FAILED.
    ENDIF.
  ELSE.
    CHECK_YEAR_1 = DATE(4) MOD 4.      " alle 4 Jahre ist schaltjahr
    IF CHECK_YEAR_1 EQ 0.
      CHECK_YEAR_1 = DATE(4) MOD 100.  " aber nicht alle 100 Jahre
      CHECK_YEAR_2 = DATE(4) MOD 400.  " aber alle 400 Jahre
      IF CHECK_YEAR_1 EQ 0
      AND CHECK_YEAR_2 NE 0.
        IF DATE+6(2) GT '28'.
          MESSAGE S004 WITH DATE+6(2) DATE+4(2)
                       RAISING PLAUSIBILITY_CHECK_FAILED.
        ENDIF.
      ELSE.
        IF DATE+6(2) GT '29'.
          MESSAGE S004 WITH DATE+6(2) DATE+4(2)
                       RAISING PLAUSIBILITY_CHECK_FAILED.
        ENDIF.
      ENDIF.
    ELSE.
      IF DATE+6(2) GT '28'.
        MESSAGE S004 WITH DATE+6(2) DATE+4(2)
                     RAISING PLAUSIBILITY_CHECK_FAILED.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFUNCTION.

你可能感兴趣的:(ABAP,其他)