在sap里有GUI_DOWNLOAD 函数将sap的数据下载到客户端机器(presentation server),而Dataset则是将数据传输到应用服务器(Application server)。然而在有些时候需要将数据传输到第三方其他系统(3rd Party System),这是我们就可以使用FTP命令来完成数据传输。
1、相关函数
HTTP_SCRAMBLE
FTP_CONNECT
FTP_R3_TO_SERVER
FTP_DISCONNECT
RFC_CONNECTION_CLOSE
2、函数说明
HTTP_SCRAMBLE: 将密码转化为SAP的格式
样例代码
l_pwd = p_pwd.
l_slen = STRLEN( l_pwd ).
CALL FUNCTION 'HTTP_SCRAMBLE'
exporting
source = l_pwd
sourcelen = l_slen
key = c_key
importing
destination = l_pwd.
FTP_CONNECT : 连接其他系统
* To Connect to the Server using FTP
样例代码
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = p_user
password = l_pwd
host = p_host
rfc_destination = c_dest
IMPORTING
handle = w_hdl
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
FTP_R3_TO_SERVER: 将SAP的内表数据按字符方式传输到其他系统.
样例代码
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
handle = w_hdl
fname = <file path of destination system>
character_mode = 'X'
TABLES
text = <internal table data>
EXCEPTIONS
tcpip_error = 1
command_error = 2
data_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
RAISING invalid_output_file.
ENDIF.
FTP_DISCONNECT: 关闭SAP与其他系统的连接.
样例代码
* To disconnect the FTP
CALL FUNCTION 'FTP_DISCONNECT'
EXPORTING
handle = w_hdl.
RFC_CONNECTION_CLOSE:关闭SAP与其他系统的RFC连接.
样例代码
CALL FUNCTION 'RFC_CONNECTION_CLOSE'
EXPORTING
destination = c_dest
EXCEPTIONS
OTHER