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: 

Error Occured While Reading File From FTP

Former Member
0 Kudos
471

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.
3 REPLIES 3

Tomas_Buryanek
Active Contributor
0 Kudos
348

Error happens randomly or always for the same file/s? Are you sure that the files with error are 100% character based?

-- Tomas --

Former Member
0 Kudos
348

Hello Tomas,

thanks for response ,

i am Getting error for random files not for any specific file, but all files having same format and same type of data.

in which most of file is reading successfully.

Tomas_Buryanek
Active Contributor
0 Kudos
348

joshiprasad Oh, ok. I would suggest to check sy-msgid, sy-msgno etc. variables after the FM returns sy-subrc <> 0. And then if you can somehow repeat the error, then try debug little bit inside the FTP_SERVER_TO_R3. There you might find more details, some returning message most likely.

-- Tomas --