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 for FB70

Former Member
0 Likes
5,355

Hi !!!

Someone knows what's the bapi that i can use as alternative by the transaction FB70 ( Customer Invoice ).

Best Regards !!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,470

BAPI_ACC_DOCUMENT_POST

read the documentation on how you can create a AR document (FB70) using the BAPI

Rishi

4 REPLIES 4
Read only

Former Member
0 Likes
2,471

BAPI_ACC_DOCUMENT_POST

read the documentation on how you can create a AR document (FB70) using the BAPI

Rishi

Read only

Former Member
0 Likes
2,470

sample code is:

REPORT zfb70.

*-----Type pool declaration

TYPE-POOLS: truxs.

*-----Structure declaration

TYPES : BEGIN OF ty_tab,

col1(30) TYPE c, "Serial No

col2(30) TYPE c, "Customer No

col3(30) TYPE c, "Company Code

col4(30) TYPE c, "Reference Document No

col5(30) TYPE c, "Document date

col6(30) TYPE c, "Posting Date

col7(30) TYPE c, "Text

col8(30) TYPE c, "Amount

col9(30) TYPE c, "Currency

col10(30) TYPE c, "G/L Account

col11(30) TYPE c, "Company Code

col12(50) TYPE c, "Amount in Doc.Currency

col13(50) TYPE c, "Currency

col14(50) TYPE c, "Profit center

col15(50) TYPE c, "Item text

END OF ty_tab,

BEGIN OF ty_header,

col1(30) TYPE c, "Serial No

col2(30) TYPE c, "Customer No

col3(30) TYPE c, "Company Code

col4(30) TYPE c, "Reference Document No

col5(30) TYPE c, "Document date

col6(30) TYPE c, "Posting Date

col7(30) TYPE c, "Text

col8(30) TYPE c, "Amount

col9(30) TYPE c, "Currency

END OF ty_header,

BEGIN OF ty_lineitem,

col10(30) TYPE c, "G/L Account

col11(30) TYPE c, "Company Code

col12(50) TYPE c, "Amount in Doc.Currency

col13(50) TYPE c, "Currency

col14(50) TYPE c, "Profit center

col15(50) TYPE c, "Item text

END OF ty_lineitem.

*-----Internal table declarations

DATA : it_tab TYPE STANDARD TABLE OF ty_tab,

it_raw TYPE truxs_t_text_data,

it_header TYPE STANDARD TABLE OF ty_header,

it_lineitem TYPE STANDARD TABLE OF ty_lineitem,

it_bapiaccr09 TYPE STANDARD TABLE OF bapiaccr09,

it_bapiacgl09 TYPE STANDARD TABLE OF bapiacgl09,

it_bapiacar09 TYPE STANDARD TABLE OF bapiacar09,

it_bapiaccr09_temp TYPE STANDARD TABLE OF bapiaccr09,"#EC NEEDED

return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,"#EC *

return1 LIKE bapiret2 OCCURS 0 WITH HEADER LINE,"#EC *

*-----Workarea declarations

x_tab LIKE LINE OF it_tab,

x_header LIKE LINE OF it_header,

x_lineitem LIKE LINE OF it_lineitem,

x_invheader TYPE bapiache09 OCCURS 0 WITH HEADER LINE,"#EC *

x_bapiaccr09 LIKE LINE OF it_bapiaccr09,

x_bapiacgl09 LIKE LINE OF it_bapiacgl09,

x_bapiacar09 LIKE LINE OF it_bapiacar09,

x_bapiaccr09_temp LIKE LINE OF it_bapiaccr09,

*-----Variables declarations

v_str1(2) TYPE c,

v_str2(2) TYPE c,

v_str3(4) TYPE c,

v_doc_date LIKE sy-datum,

v_pstng_date LIKE sy-datum,

v_obj_key TYPE bapiache09-obj_key,

v_text TYPE string,

v_customer TYPE bapiacar09-customer,

v_gl_account TYPE bapiacgl09-gl_account,

v_itemno TYPE bapiacgl09-itemno_acc,

v_itemno_1 TYPE bapiacgl09-itemno_acc,

v_amount(25) TYPE c.

----


  • SELECTION-SCREEN declaration *

----


SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 3(20) text-001 FOR FIELD p_fname.

SELECTION-SCREEN POSITION 25.

PARAMETERS: p_fname(128) TYPE c OBLIGATORY.

