前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【SAP ABAP系列】SAP ABAP 从FTP服务器读取文件到本地

【SAP ABAP系列】SAP ABAP 从FTP服务器读取文件到本地

原创
作者头像
matinal
修改2020-11-16 09:59:40
2.5K0
修改2020-11-16 09:59:40
举报
文章被收录于专栏:SAP Technical

正文部分

代码语言:javascript
复制
​
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

​

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 正文部分
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档