Difference between revisions of "SAP FI BAPI"

From SapWiki
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
==BAPI_ACC_DOCUMENT_POST ==
 
==BAPI_ACC_DOCUMENT_POST ==
 
*Ejemplo con extensión
 
*Ejemplo con extensión
  FORM document_post USING p_pernr
+
  <nowiki>FORM document_post USING p_pernr
                          p_begda
+
                        p_begda
                          p_endda
+
                        p_endda
                          p_monto
+
                        p_monto
                          p_modo
+
                        p_modo
                CHANGING p_subrc
+
                CHANGING p_subrc
                          p_return TYPE bapiret2.
+
                        p_return TYPE bapiret2.
  DATA:
+
  DATA:
    ls_documentheader    LIKE bapiache09,
+
    ls_documentheader    LIKE bapiache09,
    l_customercpd        LIKE bapiacpa09,
+
    l_customercpd        LIKE bapiacpa09,
    l_fica_hd            LIKE bapiaccahd,
+
    l_fica_hd            LIKE bapiaccahd,
    it_accountreceivable LIKE TABLE OF bapiacar09 WITH HEADER LINE,
+
    it_accountreceivable LIKE TABLE OF bapiacar09 WITH HEADER LINE,
    it_accountgl        LIKE TABLE OF bapiacgl09 WITH HEADER LINE,
+
    it_accountgl        LIKE TABLE OF bapiacgl09 WITH HEADER LINE,
    it_accounttax        LIKE TABLE OF bapiactx09 WITH HEADER LINE,
+
    it_accounttax        LIKE TABLE OF bapiactx09 WITH HEADER LINE,
    it_criteria          LIKE TABLE OF bapiackec9 WITH HEADER LINE,
+
    it_criteria          LIKE TABLE OF bapiackec9 WITH HEADER LINE,
    it_valuefield        LIKE TABLE OF bapiackev9 WITH HEADER LINE,
+
    it_valuefield        LIKE TABLE OF bapiackev9 WITH HEADER LINE,
    it_currencyamount    LIKE TABLE OF bapiaccr09 WITH HEADER LINE,
+
    it_currencyamount    LIKE TABLE OF bapiaccr09 WITH HEADER LINE,
    it_return            LIKE TABLE OF bapiret2  WITH HEADER LINE,
+
    it_return            LIKE TABLE OF bapiret2  WITH HEADER LINE,
    it_receivers        LIKE TABLE OF bdi_logsys WITH HEADER LINE,
+
    it_receivers        LIKE TABLE OF bdi_logsys WITH HEADER LINE,
    it_fica_it          LIKE TABLE OF bapiaccait WITH HEADER LINE,
+
    it_fica_it          LIKE TABLE OF bapiaccait WITH HEADER LINE,
    it_accountpayable    LIKE TABLE OF bapiacap09 WITH HEADER LINE,
+
    it_accountpayable    LIKE TABLE OF bapiacap09 WITH HEADER LINE,
    it_paymentcard      LIKE TABLE OF bapiacpc09 WITH HEADER LINE,
+
    it_paymentcard      LIKE TABLE OF bapiacpc09 WITH HEADER LINE,
    it_ext              LIKE TABLE OF bapiacextc WITH HEADER LINE,
+
    it_ext              LIKE TABLE OF bapiacextc WITH HEADER LINE,
    it_re                LIKE TABLE OF bapiacre09 WITH HEADER LINE,
+
    it_re                LIKE TABLE OF bapiacre09 WITH HEADER LINE,
    it_ext2              LIKE TABLE OF bapiparex  WITH HEADER LINE.
+
    it_ext2              LIKE TABLE OF bapiparex  WITH HEADER LINE.
+
 
  DATA: lt_p0001 TYPE TABLE OF p0001 WITH HEADER LINE,
+
  DATA: lt_p0001 TYPE TABLE OF p0001 WITH HEADER LINE,
        lt_p0185 TYPE TABLE OF p0185 WITH HEADER LINE.
+
        lt_p0185 TYPE TABLE OF p0185 WITH HEADER LINE.
+
 
  DATA: l_type LIKE ls_documentheader-obj_type,
+
  DATA: l_type LIKE ls_documentheader-obj_type,
        l_key  LIKE ls_documentheader-obj_key,
+
        l_key  LIKE ls_documentheader-obj_key,
        l_sys  LIKE ls_documentheader-obj_sys.
