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

Invoice Upload Program in FB50

Former Member
0 Likes
3,730

Hi Experts,

I need to develop an invoice upload program for transaction code FB50. The data will be from an Excel file.

As I'm new to program in accounting, is there anyone has sample code?

I'm not sure what function module to use to save the invoice.

Hope someone can help me. Many thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,349

Hi Sam,

Yes, you can go for that option too but i prefer using BAPI for the purpose bcoz

it is easy to use and code.

I have done a test recording for that transaction(F-43) and i dint come across any issues.

So, you can try BDC too.

Regards,

Jallu

15 REPLIES 15
Read only

Former Member
0 Likes
2,349

Hi Sam,

I briefly explain how to go about this. Follow these steps.

1) Upload data from Excel :

This can be done using the FMs 'GUI_UPLOAD' or 'ALSM_EXCEL_TO_INTERNAL_TABLE'

2) Now, you can use the following BAPIs for the posting or checking the documents

BAPI_ACC_DOCUMENT_POST - Posting the documents

Using this method you can create a posing in accounting for certain business transactions.

If you wan to check whether a document can be created or not, then use the bapi

BAPI_ACC_DOCUMENT_CHECK

Or if you want to PARK the documents instead of the Posting then you can use a

standard SAP program 'RFBIBL00'.

I hope this information will be helpful to you.

If you want anymore help, get back to me.

Regards,

Jallu

Read only

0 Likes
2,349

Thanks for your guide. I'll try next week and if I still have some problem, I hope you can help me further.

Many thanks again.

Read only

0 Likes
2,349

Hi Jallu,

Can you give more information of the function module BAPI_ACC_DOCUMENT_POST?

What should I input to the parameters?

Thanks

Read only

Former Member
0 Likes
2,349

Hi Sam,

It generally depends on what sort of postings you are doing.

You can refer to following code, it is for the posting of invoices.

  • Document Header
  • wa_document_header-comp_code = c_company_2001.
  • One time vendor
  • Concatenate the text and account number and pass it as a line item text
  • Check for the Payee name and use vendor number accordingly
  • Check if amount value is more than '0'
  • Vendor line item
  • GL Account line item
  • Get currency details for vendor line item
  • Get currency details for GL Account line item
  • Pass suitable posting key
  • Pass suitable posting key
  • When posting amount is less than zero
  • Vendor line item
  • Get currency details for vendor line item
  • Get currency details for GL Account line item
  • GL Account line item
  • Pass suitable posting key
  • Pass suitable posting key
  • Check if one time vendor data is available
  • Call the BAPI 'BAPI_ACC_DOCUMENT_POST' to create the invoices
  • Check if bapi return table is intial
  • Maintain a error log with all BAPI returned messages
  • Get only error\abort messages into error table
  • check if flag has been enabled
  • Check for the message type in the return table and
  • if it is success then commit the transaction.
  • Concatenate the message text and refund id into a variable
  • append success messge to the error table
  • Refresh the internal tables
  • Clear the work areas and variables
