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: 

How to Create an FI document using a BAPI

Former Member
0 Kudos

Hi,

I have a requirement as under(for a report creation):

I need get all the Account numbers(from table BSIS) depending on the Posting date(BUDAT) and the Price difference accounts(HKONT) for the previous month(say 1/1 to 31/1).

After I get all the details from BSIS, I will have to get the Material Number(MATNR), Plant(WERKS), Local Currency, Foreign Currency, Material Quantity and etc., from BSEG(by comparing the Accounting Document Number) which is common in both the tables BSIS and BSEG.

Now, for all these docs, I need to create a single FI document(that has to cover all these documents) by using the Document type,Posting date and Reclassed Account number and some text has to be inserted into the Item text field.

I came to know that, we have to use a BAPI inorder for this purpose, I could not get the exact one.

Please help me in this regard by giving your valuable inputs.

Regards,

Vishnu.

10 REPLIES 10

FredericGirod
Active Contributor
0 Kudos

you can use the FM BAPI_ACC_GL_POSTING_POST

Former Member
0 Kudos

Hello

The best way to create FI documents are the BAPIs BAPI_ACC_DOCUMENT_CHECK and BAPI_ACC_DOCUMENT_POST the first one checks if the document can be created it's a sort of simulation and the second one creates the document.

Regards

Yassine NEJMY

Former Member
0 Kudos

 DATA:
  obj_type LIKE bapiache02-obj_type,
  obj_key LIKE bapiache02-obj_key,
  obj_sys LIKE bapiache02-obj_sys,
*  documentheader LIKE bapiache08,
  documentheader LIKE bapiache09,
*  accountgl LIKE bapiacgl08 OCCURS 0 WITH HEADER LINE,
*  currencyamount LIKE bapiaccr08 OCCURS 0 WITH HEADER LINE,
*  extension1 LIKE bapiextc   OCCURS 0 WITH HEADER LINE,
  return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
  accountgl LIKE bapiacgl09  OCCURS 0 WITH HEADER LINE,
  currencyamount LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,
  extension1 LIKE bapiacextc   OCCURS 0 WITH HEADER LINE,
  t_edidd LIKE edidd OCCURS 0 WITH HEADER LINE,
  bapi_retn_info LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

  DATA: error_flag.
  DATA: gs_wait TYPE bapita-wait,
  wa_comm_return TYPE bapiret2.
  DATA : zsched_line LIKE bapiacgl09-itemno_acc.
  break developer.
  LOOP AT itab.

    IF itab-shkzg = 'H'.
      CONCATENATE itab-mblnr itab-mjahr INTO documentheader-header_txt.
      documentheader-username = sy-uname.
      documentheader-comp_code = '1000'.
      documentheader-doc_date = itab-bldat.
      documentheader-pstng_date = itab-budat.
      documentheader-doc_type = 'SA'.
      documentheader-ref_doc_no = itab-xblnr.

Former Member
0 Kudos

Continue..........


  accountgl-itemno_acc = '2'.
      accountgl-gl_account = 'WRITE UR GL NO'.
      accountgl-comp_code = '1000'.
      accountgl-pstng_date = itab-budat.
      accountgl-doc_type = 'SA'.
      accountgl-profit_ctr = itab-prctr.
      accountgl-alloc_nmbr = itab-zuonr.
      accountgl-po_number  = itab-ebeln.
      accountgl-po_item = itab-ebelp.
*    accountgL-DE_CRE_IND = 'S'.
      APPEND accountgl.

      currencyamount-itemno_acc = '2'.
      currencyamount-currency = 'USD'.
      currencyamount-amt_doccur = itab-grval.
      APPEND currencyamount.
*    zsched_line = zsched_line + 1.
***line itme 2
      accountgl-itemno_acc = '1'.
      accountgl-gl_account = 'YOUR GL NO'.
      accountgl-comp_code = '1000'.
      accountgl-pstng_date = itab-budat.
      accountgl-doc_type = 'SA'.
      accountgl-profit_ctr = itab-prctr.
      accountgl-alloc_nmbr = itab-zuonr.
*    accountgl-po_number  = itab-ebeln.
      accountgl-po_item = itab-ebelp.
*    accountgL-DE_CRE_IND = 'H'.
      APPEND accountgl.


      currencyamount-itemno_acc = '1'.
      currencyamount-currency = 'USD'.
      itab-grval = itab-grval * -1.
      currencyamount-amt_doccur = itab-grval.
      APPEND currencyamount.

ELSE.

      documentheader-username = sy-uname.
      CONCATENATE itab-mblnr itab-mjahr INTO documentheader-header_txt.
      documentheader-comp_code = '1000'.
      documentheader-doc_date = itab-bldat.
      documentheader-pstng_date = itab-budat.
      documentheader-doc_type = 'SA'.
      documentheader-ref_doc_no = itab-xblnr.
*    documentheader-BUS_ACT = 'F-02'.

