BAPI- What is It and How Its Used

6
BAPI- What is it and how its used Source: http://www.newtosap.info/2012/06/bapi-what-is-it-and-how- its-used-part-1.html http://www.newtosap.info/2012/06/bapi-what-is-it-and-how-its-used- part-2.html Part 1 BAPI's are basically function modules only. ALL BAPI's are remote enabled function modules which enables to access via non SAP systems. A remote function enabled FM(Function Module) will be attached to BOR(Business Object Repository) , then only it is termed as BAPI. Using BAPIs you can develop applications without detailed knowledge of the underlying R/3 System. Each BAPI is having its own business application and area. The integration between R/3 and third-party software, legacy systems, and custom-developed software can be achieved via BAPI. BAPI explorer with TCODE 'BAPI'. BAPI explorer All BAPI's are arraigned according to the business area. Details documentation is also available for some BAPI's to show the usage of the BAPI

Transcript of BAPI- What is It and How Its Used

Page 1: BAPI- What is It and How Its Used

BAPI- What is it and how its used

Source: http://www.newtosap.info/2012/06/bapi-what-is-it-and-how-its-used-part-1.html

http://www.newtosap.info/2012/06/bapi-what-is-it-and-how-its-used-part-2.html

Part 1BAPI's are basically function modules only. ALL BAPI's are remote enabled function modules which enables to access via non SAP systems.

A remote function enabled FM(Function Module) will be attached to BOR(Business Object Repository) , then only it is termed as BAPI. Using BAPIs you can develop applications without detailed knowledge of the underlying R/3 System.

Each BAPI is having its own business application and area. The integration between R/3 and third-party software, legacy systems, and custom-developed software can be achieved via BAPI.

BAPI explorer with TCODE 'BAPI'.

BAPI explorerAll BAPI's are arraigned according to the business area. Details documentation is also available for some BAPI's to show the usage of the BAPI

Page 2: BAPI- What is It and How Its Used

Documentation of each BAPI

BAPI since its RFC enabled FM, has no exceptions. There are BAPI return tables which can be used to analyze the success/failure of the process.

Since BAPI's are basically FM only , we call BAPI the same way we call a normal FM.

Its very important to select appropriate BAPI and also to pass the data in a way required by BAPI. Go through all I/O structures for the BAPI selected to understand this better. We can also call BAPI of other SAP systems. Just mention destination and you are good to go.

Ex:call function 'BAPI_SALESORDER_GETSTATUS'     destination 'PW2'     exporting          salesdocument = order     importing          return        = return     tables          statusinfo    = statusinfo.

We need to call BAPI_TRANSACTION_COMMIT after each BAPI call to finalize or commit the change or if some error occurs and we have identified the errors we need to use BAPI_TRANSACTION_ROLLBACK to rollback the changes made if any.

Part 2This posts explains the steps involved in using any BAPI in report/program.

Steps in using BAPI :

1) Find out which BAPI to be used.Example: To create material found out that BAPI_MATERIAL_SAVEDATA can be used

2) Go to function builder SE37 and see the BAPI. See import and export parameters. Double click on the structure or table type to know whether the fields involved in your program/report are present or not.

3) find out which are fields you require and accordingly create variables of that type only.Avoid 'like' and use 'type' and' type table of' in case of tables.

4) Pass the values to the BAPI function. Tables parameters requires variables with Header

Page 3: BAPI- What is It and How Its Used

line. All others are just work area.

5) Always after calling BAPI call , BAPI_TRANSACTION_COMMIT to commit the changes (After each BAPI call this has to be done )

6) Keep a breakpoint and look at BAPI return. IF success it shows success message also if problem it lists the problem clearly.

BAPI RETURN TABLE

7) In case of long text . See the function documentation of BAPI. Use accordingly. Just append each text_line and there you go it will pass long text.

Example program to create/update a material along with long text description of the material.

*&---------------------------------------------------------------*& Report  ZAU_BAPITEST*&*&---------------------------------------------------------------*&*&*&---------------------------------------------------------------

REPORT  zau_bapitest.

DATA: lwa_bapihead    TYPE    bapimathead,      lwa_mara        TYPE    bapi_mara,      lwa_marax       TYPE    bapi_marax,      lit_return      TYPE    bapiret2,      lit_makt        TYPE    TABLE OF bapi_makt WITH HEADER LINE,     lit_mltx        TYPE    TABLE OF bapi_mltx WITH HEADER LINE.

lwa_bapihead-material = '14842132B'.

Page 4: BAPI- What is It and How Its Used

lwa_bapihead-ind_sector = 'T'.lwa_bapihead-matl_type = 'TROH'.lwa_bapihead-basic_view = 'X'.

lwa_mara-base_uom = 'KGS'.lwa_mara-matl_group = '00104'.

lwa_marax-matl_group = 'X'.lwa_marax-base_uom = 'X'.

lit_makt-langu = '001'.lit_makt-langu_iso = 'EN'.lit_makt-matl_desc = ' This is created by using BAPI yeah !! '.APPEND lit_makt.

lit_mltx-applobject = 'MATERIAL'.lit_mltx-text_name = lwa_bapihead-material.lit_mltx-text_id = 'GRUN'.lit_mltx-langu ='001'.lit_mltx-langu_iso = 'EN'.lit_mltx-text_line =' This is 1st line'.APPEND lit_mltx.

lit_mltx-applobject = 'MATERIAL'.lit_mltx-text_name = lwa_bapihead-material.lit_mltx-text_id = 'GRUN'.lit_mltx-langu ='001'.lit_mltx-langu_iso = 'EN'.lit_mltx-text_line =' This is 2st line'.APPEND lit_mltx.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'  EXPORTING    headdata                    =   lwa_bapihead   clientdata                   =   lwa_mara   clientdatax                  =   lwa_marax*   PLANTDATA                  =*   PLANTDATAX                 =*   FORECASTPARAMETERS         =*   FORECASTPARAMETERSX        =*   PLANNINGDATA               =*   PLANNINGDATAX              =*   STORAGELOCATIONDATA        =*   STORAGELOCATIONDATAX       =*   VALUATIONDATA              =*   VALUATIONDATAX             =*   WAREHOUSENUMBERDATA        =*   WAREHOUSENUMBERDATAX       =*   SALESDATA                  =*   SALESDATAX                 =*   STORAGETYPEDATA            =*   STORAGETYPEDATAX           =

Page 5: BAPI- What is It and How Its Used

*   FLAG_ONLINE                = ' '*   FLAG_CAD_CALL              = ' '*   NO_DEQUEUE                 = ' '*   NO_ROLLBACK_WORK           = ' 'IMPORTING   return                     =  lit_return TABLES   materialdescription        = lit_makt   materiallongtext           = lit_mltx

          .CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'* EXPORTING*   WAIT          =* IMPORTING*   RETURN        =          .

WRITE:/ lit_return-type.