Application Development and Automation 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: 
Read only

BAPI_ACC_DOCUMENT_POST cannot post/create new accounting documents

siongchao_ng
Contributor
0 Likes
2,124

bapi-acc-document-post.png

Hi all,

I am having problem using BAPI_ACC_DOCUMENT_POST to post/create new accounting documents. Can anyone identify what could be the problem here? Thanks

This is the header part.

gw_documentheader-fisc_year = gw_post_rec-gjahr.
gw_documentheader-header_txt = 'CAYEAUTO'.

gw_documentheader-pstng_date = gw_post_rec-budat.
gw_documentheader-doc_date = gw_documentheader-pstng_date.

gw_documentheader-ref_doc_no = gw_post_rec-xblnr

IF gw_post_rec-bschl = '21' OR
gw_post_rec-bschl = '31'.

gw_documentheader-doc_type = 'KI'.

ELSEIF gw_post_rec-bschl = '25' OR
gw_post_rec-bschl = '50'.

gw_documentheader-doc_type = 'ZP'.

ENDIF.
gw_documentheader-fis_period = '12'. "gw_post_rec-monat.
gw_documentheader-comp_code = gw_post_rec-bukrs.

gw_documentheader-index = g_doc_count.

gw_documentheader_p-doc_status = '4'.
gw_documentheader_p-obj_type = 'ZBKPF'. "'BKPFF'.
*
*
l_belnr = gw_documentheader-ac_doc_no + 1.
CONCATENATE l_belnr
gw_documentheader-comp_code
gw_documentheader-fisc_year

INTO gw_documentheader-obj_key.
* gw_documentheader-obj_key = 'l'.
** gw_documentheader-obj_key = gw_documentheader-ref_doc_no. "'$'. "gw_documentheader_p-ac_doc_no.
gw_documentheader-obj_sys = l_logsys.

APPEND gw_documentheader TO gt_documentheader.

This is my account payable.

gw_accountpayable-itemno_acc = g_doc_count.
IF gw_post_rec-bschl = '21'.
gw_accountpayable-vendor_no = gw_post_rec-lifnr.
ELSEIF gw_post_rec-bschl = '31'.
gw_accountpayable-vendor_no = '1001941'.
ENDIF.

gw_accountpayable-comp_code = gw_post_rec-bukrs.
gw_accountpayable-gl_account = gw_post_rec-hkont.

gw_accountpayable-bus_area = gw_post_rec-gsber.

gw_accountpayable-item_text = 'CAYEAUTO'.

gw_accountpayable-bline_date = gw_documentheader-doc_date.
gw_accountpayable-pmnt_block = gw_post_rec-zlspr.
gw_accountpayable-pymt_cur = 'SGD'. "gw_post_rec-pycur.
gw_accountpayable-dsct_days1 = gw_post_rec-zbd1t.
gw_accountpayable-dsct_pct1 = gw_post_rec-zbd1p.
gw_accountpayable-dsct_days2 = gw_post_rec-zbd2t.

gw_accountpayable-pymt_amt = gw_post_rec-wrbtr.

gw_accountpayable-index = g_doc_count.

APPEND gw_accountpayable TO gt_accountpayable.

5 REPLIES 5
Read only

venkateswaran_k
Active Contributor
0 Likes
1,728

what is your issue.

All lines are created in one single document?

If so please attach your code full, using code option

Read only

former_member629447
Participant
0 Likes
1,728

What is the error in the RETURN Parameter?

From the Screenshot it seems Document is created. If that is the case, please check whether you have called Commit statement after the BAPI call.

Read only

siongchao_ng
Contributor
0 Likes
1,728
DATA: l_loop_index TYPE i.
  DATA: l_status_count TYPE i,
        l_result_count TYPE i,
        l_error_flag   TYPE c,
        l_status       TYPE icon_d,
        l_belnr        TYPE belnr_d.

  DATA: l_obj_key TYPE bapiache09-obj_key.
  DATA: l_logsys  TYPE bapiache09-obj_sys.

  DATA: l_nr_range_nr TYPE inri-nrrangenr,
        l_object      TYPE inri-object.

  REFRESH: gt_check_result,
           gt_post_result.

  CLEAR:   l_loop_index,
           g_belnr1,
           g_bukrs,
           g_budat.

  CALL FUNCTION 'FIBL_GET_LOGSYS'
    IMPORTING
      ex_logsys = l_logsys.


