cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with BAPI invocation in UDF

Former Member
0 Kudos

Dear SDN-Experts,

I have the following java code in an user defined function:

JCO.Repository mRepository;

JCO.Client mConnection = JCO.createClient(

"101",

"********",

"********",

"de",

"frba02.buc.fristo.de",

"10" );

mConnection.connect();

mRepository = new JCO.Repository( "SAPLookup", mConnection );

JCO.Function function = null;

IFunctionTemplate ft = mRepository.getFunctionTemplate( "BAPI_MATERIAL_GET_ALL" );

function = ft.getFunction();

JCO.ParameterList input = function.getImportParameterList();

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

mConnection.execute ( function );

JCO.Table unitsofmeasure= function.getTableParameterList().getTable("UNITSOFMEASURE");

mConnection.disconnect();

return unitsofmeasure.getString("ALT_UNIT_ISO");

As you can see, I try to execute "BAPI_MATERIAL_GET_ALL" with 1000 as "MATERIAL". When I test the same BAPI in the Target System with Transaction SE37 and 1000 as material, I get a table which has three rows. But when I execute the UDF with the same parameter (as above), I get the following runtime exception:

Exception:com.sap.mw.jco.JCO$Exception: (106) JCO_ERROR_RESOURCE: Trying to access row values in a table which does not have any rows yet in class com.sap.xi.tf._MM_MT_KASSE__to_WPUWBW01_ method GetME$ 2270, com.sap.aii.mappingtool.tf3.rt.Context@24650c7a

Could you help me please?

Thanks in advance.

Cheers

Ehsan

Edited by: Ehsan Baghi on Jul 11, 2008 4:58 PM

Accepted Solutions (0)

Answers (2)

Answers (2)

wilsonrsantos
Active Participant
0 Kudos

Hi Ehsan !

By the message error that you received, I think that is possible that the bapi is returning no records in the table.

Sometimes, call an RFC or BAPI from java has different behavior that executing from SE37, because of field formatting for example. In your case, there is great chance that executing this BAPI in SE37, when you fill the Material field with "1000", internally it´s proccessed as "000000000000001000", and when you call this BAPI from a java program, the field is proccessed with the exact value that you passed: "1000".

A good way to check this is logon in your SAP environment with the user that you are using in the java mapping to connect to SAP, run SE37 and open the source code of this BAPI, set a remote break point, and test your mapping, so you will see in the debugger, the exact value that is arriving to the BAPI from java, and the values that is being returned to java.

I hope this helps !

Best regards,

Wilson

Shabarish_Nair
Active Contributor
0 Kudos

Use the lookup API instead of the JCO call.

You can refer the following article to have an idea about how RFC lookup works;

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/a03e7b02-eea4-2910-089f-8214c6d1...

Documentation:

The com.sap.aii.mapping.lookup API - https://help.sap.com/javadocs/NW04S/current/pi/index.html