2023 May 17 1:23 PM
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.
2023 May 17 2:48 PM
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?
2023 May 17 7:13 PM
In your screenshot, we see that i_oldfile is of type standard table
with lines of type
of length 1200 bytes,
PS: better embed the image instead of hyperlink.
2023 May 18 5:03 AM
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.
2023 May 18 5:54 AM
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?
2023 May 18 7:50 AM
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.
2023 May 26 10:58 AM
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.