+
        l_sys  LIKE ls_documentheader-obj_sys.
  DATA l_pos TYPE posnr_acc.
+
  DATA l_pos TYPE posnr_acc.
  DATA l_amount  TYPE bapicurr-bapicurr.
+
  DATA l_amount  TYPE bapicurr-bapicurr.
+
 
  CALL FUNCTION 'HR_READ_INFOTYPE'
+
  CALL FUNCTION 'HR_READ_INFOTYPE'
    EXPORTING
+
    EXPORTING
      pernr          = p_pernr
+
      pernr          = p_pernr
      infty          = '0001'
+
      infty          = '0001'
* IMPORTING
+
* IMPORTING
*    SUBRC          =
+
*    SUBRC          =
    TABLES
+
    TABLES
      infty_tab      = lt_p0001
+
      infty_tab      = lt_p0001
    EXCEPTIONS
+
    EXCEPTIONS
      infty_not_found = 1
+
      infty_not_found = 1
      OTHERS          = 2.
+
      OTHERS          = 2.
  IF sy-subrc <> 0.
+
  IF sy-subrc <> 0.
* Implement suitable error handling here
+
* Implement suitable error handling here
  ENDIF.
+
  ENDIF.
+
 
  LOOP AT lt_p0001 WHERE begda <= p_endda
+
  LOOP AT lt_p0001 WHERE begda <= p_endda
                    AND endda >= p_begda.
+
                    AND endda >= p_begda.
  ENDLOOP.
+
  ENDLOOP.
+
 
*  CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
+
*  CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
*    IMPORTING
+
*    IMPORTING
*      own_logical_system = ls_documentheader-obj_sys.
+
*      own_logical_system = ls_documentheader-obj_sys.
*  ls_documentheader-obj_type  = 'BKPFF'.
+
*  ls_documentheader-obj_type  = 'BKPFF'.
*  ls_documentheader-obj_key = '$'.
+
*  ls_documentheader-obj_key = '$'.
  ls_documentheader-bus_act = 'RFBU'.
+
  ls_documentheader-bus_act = 'RFBU'.
*  ls_documentheader-obj_key    =
+
*  ls_documentheader-obj_key    =
  ls_documentheader-username  = sy-uname.
+
  ls_documentheader-username  = sy-uname.
  ls_documentheader-header_txt = 'Bonificación'.            "#EC NOTEXT
+
  ls_documentheader-header_txt = 'Bonificación'.            "#EC NOTEXT
* gd_documentheader-obj_key_r  =
+
* gd_documentheader-obj_key_r  =
* GD_DOCUMENTHEADER-reason_rev =
+
* GD_DOCUMENTHEADER-reason_rev =
  ls_documentheader-comp_code  = lt_p0001-bukrs.
+
  ls_documentheader-comp_code  = lt_p0001-bukrs.
* GD_DOCUMENTHEADER-AC_DOC_NO  =
+
* GD_DOCUMENTHEADER-AC_DOC_NO  =
  ls_documentheader-fisc_year  = sy-datum(4).
+
  ls_documentheader-fisc_year  = sy-datum(4).
  ls_documentheader-doc_date  = sy-datum.
+
  ls_documentheader-doc_date  = sy-datum.
  ls_documentheader-doc_type  = 'SA'.
+
  ls_documentheader-doc_type  = 'SA'.
  ls_documentheader-pstng_date = sy-datum.
+
  ls_documentheader-pstng_date = sy-datum.
* GD_DOCUMENTHEADER-TRANS_DATE =
+
* GD_DOCUMENTHEADER-TRANS_DATE =
* GD_DOCUMENTHEADER-VALUE_DATE =
+
* GD_DOCUMENTHEADER-VALUE_DATE =
  ls_documentheader-fis_period = sy-datum+4(2).
+
  ls_documentheader-fis_period = sy-datum+4(2).
* GD_DOCUMENTHEADER-DOC_TYPE  =
+
* GD_DOCUMENTHEADER-DOC_TYPE  =
* GD_DOCUMENTHEADER-REF_DOC_NO =
+
* GD_DOCUMENTHEADER-REF_DOC_NO =
* GD_DOCUMENTHEADER-COMPO_ACC  =
+
* GD_DOCUMENTHEADER-COMPO_ACC  =
  ls_documentheader-bus_act    = 'RFBU'.
+
  ls_documentheader-bus_act    = 'RFBU'.
