生活随笔
收集整理的這篇文章主要介紹了
【ABAP】在线预览文档对象的开发实现
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
應(yīng)用場(chǎng)景:有些定制化開發(fā)(報(bào)表/功能增強(qiáng)等)完成之后,客戶需要將其操作手冊(cè)或者相關(guān)文檔放在某個(gè)報(bào)表的初始畫面,供實(shí)際操作者在線查閱,當(dāng)然這個(gè)功能也同樣類似于模板的下載,這里就以在線預(yù)覽(直接打開)為例進(jìn)行說(shuō)明。
就比如上圖所示,點(diǎn)擊“事務(wù)操作手冊(cè)”按鈕即彈出PPT畫面。
前提是PPT模板已經(jīng)通過(guò)事務(wù)代碼SMW0上傳。
主要實(shí)現(xiàn)代碼:
************************************************************************
* AT SELECTION-SCREEN
************************************************************************
AT SELECTION-SCREEN.CASE SSCRFIELDS-UCOMM.WHEN 'FC01'.DATA: LV_OBJECT_ID(20),LV_TITLE(40).LV_TITLE = '操作手冊(cè)'.LV_OBJECT_ID = 'ZFI_MODEL'.CALL FUNCTION 'Z_USE_OLE'EXPORTINGI_OBJECT_ID = LV_OBJECT_IDI_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_HEADERT_ITEMUSING 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_FACTORYIMPORTINGFACTORY = FACTORYRETCODE = RETCODE.IF RETCODE NE C_OI_ERRORS=>RET_OK.EXIT.ENDIF.CALL METHOD FACTORY->START_FACTORYEXPORTINGR3_APPLICATION_NAME = P_TITLEIMPORTINGRETCODE = RETCODE.CALL METHOD C_OI_ERRORS=>SHOW_MESSAGEEXPORTINGTYPE = 'E'.CALL METHOD FACTORY->GET_LINK_SERVERIMPORTINGLINK_SERVER = LINK_SERVERRETCODE = RETCODE.CALL METHOD C_OI_ERRORS=>SHOW_MESSAGEEXPORTINGTYPE = 'E'.CALL METHOD LINK_SERVER->START_LINK_SERVEREXPORTINGLINK_SERVER_MODE = 3IMPORTINGRETCODE = RETCODE.CALL METHOD C_OI_ERRORS=>SHOW_MESSAGEEXPORTINGTYPE = 'E'.ENDIF. "factory IS INITIAL.ENDFORM. " INIT_FACTORY
*&---------------------------------------------------------------------*
*& Form OPEN_DOC
*&---------------------------------------------------------------------*
FORM OPEN_DOC TABLES HEADERITEMUSING P_OBJECT_ID.DATA : a(8) TYPE C.DEFINE M_LINK_TAB.call method link_server->add_table_item2exportingitem_name = &1importingretcode = retcodechangingdata_table = &2.call method c_oi_errors=>show_messageexportingtype = 'E'.END-OF-DEFINITION.IF NOT LINK_SERVER IS INITIAL.M_LINK_TAB 'HEADER' HEADER[].M_LINK_TAB 'ITEM' ITEM[].ENDIF.* SAP ### ## EXCEL ## OPENCALL FUNCTION 'SAP_OI_LOAD_MIME_DATA'EXPORTINGOBJECT_ID = P_OBJECT_IDIMPORTINGDATA_SIZE = DOC_SIZEDOCUMENT_FORMAT = DOC_FORMATDOCUMENT_TYPE = DOC_TYPETABLESDATA_TABLE = DOC_TABLEEXCEPTIONSOBJECT_NOT_FOUND = 1INTERNAL_ERROR = 2OTHERS = 3.IF SY-SUBRC NE 0.MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNOWITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.ENDIF.IF DOC_SIZE NE 0.CALL METHOD FACTORY->GET_DOCUMENT_PROXYEXPORTINGDOCUMENT_TYPE = DOC_TYPEIMPORTINGDOCUMENT_PROXY = DOCUMENTRETCODE = RETCODE.CALL METHOD C_OI_ERRORS=>SHOW_MESSAGEEXPORTINGTYPE = 'E'.* Document# Protected Mode# Open## #### ###.CALL METHOD DOCUMENT->OPEN_DOCUMENT_FROM_TABLEEXPORTINGDOCUMENT_TABLE = DOC_TABLE[]DOCUMENT_SIZE = DOC_SIZEIMPORTINGRETCODE = RETCODE.CALL METHOD C_OI_ERRORS=>SHOW_MESSAGEEXPORTINGTYPE = 'E'.ENDIF.ENDFORM. " OPEN_DOC*&---------------------------------------------------------------------*
*& Form MACRO
*&---------------------------------------------------------------------*
FORM MACRO .CALL METHOD DOCUMENT->EXECUTE_MACROEXPORTINGMACRO_STRING = 'R3_MACRO1'IMPORTINGRETCODE = RETCODE.CALL METHOD C_OI_ERRORS=>SHOW_MESSAGEEXPORTINGTYPE = 'E'.ENDFORM. " MACRO
*&---------------------------------------------------------------------*
*& Form CLOSE_DOC
*&---------------------------------------------------------------------*
FORM CLOSE_DOC .IF NOT DOCUMENT IS INITIAL.CALL FUNCTION 'WS_FILE_DELETE'EXPORTINGFILE = 'C:\PIC.JPG'.CALL METHOD DOCUMENT->IS_DESTROYEDIMPORTINGRET_VALUE = IS_CLOSED.IF IS_CLOSED IS INITIAL.CALL METHOD DOCUMENT->CLOSE_DOCUMENTEXPORTINGDO_SAVE = 'X'IMPORTINGRETCODE = RETCODE.CALL METHOD C_OI_ERRORS=>SHOW_MESSAGEEXPORTINGTYPE = 'E'.ENDIF.CALL METHOD DOCUMENT->RELEASE_DOCUMENTIMPORTINGRETCODE = RETCODE.CALL METHOD C_OI_ERRORS=>SHOW_MESSAGEEXPORTINGTYPE = '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_SERVERIMPORTINGRETCODE = RETCODE.FREE LINK_SERVER.ENDIF.IF NOT FACTORY IS INITIAL.CALL METHOD FACTORY->STOP_FACTORYIMPORTINGRETCODE = RETCODE.FREE FACTORY.ENDIF.ENDFORM. " CLOSE_FACTORY
程序僅供參考。
總結(jié)
以上是生活随笔為你收集整理的【ABAP】在线预览文档对象的开发实现的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。