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.
Showing results for 
Search instead for 
Did you mean: 

Post through BAPI

Former Member
0 Kudos

Can we access bapi from any interfaces like java , .NET, VB ...etc.

i need to code a program which will call the bapi in legecy

Please post the answer it is very urgent




Active Contributor
0 Kudos


We can Call BAPIs from VB or JAVA.

Check the example with Java using JAVA connector.

<b>reward if Helpful</b>

0 Kudos


here is the example code for calling the BAPI from Java interface..

Please reqard the points if usefuulll........

<b>Calling BAPIs from Java</b>

This is an example program for calling a BAPI from the IBM development platform, Access

Builder for SAP R/3.

Detailed program examples are shipped with the Access Builder for R/3.

Access Builder for SAP R/3

//Importing the required classes:





//Connecting to the R/3 System:

static private IRfcConnection establishConnection(MiddlewareInfo


throws JRfcRemoteException


IRfcConnection aConnection = null ;

ConnectInfo aConnectInfo = null ;

UserInfo aUserInfo = null ;

String orbServerName = aMiddlewareInfo.getOrbServerName() ;

// Please adjust the values written in UPPERCASE LETTERS

// in the lines below so that they fit to your needs!

// If you don't know the correct values ask your system

// administrator!

// After correcting these values you should change the

// <bAdjusted> variable in the following line

// from "false" to "true".

// Then you can re-compile ("javac") and

// re-run ("java SampleCompanyCode -conn JNI") this sample...

boolean bAdjusted = true;

if (!bAdjusted) {

throw (new JRfcRfcConnectionException (

"Please adjust the Connection-Parameters to your

needs! (See method \"establishConnection\")"));


//Connection information:

aConnectInfo = new ConnectInfo (

3, // int aRfcMode 3=R/3 or 2=R/2

null, // String aDestination

"", // String aHostName YOUR HOSTNAME (e.g. IP-


0, // int aSystemNo YOUR SYSTEM-NUMBER

null, // String aGatewayHost

null, // String aGatewayService

null, // String aSystemName

null, // String aGroupName

null, // String aMsgServer

false, // Boolean isLoadBalancing

true); // Boolean isCheckAuthorization

//User information:

aUserInfo = new UserInfo (

"MUSTER", // String aUserName, YOUR USERID

"IDES", // String aPassword, YOUR PASSWORD

"800", // String aClient, YOUR CLIENT NUMBER

"e", // String aLanguage, YOUR PREFERRED


1103); // int aCodePage YOUR REQUIRED CODEPAGE

//Technical conversion for the selected middleware;

// Open connection:

IRfcConnectionFactory aConnectionFactory =

FactoryManager.getSingleInstance().getRfcConnectionFactory() ;

aConnection =

aConnectionFactory.createRfcConnection(aConnectInfo, aUserInfo) ; ;

//Returning the connection:

return aConnection ;


//Calling the main method:

public static void main (java.lang.String[] args)

//Setting up the connection using the selected middleware:


MiddlewareInfo aMiddlewareInfo = new MiddlewareInfo(args) ;

FactoryManager aFactoryManager =

FactoryManager.getSingleInstance() ;

aFactoryManager.setMiddlewareInfo(aMiddlewareInfo) ;

//Initializing the connection object:

IRfcConnection aConnection = null ;



aConnection = establishConnection(aMiddlewareInfo) ;


catch (Exception ex)


System.out.println("ERROR : Could not create connection : "

+ ex) ;

System.exit(-1) ;


System.out.println("Connection established.");

// --- TEST CODE (start) -



printList(aConnection) ;

//Calling the BAPI:

//Declare an empty Object ID for the Business Object


objectId = CompanyCode.getEmptyObjectId() ;

//Entering a value in the object ID:

objectId.getKeyField("COMPANYCODEID").setString("1000") ;

//Instantiate the object CompanyCode with the object ID:

companyCode = new CompanyCode(objectId) ; // Create 2nd


System.out.println ("Successfully created new CompanyCode :

'" + companyCode + "'") ;

printDetails(companyCode, aConnection) ;


// --- TEST CODE (end) -

catch (Exception ex)


System.out.println ("Unexpected exception occurred:");

System.out.println (ex);



private static void printDetails(CompanyCode companyCode,

IRfcConnection connection)




//Declare the parameters of the BAPI CompanyCode.GetDetail:

CompanyCodeGetdetailParams aCompanyCodeGetdetailParams =

new CompanyCodeGetdetailParams() ;

//Aufruf des BAPIs CompanyCode.GetDetail auf die Objektinstanz:



//Splitting the parameter object into its separate components


Bapi0002_2Structure struct =

aCompanyCodeGetdetailParams.getCompanycodeDetail() ;

System.out.println ("The details of the companycode are :

") ;

//Splitting the structure into individual fields:

System.out.println ("CompCode : '" +

struct.getCompCode() + "'");

System.out.println ("CompName : '" +

struct.getCompName() + "'");

System.out.println ("City1 : '" +

struct.getCity() + "'");

System.out.println ("Country1 : '" +

struct.getCountry() + "'");

System.out.println ("Currency : '" +

struct.getCurrency() + "'");

System.out.println ("Langu1 : '" +

struct.getLangu() + "'");

System.out.println ("ChrtAccts : '" +

struct.getChrtAccts() + "'");

System.out.println ("FyVariant : '" +

struct.getFyVariant() + "'");

System.out.println ("VatRegNo : '" +

struct.getVatRegNo() + "'");

System.out.println ("Company : '" +

struct.getCompany() + "'");

System.out.println ("AddrNo : '" +

struct.getAddrNo() + "'");

System.out.println() ;


catch (Exception ex)


System.out.println("Exception in printDetails() : " + ex) ;




private static void printList(IRfcConnection connection)




//Declaring the parameter object:

CompanyCodeGetlistParams aCompanyCodeGetlistParams =

new CompanyCodeGetlistParams() ;

//Actual BAPI call:

CompanyCode.getlist(connection, aCompanyCodeGetlistParams);

//Splitting the parameter objects into its separate components


Bapi0002_1Table table =


int rowCount = table.getRowCount() ;

System.out.println ("Returned table has " + rowCount + "


//Evaluating the table row by row:

for (int i = 0; i < rowCount; i++)


Bapi0002_1TableRow row = table.getRow(i) ;

System.out.println("\t" + row.getCompCode() + "\t" +

row.getCompName()) ;


System.out.println() ;


catch (Exception ex)


System.out.println("Exception in printList() : " + ex) ;






Rajesh Akarte

Former Member
0 Kudos


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.

The following standardized BAPIs are provided:

Reading instances of SAP business objects

GetList ( ) With the BAPI GetList you can select a range of object key values, for example, company codes and material numbers.

The BAPI GetList() is a class method.

GetDetail() With the BAPI GetDetail() the details of an instance of a business object type are retrieved and returned to the calling program. The instance is identified via its key. The BAPI GetDetail() is an instance method. BAPIs that can create, change or delete instances of a business object type

The following BAPIs of the same object type have to be programmed so that they can be called several times within one transaction. For example, if, after sales order 1 has been created, a second sales order 2 is created in the same transaction, the second BAPI call must not affect the consistency of the sales order 2. After completing the transaction with a COMMIT WORK, both the orders are saved consistently in the database.

Create( ) and CreateFromData! ( )

The BAPIs Create() and CreateFromData() create an instance of an SAP business object type, for example, a purchase order. These BAPIs are class methods.

Change( )

The BAPI Change() changes an existing instance of an SAP business object type, for example, a purchase order. The BAPI Change () is an instance method.

Delete( ) and Undelete( ) The BAPI Delete() deletes an instance of an SAP business object type from the database or sets a deletion flag.

The BAPI Undelete() removes a deletion flag. These BAPIs are instance methods.

Cancel ( ) Unlike the BAPI Delete(), the BAPI Cancel() cancels an instance of a business object type. The instance to be cancelled remains in the database and an additional instance is created and this is the one that is actually canceled. The Cancel() BAPI is an instance method.

Add<subobject> ( ) and Remove<subobject> ( ) The BAPI Add<subobject> adds a subobject to an existing object inst! ance and the BAPI and Remove<subobject> removes a subobject from an object instance. These BAPIs are instance methods.

ex BAPI:



You can get good help form the following links,

BAPI-step by step

list of all bapis

for BAPI's

Also refer to the following links..

Checkout !!,289142,sid21_gci948835,00.html


Here is the step by step procedure for creating BAPIs.

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.


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.


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