SELECTION-SCREEN END OF LINE.

----


  • AT SELECTION-SCREEN ON VALUE-REQUEST *

----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.

*-----Calling function for selecting the local file

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_fname.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

*-----Uploading excel file into internal table

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

i_line_header = 'X'

i_tab_raw_data = it_raw

i_filename = p_fname

TABLES

i_tab_converted_data = it_tab[]

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

LOOP AT it_tab INTO x_tab.

*-----Checking for existing data in it_header

READ TABLE it_header INTO x_header WITH KEY col1 = x_tab-col1

col2 = x_tab-col2

col3 = x_tab-col3

col4 = x_tab-col4

col5 = x_tab-col5

col6 = x_tab-col6

col7 = x_tab-col7

col8 = x_tab-col8

col9 = x_tab-col9.

IF sy-subrc NE 0.

IF x_header IS NOT INITIAL.

*-----calling bapi for creating customer invoice

PERFORM call_bapi.

REFRESH : it_header, it_lineitem.

ENDIF.

*-----making header table

x_header-col1 = x_tab-col1.

x_header-col2 = x_tab-col2.

x_header-col3 = x_tab-col3.

x_header-col4 = x_tab-col4.

x_header-col5 = x_tab-col5.

x_header-col6 = x_tab-col6.

x_header-col7 = x_tab-col7.

x_header-col8 = x_tab-col8.

x_header-col9 = x_tab-col9.

x_lineitem-col10 = x_tab-col10.

x_lineitem-col11 = x_tab-col11.

x_lineitem-col12 = x_tab-col12.

x_lineitem-col13 = x_tab-col13.

x_lineitem-col14 = x_tab-col14.

x_lineitem-col15 = x_tab-col15.

APPEND x_header TO it_header.

APPEND x_lineitem TO it_lineitem.

ELSE.

x_lineitem-col10 = x_tab-col10.

x_lineitem-col11 = x_tab-col11.

x_lineitem-col12 = x_tab-col12.

x_lineitem-col13 = x_tab-col13.

x_lineitem-col14 = x_tab-col14.

x_lineitem-col15 = x_tab-col15.

APPEND x_lineitem TO it_lineitem.

ENDIF.

ENDLOOP.

*-----Calling BAPI for last set of data

PERFORM call_bapi.

REFRESH : it_header, it_lineitem.

----


  • Form call_bapi *

----


FORM call_bapi.

*-----Formatting invoice date

SPLIT x_header-col5 AT '.' INTO v_str1 v_str2 v_str3.

IF STRLEN( v_str1 ) LT 2.

CONCATENATE '0' v_str1 INTO v_str1.

ENDIF.

IF STRLEN( v_str2 ) LT 2.

CONCATENATE '0' v_str2 INTO v_str2.

ENDIF.

IF STRLEN( v_str3 ) LT 4.

CONCATENATE '20' v_str3 INTO v_str3.

ENDIF.

CONCATENATE v_str3 v_str1 v_str2 INTO v_doc_date.

CLEAR : v_str1, v_str2, v_str3.

*-----Formatting posting date

SPLIT x_header-col6 AT '.' INTO v_str1 v_str2 v_str3.

IF STRLEN( v_str1 ) LT 2.

CONCATENATE '0' v_str1 INTO v_str1.

ENDIF.

IF STRLEN( v_str2 ) LT 2.

CONCATENATE '0' v_str2 INTO v_str2.

ENDIF.

IF STRLEN( v_str3 ) LT 4.

CONCATENATE '20' v_str3 INTO v_str3.

ENDIF.

CONCATENATE v_str3 v_str1 v_str2 INTO v_pstng_date.

CLEAR : v_str1, v_str2, v_str3.

*-----Making the Header

x_invheader-obj_type = 'BKPFF'. "Reference procedure

x_invheader-obj_key = '$'. "Object key

CONCATENATE sy-sysid 'CLNT' sy-mandt INTO

x_invheader-obj_sys. "Logical system of source document

x_invheader-bus_act = 'RFBU'. "Business Transaction

x_invheader-username = sy-uname. "User name

x_invheader-header_txt = x_header-col7. "Document Header Text

x_invheader-comp_code = x_header-col3. "Company Code

x_invheader-doc_date = v_doc_date. "Document Date in Document

x_invheader-pstng_date = v_pstng_date. "Posting Date in the Document

