*----------------------------------------------------------------------*
***INCLUDE LZSY_D_ZDGZF01.
*----------------------------------------------------------------------*

CONSTANTS:
  GCF_DEL_FLAG       TYPE CHAR1 VALUE 'M',    " Delete Flag
  GCF_INS            TYPE CHAR1 VALUE 'N',    " Insert Date
  GCF_UPD            TYPE CHAR1 VALUE 'U',    " Update Date
  GCF_STATUS_ADD     TYPE CHAR1 VALUE 'A',    " Create Status
  GCF_STATUS_COPY    TYPE CHAR1 VALUE 'C',    " Copy Status
  GCF_STATUS_CHANGE  TYPE CHAR1 VALUE 'U',    " Change Status
  GCF_STATUS_DISPLAY TYPE CHAR1 VALUE 'S',    " Display Status
  GCF_ACTVT          TYPE CHAR2 VALUE '01'.   " Activity '01'

*&---------------------------------------------------------------------*
*& Form FRM_BEFORE_SAVE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_before_save .

  DATA: LV_LENGTH TYPE I.

  DATA: LV_ACTION TYPE C.
  DATA: LV_TSTAMP TYPE TIMESTAMP.

  DATA:LT_ZSY_D_ZDGZ_OLD TYPE TABLE OF ZSY_D_ZDGZ,
       LS_ZSY_D_ZDGZ_OLD LIKE LINE OF LT_ZSY_D_ZDGZ_OLD,
       LT_ZSY_D_ZDGZ_NEW TYPE TABLE OF ZSY_D_ZDGZ,
       LS_ZSY_D_ZDGZ_NEW LIKE LINE OF LT_ZSY_D_ZDGZ_NEW.

  FIELD-SYMBOLS: <FS_VALUE> .
  FIELD-SYMBOLS: <FS_TOTAL> .
  FIELD-SYMBOLS: <FS_EXTRACT>.

  LOOP AT TOTAL ASSIGNING <FS_TOTAL>.

    CLEAR: LV_LENGTH.
    LV_LENGTH = STRLEN( <FS_TOTAL> ) - 1.

    ASSIGN <FS_TOTAL>+LV_LENGTH(1) TO <FS_VALUE>.
    IF SY-SUBRC = 0.
      LV_ACTION = <FS_VALUE>.

*  简短格式的时间戳:
      CONVERT DATE SY-DATUM
              TIME SY-UZEIT
              INTO TIME STAMP LV_TSTAMP  "时戳
              TIME ZONE SY-ZONLO.

* If It's New Records
      IF LV_ACTION = GCF_INS.

* Set Field Value

        LV_LENGTH = LV_LENGTH - 6.
        ASSIGN <FS_TOTAL>+LV_LENGTH(6) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-UZEIT.
        ENDIF.

        LV_LENGTH = LV_LENGTH - 8.
        ASSIGN <FS_TOTAL>+LV_LENGTH(8) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-DATUM.
        ENDIF.

        LV_LENGTH = LV_LENGTH - 12.
        ASSIGN <FS_TOTAL>+LV_LENGTH(12) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-UNAME.
        ENDIF.


* If It's Update Records
      ELSEIF LV_ACTION = GCF_UPD.
* Set Field Value

        LV_LENGTH = LV_LENGTH - 6.
        ASSIGN <FS_TOTAL>+LV_LENGTH(6) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-UZEIT.
        ENDIF.

        LV_LENGTH = LV_LENGTH - 8.
        ASSIGN <FS_TOTAL>+LV_LENGTH(8) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-DATUM.
        ENDIF.

        LV_LENGTH = LV_LENGTH - 12.
        ASSIGN <FS_TOTAL>+LV_LENGTH(12) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-UNAME.
        ENDIF.

      ENDIF.
    ENDIF.

    CLEAR:LS_ZSY_D_ZDGZ_OLD.
    LS_ZSY_D_ZDGZ_OLD =  <FS_TOTAL>.
    APPEND LS_ZSY_D_ZDGZ_OLD TO LT_ZSY_D_ZDGZ_OLD.
  ENDLOOP.

  LOOP AT EXTRACT ASSIGNING <FS_EXTRACT>.

    CLEAR: LV_LENGTH.
    LV_LENGTH = STRLEN( <FS_EXTRACT> ) - 1.

    ASSIGN <FS_EXTRACT>+LV_LENGTH(1) TO <FS_VALUE>.
    IF SY-SUBRC = 0.
      LV_ACTION = <FS_VALUE>.

      "简短格式的时间戳:
      CONVERT DATE SY-DATUM
              TIME SY-UZEIT
              INTO TIME STAMP LV_TSTAMP  "时戳
              TIME ZONE SY-ZONLO.

* If It's New Records
      IF LV_ACTION = GCF_INS.

* Set Field Value

        LV_LENGTH = LV_LENGTH - 6.
        ASSIGN <FS_EXTRACT>+LV_LENGTH(6) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-UZEIT.
        ENDIF.

        LV_LENGTH = LV_LENGTH - 8.
        ASSIGN <FS_EXTRACT>+LV_LENGTH(8) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-DATUM.
        ENDIF.

        LV_LENGTH = LV_LENGTH - 12.
        ASSIGN <FS_EXTRACT>+LV_LENGTH(12) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-UNAME.
        ENDIF.

* If It's Update Records
      ELSEIF <FS_VALUE> = GCF_UPD.
* Set Field Value

        LV_LENGTH = LV_LENGTH - 6.
        ASSIGN <FS_EXTRACT>+LV_LENGTH(6) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-UZEIT.
        ENDIF.

        LV_LENGTH = LV_LENGTH - 8.
        ASSIGN <FS_EXTRACT>+LV_LENGTH(8) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-DATUM.
        ENDIF.

        LV_LENGTH = LV_LENGTH - 12.
        ASSIGN <FS_EXTRACT>+LV_LENGTH(12) TO <FS_VALUE>.
        IF SY-SUBRC = 0.
          <FS_VALUE> = SY-UNAME.
        ENDIF.
      ENDIF.
    ENDIF.

    CLEAR:LS_ZSY_D_ZDGZ_NEW.
    LS_ZSY_D_ZDGZ_NEW =  <FS_EXTRACT>.
    APPEND LS_ZSY_D_ZDGZ_NEW TO LT_ZSY_D_ZDGZ_NEW.

  ENDLOOP.

  DELETE LT_ZSY_D_ZDGZ_OLD WHERE YAER IS INITIAL AND PAY IS INITIAL.
  DELETE LT_ZSY_D_ZDGZ_NEW WHERE YAER IS INITIAL AND PAY IS INITIAL.

ENDFORM.