1、SAPABAPDOI技术的优化与说明应以前一个公司的邀请,对ABAP程序使用DOI技术输出EXCEL文件的程序进行优化处理。此公司的问题是,DOI输出的EXCEL太难看了。X系列的THINKPAD看程序要来回滚动,而现在的大屏幕的台式机上的EXCEL又局限在一个小小的角落。从我的角度来看,那批程序也是太难看了。DOI技术的优点,就不用说了!速度快,可定制EXCEL模板。缺点呢,缺点是我们ABAP顾问都太懒了,直接在网上搜到相关的程序,搞个例程下来,修理修理就成自己的了。我也在网上搜了一下,N个人的博客写的程序大同小异,甚至就是直接把别人的东西挂到自己的博客上。声讨一下,然后挂出我本人优化后的一
2、个程序。优化如下:、创建一个空屏幕上,只在屏幕上激活PAI、PBO事件下的FUNCTION MOUDLE。干嘛非要在屏幕上放一个CONTAINER组件呢,固定后那么难看。完全可以动态创建吗?动态创建使用CL_GUI_CONTAINER这个类。动态创建的好处在于,CONTAINER的大小不是固定的,完全随着屏幕的大小而创建。、本人发发善心,把夹杂在代码中的乱七八糟的内表与变量统统移到外面,定义成全局变量。在程序中随意定义代码的缺点都知道,就是没有人来给整理一下。本人还给这部分全局变量统计了命名规则,内表、变量、工作区分别用不同的前导符做区分。、把代码重新划分到不同的子程序里。通常XX出来的代码真
3、是太乱了,我受不了。在我的项目中,非把他们开掉不可(哦,我只是一个小兵,没这个权力)。、OAOR上传模版这些基本知识就说了,不知道的请XX一下。说明一下,我在程序指定了固定的区域输出数据时,不带边框;除去这一部分外,其他的部分数据输出时都加了边框,请各位兄弟姐妹们使用时注意。具体位置请搜索“CALL METHOD cl_spreadsheet-set_frame”。废说少说,上代码:*&-*& ReportZTRAINING26 事件的使用与说明*&-*REPORTztraining26 NO STANDARD PAGE HEADING.*声明数据库表 Declaration of datab
4、ase*TABLES:mara.物料主数据*定义结构类型 Define the structures type*结果内表结构TYPES:BEGIN OF typ_result,matnr TYPE matnr,物料编号werks TYPE werks_d,工厂lgort TYPE lgort_d,库存地点charg TYPE charg_d,批次boxTYPE c,END OF typ_result.*定义变量与内表 Define the variants and Internal tables*DATA:gt_result TYPE TABLE OF typ_result WITH HEAD
5、ER LINE.结果内表*-*调用相关对象使用的变量TYPE-POOLS:vrm, sbdst, soi.*定位EXCEL的单元格,TYPES:BEGIN OF typ_excel,rowTYPE kcd_ex_row_n,colTYPE kcd_ex_col_n,value TYPE char50,END OF typ_excel.DATA:gt_tabcontent TYPE TABLE OF typ_excel.DATA:wa_tabcontent TYPE typ_excel.TYPES: typ_url LIKE bapiuri-uri.TYPES: BEGIN OF typ_doc
6、u_descr,document_name(40),document_id(64),END OF typ_docu_descr.TYPES:BEGIN OF typ_area_excel,areano(2) TYPE n,tabcontent LIKE gt_tabcontent,END OF typ_area_excel.* SAP Desktop Office Integration InterfacesDATA: cl_containerTYPE REF TO cl_gui_container,cl_splitterTYPE REF TO cl_gui_splitter_containe
7、r,cl_controlTYPE REF TO i_oi_container_control,cl_docu_proxyTYPE REF TO i_oi_document_proxy,cl_spreadsheet TYPE REF TO i_oi_spreadsheet,cl_errorTYPE REF TO i_oi_error,cl_errorsTYPE REF TO i_oi_error OCCURS 0 WITH HEADER LINE.* spreadsheet interface structures for Excel data inputDATA:wa_cellitemTYPE
8、 soi_generic_item,wa_rangeitemTYPE soi_range_item,gt_rangesTYPE soi_range_list,gt_excel_input TYPE soi_generic_table,wa_excel_input TYPE soi_generic_item,g_initializedtype c,g_retcodeTYPE soi_ret_string,gt_excel_format TYPE soi_format_table,wa_formatLIKE LINE OF gt_excel_format.DATA:gt_itabTYPE TABL
9、E OF alsmex_tabline WITH HEADER LINE,gt_imt_tabTYPE TABLE OF typ_area_excel,wa_imt_tabLIKE LINE OF gt_imt_tab,g_macroTYPE text100,g_sheet(10) TYPE c,g_cell_fitTYPE c.DATA:cl_bds_instanceTYPE REF TO cl_bds_document_set,gt_doc_signatureTYPE sbdst_signature,wa_doc_signatureLIKE LINE OF gt_doc_signature
10、,gt_doc_components TYPE sbdst_components,gt_doc_urisTYPE sbdst_uri,wa_doc_urisLIKE LINE OF gt_doc_uris.DATA:g_appTYPE vrm_id,gt_applist TYPE vrm_values,g_excelTYPE text80 VALUE Excel.Sheet,EXCEL的表单g_docu_type TYPE text80,g_url(256)TYPE c,g_has_activex TYPE c,g_col TYPE i,字段所在的列数g_row TYPE i.字段所在的行数*
11、以下三个值为Tcode:OAOR里面新建模板文件的参数DATA: g_classnameTYPE sbdst_classname VALUE HRFPM_EXCEL_STANDARD,g_classtypeTYPE sbdst_classtype VALUE OT,g_object_key TYPE sbdst_object_key VALUE ZMB51_FZ.*宏定义 Define the macro*DEFINE m_value.clear &1.&1-key = &2.&1-text = &3.append &1.END-OF-DEFINITION.* 将数据对应到EXCEL的单元格,
12、并添加到内表中DEFINE m_excel_cell.clear wa_tabcontent.g_col = g_col + 1.wa_tabcontent-row= g_row.wa_tabcontent-col= g_col.wa_tabcontent-value = &1.shift wa_tabcontent-value left deleting leading space.append wa_tabcontent to gt_tabcontent.END-OF-DEFINITION.*选择屏幕 Customize the selection-screen*SELECTION-SCR
13、EEN BEGIN OF BLOCK xavery WITH FRAME TITLE text-001.SELECT-OPTIONS:s_matnr FOR mara-matnr MEMORY ID mat.物料编号SELECTION-SCREEN END OF BLOCK xavery.*执行程序事件 Executing the programs events*INITIALIZATION.START-OF-SELECTION.PERFORM sub_query_mara.END-OF-SELECTION.PERFORM sub_process_excel.CALL SCREEN 0100.
14、*&-*&Formsub_query_mara*&-*从物料主数据表MARA中取数*-*FORM sub_query_mara .* 取物料主数据SELECT matnrFROM maraINTO CORRESPONDING FIELDS OF TABLE gt_resultWHERE matnr IN s_matnr.ENDFORM. sub_query_mara* Dialog Modules PBO and PAI*MODULE status_0100 OUTPUT.DATA: wa_tab TYPE typ_area_excel.DATA: its_tab TYPE TABLE OF
15、typ_excel.SET PF-STATUS XAVERY_HSUEH.SET TITLEBAR TIT_100 WITH 活动界面示例.PERFORM sub_create_basic_object.LOOP AT gt_imt_tab INTO wa_tab.REFRESH gt_itab.gt_itab = wa_tab-tabcontent.PERFORM sub_set_cell.ENDLOOP.IF g_cell_fit = X.CALL METHOD cl_spreadsheet-fit_widestEXPORTINGname= spaceno_flush = X.ENDIF.
16、* 修改WORK SHEET 的名字CALL METHOD cl_spreadsheet-set_sheet_nameEXPORTINGnewname = 物料主数据清单oldname = Sheet1IMPORTINGerror= cl_errors.* 宏执行IF NOT g_macro IS INITIAL.*CALL METHOD DOCUMENT-EXECUTE_MACRO*EXPORTING*g_macro = g_macro*SCRIPT_NAME= Open_text*NO_FLUSH= *IMPORTING*cl_error= cl_errorS.*CALL METHOD C
17、_OI_ERRORS=SHOW_MESSAGE*EXPORTING*TYPE = E.*APPEND cl_errorS.ENDIF.ENDMODULE.status_0100 OUTPUT*&-*& Dialog Modules PAI*&-*MODULE user_command_0100 INPUT.LEAVE TO SCREEN 0.ENDMODULE.USER_COMMAND_0100 INPUT*&-*&FormSUB_CREATE_BASIC_OBJECT*&-*创建相关的对象*-*FORM sub_create_basic_object .CHECK g_initialized
18、 IS INITIAL.CALL FUNCTION GUI_HAS_ACTIVEXIMPORTINGreturn = g_has_activex.IF g_has_activex IS INITIAL.MESSAGE e007(demoofficeintegratio).ENDIF.* first get the SAP DOI i_oi_container_control interfaceCALL METHODc_oi_container_control_creator=get_container_controlIMPORTINGcontrol = cl_controlerror= cl_
19、error.* check no errors occuredCALL METHOD cl_error-raise_messageEXPORTINGtype = E.* 创建CONTIANERCREATE OBJECT cl_splitterEXPORTINGparent= cl_gui_container=screen0rows= 1columns = 1.CALL METHOD cl_splitter-set_borderEXPORTINGborder = cl_gui_cfw=false.cl_container= cl_splitter-get_container( row = 1 c
20、olumn = 1 ).* initialize the SAP DOI Container, tell it to run in the container* specified above and tell it to run Excel in-placeCALL METHOD cl_control-init_controlEXPORTINGr3_application_name= RBasis#EC NOTEXTinplace_enabled= Xinplace_scroll_documents = Xparent= cl_containerregister_on_close_event
21、= Xregister_on_custom_event = Xno_flush= XIMPORTINGerror= cl_errors.* save error object in collectionAPPEND cl_errors.CALL METHOD cl_gui_cfw=dispatch.wa_doc_signature-prop_name = DESCRIPTION.g_app = excel.IF g_app = excel.g_docu_type = g_excel.wa_doc_signature-prop_value = PP_REPORT.ELSE.ENDIF.APPEND wa_doc_signature TO gt_doc_signature.CREATE OBJECT cl_bds_instance.CALL METHOD cl_bds_instance-get_infoEXPORTINGclassname= g_classname
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1