*  l_documentheader-ref_doc_no  = '1'.
+
*  l_documentheader-ref_doc_no  = '1'.
+
 
  DATA l_valor(100).
+
  DATA l_valor(100).
+
 
  l_pos = l_pos + 1.
+
  l_pos = l_pos + 1.
  CLEAR: it_accountgl.
+
  CLEAR: it_accountgl.
+
 
  l_valor = '11111'.  "cuenta
+
  l_valor = '11111'.  "cuenta
  it_accountgl-itemno_acc  = l_pos.
+
  it_accountgl-itemno_acc  = l_pos.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
+
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
+
    EXPORTING
      input  = l_valor
+
      input  = l_valor
    IMPORTING
+
    IMPORTING
      output = it_accountgl-gl_account.
+
      output = it_accountgl-gl_account.
+
 
  CONCATENATE 'Bonificación Empleado' p_pernr INTO it_accountgl-item_text
+
  CONCATENATE 'Bonificación Empleado' p_pernr INTO it_accountgl-item_text
                                    SEPARATED BY space.
+
                                  SEPARATED BY space.
+
 
  it_accountgl-value_date  = sy-datum.
+
  it_accountgl-value_date  = sy-datum.
  APPEND it_accountgl.
+
  APPEND it_accountgl.
+
 
* 2da pos
+
* 2da pos
  CLEAR it_accountgl.
+
  CLEAR it_accountgl.
  l_pos = l_pos + 1.
+
  l_pos = l_pos + 1.
+
 
  l_valor = '22222000'. "N° cuenta
+
  l_valor = '22222000'. "N° cuenta
+
 
  it_accountgl-itemno_acc  = l_pos.
+
  it_accountgl-itemno_acc  = l_pos.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
+
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
+
    EXPORTING
      input  = l_valor
+
      input  = l_valor
    IMPORTING
+
    IMPORTING
      output = it_accountgl-gl_account.
+
      output = it_accountgl-gl_account.
+
 
  CONCATENATE 'Bonificación Empleado' p_pernr INTO it_accountgl-item_text.
+
  CONCATENATE 'Bonificación Empleado' p_pernr INTO it_accountgl-item_text.
+
 
  APPEND it_accountgl.
+
  APPEND it_accountgl.
+
 
* ver SAP Note 487722 - Using EXTENSION1 for accounting BAPIs
+
* ver SAP Note 487722 - Using EXTENSION1 for accounting BAPIs
* extension 1
+
* extension 1
  CLEAR it_ext.
+
  CLEAR it_ext.
  it_ext-field1 = it_accountgl-itemno_acc.
+
  it_ext-field1 = it_accountgl-itemno_acc.
  it_ext-field2 = 'PERNR'.
+
  it_ext-field2 = 'PERNR'.
  MOVE p_pernr TO it_ext-field3.
+
  MOVE p_pernr TO it_ext-field3.
  APPEND it_ext.
+
  APPEND it_ext.
+
 
* montos
+
* montos
  l_amount = p_monto.
+
  l_amount = p_monto.
+
 
  CALL FUNCTION 'BAPI_CURRENCY_CONV_TO_EXTERNAL'
+
  CALL FUNCTION 'BAPI_CURRENCY_CONV_TO_EXTERNAL'
    EXPORTING
+
    EXPORTING
      currency        = 'CLP'
+
      currency        = 'CLP'
      amount_internal = l_amount
+
      amount_internal = l_amount
    IMPORTING
+
    IMPORTING
      amount_external = l_amount.
+
      amount_external = l_amount.
+
 
  CLEAR it_currencyamount.
+
  CLEAR it_currencyamount.
  it_currencyamount-itemno_acc  = 1.
+
  it_currencyamount-itemno_acc  = 1.
*  it_currencyamount-curr_type    = '00'.
+
*  it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency    = 'CLP'.
+
  it_currencyamount-currency    = 'CLP'.
* IT_CURRENCYAMOUNT-CURRENCY_ISO =
+
* IT_CURRENCYAMOUNT-CURRENCY_ISO =
  it_currencyamount-amt_doccur  =  l_amount.
+
  it_currencyamount-amt_doccur  =  l_amount.
