‎2022 Jun 01 11:37 AM
Dear Friends ,
I have made a program that call an API and the answer is in UTF-16 and I cannot handle it. I have searched many hours on the forum but I did;t managed to fix it.
Can you propose something?
CALL METHOD P_HTTP_CLIENT->RECEIVE
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3
OTHERS = 4.
P_P_CONTENT = P_HTTP_CLIENT->RESPONSE->GET_CDATA( ).
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = P_P_CONTENT
IMPORTING
BUFFER = GV_XML_STRING
EXCEPTIONS
FAILED = 1
OTHERS = 2.
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
XML_INPUT = GV_XML_STRING
TABLES
XML_TABLE = GWA_XML_DATA
Look the result that I take from server

And look the headers that I sent ....

Thanks a lot .....
‎2022 Jun 01 1:22 PM
Hi Dimitras,
You could try something like this for UTF-16LE (4102 for BE) - All parameters but one are mandatory so this is just a sample but you can tailor it however you want and see if it will work. Also, if this does not work there are some system -> external and external -> system format classes you can try: CL_ABAP_CONV_IN_CE, CL_ABAP_CONV_OUT_CE.
DATA: input TYPE xstring,
output TYPE xstring,
inused TYPE i,
outused TYPE i,
substed TYPE i,
input_ends TYPE c,
too_short TYPE c.
DATA(converter) = NEW cl_abap_conv_obj( incode = '4103'
outcode = '4110' ).
converter->convert( EXPORTING
inbuff = input
outbufflg = 10485760 "10MB buffer limit
IMPORTING
outbuff = output
inused = inused
outused = outused
substed = substed
input_ends_in_char = input_ends
outbuff_too_short = too_short ).
Regards,
Ryan Crosby
‎2022 Jun 01 11:50 AM
Hi,
please check class cl_abap_conv_codepage, like
cl_abap_conv_codepage=>create_in( CODEPAGE = 'UTF-16' )->convert( l_xstr )
‎2022 Jun 01 12:04 PM
‎2022 Jun 01 12:53 PM
‎2022 Jun 01 1:04 PM
Hi Dimitras,
Is the UTF-16 big endian or little endian?
Regards,
Ryan Crosby
‎2022 Jun 01 1:21 PM
‎2022 Jun 01 1:22 PM
Hi Dimitras,
You could try something like this for UTF-16LE (4102 for BE) - All parameters but one are mandatory so this is just a sample but you can tailor it however you want and see if it will work. Also, if this does not work there are some system -> external and external -> system format classes you can try: CL_ABAP_CONV_IN_CE, CL_ABAP_CONV_OUT_CE.
DATA: input TYPE xstring,
output TYPE xstring,
inused TYPE i,
outused TYPE i,
substed TYPE i,
input_ends TYPE c,
too_short TYPE c.
DATA(converter) = NEW cl_abap_conv_obj( incode = '4103'
outcode = '4110' ).
converter->convert( EXPORTING
inbuff = input
outbufflg = 10485760 "10MB buffer limit
IMPORTING
outbuff = output
inused = inused
outused = outused
substed = substed
input_ends_in_char = input_ends
outbuff_too_short = too_short ).
Regards,
Ryan Crosby
‎2022 Jun 01 1:45 PM
Thanks a lot!
Correct answer.
You help me very much.
P.S)Thanks all for the help/
‎2022 Jun 01 5:37 PM
It's UTF-16LE (little endian) because of order <# (where # is in fact the null byte in your case). If order was #< that would be big endian.
Note that if you define an XML transformation to process the XML, you would use GET_DATA instead of GET_CDATA, and you wouldn't need to care about the encoding/codepage.