cancel
Showing results for 
Search instead for 
Did you mean: 

read XML file from FTP using FTP_SERVER_TO_R3

0 Kudos

read XML file from FTP using FTP_SERVER_TO_R3 getting # character in text content data

Sandra_Rossi
Active Contributor

Why # could not be the actual value? # instead of what?

Probably you read it with the wrong code page. What is the original code page of the file? You may read the file in binary mode + BLOB and decode the text using the right code page...

Hi Sandra,

The actual file is not having # character, getting it after reading from FTP server.

"ÿþ<#?#x#m#l# #v#e#r#s#i#o#n#=#"#1#.#0#"# #e#n#c#o#d#i#n#g#=#"#U#T#F#-#8#"<"

I am trying to read XML file from FTP using FTP_SERVER_TO_R3 character mode directly in ABAP, also tried BLOB but not able to decode the text and not able to do XML parse.

The same file from local machine, is working fine.

please suggest.

Thanks

HCG

Accepted Solutions (0)

Answers (3)

Answers (3)

Sandra_Rossi
Active Contributor
0 Kudos

What we see seems to be a UTF-16LE encoding (AKA code page) in the first characters, but the contents are in UTF-8. So maybe the reality is that the original file is fully UTF-8 and FTP_SERVER_TO_R3 does a conversion into your SAP system code page (which would be UTF-16LE ; check it with transaction code SNLS).

So if you read the file in binary mode (so those bytes would be a text in UTF-8 encoding; use BLOB and concatenate byte lines into an xstring variable), and you convert it from UTF-8 into text (cf Roberto answer, or simply use:

string = CL_ABAP_CODEPAGE=>CONVERT_FROM( xstring ). " UTF-8 by default

(if you have 7.53 there is the newest CL_ABAP_CONV_CODEPAGE)

roberto_vacca2
Active Contributor
0 Kudos

Hi.

It seems two bytes for character.

I suggest you put the content of g_t_xml_tab in an xstring field (cv_string).

After that convert this content in a string field (lv_xml_string)

Finally create your file.

Hope to help



  CALL METHOD cl_abap_conv_in_ce=>create
    EXPORTING
      input = cv_string "(Xstring variable WITH XML)
    RECEIVING
      conv  = lr_conv.

  CALL METHOD lr_conv->read
    IMPORTING
      data = lv_xml_string. "(String variable WITH XML ENCODING UTF-8)


* Write new file using UTF-8 encoding


  OPEN DATASET f_filen FOR OUTPUT   IN TEXT MODE ENCODING UTF-8 IGNORING CONVERSION ERRORS.

  CHECK sy-subrc EQ 0.

  TRANSFER lv_xml_string TO f_filen.

  CLOSE DATASET f_filen.
0 Kudos

my code,

1. using HTTP_SCRAMBLE

2. using FTP_CONNECT

3. using FTP_COMMAND > set passive on

4. using FTP_COMMAND > CD

5. using FTP_COMMAND > LS

6. Reading XML using

CALL FUNCTION 'FTP_SERVER_TO_R3'
EXPORTING
handle = w_hdl
fname = w_path
character_mode = 'X'
TABLES
text = g_t_xml_tab
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.

The g_t_xml_tab having # character along with content data. please suggest.

Sandra_Rossi
Active Contributor
0 Kudos

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: "Before answering You should only submit an answer when you are proposing a solution to the poster's problem"

alikhach
Explorer
0 Kudos

Hi, i'm using the same code as you but i'm not able to read xml file at all (result table is empty). w_path in your case is 'File_name.xml'?