SAP ABAP 从FTP服务器读取文件到本地

正文部分

​
DATA: hdl TYPE i,
      key TYPE i VALUE 26101957,
      dstlen TYPE i,
      blob_length TYPE i.
DATA filepath TYPE string .

DATA: BEGIN OF blob OCCURS 0,
      line(100) TYPE x,
      END OF blob.

PARAMETERS: user(64) TYPE c ,
            pwd(64) TYPE c ,
            host(64) TYPE c ,
            filename(80) TYPE c ,
            name2(80) TYPE c,
            dest LIKE rfcdes-rfcdest DEFAULT 'SAPFTP'.
PARAMETERS: p_file LIKE rlgrap-filename
   DEFAULT 'c:\test.xls'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  PERFORM get_p_file USING p_file text-006.

START-OF-SELECTION.
TRANSLATE  user TO lowER CASE.

  CALL 'AB_RFC_X_SCRAMBLE_STRING'
    ID 'SOURCE'      FIELD pwd    ID 'KEY'         FIELD key
    ID 'SCR'         FIELD 'X'    ID 'DESTINATION' FIELD pwd
    ID 'DSTLEN'      FIELD dstlen.


  CALL FUNCTION 'FTP_CONNECT'
    EXPORTING
      user            = user
      password        = pwd
      host            = host
      rfc_destination = dest
    IMPORTING
      handle          = hdl.


  CALL FUNCTION 'FTP_SERVER_TO_R3'
    EXPORTING
      handle      = hdl
      fname       = filename
    IMPORTING
      blob_length = blob_length
    TABLES
      blob        = blob.


  filepath = p_file .
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename = filepath
      filetype = 'BIN'
    TABLES
      data_tab = blob.



  CALL FUNCTION 'FTP_DISCONNECT'
    EXPORTING
      handle = hdl.
*&---------------------------------------------------------------------*
*&      Form  get_p_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_P_FILE  text
*      -->P_TEXT_006  text
*----------------------------------------------------------------------*
FORM get_p_file  USING    l_filename
                          l_text.
  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      def_filename     = space
      def_path         = l_filename
      mask             = ',*.xls ,*.xls.'
      mode             = 'O'
      title            = l_text
    IMPORTING
      filename         = l_filename
    EXCEPTIONS
      inv_winsys       = 04
      no_batch         = 08
      selection_cancel = 12
      selection_error  = 16.


ENDFORM.                    " get_p_file

​

 

点击进入:SAP ABAP 从FTP服务器读取文件到本地

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值