1、*&-*& Report ZWM_015*&*&-*&*&*&-*REPORT zwm_015.TABLES: mchb,mbew,t320,mara,makt.TYPE-POOLS ole2.DATA: v_excel TYPE ole2_object,v_sheet TYPE ole2_object,v_book TYPE ole2_object,v_cell TYPE ole2_object,v_range TYPE ole2_object,v_font TYPE ole2_object,v_color TYPE ole2_object,v_border TYPE ole2_object
2、,v_column TYPE ole2_object.TYPE-POOLS: slis.DATA: afield TYPE slis_fieldcat_alv,fieldcat TYPE slis_t_fieldcat_alv,gs_layout TYPE slis_layout_alv,g_repid TYPE sy-repid,i_layout TYPE slis_layout_alv,rt_extab TYPE slis_t_extab,gridlsl TYPE lvc_s_glay.DATA: BEGIN OF it_excel OCCURS 0, “输出 ALV 汇总结构l_matn
3、r TYPE mchb-matnr,“物料编码l_maktx TYPE makt-maktx,“物料描述l_werks TYPE mchb-werks, “工厂l_lgort TYPE mchb-lgort,“库存地点l_lgnum TYPE t320-lgnum, “仓库号l_mtart TYPE t134t-mtbez,“物料类型l_msehl TYPE t006a-msehl,“单位l_lbkum TYPE mbew-lbkum,“账面数量l_lbkum1 TYPE mbew-lbkum,“账面数量l_salk3 TYPE mbew-salk3, “金额END OF it_excel.S
4、ELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text.PARAMETERS: p_werks LIKE mchb-werks OBLIGATORY , “工厂p_lgort LIKE mchb-lgort OBLIGATORY , “库存地点p_lfgja LIKE mchb-lfgja OBLIGATORY DEFAULT sy-datum+0(4). “会计年度SELECTION-SCREEN END OF BLOCK blk.DATA: BEGIN OF it_tab OCCURS 0,l_matnr TYPE mchb-mat
5、nr,“物料编码l_werks TYPE mchb-werks, “工厂l_lgort TYPE mchb-lgort,“库存地点l_clabs TYPE mchb-clabs,l_cumlm TYPE mchb-cumlm,l_cinsm TYPE mchb-cinsm,l_ceinm TYPE mchb-ceinm,l_cspem TYPE mchb-cspem,l_cretm TYPE mchb-cretm,l_maktx TYPE makt-maktx,“物料描述l_meins TYPE mara-meins,“单位l_lbkum TYPE mbew-lbkum,“账面数量l_salk
6、3 TYPE mbew-salk3, “金额l_bwtar TYPE mbew-bwtar,“评估类型l_bklas TYPE mbew-bklas,“评估类l_lgnum TYPE t320-lgnum, “仓库号l_charg TYPE mchb-charg,“评估类型l_mtart TYPE t134t-mtbez,“物料类型l_zsalk3 TYPE mbew-salk3, “总金额l_msehl TYPE t006a-msehl,“单位中文文本l_salks1 TYPE mbew-salk3,l_salks2 TYPE mbew-salk3,l_salks3 TYPE mbew-sa
7、lk3,l_salks4 TYPE mbew-salk3,l_salks5 TYPE mbew-salk3,l_salks6 TYPE mbew-salk3,END OF it_tab.*DATA: BEGIN OF it_tab2 OCCURS 0,* l_matnr TYPE mard-matnr,“物料编码* l_werks TYPE mard-werks, “工厂* l_lgort TYPE mard-lgort,“库存地点* l_labst TYPE mard-labst,* l_umlme TYPE mard-umlme,* l_insme TYPE mard-insme,* l_
8、einme TYPE mard-einme,* l_speme TYPE mard-speme,* l_retme TYPE mard-retme,* l_maktx TYPE makt-maktx,“物料描述* l_meins TYPE mara-meins,“单位* l_lbkum TYPE mbew-lbkum,“账面数量* l_salk3 TYPE mbew-salk3, “金额* l_msehl TYPE t006a-msehl,“单位中文文本* l_bwtar TYPE mbew-bwtar,“评估类型* l_bklas TYPE mbew-bklas,“评估类* l_lgnum
9、TYPE t320-lgnum, “仓库号* l_charg TYPE mchb-charg,“评估类型* l_mtart TYPE t134t-mtbez,“物料类型* l_zsalk3 TYPE mbew-salk3, “总金额* l_salks1 TYPE mbew-salk3,* l_salks2 TYPE mbew-salk3,* l_salks3 TYPE mbew-salk3,* l_salks4 TYPE mbew-salk3,* l_salks5 TYPE mbew-salk3,* l_salks6 TYPE mbew-salk3,*END OF it_tab.DATA: B
10、EGIN OF itab_t320 OCCURS 0,lgnum LIKE t320-lgnum, “仓库号“lgort LIKE t320-lgort, “存储位置“END OF itab_t320.DATA : BEGIN OF it_ze OCCURS 0,l_zsalk3 TYPE mbew-salk3,END OF it_ze.DATA it_zje LIKE TABLE OF it_ze WITH HEADER LINE .DATA: BEGIN OF it_alv OCCURS 0, “输出 ALV 汇总结构flag(1),l_matnr TYPE t134t-mtbez,“物料
11、编码l_maktx TYPE makt-maktx,“物料描述l_werks TYPE mchb-werks, “工厂l_lgort TYPE mchb-lgort,“库存地点l_lgnum TYPE t320-lgnum, “仓库号l_charg TYPE mchb-charg,“评估类型l_msehl TYPE t006a-msehl,“单位l_lbkum TYPE mbew-lbkum,“账面数量l_lbkum1 TYPE mbew-lbkum,“盘点数量l_salk3 TYPE mbew-salk3, “金额l_zsalk3 TYPE mbew-salk3,“总金额l_mtart TY
12、PE t134t-mtbez,“物料类型l_bwtar TYPE mbew-bwtar,“评估类型l_bklas TYPE mbew-bklas,“评估类* l_clabs TYPE mchb-clabs,* l_cspem TYPE mchb-cspem,END OF it_alv.DATA it_tab1 LIKE TABLE OF it_tab WITH HEADER LINE.DATA: BEGIN OF it_mara OCCURS 0,l_meins TYPE mara-meins,END OF it_mara.INITIALIZATION .text = 请输入选择条件.g_re
13、pid = sy-repid.START-OF-SELECTION.*定义两个方法PERFORM get_data.PERFORM disp_data.*&-*& Form GET_DATA*&-* text*-* p1 text* p1 text* p1 text* P_FIELDCAT text*-*FORM fieldcat_init USING u_er_fieldcat TYPE slis_t_fieldcat_alv.DATA: afieldcat TYPE slis_fieldcat_alv,pos TYPE i.CLEAR pos.DEFINE d_get_field.pos
14、= pos + 1.clear afieldcat.afieldcat-col_pos = pos.afieldcat-fieldname = &1.afieldcat-seltext_l = &2.afieldcat-key = &3.append afieldcat to u_er_fieldcat.END-OF-DEFINITION.d_get_field L_MATNR 物料编码 X.d_get_field L_MAKTX 物料描述 X.d_get_field L_WERKS 工厂 X.d_get_field L_LGORT 库存地点 X.d_get_field L_LGNUM 仓库号
15、 .d_get_field L_MTART 评估类型 .d_get_field L_MSEHL 单位 .d_get_field L_LBKUM 账面数量 .d_get_field L_LBKUM1 盘点数量 .d_get_field L_SALK3 金额 .*d_get_field X.ENDFORM. “fieldcat_init*&-*& Form DISPLAY_ALV*&-* text*-* p1 text* p1 text* p1 text* p1 text* p1 text* p1 text* TYPE ANY ,TYPE ANY.DATA: lv_txt(50) TYPE c.D
16、ATA: row_i TYPE i,col_i TYPE i.LOOP AT it_alv.DATA zj1 LIKE it_alv-l_salk3 VALUE 0.zj1 = zj1 + it_alv-l_salk3.MOVE zj1 TO it_alv-l_zsalk3.MODIFY it_alv FROM it_alv.ENDLOOP.* 从内表循环数据,按顺序填到单元表中LOOP AT it_alv .MOVE-CORRESPONDING it_alv TO it_excel.APPEND it_excel.ENDLOOP.LOOP AT it_excel ASSIGNING .row
17、_i = sy-tabix + 2.col_i = sy-tabix + 1.DO 10 TIMES.col_i = sy-index .ASSIGN COMPONENT sy-index OF STRUCTURE TO .lv_txt = .fill_cell row_i col_i lv_txt 0 10.IF col_i = 11 AND row_i = 1.CALL METHOD OFv_cellINTERIOR = v_color.SET PROPERTY OF v_color ColorIndex = 5.ENDIF .ENDDO.ENDLOOP.row_i = row_i + 1
18、.fill_cell row_i 9 合计: 1 10.SET PROPERTY OF v_cell HorizontalAlignment = -4108.fill_cell row_i 10 it_alv-l_zsalk3 1 10. “总金额的行列*加边框DATA: post TYPE string,col TYPE c VALUE J,row TYPE string.MOVE row_i TO row.CONCATENATE J row INTO post.CALL METHOD OFv_excelRange = v_rangeEXPORTING#1 = A1#2 = post.CAL
19、L METHOD OFv_rangeBORDERS = v_border.SET PROPERTY OF v_border LineStyle = 1.SET PROPERTY OF v_border WEIGHT = 2 .SET PROPERTY OF v_border ColorIndex = 1.FREE OBJECT v_border.FREE OBJECT v_cell.CALL METHOD OFv_excelColumns = v_column.CALL METHOD OFv_columnAutofit.* 设置 excel 为可见SET PROPERTY OF v_excel Visible = 1.ENDFORM. “ SHO_EXCEL