专栏首页SAP TechnicalSAP ABAP 在线预览文档对象的开发实现
原创

SAP ABAP 在线预览文档对象的开发实现

应用场景:有些定制化开发(报表/功能增强等)完成之后,客户需要将其操作手册或者相关文档放在某个报表的初始画面,供实际操作者在线查阅,当然这个功能也同样类似于模板的下载,这里就以在线预览(直接打开)为例进行说明。

就比如上图所示,点击“事务操作手册”按钮即弹出PPT画面。

前提是PPT模板已经通过事务代码SMW0上传。

主要实现代码:

************************************************************************
* AT SELECTION-SCREEN
************************************************************************
AT SELECTION-SCREEN.
  CASE SSCRFIELDS-UCOMM.
    WHEN 'FC01'.
      DATA: LV_OBJECT_ID(20),
            LV_TITLE(40).
 
      LV_TITLE     = '操作手册'.
      LV_OBJECT_ID = 'ZFI_MODEL'.
 
      CALL FUNCTION 'Z_USE_OLE'
        EXPORTING
          I_OBJECT_ID = LV_OBJECT_ID
          I_TITLE     = LV_TITLE.
    WHEN 'FC02'.
    WHEN 'CLI1'.
      PERFORM SELECT_SCREEN.
    WHEN OTHERS.
  ENDCASE.

FM:Z_USE_OLE的介绍。

* regenerated at 2017.06.22 10:04:56
FUNCTION-POOL ZTEST                      MESSAGE-ID SV.
 
* INCLUDE LZTESTD...                         " Local class definition
INCLUDE LSVIMDAT                                . "general data decl.
INCLUDE LZTESTT00                               . "view rel. data dcl.
INCLUDE OLE2INCL.
INCLUDE OFFICEINTEGRATIONINCLUDE.
DATA : FACTORY TYPE REF TO I_OI_DOCUMENT_FACTORY.
DATA : DOCUMENT TYPE REF TO I_OI_DOCUMENT_PROXY.
DATA : RETCODE TYPE T_OI_RET_STRING.
DATA : DOC_TABLE LIKE W3MIME OCCURS 0.
DATA : DOC_SIZE TYPE I.
DATA : DOC_TYPE(80) VALUE SOI_DOCTYPE_WORD97_DOCUMENT.
DATA : DOC_FORMAT(80) TYPE C.
DATA : LINK_SERVER TYPE REF TO I_OI_LINK_SERVER.
DATA : IS_CLOSED TYPE I.
FUNCTION Z_USE_OLE.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(I_OBJECT_ID)
*"     VALUE(I_TITLE) OPTIONAL
*"  TABLES
*"      T_HEADER OPTIONAL
*"      T_ITEM OPTIONAL
*"----------------------------------------------------------------------
  IF I_OBJECT_ID IS INITIAL.
    RAISE OBJECT_ID_ERROR.
  ENDIF.
  PERFORM INIT_FACTORY  USING  I_TITLE.
  PERFORM OPEN_DOC      TABLES T_HEADER
                               T_ITEM
                        USING  I_OBJECT_ID.
ENDFUNCTION.
*&---------------------------------------------------------------------*
*& Form INIT_FACTORY
*&---------------------------------------------------------------------*
FORM INIT_FACTORY USING P_TITLE.
  IF FACTORY IS INITIAL.
    CALL METHOD C_OI_FACTORY_CREATOR=>GET_DOCUMENT_FACTORY
      IMPORTING
        FACTORY = FACTORY
        RETCODE = RETCODE.
    IF RETCODE NE C_OI_ERRORS=>RET_OK.
      EXIT.
    ENDIF.
 
    CALL METHOD FACTORY->START_FACTORY
      EXPORTING
        R3_APPLICATION_NAME = P_TITLE
      IMPORTING
        RETCODE             = RETCODE.
 
    CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
      EXPORTING
        TYPE = 'E'.
 
    CALL METHOD FACTORY->GET_LINK_SERVER
      IMPORTING
        LINK_SERVER = LINK_SERVER
        RETCODE     = RETCODE.
 
    CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
      EXPORTING
        TYPE = 'E'.
 
    CALL METHOD LINK_SERVER->START_LINK_SERVER
      EXPORTING
        LINK_SERVER_MODE = 3
      IMPORTING
        RETCODE          = RETCODE.
 
    CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
      EXPORTING
        TYPE = 'E'.
  ENDIF.                               "factory IS INITIAL.
ENDFORM. " INIT_FACTORY
*&---------------------------------------------------------------------*
*& Form OPEN_DOC
*&---------------------------------------------------------------------*
FORM OPEN_DOC TABLES HEADER
                       ITEM
                USING  P_OBJECT_ID.
 
  DATA : a(8) TYPE C.
 
  DEFINE M_LINK_TAB.
    call method link_server->add_table_item2
      exporting
        item_name  = &1
      importing
        retcode    = retcode
      changing
        data_table = &2.
    call method c_oi_errors=>show_message
      exporting
        type = 'E'.
  END-OF-DEFINITION.
 
  IF NOT LINK_SERVER IS INITIAL.
    M_LINK_TAB 'HEADER'  HEADER[].
    M_LINK_TAB 'ITEM'    ITEM[].
  ENDIF.
 
 
