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 Related

Former Member
0 Kudos
223

Hi,

I got a requirement in BAPI..so provide me step by step (Snap shots would preffered ) what is BAPI...How to find a BAPI for a particular Transaction / Program..and how to implement a BAPI..

Thanks

Rajiv

Edited by: Rajiv Kumar Garg on Mar 27, 2008 6:59 AM

5 REPLIES 5

Former Member
0 Kudos
111

Hi,

i will provide na sample code for material master craetion bapi you wiull get an idea

instead of bdc we use bapi

*&---------------------------------------------------------------------*
REPORT ZKAR_MATMAS_BAPI.
*----------------------------------------------------------------------*

* TABLES

*----------------------------------------------------------------------*
*----------------------------------------------------------------------*

* FLAGS *

*----------------------------------------------------------------------*
DATA: F_STOP. " Flag used to stop processing
*----------------------------------------------------------------------*

* DATA DECLARATIONS *

*----------------------------------------------------------------------*
DATA : V_EMPTY TYPE I, " No. of empty records

V_TOTAL TYPE I. " Total no. of records.
*----------------------------------------------------------------------*

* STRUCTURES & INTERNAL TABLES

*----------------------------------------------------------------------*
*BAPI structures

*----------------------------------------------------------------------*

DATA: BAPI_HEAD LIKE BAPIMATHEAD, " Header Segment with Control Information

BAPI_MAKT LIKE BAPI_MAKT, " Material Description

BAPI_MARA1 LIKE BAPI_MARA, " Client Data

BAPI_MARAX LIKE BAPI_MARAX, " Checkbox Structure for BAPI_MARA

BAPI_MARC1 LIKE BAPI_MARC, " Plant View

BAPI_MARCX LIKE BAPI_MARCX, " Checkbox Structure for BAPI_MARC

BAPI_MBEW1 LIKE BAPI_MBEW, " Accounting View

BAPI_MBEWX LIKE BAPI_MBEWX, " Checkbox Structure for BAPI_MBEW

BAPI_RETURN LIKE BAPIRET2. " Return Parameter

*--- Internal table to hold excel file data

DATA: IT_INTERN TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.

*--- Internal table to hold Matetrial descriptions

DATA: BEGIN OF IT_MAKT OCCURS 100.

        INCLUDE STRUCTURE BAPI_MAKT.

DATA: END OF IT_MAKT.

*--- Internal to hold the records in the text file

DATA : BEGIN OF IT_DATA OCCURS 100,

            WERKS(4), " Plant

            MTART(4), " Material type

            MATNR(18), " Material number

            MATKL(9) , " Material group

            MBRSH(1), " Industry sector

            MEINS(3), " Base unit of measure

            GEWEI(3), " Weight Unit

            SPART(2), " Division

            EKGRP(3), " Purchasing group

            VPRSV(1), " Price control indicator

            STPRS(12), " Standard price

            PEINH(3), " Price unit

            SPRAS(2), " Language key

            MAKTX(40), " Material description

            END OF IT_DATA.

*----------------------------------------------------------------------*

* SELECTION SCREEN. *

*----------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK SCR1 WITH FRAME TITLE TEXT-111.

PARAMETER : P_FILE TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT " Input File

'C:\Material_master.XLS'.

PARAMETER : P_MAX(4) OBLIGATORY DEFAULT '100'. " no.of recs in a session

PARAMETERS: P_HEADER TYPE I DEFAULT 0. " Header Lines

PARAMETERS: P_BEGCOL TYPE I DEFAULT 1 NO-DISPLAY,

P_BEGROW TYPE I DEFAULT 1 NO-DISPLAY,

P_ENDCOL TYPE I DEFAULT 100 NO-DISPLAY,

P_ENDROW TYPE I DEFAULT 32000 NO-DISPLAY.

SELECTION-SCREEN END OF BLOCK SCR1.

*---------------------------------------------------------------------*

* AT SELECTION-SCREEN *

*---------------------------------------------------------------------*

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

*--- Validating file

  PERFORM VALIDATE_FILE USING P_FILE.

*----------------------------------------------------------------------*

* START-OF-SELECTION

*----------------------------------------------------------------------*

START-OF-SELECTION.

*--- Perform to convert the Excel data into an internal table

  PERFORM CONVERT_XLS_ITAB.

  IF NOT IT_DATA[] IS INITIAL.

*--- Perform to delete Header lines

    PERFORM DELETE_HEADER_EMPTY_RECS.

  ENDIF.

