应用场景:有些定制化开发(报表/功能增强等)完成之后,客户需要将其操作手册或者相关文档放在某个报表的初始画面,供实际操作者在线查阅,当然这个功能也同样类似于模板的下载,这里就以在线预览(直接打开)为例进行说明。
就比如上图所示,点击“事务操作手册”按钮即弹出PPT画面。
前提是PPT模板已经通过事务代码SMW0上传。
主要实现代码:
代码语言:javascript复制************************************************************************
* 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的介绍。
代码语言:javascript复制* 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.
代码语言:javascript复制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