I want to print details of all Transport requests, I am trying to read data in table E070
from SAP ECC using SAP JCo and RFC_READ_TABLE
, I am running the following code but I am getting no output.
Here is the code:
import com.sap.conn.jco.*;
import java.util.logging.*;
public class Transport {
private static final Logger logger = Logger.getLogger(Transport.class.getName());
public static void main(String[] args) {
// Configure logger
LogManager.getLogManager().reset();
logger.setLevel(Level.ALL);
ConsoleHandler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.ALL);
logger.addHandler(consoleHandler);
// Establish connection
JCoDestination destination;
try {
destination = JCoDestinationManager.getDestination("SAP-ECC-Dest");
destination.ping();
} catch (JCoException e) {
logger.log(Level.SEVERE, "Connection error", e);
return;
}
// Create function module call
JCoFunction function;
try {
function = destination.getRepository().getFunction("RFC_READ_TABLE");
} catch (JCoException e) {
logger.log(Level.SEVERE, "Function module error", e);
return;
}
// Set up function module parameters
JCoParameterList imports = function.getImportParameterList();
imports.setValue("QUERY_TABLE", "E070"); // Table name for transport requests
imports.setValue("DELIMITER", "|"); // Set delimiter for the result
JCoParameterList tableOptions = function.getTableParameterList();
JCoTable data = tableOptions.getTable("DATA");
// System.out.println(data);
// Add filters if required
// imports.setValue("OPTIONS", ...);
// Execute the function module call
try {
function.execute(destination);
} catch (JCoException e) {
logger.log(Level.SEVERE, "Function module execution error", e);
return;
}
// Process the results
String[] rows = data.getString().split("\\|");
for (String row : rows) {
String[] columns = row.split("\\|");
if (columns.length >= 3) {
String transportRequestId = columns[0]; // Request ID column
String description = columns[2]; // Description column
logger.info("Transport Request ID: " + transportRequestId);
logger.info("Description: " + description);
logger.info("-----------------------------------");
}
}
}
}
I have tried debugging it but nothing worked. Thank you :)
Maybe someone with more experience can tell me how should I configure this sample code in order to work.
following code worked for me:
import com.sap.conn.jco.*;
public class TransportRequestDetailsExamples {
public static void main(String[] args) {
try {
JCoDestination destination = JCoDestinationManager.getDestination("SAP-ECC-Dest");
destination.ping();
JCoFunction function= destination.getRepository().getFunction("RFC_READ_TABLE");
JCoParameterList imports = function.getImportParameterList();
imports.setValue("QUERY_TABLE", "E070");
imports.setValue("DELIMITER", ";");
JCoParameterList tableOptions = function.getTableParameterList();
JCoTable data = tableOptions.getTable("DATA");
function.execute(destination);
System.out.println(data);
} catch (JCoException e) {
e.printStackTrace();
}
}
}