cancel
Showing results for 
Search instead for 
Did you mean: 

Problems calling BAPI with JCO

Former Member
0 Kudos

Hi everybody!

Here is the little problem I'm getting, which I don't know how to solve it.

I've developed a J2EE application which connects via JCO BAPI_SALESORDER_GETLIST. I have no problem executing it, but the result I get is null.

I've executed that BAPI with same input parameters in the SAP System and I've found that this bapi loads two tables (or instances of the table) "SALES_ORDERS". The first one is empty and the second one has records.

In my code, I catch the table like this:

JCO.Table table = function.getParameterList().getTable("SALES_ORDERS");

but I'm thinking this code returns me the first one, which is empty...

Any idea about this???

Anyone knows how to catch the second one?

I'm starting with these technologies and, obviously, I'm not an expert in SAP

Thanks a lot in advance!

Alberto.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You have to pass "CUSTOMER_NUMBER", "SALES_ORGANISATION" as compulsary import parameters to execute "BAPI_SALESORDER_GETLIST".

The returned output (RecordSet) contains "SALES_ORDERS" AS

internal table.

To read the data from "SALES_ORDERS" table...you need to check the following...

IRecordSet recSet = (IRecordSet) outputparam.get("SALES_ORDERS");

while(recSet.next())

{

res.write(recSet.getString("ITEM_NUMBER"));

res.write(recSet.getString("MATERIAL"));

res.write(recSet.getString("SHORT_TEXT"));

res.write(recSet.getString("DOC_DATE"));

res.write(recSet.getString("REQ_QTY"));

}

Before this,

1) you have to check whether you are getting connection or not.

2)whether you are passing input paramaeters correct or not.

Get back to me if any queries....

Hope this helps

Please Assign points to helpful answers

Regards,

Rama Raju

Former Member
0 Kudos

Hi Rama, thanks for your answer.

Yes, I pass as input parameters "CUSTOMER_NUMBER" and "SALES_ORGANIZATION" and my program connects well to the sap system.

I read the output table "SALES_ORDERS" like this:

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

//print results

if(sales_orders.getNumRows()>0){

do{

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

JCO.Field field = e.nextField();

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

}

}while(sales_orders.nextRow());

}

Is supposed that this code runs well, cause is code I've copied from a course.

The problem I think I have is that when I execute the Bapi in the SAP system with the same input parameters, in the output I can see that there are two instances of the table SALES_ORDERS loaded. The first one is empty and the second one has records. I suposse that my program is reading the first one... That's why I get no results...

I'd like to read the second one.

Any idea about this??

Thanks.

Alberto.

Former Member
0 Kudos

Hi Alberto,

I am able to read it from first sales_orders only.

Please try this program...

// Establish connection to R/3 System.

IConnection conn = null;

// Get the connection

try

{

IConnectorGatewayService cgSer = (IConnectorGatewayService)PortalRuntime.getRuntimeResources().getService(IConnectorService.KEY);

ConnectionProperties cp = new

ConnectionProperties(req.getLocale(), req.getUser());

conn = cgSer.getConnection("yourr3sys", cp);

} catch(Exception e){

res.write("Error in connection" + e.getLocalizedMessage());

}

try

{

// Create an executable interaction interface

IInteraction ix = conn.createInteractionEx();

// Create an interaction spec

IInteractionSpec ispec = ix.getInteractionSpec();

//Set the interaction properties

ispec.setPropertyValue("Name", "BAPI_SALESORDER_GETLIST");

// Create a input record factory

RecordFactory rf = ix.getRecordFactory();

// Create a mapped input record

MappedRecord inputParam = rf.createMappedRecord("inputParam");

// Get the input parameters. Hard Coded values are passed

to test.

inputParam.put("CUSTOMER_NUMBER", "0000001000");

inputParam.put("SALES_ORGANIZATION", "1000");

// Create a mapped output record

MappedRecord outputParam =

(MappedRecord)ix.execute(ispec,inputParam);

IRecordSet recSet = (IRecordSet)outputParam.get("SALES_ORDERS");

while(recSet.next())

{

res.write(recSet.getString("ITM_NUMBER"));

res.write(recSet.getString("MATERIAL"));

res.write(recSet.getString("SHORT_TEXT"));

res.write(recSet.getString("DOC_DATE"));

res.write(recSet.getString("REQ_QTY"));

}

conn.close();

}

catch(ResourceException e){

res.write("Error in BAPI function execution" +

e.getLocalizedMessage());

}catch(Exception ex)

{

res.write("Error in BAPI function execution" + ex.getLocalizedMessage());

}

Answers (3)

Answers (3)

Former Member
0 Kudos

Help!, I need somebody.. 😛

I really don't know how to solve it!

Former Member
0 Kudos

Nobody knows anything about this???

With all input parameters I send I always get the first table empty...

Former Member
0 Kudos

Hi Albert,

I will suggest you to use SAP Enterprise JCo rather then core JCo, that is much better to use and debug also.

Guru.

Former Member
0 Kudos

No succeded...

Am I the first one with this problem??

Thanks for your replies.

Alberto.