Skip to Content
-2

ENCODING XML

Oct 23, 2017 at 06:44 AM

171

avatar image

I am generating xml file from 'CALL TRANSFORMATION' and it is generating with 'UTF-16' encoding method but to transfer this file to FTP server , When i Convert String to XString using 'SCMS_STRING _TO_XSTRING' then this function module converting data in 'UTF-8'and adding a special character in start of string .

I required data in 'UTF-16', So Please help

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Horst Keller
Oct 23, 2017 at 08:11 AM
2

Why do you transform to string and not to xstring? Why are you using the undocumented function module SCMS_STRING_TO_XSTRING which is part of a special framework and not the general system method CL_ABAP_CODEPAGE=>CONVERT_TO?

Share
10 |10000 characters needed characters left characters exceeded
Sandra Rossi Oct 23, 2017 at 07:00 AM
0

No, SCMS_STRING _TO_XSTRING does not add "a special character in start of string" (I would call it a "BOM" as it's about UTF but here it seems to be a different thing), or is there a bug in a given ABAP release. Which one are you using?

Which transformation are you using? ID or a custom one?

Could you tell again if you want UTF-8 or UTF-16 in your ABAP program? Which encoding or mime type are you using while calling SCMS_STRING_TO_XSTRING?

Moreover, if you generate the file in your abap program with the right target code page, make sure you transfer in BIN mode.

Show 13 Share
10 |10000 characters needed characters left characters exceeded

(1) I am using below mention code to generate XML.

APPEND WA_XML TO IT_XMLF.
CLEAR WA_XML.
DATA:L_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT.
CALL TRANSFORMATION ('ID')
SOURCE TAB = IT_XMLF[]
RESULT XML XML_OUT.

(2) When i am using below mention code when calling 'SCMS_STRING_TO_XSTRING'

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = xml_out2
* MIMETYPE = ' '
* ENCODING =
IMPORTING
BUFFER = xstring1
* EXCEPTIONS
* FAILED = 1
* OTHERS = 2
.

Here i am not passing mime type and encoding because i required data in UTF-16 and after 'CALL TRANSFORMATION' xml data in UTF-16 also.

For target Page is below mention screen shot.

This issue is coming after GST implementation and before GST this code was working fine.

0

As you use a string variable after RESULT XML, it's automatically encoded in UTF-16 in the string.

SCMS_STRING_TO_XSTRING without mimetype/encoding converts the string variable into an xstring variable in UTF-8 without leading bytes.

You can be sure of that by debugging and displaying the xstring with the Embedded code page converter (enter the code page 4110 for UTF-8).

So, the problem is after SCMS_STRING_TO_XSTRING.

0

I checkd Codepage through Debugging SCMS_STRING_TO_XSTRING which is processing is 4110.

After SCMS_STRING_TO_XSTRING i am using below mention code to transfer file to ftp server.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = xstring1
IMPORTING
output_length = len
TABLES
binary_tab = it_str[].

And after converting XSTRING to Binary i am transferring file to FTP Server.

CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
HANDLE = W_HDL
FNAME = FILE_NAME1 "file path of destination system
BLOB_LENGTH = len
* CHARACTER_MODE = MODE
TABLES
blob = IT_STR[]
* TEXT = IT_STR[]
** TEXT = lt_xml_table[]
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4.

.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

0

I mean, just check the XSTRING1 value after SCMS_STRING_TO_XSTRING, that the "Translation" is equal to your original text:

mw3rl.png (17.4 kB)
0

I checked and find that Translation is equal to original text.

0
If the issue is with FTP, the only thing strange maybe is IT_STR, does its name mean that you defined it as a table of STRing of characters? I doubt it will solve because anyway you did the transfer in binary mode (character_mode not passed to 'X') but try with a table of bytes (data it_str type table of X255 for instance).

Or the issue is about people telling you that the file is wrong. How did they check? Did they copy the file in text mode?

0

How can i check that issue with FTP server?

0

When i am place the file on ftp server without converting SCMS_STRING_TO_XSTRING and SCMS_XSTRING_TO_BINARY is working fine and data in UTF-16 .Use code is mention below.

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILETYPE = 'BIN'
FILENAME = FILENAME"'C:\Users\VINOD\Desktop\ASN'
TABLES
DATA_TAB = IT_STR.

0

I any possibility to change encoding this below mention step.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = xstring1
IMPORTING
output_length = len
TABLES
binary_tab = it_str[].

0

?<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><EDIFACT><UNB><UNB01><UNB0101>UNOB</UNB0101><UNB0102>2</UNB0102></UNB01><UNB02><UNB0201>0000100188</UNB0201></UNB02><UNB03><UNB0301>HMCL</UNB0301></UNB03><UNB04><UNB0401>171014</UNB0401><UNB0402>1141</UNB0402></UNB04><UNB05>1101001772</UNB05><UNB07>INVOIC</UNB07></UNB></EDIFACT>

In this ? is adding in start of file due to which file is not opening

0

Yes, of course it's invalid. Wasn't it the initial question? What did produce that please?

0

I am generating XML file with whole process and below is the output.

?<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><EDIFACT><UNB><UNB01><UNB0101>UNOB</UNB0101><UNB0102>2</UNB0102></UNB01><UNB02><UNB0201>0000100188</UNB0201></UNB02><UNB03><UNB0301>HMCL</UNB0301></UNB03><UNB04><UNB0401>171014</UNB0401><UNB0402>1141</UNB0402></UNB04><UNB05>1101001772</UNB05><UNB07>INVOIC</UNB07></UNB></EDIFACT>

0

Sorry, I can't help anymore as I still don't understand where/when your problem is exactly.

0
Horst Keller
Oct 24, 2017 at 01:57 PM
0

Why don't you transform into an object of CL_SXML_STRING_WRITER, created with encoding UTF-16, and get from there an XSTRING?

Show 1 Share
10 |10000 characters needed characters left characters exceeded

This issue is coming with only one customer but same FMs and program are working properly for different customer.

0