* SAP ### ## EXCEL ## OPEN
 
  CALL FUNCTION 'SAP_OI_LOAD_MIME_DATA'
    EXPORTING
      OBJECT_ID        = P_OBJECT_ID
    IMPORTING
      DATA_SIZE        = DOC_SIZE
      DOCUMENT_FORMAT  = DOC_FORMAT
      DOCUMENT_TYPE    = DOC_TYPE
    TABLES
      DATA_TABLE       = DOC_TABLE
    EXCEPTIONS
      OBJECT_NOT_FOUND = 1
      INTERNAL_ERROR   = 2
      OTHERS           = 3.
 
  IF SY-SUBRC NE 0.
    MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 
  IF DOC_SIZE NE 0.
    CALL METHOD FACTORY->GET_DOCUMENT_PROXY
      EXPORTING
        DOCUMENT_TYPE  = DOC_TYPE
      IMPORTING
        DOCUMENT_PROXY = DOCUMENT
        RETCODE        = RETCODE.
    CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
      EXPORTING
        TYPE = 'E'.
 
 
* Document# Protected Mode# Open## #### ###.
 
    CALL METHOD DOCUMENT->OPEN_DOCUMENT_FROM_TABLE
      EXPORTING
        DOCUMENT_TABLE = DOC_TABLE[]
        DOCUMENT_SIZE  = DOC_SIZE
      IMPORTING
        RETCODE        = RETCODE.
 
    CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
      EXPORTING
        TYPE = 'E'.
  ENDIF.
 
ENDFORM. " OPEN_DOC
*&---------------------------------------------------------------------*
*& Form MACRO
*&---------------------------------------------------------------------*
FORM MACRO .
  CALL METHOD DOCUMENT->EXECUTE_MACRO
    EXPORTING
      MACRO_STRING = 'R3_MACRO1'
    IMPORTING
      RETCODE      = RETCODE.
  CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
    EXPORTING
      TYPE = 'E'.
ENDFORM. " MACRO
*&---------------------------------------------------------------------*
*& Form CLOSE_DOC
*&---------------------------------------------------------------------*
FORM CLOSE_DOC .
 
  IF NOT DOCUMENT IS INITIAL.
 
    CALL FUNCTION 'WS_FILE_DELETE'
      EXPORTING
        FILE = 'C:\PIC.JPG'.
 
    CALL METHOD DOCUMENT->IS_DESTROYED
      IMPORTING
        RET_VALUE = IS_CLOSED.
 
    IF IS_CLOSED IS INITIAL.
      CALL METHOD DOCUMENT->CLOSE_DOCUMENT
        EXPORTING
          DO_SAVE = 'X'
        IMPORTING
          RETCODE = RETCODE.
      CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
        EXPORTING
          TYPE = 'E'.
    ENDIF.
 
    CALL METHOD DOCUMENT->RELEASE_DOCUMENT
      IMPORTING
        RETCODE = RETCODE.
    CALL METHOD C_OI_ERRORS=>SHOW_MESSAGE
      EXPORTING
        TYPE = 'E'.
 
    FREE DOCUMENT.
  ENDIF.
 
ENDFORM. " CLOSE_DOC
*&---------------------------------------------------------------------*
*& Form CLOSE_FACTORY
*&---------------------------------------------------------------------*
FORM CLOSE_FACTORY .
  IF NOT LINK_SERVER IS INITIAL.
    CALL METHOD LINK_SERVER->STOP_LINK_SERVER
      IMPORTING
        RETCODE = RETCODE.
    FREE LINK_SERVER.
  ENDIF.
  IF NOT FACTORY IS INITIAL.
    CALL METHOD FACTORY->STOP_FACTORY
      IMPORTING
        RETCODE = RETCODE.
    FREE FACTORY.
  ENDIF.
ENDFORM. " CLOSE_FACTORY

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

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

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 使用特殊的技术更新数据库(ABAP)

    一,过程 1,DIALOG程序获得用户要更新的数据,并把它写到一个特殊的LOG TABLE,表内的条目属于同一个请求类型,包含了稍后将要写到数据库的数据。一个...

    matinal
  • 【SAP ABAP系列】使用特殊的技术更新数据库(ABAP)

    一,过程 1,DIALOG程序获得用户要更新的数据,并把它写到一个特殊的LOG TABLE,表内的条目属于同一个请求类型,包含了稍后将要写到数据库的数据。一个D...

    matinal
  • 我是如何在Fiori上添加UI应用的

    我在之前的文章推送里写了不少关于SAP Fiori的文章,有关于技术的也有浅谈理论发展的文章,有兴趣的朋友可以阅读一下。

    matinal
  • linux 网站目录更换后如何修改网站路径和 ftp 路径

    魏艾斯博客www.vpsss.net
  • Skype for Business预览版已登陆Android和iOS平台

    摘要:用以取代Lync的Skype for Business,已于今年4月登陆桌面平台。而今天,它终于推出了面向Android和iOS平台的版本。Skype f...

    杨强生
  • Python3实现PoC——wooyun

    py3study
  • Python爬虫实现vip电影下载的示例代码

    实现对各大视频网站vip电影的下载,因为第三方解析网站并没有提供下载的渠道,因此想要实现电影的下载。

    砸漏
  • 干货|如何入门 Python 爬虫?爬虫原理及过程详解

    Python现在非常火,语法简单而且功能强大,很多同学都想学Python!所以小的给各位看官们准备了高价值Python学习视频教程及相关电子版书籍,欢迎前来领取...

    python学习教程
  • kangle防cc教程

    flyxber
  • [SEO知识讲解] seo基础教程url优化篇

    AlexTao

扫码关注云+社区

领取腾讯云代金券