on 10-21-2008 1:21 PM
Hi All,
I have an issue getting some data from an SAP ABAP table using RFC_READ_TABLE and JCo 2.x.
The real scenario is different then the one decribed below, I am just testing.
I just want to RETURN all User Name's in the Client 400 from table USR01 using Java.util.Vector.
If I do this in a normal Java Class with a public static void main then the System.out.println returns all the values, but it doesn't work in a Session Bean as below.
I also used Hashtable, ArrayList, etc..
Please help or just let me know how to convert JCo.Table to anything (Arrays, Lists, Hashmap, Hashtable, etc..) that I can use in RETURN.
I have one Class with Getters and Setters (Demo.java) and one EJB Session Bean 3.0 (Stateless) with a Local and Remote Business Interface.
-
package entity;
import java.io.Serializable;
public class Demo implements Serializable {
/**
*/
private static final long serialVersionUID = 1L;
private String username;
public Demo(){
super();
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Demo(String pUserName){
username = pUserName;
}
}
-
/**
*/
package services;
import java.util.Vector;
import javax.ejb.Stateless;
import javax.jws.WebService;
import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.IRepository;
import com.sap.mw.jco.JCO;
import entity.Demo;
/**
@author Administrator
*
*/
@WebService(endpointInterface="services.DemoRemote", targetNamespace="http://services/", portName="DemoBeanPort", serviceName="DemoService")
@Stateless
public class DemoBean implements DemoRemote, DemoLocal {
public JCO.Connection conn = null;
private String WHERE_CLAUSE = "MANDT = '400'";
static final String SID = "R3";
JCO.Client mConnection;
IRepository repository;
public Demo[] getUserName() throws Exception {
JCO.Client client = null;
Vector<Demo> results = new Vector<Demo>();
try {
// Get a function template from the repository
IFunctionTemplate ftemplate = repository
.getFunctionTemplate("RFC_READ_TABLE");
// if the function definition was found in backend system
if (ftemplate != null) {
// Create a function from the template
JCO.Function function = ftemplate.getFunction();
// Get a client from the pool
client = JCO.getClient(SID);
// Fill in input parameters
JCO.ParameterList input = function.getImportParameterList();
// Input variable
input.setValue("USR01", "QUERY_TABLE");
input.setValue("", "DELIMITER");
input.setValue("X", "DISTINCT");
// Fill the where clause of the table
JCO.ParameterList tabInput = function.getTableParameterList();
JCO.Table inputTable = tabInput.getTable("OPTIONS");
inputTable.appendRow();
inputTable.setValue(WHERE_CLAUSE, "TEXT");
// Find the position of the field that has to be lookedUp
JCO.Table lookupFieldPos = function.getTableParameterList()
.getTable("FIELDS");
lookupFieldPos.appendRow();
lookupFieldPos.setValue("BNAME", "FIELDNAME");
// Call the remote system
client.execute(function);
// Get the exact lookupvalue from the position obtained
// above
JCO.Table valueSet = function.getTableParameterList().getTable(
"DATA");
// Print results
if (valueSet.getNumRows() > 0) {
// Loop over all rows
do {
for (int i = 0; i < valueSet.getNumRows(); i++, valueSet
.nextRow()) {
results.add((Demo) valueSet.getValue("WA"));
// System.out.println(valueSet.getValue("WA"));
}
}
while (valueSet.nextRow());
} else {
System.out.println("Hallo:" + results);
if (results.isEmpty()) {
System.out
.println("No data retirved for selection criteria");
System.exit(1);
}
System.out.println("No results found");
}
}
else {
System.out
.println("Function RFC_READ_TABLE not found in backend system.");
}
} catch (Exception ex) {
System.out.println("Caught an exception: \n" + ex);
} finally {
System.out.println("Hello:" + results);
// Release the client to the pool
JCO.releaseClient(client);
}
return (Demo[]) results.toArray(new Demo[] { });
}
}
Thanks.!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.