*----------------------------------------------------------------------*

* END OF SELECTION. *

*----------------------------------------------------------------------*

END-OF-SELECTION.

*--- Perform to upload Material Master data

  PERFORM UPLOAD_MATMAS.

*----------------------------------------------------------------------*

* Form : validate_input_file

*----------------------------------------------------------------------*

* Description : To provide F4 help for file if read from PC

*----------------------------------------------------------------------*

FORM VALIDATE_FILE USING F_FILE TYPE RLGRAP-FILENAME.

  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    CHANGING
      FILE_NAME     = F_FILE
    EXCEPTIONS
      MASK_TOO_LONG = 1
      OTHERS        = 2.

  IF SY-SUBRC <> 0.

    MESSAGE S010(ZLKPL_MSGCLASS). " 'Error in getting filename'.

  ENDIF.

ENDFORM. " validate_input_file

*&---------------------------------------------------------------------*

*& Form CONVER_XLS_ITAB

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

FORM CONVERT_XLS_ITAB.

  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      FILENAME    = P_FILE
      I_BEGIN_COL = P_BEGCOL
      I_BEGIN_ROW = P_BEGROW
      I_END_COL   = P_ENDCOL
      I_END_ROW   = P_ENDROW
    TABLES
      INTERN      = IT_INTERN.

  IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

*--- Perform to move the data into an internal data

  PERFORM MOVE_DATA.

ENDFORM. " CONVERT_XLS_ITAB

*&---------------------------------------------------------------------*

*& Form MOVE_DATA

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

FORM MOVE_DATA.

  DATA : LV_INDEX TYPE I.

  FIELD-SYMBOLS <FS>.

*--- Sorting the internal table

  SORT IT_INTERN BY ROW COL.

  CLEAR IT_INTERN.

  LOOP AT IT_INTERN.

    MOVE IT_INTERN-COL TO LV_INDEX.

*--- Assigning the each record to an internal table row

    ASSIGN COMPONENT LV_INDEX OF STRUCTURE IT_DATA TO <FS>.

*--- Asigning the field value to a field symbol

    MOVE IT_INTERN-VALUE TO <FS>.

    AT END OF ROW.

      APPEND IT_DATA.

      CLEAR IT_DATA.

    ENDAT.

  ENDLOOP.

ENDFORM. " MOVE_DATA

*&---------------------------------------------------------------------*

*& Form DELETE_HEADER_EMPTY_RECS

*&---------------------------------------------------------------------*

* To delete the Header and empty records

*----------------------------------------------------------------------*

FORM DELETE_HEADER_EMPTY_RECS.

  DATA: LV_TABIX LIKE SY-TABIX.

  IF NOT P_HEADER IS INITIAL.

    LOOP AT IT_DATA.

      IF P_HEADER > 0 AND NOT IT_DATA IS INITIAL.

        DELETE IT_DATA FROM 1 TO P_HEADER.

* P_HEADER = 0.

        EXIT.

      ENDIF.

    ENDLOOP.

  ENDIF.

  CLEAR IT_DATA.

*--- To delete the empty lines from internal table

  LOOP AT IT_DATA.

    LV_TABIX = SY-TABIX.

    IF IT_DATA IS INITIAL.

      V_EMPTY = V_EMPTY + 1.

      DELETE IT_DATA INDEX LV_TABIX..

    ENDIF.

  ENDLOOP.

  CLEAR IT_DATA.

*--- Total no of recs in file

  DESCRIBE TABLE IT_DATA LINES V_TOTAL.

  IF V_TOTAL = 0.

    MESSAGE I013(ZLKPL_MSGCLASS). " No records in the file

    F_STOP = 'X'.

    STOP.

  ENDIF.

ENDFORM. " DELETE_HEADER_EMPTY_RECS

*&---------------------------------------------------------------------*

*& Form UPLOAD_MATMAS

*&---------------------------------------------------------------------*

* to upload Material Master data

*----------------------------------------------------------------------*

FORM UPLOAD_MATMAS .

  LOOP AT IT_DATA.

* Header
    UNPACK IT_DATA-MATNR TO IT_DATA-MATNR.
    BAPI_HEAD-MATERIAL = IT_DATA-MATNR.

    BAPI_HEAD-IND_SECTOR = IT_DATA-MBRSH.

    BAPI_HEAD-MATL_TYPE = IT_DATA-MTART.

    BAPI_HEAD-BASIC_VIEW = 'X'.

    BAPI_HEAD-PURCHASE_VIEW = 'X'.

    BAPI_HEAD-ACCOUNT_VIEW = 'X'.

