on 10-10-2019 10:37 AM
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!.
"I verified the error in debugger as I am getting truncated value after the serializing string se11 structure to json."
Sorry, but you select the correct display of your variable in the debug? When you select that to display the contente, you can select the display type, like a show in the image bellow:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
(the "fast display" displays only the first 255 characters of a variable, while the "browser" options display everything)
thank you Sandra Rossi and Raphael Pacheco
Hi Manisha,
I think to comprehend the problem at hand, is the abap type you used to pass the data to the serialize method.. I don't know what "type" your body_to_string variable was, but i would guess that this has a restriction of maximum 255 chars, resulting in breaking off the variable value when passing it to the serializer.. The use of a string table like Sandra suggested is a good option to use, also a custom datatype longer than 255 chars will have helped as well.
Kind regards
Yor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
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.
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.
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.
User | Count |
---|---|
100 | |
9 | |
7 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.