LOOP AT it_record INTO wa_record. wa_document_header-username = sy-uname. wa_document_header-comp_code = v_compcode. wa_document_header-doc_date = wa_record-bkpf_bldat. wa_document_header-pstng_date = sy-datum. wa_document_header-doc_type = v_doctype. wa_document_header-ref_doc_no = wa_record-bkpf_xblnr. wa_customercpd-name = wa_record-bsec_name1. wa_customercpd-name_2 = wa_record-bsec_name2. wa_customercpd-postl_code = wa_record-bsec_pstlz. wa_customercpd-city = wa_record-bsec_ort01. wa_customercpd-country = v_country. wa_customercpd-street = wa_record-bsec_stras. wa_customercpd-tax_no_1 = wa_record-bsec_stcd1. wa_customercpd-tax_no_2 = wa_record-bsec_stcd2. wa_customercpd-region = wa_record-bsec_regio. CONCATENATE text-008 wa_record-bseg_sgtxt INTO v_item_text " Refund for Acc no SEPARATED BY space. IF wa_record-bsec_name1 = c_name_heap. v_vendor_no = v_vendor_heap. ELSE. v_vendor_no = v_vendor_onetime. ENDIF. IF wa_record-bseg_wrbtr GT 0. wa_acc_payable-itemno_acc = c_itemno_1. wa_acc_payable-vendor_no = v_vendor_no. wa_acc_payable-item_text = v_item_text. APPEND wa_acc_payable TO it_acc_payable. CLEAR: wa_acc_payable. wa_accountgl-itemno_acc = c_itemno_2. wa_accountgl-gl_account = v_glaccount. wa_accountgl-item_text = v_item_text. APPEND wa_accountgl TO it_accountgl. CLEAR: wa_accountgl. wa_currency_amount-itemno_acc = c_itemno_1. wa_currency_amount-currency = c_currency_usd . wa_currency_amount-amt_doccur = - ( wa_record-bseg_wrbtr ). APPEND wa_currency_amount TO it_currency_amount. CLEAR: wa_currency_amount. wa_currency_amount-itemno_acc = c_itemno_2. wa_currency_amount-currency = c_currency_usd . wa_currency_amount-amt_doccur = wa_record-bseg_wrbtr. APPEND wa_currency_amount TO it_currency_amount. CLEAR: wa_currency_amount. wa_extension2-structure = c_structure. wa_extension2-valuepart1 = c_itemno_1. wa_extension2-valuepart2 = c_newbs_31. " Credit indicator( Vendor side ) APPEND wa_extension2 TO it_extension2. CLEAR: wa_extension2. wa_extension2-structure = c_structure. wa_extension2-valuepart1 = c_itemno_2. wa_extension2-valuepart2 = c_newbs_40. " Debit indicator( GL Account side ) APPEND wa_extension2 TO it_extension2. CLEAR: wa_extension2. ELSE. wa_acc_payable-itemno_acc = c_itemno_1. wa_acc_payable-vendor_no = v_vendor_no. wa_acc_payable-item_text = v_item_text. APPEND wa_acc_payable TO it_acc_payable. CLEAR: wa_acc_payable. wa_currency_amount-itemno_acc = c_itemno_1. wa_currency_amount-currency = c_currency_usd . wa_currency_amount-amt_doccur = wa_record-bseg_wrbtr. APPEND wa_currency_amount TO it_currency_amount. CLEAR: wa_currency_amount. wa_currency_amount-itemno_acc = c_itemno_2. wa_currency_amount-currency = c_currency_usd . wa_currency_amount-amt_doccur = - ( wa_record-bseg_wrbtr ). APPEND wa_currency_amount TO it_currency_amount. CLEAR: wa_currency_amount. wa_accountgl-itemno_acc = c_itemno_2. wa_accountgl-gl_account = v_glaccount. wa_accountgl-item_text = v_item_text. APPEND wa_accountgl TO it_accountgl. CLEAR: wa_accountgl. wa_extension2-structure = c_structure. wa_extension2-valuepart1 = c_itemno_1. wa_extension2-valuepart2 = c_newbs_21. " Debit indicator( Vendor side ) APPEND wa_extension2 TO it_extension2. CLEAR: wa_extension2. wa_extension2-structure = c_structure. wa_extension2-valuepart1 = c_itemno_2. wa_extension2-valuepart2 = c_newbs_50. " Credit indicator( GL Account side ) APPEND wa_extension2 TO it_extension2. CLEAR: wa_extension2. ENDIF. IF wa_customercpd IS NOT INITIAL. CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST' EXPORTING documentheader = wa_document_header customercpd = wa_customercpd TABLES accountgl = it_accountgl accountpayable = it_acc_payable currencyamount = it_currency_amount return = it_return extension2 = it_extension2. IF it_return IS NOT INITIAL. LOOP AT it_return INTO wa_return WHERE type = c_msgtype_e OR type = c_msgtype_a. CONCATENATE wa_return-message text-013 wa_record-bkpf_xblnr INTO v_msg_text SEPARATED BY space. MOVE v_msg_text TO wa_return-message. APPEND wa_return TO it_error. CLEAR: wa_return, v_msg_text. f_error_ind = c_true. ENDLOOP. IF f_error_ind EQ c_true. EXIT. ELSE. DESCRIBE TABLE it_return LINES v_tabix. READ TABLE it_return INDEX v_tabix INTO wa_return. IF sy-subrc = 0. v_total_amount = ABS( wa_record-bseg_wrbtr ) + v_total_amount. " Total posting amount CONCATENATE wa_return-message text-013 wa_record-bkpf_xblnr INTO v_msg_text SEPARATED BY space. MOVE v_msg_text TO wa_return-message. APPEND wa_return TO it_success. CLEAR: wa_return, v_msg_text, v_tabix. ENDIF. ENDIF. ENDIF. ELSE. wa_return-type = c_msgtype_e. wa_return-message = text-009. " One time vendor details are not found APPEND wa_return TO it_error. CLEAR: wa_return. EXIT. ENDIF. REFRESH: it_return, it_acc_payable, it_currency_amount, it_accountgl, it_extension2. CLEAR: wa_document_header, wa_customercpd, wa_record, v_vendor_no, v_item_text. ENDLOOP.