* IT_CURRENCYAMOUNT-EXCH_RATE    = .
+
* IT_CURRENCYAMOUNT-EXCH_RATE    = .
* it_currencyamount-amt_base    =
+
* it_currencyamount-amt_base    =
* IT_CURRENCYAMOUNT-DISC_BASE    =
+
* IT_CURRENCYAMOUNT-DISC_BASE    =
* it_currencyamount-exch_rate_v  =
+
* it_currencyamount-exch_rate_v  =
* it_currencyamount-disc_amt    =
+
* it_currencyamount-disc_amt    =
  APPEND it_currencyamount.
+
  APPEND it_currencyamount.
+
 
  CLEAR it_currencyamount.
+
  CLEAR it_currencyamount.
  it_currencyamount-itemno_acc  = 2.
+
  it_currencyamount-itemno_acc  = 2.
*it_currencyamount-curr_type    = '00'.
+
*it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency    = 'CLP'.
+
  it_currencyamount-currency    = 'CLP'.
* IT_CURRENCYAMOUNT-CURRENCY_ISO =
+
* IT_CURRENCYAMOUNT-CURRENCY_ISO =
  it_currencyamount-amt_doccur  = l_amount * -1.
+
  it_currencyamount-amt_doccur  = l_amount * -1.
* IT_CURRENCYAMOUNT-EXCH_RATE    =
+
* IT_CURRENCYAMOUNT-EXCH_RATE    =
*  it_currencyamount-amt_base    =
+
*  it_currencyamount-amt_base    =
* IT_CURRENCYAMOUNT-DISC_BASE    =
+
* IT_CURRENCYAMOUNT-DISC_BASE    =
*  it_currencyamount-exch_rate_v =
+
*  it_currencyamount-exch_rate_v =
* it_currencyamount-disc_amt    =
+
* it_currencyamount-disc_amt    =
  APPEND it_currencyamount.
+
  APPEND it_currencyamount.
+
 
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
+
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
+
    EXPORTING
      documentheader = ls_documentheader
+
      documentheader = ls_documentheader
*    customercpd    = ls_customercpd
+
*    customercpd    = ls_customercpd
*    contractheader = ls_fica_hd
+
*    contractheader = ls_fica_hd
    IMPORTING
+
    IMPORTING
      obj_type      = l_type
+
      obj_type      = l_type
      obj_key        = l_key
+
      obj_key        = l_key
      obj_sys        = l_sys
+
      obj_sys        = l_sys
    TABLES
+
    TABLES
      accountgl      = it_accountgl
+
      accountgl      = it_accountgl
*    accountreceivable = it_accountreceivable
+
*    accountreceivable = it_accountreceivable
      accountpayable = it_accountpayable
+
      accountpayable = it_accountpayable
*    accounttax    = it_accounttax
+
*    accounttax    = it_accounttax
      currencyamount = it_currencyamount
+
      currencyamount = it_currencyamount
*    criteria      = it_criteria
+
*    criteria      = it_criteria
*    valuefield    = it_valuefield
+
*    valuefield    = it_valuefield
      extension1    = it_ext
+
      extension1    = it_ext
      return        = it_return
+
      return        = it_return
*    paymentcard    = it_paymentcard
+
*    paymentcard    = it_paymentcard
*    contractitem  = it_fica_it
+
*    contractitem  = it_fica_it
*    extension2    = it_ext2
+
*    extension2    = it_ext2
*    realestate    = it_re
+
*    realestate    = it_re
    .
+
    .
+
 
  LOOP AT it_return INTO p_return WHERE type = 'E'.
+
  LOOP AT it_return INTO p_return WHERE type = 'E'.
  ENDLOOP.
+
  ENDLOOP.
  IF sy-subrc NE 0.
+
  IF sy-subrc NE 0.
    p_subrc = 0.
+
    p_subrc = 0.
  ELSE.
+
  ELSE.
    p_subrc = 1.
+
    p_subrc = 1.
+
 
    MESSAGE ID p_return-id  TYPE 'I' NUMBER p_return-number
+
    MESSAGE ID p_return-id  TYPE 'I' NUMBER p_return-number
          WITH p_return-message_v1
+
          WITH p_return-message_v1
          p_return-message_v2
+
          p_return-message_v2
          p_return-message_v3
+
          p_return-message_v3
          p_return-message_v4  DISPLAY LIKE 'E'.
+
          p_return-message_v4  DISPLAY LIKE 'E'.
  ENDIF.
+
  ENDIF.
+
 
ENDFORM.                    " PAGO_ANTICIPADO
+
ENDFORM.                    " PAGO_ANTICIPADO</nowiki>
  
 
==Notas BAPI FI==
 
