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

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

主要实现代码:

FM:Z_USE_OLE的介绍。
image.png
image.png
image.png

"---------------------------------------------------------------------- ""本地接口: " IMPORTING
" VALUE(I_OBJECT_ID) " VALUE(I_TITLE) OPTIONAL
" TABLES " T_HEADER OPTIONAL
*" T_ITEM OPTIONAL

  • 目前只支持两种模式 word 和 excle如果是PDF的话PC端要安装 adobe reader
    *"----------------------------------------------------------------------

    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.

SELECT SINGLE VALUE INTO @DAta(lv_TYPE) FROM WWWPARAMS WHERE OBJID = @P_OBJECT_ID AND NAME = 'mimetype'.

CASE lv_TYPE.
WHEN 'PDF'.
DOC_TYPE = 'AcroExch.acrobatsecuritysettings.1'.
WHEN 'WORD'.
DOC_TYPE = 'Word.Document.12'.
WHEN OTHERS.
ENDCASE.

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

目录
相关文章
|
7月前
|
程序员
开发语言漫谈-ABAP
ABAP是SAP公司专门用于SAP软件环境的专门语言
SAP ABAP 程序调用设置成后台作业模式
ABAP 程序调用设置成后台作业模式
529 0
SAP ABAP 内表排序 动态字段排序
对于动态内表排序引用ABAP_SORTORDER_TAB
304 0
|
SQL 设计模式 前端开发
【置顶】SAP ABAP开发实战——从入门到精通系列目录
本文章为SAP ABAP开发实战——从入门到精通系列的目录以及关于该教程的后续写作计划表
1658 0
【置顶】SAP ABAP开发实战——从入门到精通系列目录
|
SQL
SAP ABAP-OPENSQL-数值函数简介
S4中针对OPENSQL新提供一些函数
143 0
|
SQL
SAP ABAP-OPENSQL-字符串函数介绍
S4中SQL新语法字符串函数
219 0
|
SQL
SAP ABAP-OPENSQL-日期/时间戳函数
S4提供针对OPENSQL一些新的SQL函数调用,本文展示相关函数的使用
680 0
SAP 金额转中文大写自开发函数
关于凭证打印时需将金额转换成中文大写
120 0
SAP ABAP-删除工序示例代码
ABAP-删除工序示例代码
176 0
SAP ABAP 检查事务码权限
检查用户是否有自开发事务码的权限
161 0