Skip to Content
0
Former Member
May 23, 2005 at 08:20 PM

URGENT HELP !JCO RETURN structure from SAP

286 Views

Hello,

I am working on my intern project and I got some trouble.

I have used JDBC to access a table in Oracle(this is an independent DB)I updated a column in the table and selected all data that

was marked as 6 based on the update(SAP needs this data). I passed the values to a JCO application,

which connects to SAP and send the data (I presume what I'm doing is correct) to a structure in SAP.

SAP does some internal calculations with the data and should return the data back using the same

structure but this time with some changes on the data.

For example the field steuk is marked as 7 if the data processing was successful and if the data

structure wasn't successful a 6 will be return.

The return Values should be updated in the oracle DB indicating if the transfer was successful

or not. And next time the same data will be sent to SAP following the same path.

Now when I look at the return getString data in Eclipse, the result seems ambiguous.I don't see the data I presumably

sent to the SAP structure using:

JCO.ParameterList list = function.getTableParameterList();
JCO.Table ztable =  list.getTable("ZSAORA_RUECK"); 
	for (int i = 0; i < 19; i++) {
	ztable.appendRow(); 
	ztable.setValue(value,field name);

Am I doing some thing wrong here??? Any Help will be highly appreciated. Codes could be sent to rudy-e@gmx.net

BELOW are the codes:

CONNECTING TO test_table in Oracle DB:

import java.sql.*;

public class DatabaseConnect {

	public static void main(String[] args) {

	Connection con = null;
	Statement stmt = null;
	ResultSet re = null;
		
	String[] ParamArray;	        
        ParamArray = new String[24];
        	
	//Properties logon;
	try {
		Class.forName("oracle.jdbc.driver.OracleDriver"); 
	con = DriverManager.getConnection 
("jdbc:oracle:thin:@226.190.0.1:1521:testdb","test","test1"); 
	stmt = con.createStatement ();
	stmt.executeUpdate("UPDATE test_table set steuk = 6 WHERE steuk = 5");
ResultSet rs = stmt.executeQuery("SELECT mandt,kokrs,werks,arbpl,aufnr,vornr,ile01,"+
"lsa01,ism01,ile02,lsa02,ism02,ile03,lsa03,ism03,"+
"ile04,lsa04,ism04,steuk,matnr,budat,kostl,pernr,"+
"rueckid FROM test_table where steuk =6");						
	while (rs.next()) { 
	for (int i = 1; i <= 24; i++){
					
	ParamArray[i-1] = rs.getString(i);
					
	System.out.print(rs.getString(i) + 't');
	}			
	System.out.println();				
	}
			
	} catch(Exception e) {
	e.printStackTrace();				
	} finally {
		try
		{
	if(stmt != null) stmt.close();
	if(con != null) con.close();  
				
	} catch (Exception exception) {
		exception.printStackTrace();
		}
	}
	// Bapi call
		
	TryBapi sap = new TryBapi(ParamArray);
	}
}

BELOW IS THE JCO Code which connects to SAP and send data to the structure:

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

public class TryBapi extends Object {	

JCO.Client mConnection;	
JCO.Repository mRepository;	
OrderedProperties logonProperties;

public TryBapi(String[] paramArray){

	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("Z_UPDATE_SAORA_RUECK");
		if (function == null) {
		System.out.println("Z_UPDATE_SAORA_RUECK not found in SAP.");
		System.exit(1);
		}

	JCO.ParameterList list = function.getTableParameterList();
		JCO.Table ztable =  list.getTable("ZSAORA_RUECK"); //inserting 24 records loop.
	for (int i = 0; i < 24; i++) {
	ztable.appendRow(); //ztable.setValue(value, field name)
	ztable.setValue("300","MANDT");
	ztable.setValue("KOKRS" + i, "KOKRS");
	ztable.setValue("WERKS" + i, "WERKS");
	ztable.setValue("ARBPL" + i, "ARBPL");
	ztable.setValue("AUFNR" + i, "AUFNR");
	ztable.setValue("VORNR" + i, "VORNR");
	ztable.setValue("ILE01" + i, "ILE01");
	ztable.setValue("LSA01" + i, "LSA01");
	ztable.setValue("ISM01" + i, "ISM01");
	ztable.setValue("ILE02" + i, "ILE02");
	ztable.setValue("LSA02" + i, "LSA02");
	ztable.setValue("ISM02" + i, "ISM02");
	ztable.setValue("ILE03" + i, "ILE03");
	ztable.setValue("LSA03" + i, "LSA03");
	ztable.setValue("ISM03" + i, "ISM03");
	ztable.setValue("ILE04" + i, "ILE04");
	ztable.setValue("LSA04" + i, "LSA04");
	ztable.setValue("ISM04" + i, "ISM04");
	ztable.setValue("STEUK" + i, "STEUK");
	ztable.setValue("MATNR" + i, "MATNR");
	ztable.setValue("BUDAT" + i, "BUDAT");
	ztable.setValue("KOSTL" + i, "KOSTL");
	ztable.setValue("PERNR" + i, "PERNR");
	ztable.setValue("RUECKID" + i, "RUECKID");
	}

	list.setValue(ztable,"ZSAORA_RUECK");
	function.setTableParameterList(list);
	mConnection.execute(function);
	}		
	
	catch (Exception ex) {
	ex.printStackTrace();
	System.exit(1);
	}		
		
	 JCO.Table codes = null;
	  
	try {
	codes = function.getTableParameterList().getTable("ZSAORA_RUECK");
	System.out.println("Return Values starts HERE:");
	for (int i =0; i < codes.getNumRows(); i++){		  	
	codes.setRow(i);
	System.out.println(codes.getString("MANDT")+ 't'+
	codes.getValue("KOKRS")+ 't'+
	codes.getString("WERKS")+ 't'+
	codes.getString("ARBPL")+ 't'+
	codes.getString("AUFNR")+ 't'+
	codes.getString("VORNR")+ 't'+
	codes.getString("ILE01")+ 't'+
	codes.getString("LSA01")+ 't'+
	codes.getString("ISM01")
			
/*	codes.getString("ILE02")+ 't'+
	codes.getString("LSA02")+ 't'+
	codes.getString("ISM02")+ 't'+
				
	codes.getString("ILE03")+ 't'+
	codes.getString("LSA03")+ 't'+
	codes.getString("ISM03")+ 't'+
					
	codes.getString("ILE04")+ 't'+
	codes.getString("LSA04")+ 't'+
	codes.getString("ISM04")+ 't'+
					
	codes.getString("STEUK")+ 't'+
	codes.getString("MATNR")+ 't'+
	codes.getString("BUDAT")+ 't'+
	codes.getString("KOSTL")+ 't'+
	codes.getString("PERNR")+ 't'+
	codes.getString("RUECKID")       */ 
	 ); 
	  } 
		  
	
	}
		  
	catch (Exception ex) {
	ex.printStackTrace();
	System.exit(2);		  
	}
				
	mConnection.disconnect();
	}	
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.");
		}	
}

}

Message was edited by: Rudolph Emange

Message was edited by: Rudolph Emange