Hi guys,
I am Using "RFC_READ_TABLE" function in JCO environment.I want to get the FIELD data element attribute DOCNUM, STATUS, COUNTR and STATXT from EDIDS table by giving STATUS and LOGDAT value in OPTIONS. I am unable to fetch FIELD data element attribute in different columns.
I am providing the java coding for reference.
Program Code:-
import com.sap.mw.jco.*;
public class projectIdocStatus extends Object {
public static void main(String args[]) {
projectIdocStatus app = new projectIdocStatus();
}
int count;
JCO.Client mConnection;
JCO.Repository mRepository;
String[] SAPInterfaces;
public projectIdocStatus() {
try {
// Change the logon information to your own system/user
mConnection = JCO.createClient("CLIENT", // SAP client
"USERID", // userid
"PASSWORD", // password
"LANGUAGE", // language
"HOSTNAME", // application server host name
"00"); // system number // system number
mConnection.connect();
mRepository = new JCO.Repository("ARAsoft", mConnection);*/
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
JCO.Function function = null;
JCO.Table codes = null;
try {
function = this.createFunction("RFC_READ_TABLE");
if (function == null) {
System.out.println("RFC_READ_TABLE" + " not found in SAP.");
System.exit(1);
}
// Set query
JCO.ParameterList listParams = function.getImportParameterList();
listParams.setValue("EDIDS", "QUERY_TABLE");
//listParams.setValue("1", "DELIMITER");
//listParams.setValue("", "NO_DATA");
//listParams.setValue("0", "ROWSKIPS");
listParams.setValue("100", "ROWCOUNT");
function.setImportParameterList(listParams);
//System.out.println("QUERY PASSED" );
// Set options
JCO.ParameterList itabOpt = function.getTableParameterList();
JCO.Table tableOpt = itabOpt.getTable("OPTIONS");
tableOpt.appendRow();
tableOpt.setValue("STATUS <= '51' AND LOGDAT >= '01.01.2014'", "TEXT");
numRows1 = tableOpt.getNumRows();
//System.out.println("Contents of OPTIONS " + numRows1);
function.setTableParameterList(itabOpt);
//System.out.println("OPTIONS PASSED " );
// Set fields
JCO.ParameterList itabFld = function.getTableParameterList();
JCO.Table tableFld = itabFld.getTable("FIELDS");
tableFld.appendRow();
tableFld.setValue( "DOCNUM","FIELDNAME");
tableFld.appendRow();
tableFld.setValue( "STATUS","FIELDNAME");
tableFld.appendRow();
tableFld.setValue( "COUNTR","FIELDNAME");
tableFld.appendRow();
tableFld.setValue( "STATXT","FIELDNAME");
numRows1 = tableFld.getNumRows();
// Execute the function
mConnection.execute(function);
JCO.Table tableData = function.getTableParameterList().getTable("DATA");
int columnRows = tableData.getNumColumns();
System.out.println("Columns of TableData " + columnRows);
// Print results
if (tableData.getNumRows() > 0) {
// Loop over all rows
do {
System.out.println("----------------------------------------------");
// Loop over all columns in the current row
for (JCO.FieldIterator e=tableData.fields();
e.hasMoreElements(); ) {
JCO.Field field = e.nextField();
System.out.println(field.getName() + ":\t" + field.getString());
}//for
} while(tableData.nextRow());
}else {
System.out.println("No results found");
}//if
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("Try Fails" );
}
}
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.");
}
}
}
Thanks and Regards
Anurag