15 Aralık 2011 Perşembe

SAP/ABAP: BAPI_ACC_DOCUMENT_POST FM

DATA: LS_DOCUMENTHEADER    LIKE BAPIACHE09,
      LV_OBJ_TYPE          LIKE BAPIACHE09-OBJ_TYPE,
      LV_OBJ_KEY           LIKE BAPIACHE09-OBJ_KEY,
      LV_OBJ_SYS           LIKE BAPIACHE09-OBJ_SYS,

      LT_ACCOUNTGL         LIKE TABLE OF BAPIACGL09,
      LT_ACCOUNTRECEIVABLE LIKE TABLE OF BAPIACAR09,
      LT_ACCOUNTPAYABLE    LIKE TABLE OF BAPIACAP09,
      LT_CURRENCYAMOUNT    LIKE TABLE OF BAPIACCR09,
      LT_RETURN            LIKE TABLE OF BAPIRET2,

      LS_ACCOUNTGL         LIKE          BAPIACGL09,
      LS_ACCOUNTRECEIVABLE LIKE          BAPIACAR09,
      LS_ACCOUNTPAYABLE    LIKE          BAPIACAP09,
      LS_CURRENCYAMOUNT    LIKE          BAPIACCR09,
      LS_RETURN            LIKE          BAPIRET2 .


  LS_DOCUMENTHEADER-COMP_CODE          = PA_BUKRS.
  LS_DOCUMENTHEADER-DOC_DATE           = PA_BLDAT.
  LS_DOCUMENTHEADER-PSTNG_DATE         = PA_BUDAT.
  LS_DOCUMENTHEADER-DOC_TYPE           = PA_BLART.
  LS_DOCUMENTHEADER-USERNAME           = SY-UNAME.
  LS_DOCUMENTHEADER-BUS_ACT            = 'RFBU'.
  LS_DOCUMENTHEADER-ACC_PRINCIPLE      = 'TGAP'.

*  ACCOUNTGL
    LV_ITEMNO_ACC = LV_ITEMNO_ACC + 1.

    LS_ACCOUNTGL-ITEMNO_ACC = LV_ITEMNO_ACC.
    LS_ACCOUNTGL-GL_ACCOUNT = P_P_GT_OUT-RACCT.
    LS_ACCOUNTGL-DOC_TYPE   = PA_BLART.        
    LS_ACCOUNTGL-COMP_CODE  = PA_BUKRS.
    LS_ACCOUNTGL-REF_KEY_1  = LS_ZFIT_BKY_DUZELT-XREF1.
    LS_ACCOUNTGL-REF_KEY_3  = LS_ZFIT_BKY_DUZELT-XREF3.

    APPEND LS_ACCOUNTGL TO LT_ACCOUNTGL.
    CLEAR: LS_ACCOUNTGL.

    LV_ITEMNO_ACC = LV_ITEMNO_ACC + 1.

    LS_ACCOUNTGL-ITEMNO_ACC = LV_ITEMNO_ACC.
    LS_ACCOUNTGL-GL_ACCOUNT = LS_ZFIT_BKY_DUZELT-HEDEF_HKONT.
    LS_ACCOUNTGL-DOC_TYPE   = PA_BLART.                    
    LS_ACCOUNTGL-COMP_CODE  = PA_BUKRS.
    LS_ACCOUNTGL-REF_KEY_1  = LS_ZFIT_BKY_DUZELT-XREF1.
    LS_ACCOUNTGL-REF_KEY_3  = LS_ZFIT_BKY_DUZELT-XREF3.

    APPEND LS_ACCOUNTGL TO LT_ACCOUNTGL.
    CLEAR: LS_ACCOUNTGL.


*--------------------------------------------------------------------*
*    CURRENCYAMOUNT

    READ TABLE LT_LOG INTO LS_LOG INDEX 1.

    CLEAR: LV_ITEMNO_ACC.
    LV_ITEMNO_ACC = LV_ITEMNO_ACC + 1.

    LS_CURRENCYAMOUNT-ITEMNO_ACC = LV_ITEMNO_ACC.
    LS_CURRENCYAMOUNT-CURR_TYPE  = '10'.
    LS_CURRENCYAMOUNT-CURRENCY   = 'TRY'.
    LS_CURRENCYAMOUNT-AMT_DOCCUR = P_P_GT_OUT-HSLXX * LV_CARPAN.
    LS_CURRENCYAMOUNT-CURRENCY_ISO = 'TRY'.

    APPEND LS_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
    CLEAR: LS_CURRENCYAMOUNT.

    IF LV_CURRENCY NE 'TRY'.

      LS_CURRENCYAMOUNT-ITEMNO_ACC = LV_ITEMNO_ACC.
      LS_CURRENCYAMOUNT-CURR_TYPE  = '00'.
      LS_CURRENCYAMOUNT-CURRENCY   = LV_CURRENCY.
      LS_CURRENCYAMOUNT-AMT_DOCCUR = P_P_GT_OUT-TSLXX * LV_CARPAN.
      LS_CURRENCYAMOUNT-CURRENCY_ISO = LV_CURRENCY.

      APPEND LS_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
      CLEAR: LS_CURRENCYAMOUNT.

    ENDIF.

    LS_CURRENCYAMOUNT-ITEMNO_ACC = LV_ITEMNO_ACC.
    LS_CURRENCYAMOUNT-CURR_TYPE  = '30'.
    LS_CURRENCYAMOUNT-CURRENCY   = 'EUR'.
    LS_CURRENCYAMOUNT-AMT_DOCCUR = P_P_GT_OUT-KSLXX * LV_CARPAN.
    LS_CURRENCYAMOUNT-CURRENCY_ISO = 'EUR'.

    APPEND LS_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
    CLEAR: LS_CURRENCYAMOUNT.

    LS_CURRENCYAMOUNT-ITEMNO_ACC = LV_ITEMNO_ACC.
    LS_CURRENCYAMOUNT-CURR_TYPE  = '50'.
    LS_CURRENCYAMOUNT-CURRENCY   = 'USD'.
    LS_CURRENCYAMOUNT-AMT_DOCCUR = P_P_GT_OUT-OSLXX * LV_CARPAN.
    LS_CURRENCYAMOUNT-CURRENCY_ISO = 'USD'.

    APPEND LS_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
    CLEAR: LS_CURRENCYAMOUNT.

