/********* Begin Procedure Script ************/ BEGIN var_out = with a as ( select mandt,matnr,werks,lgort,charg,lfgja,lfmon,sum(clabs+CUMLM) clabs from ( select mandt,matnr,werks,lgort,charg,lfgja,lfmon,clabs,cumlm from SAPABAP1.nsdm_v_mchbh as h where h.mandt = '820' and (h.clabs+CUMLM) <> 0) group by mandt,matnr,werks,lgort,charg,lfgja,lfmon ),b as ( select * from SAPABAP1.zwql_mbewh_001 a where a.mandt = '820' and LBKUM <> 0 union all select * from SAPABAP1.zwql_mbew_001 a where a.mandt = '820' and LBKUM <> 0 ),c as ( select mandt,matnr,werks,lgort,charg,lfgja,lfmon,clabs,je from ( select a.mandt,a.matnr,a.werks,a.lgort,a.charg,a.lfgja,a.lfmon,a.clabs, row_number() over(partition by b.matnr,b.bwkey,b.bwtar,a.lfgja,a.lfmon,a.lgort order by a.lfgja,a.lfmon asc) rn,salk3,LBKUM,round(salk3/lbkum*clabs,2) as je from a inner join b on a.matnr = b.matnr and a.werks =b.bwkey and a.charg = b.bwtar and b.lfgja||b.lfmon >= a.lfgja||a.lfmon group by a.mandt,a.matnr,a.werks,a.lgort,a.charg,a.lfgja,a.lfmon,a.clabs,b.mandt,a.clabs,b.matnr,b.bwkey,b.bwtar,b.lfgja,b.lfmon,b.salk3,b.lbkum ) where rn = 1) select mandt,matnr,werks,lgort,lfgja, sum(sl01) sl01, sum(je01) je01, sum(sl02) sl02, sum(je02) je02, sum(sl03) sl03, sum(je03) je03, sum(sl04) sl04, sum(je04) je04, sum(sl05) sl05, sum(je05) je05, sum(sl06) sl06, sum(je06) je06, sum(sl07) sl07, sum(je07) je07, sum(sl08) sl08, sum(je08) je08, sum(sl09) sl09, sum(je09) je09, sum(sl10) sl10, sum(je10) je10, sum(sl11) sl11, sum(je11) je11, sum(sl12) sl12, sum(je12) je12 from ( select mandt,matnr,werks,lgort,lfgja, case when lfmon = '01' then sl else 0 end sl01, case when lfmon = '01' then je else 0 end je01, case when lfmon = '02' then sl else 0 end sl02, case when lfmon = '02' then je else 0 end je02, case when lfmon = '03' then sl else 0 end sl03, case when lfmon = '03' then je else 0 end je03, case when lfmon = '04' then sl else 0 end sl04, case when lfmon = '04' then je else 0 end je04, case when lfmon = '05' then sl else 0 end sl05, case when lfmon = '05' then je else 0 end je05, case when lfmon = '06' then sl else 0 end sl06, case when lfmon = '06' then je else 0 end je06, case when lfmon = '07' then sl else 0 end sl07, case when lfmon = '07' then je else 0 end je07, case when lfmon = '08' then sl else 0 end sl08, case when lfmon = '08' then je else 0 end je08, case when lfmon = '09' then sl else 0 end sl09, case when lfmon = '09' then je else 0 end je09, case when lfmon = '10' then sl else 0 end sl10, case when lfmon = '10' then je else 0 end je10, case when lfmon = '11' then sl else 0 end sl11, case when lfmon = '11' then je else 0 end je11, case when lfmon = '12' then sl else 0 end sl12, case when lfmon = '12' then je else 0 end je12 from ( select mandt,matnr,werks,lgort,lfgja,lfmon,sum(clabs) sl,sum(je) je from c b where 1=1 group by mandt,matnr,werks,lgort,lfgja,lfmon)) group by mandt,matnr,werks,lgort,lfgja ; END /********* End Procedure Script ************/zql_mm050_001
CREATE VIEW "SAPABAP1"."ZWQL_MBEWH_001" ( "MANDT", "MATNR", "BWKEY", "BWTAR", "LFGJA", "LFMON", "LBKUM", "SALK3", "VPRSV", "VERPR", "STPRS" ) AS SELECT "MBVMBEWH"."MANDT", "MBVMBEWH"."MATNR", "MBVMBEWH"."BWKEY", "MBVMBEWH"."BWTAR", "MBVMBEWH"."LFGJA", "MBVMBEWH"."LFMON", "MBVMBEWH"."LBKUM", "MBVMBEWH"."SALK3", "MBVMBEWH"."VPRSV", "MBVMBEWH"."VERPR", "MBVMBEWH"."STPRS" FROM "MBVMBEWH" "MBVMBEWH" WHERE ( "MBVMBEWH"."MANDT" = SESSION_CONTEXT( 'CDS_CLIENT') AND NOT ( "MBVMBEWH"."BWTAR" = N'' ) ) WITH READ ONLYZWQL_MBEWH_001
CREATE VIEW "SAPABAP1"."ZWQL_MBEW_001" ( "MANDT", "MATNR", "BWKEY", "BWTAR", "LFGJA", "LFMON", "LBKUM", "SALK3", "VPRSV", "VERPR", "STPRS" ) AS SELECT "MBVMBEW"."MANDT", "MBVMBEW"."MATNR", "MBVMBEW"."BWKEY", "MBVMBEW"."BWTAR", N'9999' AS "LFGJA", N'12' AS "LFMON", "MBVMBEW"."LBKUM", "MBVMBEW"."SALK3", "MBVMBEW"."VPRSV", "MBVMBEW"."VERPR", "MBVMBEW"."STPRS" FROM "MBVMBEW" "MBVMBEW" WHERE ( "MBVMBEW"."MANDT" = SESSION_CONTEXT('CDS_CLIENT') AND NOT ( "MBVMBEW"."BWTAR" = N'' ) ) WITH READ ONLYZWQL_MBEW_001
/********* Begin Procedure Script ************/ BEGIN var_out = select matnr,mjahr,month_budat,lgort, sum(purchase_num) purnum, sum(purchase_mon) purmon, sum(production_num) pronum, sum(production_mon) promon, sum(allocation_num) allnum, sum(allocation_mon) allmon, sum(sales_return_num) salret_num, sum(sales_return_mon) salret_mon, sum(others_num) othnum, sum(others_mon) othmon, sum(sales_num) salnum, sum(sales_mon) salmon, sum(pur_out_num) purout_num, sum(pur_out_mon) purout_mon, sum(others_out_num) othout_num, sum(others_out_mon) othout_mon, werks from ( select matnr,mjahr,month_budat,lgort, others_num, others_mon, purchase_num,production_num,allocation_num,sales_return_num, purchase_mon,production_mon,allocation_mon,sales_return_mon, others_out_num, others_out_mon, sales_num,pur_out_num, sales_mon,pur_out_mon,werks from ( select matnr,mjahr,month_budat,lgort,shkzg, case when bwart = '101' and ebeln <> '' then menge when bwart = '102' and ebeln <> '' then 0-menge else 0 end purchase_num, case when bwart = '101' and ebeln <> '' then dmbtr when bwart = '102' and ebeln <> '' then 0-dmbtr else 0 end purchase_mon, case when bwart = '101' and aufnr <> '' then menge when bwart = '102' and aufnr <> '' then 0-menge else 0 end production_num, case when bwart = '101' and aufnr <> '' then dmbtr when bwart = '102' and aufnr <> '' then 0-dmbtr else 0 end production_mon, case when (bwart = '311' or bwart = '315') and shkzg = 'S' then menge when (bwart = '312' or bwart = '316') and shkzg = 'H' then 0-menge else 0 end allocation_num, case when (bwart = '311' or bwart = '315') and shkzg = 'S' then dmbtr when (bwart = '312' or bwart = '316') and shkzg = 'H' then 0-dmbtr else 0 end allocation_mon, case when bwart = '653' then menge when bwart = '654' then 0-menge else 0 end sales_return_num, case when bwart = '653' then dmbtr when bwart = '654' then 0-dmbtr else 0 end sales_return_mon, case when bwart not in ('101','102','311','312','315','316','653','654','311','313','312','314','601','602') and shkzg = 'S' then menge else 0 end others_num, case when bwart not in ('101','102','311','312','315','316','653','654','311','313','312','314','601','602') and shkzg = 'S' then dmbtr else 0 end others_mon, case when bwart = '601' then menge when bwart = '602' then 0-menge else 0 end sales_num, case when bwart = '601' then dmbtr when bwart = '602' then 0-dmbtr else 0 end sales_mon, case when (bwart = '311' or bwart = '313') and shkzg = 'H' then menge when (bwart = '312' or bwart = '314') and shkzg = 'S' then 0-menge else 0 end pur_out_num, case when (bwart = '311' or bwart = '313') and shkzg = 'H' then dmbtr when (bwart = '312' or bwart = '314') and shkzg = 'S' then 0-dmbtr else 0 end pur_out_mon, case when bwart not in ('101','102','311','312','315','316','653','654','311','313','312','314','601','602') and shkzg = 'H' then menge else 0 end others_out_num, case when bwart not in ('101','102','311','312','315','316','653','654','311','313','312','314','601','602') and shkzg = 'H' then dmbtr else 0 end others_out_mon, menge,dmbtr,werks from( select d.matnr, d.bwart, d.bwtar, d.ebeln, d.werks, d.lgort, d.menge, d.dmbtr, d.shkzg, d.mjahr, d.month_budat, d.aufnr from sapabap1.matdoc d where d.mandt = '820'))) group by matnr,mjahr,month_budat,lgort,werks; END /********* End Procedure Script ************/ZQL_MM050_002
*&---------------------------------------------------------------------* *& Report ZMM050 *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT zmm050. TABLES:mara,marc,t001l,mseg,mbewh,zql_mm050_002. DATA:zbyear TYPE mseg-mjahr, zeyear TYPE mseg-mjahr, zbegin TYPE mbewh-lfmon, zend TYPE mbewh-lfmon. DATA:BEGIN OF ls_mchbh, matnr TYPE mara-matnr, "物料 matkl TYPE mara-matkl, wgbez TYPE t023t-wgbez, maktx TYPE makt-maktx, "物料描述 werks TYPE t001w-werks, "工厂 name1 TYPE t001w-name1, "工厂描述 lgort TYPE t001l-lgort, "库存地点 lgobe TYPE t001l-lgobe, "库存地点描述 qcsl TYPE zql_mm050_001-sl01, "期初数量(合格) qmsl TYPE zql_mm050_001-sl02, qcje TYPE zql_mm050_001-je01, "期初数量(合格) qmje TYPE zql_mm050_001-je02, * lfgja TYPE zql_mm050_001-lfgja, "年 lfmon TYPE mchbh-lfmon, "月 END OF ls_mchbh. DATA:BEGIN OF ls_money, matnr TYPE matnr, lfgja TYPE lfgja, lfmon TYPE lfmon, lbkum TYPE lbkum, "总计已估计库存 salk3 TYPE salk3, "估价的总库存价值 bwkey TYPE mbewh-bwkey, bwtar TYPE mbewh-bwtar, vprsv TYPE mbewh-vprsv, verpr TYPE mbewh-verpr, stprs TYPE mbewh-stprs, END OF ls_money. DATA:ls_mard LIKE ls_mchbh, lt_mchbh_qc LIKE TABLE OF ls_mchbh, lt_mchbh_qm LIKE TABLE OF ls_mchbh, lt_mchbh LIKE TABLE OF ls_mchbh, lt_mchbh_all LIKE TABLE OF ls_mchbh, ls_matdoc TYPE zql_mm050_002, lt_matdoc TYPE TABLE OF zql_mm050_002, ls_mbewh LIKE ls_money, lt_mbewh LIKE TABLE OF ls_money, ls_mbew LIKE ls_money, lt_mbew LIKE TABLE OF ls_money, ls_mbewh2 LIKE ls_money, lt_mbewh2 LIKE TABLE OF ls_money, ls_mbew2 LIKE ls_money, lt_mbew2 LIKE TABLE OF ls_money. . DATA: BEGIN OF ls_itab, matnr TYPE mara-matnr, "物料 maktx TYPE makt-maktx, "物料描述 werks TYPE t001w-werks, "工厂 name1 TYPE t001w-name1, "工厂描述 matkl TYPE mara-matkl, wgbez TYPE t023t-wgbez, lgort TYPE t001l-lgort, "库存地点 lgobe TYPE t001l-lgobe, "库存地点描述 clabs TYPE mchbh-clabs, "期初库存数量 salk3 TYPE mbewh-salk3, "期初库存金额 menge1 TYPE matdoc-menge, "采购入库数量 menge2 TYPE matdoc-menge, "生产入库数量 menge3 TYPE matdoc-menge, "调拨入库数量 menge4 TYPE matdoc-menge, "销售退货入库数量 menge5 TYPE matdoc-menge, "其他入库数量 menge6 TYPE matdoc-menge, "入库数量合计 dmbtr1 TYPE matdoc-dmbtr, "采购入库金额 dmbtr2 TYPE matdoc-dmbtr, "生产入库金额 dmbtr3 TYPE matdoc-dmbtr, "调拨入库金额 dmbtr4 TYPE matdoc-dmbtr, "销售退货入库金额 dmbtr5 TYPE matdoc-dmbtr, "其他入库金额 dmbtr6 TYPE matdoc-dmbtr, "入库金额合计 menge7 TYPE matdoc-menge, "销售出库数量 menge8 TYPE matdoc-menge, "调拨出库数量 menge9 TYPE matdoc-menge, "其它出库数量 menge10 TYPE matdoc-menge, "出库数量合计 dmbtr7 TYPE matdoc-dmbtr, "销售出库金额 dmbtr8 TYPE matdoc-dmbtr, "调拨出库金额 dmbtr9 TYPE matdoc-dmbtr, "其它出库金额 dmbtr10 TYPE matdoc-dmbtr, "出库金额合计 menge11 TYPE matdoc-menge, "期末库存数量 dmbtr11 TYPE matdoc-dmbtr, "期末库存金额 charg TYPE mchbh-charg, END OF ls_itab. DATA: BEGIN OF ls_itab2, matnr TYPE mara-matnr, "物料 maktx TYPE makt-maktx, "物料描述 werks TYPE t001w-werks, "工厂 name1 TYPE t001w-name1, "工厂描述 matkl TYPE mara-matkl, wgbez TYPE t023t-wgbez, lgort TYPE t001l-lgort, "库存地点 lgobe TYPE t001l-lgobe, "库存地点描述 clabs TYPE mchbh-clabs, "期初库存数量 salk3 TYPE mbewh-salk3, "期初库存金额 menge1 TYPE matdoc-menge, "采购入库数量 menge2 TYPE matdoc-menge, "生产入库数量 menge3 TYPE matdoc-menge, "调拨入库数量 menge4 TYPE matdoc-menge, "销售退货入库数量 menge5 TYPE matdoc-menge, "其他入库数量 menge6 TYPE matdoc-menge, "入库数量合计 dmbtr1 TYPE matdoc-dmbtr, "采购入库金额 dmbtr2 TYPE matdoc-dmbtr, "生产入库金额 dmbtr3 TYPE matdoc-dmbtr, "调拨入库金额 dmbtr4 TYPE matdoc-dmbtr, "销售退货入库金额 dmbtr5 TYPE matdoc-dmbtr, "其他入库金额 dmbtr6 TYPE matdoc-dmbtr, "入库金额合计 menge7 TYPE matdoc-menge, "销售出库数量 menge8 TYPE matdoc-menge, "调拨出库数量 menge9 TYPE matdoc-menge, "其它出库数量 menge10 TYPE matdoc-menge, "出库数量合计 dmbtr7 TYPE matdoc-dmbtr, "销售出库金额 dmbtr8 TYPE matdoc-dmbtr, "调拨出库金额 dmbtr9 TYPE matdoc-dmbtr, "其它出库金额 dmbtr10 TYPE matdoc-dmbtr, "出库金额合计 menge11 TYPE matdoc-menge, "期末库存数量 dmbtr11 TYPE matdoc-dmbtr, "期末库存金额 END OF ls_itab2. DATA:lt_itab LIKE TABLE OF ls_itab, lt_itab2 LIKE TABLE OF ls_itab2, lt_itab3 LIKE TABLE OF ls_itab2, lt_money LIKE TABLE OF ls_money, lt_money2 LIKE TABLE OF ls_money. DATA: l_field(300) TYPE c. ************************************************************* SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text001. SELECT-OPTIONS: s_matnr FOR mara-matnr,"物料 s_werks FOR marc-werks DEFAULT '8000',"工厂 s_lgort FOR t001l-lgort,"库存地点 s_matkl FOR mara-matkl,"物料组 s_mtart FOR mara-mtart,"物料类型 s_mjahr FOR mseg-mjahr DEFAULT sy-datum+(4) NO-EXTENSION NO INTERVALS,"年度 s_begin FOR mbewh-lfmon DEFAULT sy-datum+4(2) NO-EXTENSION NO INTERVALS,"开始月 s_end FOR mbewh-lfmon DEFAULT sy-datum+4(2) NO-EXTENSION NO INTERVALS."结束月 SELECTION-SCREEN END OF BLOCK blk1. INITIALIZATION. text001 = '选择条件'. LOOP AT SCREEN. IF screen-name = 'S_MJAHR-LOW' OR screen-name = 'S_BEGIN-LOW' OR screen-name = 'S_END-LOW'. screen-required = '1'. MODIFY SCREEN. ENDIF. ENDLOOP. *****************************执行*************************** START-OF-SELECTION. PERFORM checkdata. PERFORM getdata. PERFORM alv_data. ******************************************************** FORM getdata. CLEAR:lt_itab,lt_matdoc,lt_mbewh,lt_mbew. l_field = ' mara~matnr,mara~matkl,t~WGBEZ,makt~maktx,mchbh~werks,t001w~name1,mchbh~lgort,t001l~lgobe,sl' && zend && ' as qcsl,je' && zend && ' as qcje'. "查询成品历史库存信息 SELECT (l_field) FROM zql_mm050_001 AS mchbh INNER JOIN mara ON mara~matnr = mchbh~matnr INNER JOIN makt ON makt~matnr = mara~matnr LEFT JOIN t023t AS t ON mara~matkl = t~matkl INNER JOIN t001w ON t001w~werks = mchbh~werks INNER JOIN t001l ON t001l~werks = mchbh~werks AND t001l~lgort = mchbh~lgort WHERE mara~matnr IN @s_matnr AND mchbh~werks IN @s_werks AND mchbh~lgort IN @s_lgort AND mara~matkl IN @s_matkl AND mara~mtart IN @s_mtart AND mchbh~lfgja = @zeyear AND mara~mtart = 'Z003' INTO CORRESPONDING FIELDS OF TABLE @lt_mchbh_qc. l_field = ' mara~matnr,mara~matkl,t~WGBEZ,makt~maktx,mchbh~werks,t001w~name1,mchbh~lgort,t001l~lgobe,sl' && s_end-low && ' as qmsl,je' && s_end-low && ' as qmje'. SELECT (l_field) FROM zql_mm050_001 AS mchbh INNER JOIN mara ON mara~matnr = mchbh~matnr INNER JOIN makt ON makt~matnr = mara~matnr LEFT JOIN t023t AS t ON mara~matkl = t~matkl INNER JOIN t001w ON t001w~werks = mchbh~werks INNER JOIN t001l ON t001l~werks = mchbh~werks AND t001l~lgort = mchbh~lgort WHERE mara~matnr IN @s_matnr AND mchbh~werks IN @s_werks AND mchbh~lgort IN @s_lgort AND mara~matkl IN @s_matkl AND mara~mtart IN @s_mtart AND mchbh~lfgja = @s_mjahr-low AND mara~mtart = 'Z003' INTO CORRESPONDING FIELDS OF TABLE @lt_mchbh_qm. APPEND LINES OF lt_mchbh_qc TO lt_mchbh_all. APPEND LINES OF lt_mchbh_qm TO lt_mchbh_all. SORT lt_mchbh_all BY matnr werks lgort. "合并期初和期末 LOOP AT lt_mchbh_all INTO ls_mchbh. COLLECT ls_mchbh INTO lt_mchbh. ENDLOOP. SELECT matdoc~matnr,werks,lgort, SUM( purnum ) AS purnum, SUM( purmon ) AS purmon, SUM( pronum ) AS pronum, SUM( promon ) AS promon, SUM( allnum ) AS allnum, SUM( allmon ) AS allmon, SUM( salret_num ) AS salret_num, SUM( salret_mon ) AS salret_mon, SUM( othnum ) AS othnum, SUM( othmon ) AS othmon, SUM( salnum ) AS salnum, SUM( salmon ) AS salmon, SUM( purout_num ) AS purout_num, SUM( purout_mon ) AS purout_mon, SUM( othout_num ) AS othout_num, SUM( othout_mon ) AS othout_mon FROM zql_mm050_002 AS matdoc INNER JOIN mara ON mara~matnr = matdoc~matnr WHERE matdoc~matnr IN @s_matnr AND matdoc~werks IN @s_werks AND matdoc~lgort IN @s_lgort AND mara~matkl IN @s_matkl AND mara~mtart IN @s_mtart AND matdoc~mjahr = @s_mjahr-low AND matdoc~month_budat >= @s_begin-low AND matdoc~month_budat <= @s_end-low GROUP BY matdoc~matnr,werks,lgort INTO CORRESPONDING FIELDS OF TABLE @lt_matdoc. SORT lt_matdoc BY matnr werks lgort. LOOP AT lt_mchbh INTO ls_mchbh. CLEAR ls_itab. ls_itab-matkl = ls_mchbh-matkl. ls_itab-wgbez = ls_mchbh-wgbez. ls_itab-matnr = ls_mchbh-matnr. ls_itab-maktx = ls_mchbh-maktx. ls_itab-werks = ls_mchbh-werks. ls_itab-name1 = ls_mchbh-name1. ls_itab-lgort = ls_mchbh-lgort. ls_itab-lgobe = ls_mchbh-lgobe. ls_itab-clabs = ls_mchbh-qcsl."期初库存数量 ls_itab-salk3 = ls_mchbh-qcje."期初库存金额 ls_itab-menge11 = ls_mchbh-qmsl."期末库存数量 ls_itab-dmbtr11 = ls_mchbh-qmje."期末库存金额 READ TABLE lt_matdoc INTO ls_matdoc WITH KEY matnr = ls_mchbh-matnr werks = ls_mchbh-werks lgort = ls_mchbh-lgort BINARY SEARCH. IF sy-subrc = 0. ls_itab-menge1 = ls_matdoc-purnum."采购入库数量 ls_itab-dmbtr1 = ls_matdoc-purmon."采购入库金额 ls_itab-menge2 = ls_matdoc-pronum."生产入库数量 ls_itab-dmbtr2 = ls_matdoc-promon."生产入库金额 ls_itab-menge3 = ls_matdoc-allnum."调拨入库数量 ls_itab-dmbtr3 = ls_matdoc-allmon."调拨入库金额 ls_itab-menge4 = ls_matdoc-salret_num."销售退货入库数量 ls_itab-dmbtr4 = ls_matdoc-salret_mon."销售退货入库金额 ls_itab-menge5 = ls_matdoc-othnum."其他入库数量 ls_itab-dmbtr5 = ls_matdoc-othmon."其他入库金额 ls_itab-menge7 = ls_matdoc-salnum."销售出库数量 ls_itab-dmbtr7 = ls_matdoc-salmon."销售出库金额 ls_itab-menge8 = ls_matdoc-purout_num."调拨出库数量 ls_itab-dmbtr8 = ls_matdoc-purout_mon."调拨出库金额 ls_itab-menge9 = ls_matdoc-othout_num."其他出库数量 ls_itab-dmbtr9 = ls_matdoc-othout_mon."其他出库金额 "入库数量合计:采购入库数量 + 生产入库数量 + 调拨入库数据 + 销售退货入库数量 + 其他入库数量 ls_itab-menge6 = ls_itab-menge1 + ls_itab-menge2 + ls_itab-menge3 + ls_itab-menge4 + ls_itab-menge5. "入库金额合计:采购入库金额 + 生产入库金额 + 调拨入库金额 + 销售退货入库金额 + 其他入库金额 ls_itab-dmbtr6 = ls_itab-dmbtr1 + ls_itab-dmbtr2 + ls_itab-dmbtr3 + ls_itab-dmbtr4 + ls_itab-dmbtr5. "出库数量合计:销售出库数量 + 调拨出库数量 + 其它出库数量 ls_itab-menge10 = ls_itab-menge7 + ls_itab-menge8 + ls_itab-menge9. "出库金额合计:销售出库金额 + 调拨出库金额 + 其它出库金额 ls_itab-dmbtr10 = ls_itab-dmbtr7 + ls_itab-dmbtr8 + ls_itab-dmbtr9. ENDIF. APPEND ls_itab TO lt_itab. ENDLOOP. ENDFORM. FORM checkdata. "取最近一年的 IF s_begin-low > s_end-low. MESSAGE i000(0k) WITH '结束月必须大于等于开始月!'. STOP. ELSE. zbyear = ''.zeyear = ''.zbegin = ''.zend = ''. IF s_begin-low = 1. zbyear = s_mjahr-low - 1. zeyear = s_mjahr-low - 1. zbegin = 1. zend = 12. ELSE. zbyear = s_mjahr-low - 1. zeyear = s_mjahr-low. zbegin = s_begin-low. zend = s_begin-low - 1. ENDIF. ENDIF. ENDFORM. FORM alv_data. DATA: lw_layout TYPE slis_layout_alv, lt_fieldcat TYPE slis_t_fieldcat_alv. lw_layout-colwidth_optimize = 'X'. lw_layout-zebra = 'X'. DATA:lw_fcat TYPE slis_fieldcat_alv. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MATNR' '物料' . PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MAKTX' '物料描述' . PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MATKL' '物料组' . PERFORM fill_fieldcat TABLES lt_fieldcat USING 'WGBEZ' '物料组描述' . PERFORM fill_fieldcat TABLES lt_fieldcat USING 'WERKS' '工厂' . PERFORM fill_fieldcat TABLES lt_fieldcat USING 'NAME1' '工厂描述' . PERFORM fill_fieldcat TABLES lt_fieldcat USING 'LGORT' '库存地点' . PERFORM fill_fieldcat TABLES lt_fieldcat USING 'LGOBE' '库存地点描述' . PERFORM fill_fieldcat TABLES lt_fieldcat USING 'CLABS' '期初库存数量'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'SALK3' '期初库存金额' . PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MENGE1' '采购入库数量'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MENGE2' '生产入库数量'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MENGE3' '调拨入库数量'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MENGE4' '销售退货入库数量'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MENGE5' '其他入库数量'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MENGE6' '入库数量合计'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'DMBTR1' '采购入库金额'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'DMBTR2' '生产入库金额'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'DMBTR3' '调拨入库金额'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'DMBTR4' '销售退货入库金额'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'DMBTR5' '其他入库金额'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'DMBTR6' '入库金额合计'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MENGE7' '销售出库数量'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MENGE8' '调拨出库数量'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MENGE9' '其它出库数量'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MENGE10' '出库数量合计'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'DMBTR7' '销售出库金额'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'DMBTR8' '调拨出库金额'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'DMBTR9' '其它出库金额'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'DMBTR10' '出库金额合计'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'MENGE11' '期末库存数量'. PERFORM fill_fieldcat TABLES lt_fieldcat USING 'DMBTR11' '期末库存金额'. "期初 lw_fcat-emphasize = 'C310'. MODIFY lt_fieldcat[] FROM lw_fcat TRANSPORTING emphasize WHERE fieldname = 'CLABS' OR fieldname = 'SALK3'. "入 lw_fcat-emphasize = 'C410'. MODIFY lt_fieldcat[] FROM lw_fcat TRANSPORTING emphasize WHERE fieldname = 'MENGE1' OR fieldname = 'MENGE2' OR fieldname = 'MENGE3' OR fieldname = 'MENGE4' OR fieldname = 'MENGE5' OR fieldname = 'MENGE6' OR fieldname = 'DMBTR1' OR fieldname = 'DMBTR2' OR fieldname = 'DMBTR3' OR fieldname = 'DMBTR4' OR fieldname = 'DMBTR5' OR fieldname = 'DMBTR6'. "出 lw_fcat-emphasize = 'C510'. MODIFY lt_fieldcat[] FROM lw_fcat TRANSPORTING emphasize WHERE fieldname = 'MENGE7' OR fieldname = 'MENGE8' OR fieldname = 'MENGE9' OR fieldname = 'MENGE10' OR fieldname = 'DMBTR7' OR fieldname = 'DMBTR8' OR fieldname = 'DMBTR9' OR fieldname = 'DMBTR10'. "期末 lw_fcat-emphasize = 'C710'. MODIFY lt_fieldcat[] FROM lw_fcat TRANSPORTING emphasize WHERE fieldname = 'MENGE11' OR fieldname = 'DMBTR11'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING it_fieldcat = lt_fieldcat[] i_callback_program = sy-repid is_layout = lw_layout i_save = 'A' TABLES t_outtab = lt_itab. ENDFORM. FORM fill_fieldcat TABLES ft_fieldcat TYPE STANDARD TABLE USING fu_fieldname fu_fieldtext. DATA: lw_fieldcat TYPE slis_fieldcat_alv. CLEAR lw_fieldcat. lw_fieldcat-fieldname = fu_fieldname. lw_fieldcat-seltext_l = fu_fieldtext. APPEND lw_fieldcat TO ft_fieldcat. ENDFORM. "FILL_FIELDCATZMM050N
标签:matdoc,matnr,fieldcat,when,ZMM050N,lt,TYPE From: https://www.cnblogs.com/sapSB/p/18336536