==Notas BAPI FI==
 
===SAP Note 487722 - Using EXTENSION1 for accounting BAPIs===
 
===SAP Note 487722 - Using EXTENSION1 for accounting BAPIs===
  
====Implementing CMOD/SMOD exit ACBAPI01 with enhancement structure EXTENSION1, exit EXIT_SAPLACC4_001, include ZXACCU15====
+
===Implementing CMOD/SMOD exit ACBAPI01 with enhancement structure EXTENSION1, exit EXIT_SAPLACC4_001, include ZXACCU15===
====Implementing the Business Transaction Event (BTE, also OPEN FI) RWBAPI01 with enhancement structure EXTENSION1 at BAPI_ACC_DOCUMENT_POST====
+
===Implementing the Business Transaction Event (BTE, also OPEN FI) RWBAPI01 with enhancement structure EXTENSION1 at BAPI_ACC_DOCUMENT_POST===
  
Transaction FIBF:
+
Transaction FIBF:
 
#Call the menu path "Settings > Products -> ...of a customer" and create a product that mirrors the function which is to be mapped in the BTE.
 
#Call the menu path "Settings > Products -> ...of a customer" and create a product that mirrors the function which is to be mapped in the BTE.
 
#Create a function module that contains the same interface, such as example module SAMPLE_INTERFACE_RWBAPI01.
 
#Create a function module that contains the same interface, such as example module SAMPLE_INTERFACE_RWBAPI01.
Line 214: Line 214:
 
#Finally, activate the product you have created in the first step so that the module will run.
 
#Finally, activate the product you have created in the first step so that the module will run.
  
ejemplo para colocar Nº de Personal:
+
ejemplo para colocar Nº de Personal:
 
   
 
   
  * extension 1, ver funcion Z_SAMPLE_INTERFACE_RWBAPI01, BTE RWBAPI01 (tran. FIBF)
+
  <nowiki>* extension 1, ver funcion Z_SAMPLE_INTERFACE_RWBAPI01, BTE RWBAPI01 (tran. FIBF)
  CLEAR it_ext.
+
  CLEAR it_ext.
  it_ext-field1 = it_accountgl-itemno_acc.
+
  it_ext-field1 = it_accountgl-itemno_acc.
  it_ext-field2 = 'PERNR'.
+
  it_ext-field2 = 'PERNR'.
  MOVE p_pernr TO it_ext-field3.
+
  MOVE p_pernr TO it_ext-field3.
  APPEND it_ext.
+
  APPEND it_ext.
+
 
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
+
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
+
    EXPORTING
      documentheader    = ls_documentheader
+
      documentheader    = ls_documentheader
    IMPORTING
+
    IMPORTING
      obj_type          = l_type
+
      obj_type          = l_type
      obj_key          = l_key
+
      obj_key          = l_key
      obj_sys          = l_sys
+
      obj_sys          = l_sys
    TABLES
+
    TABLES
      accountgl        = it_accountgl
+
      accountgl        = it_accountgl
      accountpayable    = it_accountpayable
+
      accountpayable    = it_accountpayable
      currencyamount    = it_currencyamount
+
      currencyamount    = it_currencyamount
      extension1        = it_ext
+
      extension1        = it_ext
      return            = it_return
+
      return            = it_return
     .
+
    .
 +
 
 +
FUNCTION z_sample_interface_rwbapi01.
 +
*"----------------------------------------------------------------------
 +
*"*"Interfase local
 +
*"  TABLES
 +
*"      IT_ACCIT STRUCTURE  ACCIT
 +
*"      IT_ACCCR STRUCTURE  ACCCR
 +
*"      RETURN STRUCTURE  BAPIRET2
 +
*"      EXTENSION STRUCTURE  BAPIACEXTC
 +
*"     IT_ACCWT STRUCTURE  ACCIT_WT
 +
*"  CHANGING
 +
*"    VALUE(DOCUMENT_HEADER) LIKE  ACCHD STRUCTURE  ACCHD
 +
*"----------------------------------------------------------------------
 +
  DATA : ls_bapi_extension TYPE bapiacextc.
 +
  DATA ld_posnr TYPE posnr_acc.
 +
 
 +
  CLEAR: ls_bapi_extension.
 +
 
 +
  LOOP AT extension INTO ls_bapi_extension.
 +
    ld_posnr = ls_bapi_extension-field1.
 +