Sam, before making the postings directly, try using 'BAPI_ACC_DOCUMENT_CHECK' so that

you will get to mo

I hope, it will be helpful to you.

If you want any more help, get back to me.

Regards,

Jallu

Read only

0 Likes
2,349

Really thanks for your quick response.

I'm doing a posting of invoice actually.

Read only

0 Likes
2,349

Hi Jallu,

Is this code suitable for transaction F-02 or F-43?

Rgds,

Irene

Edited by: Irene Sam on Mar 16, 2008 7:50 PM

Read only

0 Likes
2,349

Hi Jallu,

What should I put for item wa_extension2-structure = c_structure? What is the data declaration for c_structure?

Besides, what should I put for wa_acc_payable-itemno_acc and wa_acc_gl-itemno_acc? What is the data declaration for c_itemno_1 and c_itemno_2.

Is the input for customercpd into the FM a must?

Hope you can reply me as soon as possible.

Many thanks in advance.

Rgds,

Irene

Read only

0 Likes
2,349

Hi Jallu

As you mentioned "Or if you want to PARK the documents instead of the Posting then you can use a

standard SAP program 'RFBIBL00'", can you also help with the What should the parameters be input if I want to park invoices through Excel file?

Thank you,

Read only

Former Member
0 Likes
2,349

Hi Sam,

I think, You can use that BAPI code for these transactions (F-02 and F-43 ) too.

The difference between these transactions is

F-02 - General Posting

F-43 - Invoice - General

FB50 - Enter G/L Account Document

You can use these transactions for posting but only change will be the screens.

In FB50 transaction you can have option of providing many line items at a time where as

in other transactions you have to provide only one line item details in the initial screen.

As you need to post the invoices, pass the data to the tables parameter 'accountpayable' of the BAPI.

If the vendor is one time vendor, you need to pass the vendor details also through 'customercpd' parameter

of the BAPI.

If you want any more help, get back to me.

Regards,

Jallu

Read only

0 Likes
2,349

Hi Jallu,

Thanks for helping.

However what about the item I mentioned above?

What should I put for item wa_extension2-structure = c_structure? What is the data declaration for c_structure?

Besides, what should I put for wa_acc_payable-itemno_acc and wa_acc_gl-itemno_acc? What is the data declaration for c_itemno_1 and c_itemno_2.

Read only

