Skip to Content
0

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

Jan 24 at 05:57 AM

137

avatar image
Former Member

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.

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

1 Answer

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

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Kavi,

Thank you very much for the response. I'm testing the provided solution and get the below error.

I 001 XML_PARSER

E 999 Number of errors: 1

E 999 line 1 col 1-unexpected end-of-file

I'm checking further If I have missed anything.

0
Former Member

Hello Ruchira ,

Please try the Excel FM ,you will get .

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

Thanks,

0