Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Using FM FTP_SERVER_TO_R3, how to change the special characters?

0 Kudos

Hi guys! I tried to look for answers regarding this matter but it seems not working for my case. I can't use OPEN Dataset as I am using Username/PW and destination to connect to the folder.

The other option for a program is to select a file from Local directory. Using GUI_UPLOAD has a parameter to use CODEPAGE = 4110. So this method is perfectly fine. My only problem left is FTP_SERVER_TO_R3 and how to convert to normal characters.

Below are the steps on how I coded it in order and tried other method to convert it.

1.) SAPFTP, no ascii to FTP Command

From server: This is the character that is from the upload file

After calling FTP_SERVER_TO_R3, it converts into this in the debug mode

2.) Tried to use FM 'SCP_REPLACE_STRANGE_CHARS' ,using default parameters. Not sure what codepage I need to enter to those parameters.

Output

3.) If I change destination from SAPFTP to SAPFTPA

After calling FTP_SERVER_TO_R3, it converts into this in the debug mode

4.) Using ASCII to FTP Command

5.) Tried LT_BLOB and convert to XSTRING but it is truncated and format is no good.

Hoping for your ideas. Thank you!

5 REPLIES 5

Sandra_Rossi
Active Contributor
0 Kudos

Please don't post text and code as images. Use the "CODE" button to format them nicely.

Sandra_Rossi
Active Contributor

You should call FTP_SERVER_TO_R3 in BINARY mode, and decode from UTF-8 (SAP code page 4110) this way (NB: this example is with a subroutine that I recommend to transform into a method):

FORM ftp_get_utf8
  USING    VALUE(i_ftp_handle) TYPE i
           VALUE(i_filename)   TYPE c
  CHANGING e_string            TYPE string.

  DATA: l_blob_length TYPE i,
        lt_blob       TYPE solix_tab.

  CALL FUNCTION 'FTP_SERVER_TO_R3'
    EXPORTING
      handle        = i_ftp_handle
      fname         = i_filename
    IMPORTING
      blob_length   = l_blob_length
    TABLES
      blob          = lt_blob
    EXCEPTIONS
      tcpip_error   = 1
      command_error = 2
      data_error    = 3
      OTHERS        = 4.
  CONCATENATE LINES OF lt_blob INTO e_blob IN BYTE MODE.
  e_blob = e_blob(l_blob_length).

  DATA xstring TYPE xstring.
  xstring = cl_bcs_convert=>solix_to_xstring( IT_SOLIX = lt_blob IV_SIZE = l_blob_length ).

  " NB: we assume that file has UTF-8 encoding
  e_string = cl_abap_codepage=>convert_from( xstring ). " UTF-8 by default

ENDFORM.

0 Kudos

Hi Sandra,

Appreciate for sharing this. I also tried this hoping it will solve my problem, but my list is truncated. The file consists of Header, Items and Trail. So when it pass to e_string, it is truncated. 😞

0 Kudos

EDIT fixed the syntax error of my answer: "IT_SOLIX = solix_tab" replaced with "IT_SOLIX = lt_blob".

Technically speaking, a file is made of only one string of bytes, your vision of "Header, Items and Trail" is a functional split of this stream of bytes. The example code above only considers a string of bytes, so it's valid for any further interpretation of these bytes.

So, after calling the procedure above, probably the result is valid but the rest of your code is faulty.

tma_sopra
Explorer
0 Kudos

Hello,

I am trying to transfer a FTP file in UTF-8 using your routine.

What is the type of e_blob?

Thank you

Best regards,

Christophe