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: 

Unable To Read File From FTP Server

anujmudholkar
Explorer
0 Kudos

17052023-a.jpg

Hello helpers,

My requirement is i want to fetch some files data from ftp to my internal table, I have used 'FTP_SERVER_TO_R3' function module for read file data but once this function module executes its returning sy-subrc = 3 ( data error) but for some files its working fine and file format of both files also same.

please do needfull.

logic :

*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 '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.


6 REPLIES 6

Tomas_Buryanek
Active Contributor

Can you please use "CODE" button to better format your code?

What is i_oldfile?

Which sy-msgid, msgno etc. you are getting from the FM?

-- Tomas --

Sandra_Rossi
Active Contributor

In your screenshot, we see that i_oldfile is of type standard table

with lines of type

  • either elementary
  • or structure containing 1 component
  • ?

of length 1200 bytes,

  • but 1200 bytes is either of type character (600 characters)
  • or of type byte (1200 bytes)
  • ?

PS: better embed the image instead of hyperlink.

anujmudholkar
Explorer
0 Kudos
test.jpg

Hello Tomas / Sandra,

Thanks For Your Reply,

Please see below code and attached screenshot :

DATA: BEGIN OF i_oldfile OCCURS 1,
line(600) TYPE c,
END OF i_oldfile.
TYPES: BEGIN OF text,
line(120) TYPE c,
END OF text.
DATA: result TYPE TABLE OF text WITH HEADER LINE.
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 '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.
endloop.

matt
Active Contributor

When you type a question or a comment, the editor has a button marked "CODE". If you use it then the code you paste will be nicely formatted and readable, and people will be more inclined to answer. You've already been asked once to use it.

E.g.

DATA: BEGIN OF i_oldfile OCCURS 1,
        line(600) TYPE c,
END OF i_oldfile.
TYPES: BEGIN OF text,
  line(120) TYPE c,
END OF text.

See how much nicer it is?

Sandra_Rossi
Active Contributor
0 Kudos

Thanks for the information that the type of lines of I_OLDFILE is a structure made of one component of 600 characters. So, it's consistent with the fact that you read a text file (character_mode = 'X').

No idea what means DATA_ERROR. Could it be a file authorization error (check at OS level, i.e. Unix/Linux chmod, etc.), a file not of type text or at least not of the "expected" character set/code page (try with character_mode = ' ' and internal table with line(600) TYPE X instead of C), etc.

PS: again, you missed embedding the image, you just shared the link (maybe you had an issue when trying to use the button [code]).

PPS: you may enrich your question using menu Actions > Edit.

anujmudholkar
Explorer
0 Kudos

Hello sandra ,

Thanks For Response ,

As Per response I have set character mode as ' ' , now issue is i am getting sy-subrc 0 but that file data is not retriving in internal table. i am sharing screenshot of file which i am reading.

see screenshot.