* evaluate fieldname
 +
    CASE ls_bapi_extension-field2.
 +
      WHEN 'PERNR'.
 +
* set document Status
 +
        READ TABLE it_accit
 +
            WITH KEY posnr = ld_posnr.
 +
        CHECK sy-subrc EQ 0.
 +
        it_accit-pernr = ls_bapi_extension-field3.
 +
        MODIFY it_accit INDEX sy-tabix.
 +
    ENDCASE.
 +
  ENDLOOP.
  
FUNCTION z_sample_interface_rwbapi01.
+
ENDFUNCTION.</nowiki>
*"----------------------------------------------------------------------
 
*"*"Interfase local
 
*"  TABLES
 
*"      IT_ACCIT STRUCTURE  ACCIT
 
*"      IT_ACCCR STRUCTURE  ACCCR
 
*"      RETURN STRUCTURE  BAPIRET2
 
*"      EXTENSION STRUCTURE  BAPIACEXTC
 
*"      IT_ACCWT STRUCTURE  ACCIT_WT
 
*"  CHANGING
 
*"    VALUE(DOCUMENT_HEADER) LIKE  ACCHD STRUCTURE  ACCHD
 
*"----------------------------------------------------------------------
 
  DATA : ls_bapi_extension TYPE bapiacextc.
 
  DATA ld_posnr TYPE posnr_acc.
 
 
  CLEAR: ls_bapi_extension.
 
 
  LOOP AT extension INTO ls_bapi_extension.
 
    ld_posnr = ls_bapi_extension-field1.
 
* evaluate fieldname
 
    CASE ls_bapi_extension-field2.
 
      WHEN 'PERNR'.
 
* set document Status
 
        READ TABLE it_accit
 
              WITH KEY posnr = ld_posnr.
 
        CHECK sy-subrc EQ 0.
 
        it_accit-pernr = ls_bapi_extension-field3.
 
        MODIFY it_accit INDEX sy-tabix.
 
    ENDCASE.
 
  ENDLOOP.
 
 
ENDFUNCTION.
 

Revision as of 20:51, 5 April 2020

BAPI_ACC_DOCUMENT_POST

  • Ejemplo con extensión
FORM document_post USING p_pernr
                         p_begda
                         p_endda
                         p_monto
                         p_modo
                CHANGING p_subrc
                         p_return TYPE bapiret2.
  DATA:
    ls_documentheader    LIKE bapiache09,
    l_customercpd        LIKE bapiacpa09,
    l_fica_hd            LIKE bapiaccahd,
    it_accountreceivable LIKE TABLE OF bapiacar09 WITH HEADER LINE,
    it_accountgl         LIKE TABLE OF bapiacgl09 WITH HEADER LINE,
    it_accounttax        LIKE TABLE OF bapiactx09 WITH HEADER LINE,
    it_criteria          LIKE TABLE OF bapiackec9 WITH HEADER LINE,
    it_valuefield        LIKE TABLE OF bapiackev9 WITH HEADER LINE,
    it_currencyamount    LIKE TABLE OF bapiaccr09 WITH HEADER LINE,
    it_return            LIKE TABLE OF bapiret2   WITH HEADER LINE,
    it_receivers         LIKE TABLE OF bdi_logsys WITH HEADER LINE,
    it_fica_it           LIKE TABLE OF bapiaccait WITH HEADER LINE,
    it_accountpayable    LIKE TABLE OF bapiacap09 WITH HEADER LINE,
    it_paymentcard       LIKE TABLE OF bapiacpc09 WITH HEADER LINE,
    it_ext               LIKE TABLE OF bapiacextc WITH HEADER LINE,
    it_re                LIKE TABLE OF bapiacre09 WITH HEADER LINE,
    it_ext2              LIKE TABLE OF bapiparex  WITH HEADER LINE.

  DATA: lt_p0001 TYPE TABLE OF p0001 WITH HEADER LINE,
        lt_p0185 TYPE TABLE OF p0185 WITH HEADER LINE.

  DATA: l_type LIKE ls_documentheader-obj_type,
        l_key  LIKE ls_documentheader-obj_key,
        l_sys  LIKE ls_documentheader-obj_sys.
  DATA l_pos TYPE posnr_acc.
  DATA l_amount  TYPE bapicurr-bapicurr.

  CALL FUNCTION 'HR_READ_INFOTYPE'
    EXPORTING
      pernr           = p_pernr
      infty           = '0001'
