10-18-2007 2:50 AM
Hi gurus,
Can you give me a sample code in which we have to post an FI document with CO-PA data using BAPI_ACC_DOCUMENT_POST. Currently I'm having trouble posting a document with profit segment.
Thank you very much
Andre
10-18-2007 2:55 AM
Check this link -
http://www.sapfans.com/forums/viewtopic.php?p=76232&sid=b6519d31b5097f49dc303d03b35eed43
http://www.sapfans.com/forums/viewtopic.php?t=137643&highlight=bapiaccdocumentpost
It also tells that the documentation is not clear so which all errors you can avoid.
Sample code -
REFRESH : i_accountgl,
i_accountreceivable,
i_currencyamount,
i_return.
CLEAR : wa_documentheader,
wa_accountgl,
wa_accountreceivable,
wa_currencyamount,
wa_return,
g_shipdate,
g_matdate,
g_amount.
*changing the format of the shipment date from MM/DD/YYYY TO YYYYMMDD
CONCATENATE p_wa_item-shipdate+6(4)
p_wa_item-shipdate+0(2)
p_wa_item-shipdate+3(2)
INTO g_shipdate.
*changing the format of the loan maturity date from MM/DD/YYYY TO YYYYMMDD
CONCATENATE p_wa_item-matdate+6(4)
p_wa_item-matdate+0(2)
p_wa_item-matdate+3(2)
INTO g_matdate.
*changing the format of the due date from MM/DD/YYYY TO YYYY.MM.DD
CONCATENATE p_wa_item-duedate+6(4)
c_dot
p_wa_item-duedate+0(2)
c_dot
p_wa_item-duedate+3(2)
INTO p_wa_item-duedate.
*assignment of credit/debit indicator and document type(invoice/credit memo)
IF p_wa_item-amount LT 0.
g_credeb_ind = c_debit -
S.
g_doctyp = c_doctypcreditmemo DG.
ELSE.
g_credeb_ind = c_credit H.
g_doctyp = c_doctypinvoice. DR
ENDIF.
wa_documentheader-bus_act = c_busact. RFBU
wa_documentheader-username = sy-uname.
wa_documentheader-comp_code = p_wa_item-compcode.
wa_documentheader-doc_date = g_shipdate.
wa_documentheader-pstng_date = p_posdat.
wa_documentheader-ref_doc_no = p_wa_item-docnum.
wa_documentheader-doc_type = g_doctyp.
wa_accountgl-itemno_acc = c_glitemno. 2
wa_accountgl-gl_account = p_saknr.
wa_accountgl-comp_code = p_wa_item-compcode.
wa_accountgl-de_cre_ind = g_credeb_ind.
APPEND wa_accountgl TO i_accountgl.
wa_accountreceivable-itemno_acc = c_hditemno. 1
wa_accountreceivable-customer = p_kunnr.
wa_accountreceivable-comp_code = p_wa_item-compcode.
wa_accountreceivable-bline_date = g_matdate.
wa_accountreceivable-pmnttrms = p_zterm.
wa_accountreceivable-pmnt_block = c_blockpayment.
APPEND wa_accountreceivable TO i_accountreceivable.
wa_currencyamount-itemno_acc = c_hditemno. 1
wa_currencyamount-curr_type = c_currtyp. 00
wa_currencyamount-amt_doccur = p_wa_item-amount.
wa_currencyamount-currency = p_wa_item-currency.
APPEND wa_currencyamount TO i_currencyamount.
g_amount = p_wa_item-amount.
IF p_wa_item-amount GT 0.
CONCATENATE c_minus p_wa_item-amount INTO p_wa_item-amount.
CONDENSE p_wa_item-amount NO-GAPS.
ELSE.
REPLACE FIRST OCCURRENCE OF c_minus IN p_wa_item-amount WITH space.
ENDIF.
wa_currencyamount-itemno_acc = c_glitemno.
wa_currencyamount-curr_type = c_currtyp.
wa_currencyamount-amt_doccur = p_wa_item-amount.
wa_currencyamount-currency = p_wa_item-currency.
APPEND wa_currencyamount TO i_currencyamount.
*bapi for posting the invoice and credit memo documents
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = wa_documentheader
TABLES
accountgl = i_accountgl
accountreceivable = i_accountreceivable
currencyamount = i_currencyamount
return = i_return.
for more information:
ashish
Message was edited by:
Ashish Gundawar
10-18-2007 3:10 AM
Hi Ashish,
Do have an example wherein you must post an FI document having CO-PA (Profit Segment Data). Currently I am not successful posting it. I've filled up the CRITERIA table of the BAPI.
Regards,
Andre
10-18-2007 3:19 AM
Check this link -
It might help. Code is at the end.
ashish
10-18-2007 3:48 AM
Hi ashish ,
I still cant find any sample regarding posting of FI Document with CO-PA.
Regards
Andre
10-18-2007 3:53 AM
10-18-2007 4:13 AM
Thanks anyway. I really appreciate your help.
Regards,
Andre
10-18-2007 7:12 AM
10-18-2007 9:21 AM
Hi,
For a posting to CO-PA you have to assign a tables containing data for
characteristics and value fields in the parameters CRITERIA and
VALUEFIELD of function BAPI_ACC_DOCUMENT_POST
regards
Waman
10-18-2007 9:49 AM
Hi,
Here is a sample program which posts FI document along with CO-PA characteristics.
REPORT ZRBC060 .
*
DATA: doc_header LIKE BAPIACHE09,
criteria LIKE BAPIACKEC9 OCCURS 0 WITH HEADER LINE,
doc_item LIKE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
doc_values LIKE BAPIACCR09 OCCURS 0 WITH HEADER LINE,
return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
extension1 like BAPIACEXTC occurs 0 with header line,
obj_type LIKE bapiache08-obj_type,
obj_key LIKE bapiache02-obj_key,
obj_sys LIKE bapiache02-obj_sys,
docnum LIKE bkpf-belnr.
*
* Fill Document Header
doc_header-bus_act = 'RFBU'.
*doc_header-obj_type = 'BKPFF'.
*doc_header-obj_key = 'AAAABBBB'.
*doc_header-obj_sys = 'NLD220'.
doc_header-username = sy-uname.
doc_header-header_txt = 'TEST BOC BAPI POSTING'.
doc_header-comp_code = 'IN10'.
doc_header-doc_date = '20060127'.
doc_header-pstng_date = sy-datlo.
doc_header-doc_type = 'SA'.
* Fill Line 1 of Document Item
doc_item-itemno_acc = '1'.
doc_item-gl_account = '0000500001'.
doc_item-pstng_date = sy-datum.
doc_item-item_text = 'TEST POSTING DEBIT ITEM'.
doc_item-costcenter = ''.
doc_item-quantity = '1'.
doc_item-base_uom = 'ST'.
*doc_item-stat_con = 'X'.
*doc_item-orderid = 'M5253'.
*_____________
*doc_item-comp_code = 'IN01'.
*_______________
APPEND doc_item.
CLEAR doc_item.
* Fill Line 2 of Document Item
doc_item-itemno_acc = '2'.
doc_item-gl_account = '0000210072'.
doc_item-pstng_date = sy-datlo.
doc_item-item_text = 'TEST POSTING CREDIT ITEM'.
*doc_item-stat_con = 'X'.
*doc_item-costcenter = '0000201681'.
*_______________
*doc_item-comp_code = 'IN01'.
*_______________
APPEND doc_item.
CLEAR doc_item.
* Fill Line 1 of Document Value.
doc_values-itemno_acc = '1'.
doc_values-currency_iso = 'INR'.
doc_values-amt_doccur = '0.02-'.
APPEND doc_values.
CLEAR doc_values.
* Fill Line 2 of Document Value
doc_values-itemno_acc = '2'.
doc_values-currency_iso = 'INR'.
doc_values-amt_doccur = '0.02'.
APPEND doc_values.
CLEAR doc_values.
* Add tax code in extension1 table.
extension1-field1 = 'BAPI CALL'.
APPEND EXTENSION1.
*
* Fill CRITERIA for CO-PA
*
refresh criteria.
criteria-ITEMNO_ACC = '1'.
criteria-FIELDNAME = 'ARTNR'.
criteria-CHARACTER = '000000000001312251'.
Append criteria.
criteria-ITEMNO_ACC = '1'.
criteria-FIELDNAME = 'WERKS'.
criteria-CHARACTER = 'IN91'.
Append criteria.
criteria-ITEMNO_ACC = '1'.
criteria-FIELDNAME = 'KNDNR'.
criteria-CHARACTER = '0000000016'.
Append criteria.
criteria-ITEMNO_ACC = '1'.
criteria-FIELDNAME = 'FKART'.
criteria-CHARACTER = 'ZIN2'.
Append criteria.
criteria-ITEMNO_ACC = '1'.
criteria-FIELDNAME = 'KAUFN'.
criteria-CHARACTER = '0000000633'.
Append criteria.
criteria-ITEMNO_ACC = '1'.
criteria-FIELDNAME = 'KDPOS'.
criteria-CHARACTER = '000010'.
Append criteria.
*criteria-ITEMNO_ACC = '1'.
*criteria-FIELDNAME = 'VKGRP'.
*criteria-CHARACTER = '009'.
**Append criteria.
*
* All tables filled - now call BAPI.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = doc_header
IMPORTING
OBJ_TYPE = doc_header-obj_type
OBJ_KEY = doc_header-obj_key
OBJ_SYS = doc_header-obj_sys
TABLES
criteria = criteria
accountgl = doc_item
currencyamount = doc_values
return = return
EXTENSION1 = EXTENSION1.
*
LOOP AT return WHERE type = 'E'.
EXIT.
ENDLOOP.
*
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = doc_header
IMPORTING
OBJ_TYPE = doc_header-obj_type
OBJ_KEY = doc_header-obj_key
OBJ_SYS = doc_header-obj_sys
TABLES
criteria = criteria
accountgl = doc_item
currencyamount = doc_values
return = return
EXTENSION1 = EXTENSION1.
LOOP AT return WHERE type = 'E'.
EXIT.
ENDLOOP.
IF sy-subrc EQ 0.
WRITE: / 'BAPI call failed - debug and fix!'.
ELSE.
CLEAR return.
REFRESH return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
IMPORTING
return = return.
WRITE: / 'BAPI call worked!!'.
WRITE: / doc_header-obj_key, ' posted'.
ENDIF.
I hope this helps,
Regards
Raju chitale
10-22-2007 7:01 AM
Hi Raju,
I am encounterin these problems when I use the BAPI.
Error in document: BKPFF $ SFDCLNT100
Complete PA transfer structure FI
Profitability segment being derived again
Regards
Andre
02-23-2023 7:53 AM
Same procedure updated as per 23-Feb-23
*&---------------------------------------------------------------------*
*& Report ZAM_BAPI_JOURNALENTRY
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZAM_BAPI_JOURNALENTRY.
DATA: doc_header LIKE BAPIACHE09,
* criteria LIKE BAPIACKEC9 OCCURS 0 WITH HEADER LINE,
doc_item LIKE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
doc_values LIKE BAPIACCR09 OCCURS 0 WITH HEADER LINE,
return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
* extension1 like BAPIACEXTC occurs 0 with header line,
obj_type LIKE bapiache08-obj_type,
obj_key TYPE BAPIACHE09-OBJ_KEY,
obj_sys LIKE bapiache02-obj_sys,
docnum LIKE bkpf-belnr.
*
* Fill Document Header
doc_header-bus_act = 'RFBU'.
*doc_header-obj_type = 'BKPFF'.
*doc_header-obj_key = 'AAAABBBB'.
*doc_header-obj_sys = 'NLD220'.
doc_header-username = sy-uname.
doc_header-header_txt = 'AK TEST BOC BAPI POSTING 01'.
doc_header-comp_code = '1000'.
doc_header-doc_date = '20230221'.
doc_header-pstng_date = sy-datlo.
doc_header-doc_type = 'SA'.
* Fill Line 1 of Document Item
doc_item-itemno_acc = '1'.
doc_item-gl_account = '5410000004'.
doc_item-pstng_date = sy-datum.
doc_item-item_text = 'TEST POSTING DEBIT ITEM'.
doc_item-costcenter = '1000001001'.
*doc_item-quantity = '1'.
*doc_item-base_uom = 'ST'.
*doc_item-stat_con = 'X'.
*doc_item-orderid = 'M5253'.
*_____________
*doc_item-comp_code = 'IN01'.
*_______________
APPEND doc_item.
CLEAR doc_item.
* Fill Line 2 of Document Item
doc_item-itemno_acc = '2'.
doc_item-gl_account = '3010000001'.
doc_item-pstng_date = sy-datlo.
doc_item-item_text = 'TEST POSTING CREDIT ITEM'.
*doc_item-stat_con = 'X'.
*doc_item-costcenter = '0000201681'.
*_______________
*doc_item-comp_code = 'IN01'.
*_______________
APPEND doc_item.
CLEAR doc_item.
* Fill Line 1 of Document Value.
doc_values-itemno_acc = '1'.
doc_values-currency_iso = 'PKR'.
doc_values-amt_doccur = '10'.
APPEND doc_values.
CLEAR doc_values.
* Fill Line 2 of Document Value
doc_values-itemno_acc = '2'.
doc_values-currency_iso = 'PKR'.
doc_values-amt_doccur = '10-'.
APPEND doc_values.
CLEAR doc_values.
* Add tax code in extension1 table.
*extension1-field1 = 'BAPI CALL'.
*APPEND EXTENSION1.
**
** Fill CRITERIA for CO-PA
**
*refresh criteria.
*criteria-ITEMNO_ACC = '1'.
*criteria-FIELDNAME = 'ARTNR'.
*criteria-CHARACTER = '000000000001312251'.
*Append criteria.
*criteria-ITEMNO_ACC = '1'.
*criteria-FIELDNAME = 'WERKS'.
*criteria-CHARACTER = 'IN91'.
*Append criteria.
*criteria-ITEMNO_ACC = '1'.
*criteria-FIELDNAME = 'KNDNR'.
*criteria-CHARACTER = '0000000016'.
*Append criteria.
*criteria-ITEMNO_ACC = '1'.
*criteria-FIELDNAME = 'FKART'.
*criteria-CHARACTER = 'ZIN2'.
*Append criteria.
*criteria-ITEMNO_ACC = '1'.
*criteria-FIELDNAME = 'KAUFN'.
*criteria-CHARACTER = '0000000633'.
*Append criteria.
*criteria-ITEMNO_ACC = '1'.
*criteria-FIELDNAME = 'KDPOS'.
*criteria-CHARACTER = '000010'.
*Append criteria.
**criteria-ITEMNO_ACC = '1'.
**criteria-FIELDNAME = 'VKGRP'.
**criteria-CHARACTER = '009'.
***Append criteria.
*
* All tables filled - now call BAPI.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = doc_header
* CUSTOMERCPD =
* CONTRACTHEADER =
tables
ACCOUNTGL = doc_item
* ACCOUNTRECEIVABLE =
* ACCOUNTPAYABLE =
* ACCOUNTTAX =
CURRENCYAMOUNT = doc_values
* CRITERIA =
* VALUEFIELD =
* EXTENSION1 =
return = return
* PAYMENTCARD =
* CONTRACTITEM =
* EXTENSION2 =
* REALESTATE =
* ACCOUNTWT =
.
LOOP AT return WHERE type = 'E'.
EXIT.
ENDLOOP.
"call BAPI to post the document
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = doc_header
IMPORTING
* OBJ_TYPE = doc_header-obj_type
OBJ_KEY = doc_header-obj_key
* OBJ_SYS = doc_header-obj_sys
TABLES
* criteria = criteria
accountgl = doc_item
currencyamount = doc_values
return = return
* EXTENSION1 = EXTENSION1
.
LOOP AT return WHERE type = 'E'.
EXIT.
ENDLOOP.
IF sy-subrc EQ 0.
WRITE: / 'BAPI call failed - debug and fix!'.
ELSE.
CLEAR return.
REFRESH return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
IMPORTING
return = return.
WRITE: / 'BAPI call worked!!'.
WRITE: / doc_header-obj_key, ' posted'.
ENDIF.