Question:
HI guys,
I am Using "RFC_READ_TABLE" function in JCO environment.
here I am giving code.
I want to get the data of MARA table by giving MATNR value.
here I am giving code.
<%@ page language="java" %>
<%@page import="com.sap.mw.jco.*"%>
<HTML>
<BODY class=bg MARGINWIDTH="0" MARGINHEIGHT="0" LEFTMARGIN="0" TOPMARGIN="0" BGCOLOR="#FFFFFF">
<%
// The MySAP.com system we gonna be using
String SID = "R3";
// The repository we will be using
IRepository repository;
try {
// Add a connection pool to the specified system
JCO.addClientPool(SID, // Alias for this pool
10, // Max. number of connections
"000", // SAP client
"abapdev1", // userid
"bct", // password
"EN", // language
"172.16.0.188",// host name
"00");
// Create a new repository
repository = JCO.createRepository("MYRepository", SID);
}
catch (JCO.Exception ex) {
System.out.println("Caught an exception: \n" + ex);
}
repository = JCO.createRepository("MYRepository", SID);
try {
// Get a function template from the repository
IFunctionTemplate ftemplate = repository.getFunctionTemplate("RFC_READ_TABLE");
// Create a function from the template
JCO.Function function = new JCO.Function(ftemplate);
// Get a client from the pool
JCO.Client client = JCO.getClient(SID);
JCO.ParameterList input = function.getImportParameterList();
input.setValue("000000000000001", "MATERIAL_NUMBER");
// We can call 'RFC_SYSTEM_INFO' directly since it does not need any input parameters
client.execute(function);
// The export parameter 'RFCSI_EXPORT' contains a structure of type 'RFCSI'
JCO.Structure s = function.getExportParameterList().getStructure("RFCSI_EXPORT");
// Use enumeration to loop over all fields of the structure
%>
<H1>System info for <%= SID %></H1>
<BR>
<%
for (JCO.FieldIterator e = s.fields(); e.hasMoreElements(); ) {
JCO.Field field = e.nextField();
%>
<%= field.getName() %> : <%= field.getString() %><BR>
<%
}//for
%>
<BR>
<%
// Release the client into the pool
JCO.releaseClient(client);
}
catch (Exception ex) {
System.out.println("Caught an exception: \n" + ex);
}
%>
</BODY>
</HTML>
bye
Rajagopal
Answer:
as you know how to set input parameter and read output parameter of a function in JCO, you should manage without sample code.
However some hints:
first have a look at SE37 in your SAP system, there you can test RFC_READ_TABLE directly and you can see which parameters the function has
then fill in parameter QUERY_TABLE the table you want to read
provide a valid abap where clause (without where) in OPTIONS.
e.g. MATNR = '0000000000000001'
provide Table FIELDS with all the fields you want to read from the table you specified in QUERY_TABLE.
Regards
Christine