Code: Alles auswählen.
IF p_file IS NOT INITIAL.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = filesize
filename = filename_string
filetype = 'BIN'
no_auth_check = 'X'
IMPORTING
filelength = after_download_length
CHANGING
data_tab = tab_x
EXCEPTIONS
file_not_found = 91
file_write_error = 92
filesize_not_allowed = 93
invalid_type = 95
no_batch = 96
OTHERS = 97.
IF sy-subrc NE 0. "download error
result = sy-subrc.
ELSEIF after_download_length EQ 0. "nothing written
result = 97.
ENDIF.
ELSE.
IF wa_regut-codepage = '4102' OR wa_regut-codepage = '4103'. " Unicode
OPEN DATASET filename_string IN BINARY MODE FOR OUTPUT.
ELSEIF wa_regut-codepage = '4110'. " UTF-8
OPEN DATASET filename_string IN TEXT MODE FOR OUTPUT ENCODING DEFAULT.
ELSEIF wa_regut-codepage IS NOT INITIAL.
OPEN DATASET filename_string FOR OUTPUT IN LEGACY BINARY MODE CODE PAGE out_codepage.
ELSE.
OPEN DATASET filename_string FOR OUTPUT IN LEGACY BINARY MODE.
ENDIF.
LOOP AT tab_x INTO str_line.
TRANSFER str_line TO wa_regut-dwnam.
ENDLOOP.
CLOSE DATASET wa_regut-dwnam.
ENDIF.
Code: Alles auswählen.
DATA: w_outfilename(255) TYPE c,
lang TYPE i,
anzahl TYPE i.
DATA: ftp LIKE vbak OCCURS 0 WITH HEADER LINE.
*-Pfadname
CONCATENATE w_outfilename ''.txt' INTO w_outfilename.
CLOSE DATASET w_outfilename.
* File öffnen
OPEN DATASET w_outfilename FOR INPUT IN TEXT MODE ENCODING DEFAULT.
check sy-subrc = 0.
DO.
CLEAR ftp.
READ DATASET w_outfilename INTO ftp LENGTH lang.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ADD 1 TO anzahl.
APPEND ftp.
ENDDO.
CLOSE DATASET w_outfilename.
Code: Alles auswählen.
CONCATENATE 'STAT' sy-uname sy-datum sy-uzeit '.txt' into docid.
call function 'FTP_CONNECT'
EXPORTING
user = ''
password = ''
host = 'XX.XXX.XX.X' " IP
rfc_destination = 'SAPFTPA'
IMPORTING
handle = hdl.
APPEND 'cd sap' TO commandlist.
CALL FUNCTION 'FTP_COMMAND_LIST'
EXPORTING
handle = hdl
IMPORTING
command_index = cmdindex
TABLES
data = result
commands = commandlist
EXCEPTIONS
command_error = 1
tcpip_error = 2
data_error = 3.
* Character mode
call function 'FTP_COMMAND'
EXPORTING
handle = hdl
command = 'ascii'
TABLES
data = result
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3.
call function 'FTP_R3_TO_SERVER'
EXPORTING
handle = hdl
fname = docid
character_mode = 'X'
TABLES
text = iftp.
* Disconnect
call function 'FTP_DISCONNECT'
EXPORTING
handle = hdl.
* SAPFTP = Online , SAPFTPA = BATCH
call function 'RFC_CONNECTION_CLOSE'
EXPORTING
destination = 'SAPFTPA'
EXCEPTIONS
others = 1.