Former Member
0 Likes
2,349

Hi Sam,

I didn't see your latest reply while answering last time.

I was using the 'extension2' parameter to overwrite\Set the posting keys. For the purpose, I have

implemented one BADI for that BAPI. If you want to implement that BADI too then follow this procedure.

Go to the BAPI 'BAPI_ACC_DOCUMENT_POST' source code there you will find

following code.

PERFORM call_badi

TABLES extension2.

Double click on that perform, it will take you to the subroutine. There you will find the following code.

CALL METHOD g_exit->change

EXPORTING

flt_val = gs_aw-awtyp

CHANGING

c_acchd = ls_acchd

c_accit = it_accit

c_acccr = it_acccr

c_accwt = it_accwt

c_acctx = it_acctx

c_extension2 = p_extension[]

c_return = lt_return.

Now click on the method 'Change' and it will ask for BADI implementation. you can do the same through SE18 and SE19 transactions too.

In the BADI implementation part, plug in following code.

  • Change the Posting keys - Code*

DATA: wa_extension TYPE bapiparex,

wa_accit TYPE accit.

LOOP AT c_extension2 INTO wa_extension.

IF wa_extension-structure = 'POSTING_KEY'.

CLEAR wa_accit.

READ TABLE c_accit INTO wa_accit

WITH KEY posnr = wa_extension-valuepart1.

IF sy-subrc = 0.

wa_accit-bschl = wa_extension-valuepart2.

MODIFY c_accit FROM wa_accit INDEX sy-tabix TRANSPORTING bschl.

ENDIF.

ENDIF.

ENDLOOP.

So what ever structure name you provide in that implementation, you need to use the same

in your program also. In my case it is 'POSTING_KEY'.

In that BAPI, we don't have any parameter to pass the posting keys (like 31 ,40 etc) to the BAPI and

it has got only one field 'DE_CRE_IND' in table parameter 'BAPIACGL09' where we can

set whether line item is a Credit or Debit. So, i have implemented the BADI to overcome this.

Take the decision after analyzing your scenario whether to implement the BADI or not.

If you are not doing that, then there is no need to fill the 'EXTENSION2' parameter data.

Regarding Item numbers:

you can declare them in a following way.

c_itemno_1 TYPE posnr_acc VALUE '1', " Line item number

c_itemno_2 TYPE posnr_acc VALUE '2', " Line item number

Generally, BAPI will co-relate the line item details passed to it based on the

line item number (ITEMNO_ACC) provided in the tables parameter.

if it is 1st line item, simply pass the value '1' to that parameter (ITEMNO_ACC) and

similarly '2', if it is second line item.

I hope this will help you.

If you want anymore help, get back to me.

Regards,

Jallu

Read only

0 Likes
2,349

Hi Jallu,

I try to test the FM in SE37, but it keeps give me the error regarding BUS_ACT in structure 'DOCUMENTHEADER'.

What should I input?

Read only

Former Member
0 Likes
2,349

Hi Sam,

Yes, It will give you the error as these are the mandatory fields.

Try using following data for them in the header.

Reference Transaction (obj_type) - 'IDOC'

Reference Key (obj_key) - 'TEST000001BAPICALL'

Business Transaction (bus_act) - 'RFBU'

Logical system (obj_sys) - Use the FM to fetch this ('OWN_LOGICAL_SYSTEM_GET'')

I hope this helps you.

If you want any more info, refer to the BAPI documentation or get back to me.

Regards,

Jallu

Read only

0 Likes
2,349

Hi Jallu,

Can we use BDC recording for T-Code F-43 instead of using the Function Module?

Read only

Former Member
0 Likes
2,350

Hi Sam,

Yes, you can go for that option too but i prefer using BAPI for the purpose bcoz

it is easy to use and code.

I have done a test recording for that transaction(F-43) and i dint come across any issues.

So, you can try BDC too.

Regards,

Jallu