cancel
Showing results for 
Search instead for 
Did you mean: 

Problem while calling RFC in java

Former Member
0 Kudos

hi,

I writed a java program calling a batch input RFC. The RFC return an internal table which storing the system messages of the batch input process. My problem is:

When i debug the java program,the RFC excecuted and return the correct internal table to me.

But when i executed it not in debug mode, there is no batch input messages return to me.

My code is:

package com.hongta.com.z_delivery_bdc;

import com.sap.mw.jco.IFunctionTemplate;

import com.sap.mw.jco.JCO;

import com.sap.mw.jco.JCO.ParameterList;

/**

  • @author Administrator

*

  • To change the template for this generated type comment go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

public class ConnectRFC extends Object {

JCO.Client mConnection;

JCO.Repository mRepository;

String filePath;

String BDCLOG;

JCO.Function function;

public void Connect1() {

filePath =

"C:
Documents and Settings
Administrator.3939200975DB4C5
desktop
cigaXY2008-12-15.xml";

function = null;

try {

// Change the logon information to your own system/user

mConnection = JCO.createClient("610", // SAP client

"xxxxxx", // userid

"xxxxxx", // password

null, // language

"10.96.0.53", // application server host name

"01"); // system number

// mConnection.setAbapDebug(true);

mConnection.connect();

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

} catch (Exception ex) {

ex.printStackTrace();

System.out.println("jco connect failed");

mConnection.disconnect();

System.exit(1);

}

//JCO.Table codes = null;

try {

function = this.createFunction("Z_BAPI_CONTRACT_BDC");

if (function == null) {

System.out.println(

"Z_BAPI_contract_bdc" + " not found in SAP.");

if ( mConnection != null && mConnection.isAlive()) {

mConnection.disconnect();

}

System.exit(1);

}

//function.getImportParameterList().setValue(filePath, "FILEPATH");

//function.getImportParameterList().setValue(BDCLOG, "BDCLOG");

mConnection.execute(function);

}

catch (Exception ex) {

//System.out.println(ex.toString());

ex.printStackTrace();

System.out.println("execute failed");

mConnection.disconnect();

System.exit(1);

}

JCO.Table codes = null;

codes =

function.getTableParameterList().getTable("MESSAGE");

try {

codes.firstRow();

for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow()) {

System.out.println(codes.getString("CON")" "codes.getString("MESG"));

}

}

catch(Exception ex1){

ex1.printStackTrace();

System.out.println("codes");

}

if ( mConnection != null && mConnection.isAlive()) {

mConnection.disconnect();

}

System.out.println("chenggong");

}

public JCO.Function createFunction(String name) throws Exception {

try {

IFunctionTemplate ft =

mRepository.getFunctionTemplate(name.toUpperCase());

if (ft == null){

return null;

}

return ft.getFunction();

} catch (Exception ex) {

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

}

}

public static void main(String[] args) {

ConnectRFC app = new ConnectRFC();

app.Connect1();

}

}

Regards,

taowenbo.

Accepted Solutions (1)

Accepted Solutions (1)

ravindra_bollapalli2
Active Contributor
0 Kudos
Former Member
0 Kudos

hi, bvr

thanks for your help.

The example "Calling BAPIs from Java" you provided need the package com.ibm.sap.bapi.;com.ibm.sap.bapi.generated.;

I do not know where to get these.

Also please give me some help why my program running correctly only when debug if possible.

thanks and regards,

taowenbo

ravindra_bollapalli2
Active Contributor
0 Kudos

hi tao,

check this link

check this thread

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/ad09cd07-0a01-0010-93a9-933e247d...

http://www.apentia-forum.de/viewtopic.php?t=1962

add those... if u still in same case

check with pdf how to create a bapi and how to access the bapi from java application programming

http://www.sapdevelopment.co.uk/java/jco/bapi_jco.pdf

let me know u need any further info

bvr

Edited by: bvr on Jan 1, 2009 5:34 AM

Edited by: bvr on Jan 4, 2009 5:29 AM

0 Kudos

Hi Ravindra

Could you help me in getting the library for com.ibm.sap.*, as it is needed for my java program to call BAPI in transaction mode

Thanks

Sekhar

Answers (2)

Answers (2)

Former Member
0 Kudos

some help to me .thanks

Former Member
0 Kudos

hi,

i had resolved my problem in other way.I don't upload my data using ws_upload now,but upload with table.

here is my code.Maybe helpful to somebody:

JCO.Table C_XYORDERTable;

JCO.Table C_XYORDPR_FINALTable;

public void getXyordprFinalElement(Element e) {

try {

for (Iterator i = e.getChildren().iterator(); i.hasNext();) {

Element child = (Element) i.next();

if (child.getName().equals("ORDER_ID"))

C_XYORDPR_FINALTable.setValue(child.getText(), "ORDER_ID");

else if (child.getName().equals("ID"))

C_XYORDPR_FINALTable.setValue(child.getText(), "ID");

else if (child.getName().equals("PRODUCT_ID"))

C_XYORDPR_FINALTable.setValue(

child.getText(),

"PRODUCT_ID");

else if (child.getName().equals("MATNR"))

C_XYORDPR_FINALTable.setValue(child.getText(), "MATNR");

else if (child.getName().equals("QUANTITY"))

C_XYORDPR_FINALTable.setValue(child.getText(), "QUANTITY");

}

C_XYORDPR_FINALTable.nextRow();

} catch (Exception ex) {

ex.printStackTrace();

}

}