* Material Description

    REFRESH IT_MAKT.

    IT_MAKT-LANGU = IT_DATA-SPRAS.

    IT_MAKT-MATL_DESC = IT_DATA-MAKTX.

    APPEND IT_MAKT.

* Client Data - Basic

    BAPI_MARA1-MATL_GROUP = IT_DATA-MATKL.

    BAPI_MARA1-BASE_UOM = IT_DATA-MEINS.

    BAPI_MARA1-UNIT_OF_WT = IT_DATA-GEWEI.

    BAPI_MARA1-DIVISION = IT_DATA-SPART.

    BAPI_MARAX-MATL_GROUP = 'X'.

    BAPI_MARAX-BASE_UOM = 'X'.

    BAPI_MARAX-UNIT_OF_WT = 'X'.

    BAPI_MARAX-DIVISION = 'X'.

* Plant - Purchasing

    BAPI_MARC1-PLANT = IT_DATA-WERKS.

    BAPI_MARC1-PUR_GROUP = IT_DATA-EKGRP.

    BAPI_MARCX-PLANT = IT_DATA-WERKS.

    BAPI_MARCX-PUR_GROUP = 'X'.

* Accounting

    BAPI_MBEW1-VAL_AREA = IT_DATA-WERKS.

    BAPI_MBEW1-PRICE_CTRL = IT_DATA-VPRSV.

    BAPI_MBEW1-STD_PRICE = IT_DATA-STPRS.

    BAPI_MBEW1-PRICE_UNIT = IT_DATA-PEINH.

    BAPI_MBEWX-VAL_AREA = IT_DATA-WERKS.

    BAPI_MBEWX-PRICE_CTRL = 'X'.

    BAPI_MBEWX-STD_PRICE = 'X'.

    BAPI_MBEWX-PRICE_UNIT = 'X'.

*--- BAPI to create material

    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

    EXPORTING

    HEADDATA = BAPI_HEAD

    CLIENTDATA = BAPI_MARA1

    CLIENTDATAX = BAPI_MARAX

    PLANTDATA = BAPI_MARC1

    PLANTDATAX = BAPI_MARCX

* FORECASTPARAMETERS =

* FORECASTPARAMETERSX =

* PLANNINGDATA =

* PLANNINGDATAX =

* STORAGELOCATIONDATA =

* STORAGELOCATIONDATAX =

* VALUATIONDATA = BAPI_MBEW1

* VALUATIONDATAX = BAPI_MBEWX

* WAREHOUSENUMBERDATA =

* WAREHOUSENUMBERDATAX =

* SALESDATA = BAPI_MVKE1

* SALESDATAX = BAPI_MVKEX

* STORAGETYPEDATA =

* STORAGETYPEDATAX =

    IMPORTING

    RETURN = BAPI_RETURN

    TABLES

    MATERIALDESCRIPTION = IT_MAKT

* UNITSOFMEASURE =

* UNITSOFMEASUREX =

* INTERNATIONALARTNOS =

* MATERIALLONGTEXT =

* TAXCLASSIFICATIONS =

* RETURNMESSAGES =

* PRTDATA =

* PRTDATAX =

* EXTENSIONIN =

* EXTENSIONINX =

    .

    IF BAPI_RETURN-TYPE = 'E'.

      WRITE:/ 'Error:' ,BAPI_RETURN-MESSAGE ,'for material:' ,IT_DATA-MATNR.

    ELSEIF BAPI_RETURN-TYPE = 'S'.

      WRITE: 'Successfully created material' ,IT_DATA-MATNR.

    ENDIF.

  ENDLOOP.

ENDFORM. " UPLOAD_MATMAS

Regards,

V.Balaji

Reward if Usefull...

Former Member
0 Kudos
111

Hi,

Try this link

