cancel
Showing results for 
Search instead for 
Did you mean: 

Sample code for posting Outgoing Vendor payments document(F-53) using BAPI: BAPI_ACC_DOCUMENT_POST

snehbansode
Explorer
0 Kudos

Hello All,

Can anyone please provide me with a sample code to post outgoing vendor payment documents via BAPI: BAPI_ACC_DOCUMENT_POST.

Also, does this BAPI automatically clears the open items(F.13)?

Thanks & Regards,

Sneh

Accepted Solutions (0)

Answers (1)

Answers (1)

Abinathsiva
Active Contributor

HI, Sneh

try below code..


DATA: headerinfo LIKE BAPIACHE09,
      sample   LIKE BAPIACKEC9 OCCURS 0 WITH HEADER LINE,
      iteminfo   LIKE BAPIACGL09 OCCURS 0 WITH HEADER LINE,
      valueinfo 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 Information
headerinfo-bus_act = 'RFBU'.
headerinfo-username = sy-uname.
headerinfo-header_txt = 'TEST BOC BAPI POSTING'.
headerinfo-comp_code = 'IN10'.
headerinfo-doc_date = '20060127'.
headerinfo-pstng_date = sy-datlo.
headerinfo-doc_type = 'SA'.
* Fill Line of Document Item related Information
iteminfo-itemno_acc = '1'.
iteminfo-gl_account = '0000500001'.
iteminfo-pstng_date = sy-datum.
iteminfo-item_text = 'TEST POSTING DEBIT ITEM'.
iteminfo-costcenter = ''.
iteminfo-quantity = '1'.
iteminfo-base_uom = 'ST'.

APPEND iteminfo.
CLEAR iteminfo.

* Fill Line 1 of Document Value related Information
valueinfo-itemno_acc = '1'.
valueinfo-currency_iso = 'INR'.
valueinfo-amt_doccur = '0.02-'.
APPEND valueinfo.
CLEAR valueinfo.

* Add tax code in extension1 table.
extension1-field1 = 'BAPI CALL'.
APPEND EXTENSION1.

refresh sample.
sample-ITEMNO_ACC = '1'.
sample-FIELDNAME  = 'ARTNR'.
sample-CHARACTER  = '000000000001312251'.
Append sample.
sample-ITEMNO_ACC = '1'.
sample-FIELDNAME  = 'WERKS'.
sample-CHARACTER  = 'IN91'.
Append sample.
sample-ITEMNO_ACC = '1'.
sample-FIELDNAME  = 'KNDNR'.
sample-CHARACTER  = '0000000016'.
Append sample.
sample-ITEMNO_ACC = '1'.
sample-FIELDNAME  = 'FKART'.
sample-CHARACTER  = 'ZIN2'.
Append sample.
sample-ITEMNO_ACC = '1'.
sample-FIELDNAME  = 'KAUFN'.
sample-CHARACTER  = '0000000633'.
Append sample.
sample-ITEMNO_ACC = '1'.
sample-FIELDNAME  = 'KDPOS'.
sample-CHARACTER  = '000010'.
Append sample.

* All tables filled - now call BAPI.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
  EXPORTING
    documentheader       = headerinfo
  IMPORTING
    OBJ_TYPE             = headerinfo-obj_type
    OBJ_KEY              = headerinfo-obj_key
    OBJ_SYS              = headerinfo-obj_sys
  TABLES
    sample             = sample
    accountgl            = iteminfo
    currencyamount       = valueinfo
    return               = return
    EXTENSION1           = EXTENSION1.
*
LOOP AT return WHERE type = 'E'.
  EXIT.
ENDLOOP.
*
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
  EXPORTING
    documentheader       = headerinfo
  IMPORTING
    OBJ_TYPE             = headerinfo-obj_type
    OBJ_KEY              = headerinfo-obj_key
    OBJ_SYS              = headerinfo-obj_sys
  TABLES
    sample             = sample
    accountgl            = iteminfo
    currencyamount       = valueinfo
    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: / headerinfo-obj_key, ' posted'.
ENDIF.
snehbansode
Explorer

Hello Abinath,

Thanks for the reply but I want to post a Outgoing Vendor Payments doc. through the BAPI: BAPI_ACC_DOCUMENT_POST in which the credit entry will have the posting key as '31'(Invoice).

The above code does not post a Outgoing Vendor Payments doc.

Can you please provide a sample code where the BAPI replicates (F-53) and posts an Outgoing Vendor Payments doc.?

Thanks & Regards,

Sneh

snehbansode
Explorer
0 Kudos

Hello Abinath,

Based on your sample code build the sample code which posts an Outgoing Vendor Payments Doc. through the BAPI: BAPI_ACC_DOCUMENT_POST. The only change I did was instead of using 'AccountGL' table of BAPI used 'AccountPayable' and added vendor number in the credit line item which also according to the GL automatically took the posting key as '31'.

PFB the sample code I built.

DATA: headerinfo LIKE bapiache09,
        sample     LIKE bapiackec9 OCCURS 0 WITH HEADER LINE,
        iteminfo   LIKE bapiacap09 OCCURS 0 WITH HEADER LINE,
        valueinfo  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 Information
  headerinfo-bus_act = 'RFBU'.
  headerinfo-username = sy-uname.
  headerinfo-header_txt = 'TEST BOC BAPI POSTING'.
  headerinfo-comp_code = '7200'.
  headerinfo-doc_date = '20190416'.
  headerinfo-pstng_date = sy-datlo.
  headerinfo-doc_type = 'KR'.
  headerinfo-ref_doc_no = 'Test Sneh'.


* Fill Line of Document Item related Information
  iteminfo-itemno_acc = '1'.
  iteminfo-gl_account = '0000220100'.
  iteminfo-bline_date = sy-datum.
  iteminfo-vendor_no = '1000104908'.
  iteminfo-item_text = 'TEST POSTING DEBIT ITEM'.


  APPEND iteminfo.
  CLEAR iteminfo.


* Fill Line 1 of Document Value related Information
  valueinfo-itemno_acc = '1'.
  valueinfo-currency_iso = 'INR'.
  valueinfo-amt_doccur = '0.02-'.
  APPEND valueinfo.
  CLEAR valueinfo.


* Fill Line of Document Item related Information
  iteminfo-itemno_acc = '2'.
  iteminfo-gl_account = '0000238101'.
  iteminfo-bline_date = sy-datum.
  iteminfo-item_text = 'TEST POSTING DEBIT ITEM'.


  APPEND iteminfo.
  CLEAR iteminfo.


* Fill Line 1 of Document Value related Information
  valueinfo-itemno_acc = '2'.
  valueinfo-currency_iso = 'INR'.
  valueinfo-amt_doccur = '0.02'.
  APPEND valueinfo.
  CLEAR valueinfo.


* All tables filled - now call BAPI.
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
    EXPORTING
      documentheader = headerinfo
    TABLES
      accountpayable = iteminfo
      currencyamount = valueinfo
      return         = return
      extension1     = extension1.
*
  LOOP AT return WHERE type = 'E'.
    EXIT.
  ENDLOOP.
*
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
      documentheader = headerinfo
    TABLES
      accountpayable = iteminfo
      currencyamount = valueinfo
      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   = abap_true
      IMPORTING
        return = return.
    WRITE: / 'BAPI call worked!!'.
    WRITE: / headerinfo-obj_key, ' posted'.
  ENDIF.

Abinathsiva
Active Contributor

Hi Sneh,

can you please mention debit posting key so, that can understand the transaction and give the code accordingly..

Thanks,

Abinath. S