* IMPORTING
*     SUBRC           =
    TABLES
      infty_tab       = lt_p0001
    EXCEPTIONS
      infty_not_found = 1
      OTHERS          = 2.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

  LOOP AT lt_p0001 WHERE begda <= p_endda
                    AND endda >= p_begda.
  ENDLOOP.

*  CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
*    IMPORTING
*      own_logical_system = ls_documentheader-obj_sys.
*  ls_documentheader-obj_type   = 'BKPFF'.
*  ls_documentheader-obj_key = '$'.
  ls_documentheader-bus_act = 'RFBU'.
*  ls_documentheader-obj_key    =
  ls_documentheader-username   = sy-uname.
  ls_documentheader-header_txt = 'Bonificación'.            "#EC NOTEXT
* gd_documentheader-obj_key_r  =
* GD_DOCUMENTHEADER-reason_rev =
  ls_documentheader-comp_code  = lt_p0001-bukrs.
* GD_DOCUMENTHEADER-AC_DOC_NO  =
  ls_documentheader-fisc_year  = sy-datum(4).
  ls_documentheader-doc_date   = sy-datum.
  ls_documentheader-doc_type   = 'SA'.
  ls_documentheader-pstng_date = sy-datum.
* GD_DOCUMENTHEADER-TRANS_DATE =
* GD_DOCUMENTHEADER-VALUE_DATE =
  ls_documentheader-fis_period = sy-datum+4(2).
* GD_DOCUMENTHEADER-DOC_TYPE   =
* GD_DOCUMENTHEADER-REF_DOC_NO =
* GD_DOCUMENTHEADER-COMPO_ACC  =
  ls_documentheader-bus_act    = 'RFBU'.
*  l_documentheader-ref_doc_no  = '1'.

  DATA l_valor(100).

  l_pos = l_pos + 1.
  CLEAR: it_accountgl.

  l_valor = '11111'.  "cuenta
  it_accountgl-itemno_acc  = l_pos.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = l_valor
    IMPORTING
      output = it_accountgl-gl_account.

  CONCATENATE 'Bonificación Empleado' p_pernr INTO it_accountgl-item_text
                                   SEPARATED BY space.

  it_accountgl-value_date  = sy-datum.
  APPEND it_accountgl.

* 2da pos
  CLEAR it_accountgl.
  l_pos = l_pos + 1.

  l_valor = '22222000'. "N° cuenta

  it_accountgl-itemno_acc  = l_pos.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      input  = l_valor
    IMPORTING
      output = it_accountgl-gl_account.

  CONCATENATE 'Bonificación Empleado' p_pernr INTO it_accountgl-item_text.

  APPEND it_accountgl.

* ver SAP Note 487722 - Using EXTENSION1 for accounting BAPIs
* extension 1
  CLEAR it_ext.
  it_ext-field1 = it_accountgl-itemno_acc.
  it_ext-field2 = 'PERNR'.
  MOVE p_pernr TO it_ext-field3.
  APPEND it_ext.

* montos
  l_amount = p_monto.

  CALL FUNCTION 'BAPI_CURRENCY_CONV_TO_EXTERNAL'
    EXPORTING
      currency        = 'CLP'
      amount_internal = l_amount
    IMPORTING
      amount_external = l_amount.

  CLEAR it_currencyamount.
  it_currencyamount-itemno_acc   = 1.
*  it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency     = 'CLP'.
* IT_CURRENCYAMOUNT-CURRENCY_ISO =
  it_currencyamount-amt_doccur   =  l_amount.
* IT_CURRENCYAMOUNT-EXCH_RATE    = .
* it_currencyamount-amt_base     =
* IT_CURRENCYAMOUNT-DISC_BASE    =
* it_currencyamount-exch_rate_v  =
* it_currencyamount-disc_amt     =
  APPEND it_currencyamount.

  CLEAR it_currencyamount.
  it_currencyamount-itemno_acc   = 2.
*it_currencyamount-curr_type    = '00'.
  it_currencyamount-currency     = 'CLP'.
* IT_CURRENCYAMOUNT-CURRENCY_ISO =
  it_currencyamount-amt_doccur   = l_amount * -1.
