Skip to Content
0
Former Member
Dec 31, 2008 at 07:47 AM

Problem while calling RFC in java

145 Views

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.