SAP与外部系统异常之间可以采用FTP技术进行文件的交换处理,达到信息共享的目的, ftp技术的调如方式如下:
REPORT zfiletest .
DATA: p_prg LIKE sy-repid.
DATA: com(100) ,
t_name(40),
t_cnt TYPE i,
t_typ(3).
DATA: BEGIN OF tabl OCCURS 100,
line(255),
END OF tabl.
data: begin of commands occurs 0,
cmd(100) type c,
end of commands.
data: hdl type i,
key type i value 26101957,
dstlen type i,
nlen type i.
data: begin of result occurs 0,
line(100) type c,
end of result.
data: CNS_DIR(40) TYPE C . "VALUE 'MAS'.
start-of-selection.
p_prg = sy-repid.
call function 'FTP_CONNECT'
EXPORTING
user = 'ftp'
password = 'ftp'
host = '10.0.4.85'
rfc_destination = 'SAPFTPA'
IMPORTING
handle = hdl.
move 'lcd /usr/sap/tmp' to commands-cmd.
call function 'FTP_COMMAND'
EXPORTING
handle = hdl
command = commands-cmd
TABLES
data = result
EXCEPTIONS
command_error = 1.
REFRESH RESULT.
move 'cd MAS' to commands-cmd.
call function 'FTP_COMMAND'
EXPORTING
handle = hdl
command = commands-cmd
TABLES
data = result
EXCEPTIONS
command_error = 1.
move 'mget *.txt' to commands-cmd.
call function 'FTP_COMMAND'
EXPORTING
handle = hdl
command = commands-cmd
TABLES
data = result
EXCEPTIONS
command_error = 1.
CNS_DIR = '/usr/sap/tmp'.
* cns_dir = '/MAS'.
CONCATENATE 'ls' cns_dir INTO com SEPARATED BY space.
REFRESH tabl.
SET BLANK LINES ON.
CALL 'SYSTEM' ID 'COMMAND' FIELD com
ID 'TAB' FIELD tabl-*sys*.
IF tabl[] IS INITIAL.
MESSAGE w398(00) WITH '没有所需的文件'.
ENDIF.
SORT tabl BY line DESCENDING.
LOOP AT tabl.
WRITE tabl-line.
ENDLOOP.
*&Directory Handle Part.
clear : cns_dir, tabl.
refresh tabl.
set blank lines on.
cns_dir = '/usr/sap/trans/public/order'.
*&no 1.
CONCATENATE 'mkdir' cns_dir INTO com SEPARATED BY space.
CALL 'SYSTEM' ID 'COMMAND' FIELD com
ID 'TAB' FIELD tabl-*sys*.
*&no 2.
CONCATENATE 'chmod 777' cns_dir INTO com SEPARATED BY space.
CALL 'SYSTEM' ID 'COMMAND' FIELD com
ID 'TAB' FIELD tabl-*sys*.
*&no 3.
CONCATENATE 'chown qasadm: sapsys' cns_dir INTO com SEPARATED BY
space
.
CALL 'SYSTEM' ID 'COMMAND' FIELD com
ID 'TAB' FIELD tabl-*sys*.
*&end.