cancel
Showing results for 
Search instead for 
Did you mean: 

JCo getting truncated value from SAP when field data type is RAW

Former Member
0 Kudos

We are trying to fetch data from a SAP-AII table by using JCo using the RFC RFC_READ_TABLE.

We are getting incomplete data when the data type of the column is RAW in a particular table.A typical case is:

Table Name: /AIN/DM_DEVCTR

Field : CLIENT Type: CLNT Length:3 Value: 100 (SAP Generated)

Field: DEVCTR_GUID Type:RAW Length:16 Value: 306F50F53805ED488DE9797AC86B5728 (SAP Generated)

Filed: DEVCTR_ID Type:CHAR Length:128 Value: KDEVICECONTROLLER (User input)

For the fields CLIENT and DEVCTR_ID we get the entire value (including blank spaces) but for DEVCTR_GUID we get only 16 characters whereas SAP-AII stores a value that is 32 characters in length. How do we fetch the actual value instead of the truncated value?

Sample code is attached.

-


try {

mConnection = JCO.createClient("100", // SAP client

"User", // userid

"Password", // password

"EN", // language

"SAP", // host name

"00"); // system number

mConnection.connect();

if (mConnection == null) {

System.out.println("Connection to SAP Server failed.");

}

mRepository = new JCO.Repository("User", mConnection);

ftemplate = mRepository.getFunctionTemplate("RFC_READ_TABLE");

} catch (Exception ex) {

ex.printStackTrace();

System.exit(1);

}

JCO.Function function = ftemplate.getFunction();

JCO.ParameterList importParamList = function.getImportParameterList();

importParamList.setValue("/AIN/DM_DEVCTR", "QUERY_TABLE");

importParamList.setValue(";", "DELIMITER");

JCO.Table tableData = function.getTableParameterList().getTable("DATA");

JCO.Table fields = function.getTableParameterList().getTable("FIELDS");

mConnection.execute(function);

if (tableData.getNumRows() > 0) {

do {

for (JCO.FieldIterator e = tableData.fields(); e

.hasMoreElements();) {

JCO.Field field = e.nextField();

String str = field.getString();

String[] values = str.split(";");

for(int i = 0; i < values.length; i++){

System.out.println(values<i>);

}

}

} while (tableData.nextRow());

} else {

System.out.println("No results found");

}

mConnection.disconnect();

}

-


Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Kaanu,

You have to modify your java code.

String val = new String( field.getByteArray());

PS: Please reward points for helpful answer or problem resolved.

Former Member
0 Kudos

Hi Joshi,

The <b>DATA</b> table in <b>RFC_READ_TABLE</b> has WA of type SYCHAR512. Hence it cannot hold more that 512 characters. Though the data returned is of BYTES it runs out of space. Try to create a custom function module similar to RFC_READ_TABLE. Here in the <b>DATA</b> table create WA of type CHAR4000. Then you will not face this problem. I had a similar situation where i was not able to download data from tables like MARA. Give a try. Hope this solves your problem.

Thanks

Kathirvel

Former Member
0 Kudos

Hi Kathirvel,

Well RFC_READ_TABLE works fine as it is not the one truncating the value of the field. The problem is SAP defined the field in the table as RAW with length as 16 when actually it stores a 32 character value in it. However, JCo does not seem to understand the meaning of RAW and instead of getting 32 character value fetches only the first 16 characters from that field (probably because SAP defined it with a length of 16). How do I overcome this to get all the 32 characters??

Former Member
0 Kudos

You can't use string for a RAW data type. If you look at the JCO_Tutorial.pdf document you recieved with JCO you will find a chart that show the ABAP data type and the corresonding Java data type. RAW has to be assigned to the JCO.BYTE type.

There are two ways to do this. Change you java code or build an ABAP wrapper that will translate the RAW into a CHAR type in ABAP side (recommended).

Stephen

PS.

The chart should be on or around page 19 of the Tutorial.

Former Member
0 Kudos

"You can't use string for a RAW data type. ....". I completetly agree with you on this. I do not know what to change in either the Java code nor in the ABAP code!!!