Skip to Content
-1
6 days ago

Error Occured While Reading File From FTP

41 Views

Hello ,

I want to get file data from ftp server to my internal table, in ftp sever directory having multiples files which is in .txt format , for read file from ftp i have used 'FTP_SERVER_TO_R3' . for most of the file this function module working fine and i am able to get data of my file into internal table ,but for some file while reading it's giving me sy-subrc 3 .

all files have same format, i don't know why its giving me sy-subrc 3 (Data Error) .

for reference please see below code and attached screeenshots.

Thanks in Advance.

TYPES : BEGIN OF ty_result ,
line(100) TYPE c,
END OF ty_result.
DATA : result1 TYPE TABLE OF ty_result.
DATA:it_data TYPE TABLE OF ty_result,
wa_data TYPE ty_result.
DATA :host(64),p_spath(50),
dest TYPE rfcdes-rfcdest.
DATA: hdl TYPE i,
key TYPE i VALUE 26101957,
cmd1(255) TYPE c,
cmd(255) TYPE c,
slen TYPE i,
in_dest(100) TYPE c.
DATA: BEGIN OF i_oldfile OCCURS 1,
line(1200) TYPE c,
END OF i_oldfile.
in_dest = '/home/Documents/ ' .
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
source = pwd
sourcelen = slen
key = key
IMPORTING
destination = pwd.
IF sy-subrc EQ 0.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = user
password = pwd
host = host
rfc_destination = dest
IMPORTING
handle = hdl
EXCEPTIONS
not_connected = 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.
WRITE:/ 'Not Connected'.


    ELSE.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = hdl
command = 'set passive on'
TABLES
data = result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
CONCATENATE 'cd' in_dest INTO cmd SEPARATED BY space.
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = hdl
command = cmd
TABLES
data = result
EXCEPTIONS
command_error = 1
tcpip_error = 2.
**Get list file in FTP Folder
CALL FUNCTION 'FTP_COMMAND'
EXPORTING
handle = hdl
command = 'nlist'
TABLES
data = it_data
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3.
LOOP AT it_data INTO wa_data WHERE line Cs 't4.txt'. "getting data based on file name.
CALL FUNCTION 'FTP_SERVER_TO_R3'
EXPORTING
handle = hdl
fname = wa_data-line
character_mode = 'X'
* IMPORTING
* blob_length = ld_bloblen
TABLES
* blob =
text = i_oldfile
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.ftp-error.jpgfiles.jpg
endloop.

Attachments

ftp-error.jpg (124.9 kB)
files.jpg (118.3 kB)