Error RW022 en BAPI_ACC_DOCUMENT_POST o BAPI_ACC_DOCUMENT_CHECK
Caso: Al ejecutar la BAPI BAPI_ACC_DOCUMENT_CHECK o la BAPI_ACC_DOCUMENT_POST se genera el error RW022 “Interfase RW: Saldo en moneda de transacción” y el monto de diferencia es de un monto mínimo (ejemplo, 1 o 2 pesos chilenos –CLP-). También aparece como cabecera el error RW609: Error en el documento: BKPFF ….
Solución: Luego de dar varias vueltas al tema y dado que estaba trabajando con una moneda distinta a la moneda de la sociedad, el problema era al traspasar los valores al campo AMT_DOCCUR. Utilicé entonces la BAPI_CURRENCY_CONV_TO_EXTERNAL y funcionó OK.
CALL FUNCTION ‘BAPI_CURRENCY_CONV_TO_EXTERNAL’
EXPORTING
currency = wa_currencyamount-currency
amount_internal = wa_datos-monto_prov
IMPORTING
amount_external = wa_currencyamount-amt_doccur.
Va el código:
DATA: wa_documentheader TYPE bapiache09, it_accountgl TYPE STANDARD TABLE OF bapiacgl09, wa_accountgl TYPE bapiacgl09, it_currencyamount TYPE STANDARD TABLE OF bapiaccr09, wa_currencyamount TYPE bapiaccr09, it_return TYPE STANDARD TABLE OF bapiret2, wa_return TYPE bapiret2, lw_error TYPE ty_error, lv_posnr_acc TYPE posnr_acc, wa_datos TYPE ty_datos, lv_gl_account TYPE hkont, lv_importe TYPE bapidoccur. * Clear de tablas internas REFRESH: it_accountgl, it_currencyamount, it_return. * Cabecera del documento CLEAR: wa_documentheader. MOVE sy-uname TO wa_documentheader-username. " Usuario MOVE p_bukrs TO wa_documentheader-comp_code. " Sociedad MOVE pa_stida TO wa_documentheader-doc_date. " Fecha del documento MOVE p_fecha_doc TO wa_documentheader-pstng_date. " Fecha de contabilización MOVE 'AB' TO wa_documentheader-doc_type. " Tipo de documento MOVE p_texto_periodo TO wa_documentheader-header_txt. " Texto cabecera documento MOVE 'RFBU' TO wa_documentheader-bus_act. " Operación empresarial lv_posnr_acc = '0000000000'. " Inicializo la Posición * GL Account 001 CLEAR: lv_importe. LOOP AT pt_datos INTO wa_datos. CLEAR : wa_accountgl, wa_currencyamount. ADD 1 TO lv_posnr_acc. MOVE lv_posnr_acc TO wa_accountgl-itemno_acc. " Line Item No CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = pa_gast " Cuenta de gasto IMPORTING output = lv_gl_account. MOVE lv_gl_account TO wa_accountgl-gl_account. " Cuenta contable - G/L Account MOVE p_texto_periodo TO wa_accountgl-item_text. " Texto del ítem MOVE p_bukrs TO wa_accountgl-comp_code. " Sociedad MOVE wa_datos-gsber TO wa_accountgl-bus_area. " División MOVE wa_datos-kostl TO wa_accountgl-costcenter. " Centro de costo = CeBe wa_accountgl-acct_type = 'S'. APPEND wa_accountgl TO it_accountgl. * Fill Currency Line item MOVE lv_posnr_acc TO wa_currencyamount-itemno_acc. " Line Item No * curr_type ==> 00 Moneda del documento /// curr_type ==> 10 Moneda de sociedad MOVE '00' TO wa_currencyamount-curr_type. " Currency Type MOVE p_moneda TO wa_currencyamount-currency . " Moneda * wa_currencyamount-amt_doccur = wa_datos-monto_prov. " Aquí estaba el error, para CLP no funcionaba CALL FUNCTION 'BAPI_CURRENCY_CONV_TO_EXTERNAL' EXPORTING currency = wa_currencyamount-currency amount_internal = wa_datos-monto_prov IMPORTING amount_external = wa_currencyamount-amt_doccur. ADD wa_currencyamount-amt_doccur TO lv_importe. " MOD Q_EPURICELLI - 21.04.2016 - APPEND wa_currencyamount TO it_currencyamount. ENDLOOP. * GL Account 002 CLEAR : wa_accountgl, wa_currencyamount. ADD 1 TO lv_posnr_acc. MOVE lv_posnr_acc TO wa_accountgl-itemno_acc. " Line Item No CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = pa_prov " Cuenta de provisión IMPORTING output = lv_gl_account. MOVE lv_gl_account TO wa_accountgl-gl_account. " Cuenta contable - G/L Account MOVE p_bukrs TO wa_accountgl-comp_code. " Sociedad MOVE 'Prov.incobrables' TO wa_accountgl-item_text. " Texto del ítem wa_accountgl-acct_type = 'S'. APPEND wa_accountgl TO it_accountgl. * Fill Currency Line item MOVE lv_posnr_acc TO wa_currencyamount-itemno_acc. " Line Item No * curr_type ==> 00 Moneda del documento // curr_type ==> 10 Moneda de sociedad MOVE '00' TO wa_currencyamount-curr_type. " Currency Type MOVE p_moneda TO wa_currencyamount-currency . " Moneda lv_importe = lv_importe * -1. MOVE lv_importe TO wa_currencyamount-amt_doccur. " Monto APPEND wa_currencyamount TO it_currencyamount. * Llamado a la BAPI MODO TEST CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK' EXPORTING documentheader = wa_documentheader TABLES accountgl = it_accountgl currencyamount = it_currencyamount return = it_return. LOOP AT it_return INTO wa_return WHERE type = 'E'. p_error = 'X'. CONCATENATE 'E' wa_return-id wa_return-number INTO lw_error-error. lw_error-mensaje = wa_return-message. APPEND lw_error TO pt_error. ENDLOOP.