cancel
Showing results for 
Search instead for 
Did you mean: 

\n (New Line) changing to # in Payload in POST method in JSON format

devagreen
Explorer
0 Kudos
1,897

payload.jpgslash-n-converted-to-hash.jpgHello Experts,

I have to create Notification in SAP using POST method by using data from Mulesoft.

I have a field called LongText where it can take upto 30000 chars. In this text field, wherever \n is there, i need to break the text to new line. Now the problem is When i receive payload, no where i see the \n but system replacing \n with #.

SPLIT ls_data-long_text AT '#' INTO TABLE lt_ltext.

SPLIT ls_data-long_text AT '\n' INTO TABLE lt_ltext2.

Tried both the above statments to split, but not working. Because it is not exactly #.

Note : Facing this issue only in JSON format. When i test in XML format, It is working fine. But the business needs it in JSON format only.

Thanks

Deva

Sandra_Rossi
Active Contributor
0 Kudos

In the debugger, in hexadecimal mode, you'll see 000A or 0A00 at the start of the second line where there is #. U+000A is the Unicode character corresponding to "\n". See Jörgen answer for more information.

View Entire Topic
joltdx
Active Contributor

Hi!

The \n is not replaced by a # sign in the real data, but in that debugger screen, the newline character can not be displayed. Characters that can not be displayed will be displayed as # instead.

As to the SPLIT not working, when you use ' to define a character string, the literal characters are used, so '\n' is a c with length 2 consisting of \ and n, which is not what you want.

Instead you need to specify it as a string, using |, so |\n| will be a CString with length 1 containg a newline character. (Displayed like # in the debugger as explained above)

You can also usa a system constant for it, either of these lines should do the trick:

SPLIT ls_data-long_text AT |\n| INTO TABLE lt_ltext2.
SPLIT ls_data-long_text AT cl_abap_char_utilities=>newline INTO TABLE lt_ltext2.
devagreen
Explorer
0 Kudos

Thank You jorgen_lindqvist41.

It works.

SPLIT ls_data-long_text AT cl_abap_char_utilities=>newline INTOTABLE lt_ltext2.