2023 Nov 21 6:34 AM
Hi, I am trying to pull list of all users in SAP ECC using the below code:
```
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoDestinationManager;
import com.sap.conn.jco.JCoException;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoParameterList;
import com.sap.conn.jco.JCoTable;
public class SAPDestinationTable {
public static void main(String[] args) {
try { //
Establish connection
JCoDestination destination = JCoDestinationManager.getDestination("SAP-ECC"); destination.ping();
// Create function module call JCoFunction function = destination.getRepository().getFunction("RFC_READ_TABLE");
// Set up function module parameters
JCoParameterList imports = function.getImportParameterList();
imports.setValue("QUERY_TABLE", "USR02");
imports.setValue("DELIMITER", ",");
// Execute the function module call
function.execute(destination);
System.out.println(function.getTableParameterList().getTable("OPTIONS"));
// Get the data table
JCoTable dataTable = function.getTableParameterList().getTable("DATA");
// Get the fields table
JCoTable fieldsTable = function.getTableParameterList().getTable("FIELDS");
System.out.println(dataTable.getNumRows());
System.out.println(fieldsTable);
// Create CSV file writer
BufferedWriter writer = new BufferedWriter(new FileWriter("output-testing.csv"));
// Write column headings to CSV
System.out.println(fieldsTable);
for (int i = 0; i < fieldsTable.getNumRows(); i++) {
fieldsTable.setRow(i);
String fieldName = fieldsTable.getString("FIELDTEXT");
writer.write(fieldName);
if (i < fieldsTable.getNumRows() - 1) {
writer.write(",");
}
} writer.newLine();
// Write data rows to CSV
for (int i = 0; i < dataTable.getNumRows(); i++) {
dataTable.setRow(i);
for (int j = 0; j < dataTable.getNumColumns(); j++) {
String fieldValue = dataTable.getString(j);
writer.write(fieldValue);
if (j < dataTable.getNumColumns() - 1) {
writer.write(",");
} }
writer.newLine();
}
// Close the writer writer.close();
System.out.println("Data written to output-testing.csv successfully.");
}
\catch (JCoException | IOException e) {
e.printStackTrace();
}
}}
```
but getting below error:
com.sap.conn.jco.AbapException: (126) DATA_BUFFER_EXCEEDED: DATA_BUFFER_EXCEEDED at com.sap.conn.jco.rt.ClientConnection.executeInternal(ClientConnection.java:2062) at com.sap.conn.jco.rt.ClientConnection.execute(ClientConnection.java:2257) at com.sap.conn.jco.rt.ClientConnection.execute(ClientConnection.java:2124) at com.sap.conn.jco.rt.RfcDestination.execute(RfcDestination.java:2289) at com.sap.conn.jco.rt.RfcDestination.execute(RfcDestination.java:2253) at com.sap.conn.jco.rt.AbapFunction.execute(AbapFunction.java:305) at SAPDestinationTable.main(SAPDestinationTable.java:27)
2023 Nov 21 8:22 AM
Hello amankumarchagti
As per note 382318 - FAQ | Function module RFC_READ_TABLE the function is not recommended for customer usage.
The DATA_BUFFER_EXCEEDED exception is caused by the fact that the function uses 512 chars buffer to get the data from a table. To get around it select fewer fields from the table, so a single result row fits 512 chars limitation. You can specify the fields with FIELDS parameters.
Alternatively as per note 3291780 - Enhancement RFC_READ_TABLE (7.31) you can get the data from the table in ET_DATA export parameter which is not limited to 512 chars:
Instead of using the table parameter DATA with the maximum output length of 512 characters and the fixed length display, the new export parameter ET_DATA can be used to return data in a string-based format. In this format, cell contents are transferred in dynamic lengths separated by delimiters. This means that data fields with dynamic length (STRING, ... ) are supported. Set the new optional import parameter USE_ET_DATA_4_RETURN to 'X' to get results returned in ET_DATA.
Best regards
Dominik Tylczynski
2023 Nov 21 9:19 AM
made below change in code, giving an error:
```
JCoParameterList imports = function.getImportParameterList();
```
error:
```
Exception in thread "main" com.sap.conn.jco.JCoRuntimeException: (127) JCO_ERROR_FIELD_NOT_FOUND: Field 'USE_ET_DATA_4_RETURN' is not a member of record 'INPUT'
```
2023 Nov 21 9:31 AM
amankumarchagti
Check the RFC_READ_TABLE function in the SE37 transaction and see its interface. The interface in my system is the following:
USE_ET_DATA_4_RETURN is there. Maybe we are on an older version where this parameter is not implemented yet?
If you don't have USE_ET_DATA_4_RETURN and ET_DATA, then you need to fit your result within 512 chars limit by specifying result fields in FIELDS.
2023 Nov 21 8:50 AM
RFC_READ_TABLE is a security risk. If the service user is authorised for that FM, there is nothing to stop it being used to read any data on the system. Very insecure, not recommended at all.
If you want data from a sap system, create your own function module. Then the service user can be authorised for just that function module and nothing else.
Additionally, it'll make it easy to code for in Java.