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: 

Why some BAPIs can't be called by external program using JCo?

Former Member
0 Kudos
242

Hi,

I have a big problem, hope some experts can help me.

I want to write some external program using JCo to call some BAPIs.

But some BAPIs can be called but some other can't, and I really don't know what happened.

I write two programs using JCo to call two BAPIs.

But one can work and another can't.

The first program try to call BAPI_COMPANYCODE_GETDETAIL, and I import Company_code 1000. Then it return the IDES_AG correctly.

But the second program try to call BAPI_COMPANY_GETDETAIL, and I import Company_id 1000 again. But it doesn't return anything.

I really can't figure out the reason, the differents between these two programs is the Fm and the parameters only. And these two BAPIs are builded in the R/3. I've tested in R/3 and both of them are work correctly.

But why only one can work when I called them by external program using JCo?

Where could be wrong?

The reason I want to ask this question is that not only BAPI_COMPANY_GETDETAIL can't be called by external program using JCo in my system, but also all ZBAPIs write by myself can't be call.

I really hope some experts can give me some advise about what points should I check.

Thanks.

1 ACCEPTED SOLUTION

mvoros
Active Contributor
0 Kudos
197

Hi,

there is no difference between BAPIs in term of calling them from JCo. Are you sure that you have correct types for your second BAPI? For example BAPI_COMPANYCODE_GETDETAIL returns company code with type CHAR4 and BAPI_COMPANY_GETDETAIL returns company with type CHAR6. Do you get any messages in return table?

Cheers

6 REPLIES 6

Former Member
0 Kudos
197

hi,

BAPI_COMPANYCODE_GETDETAIL and BAPI_COMPANY_GETDETAIL

are completly different: compare them in se37 transaction....

regards,darek

mvoros
Active Contributor
0 Kudos
198

Hi,

there is no difference between BAPIs in term of calling them from JCo. Are you sure that you have correct types for your second BAPI? For example BAPI_COMPANYCODE_GETDETAIL returns company code with type CHAR4 and BAPI_COMPANY_GETDETAIL returns company with type CHAR6. Do you get any messages in return table?

Cheers

Former Member
0 Kudos
197

Hi,

Thanks for your response.

I've checked the TYPE of returned parameters, but I think "maybe" these can be assigned to a String in Jco?

If it can't,how should I get the returned parameters correctly?

The source codes of these two programs are show below.

I tried to assign 1000 as the input parameter for both program1 and program2.

But only program1 can return IDES AG correctly, program2 returned nothing.

Do I miss any part?

Hope experts can give me some advises.

Thanks a lot.


repository = JCO.createRepository("MYRepository", SID); 
// Get a function template from the repository			
IFunctionTemplate ftemplate = repository.getFunctionTemplate("BAPI_COMPANYCODE_GETDETAIL");			
// Create a function from the template
JCO.Function function = new JCO.Function(ftemplate); 
JCO.Client client = JCO.getClient(SID); // Get a client from the pool
JCO.ParameterList input = function.getImportParameterList(); // Fill in input parameters 

input.setValue(id, "COMPANYCODEID" );
client.execute(function); // Call the remote system

JCO.Structure ret = function.getExportParameterList().getStructure("COMPANYCODE_DETAIL");
System.out.println(ret.getString("COMP_NAME"));


repository = JCO.createRepository("MYRepository", SID); 
			
// Get a function template from the repository			
IFunctionTemplate ftemplate = repository.getFunctionTemplate("BAPI_COMPANY_GETDETAIL");			
// Create a function from the template
JCO.Function function = new JCO.Function(ftemplate); 
JCO.Client client = JCO.getClient(SID); // Get a client from the pool
JCO.ParameterList input = function.getImportParameterList(); // Fill in input parameters 

input.setValue(id, "COMPANYID" );
client.execute(function); // Call the remote system

JCO.Structure ret = function.getExportParameterList().getStructure("COMPANY_DETAIL");
System.out.println(ret.getString("NAME1"));

0 Kudos
197

Hi,

Try giving the input as '001000' instead of '1000'.

As the Input parameter ("COMPANYID") for second BAPI is of 6 char length, may be it's not considering the leading spaces.

thanks\

Mahesh

mvoros
Active Contributor
0 Kudos
197

Hi,

I agree with this comment. You need to add zeros. Actually it's stated in BAPI documentation.

The system does not convert the input parameter COMPANYID, meaning that

leading blank characters within this parameter are not cleared.

Cheers

Former Member
0 Kudos
197

Hi Mahesh and Cheers,

Thanks a lot, I fixed my problem.

Thank you very much for the advices.