如何将SAP数据传输到其他系统(Transferring Data from SAP to Other Systems)

在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
OTHERS = 1.

3、SAP的样例代码
report rsftp004.

parameters: suser(30) type c lower case,
            spwd(30) type c lower case,
            shost(64) type c lower case,
            duser(30) type c lower case,
            dpwd(30) type c lower case,
            dhost(64) type c lower case,
            lines type i default 1000,
            pasv.
selection-screen skip 1.
parameters: dest like rfcdes-rfcdest default 'SAPFTP'.

types: begin of text,
       line(120) type c,
       end of text.

types: begin of blob,
       line(80) type x,
       end of blob.

data: shdl type i,
      dhdl type i,
      key type i value 26101957,
      slen type i,
      bline(80) type x,
      sdocid like sysuuid-c,
      ddocid like sysuuid-c,
      blob_length type i,
      cmd(120),
      error.

data: result type table of text with header line,
      bindata type table of blob with header line.

* Create data

set extended check off.
error = 0.
bline = '0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F' &
        '0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F' &
        '0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F' &
        '0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F'.

do lines times.
  bindata-line = bline.
  append bindata.
enddo.

call function 'SYSTEM_UUID_C_CREATE'
  importing
    uuid = sdocid.

call function 'SYSTEM_UUID_C_CREATE'
  importing
    uuid = ddocid.

* connect to ftp server - source

slen = strlen( spwd ).

call function 'HTTP_SCRAMBLE'
  exporting
    source      = spwd
    sourcelen   = slen
    key         = key
  importing
    destination = spwd.

call function 'SAPGUI_PROGRESS_INDICATOR'
  exporting
    text = 'Connect to FTP Server - Source'.

call function 'FTP_CONNECT'
  exporting
    user            = suser
    password        = spwd
    host            = shost
    rfc_destination = dest
  importing
    handle          = shdl.

* connect to ftp server - destination

slen = strlen( dpwd ).

call function 'HTTP_SCRAMBLE'
  exporting
    source      = dpwd
    sourcelen   = slen
    key         = key
  importing
    destination = dpwd.

call function 'SAPGUI_PROGRESS_INDICATOR'
  exporting
    text = 'Connect to FTP Server - Destination'.

call function 'FTP_CONNECT'
  exporting
    user            = duser
    password        = dpwd
    host            = dhost
    rfc_destination = dest
  importing
    handle          = dhdl.

if not pasv is initial.
  refresh result.

call function 'FTP_COMMAND'
    exporting
      handle        = shdl
      command       = 'set passive on'
    tables
      data          = result
    exceptions
      tcpip_error   = 1
      command_error = 2
      data_error    = 3.

if sy-subrc eq 0.
    write: / 'Set passive mode - Source'.
  endif.

refresh result.

call function 'FTP_COMMAND'
    exporting
      handle        = dhdl
      command       = 'set passive on'
    tables
      data          = result
    exceptions
      tcpip_error   = 1
      command_error = 2
      data_error    = 3.

if sy-subrc eq 0.
    write: / 'Set passive mode - Destination'.
  endif.
  skip 1.

endif.

* Create file on Source

blob_length = lines * 80.

call function 'SAPGUI_PROGRESS_INDICATOR'
  exporting
    text = 'Create File on Source'.

call function 'FTP_R3_TO_SERVER'
  exporting
    handle      = shdl
    fname       = sdocid
    blob_length = blob_length
  tables
    blob        = bindata.

* Copy Files

call function 'SAPGUI_PROGRESS_INDICATOR'
  exporting
    text = 'Copy File to Destination'.

refresh result.

call function 'FTP_COPY'
  exporting
    handle_source      = shdl
    handle_destination = dhdl
    file_source        = sdocid
    file_destination   = ddocid
  tables
    data               = result
  exceptions
    tcpip_error        = 1
    command_error      = 2
    data_error         = 3
    others             = 4.

if sy-subrc ne 0. error = 1. endif.

loop at result.
  write / result-line.
endloop.

* compare content

if error eq 0.

call function 'SAPGUI_PROGRESS_INDICATOR'
    exporting
      text = 'Compare Content'.

skip 1.
  refresh bindata.

call function 'FTP_SERVER_TO_R3'
    exporting
      handle      = shdl
      fname       = sdocid
    importing
      blob_length = blob_length
    tables
      blob        = bindata.

slen = lines * 80.

if slen ne blob_length.
    error = 1.
    write: / 'Length error - expected',slen,'received',blob_length.
  else.
    loop at bindata.
      if bindata-line ne bline.
        slen = sy-tabix * 80.
        write: / 'Content error at',slen,bindata-line.
        error = 1.
        exit.
      endif.
    endloop.
  endif.

refresh bindata.

call function 'FTP_SERVER_TO_R3'
    exporting
      handle      = dhdl
      fname       = ddocid
    importing
      blob_length = blob_length
    tables
      blob        = bindata.

slen = lines * 80.

if slen ne blob_length.
    error = 1.
    write: / 'Length error - expected',slen,'received',blob_length.
  else.
    loop at bindata.
      if bindata-line ne bline.
        slen = sy-tabix * 80.
        write: / 'Content error at',slen,bindata-line.
        error = 1.
        exit.
      endif.
    endloop.
  endif.

if error eq 0.
    write: / 'Content compare OK'.
  else.
    write: / 'Content compare error'.
  endif.
  skip 1.

endif.

* Delete

concatenate 'del' sdocid into cmd separated by ' '.
refresh result.

call function 'SAPGUI_PROGRESS_INDICATOR'
  exporting
    text = 'Delete Files'.

