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: 

BAPI

Former Member
0 Kudos

Hi experts,

Can any tell me What is the use of BAPI and where it can be used.

Pls give me a example code for BAPI.

Regards.

Murugan Arumugam

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Murugan,

BAPI stands for Business API(Application Program Interface).

A BAPI is remotely enabled function module ie it can be invoked from remote programs like standalone JAVA programs, web interface etc..

You can make your function module remotely enabled in attributes of Function module but

A BAPI are standard SAP function modules provided by SAP for remote access. Also they are part of Businees Objest Repository(BOR).

BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects.

You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA.

in this case u only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types.

These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs.

Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.

Check the following thread for more info on BAPIs & also for sample code:

For BAPI programming Tcode - <b>BAPI</b>

BAPI programming guide:

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/CABFABAPIREF/CABFABAPIPG.pdf

BAPI user guide:

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCMIDAPII/CABFAAPIINTRO.pdf

For creating a RFC - SE37

RFC is a remote-enabled Function Module.

Create a function module with attributes Remote-enabled.

RFC programming in ABAP:

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCFESDE2/BCFESDE2.pdf

best regards,

Thangesh

6 REPLIES 6

Former Member
0 Kudos

hi murugan

we are using RFC for SAP TO SAP communication

BAPI for SAP TO NON SAP communication in short words

BAPI IS NOTHING BUT Remote Enabled Function Module.....

create function module with remote enabled put the export paramater as bapi return ........................................

Release the function module

come to SWO1

create as business object repository

add this method to BOR object

built the all components

and release all the components

simple making of bapi.......

Former Member
0 Kudos

Hi Murugan,

BAPI stands for Business API(Application Program Interface).

A BAPI is remotely enabled function module ie it can be invoked from remote programs like standalone JAVA programs, web interface etc..

You can make your function module remotely enabled in attributes of Function module but

A BAPI are standard SAP function modules provided by SAP for remote access. Also they are part of Businees Objest Repository(BOR).

BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects.

You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA.

in this case u only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types.

These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs.

Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.

Check the following thread for more info on BAPIs & also for sample code:

For BAPI programming Tcode - <b>BAPI</b>

BAPI programming guide:

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/CABFABAPIREF/CABFABAPIPG.pdf

BAPI user guide:

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCMIDAPII/CABFAAPIINTRO.pdf

For creating a RFC - SE37

RFC is a remote-enabled Function Module.

Create a function module with attributes Remote-enabled.

RFC programming in ABAP:

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCFESDE2/BCFESDE2.pdf

best regards,

Thangesh

0 Kudos

Hi, Thangeswaran T.K ,

Can u tell me some words about mass data transfer using BAPI.

regards,

Murugan Arumugam.

0 Kudos

Hi Murugan,

You can do mass data transfer using BAPI.

For example, if you want to udate the Customer Master with bulk data, you can use the following BAPI:

BAPI_CUSTOMER_CREATEFROMDATA1

You can get the input from a txt file into an internal table & from the internal table you can pass the data to this BAPI.

Goto to transaction code <b>BAPI</b> to find more about BAPIs.

You can find the list of BAPIs used for each application.

There are separate set of BAPIs to update Master data as well as Transaction data.

Reward points for helpful answers!

best regards,

Thangesh

Former Member
0 Kudos

Hi,

SAP created the Business Framework to allow the technical integration and exchange of business data among SAP components and between SAP and non-SAP components. Important components of the Business Framework are the Business Application Programming Interfaces (BAPIs), which represent visible interfaces at the component boundaries and whose properties serve to integrate these components.

The integration can include both components within a local network and components that are connected with one another through the Internet.

BAPIs allow integration at the business level, not the technical level. This provides for greater stability in the link, and independence from the underlying communication technology.

You can get all the standard SAP BAPI functions with the transactions code 'BAPI'.

For more information check the following link:

http://sap-img.com/bapi.htm

http://www.sapbrainsonline.com/TUTORIALS/TECHNICAL/BAPI_tutorial.html

http://sapmaterial.com/bapi.html

Regards,

Bhaskar

Former Member
0 Kudos

Hi,

Exapansion for BAPI is Business Application Programming Interface.

It is a Remote Enabled Fucntion module. There are standard BAPI's which u can use. Mainly for uploading data from legacy to SAP we use BAPI. For example,

Inquiry - BAPI_INQUIRY_CREATEFROMDATA2

Quotation - BAPI_QUOTATION_CREATEFROMDATA2

Proposals -

