08-23-2016 6:46 AM
Hello all
I need to send JSON data to a customer, for example :
[{"PERNR":"00000001","NACHN":"Smith","VORNA":"Jürgen"}]
This data will be sent and received via flat files, and also via OData in SEGW (SAP Gateway Builder). So I assume the name "Jürgen" for example would need to be encoded ..
Questions:
1) Do I need to encode this to UTF-8 ?
2) If so, how do I do this in ABAP ?
(If seen cl_abap_conv_out_ce=>create( encoding = '4110' ) - but this results in an XSTRING ? )
Thanks in advance !
Jan
08-23-2016 7:01 AM
Of course it's XSTRING, how could it be stored another way? If you're in a Unicode system, characters in String or C are always stored in UTF-16, cannot be anything else (more exactly UCS-2).
08-23-2016 7:00 AM
08-23-2016 7:01 AM
Of course it's XSTRING, how could it be stored another way? If you're in a Unicode system, characters in String or C are always stored in UTF-16, cannot be anything else (more exactly UCS-2).
08-23-2016 7:20 AM
Thanks Sandra, I understand that the result is XSTRING but my challenge is to now represent this as JSON data in an OData response - which I thought could only be of type STRING - therefore ü would be "ü" or something similar ?
08-23-2016 7:41 AM
which I thought could only be of type STRING
What makes you think so?
OData is itself based on XML and/or JSON. You create the files as strings on your platform, but you send them around as UTF-8.
In fact I don't think you have to care at all. "Jürgen" should be translated to the appropriate UTF-8 representation by the OData framework, your'e using.
Horst
08-23-2016 7:51 AM
08-23-2016 7:55 AM
08-23-2016 7:10 AM
cl_abap_conv_out_ce=>create( encoding = '4110' )
A more convenient class is CL_ABAP_CODEPAGE, e.g.:
DATA: str TYPE string,
xstr TYPE xstring.
xstr = cl_abap_codepage=>convert_to(
source = str
codepage = `UTF-8` ).
You get a codepage representation of a character string in an xstring. Method convert_from does it vice versa.
If you transform ABAP data with call transformation you can decide whether the result is a string or an xstring, where xstring is the recommended type.
As Sandra said, ABAP characters are stored internally in UCS-2. But the standard transfer format for XML and JSON is UTF-8. Therfore, it makes sense to convert the internal ABAP representation into UTF-8 in an xstring.
Horst