Skip to Content
author's profile photo Former Member
Former Member

Sample code for BAPI_ACC_DOCUMENT_POST - for creating Credit Memo(FB75)

Hello All,

I need you expertise... I'm trying to create Credit memo (FB75) using BAPI_ACC_DOCUMENT_POST. Please tell me if if using the parameters correctly or if I'm missing some thing ?

I got this error - FI/CO interface: Object type FB75 not defined

Here is the code i'm using

*
* Fill Document Header
doc_header-bus_act = 'RFBU'.
doc_header-obj_type = 'FB75'.
doc_header-obj_key = '1600000001'.
doc_header-obj_sys = sy-sysid.
doc_header-username = sy-uname.
doc_header-header_txt = 'CREDIT MEMO'.
doc_header-comp_code = 'BP01'.
doc_header-doc_date = '20100513'.
doc_header-pstng_date = '20100513'.
doc_header-doc_type = 'DG'.

* Fill Line 1 of Document Item
doc_item-itemno_acc = '1'.
doc_item-gl_account = '0000630010'.
doc_item-pstng_date = '20100513'.
doc_item-item_text = 'TEST'.
doc_item-costcenter = '0000001101'.
doc_item-quantity = '1'.
doc_item-base_uom = 'ST'.
APPEND doc_item.
CLEAR doc_item.

* Fill Line 1 of Document Value.
doc_values-itemno_acc = '1'.
doc_values-currency_iso = 'MXP'.
doc_values-amt_doccur = '10.00'.
APPEND doc_values.
CLEAR doc_values.

* Add tax code in extension1 table.
extension1-field1 = 'BAPI CALL'.
APPEND EXTENSION1.
**
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.

Note: There are few posts with similar question, but none of them had answer, so I'm posting this question.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on May 13, 2015 at 09:01 PM

    You don't use the transaction here; use the reference transaction. For GL postings, it is BKPF.

    Rob

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 14, 2015 at 05:34 AM

    You can avoid passing that information, instead you can change the posting key in the exit with the help of the Extension table.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 14, 2015 at 09:14 AM

    Hi Ram,

    Also you have to call this fm 'BAPI_TRANSACTION_COMMIT' in the end to save it.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    *EXPORTING

    * WAIT =

    IMPORTING

    return = return2.

    Where is customer information data?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 15, 2015 at 08:11 PM

    Here is the updated code.


    REPORT ZCRD.

    DATA: DOC_HEADER LIKE BAPIACHE09,
    CRITERIA LIKE BAPIACKEC9 OCCURS 0 WITH HEADER LINE,
    DOC_ITEM LIKE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
    DOC_CUST LIKE BAPIACAR09 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-OBJ_TYPE = 'IDOC'.
    DOC_HEADER-OBJ_KEY = '1600000001BP012010'.
    DOC_HEADER-OBJ_SYS = SY-SYSID.
    DOC_HEADER-BUS_ACT = 'RFBU'.
    DOC_HEADER-USERNAME = SY-UNAME.
    DOC_HEADER-HEADER_TXT = 'CREDIT MEMO'.
    DOC_HEADER-COMP_CODE = 'BP01'.
    DOC_HEADER-DOC_DATE = '20100513'.
    DOC_HEADER-PSTNG_DATE = '20100513'.
    DOC_HEADER-TRANS_DATE = SY-DATUM.
    DOC_HEADER-FISC_YEAR = '2010'.
    DOC_HEADER-FIS_PERIOD = '05'.
    DOC_HEADER-DOC_TYPE = 'DG'.
    DOC_HEADER-REF_DOC_NO = 'CONTRACT'.

    * Fill Line 1 of Document Item
    DOC_ITEM-ITEMNO_ACC = '10'.
    DOC_ITEM-GL_ACCOUNT = '0000630010'.
    DOC_ITEM-REF_KEY_1 = 'CONTRACT'.
    DOC_ITEM-PSTNG_DATE = '20100513'.
    DOC_ITEM-ITEM_TEXT = 'TEST'.
    DOC_ITEM-COSTCENTER = '0000001101'.
    DOC_ITEM-QUANTITY = '1'.
    DOC_ITEM-BASE_UOM = 'ST'.
    APPEND DOC_ITEM.
    CLEAR DOC_ITEM.

    * Fill line 1 ACCOUNTRECEIVABLE
    DOC_CUST-ITEMNO_ACC = '20'.
    DOC_CUST-CUSTOMER = '0000000401'.
    DOC_CUST-GL_ACCOUNT = '0000121001'.
    DOC_CUST-REF_KEY_1 = 'CONTRACT'.
    DOC_CUST-COMP_CODE = 'BP01'.
    *DOC_CUST-PYMT_CUR = 'MXP'.
    DOC_CUST-PYMT_CUR_ISO = 'MXP'.
    DOC_CUST-PYMT_AMT = '10.00'.
    DOC_CUST-ALLOC_NMBR = '0000001101'.
    APPEND DOC_CUST.
    CLEAR DOC_CUST.

    * Fill Line 1 of Document Value.
    DOC_VALUES-ITEMNO_ACC = '10'.
    *DOC_VALUES-CURRENCY = 'MXP'.
    DOC_VALUES-CURRENCY_ISO = 'MXP'.
    DOC_VALUES-AMT_DOCCUR = '-10.00'.
    APPEND DOC_VALUES.
    CLEAR DOC_VALUES.

    DOC_VALUES-ITEMNO_ACC = '20'.
    *DOC_VALUES-CURRENCY = 'MXP'.
    DOC_VALUES-CURRENCY_ISO = 'MXP'.
    DOC_VALUES-AMT_DOCCUR = '10.00'.
    APPEND DOC_VALUES.
    CLEAR DOC_VALUES.

    * Add tax code in extension1 table.
    EXTENSION1-FIELD1 = 'BAPI CALL'.
    APPEND EXTENSION1.
    **
    **
    **
    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
    ACCOUNTRECEIVABLE = DOC_CUST
    CURRENCYAMOUNT = DOC_VALUES
    RETURN = RETURN
    EXTENSION1 = EXTENSION1.
    BREAK-POINT.
    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.