Sales Order - BAPI_SALESORDER_CREATEFROMDAT2

Goods Issue - BAPI_GOODSMVT_CREATE

Refer the following code,

REPORT zsample_bapi_va01.

TYPES : BEGIN OF ty_so,

ind,

vkorg(4), "VBAK - Sales Organization

vtweg(2), "VBAK - Distribution Channel

spart(2), "VBAK - Division

vbeln(10), "VBAK - Sales Document

ketdat(8), "Requested delivery date of the document - Sales Order Data

vkbur(4), "VBAK - Sales office

kunnr1(10), "VBPA - Sold-to party

kunnr2(10), "VBPA - Ship-To Party

bstkd(35), "VBKD - Customer purchase order number

zterm(4), "VBKD - Terms of payment key

augru(3), "VBAK - Order reason

mabnr(18), "Material Number

kwmeng(15), "Cumulative order quantity in sales units

vrkme(3), "VBAP - Sales unit

werks(4), "VBAP - Plant (Own or External)

vstel(4), "VBAP - Shipping Point/Receiving Point

kbetr1(11), "KONV - Rate (condition amount or percentage)

kbetr2(11), "KONV - Rate (condition amount or percentage)

prctr(10), "Profit Center

END OF ty_so.

DATA : it_so TYPE STANDARD TABLE OF ty_so,

it_so1 TYPE STANDARD TABLE OF ty_so,

v_order_header_in LIKE bapisdhd1,

v_salesdocumentin LIKE bapivbeln-vbeln,

v_order_partners LIKE bapiparnr OCCURS 0 WITH HEADER LINE,

v_order_items_in LIKE bapisditm OCCURS 0,

v_order_conditions_in LIKE bapicond OCCURS 0,

v_order_schedules_in LIKE bapischdl OCCURS 0,

order_header_inx LIKE bapisdhd1x,

order_items_inx LIKE bapisditmx OCCURS 0 WITH HEADER LINE,

order_schedules_inx LIKE bapischdlx OCCURS 0 WITH HEADER LINE,

order_conditions_inx LIKE bapicondx OCCURS 0 WITH HEADER LINE,

it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

FIELD-SYMBOLS : <fs_so> TYPE ty_so, <fs_so1> LIKE LINE OF it_so.

DATA : wa_bapisditm LIKE bapisditm,

wa_bapicond LIKE bapicond,

wa_bapischdl LIKE bapischdl,

w_schditm LIKE bapischdl-sched_line,

w_itemno(6) TYPE n,

w_profit_ctr LIKE bapisditm-profit_ctr,

mesid(2) TYPE c.

PARAMETERS : testrun AS CHECKBOX DEFAULT 'X'.

CALL FUNCTION 'UPLOAD'

EXPORTING

filetype = 'DAT'

TABLES

data_tab = it_so

EXCEPTIONS

conversion_error = 1

invalid_table_width = 2

invalid_type = 3

no_batch = 4

unknown_error = 5

gui_refuse_filetransfer = 6

OTHERS = 7

.

IF sy-subrc <> 0.

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

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

ENDIF.

*CALL FUNCTION 'GUI_UPLOAD'

  • EXPORTING

  • filename = 'C:\Documents and Settings\Desktop\SO.TXT'

  • filetype = 'ASC'

  • has_field_separator = 'X'

  • TABLES

  • data_tab = it_so

  • EXCEPTIONS

  • file_open_error = 1

  • file_read_error = 2

  • no_batch = 3

  • gui_refuse_filetransfer = 4

  • invalid_type = 5

  • no_authority = 6

  • unknown_error = 7

  • bad_data_format = 8

  • header_not_allowed = 9

  • separator_not_allowed = 10

  • header_too_long = 11

  • unknown_dp_error = 12

  • access_denied = 13

  • dp_out_of_memory = 14

  • disk_full = 15

  • dp_timeout = 16

  • OTHERS = 17.

*IF sy-subrc <> 0.

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

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

*ENDIF.

it_so1[] = it_so[].

DELETE it_so WHERE ind = 'D'.

DELETE it_so1 WHERE ind = 'H'.

order_header_inx-updateflag = 'I'.

order_header_inx-doc_type = 'X'.

order_header_inx-sales_org = 'X'.

order_header_inx-distr_chan = 'X'.

order_header_inx-division = 'X'.

order_header_inx-sales_off = 'X'.

order_header_inx-pmnttrms = 'X'.

order_header_inx-ord_reason = 'X'.