x_invheader-doc_type = 'DR'. "Reference Document Number

x_invheader-ref_doc_no = x_header-col4. "Reference Document Number

*-----For ACCOUNTRECEIVABLE

LOOP AT it_header INTO x_header.

x_bapiacar09-itemno_acc = '1'. "Accounting Document Line Item Number

*-----Filling zeros before Customer No

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = x_header-col2

IMPORTING

output = v_customer.

x_bapiacar09-customer = v_customer. "Customer Number 1

x_bapiacar09-comp_code = x_header-col3. "Company Code

APPEND x_bapiacar09 TO it_bapiacar09.

ENDLOOP.

*-----For ACCOUNTGL

LOOP AT it_lineitem INTO x_lineitem.

IF it_bapiacgl09 IS INITIAL.

v_itemno = 2.

ELSE.

v_itemno = v_itemno + 1.

ENDIF.

x_bapiacgl09-itemno_acc = v_itemno. "Accounting Document Line Item Number

*-----Filling zeros before G/L Account no

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = x_lineitem-col10

IMPORTING

output = v_gl_account.

x_bapiacgl09-gl_account = v_gl_account. "General Ledger Account

x_bapiacgl09-comp_code = x_lineitem-col11. "Company Code

x_bapiacgl09-profit_ctr = x_lineitem-col14. "Profit Center

x_bapiacgl09-item_text = x_lineitem-col15. "Item Text

APPEND x_bapiacgl09 TO it_bapiacgl09.

ENDLOOP.

*-----Clearing variable

CLEAR : v_itemno.

*-----For CURRENCYAMOUNT

LOOP AT it_header INTO x_header.

x_bapiaccr09-itemno_acc = '0000000001'. "Accounting Document Line Item Number

x_bapiaccr09-curr_type = '00'. "Currency type and valuation view

x_bapiaccr09-amt_doccur = x_header-col8. "Amount in document currency

x_bapiaccr09-currency = x_header-col9. "Currency Key

APPEND x_bapiaccr09 TO it_bapiaccr09.

ENDLOOP.

v_itemno_1 = 1.

LOOP AT it_lineitem INTO x_lineitem.

v_itemno_1 = v_itemno_1 + 1.

x_bapiaccr09_temp-itemno_acc = v_itemno_1. "Accounting Document Line Item Number

x_bapiaccr09_temp-curr_type = '00'. "Currency type and valuation view

CONCATENATE '-' x_lineitem-col12 INTO v_amount.

x_bapiaccr09_temp-amt_doccur = v_amount. "x_lineitem-col12. "Amount in document currency

x_bapiaccr09_temp-currency = x_lineitem-col13. "Currency Key

APPEND x_bapiaccr09_temp TO it_bapiaccr09.

ENDLOOP.

CLEAR : v_itemno_1.

*-----Calling BAPI for creating Customer Invoice

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = x_invheader

IMPORTING

obj_key = v_obj_key

TABLES

accountgl = it_bapiacgl09

accountreceivable = it_bapiacar09

currencyamount = it_bapiaccr09

return = return.

*-----Check the return code for error message.

LOOP AT return

TRANSPORTING NO FIELDS

WHERE type = 'E' OR type = 'A'.

EXIT.

ENDLOOP.

*-----Generating errors (if any)

IF sy-subrc = 0.

WRITE : text-003, x_header-col1. "Serial No :

WRITE 😕 text-002. "Invoice Not Created Because :

LOOP AT return. "#EC *

WRITE:/ "return-type,

return-message.

ENDLOOP.

ULINE :/(150).

ELSE.

*-----BAPI Commit

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'

IMPORTING

return = return1.

*-----Displaying invoice no as Success message

WRITE : text-003, x_header-col1. "Serial No :

CONCATENATE 'Invoice No. ' v_obj_key+0(10) ' Created ' INTO v_text."#EC NOTEXT

WRITE 😕 v_text.

ULINE :/(150).

ENDIF.

*-----Refreshing internal tables

REFRESH : it_bapiaccr09, it_bapiacgl09, it_bapiacar09, it_bapiaccr09_temp, return.

ENDFORM. " call_bapi

Read only

0 Likes
2,470

This message was moderated.

Read only

Former Member
0 Likes
2,470

Hi Saha,

Can you send me the sample file your are uploading for the above given sample code.