2018년 11월 2일 금요일

임시전표삭제

  SELECT SINGLE *
    FROM VBKPF
   WHERE VBKPF~BUKRS EQ I_BUKRS
     AND VBKPF~GJAHR EQ I_GJAHR
     AND VBKPF~BELNR EQ I_BELNR.
  IF SY-SUBRC EQ 0.
    CASE VBKPF-AWTYP.
      WHEN 'RMRP'.


      WHEN OTHERS.
*     전표 삭제 시 CO/FM전표 삭제도 동시에 하도록..
        CLEAR LS_ACCDEL.
        LS_ACCDEL-AWTYP      'BKPF'.      "참조절차
        LS_ACCDEL-AWREF      VBKPF-BELNR"전표번호
        LS_ACCDEL-STATUS_OLD '3'.         "이전 대체전표의 상태
        CONCATENATE I_BUKRS I_GJAHR INTO LS_ACCDEL-AWORG.

        CALL FUNCTION 'AC_DOCUMENT_DELETE'
          EXPORTING
            I_ACCDEL          LS_ACCDEL
          EXCEPTIONS
            DELETE_IMPOSSIBLE 1
            OTHERS            2.

        CHECK SY-SUBRC EQ 0.
*       임시전표 삭제 펑션
        CALL FUNCTION 'PRELIMINARY_POSTING_DOC_DELETE'
          EXPORTING
            BELNR              I_BELNR
            BSTAT              'Z'
            BUKRS              I_BUKRS
            GJAHR              I_GJAHR
          EXCEPTIONS
            DOCUMENT_NOT_FOUND 1
            UPDATE_ERROR       2
            OTHERS             3.

        CHECK SY-SUBRC EQ 0.
        CALL FUNCTION 'AC_DOCUMENT_POST'
          EXPORTING
            I_AWTYP LS_ACCDEL-AWTYP
            I_AWREF LS_ACCDEL-AWREF
            I_AWORG LS_ACCDEL-AWORG.

        CHECK SY-SUBRC EQ 0.
        CALL FUNCTION 'FI_CHECK_EXTENDED_WT'
          EXPORTING
            I_BUKRS              I_BUKRS
          EXCEPTIONS
            COMPONENT_NOT_ACTIVE 1
            NOT_FOUND            2
            OTHERS               3.

        CALL FUNCTION 'FI_WT_PRELIMINARY_POST_DOC_DEL' IN UPDATE TASK
          EXPORTING
            I_BELNR I_BELNR
            I_BUKRS I_BUKRS
            I_GJAHR I_GJAHR
          EXCEPTIONS
            OTHERS  1.

        IF SY-SUBRC EQ 0.
'.          COMMIT WORK.
        ELSE.
          ROLLBACK WORK.
        ENDIF.

    ENDCASE.
*
  ELSE.
    ROLLBACK WORK.
  ENDIF.