Skip to Content
avatar image
Former Member

How to read .XLS file from FTP server in readable format

HI All,

I'm reading a .XLS file from FTP server using below FMs.

HTTP_SCRAMBLE

FTP_CONNECT - FTP connection

FTP_COMMAND - Change directory

FTP_SERVER_TO_R3 - Read file.

Issue is "FTP_SERVER_TO_R3" returns junk data as below.

Ex :" ÐÏࡱá > .................".

FYI :When I open the file directly from WINSCP in FTP server it shows the same junk data. (Or what ever the compression format it is in.) But, once I download the file to front end and open in Excel it shows data correctly.

Need your help to get the accurate data to internal table.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Jan 24 at 06:17 AM

    Hello Ruchira ,

    Try the below code :

    CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
    TEXT = 'Read file from FTP Server'.

    LV_CMD = WA_FILE.

    DATA: W_HDL TYPE I VALUE 1.

    CALL FUNCTION 'FTP_SERVER_TO_R3'
    EXPORTING
    HANDLE = W_HDL
    FNAME = LV_CMD --> Give file name
    CHARACTER_MODE = 'X'
    * IMPORTING
    * BLOB_LENGTH =
    TABLES
    * BLOB =
    TEXT = CSV_CONVERTED_TABLE
    * EXCEPTIONS
    * TCPIP_ERROR = 1
    * COMMAND_ERROR = 2
    * DATA_ERROR = 3
    * OTHERS = 4
    .
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    LOOP AT CSV_CONVERTED_TABLE INTO WA_XDATA.
    CONCATENATE XMLUPL WA_XDATA-STR INTO XMLUPL.
    ENDLOOP.

    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
    TEXT = XMLUPL "CSV_CONVERTED_TABLE
    MIMETYPE = ' '
    * ENCODING =
    IMPORTING
    BUFFER = XSTRING
    * EXCEPTIONS
    * FAILED = 1
    * OTHERS = 2
    .
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    CALL FUNCTION 'SMUM_XML_PARSE'
    EXPORTING
    XML_INPUT = XSTRING
    TABLES
    XML_TABLE = ITAB
    RETURN = RETURN.

    * In ITAB you will get the data from XLS file ..

    Thank you ,

    Kavi prasath R

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello Ruchira ,

      Please try the Excel FM ,you will get .

      I have given the FM for XML phrase "XML_PARSER"..

      Thanks,