Former Member
0 Kudos

 accountgl-itemno_acc = '1'.
      accountgl-gl_account = '0000261065'.

      accountgl-comp_code = '1000'.
      accountgl-pstng_date = itab-budat.
      accountgl-doc_type = 'SA'.
      accountgl-profit_ctr = itab-prctr.
      accountgl-alloc_nmbr = itab-zuonr.
*    accountgL-DE_CRE_IND = 'S'.
      APPEND accountgl.

      currencyamount-itemno_acc = '1'.
      currencyamount-currency = 'USD'.
      currencyamount-amt_doccur = itab-grval.
      APPEND currencyamount.
*    zsched_line = zsched_line + 1.
***line itme 2
      accountgl-itemno_acc = '2'.
      accountgl-gl_account = 'YOUR GL NO'.
      accountgl-comp_code = '1000'.
      accountgl-pstng_date = itab-budat.
      accountgl-doc_type = 'SA'.
      accountgl-profit_ctr = itab-prctr.
      accountgl-alloc_nmbr = itab-zuonr.
      accountgl-po_number  = itab-ebeln.
      accountgl-po_item = itab-ebelp.
*    accountgL-DE_CRE_IND = 'H'.
      APPEND accountgl.

      currencyamount-itemno_acc = '2'.
      currencyamount-currency = 'USD'.
      itab-grval = itab-grval * -1.
      currencyamount-amt_doccur = itab-grval.
      APPEND currencyamount.
    ENDIF.
 CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
      EXPORTING
        documentheader = documentheader
      TABLES
        accountgl      = accountgl
        currencyamount = currencyamount
        return         = return
        extension1     = extension1
      EXCEPTIONS
        OTHERS         = 1.
    IF sy-subrc <> 0.
      MESSAGE e999(re) WITH 'Problem occured'.
    ELSE.

Former Member
0 Kudos

Continue................


 LOOP AT return.
        IF NOT return IS INITIAL.
          CLEAR bapi_retn_info.
          MOVE-CORRESPONDING return TO bapi_retn_info.
          IF return-type = 'A' OR return-type = 'E'.
            error_flag = 'X'.
          ENDIF.
          APPEND bapi_retn_info.
        ENDIF.
      ENDLOOP.
      IF error_flag = 'X'.
        MESSAGE e999(re) WITH 'Problem occured'.
        ROLLBACK WORK.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait   = gs_wait
          IMPORTING
            return = wa_comm_return.
        WRITE 😕 return-message+0(30),return-message+36(10).
      ENDIF.

    ENDIF.
    REFRESH: currencyamount,accountgl,return,extension1.
    CLEAR: currencyamount,accountgl,documentheader,return,extension1.

  ENDLOOP.

0 Kudos

Hi,

Thanks for the mail.

I have a few queries on the BAPI - 'BAPI_ACC_DOCUMENT_POST':

- I was calling this BAPI by passing these values into the Header structure: obj_type(BKPF-AWTYP), obj_key(BKPF-AWKEY), bus_act(BKPF-GLVOR), comp_code(BKPF-BUKRS), pstng_date(the posting date entered by the user from the selection screen), doc_type(= 'PS' - Purchase Excess), ref_doc_no(BKPF-XBLNR), ac_doc_no(BKPF-BELNR)

[in my case, for a combination of BUKRS,BELNR and GJHAR from BKPF, I am having 6 entries and for these 6 entries I am fetching relevant fields from the table 'BSEG' which are needed in the filling of the Items table in the BAPI].

now, my questions are:

- I need to reverse the posting of these 6 documents using this BAPI depending on the debit/credit indicator. when I tried to post

only 1 item, I was getting the message that 'Document was successfully posted' in the BAPI return(and after which, I made a

BAPI commit also, but I could not see the new document details.... how can I see this new document with the 1 line item being

posted?

- suppose if I have 2 sets of data with different Company codes, in this case, do I need to run this process for each of the

seperate set of data?(as the company code element field is there in the Header level?

please provide your valuable inputs on this.

Regards,

Vishnu.

0 Kudos

Hi group,

I was working with the BAPI 'BAPI_ACC_DOCUMENT_POST' to create an FI document with some line items in it.

when I tried with some test data directly in SE37, I could see an FI document being created in the tables BKPF and BSEG.

But, when I tried to use these entries in a program, I was getting errors.... this was mainly because of 4 fields (obj_type, obj_key, Obj_sys and Bus_act - first 4 fields in the header structure 'BAPIACHE09' in the import parameter of the interface)....

when I was trying with a blank values in these 4 fields in the program, I was getting errors saying that these 4 fields have to be mandatorily filled without which the BAPI cannot create an FI document.

Could you please let me know how I can proceed on this? I am not able to understand why there was a mismatch in running in SE37 and in the program SE38, in SE37 - no errors and SE38 - errors on these fields.

please provide inputs on these lines... as to how to go about tackling this issue....

Regards,

Vishnu.

0 Kudos

obj_type = Check table - TTYP with help of FI consultant

bus_act = 'RFBU'.

obj_key = Should be document number

obj_sys = CONCATENATE 'LOGSYS' sy-mandt

Check the documentation maintai for the parameter - DOCUMENTHEADER with FI Consultant

Former Member
0 Kudos

Very valuable answers.