cancel
Showing results for 
Search instead for 
Did you mean: 

urgently needed help in BAPI

Former Member
0 Kudos

hello everybody,

I have a BAPI called "CreateFromData" for business object called 'SalesOrder'.

i want to use this BAPI in Java(developer studio).

we can use this method to create sales orders.

A sales order contains information about prices, quantities and dates.

A sales order consists of several items that contain the quantity of the material or service specified for the order.

we have to enter item data required for using the above BAPI using ORDER_ITEMS_IN table(this is a parameter for the above mentioned method).

how to enter data into this parameter(table) from java...i know that we have to use Jco but how to use it i donot know....i mean how to give parameter values to these methods in java?

pls help me reagarding this problem...

thx in advance,

bye,

aj.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Ajay,

There are two ways of using this.

In Webdynpro application, You can create RFC model and then execute this model. It will inturn calls BAPI in SAP R/3.

Second, You can use JCO connections in any J2ee applications to connect to the SAP system and execute this BAPI.

Tutorials available for webdynpro application at following location:

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/web dynpro tutorial and sample applications.faq

Regards,

Bhavik

Former Member
0 Kudos

hi bhavik,

thx for ur reply....

i know that we have to use jco connections but i want to know how to execute BAPI in JCO...

can u give me one example of how to execute the bapi by giving parameters..

thx,

regards,

aj.

Former Member
0 Kudos

Hi Ajay,

Yake this code to call your BAPI from your JAVA class.

This is the sample program for BAPI "BAPI_SALESORDER_GETLIST"

import com.sap.mw.jco.*;

public class Example2 {

// The MySAP.com system we gonna be using

static final String SID = "R3";

// The repository we will be using

IRepository repository;

public Example2()

{

try {

// Add a connection pool to the specified system

// The pool will be saved in the pool list to be used

// from other threads by JCO.getClient(SID).

// The pool must be explicitely removed by JCO.removeClientPool(SID)

JCO.addClientPool( SID, // Alias for this pool

10, // Max. number of connections

"000", // SAP client

"johndoe", // userid

"*****", // password

"EN", // language

"appserver", // host name

"00" );

// Create a new repository

// The repository caches the function and structure definitions

// to be used for all calls to the system SID. The creation of

// redundant instances cause performance and memory waste.

repository = JCO.createRepository("MYRepository", SID);

}

catch (JCO.Exception ex) {

System.out.println("Caught an exception: \n" + ex);

}

}

// Retrieves and prints information about the remote system

public void systemInfo()

{

try {

// Get a function template from the repository

IFunctionTemplate ftemplate = repository.getFunctionTemplate("RFC_SYSTEM_INFO");

// if the function definition was found in backend system

if(ftemplate != null) {

// Create a function from the template

JCO.Function function = ftemplate.getFunction();

// Get a client from the pool

JCO.Client client = JCO.getClient(SID);

// We can call 'RFC_SYSTEM_INFO' directly since it does not need any input parameters

client.execute(function);

// The export parameter 'RFCSI_EXPORT' contains a structure of type 'RFCSI'

JCO.Structure s = function.getExportParameterList().getStructure("RFCSI_EXPORT");

// Use enumeration to loop over all fields of the structure

System.out.println("System info for " + SID + ":\n" +

"----


");

for (JCO.FieldIterator e = s.fields(); e.hasMoreElements(); ) {

JCO.Field field = e.nextField();

System.out.println(field.getName() + ":\t" + field.getString());

}//for

System.out.println("\n\n");

// Release the client into the pool

JCO.releaseClient(client);

}

else {

System.out.println("Function RFC_SYSTEM_INFO not found in backend system.");

}

}

catch (Exception ex) {

System.out.println("Caught an exception: \n" + ex);

}

}

// Retrieves and displays a sales order list

public void salesOrders()

{

JCO.Client client = null;

try {

// Get a function template from the repository

IFunctionTemplate ftemplate = repository.getFunctionTemplate("BAPI_SALESORDER_GETLIST");

// if the function definition was found in backend system

if(ftemplate != null) {

// Create a function from the template

JCO.Function function = ftemplate.getFunction();

// Get a client from the pool

client = JCO.getClient(SID);

// Fill in input parameters

JCO.ParameterList input = function.getImportParameterList();

input.setValue("0000001200", "CUSTOMER_NUMBER" );

input.setValue( "1000", "SALES_ORGANIZATION");

input.setValue( "0", "TRANSACTION_GROUP" );

// Call the remote system

client.execute(function);

// Print return message

JCO.Structure ret = function.getExportParameterList().getStructure("RETURN");

System.out.println("BAPI_SALES_ORDER_GETLIST RETURN: " + ret.getString("MESSAGE"));

// Get table containing the orders

JCO.Table sales_orders = function.getTableParameterList().getTable("SALES_ORDERS");

// Print results

if (sales_orders.getNumRows() > 0) {

// Loop over all rows

do {

System.out.println("----


");

// Loop over all columns in the current row

for (JCO.FieldIterator e = sales_orders.fields(); e.hasMoreElements(); ) {

JCO.Field field = e.nextField();

System.out.println(field.getName() + ":\t" + field.getString());

}//for

} while(sales_orders.nextRow());

}

else {

System.out.println("No results found");

}//if

}

else {

System.out.println("Function BAPI_SALESORDER_GETLIST not found in backend system.");

}//if

}

catch (Exception ex) {

System.out.println("Caught an exception: \n" + ex);

}

finally {

// Release the client to the pool

JCO.releaseClient(client);

}

}

protected void cleanUp() {

JCO.removeClientPool(SID);

}

public static void main(String[] argv)

{

Example2 e = new Example2();

e.systemInfo();

e.salesOrders();

e.cleanUp();

}

}

regards,

Bhavik

Former Member
0 Kudos

hi bhavik,

thx very much for ur help...

cheers ,

aj.

Former Member
0 Kudos

Hi Ajay,

If you have solved this problem then please close this thread.

Donot forget to reward points if answer was helpful.

Regards,

Bhavik

Former Member
0 Kudos

Depending on the release of your system you should be using

BAPI_SALESORDER_CREATE_FROM_DATA2

as the previous versions become obsolete !!

Enjoy