* IT_CURRENCYAMOUNT-EXCH_RATE    =
*  it_currencyamount-amt_base    =
* IT_CURRENCYAMOUNT-DISC_BASE    =
*  it_currencyamount-exch_rate_v =
* it_currencyamount-disc_amt     =
  APPEND it_currencyamount.

  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
      documentheader = ls_documentheader
*     customercpd    = ls_customercpd
*     contractheader = ls_fica_hd
    IMPORTING
      obj_type       = l_type
      obj_key        = l_key
      obj_sys        = l_sys
    TABLES
      accountgl      = it_accountgl
*     accountreceivable = it_accountreceivable
      accountpayable = it_accountpayable
*     accounttax     = it_accounttax
      currencyamount = it_currencyamount
*     criteria       = it_criteria
*     valuefield     = it_valuefield
      extension1     = it_ext
      return         = it_return
*     paymentcard    = it_paymentcard
*     contractitem   = it_fica_it
*     extension2     = it_ext2
*     realestate     = it_re
    .

  LOOP AT it_return INTO p_return WHERE type = 'E'.
  ENDLOOP.
  IF sy-subrc NE 0.
    p_subrc = 0.
  ELSE.
    p_subrc = 1.

    MESSAGE ID p_return-id  TYPE 'I' NUMBER p_return-number
          WITH p_return-message_v1
          p_return-message_v2
          p_return-message_v3
          p_return-message_v4  DISPLAY LIKE 'E'.
  ENDIF.

ENDFORM.                    " PAGO_ANTICIPADO

Notas BAPI FI

SAP Note 487722 - Using EXTENSION1 for accounting BAPIs

Implementing CMOD/SMOD exit ACBAPI01 with enhancement structure EXTENSION1, exit EXIT_SAPLACC4_001, include ZXACCU15

Implementing the Business Transaction Event (BTE, also OPEN FI) RWBAPI01 with enhancement structure EXTENSION1 at BAPI_ACC_DOCUMENT_POST

Transaction FIBF:

  1. Call the menu path "Settings > Products -> ...of a customer" and create a product that mirrors the function which is to be mapped in the BTE.
  2. Create a function module that contains the same interface, such as example module SAMPLE_INTERFACE_RWBAPI01.
  3. Call menu path "Settings -> Process function modules > ...of a customer" enter process = RWBAPI01, the function module created and the product.
  4. Finally, activate the product you have created in the first step so that the module will run.

ejemplo para colocar Nº de Personal:

* extension 1, ver funcion Z_SAMPLE_INTERFACE_RWBAPI01, BTE RWBAPI01 (tran. FIBF)
  CLEAR it_ext.
  it_ext-field1 = it_accountgl-itemno_acc.
  it_ext-field2 = 'PERNR'.
  MOVE p_pernr TO it_ext-field3.
  APPEND it_ext.

  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
      documentheader    = ls_documentheader
    IMPORTING
      obj_type          = l_type
      obj_key           = l_key
      obj_sys           = l_sys
    TABLES
      accountgl         = it_accountgl
      accountpayable    = it_accountpayable
      currencyamount    = it_currencyamount
      extension1        = it_ext
      return            = it_return
    .

FUNCTION z_sample_interface_rwbapi01.
*"----------------------------------------------------------------------
*"*"Interfase local
*"  TABLES
*"      IT_ACCIT STRUCTURE  ACCIT
*"      IT_ACCCR STRUCTURE  ACCCR
*"      RETURN STRUCTURE  BAPIRET2
*"      EXTENSION STRUCTURE  BAPIACEXTC
*"      IT_ACCWT STRUCTURE  ACCIT_WT
*"  CHANGING
*"     VALUE(DOCUMENT_HEADER) LIKE  ACCHD STRUCTURE  ACCHD
*"----------------------------------------------------------------------
  DATA : ls_bapi_extension TYPE bapiacextc.
  DATA ld_posnr TYPE posnr_acc.

  CLEAR: ls_bapi_extension.

  LOOP AT extension INTO ls_bapi_extension.
    ld_posnr = ls_bapi_extension-field1.
* evaluate fieldname
    CASE ls_bapi_extension-field2.
      WHEN 'PERNR'.
* set document Status
        READ TABLE it_accit
             WITH KEY posnr = ld_posnr.
        CHECK sy-subrc EQ 0.
        it_accit-pernr = ls_bapi_extension-field3.
        MODIFY it_accit INDEX sy-tabix.
    ENDCASE.
  ENDLOOP.

ENDFUNCTION.