order_header_inx-purch_no_c = 'X'.

order_header_inx-req_date_h ='X'.

order_header_inx-date_type = 'X'.

LOOP AT it_so ASSIGNING <fs_so>.

CLEAR : v_order_header_in, v_salesdocumentin, v_order_partners[], v_order_items_in[], v_order_conditions_in[], v_order_conditions_in[],

order_items_inx[], order_conditions_inx[], v_order_schedules_in[], order_schedules_inx[].

v_order_header_in-doc_type = 'ZDEP'.

v_order_header_in-sales_org = <fs_so>-vkorg.

v_order_header_in-distr_chan = <fs_so>-vtweg.

v_order_header_in-division = <fs_so>-spart.

v_order_header_in-sales_off = <fs_so>-vkbur.

v_order_header_in-pmnttrms = <fs_so>-zterm.

v_order_header_in-ord_reason = <fs_so>-augru.

v_order_header_in-purch_no_c = <fs_so>-bstkd.

v_order_header_in-req_date_h = <fs_so>-ketdat.

v_order_header_in-date_type = '1'.

v_salesdocumentin = <fs_so>-vbeln.

w_itemno = 10.

CLEAR wa_bapisditm.

wa_bapisditm-itm_number = w_itemno.

wa_bapisditm-material = <fs_so>-mabnr.

wa_bapisditm-sales_unit = <fs_so>-vrkme.

wa_bapisditm-net_weight = <fs_so>-kwmeng.

wa_bapisditm-untof_wght = <fs_so>-vrkme.

wa_bapisditm-plant = <fs_so>-werks.

wa_bapisditm-ship_point = <fs_so>-vstel.

wa_bapisditm-profit_ctr = <fs_so>-prctr.

APPEND wa_bapisditm TO v_order_items_in.

order_items_inx-itm_number = w_itemno.

order_items_inx-updateflag = 'I'.

order_items_inx-material = 'X'.

order_items_inx-sales_unit = 'X'.

order_items_inx-net_weight = 'X'.

order_items_inx-untof_wght = 'X'.

order_items_inx-plant = 'X'.

order_items_inx-ship_point = 'X'.

order_items_inx-profit_ctr = 'X'.

APPEND order_items_inx.

v_order_partners-partn_role = 'AG'. "Sold-to-Party

v_order_partners-partn_numb = <fs_so>-kunnr1.

APPEND v_order_partners.

v_order_partners-partn_role = 'WE'. "Ship-to-Party

v_order_partners-partn_numb = <fs_so>-kunnr2.

APPEND v_order_partners.

CLEAR wa_bapischdl.

w_schditm = 1.

wa_bapischdl-itm_number = w_itemno.

wa_bapischdl-sched_line = w_schditm.

wa_bapischdl-req_date = <fs_so>-ketdat.

wa_bapischdl-date_type = '1'.

wa_bapischdl-req_qty = <fs_so>-kwmeng.

wa_bapischdl-sched_type = 'CP'.

wa_bapischdl-dlv_date = <fs_so>-ketdat.

APPEND wa_bapischdl TO v_order_schedules_in.

order_schedules_inx-itm_number = w_itemno.

order_schedules_inx-updateflag = 'I'.

order_schedules_inx-sched_line = 'X'.

order_schedules_inx-req_date = 'X'.

order_schedules_inx-date_type = 'X'.

order_schedules_inx-req_qty = 'X'.

order_schedules_inx-sched_type = 'X'.

order_schedules_inx-dlv_date = 'X'.

APPEND order_schedules_inx.

CLEAR wa_bapicond.

wa_bapicond-itm_number = w_itemno.

wa_bapicond-cond_type = 'ZDPR'.

wa_bapicond-cond_value = <fs_so>-kbetr1.

wa_bapicond-currency = 'INR'.

APPEND wa_bapicond TO v_order_conditions_in.

wa_bapicond-cond_type = 'ZDBV'.

wa_bapicond-cond_value = <fs_so>-kbetr2.

APPEND wa_bapicond TO v_order_conditions_in.

CLEAR order_conditions_inx.

order_conditions_inx-itm_number = w_itemno.

order_conditions_inx-cond_type = 'ZDPR'.

order_conditions_inx-updateflag = 'I'.

order_conditions_inx-cond_value = 'X'.

order_conditions_inx-currency = 'X'.

APPEND order_conditions_inx.

order_conditions_inx-cond_type = 'ZDBV'.

APPEND order_conditions_inx.

