cancel
Showing results for 
Search instead for 
Did you mean: 

Is String to JSON Serializer length restricted to 255 characters ?

Hello all,

I am building an application which integrates s4hana with external web service for eg. successfactors to ariba. So our s4hana abap is consuming rest api based in python. While passing body parameters to the rest api call, I am serializing the string structure to json format which is accepted by our rest api. For eg,

body_in_string:

"Attribute1":"Value1",

"Attribute2":"Value2",

"Attribute3":[{"Sub-attri1":"Name1"},[{"Sub-attri2":"Name2"},[{"Sub-attri3":"Name3"},[{"Sub-attri4":"Name4"},[{"Sub-attri5":"Name5"},[{"Sub-attri6":"Name6"},[{"Sub-attri7":"Name7"},[{"Sub-attri8":"Name8"},[{"Sub-attri9":"Name9"},[{"Sub-attri10":"Name10"}],

"Attribute4":"Value4",

"Attribute5":"Value5",

"Attribute6":"Value6",

"Attribute7":"Value7"

I am using

/ui2/cl_json=>serialize( data =body_in_string compress = abap_false pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).

to serialize above string to json format as

{"Attribute1":"Value1",

"Attribute2":"Value2",

"Attribute3":[{"Sub-attri1":"Name1"},[{"Sub-attri2":"Name2"},[{"Sub-attri3":"Name3"},[{"Sub-attri4":"Name4"},[{"Sub-attri5":"Name5"},[{"Sub-attri6":"Name6"},[{"Sub-attri7":"Name7"},[{"Sub-attri8":"Name8"},[{"Sub-attri9":"Name9"},[{"Sub-attri10":"Name10"}],

"Attribute4":"Value4",

"Attribute5":"Value5",

"Attribute6":"Value6",

"Attribute7":"Value7"}

/ui2/cl_json Serializer is serializing string to json only upto 255 characters and rest is getting truncated. I have also tried-

DATA lo_json_writer TYPE REF TO cl_sxml_string_writer.
lo_json_writer = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json ).
CALL TRANSFORMATION id
SOURCE body = body_in_string
RESULT XML lo_json_writer.

Also tried,

DATA lr_json_serializer TYPE REF TO cl_trex_json_serializer.
CREATE OBJECT lr_json_serializer
EXPORTING
data = body_in_string.
lr_json_serializer->serialize( ).
lv_body = lr_json_serializer->get_data( ).

All of the options are truncating string value after 255 characters post above body_in_string to json serialization.

Please help!.

Sandra_Rossi
Active Contributor
0 Kudos

/UI2/CL_JSON and CALL TRANSFORMATION should not truncate strings. How are you sure it truncates?

NB: please use the CODE button to format your code so that it's shown in a more user-friendly format (colorized).

UweFetzer_se38
Active Contributor

Your body_in_string is already JSON. What do you want to achieve?

ABAP Data -> JSON

or

JSON -> ABAP-Data

Sandra_Rossi
Active Contributor

Uh I didn't pay attention enough to your code, but Uwe Fetzer is right, I don't understand what you're trying to achieve too !

0 Kudos

Hi Sandra and Uwe Fetzer,

I want to achieve ABAP DATA to JSON. Basically I have set of attributes to be passed as body parameter when consuming rest api service from abap. These attributes need to be serialized as json to be consumed by the service.

0 Kudos

Sorry for the confusion. I meant to paste internal table in body_in_string variable.

Sandra_Rossi
Active Contributor
0 Kudos

Manisha Madhwani What internal table?

0 Kudos

Internal table sap_t_dc_ec_req. Please find sample snippet.


DATA lv_body TYPE string.
DATA sap_v_len TYPE i.

TYPES: BEGIN OF ty_request,
attribute1 TYPE string,
attribute2 TYPE string,
attribute3 TYPE ztt_fields,
attribute4 TYPE string,
attribute5 TYPE string,
attribute6 TYPE string,
END OF ty_request.
DATA: sap_s_dc_ec_req TYPE ty_request,
sap_t_dc_ec_req TYPE STANDARD TABLE OF ty_request.

ls_fields-field = 'DUMMY'.
ls_fields-attribute = NAME'.
APPEND ls_fields TO lt_fields.

ls_fields-field = 'DUMMY'.
ls_fields-attribute = 'NAME2'.
APPEND ls_fields TO lt_fields.

ls_fields-field = 'DUMMY'.
ls_fields-attribute = 'NAME3'.
APPEND ls_fields TO lt_fields.

*&&&--- prepare request parameters for rest api call ---
sap_s_dc_ec_req-attribute1 = '127.0.0.1'.
sap_s_dc_ec_req-attribute2 = sy-uname.
sap_s_dc_ec_req-attribute6 = '420EEE10A8A00041EE9BAEE6CBF223D5CC9'.
sap_s_dc_ec_req-attribute4 = 'DUMMY'.
sap_s_dc_ec_req-attribute3[] = lt_fields[].

*&&&--- get utc time
sap_s_dc_ec_req-attribute5 = '2019-10-10T15:41:02Z'.
*&&&--- move to table
APPEND sap_s_dc_ec_req TO sap_t_dc_ec_req.
*&&&--- creating and returning json body request for rest call ---
TRY.
* option 3 ui2/json serializer

lv_body = /ui2/cl_json=>serialize( data = sap_t_dc_ec_req compress = abap_false pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).
Sandra_Rossi
Active Contributor

So you get this string of 286 characters - what is the problem?

[{"attribute1":"127.0.0.1","attribute2":"ROSSIS","attribute3":[{"field":"DUMMY","attribute":"NAME"},{"field":"DUMMY","attribute":"NAME2"},{"field":"DUMMY","attribute":"NAME3"}],"attribute4":"DUMMY","attribute5":"2019-10-10T15:41:02Z","attribute6":"420EEE10A8A00041EE9BAEE6CBF223D5CC9"}]

PS: here is the completed reproducible example:

DATA lv_body TYPE string.
DATA sap_v_len TYPE i.
TYPES:
BEGIN OF ty_field,
field TYPE string,
attribute TYPE string,
END OF ty_field,
ty_fields TYPE STANDARD TABLE OF ty_field WITH EMPTY KEY,
       BEGIN OF ty_request,
attribute1 TYPE string,
attribute2 TYPE string,
attribute3 TYPE ty_fields,
attribute4 TYPE string,
attribute5 TYPE string,
attribute6 TYPE string,
END OF ty_request.
DATA: ls_fields type ty_field,
lt_fields type ty_fields,
      sap_s_dc_ec_req TYPE ty_request,
sap_t_dc_ec_req TYPE STANDARD TABLE OF ty_request.

ls_fields-field = 'DUMMY'.
ls_fields-attribute = 'NAME'.
APPEND ls_fields TO lt_fields.

ls_fields-field = 'DUMMY'.
ls_fields-attribute = 'NAME2'.
APPEND ls_fields TO lt_fields.

ls_fields-field = 'DUMMY'.
ls_fields-attribute = 'NAME3'.
APPEND ls_fields TO lt_fields.

*&&&--- prepare request parameters for rest api call ---
sap_s_dc_ec_req-attribute1 = '127.0.0.1'.
sap_s_dc_ec_req-attribute2 = sy-uname.
sap_s_dc_ec_req-attribute6 = '420EEE10A8A00041EE9BAEE6CBF223D5CC9'.
sap_s_dc_ec_req-attribute4 = 'DUMMY'.
sap_s_dc_ec_req-attribute3[] = lt_fields[].

*&&&--- get utc time
sap_s_dc_ec_req-attribute5 = '2019-10-10T15:41:02Z'.
*&&&--- move to table
APPEND sap_s_dc_ec_req TO sap_t_dc_ec_req.
*&&&--- creating and returning json body request for rest call ---

lv_body = /ui2/cl_json=>serialize( data = sap_t_dc_ec_req compress = abap_false pretty_name = /ui2/cl_json=>pretty_mode-camel_case ).

BREAK-POINT.
View Entire Topic
0 Kudos

Hi Sandra,

Thank you for your reply. After the string structure is passed to the CALL TRANSFORMATION I am getting string returned with 255 characters only. I even tried editing the same by manually appending attribute to the json string(in debugger) the abap editor displayed error that only 255 characters will be transferred. Please let me know if you further need any information to help me fix this.

Thanks,

Manisha Madhwani

Sandra_Rossi
Active Contributor

Please use the COMMENT button for comments, questions, adding details, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

Sandra_Rossi
Active Contributor

Note that the backend debugger is a SAP GUI screen so its one-line input and text fields display only the first 255 characters of the variables.

0 Kudos

I verified the error in debugger as I am getting truncated value after the serializing string se11 structure to json.

Sandra_Rossi
Active Contributor

I am sure that SAP does not truncate to 255 characters (except if you have defined body_in_string as a variable of type C with 255 characters maximum). Only the value displayed is truncated. In memory, it's NOT truncated.

0 Kudos

yes thats what the issue is as I am using string to store value returned from json serializer.

Sandra_Rossi
Active Contributor
0 Kudos

I understand that your question is: how to display more than 255 characters in the backend debugger. Right?

Answer: see Raphael Pacheco comment.

Thank you Sandra you can mark your debugger reply as answer. It really helped.

Sandra_Rossi
Active Contributor
0 Kudos

Manisha Madhwani If you do a comment under a question/answer and you want to target someone else than the question/answer' author, the only solution is to copy/paste their hyperlinked name so that the person receives a warning.