Skip to Content
author's profile photo Former Member
Former Member

URGENT HELP !JCO RETURN structure from SAP

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on May 24, 2005 at 09:24 AM

    Hi,

    what is the problem ? Don't you get any return ? Or wrong return values ?

    As far as I can see it, you are using the table ZSAORA_RUECK for both directions (import and export).

    I would expect, that R\3 overwrites the values and you read the changed values after RFC-excecution. Than of course, the values you have set initially might be same any more as they were before you excecuted the function.

    Please describe some more details of your problem.

    Regards, Astrid

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Astrid,

      Thank you for your remarks. The problem I'm having is that when I do send the values to SAP using the loop:

      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);

      I do expect to have(or see) some values when I do access the same table structure(This is just a structure and

      not a real table as I do understand that there is a different between a structure and a table in SAP) and

      not the field names back.In the second try and catch block:

      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")

      I'm trying to access the values I sent in the first try and catch block. I presume I should see some real values and not the

      field names.This is how my output looks like:

      300	KOKR	WERK	ARBPL0	AUFNR0	VORN	ILE	
      300	KOKR	WERK	ARBPL1	AUFNR1	VORN	ILE	
      300	KOKR	WERK	ARBPL2	AUFNR2	VORN	ILE	
      300	KOKR	WERK	ARBPL3	AUFNR3	VORN	ILE	
      300	KOKR	WERK	ARBPL4	AUFNR4	VORN	ILE	
      300	KOKR	WERK	ARBPL5	AUFNR5	VORN	ILE

      This does not reflect the values but the field names. Why is it this way? Does it mean that my array is wrong or I'm not at all

      sending the values. Please HELP ME OUT HERE.

      Could any one show me a better way how to send the values selected from Oracle table using perhaps an

      ARRAY to the ZSAORA_RUECK structure in SAP?

      I am trying to send the values from the select statement in the first jdbc application

      to the value field in ztable.setValue(value, field name).

      My Regards!

      Message was edited by: Rudolph Emange

  • author's profile photo Former Member
    Former Member
    Posted on May 25, 2005 at 08:24 AM

    Rudolph,

    your code looks ok to me. I use structures in the same way as you do to obtain the values.

    To me, your output looks as if the RFC-functions returns some kind of debug output. Your output list doesn't contain the field names, e.g. 300 seems to be the client (Mandant). And the other values are counted up from 1 to row end.

    Try to excecute the function with the same input parameters directly in R\3 and compare the result. I would guess it's the same. Perhaps the function module is not finished and the developer just returns some debug values ?

    Regards, Astrid

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Astrid,

      Thanks for your input. I tried some thing else. This is what I did. I gave the parameterArray from Oracle jdbc as the value of:

      ztable.setValue(value,field name);

      This is what I did:

      for (int i = 0; i < paramArray.length; i++) {
      ztable.appendRow(); //ztable.setValue(value, name of the field)
      
      ztable.setValue(paramArray<i>,"MANDT");
      ztable.setValue(paramArray<i>, "KOKRS");
      ztable.setValue(paramArray<i>, "WERKS");
      ztable.setValue(paramArray<i>, "ARBPL");
      ztable.setValue(paramArray<i>, "AUFNR");
      ztable.setValue(paramArray<i>, "VORNR");

      What I am doing to my openion is giving the value from the select jdbc application direct as the value in the setValue Method in JCO.

      Interestingly the result looks different and more interesting but I still got doubts.

      The array starts at 0 and the first value to my openion should be MANDT and second KOKRS etc.

      But is that what really happen in the structure? Your input will be appreciated Astrid.

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.