LOOP AT it_so1 ASSIGNING <fs_so1> WHERE vbeln = <fs_so>-vbeln.

CLEAR wa_bapisditm.

ADD 10 TO w_itemno.

wa_bapisditm-itm_number = w_itemno.

wa_bapisditm-material = <fs_so1>-mabnr.

wa_bapisditm-sales_unit = <fs_so1>-vrkme.

wa_bapisditm-net_weight = <fs_so1>-kwmeng.

wa_bapisditm-untof_wght = <fs_so1>-vrkme.

wa_bapisditm-plant = <fs_so1>-werks.

wa_bapisditm-ship_point = <fs_so1>-vstel.

wa_bapisditm-profit_ctr = <fs_so1>-prctr.

APPEND wa_bapisditm TO v_order_items_in.

order_items_inx-itm_number = w_itemno.

order_items_inx-updateflag = 'I'.

order_items_inx-material = 'X'.

order_items_inx-sales_unit = 'X'.

order_items_inx-net_weight = 'X'.

order_items_inx-untof_wght = 'X'.

order_items_inx-plant = 'X'.

order_items_inx-ship_point = 'X'.

order_items_inx-profit_ctr = 'X'.

APPEND order_items_inx.

CLEAR wa_bapischdl.

ADD 1 TO w_schditm.

wa_bapischdl-itm_number = w_itemno.

wa_bapischdl-sched_line = w_schditm.

wa_bapischdl-req_date = <fs_so1>-ketdat.

wa_bapischdl-date_type = '1'.

wa_bapischdl-req_qty = <fs_so1>-kwmeng.

wa_bapischdl-sched_type = 'CP'.

wa_bapischdl-dlv_date = <fs_so1>-ketdat.

APPEND wa_bapischdl TO v_order_schedules_in.

order_schedules_inx-itm_number = w_itemno.

order_schedules_inx-updateflag = 'I'.

order_schedules_inx-sched_line = 'X'.

order_schedules_inx-req_date = 'X'.

order_schedules_inx-date_type = 'X'.

order_schedules_inx-req_qty = 'X'.

order_schedules_inx-sched_type = 'X'.

order_schedules_inx-dlv_date = 'X'.

APPEND order_schedules_inx.

CLEAR wa_bapicond.

wa_bapicond-itm_number = w_itemno.

wa_bapicond-cond_type = 'ZDPR'.

wa_bapicond-cond_value = <fs_so1>-kbetr1.

wa_bapicond-currency = 'INR'.

APPEND wa_bapicond TO v_order_conditions_in.

wa_bapicond-cond_type = 'ZDBV'.

wa_bapicond-cond_value = <fs_so1>-kbetr2.

APPEND wa_bapicond TO v_order_conditions_in.

order_conditions_inx-itm_number = w_itemno.

order_conditions_inx-cond_type = 'ZDPR'.

order_conditions_inx-updateflag = 'I'.

order_conditions_inx-cond_value = 'X'.

order_conditions_inx-currency = 'X'.

APPEND order_conditions_inx.

order_conditions_inx-cond_type = 'ZDBV'.

APPEND order_conditions_inx.

ENDLOOP.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

salesdocumentin = v_salesdocumentin

order_header_in = v_order_header_in

order_header_inx = order_header_inx

testrun = testrun

TABLES

return = it_return

order_items_in = v_order_items_in

order_items_inx = order_items_inx

order_partners = v_order_partners

order_conditions_in = v_order_conditions_in

order_conditions_inx = order_conditions_inx

order_schedules_in = v_order_schedules_in

order_schedules_inx = order_schedules_inx.

  • CALL FUNCTION 'BAPI_SALESDOCU_CREATEWITHDIA'

  • EXPORTING

  • salesdocument = v_salesdocumentin

  • sales_header_in = v_order_header_in

  • sales_header_inx = order_header_inx

*

  • TABLES

  • return = it_return

  • sales_items_in = v_order_items_in

  • sales_items_inx = order_items_inx

  • sales_partners = v_order_partners

  • sales_schedules_in = v_order_schedules_in

  • sales_schedules_inx = order_schedules_inx

  • sales_conditions_in = v_order_conditions_in

  • sales_conditions_inx = order_conditions_inx.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

LOOP AT it_return.

mesid = it_return-id+0(2).

CONDENSE mesid.

WRITE 😕 it_return-type, mesid, it_return-number, it_return-message+0(80).

ENDLOOP.

ENDLOOP.

Reward if useful.

Message was edited by:

Sathya