*  WHILE l_loop_index < g_doc_count.
  ADD 1 TO l_loop_index.
  CLEAR l_error_flag.

*--> If Errors exist in the previous checking, ignore the record
  READ TABLE gt_status INTO gw_status
    WITH KEY index = l_loop_index
              type = 'E'.

*--> Errors found in the document. Add the Error status message and
*    ignore the record
  IF sy-subrc = 0.

    LOOP AT gt_status INTO gw_status
      WHERE index = l_loop_index.
      gw_status-type   = 'E'.
      gw_status-status  = icon_led_red.

      APPEND gw_status TO gt_check_result.
      APPEND gw_status TO gt_final_result.
      l_error_flag = gc_x.
    ENDLOOP.

    IF l_error_flag = gc_x.
      IF g_check IS INITIAL.
        g_check = 8.
      ENDIF.
*        CONTINUE.
    ENDIF.
  ENDIF.

  REFRESH: gt_documentheader_p,
           gt_accountgl_p,
           gt_accountreceivable_p,
           gt_accountpayable_p,
           gt_currencyamount_p,
           gt_criteria_p,
           gt_accounttax_p,
           gt_bapiret2_p,
           gt_accountreceivable_b,
           gt_currencyamount_b,
           gt_accountgl_b,
           gt_accounttax_b,
           gt_bapiret2_b.

** Document Header
  LOOP AT gt_documentheader INTO gw_documentheader.
    "WHERE index = l_loop_index.

    gw_documentheader_p = gw_documentheader.
    gw_documentheader_p-bus_act = 'RFBU'.
    gw_documentheader_p-username = sy-uname.

    IF gw_documentheader_p-doc_type EQ 'RV'
    OR gw_documentheader_p-doc_type EQ 'RC'
    OR gw_documentheader_p-doc_type EQ 'RR'.


      gw_documentheader_p-obj_type = 'ZBKPF'.
      gw_documentheader_p-obj_key =  gw_documentheader_p-ac_doc_no.
      gw_documentheader_p-obj_sys = l_logsys.

    ELSEIF gw_documentheader_p-doc_type EQ 'RE'
    OR     gw_documentheader_p-doc_type EQ 'KI'
    OR     gw_documentheader_p-doc_type EQ 'ZP'.

      gw_documentheader_p-ac_doc_no = space.
*      gw_documentheader_p-doc_status = '4'.
      gw_documentheader_p-obj_type = 'ZBKPF'. "'BKPFF'.
*
*
      l_belnr = gw_documentheader_p-ac_doc_no + 1.
      CONCATENATE l_belnr
                  gw_documentheader_p-comp_code
                  gw_documentheader_p-fisc_year

                  INTO gw_documentheader_p-obj_key.
*      gw_documentheader_p-obj_key = 'l'.
**      gw_documentheader_p-obj_key = gw_documentheader-ref_doc_no.  "'$'. "gw_documentheader_p-ac_doc_no.
      gw_documentheader_p-obj_sys = l_logsys.

    ENDIF.
    APPEND gw_documentheader_p TO gt_documentheader_p.

  ENDLOOP.

** GL
  LOOP AT gt_accountgl INTO gw_accountgl." WHERE index = l_loop_index.
    gw_accountgl_p = gw_accountgl.
    APPEND gw_accountgl_p TO gt_accountgl_p.
  ENDLOOP.

** AR
  LOOP AT gt_accountreceivable INTO gw_accountreceivable.
    " WHERE index = l_loop_index.
    gw_accountreceivable_p = gw_accountreceivable.
    APPEND gw_accountreceivable_p TO gt_accountreceivable_p.
  ENDLOOP.

