on 2023 May 31 8:44 PM
Hello,
Here is the scenario: I execute a JCo call on a function module and call the toJSON() on the output Table or Structure. All the data prints fine except for fields which are of type "RAW".
Here is an example where I am looking at the output of SWNC_GET_WORKLOAD_STATRECS and the field DISPCNT shows up as:
"DISPCNT":"AAE="
If you check the metadata, DISPCNT is of type RAW as shown in the screenshot below. The same happens for few other fields (ex: "WPID":"AAA=", "TASKTYPE":"Cw==", "LUW_INFO":"Fw==") and all of them are of type RAW. I am using JCo version 3.1.7.
Any pointers are very much appreciated!

Request clarification before answering.
The RAW data bytes are serialized as Base64 string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks stefan.gass
Any pointers on how to go about decoding it? I have tried java.util.Base64 decoder as well Apache commons without any luck.
Using Apache Commons: org.apache.commons.codec.binary.Base64;
String encodedString = "sGwAAA==";
Base64 base64 = new Base64();
String decodedString = new String(base64.decode(encodedString.getBytes()));
System.out.println(decodedString);The above prints output as: �l
Using the java.util.Base64 library
String encodedString = "sGwAAA==";
byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
String decodedString = new String(decodedBytes);
System.out.println(decodedString);Prints the output as �l
stefan.gass - The problem is that the output (after decoding) does not match the expected String. Here is another example:
Here is a snapshot of the raw JSON output received after calling toJSON() on the MAINRECS table received from SWNC_GET_WORKLOAD_SNAPSHOT
{“MAINREC”:{“RECNO”:2,“DISPCNT”:“AAE=“,”ZTTADATE”:“2023-06-02”,“STARTDATE”:“2023-06-02”,“STARTTIME”:“14:06:41”,“STARTTIMESTAMP”:20230602180641,“ENDDATE”:“2023-06-02",“ENDTIME”:“14:06:41",“ENDTIMESTAMP”:20230602180641,“TARGETTIMEZONE”:“EST”,“RESPTI”:3213,“CPUTI”:0,“QUEUETI”:50,“WPID”:“AAA=“,”TASKTYPE”:“Cw==“,”TABLOAD”:“AA==“,”ACCOUNT”:“SAPSYS”,“MANDT”:“000”,“ROLLKEY”:“KT0AAA==“,
As you can see, ROLLKEY shows up as: KT0AAA==
If you look in SAPGUI for this data, ROLLKEY is displayed as 293D0000. Below is a screenshot.
Now when I decode KT0AAA== using either java.util.Base64 or org.apache.commons.codec.binary.Base64 (same java code snippet pasted in earlier comment) in both cases the output is )=
Wondering how do I get what SAP GUI shows: 293D0000
Thanks again!

Base64 string "KT0AAA==" represents the 4 bytes: 0x29 0x3D 0x00 0x00
So what is done by this ABAP transaction for the SAP GUI output, is to convert the RAW bytes into a hex string.
If you would like to achieve the same in Java, decode the Base64 string into a byte[], and afterwards convert the byte[] into a hex string.
-- Or simply call myMainrec.getString("ROLLKEY") on the respective JCoStructure object. The JCoRecord.getString() API will also do an on-the-fly conversion from RAW/BYTE type fields to hex strings.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.