cancel
Showing results for 
Search instead for 
Did you mean: 

Need example for BAPI query. Please, help.

Former Member
0 Kudos

Hi,

badly need help on BAPI_ACC_ACTIVITY_ALLOC_POST.

Does anybody have some example code for jCO query?

Thanks.

Vladimir

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Try this code...

package jco;

import com.sap.mw.jco.*;

public class jcosample

{

public static void main(String args[])

{

JCO.Client myConnection = null;

JCO.Repository mRepository = null;

JCO.Function myFunction = null;

try

{

myConnection = JCO.createClient("client","username","password" ,"language","ip address","system no");

myConnection.connect();

mRepository = new JCO.Repository("WIPRO",myConnection);

try

{

if (mRepository == null )

{

System.out.println("NuLL");

}

try

{

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

myFunction=ft.getFunction();

}catch (Exception ex)

{

throw new Exception(ex + "Problem retrieving JCO.Function object.");

}

if (myFunction == null)

{

System.exit(1);

}

myConnection.execute(myFunction);

}catch (Exception ex)

{

ex.printStackTrace();

System.exit(1);

}

myConnection.execute(myFunction);

JCO.Table codes = null;

codes =myFunction.getTableParameterList().getTable("COMPANYCODE_LIST");

int size;

size =codes.getNumRows();

if (size == 0)

{

System.out.println("No value matches the selection cretaria");

}

else

{

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

{

codes.setRow(i); System.out.print(codes.getString("COMP_CODE")); System.out.println(codes.getString("COMP_NAME"));

}

}

}catch( Exception e)

{

e.printStackTrace();

}

}

}

Hope that helps...

Note: in case for the BAPI that inserts or modified data you must call the BAPI_TRANSACTION_COMMIT also for the changes to get reflected in the Database.

Please let me if that helps you.

Cheers

Kathir~

Former Member
0 Kudos

Hi, Kathirvel:

thank you very much for reply.

Unfortunately, my problem is still not solved.

Please, have a look at the code below.

All unimportant (to my mind) details have been removed.

BAPI query over SAP-BAPI Browser with exactely the same set of parameters successfully returns DOC_NO.

My JCO query returns the message "Die Version 0 ist für den KoReKreis 1000 nicht vorgesehen". This is German and means that the version 0 does not fit accounting arrea 1000. It looks like my data for this BAPI are not correct BUT IT CANNOT BE THE CASE because BAPI browser works fine with the same parameters set.

May be you will see what is wrong there:

// Get repository:

JCO.addClientPool("MyPool", noOfConnections, props);

mRepository = new com.sap.mw.jco.JCO

.Repository("Company", "MyPool");

// Get client and connect:

mConnection = JCO.getClient("MyPool");

mConnection.connect();

// Get function:

String functionName = "BAPI_ACC_ACTIVITY_ALLOC_POST";

com.sap.mw.jco.JCO.Function function =

mRepository.getFunctionTemplate(functionName

.toUpperCase()).getFunction();

// Set head parameters:

com.sap.mw.jco.JCO.Structure header =

function.getImportParameterList()

.getStructure("DOC_HEADER");

header.setValue(new Date(),"DOCDATE");

header.setValue(new Date(), "POSTGDATE");

header.setValue("0", "VERSION");

header.setValue("USER", "USERNAME");

header.setValue("1000","CO_AREA");

// Set item parameters:

// important! The table is used here as IMPORT parameters:

com.sap.mw.jco.JCO.Table paramTable =

function.getTableParameterList()

.getTable("DOC_ITEMS");

paramTable.appendRow();

paramTable.setValue("SN6200", "REC_ORDER");

paramTable.setValue("5322", "SEND_CCTR");

paramTable.setValue("S-REP", "ACTTYPE");

paramTable.setValue(1.000, "ACTVTY_QTY");

paramTable.setValue("H", "ACTIVITYUN");

// Parameters set, execute:

mConnection.execute(function);

// Check if successful (there is an export parameter DOC_NO to be filled by BAPI):

if(function.getExportParameterList()

.getString("DOC_NO") == null || function.getExportParameterList()

.getString("DOC_NO").equals(""))

{

// If we end here, there is an error !

com.sap.mw.jco.JCO.Table results =

function.getTableParameterList()

.getTable("RETURN");

logger.debug(results.getString("MESSAGE"));

}

All possible combinations of parameters result in some (slightly different) error messages in "RETURN" structure. But even when the set of parameters is incomplete, the BAPI browser (same set of parameters as jCO) returns message that is different from the message I get over jCO. Therefore, it seems to me the problem is somewhere else and the messages are actually missleading.

Thank you very much in advance for any hint.

Vladimir

Former Member
0 Kudos

This is most probably dependant on some user defaults.

Do you use the same user with the BAPI Browser and the JCO ?

I believe there are some BAPIS to set stuff like default areas, company code etc...

If not check if the field is on one of the BAPI's input parms or tables. You may need to specifically set it.

Your user default may not use version 0.

Enjoy 😎

Former Member
0 Kudos

Hi,

seems that all parameters set and still it does not work.

I am trying to activate debug. The client is installed on the computer where JCO application run. I add in the code the following lines:

mConnection = JCO.getClient("MyPool");

mConnection.setAbapDebug(true); // line 1

mConnection.setSapGui(1); // line 2

mConnection.connect();

But this is somehow not enough. Should one start SAP GUI before JCO application? Actually I tried it both ways but debug window never appeared. Do you know what else should be set?

Thanks,

Vladimir

Former Member
0 Kudos

Hi,

i have solved the problem. It's actually very stupid - this BAPI has such parameter as SENT_CCTR (and others) that was set, e.g. to "5322" and should be set to "0000005322". If the numbers are represented by strings, it MUST be emphasized in the documentation that these strings should be filled with "0" to the size of the parameter. I have never seen it in the docu.