** AP
  LOOP AT gt_accountpayable INTO gw_accountpayable.
    "WHERE index = l_loop_index.
    gw_accountpayable_p = gw_accountpayable.
    APPEND gw_accountpayable_p TO gt_accountpayable_p.
  ENDLOOP.

** Currency - Posting Amount
  LOOP AT gt_currencyamount INTO gw_currencyamount.
    "WHERE index = l_loop_index.
    gw_currencyamount_p = gw_currencyamount.
    APPEND gw_currencyamount_p TO gt_currencyamount_p.
  ENDLOOP.

** Criteria - Profit Segment
  LOOP AT gt_criteria INTO gw_criteria." WHERE index = l_loop_index.
    gw_criteria_p = gw_criteria.
    APPEND gw_criteria_p TO gt_criteria_p.
  ENDLOOP.

** Account Tax
  LOOP AT gt_accounttax INTO gw_accounttax." WHERE index = l_loop_index.
    gw_accounttax_p = gw_accounttax.
    APPEND gw_accounttax_p TO gt_accounttax_p.
  ENDLOOP.

*** Post Document
*    CLEAR l_obj_key.
*    IF l_loop_index > 1.
*      CONCATENATE 'Refer'(t11) g_bukrs g_belnr1 INTO
*        gw_documentheader_p-header_txt SEPARATED BY space.
*    ENDIF.

  REFRESH gt_bapiret2_p.
  CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
    EXPORTING
      documentheader    = gw_documentheader_p
    TABLES
      accountgl         = gt_accountgl_p
      accountreceivable = gt_accountreceivable_p
      accountpayable    = gt_accountpayable_p
      accounttax        = gt_accounttax_p
      currencyamount    = gt_currencyamount_p
      return            = gt_bapiret2_p.

  IF gt_bapiret2_p IS NOT INITIAL.
    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
      EXPORTING
        documentheader    = gw_documentheader_p
      IMPORTING
        obj_key           = l_obj_key
      TABLES
        accountgl         = gt_accountgl_p
        accountreceivable = gt_accountreceivable_p
        accountpayable    = gt_accountpayable_p
        accounttax        = gt_accounttax_p
        currencyamount    = gt_currencyamount_p
        return            = gt_bapiret2_p.

    IF l_obj_key = '$'.
*      LOOP AT gt_bapiret2_p INTO gw_bapiret2_p
*               WHERE type = 'A' OR type = 'E' OR type = 'X'.
      l_status = icon_led_red.
*        EXIT.
*      ENDLOOP.

    ELSE.
      WAIT UP TO 10 SECONDS.

      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = gc_x.

*      COMMIT WORK AND WAIT.

*     unblock invoice document
*     only unblock if there is no error
      UNASSIGN <gs_bsik>.
      LOOP AT gt_bsik ASSIGNING <gs_bsik>.
        <gs_bsik>-zlspr = space.
      ENDLOOP.
      UPDATE bsik FROM TABLE gt_bsik.
      COMMIT WORK.

      gw_check_result-belnr = l_obj_key+0(10).

      CLEAR l_status_count.
      DESCRIBE TABLE gt_bapiret2_p LINES l_result_count.

      l_status = icon_led_green.

    ENDIF.



  ENDIF.
Read only

siongchao_ng
Contributor
0 Likes
1,728

For every 1 line of BSIK i retrieved, I created 4 lines of documents to be posted.

1st pair:

posting key 21 and 31 for vendor.

2nd pair:

posting key 25 and 50 for GL account.

So you can imagine for each loop of BSIK entry,

My first posting: i have 1 document header line, 2 entries in my account payable table and 2 entries in my currency table.

My second posting: i have 1 document header line, 2 entries in my account G/L table and 2 entries in my currency table.

Is this concept right?

Read only

siongchao_ng
Contributor
0 Likes
1,728

The following is used after CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING

wait = gc_x.

Although the BAPI state it is successful, no accounting documents gets created. I searched in FB03 on today entry date or table BKPF for today's entry but found none.