call function 'FTP_COMMAND'
  exporting
    handle        = shdl
    command       = cmd
  tables
    data          = result
  exceptions
    tcpip_error   = 1
    command_error = 2
    data_error    = 3.

loop at result.
  write / result-line.
endloop.

concatenate 'del' ddocid into cmd separated by ' '.
refresh result.

call function 'FTP_COMMAND'
  exporting
    handle        = dhdl
    command       = cmd
  tables
    data          = result
  exceptions
    tcpip_error   = 1
    command_error = 2
    data_error    = 3.

loop at result.
  write / result-line.
endloop.

* Disconnect
call function 'FTP_DISCONNECT'
  exporting
    handle = shdl.
call function 'FTP_DISCONNECT'
  exporting
    handle = dhdl.

call function 'RFC_CONNECTION_CLOSE'
  exporting
    destination = dest
  exceptions
    others = 1.

if error ne 0.
  format color col_negative.
  write: / 'Error im Test'.
else.
  format color col_positive.
  write: / ' Test OK'.
endif.

* password not visible

at selection-screen output.

loop at screen.
    if screen-name = 'SPWD' or screen-name = 'DPWD'.
      screen-invisible = '1'.
      modify screen.
    endif.
  endloop.

怎么将SAP数据传输到其他系统(Transferring Data from SAP to Other Systems)相关推荐

  1. 如何将SAP数据传输到其他系统(Transferring Data from SAP to Other Systems)

    在sap里有GUI_DOWNLOAD 函数将sap的数据下载到客户端机器(presentation server),而Dataset则是将数据传输到应用服务器(Application server). ...

  2. SAP QM 检验批的系统状态标识‘HUM‘

    SAP QM 检验批的系统状态标识'HUM' 如下检验批#10000043946.系统状态里有'HUM',如下图, 它标识该检验批的质检库存是有Handling Unit管理的,关联了HU号码的. - ...

  3. sap模块介绍_SAP系统操作指南.doc

    Sekurit University 课程推荐 <SAP报废&生产报告> Understand系列课程 开课时间:2020/7/30 SAP帮助企业实现各种数字化解决方案 自动化的 ...

  4. 如何访问 SAP Screen Personas 培训系统以及完成一个最简单的例子

    Access the SAP Screen Personas Training System SAP Screen Personas 团队 免 费 提供培训系统,目的是让学习者能够亲身体验产品. 用户 ...

  5. sap 供应商表_SAP系统玩阴的?

    SAP系统玩阴的? 近日和项目上的ABAP开发顾问一起弄一个自开发的报表.其中某个栏位的取值需要从批次主数据里抓取到供应商代码,然后根据供应商代码取到供应商名称等.为此笔者需要备功能说明书,在说明书里 ...

  6. SAP License:ERP系统供应商管理都包含什么?

    1.流程繁复,效率低下 传统采购模式要经过询价/报价.招标/投标.竞价谈判等繁杂流程,大型企业还要考虑到分支机构的采购管理问题,耗时耗力.如遇到企业有紧急需求的情况,而供应商响应客户需求的能力迟钝时, ...

  7. SAP License:ERP系统有哪些?

    ERP系统有哪些?其中哪种品牌的ERP系统好?ERP管理系统是一个应用范围广.高度集成的系统.它不仅融入了最新的管理理念,还采用了计算机最新的主流技术和体系结构.可以说是功能强大.性能优势.比如说,赛 ...

  8. SAP ERP 安全管理平台系统

    系统引言 SAP全日志安全管理系统(SAP ERP安全管理平台, 简称AMS-L系统)是一款面向SAP ERP 系统的网络安全管理工具,提供基于SAP系统用户业务行为的常态化监管,是对SAP现有日志体 ...

  9. 公司财务系统html,什么是sap管理系统?

    SAP系统(systems applications and products in data processing)是一套企业资源管理软件系统,具有现代化.信息化.智能化的应用优势,能够为企业管理问 ...

最新文章

  1. All input tensors must be on the same device
  2. REST framework 基本使用
  3. 成功解决tensorflow.keras: AttributeError: ‘str‘ object has no attribute ‘decode‘
  4. 每日一算法 ---- 打印九九乘法表
  5. html的title设置,动态设置html的title
  6. OpenCV-绘制箭头cv::arrowedLine
  7. python常用算法有哪些_python常见排序算法基础教程
  8. 2018 KDD CUP支付宝安全团队Deep X斩获两项大奖
  9. 前端复习笔记(二)——CSS
  10. 有没有这样一种程序员写代码的利器
  11. mavan自动化接管浏览器_人工智能与自动化:接管还是共生?
  12. 部署单节点OpenStack
  13. Java面试题全集(上)
  14. 变化世界中的军事地质学
  15. otool 分析Mach-O
  16. 5、判断是否为偶数(0106)
  17. 视频编码基础:I帧、P帧 和 B 帧
  18. 康海时代nc系列串口服务器,康海时代NC616系列串口服务器
  19. pyspider爬取免费正版图片网站Pixabay
  20. 第1章计算机网络概述——1.互联网概述

热门文章

  1. 比iPhone8更重要的新App Store,给内容产品的未来指出明路
  2. 火热招募中 | PMCAFF产品经理社区志愿者计划火热开启
  3. 沟通篇:产品经理如何与UI进行沟通
  4. O2O产品经理,请多关注屏幕之外
  5. MongoDB资料大全
  6. ASA基本配置实验报告
  7. 沙盒单机网站代表-Steam【推荐】
  8. 一个基于Python2.7的智慧校园系统
  9. 《深入理解大数据:大数据处理与编程实践》一一3.3 HDFS文件存储组织与读写...
  10. Spring Boot工程支持HTTP和HTTPS,HTTP重定向HTTPS