[http://www.erpgenie.com/abap/bapi/example.htm]

[https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/200dd1cc-589e-2910-98a9-bb2c48b78dfa]

Reward if useful

REGARDS

Sandipan

Edited by: Sandipan Ghosh on Mar 27, 2008 12:02 PM

Former Member
0 Kudos
111

http://www.sapmaterial.com/?gclid=CN322K28t4sCFQ-WbgodSGbK2g....>ALL

STEP BY STEP for BAPI

http://sap-img.com/abap/bapi-step-by-step-guidance.htm

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

http://techrepublic.com.com/5100-6329-1051160.html#

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

http://www.sap-img.com/abap/bapi-conventions.htm

http://www.sappoint.com/abap/bapiintro.pdf

http://ifr.sap.com/catalog/query.asp

http://www.saptechnical.com/Tutorials/BAPI/BAPIMainPage.htm

step by step BAPI Creation with screen shots.

http://www.sapgenie.com/abap/bapi/example.htm

BAPI Programming guide: -

http://help.sap.com/saphelp_nw04/helpdata/en/e0/9eb2370f9cbe68e10000009b38f8cf/frameset.htm

BAPI user guide: -

http://help.sap.com/saphelp_46c/helpdata/en/7e/5e115e4a1611d1894c0000e829fbbd/frameset.htm

BAPI STEP BY STEP PROCEDURE: -

http://www.sap-img.com/abap/bapi-step-by-step-guidance.htm

Example:-

http://www.erpgenie.com/abap/bapi/example.htm

PDF download: -

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/200dd1cc-589e-2910-98a9-bb2c48b7...

list of all bapis

http://www.planetsap.com/LIST_ALL_BAPIs.htm

for BAPI's

http://www.sappoint.com/abap/bapiintro.pdf

http://www.sappoint.com/abap/bapiprg.pdf

http://www.sappoint.com/abap/bapiactx.pdf

http://www.sappoint.com/abap/bapilst.pdf

http://www.sappoint.com/abap/bapiexer.pdf

http://service.sap.com/ale

http://service.sap.com/bapi

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

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

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

http://www.planetsap.com/Bapi_main_page.htm

http://www.topxml.com/sap/sap_idoc_xml.asp

http://www.sapdevelopment.co.uk/

http://www.sapdevelopment.co.uk/java/jco/bapi_jco.pdf

Also refer to the following links..

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

http://www.sap-img.com/abap/bapi-conventions.htm

http://www.planetsap.com/Bapi_main_page.htm

http://www.sapgenie.com/abap/bapi/index.htm

Checkout !!

http://searchsap.techtarget.com/originalContent/0,289142,sid21_gci948835,00.html

http://techrepublic.com.com/5100-6329-1051160.html#

http://www.saptechnical.com/Tutorials/BAPI/CustomBAPICreation2/page1.htm

There are 5 different steps in BAPI.

Create BAPI Structure

Create BAPI Function Module or API Method.

Create BAPI object

Release BAPI Function Module.

Release BAPI object.

Step1. Creating BAPI Structure:

Go to <SE11>.

Select Data Type & Enter a name.

Click on Create.

Note: Always BAPI should be in a development class with request number (Not Local Object).

Select Structure & hit ENTER.

Enter the fields from your database. Make sure that the first field is the Primary Key Field.

Then SAVE & ACTIVATE.

Step 2. Creating BAPI module:

Enter TR.CODE <SE37>.

Before entering any thing, from the present screen that you are in, select the menu

Goto -> Function Groups -> Create Group.

Enter a name (Note: This name Must start with ZBAPI)

Let this screen be as it is and open another window and there, enter TR.CODE <SE80).

Click on the Third ICON that says Inactive Objects.

Select the group that you just created and click on Activate.

Notice that the group you created will disappear from the list of inactive objects.

Go back to <SE37> screen and enter a name and hit <ENTER>. Then enter the group name that you just created and activated.

NOTE: When you release a function module the respective group will be attached to that particular application. It cannot be used for any other application. NEVER include an already existing group that is attached to another module.

Now click on the first Tab that says ATTRIBUTES and select the radio button that says remote-enabled module since we will be accessing this from any external system.

Then click on the second tab that says IMPORT.

Enter a PARAMETER NAME, TYPE and the structure you created in the first step. Also select the check box ‘Pa’. All remotely enabled functional modules MUST be Pa enabled, where Pa means ‘Passed by Value’ and if you don’t select ‘Pa’, then that means it will be passed by reference..

Then click on tab that says EXPORT.

Enter the following as is in the first three fields

RETURN TYPE BAPIRETURN (These 3 field values are always same)

Here also select ‘Pa’ meaning Pass by value.

Note: BAPIRETURN contains structure with message fields.

Then SAVE and ACTIVATE.

Step 3. Creating BAPI object:

Enter Tr.Code <SWO1> (Note. It is letter ‘O’ and not Zero).

Enter a name and then click on create. Enter details.

NOTE: Make sure that that Object Type and Program name are SAME.

Enter Application ‘M’, if you are using standard table Mara. If you are using your own database then select ‘Z’ at the bottom.

