cancel
Showing results for 
Search instead for 
Did you mean: 

[b]Why is this not working?Could any One Help Explain[/b]

Former Member
0 Kudos

Hello,

Using the Tutorial BAPI which comes with the JCO Tutorial, I just wanna call the first function. When I run the code it runs well without an Error but it doesn't produce any result which is strange to me. Could any body please help me to explain why it doesn't produce the first function Export Parameters? BELOW IS THE CODE:

import com.sap.mw.jco.*;
public class Test extends Object {
	JCO.Client mConnection;
	JCO.Repository mRepository;

	OrderedProperties logonProperties;
	public Test() 
	{
		
	}
	
	public int doBapi()
	{
		
		try {
			logonProperties = OrderedProperties.load("/logon.properties");

			mConnection =
				JCO.createClient((String)logonProperties.get("jco.client.client"), 
                 				(String)logonProperties.get("jco.client.user"), 
                 				(String)logonProperties.get("jco.client.passwd"), 
                 				 null, 
                 				(String)logonProperties.get("jco.client.ashost"),                					(String)logonProperties.get("jco.client.sysnr")
                			);
			mConnection.connect();
			mRepository = new JCO.Repository("SAPJCO", mConnection);
		}
		catch (Exception ex) {
			
			ex.printStackTrace();
			System.exit(1);
		}
				
		JCO.Function function = null;
		JCO.Table tab = null;
		try {
			function = this.createFunction("BAPI_COMPANYCODE_GETLIST");
			if (function == null) {
				System.out.println("BAPI_COMPANYCODE_GETLIST not found in SAP.");
				System.exit(1);
			}
			mConnection.execute(function);

			JCO.Structure returnStructure =	function.getExportParameterList().getStructure("RETURN");
			if (! (returnStructure.getString("TYPE").equals("") ||
					returnStructure.getString("TYPE").equals("S")) ) {
				System.out.println(returnStructure.getString("MESSAGE"));
				System.exit(1);
			}
			tab =	function.getTableParameterList().getTable("COMPANYCODE_LIST");
			for (int i = 0; i < tab.getNumRows(); i++) {
				tab.setRow(i);
				System.out.println(tab.getString("COMP_CODE") + 't' +
						tab.getString("COMP_NAME"));
			}
		}
		catch (Exception ex) {
			
			ex.printStackTrace();
			System.exit(1);
		}
		mConnection.disconnect();		
		return 0;
	}
	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){
	Test app = new Test();
	}
}

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Rudolph,

The bugs is in you <b>main()</b> method. Add the following line after <b>Test app = new Test();</b>.

app.doBapi();

if it doesn't work then

cut and paste the following and modify the connection parameter.

import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.JCO;
public class Test extends Object {
	JCO.Client mConnection;
	JCO.Repository mRepository;
 
	public Test() 
	{
		
	}
	
	public int doBapi()
	{
		
		try {
			mConnection =
				JCO.createClient("200", //client
								"userxxx", //username
								"password", //password
								 "EN", //language
								"10.93.1.12",//application sever host name or ip address
								"00" //system number             
							);
			mConnection.connect();
			mRepository = new JCO.Repository("SAPJCO", mConnection);
		}
		catch (Exception ex) {
			
			ex.printStackTrace();
			System.exit(1);
		}
				
		JCO.Function function = null;
		JCO.Table tab = null;
		try {
			function = this.createFunction("BAPI_COMPANYCODE_GETLIST");
			if (function == null) {
				System.out.println("BAPI_COMPANYCODE_GETLIST not found in SAP.");
				System.exit(1);
			}
			mConnection.execute(function);
 
			JCO.Structure returnStructure =	function.getExportParameterList().getStructure("RETURN");
			if (! (returnStructure.getString("TYPE").equals("") ||
					returnStructure.getString("TYPE").equals("S")) ) {
				System.out.println(returnStructure.getString("MESSAGE"));
				System.exit(1);
			}
			tab =	function.getTableParameterList().getTable("COMPANYCODE_LIST");
			for (int i = 0; i < tab.getNumRows(); i++) {
				tab.setRow(i);
				System.out.println(tab.getString("COMP_CODE") + 't' +
						tab.getString("COMP_NAME"));
			}
		}
		catch (Exception ex) {
			
			ex.printStackTrace();
			System.exit(1);
		}
		mConnection.disconnect();		
		return 0;
	}
	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){
	Test app = new Test();
	app.doBapi();
	}
}