Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI FUNCTION MODULE BAPI_ACC_DOCUMENT_POST : How to give posting keys?

Former Member
0 Kudos

Hi ,

i am using BAPI_ACC_DOCUMENT_POST to post accounting document. This accounting document is used to post amount from reconcilation account to bank GL account.the table parameter am using is ACCOUNTGL (in the function module)Now i want to give posting keys to the function module parameter. can anyone please guide me how to give posting keys?

Edited by: Santhosh Kumar Cheekoti on Dec 18, 2008 7:48 AM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

refer the following thread:

Regards,

Rahul

7 REPLIES 7

Former Member
0 Kudos

Hi,

refer the following thread:

Regards,

Rahul

0 Kudos

Thanks for replying but that answer my question..i want to how to give posting keys in my account.?

0 Kudos

Hi,

posting keys are mainly to determine credits and debits.

In the corresponding SAP screens ,if u are giving posting key 40 for debit and 50 for credit accounts,u will see the same 40 and 50 in document generated by BAPI given the same other data as in SAP screens.so when done through bapi, u dont need to bother about posting keys.just give sign to amounts.

if user want to enter posting keys,what we did is, we simply gave posting key fields in non SAP screens where user can enter and see the values just to simulate the same SAP environment.

there is a way to actually pass posting keys and thereby make bapi to put -ve signs automatically to credit amounts through EXTENSION parameters in the BAPI.u can search for that in forums.there r lot of links.

but that method demands more effort.

regards

Arjun

Edited by: Arjun Subhash on Dec 18, 2008 12:49 PM

arjun_subhash
Active Participant
0 Kudos

Hi,

No need to pass posting keys.BAPI will automatically determine the posting keys from accounts,credit,debit and doc types passed.

the posting keys will be same as we do through SAP transaction.

give -ve sign to credit amouts in 'amount' field of 'currencyamount' table.

u can leave obj_KEY,OBJ_SYS,OBJ_TYPE fields blank.

regards

Arjun

Edited by: Arjun Subhash on Dec 18, 2008 12:38 PM

Former Member
0 Kudos

Hi,

I hope the below code will help you.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = lw_docheader

IMPORTING

obj_type = lv_obj_type

obj_key = lv_obj_key

obj_sys = lv_obj_sys

TABLES

accountgl = it_accountgl

currencyamount = it_currencyamount

return = it_return.

Thanks & Regards,

Khushboo.

Former Member
0 Kudos

Thanks every one

Former Member
0 Kudos

Hi,

As pointed out in one of the previous post, posting key will be decided by the BAPI depending on the sign of the amount. Have a look at bthe following code:-


DATA: doc_header LIKE BAPIACHE09,
      criteria   LIKE BAPIACKEC9 OCCURS 0 WITH HEADER LINE,
      doc_item   LIKE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
      doc_ar     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.
*
*DATA:
*       ITEMNO_ACC	POSNR_ACC
*       FIELDNAME	FIELDNAME
*       CHARACTER	ACPI_RKE_CRIGEN
*
* Fill Document Header
doc_header-bus_act = 'RFBU'.
doc_header-bus_act = 'RMRP'.
*doc_header-bus_act = 'SD00'.
doc_header-username = sy-uname.
doc_header-header_txt = 'TEST BOC BAPI POSTING'.
doc_header-comp_code = 'IN10'.
*
doc_header-compo_acc = 'FICA'.
*
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'.
*APPEND doc_item.
*CLEAR doc_item.
** Fill Line 2 of Document Item
*doc_item-itemno_acc = '2'.
*doc_item-customer = '0000000016'.
*doc_item-gl_account = '0000000016'.
*doc_item-pstng_date = sy-datlo.
*doc_item-item_text = 'TEST POSTING CREDIT ITEM'.
**_______________
*APPEND doc_item.
*CLEAR doc_item.
doc_ar-itemno_acc = '1'.
doc_ar-gl_account = '0000500001'.
doc_ar-pstng_date = sy-datum.
doc_ar-item_text = 'TEST POSTING DEBIT ITEM'.
doc_ar-costcenter = ''.
doc_ar-quantity = '1'.
doc_ar-base_uom = 'ST'.
APPEND doc_ar.
CLEAR doc_ar.
* Fill Line 2 of Document Item
doc_ar-itemno_acc = '2'.
doc_ar-customer = '0000000016'.
doc_ar-gl_account = '0000000016'.
doc_ar-pstng_date = sy-datlo.
doc_ar-item_text = 'TEST POSTING CREDIT ITEM'.
doc_ar-stat_con = ' '.
doc_ar-costcenter = '0000201681'.
APPEND doc_ar.
CLEAR doc_ar.
* Fill Line 1 of Document Value.
doc_values-itemno_acc = '1'.
doc_values-currency_iso = 'INR'.
doc_values-amt_doccur = '200.00'.
doc_values-currency = 'INR'.
doc_values-CURR_TYPE = '00'.  "Doc currency
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 = '200.00-'.
doc_values-currency = 'INR'.
doc_values-curr_type = '00'.  "Doc currency
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
    ACCOUNTRECEIVABLE    = doc_ar
    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.

Regards

Raju Chitale

Edited by: Raju Chitale on Dec 18, 2008 8:31 AM