Then hit <ENTER>.

Now we have to add ‘Methods’. High light METHODS and then select the following from the menu:

Goto Utilities -> API Methods -> Add Methods.

Enter function Module name and hit <ENTER>.

Select the second FORWARD ARROW button (>)to go to next step.

Check if every thing looks ok and again click on FORWARD ARROW button (>).

Then select ‘YES’ and click on <SAVE>.

Now on a different screen goto TR.CODE <SE37>. Enter Function Module name and select from the top menu Function Module -> Release -> Release.

Goback to TR.CODE <SWO1>.

Here select the menu combination shown below in the same order.

Edit -> Change Release Status -> Object Type Component -> To Implemented.

Edit -> Change Release Status -> Object Type Component -> To Released.

Edit -> Change Release Status -> Object Type -> To Implemented.

Edit -> Change Release Status -> Object Type -> To Released.

Then click on <SAVE>.

Then click on Generate Button (4th button from left hand side looks like spinning wheel).

Then Click on the button that says ‘PROGRAM’ to see the source code.

To check if this is present in work flow goto TR.CODE <BAPI>.

Here it shows business object repository.

First click on the middle button and then select “ALL” and hit ENTER.

Goto tab ALPHABETICAL and look for the object that you created. This shows that the BAPI object has been created successfully

BAPI/RFC Interface

A remote function call is a call to a function module running in a system different from the caller's.

The remote function can also be called from within the same system (as a remote call), but usually caller and callee will be in different systems.

In the SAP System, the ability to call remote functions is provided by the Remote Function Call interface system (RFC). RFC allows for remote calls between two SAP Systems (R/3 or R/2), or between an SAP System and a non-SAP System.

RFC consists of the following interfaces:-

A calling interface for ABAP programs

Any ABAP program can call a remote function using the CALL FUNCTION...DESTINATION statement. The DESTINATION parameter tells the SAP System that the called function runs in a system other than the caller's.

RFC communication with the remote system happens as part of the CALL FUNCTION statement.

RFC functions running in an SAP System must be actual function modules, and must be registered in the SAP System as "remote".

When both caller and called program are ABAP programs, the RFC interface provides both partners to the communication. The caller may be any ABAP program, while the called program must be a function module registered as remote.

Calling interfaces for non-SAP programs

When either the caller or the called partner is a non-ABAP program, it must be programmed to play the other partner in an RFC communication.

To help implement RFC partner programs in non-SAP Systems, SAP provides-

External Interfaces

RFC-based and GUI-based interfaces can be used by external programs to call function modules in SAP R/2 or R/3 systems and execute them in these systems.

Vice versa, ABAP programs in R/2 or R/3 can use the functions provided by external programs via these interfaces.

Reward points..

Former Member
0 Kudos
111

hi,

BAPI (Business Application Programming Interface) is a set of interfaces to object-oriented programming methods that enable a programmer to integrate third-party software into the proprietary R/3 product from SAP. For specific business tasks such as uploading transactional data, BAPIs are implemented and stored in the R/3 system as remote function call (RFC) modules.

Follow this link for step by step creation of BAPI.

http://www.erpgenie.com/abap/bapi/example.htm#About%20the%20example

How to find function module or Bapi for particular transaction in sap?

If you mean that you need to know what BAPI's a particular tranx uses, which I can only assume that's what you mean, then you should access the code behind the transaction and search for 'CALL'. That normally is the standard method that think that most people use.

Suppose you want to find the bapi for creating a sales order, you usually use transaction VA01 for this.

1. Find out the package of the transaction.

Start Va01 go to system --> status.

Double click on transaction

Package is VA

Open this package in SE80

Open business engineering-->Business object types

Find the BO which sounds the most appropriate

I would suggest BUS2032 Sales Order

Double click.

Open methods.

Find the released method with from data or something similar in the name

, Createfromdat2

Position the cursor in it and click the program button

Scroll down to find the bapi used in this method

With this way you can also find out programs and FM's

2. Start va01 go to system-->status

Double click transaction VA01

Double click on package

Read the application component. (this is SD-SLS Sales)

Then open the transaction BAPI

Sales and distribution>Sales>sales order

createfromdat2

Hope this helps, Do reward.

Edited by: Runal Singh on Mar 27, 2008 12:17 PM

Former Member
0 Kudos
111

Hi,

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-step by step

http://www.sapgenie.com/abap/bapi/example.htm

Reward if usefull

Regards

Chinni