*--------------------------------------------------------------------*
    LV_ITEMNO_ACC = LV_ITEMNO_ACC + 1.

    LS_CURRENCYAMOUNT-ITEMNO_ACC = LV_ITEMNO_ACC.
    LS_CURRENCYAMOUNT-CURR_TYPE  = '10'.
    LS_CURRENCYAMOUNT-CURRENCY   = 'TRY'.
    LS_CURRENCYAMOUNT-AMT_DOCCUR = P_P_GT_OUT-HSLXX.
    LS_CURRENCYAMOUNT-CURRENCY_ISO = 'TRY'.

    APPEND LS_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
    CLEAR: LS_CURRENCYAMOUNT.

    IF LV_CURRENCY NE 'TRY'.

      LS_CURRENCYAMOUNT-ITEMNO_ACC = LV_ITEMNO_ACC.
      LS_CURRENCYAMOUNT-CURR_TYPE  = '00'.
      LS_CURRENCYAMOUNT-CURRENCY   = LV_CURRENCY.
      LS_CURRENCYAMOUNT-AMT_DOCCUR = P_P_GT_OUT-TSLXX.
      LS_CURRENCYAMOUNT-CURRENCY_ISO = LV_CURRENCY.

      APPEND LS_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
      CLEAR: LS_CURRENCYAMOUNT.

    ENDIF.



    LS_CURRENCYAMOUNT-ITEMNO_ACC = LV_ITEMNO_ACC.
    LS_CURRENCYAMOUNT-CURR_TYPE  = '30'.
    LS_CURRENCYAMOUNT-CURRENCY   = 'EUR'.
    LS_CURRENCYAMOUNT-AMT_DOCCUR = P_P_GT_OUT-KSLXX.
    LS_CURRENCYAMOUNT-CURRENCY_ISO = 'EUR'.

    APPEND LS_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
    CLEAR: LS_CURRENCYAMOUNT.

    LS_CURRENCYAMOUNT-ITEMNO_ACC = LV_ITEMNO_ACC.
    LS_CURRENCYAMOUNT-CURR_TYPE  = '50'.
    LS_CURRENCYAMOUNT-CURRENCY   = 'USD'.
    LS_CURRENCYAMOUNT-AMT_DOCCUR = P_P_GT_OUT-OSLXX.
    LS_CURRENCYAMOUNT-CURRENCY_ISO = 'USD'.

    APPEND LS_CURRENCYAMOUNT TO LT_CURRENCYAMOUNT.
    CLEAR: LS_CURRENCYAMOUNT.

IF RB_TEST EQ 'X'.

    CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
      EXPORTING
        DOCUMENTHEADER = LS_DOCUMENTHEADER
      TABLES
        ACCOUNTGL      = LT_ACCOUNTGL
        CURRENCYAMOUNT = LT_CURRENCYAMOUNT
        RETURN         = LT_RETURN.

ELSEIF RB_YARD EQ 'X'.

    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
      EXPORTING
        DOCUMENTHEADER     = LS_DOCUMENTHEADER
      IMPORTING
        OBJ_TYPE           = LV_OBJ_TYPE
        OBJ_KEY            = LV_OBJ_KEY
        OBJ_SYS            = LV_OBJ_SYS
      TABLES
        ACCOUNTGL          = LT_ACCOUNTGL
*        accountreceivable = LT_ACCOUNTRECEIVABLE
*        accountpayable    = LT_ACCOUNTPAYABLE
        CURRENCYAMOUNT     = LT_CURRENCYAMOUNT
        RETURN             = LT_RETURN.
  ENDIF.

  CLEAR: W_ERROR.

  LOOP AT LT_RETURN
     INTO LS_RETURN
    WHERE TYPE EQ 'E'.

    W_ERROR = 'X'.

    EXIT.

  ENDLOOP.

 IF W_ERROR NE 'X'.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT = 'X'.
    MESSAGE 'Belge Kaydedildi' TYPE 'S'.

    CLEAR: LT_LOG[].

    PERFORM ZFIT_BKY_LOG USING    LV_KAYIT_TURU
                         CHANGING LT_LOG.

  ENDIF.

  CALL FUNCTION 'RSCRMBW_DISPLAY_BAPIRET2'
    TABLES
      IT_RETURN = LT_RETURN.

Hiç yorum yok:

Yorum Gönder

İnsdroid

Sabahtan beri çatada çutada çatada çutada… Bitmedi yine de… Neyse, yolumuz uzun, toparlıyorum çantamı, adaptörü falan tıkıştırıyorum bir şe...