MM52 历史库存及历史金额查询-LMLPHP

"表:TABLES:MSEG,LFA1,MARA,EKPO,EKKO,MARD,EKBE,EKET.
************************************************************************
* Modification Log
************************************************************************
* Date Ver. Programmer Descriptions
* -------- ---- ------------ -------------------------------------------
* 201 1.0 Original Create
*
************************************************************************

REPORT ZCOR004 NO STANDARD PAGE HEADING
MESSAGE-ID 00 LINE-SIZE 177 LINE-COUNT 200.
***********************************************************************
* Tables Definitions
************************************************************************
*TABLES:.
DATA: layout TYPE slis_layout_alv,
events TYPE slis_t_event.
DATA: wa_structure TYPE lvc_s_fcat,
wa_structure1 TYPE lvc_s_fcat,
wa_structure2 TYPE lvc_s_fcat,
wa_structure3 TYPE lvc_s_fcat,

set_wa_structure TYPE lvc_s_fcat,
set_wa_structure1 TYPE lvc_s_fcat,
set_wa_structure2 TYPE lvc_s_fcat,
set_wa_structure3 TYPE lvc_s_fcat.
* wa_fieldcat TYPE slis_fieldcat_alv.
TABLES:
zmmr01_stok,
zmmr02_stok,
zmmr03_stok,
BICKEY,"特殊库存码说明
T001,"公司代碼
MARC,"物料工廠資料
EBEW,"銷售訂單庫存評價
MKOL,"供應商的特殊庫存
MARD," 物料儲存地點資料
EKPO,
* MARA,
*-----MB5L---
t134m,
SKA1,
marv,
T030R,
T030,
skat,
ACDOCA_M_EXTRACT , " ACDOCA Extract Table for Material Ledger
MATDOC . " Material Documents

************************************************************************
* Data Definitions
************************************************************************
DATA:BEGIN OF GT_MB52_1 OCCURS 0,
LGORT LIKE mardh-LGORT,"存储地点
WERKS LIKE T001W-WERKS," 工厂
MTART LIKE MARA-MTART,"物料类型
MATKL LIKE MARA-MATKL,"物料群组
MATNR LIKE MARA-MATNR ,"料号
MAKTX LIKE MAKT-MAKTX,"物料说明
LGOBE LIKE T001L-LGOBE,"储存位置说明
LGPBE LIKE mard-LGPBE, "储格
LABST LIKE mardh-LABST,"未限制
SALK3 type p decimals 3," mbewh-SALK3,"值未限制
SOBKZ LIKE MKOL-SOBKZ,"特别库存
INSME LIKE mardh-INSME,"品质检验中
EINME LIKE mardh-EINME,"限制使用库存
SALK3_1 LIKE mbewh-SALK3,"值已限制
SPEME LIKE mardh-SPEME,"已冻结
SALK3_2 LIKE mbewh-SALK3,"冻结库存值
RETME LIKE mardh-RETME,"退货
SALK3_3 LIKE mbewh-SALK3,"冻结退货值
DISPO LIKE MARC-DISPO, "MRP控制员
labst_insme like mardh-labst,"未限制 & 品质检验中
SALK3_4 LIKE mbewh-SALK3,"评估GR冻结库存
BWESB LIKE MARC-BWESB,"已评估的收货冻结库存
SSNUM LIKE BICKEY-SSNUM,"特殊库存号码
MEINS LIKE MARA-MEINS,"单位
WAERS LIKE T001-WAERS,"币别
lbkum_e LIKE ebewh-lbkum, " 销售库存
lbkum_m LIKE mbewh-lbkum, " 评估库存
PRICE like ebewh-verpr, " 异动平均价额
stprs LIKE mbewh-stprs, " 标准价格
verpr LIKE ebewh-verpr, " 异动平均价格
peinh LIKE ebewh-peinh, "每
vprsv LIKE ebewh-vprsv, " 价格控制
vbeln LIKE mskah-vbeln, " sd文件
posnr like mskah-posnr, " 项次
kunnr like mskuh-kunnr, " 客户
lifnr like mslbh-lifnr,"供应商
END OF GT_MB52_1.

data:begin of g_mslb1 occurs 0, " 特别库存 O
lgort like mardh-lgort,"存储地点
werks like t001w-werks," 工厂
mtart like mara-mtart,"物料类型
matkl like mara-matkl,"物料群组
matnr like mslbh-matnr ,"料号
maktx like makt-maktx,"物料说明
lgobe like t001l-lgobe,"储存位置说明
lgpbe like mard-lgpbe, "储格
labst like mslbh-lblab,"未限制
salk3 type p decimals 3," mbewh-salk3,"值未限制
sobkz like mkol-sobkz,"特别库存
insme like mardh-insme,"品质检验中
einme like mardh-einme,"限制使用库存
salk3_1 like mbewh-salk3,"值已限制
speme like mardh-speme,"已冻结
salk3_2 like mbewh-salk3,"冻结库存值
retme like mardh-retme,"退货
salk3_3 like mbewh-salk3,"冻结退货值
dispo like marc-dispo, "mrp控制员
labst_insme like mardh-labst,"未限制 & 品质检验中
salk3_4 like mbewh-salk3,"评估gr冻结库存
bwesb like marc-bwesb,"已评估的收货冻结库存
ssnum like bickey-ssnum,"特殊库存号码
meins like mara-meins,"单位
waers like t001-waers,"币别
lbkum_e like ebewh-lbkum, " 销售库存
lbkum_m like mbewh-lbkum, " 评估库存
price like ebewh-verpr, " 异动平均价额
stprs like mbewh-stprs, " 标准价格
verpr LIKE ebewh-verpr, " 异动平均价格
peinh LIKE ebewh-peinh, "每
vprsv LIKE ebewh-vprsv, " 价格控制
vbeln LIKE mskah-vbeln, " sd文件
posnr like mskah-posnr, " 项次
kunnr like mskuh-kunnr, " 客户
lifnr like mslbh-lifnr,"供应商
end of g_mslb1.

data:begin of g_msku1 occurs 0, " 特别库存为 W
lgort like mardh-lgort,"存储地点
werks like t001w-werks," 工厂
mtart like mara-mtart,"物料类型
matkl like mara-matkl,"物料群组
matnr like mara-matnr ,"料号
maktx like makt-maktx,"物料说明
lgobe like t001l-lgobe,"储存位置说明
lgpbe like mard-lgpbe, "储格
labst like mardh-labst,"未限制
salk3 type p decimals 3," mbewh-salk3,"值未限制
sobkz like mkol-sobkz,"特别库存
insme like mardh-insme,"品质检验中
einme like mardh-einme,"限制使用库存
salk3_1 like mbewh-salk3,"值已限制
speme like mardh-speme,"已冻结
salk3_2 like mbewh-salk3,"冻结库存值
retme like mardh-retme,"退货
salk3_3 like mbewh-salk3,"冻结退货值
dispo like marc-dispo, "mrp控制员
labst_insme like mardh-labst,"未限制 & 品质检验中
salk3_4 like mbewh-salk3,"评估gr冻结库存
bwesb like marc-bwesb,"已评估的收货冻结库存
ssnum like bickey-ssnum,"特殊库存号码
meins like mara-meins,"单位
waers like t001-waers,"币别
lbkum_e like ebewh-lbkum, " 销售库存
lbkum_m like mbewh-lbkum, " 评估库存
price like ebewh-verpr, " 异动平均价额
stprs like mbewh-stprs, " 标准价格
verpr like ebewh-verpr, " 异动平均价格
peinh like ebewh-peinh, "每
vprsv like ebewh-vprsv, " 价格控制
kunnr like mskuh-kunnr, " 客户号码
end of g_msku1.

data:begin of g_ebew1 occurs 0, " 特别库存为 e
lgort like mardh-lgort,"存储地点
werks like t001w-werks," 工厂
mtart like mara-mtart,"物料类型
matkl like mara-matkl,"物料群组
matnr like mara-matnr ,"料号
maktx like makt-maktx,"物料说明
lgobe like t001l-lgobe,"储存位置说明
lgpbe like mard-lgpbe, "储格
labst like mardh-labst,"未限制
salk3 type p decimals 3,"mbewh-salk3,"值未限制
sobkz like mkol-sobkz,"特别库存
insme like mardh-insme,"品质检验中
einme like mardh-einme,"限制使用库存
salk3_1 like mbewh-salk3,"值已限制
speme like mardh-speme,"已冻结
salk3_2 like mbewh-salk3,"冻结库存值
retme like mardh-retme,"退货
salk3_3 like mbewh-salk3,"冻结退货值
dispo like marc-dispo, "mrp控制员
labst_insme like mardh-labst,"未限制 & 品质检验中
salk3_4 like mbewh-salk3,"评估gr冻结库存
bwesb like marc-bwesb,"已评估的收货冻结库存
ssnum like bickey-ssnum,"特殊库存号码
meins like mara-meins,"单位
waers like t001-waers,"币别
lbkum_e like ebewh-lbkum, " 销售库存
lbkum_m like mbewh-lbkum, " 评估库存
price like ebewh-verpr, " 异动平均价额
stprs like mbewh-stprs, " 标准价格
verpr like ebewh-verpr, " 异动平均价格
peinh like ebewh-peinh, "每
vprsv like ebewh-vprsv, " 价格控制
vbeln like mskah-vbeln, " sd文件
posnr like mskah-posnr, " 项次
lifnr like mslbh-lifnr,"供应商
end of g_ebew1.

data:begin of g_mslb2 occurs 0, " 特别库存 O
lgort2(8),"存储地点 ii
text(40) type c, "呆滞期
werks like t001w-werks," 工厂
mtart like mara-mtart,"物料类型
matkl like mara-matkl,"物料群组
matnr like mara-matnr ,"料号
maktx like makt-maktx,"物料说明
lgort like mardh-lgort,"存储地点
lgobe like t001l-lgobe,"储存位置说明
lgpbe like mard-lgpbe, "储格
salk3 like mbewh-salk3,"值未限制
sobkz like mkol-sobkz,"特别库存
einme like mardh-einme,"限制使用库存
salk3_1 like mbewh-salk3,"值已限制
speme like mardh-speme,"已冻结
salk3_2 like mbewh-salk3,"冻结库存值
retme like mardh-retme,"退货
salk3_3 like mbewh-salk3,"冻结退货值
salk3_4 like mbewh-salk3,"评估gr冻结库存
bwesb like marc-bwesb,"已评估的收货冻结库存
ssnum like bickey-ssnum,"特殊库存号码
LVORM LIKE mard-lvorm," sloc level DF存储位置等级
meins like mara-meins,"单位
waers like t001-waers,"币别
labst like mardh-labst,"未限制
insme like mardh-insme,"品质检验中
dispo like marc-dispo, "mrp控制员
labst_insme like mardh-labst,"未限制 & 品质检验中
price type p decimals 5, "单价
hsl type p LENGTH 16 decimals 5, " 金额
*text(40) type c, "呆滞期
price1 like ebewh-verpr, " 异动平均价额
stprs like mbewh-stprs, " 标准价格
verpr like ebewh-verpr, " 异动平均价格
peinh like ebewh-peinh, "每
vprsv like ebewh-vprsv, " 价格控制
vbeln like mskah-vbeln, " sd文件
posnr like mskah-posnr, " 项次
lifnr like mslbh-lifnr,"供应商
end of g_mslb2.

data:begin of g_msku2 occurs 0, " 特别库存为 W
lgort2(8),"存储地点 ii
text(40) type c, "呆滞期
werks like t001w-werks," 工厂
mtart like mara-mtart,"物料类型
matkl like mara-matkl,"物料群组
matnr like mara-matnr ,"料号
maktx like makt-maktx,"物料说明
lgort like mardh-lgort,"存储地点
lgobe like t001l-lgobe,"储存位置说明
lgpbe like mard-lgpbe, "储格
salk3 like mbewh-salk3,"值未限制
sobkz like mkol-sobkz,"特别库存
einme like mardh-einme,"限制使用库存
salk3_1 like mbewh-salk3,"值已限制
speme like mardh-speme,"已冻结
salk3_2 like mbewh-salk3,"冻结库存值
retme like mardh-retme,"退货
salk3_3 like mbewh-salk3,"冻结退货值
salk3_4 like mbewh-salk3,"评估gr冻结库存
bwesb like marc-bwesb,"已评估的收货冻结库存
ssnum like bickey-ssnum,"特殊库存号码
LVORM LIKE mard-lvorm," sloc level DF存储位置等级
meins like mara-meins,"单位
waers like t001-waers,"币别
labst like mardh-labst,"未限制
insme like mardh-insme,"品质检验中
dispo like marc-dispo, "mrp控制员
labst_insme like mardh-labst,"未限制 & 品质检验中
price type p decimals 5, "单价
hsl type p LENGTH 16 decimals 5, " 金额
*text(40) type c, "呆滞期
price1 like ebewh-verpr, " 异动平均价额
stprs like mbewh-stprs, " 标准价格
verpr like ebewh-verpr, " 异动平均价格
peinh like ebewh-peinh, "每
vprsv like ebewh-vprsv, " 价格控制
vbeln like mskah-vbeln, " sd文件
posnr like mskah-posnr, " 项次
kunnr like mskuh-kunnr, " 客户
end of g_msku2.

data:begin of g_ebew2 occurs 0, " 特别库存为 e
lgort2(8),"存储地点 ii
text(40) type c, "呆滞期
werks like t001w-werks," 工厂
mtart like mara-mtart,"物料类型
matkl like mara-matkl,"物料群组
matnr like mara-matnr ,"料号
maktx like makt-maktx,"物料说明
lgort like mardh-lgort,"存储地点
lgobe like t001l-lgobe,"储存位置说明
lgpbe like mard-lgpbe, "储格
salk3 like mbewh-salk3,"值未限制
sobkz like mkol-sobkz,"特别库存
einme like mardh-einme,"限制使用库存
salk3_1 like mbewh-salk3,"值已限制
speme like mardh-speme,"已冻结
salk3_2 like mbewh-salk3,"冻结库存值
retme like mardh-retme,"退货
salk3_3 like mbewh-salk3,"冻结退货值
salk3_4 like mbewh-salk3,"评估gr冻结库存
bwesb like marc-bwesb,"已评估的收货冻结库存
ssnum like bickey-ssnum,"特殊库存号码
LVORM LIKE mard-lvorm," sloc level DF存储位置等级
meins like mara-meins,"单位
waers like t001-waers,"币别
labst like mardh-labst,"未限制
insme like mardh-insme,"品质检验中
dispo like marc-dispo, "mrp控制员
labst_insme like mardh-labst,"未限制 & 品质检验中
price type p decimals 5, "单价
hsl type p LENGTH 16 decimals 5, " 金额
price1 like ebewh-verpr, " 异动平均价额
stprs like mbewh-stprs, " 标准价格
verpr like ebewh-verpr, " 异动平均价格
peinh like ebewh-peinh, "每
vprsv like ebewh-vprsv, " 价格控制
vbeln like mskah-vbeln, " sd文件
posnr like mskah-posnr, " 项次
end of g_ebew2.

DATA: factor TYPE f .

DATA:BEGIN OF g_mslb3 occurs 0, " O 特别库存
ZWHCODE LIKE MARA-ZWHCODE,"WH CODE
WERKS LIKE T001W-WERKS," 工厂
MTART LIKE MARA-MTART,"物料类型
MATKL LIKE MARA-MATKL,"物料群组
MATNR LIKE MARA-MATNR ,"料号
MB_ZWHCODE LIKE MARA-ZWHCODE," MBS 库存
S_ZWHCODE LIKE MARA-ZWHCODE," WH CODE & MBS 库存
MAKTX LIKE MAKT-MAKTX,"物料说明
LGORT LIKE mardh-LGORT,"存储地点
LGOBE LIKE T001L-LGOBE,"储存位置说明
LGPBE LIKE mard-LGPBE, "储格
LABST LIKE mardh-LABST,"未限制
SALK3 TYPE p DECIMALS 4,"值未限制
SOBKZ LIKE MKOL-SOBKZ,"特别库存
INSME LIKE mardh-INSME,"品质检验中
EINME LIKE mardh-EINME,"限制使用库存
SALK3_1 LIKE mbewh-SALK3,"值已限制
SPEME LIKE mardh-SPEME,"已冻结
SALK3_2 LIKE mbewh-SALK3,"冻结库存值
RETME LIKE mardh-RETME,"退货
SALK3_3 LIKE mbewh-SALK3,"冻结退货值
DISPO LIKE MARC-DISPO, "MRP控制员
SALK3_4 LIKE mbewh-SALK3,"评估GR冻结库存
BWESB LIKE MARC-BWESB,"已评估的收货冻结库存
SSNUM LIKE BICKEY-SSNUM,"特殊库存号码
MEINS LIKE MARA-MEINS,"单位
WAERS LIKE T001-WAERS,"币别
PRICE like ebewh-verpr, " 异动平均价额
stprs LIKE mbewh-stprs, " 标准价格
verpr LIKE ebewh-verpr, " 异动平均价格
peinh LIKE ebewh-peinh, "每
vprsv LIKE ebewh-vprsv, " 价格控制
lifnr LIKE mslbh-lifnr,"供应商
END OF g_mslb3.

DATA:BEGIN OF g_msku3 occurs 0, " 特别库存为 O
ZWHCODE LIKE MARA-ZWHCODE,"WH CODE
WERKS LIKE T001W-WERKS," 工厂
MTART LIKE MARA-MTART,"物料类型
MATKL LIKE MARA-MATKL,"物料群组
MATNR LIKE MARA-MATNR ,"料号
MB_ZWHCODE LIKE MARA-ZWHCODE," MBS 库存
S_ZWHCODE LIKE MARA-ZWHCODE," WH CODE & MBS 库存
MAKTX LIKE MAKT-MAKTX,"物料说明
LGORT LIKE mardh-LGORT,"存储地点
LGOBE LIKE T001L-LGOBE,"储存位置说明
LGPBE LIKE mard-LGPBE, "储格
LABST LIKE mardh-LABST,"未限制
SALK3 TYPE p DECIMALS 4,"值未限制
SOBKZ LIKE MKOL-SOBKZ,"特别库存
INSME LIKE mardh-INSME,"品质检验中
EINME LIKE mardh-EINME,"限制使用库存
SALK3_1 LIKE mbewh-SALK3,"值已限制
SPEME LIKE mardh-SPEME,"已冻结
SALK3_2 LIKE mbewh-SALK3,"冻结库存值
RETME LIKE mardh-RETME,"退货
SALK3_3 LIKE mbewh-SALK3,"冻结退货值
DISPO LIKE MARC-DISPO, "MRP控制员
SALK3_4 LIKE mbewh-SALK3,"评估GR冻结库存
BWESB LIKE MARC-BWESB,"已评估的收货冻结库存
SSNUM LIKE BICKEY-SSNUM,"特殊库存号码
MEINS LIKE MARA-MEINS,"单位
WAERS LIKE T001-WAERS,"币别
PRICE like ebewh-verpr, " 异动平均价额
stprs LIKE mbewh-stprs, " 标准价格
verpr LIKE ebewh-verpr, " 异动平均价格
peinh LIKE ebewh-peinh, "每
vprsv LIKE ebewh-vprsv, " 价格控制
kunnr LIKE mskuh-kunnr, " 客户

END OF g_msku3.

DATA:BEGIN OF g_ebew3 occurs 0, " 特别库存为 E
ZWHCODE LIKE MARA-ZWHCODE,"WH CODE
WERKS LIKE T001W-WERKS," 工厂
MTART LIKE MARA-MTART,"物料类型
MATKL LIKE MARA-MATKL,"物料群组
MATNR LIKE MARA-MATNR ,"料号
MB_ZWHCODE LIKE MARA-ZWHCODE," MBS 库存
S_ZWHCODE LIKE MARA-ZWHCODE," WH CODE & MBS 库存
MAKTX LIKE MAKT-MAKTX,"物料说明
LGORT LIKE mardh-LGORT,"存储地点
LGOBE LIKE T001L-LGOBE,"储存位置说明
LGPBE LIKE mard-LGPBE, "储格
LABST LIKE mardh-LABST,"未限制
SALK3 TYPE p DECIMALS 4,"值未限制
SOBKZ LIKE MKOL-SOBKZ,"特别库存
INSME LIKE mardh-INSME,"品质检验中
EINME LIKE mardh-EINME,"限制使用库存
SALK3_1 LIKE mbewh-SALK3,"值已限制
SPEME LIKE mardh-SPEME,"已冻结
SALK3_2 LIKE mbewh-SALK3,"冻结库存值
RETME LIKE mardh-RETME,"退货
SALK3_3 LIKE mbewh-SALK3,"冻结退货值
DISPO LIKE MARC-DISPO, "MRP控制员
SALK3_4 LIKE mbewh-SALK3,"评估GR冻结库存
BWESB LIKE MARC-BWESB,"已评估的收货冻结库存
SSNUM LIKE BICKEY-SSNUM,"特殊库存号码
MEINS LIKE MARA-MEINS,"单位
WAERS LIKE T001-WAERS,"币别
PRICE like ebewh-verpr, " 异动平均价额
stprs LIKE mbewh-stprs, " 标准价格
verpr LIKE ebewh-verpr, " 异动平均价格
peinh LIKE ebewh-peinh, "每
vprsv LIKE ebewh-vprsv, " 价格控制
vbeln LIKE mskah-vbeln, " sd文件
posnr like mskah-posnr, " 项次
END OF g_ebew3.

DATA:l_lbkum LIKE mbewh-lbkum,
l_verpr LIKE mbewh-verpr,
l_salk3 LIKE mbewh-salk3,
l_peinh LIKE mbewh-peinh.

DATA:l_existed TYPE i, " 已存在前期值
l_existed1 TYPE i," 已存在前期值
l_existed2 TYPE i," 已存在前期值
l_existed3 TYPE i, " 已存在前期值
l_existed_turr TYPE i. " 已存在前期值

*定义变量参数用于下载路径和文件名
DATA: L_PATH TYPE STRING.

DATA:BEGIN OF GT_MB52_2 OCCURS 0,
LGORT2(8),"存储地点 II
text(40) TYPE c, "呆滞期
WERKS LIKE T001W-WERKS," 工厂
MTART LIKE MARA-MTART,"物料类型
MATKL LIKE MARA-MATKL,"物料群组
MATNR LIKE MARA-MATNR ,"料号
MAKTX LIKE MAKT-MAKTX,"物料说明
LGORT LIKE mardh-LGORT,"存储地点
LGOBE LIKE T001L-LGOBE,"储存位置说明
LGPBE LIKE mard-LGPBE, "储格
SALK3 LIKE mbewh-SALK3,"值未限制
SOBKZ LIKE MKOL-SOBKZ,"特别库存
EINME LIKE mardh-EINME,"限制使用库存
SALK3_1 LIKE mbewh-SALK3,"值已限制
SPEME LIKE mardh-SPEME,"已冻结
SALK3_2 LIKE mbewh-SALK3,"冻结库存值
RETME LIKE mardh-RETME,"退货
SALK3_3 LIKE mbewh-SALK3,"冻结退货值
SALK3_4 LIKE mbewh-SALK3,"评估GR冻结库存
BWESB LIKE MARC-BWESB,"已评估的收货冻结库存
SSNUM LIKE BICKEY-SSNUM,"特殊库存号码
LVORM LIKE mard-lvorm," sloc level DF存储位置等级
MEINS LIKE MARA-MEINS,"单位
WAERS LIKE T001-WAERS,"币别
LABST LIKE mardh-LABST,"未限制
INSME LIKE mardh-INSME,"品质检验中
DISPO LIKE MARC-DISPO, "MRP控制员
LABST_INSME LIKE mardh-LABST,"未限制 & 品质检验中
price type p decimals 5, "单价
hsl type p LENGTH 16 decimals 5, " 金额
*text(40) TYPE c, "呆滞期
PRICE1 like ebewh-verpr, " 异动平均价额
stprs LIKE mbewh-stprs, " 标准价格
verpr LIKE ebewh-verpr, " 异动平均价格
peinh LIKE ebewh-peinh, "每
vprsv LIKE ebewh-vprsv, " 价格控制
vbeln LIKE mskah-vbeln, " sd文件
posnr like mskah-posnr, " 项次
kunnr like mskuh-kunnr, " 客户
lifnr like mslbh-lifnr,"供应商
END OF GT_MB52_2.

DATA:BEGIN OF gt_t001l occurs 0,
LGORT2 LIKE zmmr02_stok-LGORT2,"存储地点 II
END OF gt_t001l.

DATA:BEGIN OF GT_MB52_3 OCCURS 0,
ZWHCODE LIKE MARA-ZWHCODE,"WH CODE
WERKS LIKE T001W-WERKS," 工厂
MTART LIKE MARA-MTART,"物料类型
MATKL LIKE MARA-MATKL,"物料群组
MATNR LIKE MARA-MATNR ,"料号
MB_ZWHCODE LIKE MARA-ZWHCODE," MBS 库存
S_ZWHCODE LIKE MARA-ZWHCODE," WH CODE & MBS 库存
MAKTX LIKE MAKT-MAKTX,"物料说明
LGORT LIKE mardh-LGORT,"存储地点
LGOBE LIKE T001L-LGOBE,"储存位置说明
LGPBE LIKE mard-LGPBE, "储格
LABST LIKE mardh-LABST,"未限制
SALK3 TYPE p DECIMALS 4,"值未限制
SOBKZ LIKE MKOL-SOBKZ,"特别库存
INSME LIKE mardh-INSME,"品质检验中
EINME LIKE mardh-EINME,"限制使用库存
SALK3_1 LIKE mbewh-SALK3,"值已限制
SPEME LIKE mardh-SPEME,"已冻结
SALK3_2 LIKE mbewh-SALK3,"冻结库存值
RETME LIKE mardh-RETME,"退货
SALK3_3 LIKE mbewh-SALK3,"冻结退货值
DISPO LIKE MARC-DISPO, "MRP控制员
SALK3_4 LIKE mbewh-SALK3,"评估GR冻结库存
BWESB LIKE MARC-BWESB,"已评估的收货冻结库存
SSNUM LIKE BICKEY-SSNUM,"特殊库存号码
MEINS LIKE MARA-MEINS,"单位
WAERS LIKE T001-WAERS,"币别
PRICE like ebewh-verpr, " 异动平均价额
stprs LIKE mbewh-stprs, " 标准价格
verpr LIKE ebewh-verpr, " 异动平均价格
peinh LIKE ebewh-peinh, "每
vprsv LIKE ebewh-vprsv, " 价格控制
vbeln LIKE mskah-vbeln, " sd文件
posnr like mskah-posnr, " 项次
kunnr like mskuh-kunnr, " 客户
lifnr like mslbh-lifnr,"供应商
labst_insme LIKE mardh-labst,
END OF GT_MB52_3.

DATA: BEGIN OF gt_period OCCURS 0,
seqno(2) TYPE n,
datum LIKE sy-datum,
sdate LIKE sy-datum,
tdate LIKE sy-datum,
ptext(20) TYPE c,
END OF gt_period.

DATA:gt_period1 LIKE gt_period occurs 0 WITH HEADER LINE,
gt_period2 LIKE gt_period occurs 0 WITH HEADER LINE,
gt_period3 LIKE gt_period occurs 0 WITH HEADER LINE.

DATA: BEGIN OF set_mb52_2 OCCURS 0,
lgort2 LIKE zmmr02_stok-LGORT2, " 储存地点 II
lgobe2 LIKE T001L-LGOBE," 存储地说明
sum3 TYPE P DECIMALS 2, " 0-3个月
sum04_06 TYPE P DECIMALS 2, " 4-6个月
sum07_12 TYPE P DECIMALS 2, " 7-12 个月
sum12_24 TYPE P DECIMALS 2, " 1-2 年
sum24 TYPE P DECIMALS 2, " 24 个月
sum TYPE P DECIMALS 2, " 总计
END OF set_mb52_2.
"呆滞期金额汇总

*----动态alv说明
DATA: BEGIN OF GT_DTYPE OCCURS 0,
dtype(2) TYPE C ,
dtext(20) TYPE C,
END OF GT_DTYPE.

DATA:BEGIN OF SUM_300 OCCURS 0,
ZWHCODE LIKE MARA-ZWHCODE,"WH CODE
SALK3 LIKE MBEW-SALK3,"值未限制
REMARKS(30) type C,"WH CODE 备注
END OF SUM_300.

DATA:BEGIN OF SUM_100 OCCURS 0,
LGORT LIKE MARD-LGORT,"存储地点
LGOBE LIKE T001L-LGOBE,"储存位置说明
SALK3 LIKE MBEW-SALK3,"值未限制
END OF SUM_100.

DATA:BEGIN OF sum_200 OCCURS 0,
LGORT2(8),"存储地点
LGOBE2 LIKE T001L-LGOBE,"储存位置说明
SALK3 type p decimals 2, "LIKE MBEW-SALK3,"值未限制
END OF sum_200.

DATA: sum_200_1 LIKE sum_200 occurs 0 WITH HEADER LINE,
sum_100_1 LIKE sum_100 occurs 0 WITH HEADER LINE,
sum_300_1 LIKE sum_300 occurs 0 WITH HEADER LINE.

DATA:L2_KUNNR LIKE MSKU-KUNNR, " 供应商
L2_LIFNR LIKE MSLB-LIFNR, " 客户编号
L2_VBELN LIKE MSKA-VBELN , "采购单号
L2_POSNR LIKE MSKA-POSNR, "采购单项次
L1_KUNNR LIKE MSKU-KUNNR," 供应商
L1_LIFNR LIKE MSLB-LIFNR, " 客户编号
L1_VBELN LIKE MSKA-VBELN , "采购单号
L1_POSNR LIKE MSKA-POSNR,"采购单项次
L3_KUNNR LIKE MSKU-KUNNR," 供应商
L3_LIFNR LIKE MSLB-LIFNR, " 客户编号
L3_VBELN LIKE MSKA-VBELN , "采购单号
L3_POSNR LIKE MSKA-POSNR."采购单项次

DATA:L2_INDEX1 TYPE SY-TABIX,
L1_INDEX1 TYPE SY-TABIX,
L3_INDEX1 TYPE SY-TABIX.
DATA: g_sdate LIKE sy-datum.

DATA: colname(10),
index(2).

DATA: wa_fcat TYPE lvc_s_fcat,
wa_fcat1 TYPE lvc_s_fcat,
wa_fcat2 TYPE lvc_s_fcat,
wa_fcat3 TYPE lvc_s_fcat,

set_wa_fcat TYPE lvc_s_fcat,
set_wa_fcat1 TYPE lvc_s_fcat,
set_wa_fcat2 TYPE lvc_s_fcat,
set_wa_fcat3 TYPE lvc_s_fcat.
DATA: ne_col1 LIKE ALSMEX_TABLINE-col VALUE 1,
ne_col2 LIKE ALSMEX_TABLINE-col VALUE 2.

DATA: BEGIN OF upload1 OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE.
DATA:END OF upload1.

DATA: BEGIN OF upload2 OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE.
DATA:END OF upload2.

DATA: BEGIN OF upload3 OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE.
DATA:END OF upload3.

DATA: BEGIN OF upload4 OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE.
DATA:END OF upload4.
DATA: G_FIYEAR4(4) TYPE N. "年
DATA: G_FIYEAR3(3) TYPE N. "月
DATA: G_FIYEAR(7) TYPE N. "前三月
DATA: DATE TYPE D. "当月第一天
DATA: GET_DATE TYPE D. "当月最后一天
DATA: N1(4) TYPE N. "获取前三月年
DATA: N2(2) TYPE N. "前三月
DATA: DATE1 TYPE D. " 三月第一天
DATA: GET_DATE1 TYPE D. "前三月最后一天
DATA: G_MBLNR(3) TYPE C. "单据单头 20181008 LZW ADD
DATA: G_MBLNR1(3) TYPE C. "单据单头 20181008 LZW ADD

DATA: G_HIGH TYPE SY-DATUM. " 最后一天
DATA: G_LOW TYPE SY-DATUM. " 第一天
DATA: L_N(7) TYPE P . " 天数
DATA: L_N_ALL(7) TYPE P . " 当月总天数

DATA: L_MONTH1(7) TYPE P . " 月数
DATA: L_MONTH2(7) TYPE P . " 月数

DATA: E_DAYS LIKE VTBBEWE-ATAGE . " 天数
DATA: E_MONTHS LIKE VTBBEWE-ATAGE . " 月数
DATA: E_YEARS LIKE VTBBEWE-ATAGE . " 年数
DATA: DEAD_MONTH1 TYPE P DECIMALS 2 . " 呆滯期(月)

DATA:BEGIN OF GT_DATA OCCURS 0,
MATNR LIKE MARA-MATNR,
GT_DMBTR LIKE BSEG-DMBTR, "本国货币金额
H_BUDAT LIKE BSEG-H_BUDAT, " 过账日期
END OF GT_DATA.

*----ZCOR002------

*ALV自定义按钮
CONSTANTS ALV_PF_STATUS TYPE SLIS_FORMNAME VALUE 'ALV_PF_STATUS'.
*ALV自定义按钮事件
CONSTANTS ALV_USER_COMMAND TYPE SLIS_FORMNAME
VALUE 'ALV_USER_COMMAND'.

"FOR ALV报表
TYPE-POOLS SLIS.
DATA: GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
GT_FIELDCATS TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
GS_LAYOUT1 TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
WA_FIELDCAT1 TYPE SLIS_FIELDCAT_ALV,
GS_LAYOUT2 TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
WA_FIELDCAT2 TYPE SLIS_FIELDCAT_ALV,
GS_LAYOUT3 TYPE SLIS_LAYOUT_ALV,
GT_FIELDCAT3 TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
WA_FIELDCAT3 TYPE SLIS_FIELDCAT_ALV,

set_wa_FIELDCAT1 TYPE SLIS_FIELDCAT_ALV,
set_wa_FIELDCAT2 TYPE SLIS_FIELDCAT_ALV,
set_wa_FIELDCAT3 TYPE SLIS_FIELDCAT_ALV,
set_wa_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
set_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
set_FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
set_FIELDCAT2 TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
set_FIELDCAT3 TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.

DATA: L_number LIKE sy-tabix.
DATA: LASTDAY TYPE SY-DATUM,
date4 TYPE sy-datum,
date4_day TYPE sy-datum, " 下限日期的第一天
date4_s TYPE sy-datum. "上线日期日期第一天

*-----> 判断选择屏明细日期后是否需要下载
DATA: Have_data TYPE c,
p_return TYPE i. " 下载变量

DATA: MANDT TYPE SY-MANDT. " 用户端

DATA: date3 TYPE vtbbewe-dvalut. " 上个月最后一天
DATA: date3_1 TYPE vtbbewe-dvalut. " 上 5个月最后一天

DATA:P_WERKS1 LIKE T001W-WERKS VALUE '100',
P_WERKS2 LIKE T001W-WERKS VALUE '200',
P_WERKS3 LIKE T001W-WERKS VALUE '300'.
* flag TYPE trff_flg,
* days TYPE trff_type_n_2.
FIELD-SYMBOLS:<gt_table> TYPE STANDARD TABLE,
<g_wa>,
<g_comp>,
<g_field>.

FIELD-SYMBOLS:<gt_table1> TYPE STANDARD TABLE,
<g_wa1>,
<g_comp1>,
<g_field1>.

FIELD-SYMBOLS:<gt_table2> TYPE STANDARD TABLE,
<g_wa2>,
<g_comp2>,
<g_field2>.

FIELD-SYMBOLS:<gt_table3> TYPE STANDARD TABLE,
<g_wa3>,
<g_comp3>,
<g_field3>.

DATA: gt_table TYPE REF TO data,
gt_structure TYPE lvc_t_fcat,
gt_table1 TYPE REF TO data,
gt_structure1 TYPE lvc_t_fcat,
gt_table2 TYPE REF TO data,
gt_structure2 TYPE lvc_t_fcat,
gt_table3 TYPE REF TO data,
gt_structure3 TYPE lvc_t_fcat,

create_table TYPE REF TO data,
set_structure TYPE lvc_t_fcat,
create_table1 TYPE REF TO data,
set_structure1 TYPE lvc_t_fcat,
create_table2 TYPE REF TO data,
set_structure2 TYPE lvc_t_fcat,
create_table3 TYPE REF TO data,
set_structure3 TYPE lvc_t_fcat.

*DATA: down_table1 LIKE <create_table1> occurs 0 WITH HEADER LINE.
* down_table2 LIKE <create_table1> occurs 0 WITH HEADER LINE,
* down_table3 LIKE <create_table1> occurs 0 WITH HEADER LINE,
* down_table LIKE <create_table1> occurs 0 WITH HEADER LINE.

" 下载资料明细
"MB52_100 明细
DATA: BEGIN OF down_mb52_1 OCCURS 0,
C1(100) TYPE C,
C2(100) TYPE C,
C3(100) TYPE C,
C4(100) TYPE C,
C5(100) TYPE C,
C6(100) TYPE C,
C7(100) TYPE C,
C8(100) TYPE C,
C9(100) TYPE C,
C10(100) TYPE C,
C11(100) TYPE C,
C12(100) TYPE C,
C13(100) TYPE C,
C14(100) TYPE C,
C15(100) TYPE C,
C16(100) TYPE C,
C17(100) TYPE C,
C18(100) TYPE C,
C19(100) TYPE C,
C20(100) TYPE C,
C21(100) TYPE C,
C22(100) TYPE C,
C23(100) TYPE C,
C24(100) TYPE C,
C25(100) TYPE C,
C26(100) TYPE C,
C27(100) TYPE C,
C28(100) TYPE C,
C29(100) TYPE C,
C30(100) TYPE C,
C31(100) TYPE C,
C32(100) TYPE C,
C33(100) TYPE C,
C34(100) TYPE C,

END OF down_mb52_1.

DATA: down_mb52_2 LIKE down_mb52_1 occurs 0 WITH HEADER LINE,
*DATA: down_mb52_2 LIKE down_mb52_1 occurs 0 WITH HEADER LINE, " MB52_200 明细
down_mb52_3 LIKE down_mb52_1 occurs 0 WITH HEADER LINE. " MB52_300 明细

" 下载变量
DATA: L_FINIT TYPE STRING, " default file path
L_FPATH TYPE STRING, " file path
P_FPATH2 TYPE STRING, " file path
L_LEN TYPE I. " file path length

" 汇总 邮件变量
DATA: g_string_1 TYPE string,
g_string_2 TYPE string,
g_string_3 TYPE string,
g_string_4 TYPE string,
g_mail_address TYPE ad_smtpadr.

DATA: g_datel_1 TYPE string,
g_datel_2 TYPE string,
g_datel_3 TYPE string,
g_datel_4 TYPE string.

CONSTANTS: gc_tab TYPE c VALUE cl_bcs_convert=>gc_tab,
gc_crlf TYPE c VALUE cl_bcs_convert=>gc_crlf.

*数据往期数据 table
DATA: BEGIN OF gt_tcurr occurs 0 ,
kurst LIKE tcurr-kurst,"汇率类型
fcurr LIKE tcurr-fcurr," 来源货币
tcurr LIKE tcurr-tcurr,"目标货币
gdatu LIKE tcurr-gdatu,"生效日期
ukurs LIKE tcurr-ukurs,"汇率
ffact LIKE tcurr-ffact,"比率来源
tfact LIKE tcurr-tfact,"比率目标
END OF gt_tcurr.

"获取往期库存值
DATA:BEGIN OF gt_zmmr01_stok occurs 0,
LGORT2 LIKE zmmr01_stok-LGORT2,
WERKS LIKE zmmr01_stok-WERKS,
ZNUM LIKE zmmr01_stok-ZNUM,
DATUM LIKE zmmr01_stok-DATUM,
LIFAB LIKE zmmr01_stok-LIFAB,
shkzg LIKE zmmr01_stok-shkzg,
SALK3 LIKE zmmr01_stok-SALK3,
TEXT LIKE zmmr01_stok-TEXT,
END OF gt_zmmr01_stok.

DATA:BEGIN OF gt_zmmr02_stok occurs 0,
LGORT2 LIKE zmmr02_stok-LGORT2,
WERKS LIKE zmmr02_stok-WERKS,
ZNUM LIKE zmmr02_stok-ZNUM,
DATUM LIKE zmmr02_stok-DATUM,
LIFAB LIKE zmmr02_stok-LIFAB,
shkzg LIKE zmmr02_stok-shkzg,
SALK3 LIKE zmmr02_stok-SALK3,
TEXT LIKE zmmr02_stok-TEXT,
END OF gt_zmmr02_stok.

DATA:BEGIN OF gt_zmmr02_year occurs 0, " 年度标准成本
znum LIKE zmmr02_year-znum,
werks LIKE zmmr02_year-werks,
datum LIKE zmmr02_year-datum,
lifab LIKE zmmr02_year-lifab,
lfgja LIKE zmmr02_year-lfgja,
shkzg LIKE zmmr02_year-shkzg,
annual LIKE zmmr02_year-annual,
taxt LIKE zmmr02_year-text,
END OF gt_zmmr02_year.

DATA:BEGIN OF gt_zmmr03_stok occurs 0,
ZWHCODE LIKE zmmr03_stok-ZWHCODE,
WERKS LIKE zmmr03_stok-WERKS,
ZNUM LIKE zmmr03_stok-ZNUM,
DATUM LIKE zmmr03_stok-DATUM,
LIFAB LIKE zmmr03_stok-LIFAB,
shkzg LIKE zmmr03_stok-shkzg,
SALK3 LIKE zmmr03_stok-SALK3,
TEXT LIKE zmmr03_stok-TEXT,
END OF gt_zmmr03_stok.

DATA:BEGIN OF gt_zmmr00_example occurs 0,
ZNUM LIKE zmmr00_example-ZNUM,
LGORT LIKE zmmr00_example-LGORT,
* WERKS LIKE zmmr00_example-WERKS,
DATUM LIKE zmmr00_example-DATUM,
LIFAB LIKE zmmr00_example-LIFAB,
shkzg LIKE zmmr00_example-shkzg,
SALK3 LIKE zmmr00_example-SALK3,
text LIKE zmmr00_example-text,
END OF gt_zmmr00_example.

DATA:BEGIN OF gt_zmmr00_aims occurs 0,
znum LIKE zmmr00_aims-znum,
datum LIKE zmmr00_aims-datum,
lifab LIKE zmmr00_aims-lifab,
lfgja LIKE zmmr00_aims-lfgja,
shkzg_y LIKE zmmr00_aims-shkzg_y,
turnover LIKE zmmr00_aims-turnover,
shkzg_m LIKE zmmr00_aims-shkzg_m,
zaims LIKE zmmr00_aims-zaims,
text LIKE zmmr00_aims-text,
END OF gt_zmmr00_aims.

" 前期汇率
DATA:BEGIN OF gt_zmmr00_turr occurs 0,
znum LIKE zmmr00_turr-znum,
datum LIKE zmmr00_turr-datum,
lifab LIKE zmmr00_turr-lifab,
cny_twd LIKE zmmr00_turr-cny_twd,
usd_twd LIKE zmmr00_turr-usd_twd,
cny_twd1 LIKE zmmr00_turr-cny_twd1,
usd_twd1 LIKE zmmr00_turr-usd_twd1,
text LIKE zmmr00_aims-text,
END OF gt_zmmr00_turr.

*数据往期数据 table end

*写入table
DATA: write_zmmr01_stok LIKE zmmr01_stok occurs 0 WITH HEADER LINE," 100前期值
write_zmmr02_stok LIKE zmmr02_stok occurs 0 WITH HEADER LINE," 200前期值
write_zmmr03_stok LIKE zmmr03_stok occurs 0 WITH HEADER LINE," 300前期值
write_zmmr00_turr LIKE zmmr00_turr occurs 0 WITH HEADER LINE,"前期汇率
* write_zmmr00_aims LIKE zmmr00_aims occurs 0 WITH HEADER LINE, " 公司年度目标
write_zmmr00_example LIKE zmmr00_example occurs 0 WITH HEADER LINE. " 库存范例

DATA:id_1 TYPE i VALUE '0',"1000 ID
id_2 TYPE i VALUE '0',"2000 ID
id_0_2 TYPE i VALUE '0', "年度标本 ID
id_3 TYPE i VALUE '0', " 300 ID
id_00_1 TYPE i VALUE '0', " 年度目标 ID
id_00_2 TYPE i VALUE '0'," 范例 ID
max_01_date LIKE sy-datum, " maxdate
max_02_date LIKE sy-datum," maxdate
max_02y_date LIKE zmmr02_year-lfgja," maxyear
max_03_date LIKE sy-datum," maxdate
max_00a_date LIKE zmmr00_aims-lfgja," maxyear
max_00e_date LIKE sy-datum." maxdate

"获取周期数
DATA: BEGIN OF gt_num occurs 0 ,
lifab LIKE sy-datum,
l_num TYPE i,
END OF gt_num.

DATA: gt_num1 LIKE gt_num occurs 0 WITH HEADER LINE,
gt_num2 LIKE gt_num occurs 0 WITH HEADER LINE,
gt_num3 LIKE gt_num occurs 0 WITH HEADER LINE,
gt_num4 LIKE gt_num occurs 0 WITH HEADER LINE." 汇率
DATA: l_sdate TYPE sy-datum, " max tate
l_endate TYPE sy-datum, " min tate
lv_date type i. " 接收变量

DATA:lv_num type i ,
lv_num1 type i,
lv_num2 type i,
lv_num3 type i.
"2000
DATA:g_sum_new like acdoca_m_extract-hsl VALUE '0', " 按库别新值汇总
g_sum_sum TYPE p DECIMALS 2 VALUE '0'," sum 按库别新值汇总
g_sum3 like acdoca_m_extract-hsl VALUE '0'," 呆滞
g_sum04_06 like acdoca_m_extract-hsl VALUE '0',
g_sum07_12 like acdoca_m_extract-hsl VALUE '0',
g_sum12_24 like acdoca_m_extract-hsl VALUE '0',
g_sum24 like acdoca_m_extract-hsl VALUE '0',
g_sum like acdoca_m_extract-hsl VALUE '0'.

"1000 3000
DATA: g1_sum_1 like acdoca_m_extract-hsl VALUE '0', " 新值 sum 1000
g1_sum_2 like acdoca_m_extract-hsl VALUE '0', " HB-台湾
g2_sum_1 like acdoca_m_extract-hsl VALUE '0', " 小计
g2_sum_2 like acdoca_m_extract-hsl VALUE '0', " 总计
g3_sum_1 like acdoca_m_extract-hsl VALUE '0'," 新值 sum 3000
g3_sum_2 like acdoca_m_extract-hsl VALUE '0'. " 不含淘汰产品 及 mbs 库存

DATA: L_FIYEAR TYPE SY-DATUM.

DATA:BEGIN OF gt_datum occurs 0,"明细周期
text1(10),"选项
text2(10),"选项
opedatem LIKE sy-datum," 开始日期
enddatem LIKE sy-datum," 结束日期
END OF gt_datum.

DATA:gt_datum1 LIKE gt_datum occurs 0 WITH HEADER LINE. "选择屏周期

*---> 明细数据选择屏工厂条件
DATA:BEGIN OF gt_bukrs occurs 0,
text1(10),"选项
text2(10),"选项
opewerks LIKE MATDOC-BUKRS," 开始日期
endwerks LIKE MATDOC-BUKRS," 结束日期
END OF gt_bukrs.

************************************************************************
* Includes Module
************************************************************************

************************************************************************
* Selection Screen
************************************************************************
*--->选择屏
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-B01.
PARAMETERS: P_Start LIKE ACDOCA_M_EXTRACT-FISCYEARPER . "起始期间.
PARAMETERS: P_FIYEAR LIKE ACDOCA_M_EXTRACT-FISCYEARPER OBLIGATORY . " 年度期别
SELECT-OPTIONS: s_matnr FOR marc-matnr.
PARAMETERS: P_FPATH1 TYPE STRING DEFAULT 'Z:\' . "OBLIGATORY.
* PARAMETERS: i_elikz AS CHECKBOX DEFAULT 'X'. " 下限呆滞
SELECT-OPTIONS:BKLAS FOR EBEW-BKLAS NO-DISPLAY, " Bewertungsklasse
MATNR FOR EBEW-MATNR MATCHCODE OBJECT MAT1 NO-DISPLAY,
SKONT FOR SKA1-SAKNR NO-DISPLAY, " Bestandskonto
BWTAR FOR EBEW-BWTAR MEMORY ID BWT NO-DISPLAY. " Bewertungsart
PARAMETERS:NULLB LIKE AM07M-SENUL NO-DISPLAY, " Materialien mit Nullbestand
KEINZEL LIKE AM07M-KGEBE NO-DISPLAY, " Bewertungskreisebene
PRUEF LIKE AM07M-ERWPR NO-DISPLAY, " erweiterte Prüfung bei
" getrennter Bewertung
matlines NO-DISPLAY ."as checkbox .
PARAMETERS: summen like am07m-xsums NO-DISPLAY, " nur Summen ausgegeben
NEGATIV LIKE AM07M-SENEG NO-DISPLAY. " Negative Bestände anzeigen

SELECTION-SCREEN END OF BLOCK B1.

SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-B02.
SELECT-OPTIONS: FIYEAR FOR ACDOCA_M_EXTRACT-FISCYEARPER , " 年度期别
P_WERKS FOR MATDOC-BUKRS NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK B2.

RANGES: BERMON FOR MARD-LFMON ,
IBWKEY FOR MBEW-BWKEY ,
IBKLAS FOR MBEW-BKLAS.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: vmsaldo LIKE AM07M-XSALD NO-DISPLAY ."RADIOBUTTON GROUP LIST.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: AKSALDO LIKE AM07M-XSALD NO-DISPLAY DEFAULT 'X'."RADIOBUTTON GROUP LIST DEFAULT 'X' .
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: VJSALDO LIKE AM07M-XSALD NO-DISPLAY ."RADIOBUTTON GROUP LIST.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-b03.
PARAMETER: p_title TYPE so_obj_des DEFAULT '经营会议'.
SELECT-OPTIONS: s_addr FOR g_mail_address NO INTERVALS DEFAULT'[email protected]'.

SELECTION-SCREEN END OF BLOCK b3.

************************************************************************
* Initialization
************************************************************************
INITIALIZATION.

" 获取系统年月方法二
*-->本月最后一天
CALL FUNCTION 'BKK_GET_MONTH_LASTDAY'
EXPORTING
I_DATE = SY-DATUM
IMPORTING
E_DATE = LASTDAY.

*----获取上月最后一天
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
i_date = LASTDAY "'20140101' "输入日期
i_flg_end_of_month = ' '
i_months = -1 "表示当前月的前一个月
i_set_last_day_of_month = 'X' "返回的日期为当前月份的最后一天
IMPORTING
e_date = date3 . "返回的日期为当前月份的最后一天

*----获取上5个月最后一天
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
i_date = LASTDAY "'20140101' "输入日期
i_flg_end_of_month = ' '
i_months = -5 "表示当前月的前一个月
i_set_last_day_of_month = 'X' "返回的日期为当前月份的最后一天
IMPORTING
e_date = date3_1 . "返回的日期为当前月份的最后一天

P_START = date3_1(4) && '0' && date3_1+4(2).
P_FIYEAR = date3+0(4) && '0' && date3+4(2).

* p_endate = date3_1.
PERFORM FRM_SET_NEDIT." 设置选择屏元素不能编辑
************************************************************************
* At Selection Screen
************************************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FPATH1. " 获取档案路径
PERFORM GET_FPATH.

************************************************************************
* At Selection Screen Output
************************************************************************
AT SELECTION-SCREEN OUTPUT.

************************************************************************
* Report Format
************************************************************************
TOP-OF-PAGE.

END-OF-PAGE.
************************************************************************
* Main Process
************************************************************************
START-OF-SELECTION.
PERFORM set_FIYEAR. " 获获取日期
PERFORM gt_Detail." 往期明细数据.
PERFORM GET_COL.
PERFORM ALV_SHOW.
END-OF-SELECTION.

*----> 自定义按钮
FORM ALV_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'STATUS_PRINT' .
ENDFORM.

*--->选择屏上部分的值不能修改
FORM FRM_SET_NEDIT.
LOOP AT SCREEN .
IF "SCREEN-NAME EQ 'P_FIYEAR' OR
SCREEN-NAME EQ 'P_ENDATE'. "and sy-uname co 'IT'.
SCREEN-INPUT = '0' .
MODIFY SCREEN .
ENDIF .
IF screen-name EQ 'BKLAS' OR
screen-name EQ 'MATLINES' OR
screen-name EQ 'IBWKEY' OR
screen-name EQ 'IBKLAS' OR
screen-name EQ 'VMSALDO' OR
screen-name EQ 'AKSALDO' OR
screen-name EQ 'VJSALDO'." OR
screen-invisible = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP .
ENDFORM .

*&---------------------------------------------------------------------*
*& Form GET_FPATH
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM GET_FPATH .
* -選擇檔案路徑-
L_FINIT = 'E:\'. " default

CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
EXPORTING
WINDOW_TITLE = 'Find Output Path'
INITIAL_FOLDER = L_FINIT
CHANGING
SELECTED_FOLDER = L_FPATH
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.

* -最後一個字元不為'\',補上'\'-
IF L_FPATH IS NOT INITIAL.
L_LEN = STRLEN( L_FPATH ) - 1.

IF L_FPATH+L_LEN(1) NE '\'.
P_FPATH1 = L_FPATH && |\\|.
ELSE.
P_FPATH1 = L_FPATH.
ENDIF.
ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form ALV_SHOW
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM ALV_SHOW .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = GS_LAYOUT2
* IT_FIELDCAT = GT_FIELDCAT2[]
IT_FIELDCAT = GT_FIELDCATS[]
I_CALLBACK_PF_STATUS_SET = 'ALV_PF_STATUS' "触发事件调用子程序
I_CALLBACK_USER_COMMAND = 'ALV_USER_COMMAND'
I_SAVE = 'A'
TABLES
T_OUTTAB = GT_MB52_2[]"<gt_table2>"GT_MB52_2
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form BSEG
*&---------------------------------------------------------------------*
*& text 获取线上在制金额
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM get_BSEG USING in_datum.
DATA: GT_DMBTR_H LIKE BSEG-DMBTR,
GT_DMBTR_S LIKE BSEG-DMBTR.
DATA: en_datum LIKE sy-datum.
*ACCTIT
*RBKP

CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
i_date = in_datum "'20140101' "输入日期
i_flg_end_of_month = ' '
i_months = 0 "表示当前月的前一个月
i_set_last_day_of_month = 'X' "返回的日期为当前月份的最后一天
IMPORTING
e_date = en_datum . "返回的日期为当前月份的最后一天

SELECT SUM( DMBTR ) INTO GT_DMBTR_H
FROM BSEG
WHERE BUKRS = p_werks2
AND HKONT IN ( '1314000000','1314000001' )
AND SHKZG EQ 'H'
AND H_BUDAT <= en_datum.

SELECT SUM( DMBTR ) INTO GT_DMBTR_S
FROM BSEG
WHERE BUKRS = p_werks2
AND HKONT IN ( '1314000000','1314000001' )
AND SHKZG EQ 'S'
AND H_BUDAT <= en_datum.
*-->线上在制金额
GT_DATA-GT_DMBTR = GT_DMBTR_S - GT_DMBTR_H.
APPEND gt_data .
ENDFORM.

*&---------------------------------------------------------------------*
*& Form GET_COL
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM GET_COL.
DEFINE FILEDCAT.
GT_FIELDCATS-FIELDNAME = &1. "对应内表的字段名
GT_FIELDCATS-SELTEXT_L = &2. "输出列文本
APPEND GT_FIELDCATS.
END-OF-DEFINITION.
FILEDCAT 'WERKS' '工厂'.
FILEDCAT 'MTART' '物料类型'.
FILEDCAT 'MATKL' '物料群组'.
FILEDCAT 'MATNR' '料号'.
FILEDCAT 'MAKTX' '物料说明'.
FILEDCAT 'LGORT' '存储地点'.
FILEDCAT 'LGORT2' '存储地点 II'.
FILEDCAT 'LGOBE' '储存位置说明'.
FILEDCAT 'LGPBE' '储格'.
FILEDCAT 'SALK3' '值未限制'.
FILEDCAT 'SOBKZ' '特别库存'.
FILEDCAT 'EINME' '限制使用库存'.
FILEDCAT 'SALK3_1' '值已限制'.
FILEDCAT 'SPEME' '已冻结'.
FILEDCAT 'SALK3_2' '冻结库存值'.
FILEDCAT 'RETME' '退货'.
FILEDCAT 'SALK3_3' '冻结退货值'.
FILEDCAT 'SALK3_4' '评估GR冻结库存'.
FILEDCAT 'BWESB' '已评估的收货冻结库存'.
FILEDCAT 'SSNUM' '特殊库存号码'.
FILEDCAT 'MEINS' '单位'.
FILEDCAT 'WAERS' '币别'.
FILEDCAT 'LABST' '未限制'.
FILEDCAT 'LBKUM_E' '销售库存'.
FILEDCAT 'LBKUM_M' '物料评价库存'.
FILEDCAT 'INSME' '品质检验中'.
FILEDCAT 'DISPO' 'MRP控制员'.
FILEDCAT 'LABST_INSME' '未限制 & 品质检验中'.
FILEDCAT 'PRICE' '单价'.
FILEDCAT 'HSL' '金额'.
FILEDCAT 'TEXT' '呆滞期'.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form SET_100
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SET_100 USING in_datum .

DATA: l_lbkum2 LIKE mbewh-lbkum,
l_salk32 LIKE mbewh-salk3,
l_fiscye LIKE acdoca_m_extract-fiscyearper.

APPEND LINES OF g_ebew1[] to gt_mb52_1[].
APPEND LINES OF g_mslb1[] to gt_mb52_1[].
APPEND LINES OF g_msku1[] to gt_mb52_1[].

LOOP AT GT_MB52_1.

CLEAR :l_lbkum,l_salk3,l_peinh.
CLEAR:L1_KUNNR,L1_LIFNR,L1_VBELN ,L1_POSNR.
L1_INDEX1 = SY-TABIX.

*----->存储地点说明
SELECT SINGLE lgobe FROM t001l INTO gt_mb52_1-lgobe
WHERE lgort EQ gt_mb52_1-lgort .

*----->储格 、DF 存储位置等级
SELECT SINGLE lgpbe from mard INTO
(gt_mb52_1-lgpbe)
WHERE matnr EQ gt_mb52_1-matnr AND
WERKS EQ P_WERKS1.

*-----> MRP控制员
SELECT SINGLE dispo FROM marc INTO gt_mb52_1-dispo
WHERE matnr EQ gt_mb52_1-matnr AND
WERKS EQ P_WERKS1.

*---->物料说明
SELECT single maktx FROM makt
INTO GT_MB52_1-maktx
WHERE makt~matnr eq GT_MB52_1-matnr
AND spras = sy-langu .

*--->币别
SELECT SINGLE WAERS INTO GT_MB52_1-WAERS
FROM MSEG
WHERE MATNR EQ GT_MB52_1-MATNR AND
WERKS EQ P_WERKS1.

CLEAR:factor.
CLEAR: l_lbkum2,l_salk32.

CONCATENATE in_datum(4) '0' in_datum+4(2) INTO l_fiscye.
SELECT SUM( vmsl ) SUM( hsl ) INTO ( l_lbkum2,l_salk32 )
FROM acdoca_m_extract
WHERE fiscyearper LE l_fiscye
AND bwkey EQ p_werks1
AND matnr EQ gt_mb52_1-matnr.

IF l_lbkum2 EQ '0'.
factor = '0'.
ELSE.
factor = l_salk32 / l_lbkum2 * 100.
ENDIF.
gt_mb52_1-labst_insme = gt_mb52_1-labst + gt_mb52_1-insme.

gt_mb52_1-price = factor .
gt_mb52_1-salk3 = gt_mb52_1-labst_insme * factor.

MODIFY GT_MB52_1 INDEX L1_INDEX1.
ENDLOOP.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form SET_200
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SET_200 USING in_datum .
DATA: l_lbkum1 LIKE mbewh-lbkum,
l_lbkum2 LIKE mbewh-lbkum,
l_matnr1 LIKE mbewh-matnr,
l_matnr2 LIKE mbewh-matnr,
l_salk31 LIKE mbewh-salk3,
l_salk32 LIKE mbewh-salk3,
l_vprsv LIKE mbewh-vprsv,
l_verpr LIKE mbewh-verpr,
l_stprs LIKE mbewh-stprs,
l_peinh LIKE mbewh-peinh,
id_price TYPE n.

DATA: l_fiscye LIKE acdoca_m_extract-fiscyearper.

APPEND LINES OF g_ebew2[] to gt_mb52_2[].
APPEND LINES OF g_mslb2[] to gt_mb52_2[].
APPEND LINES OF g_msku2[] to gt_mb52_2[].

LOOP AT GT_MB52_2.
CLEAR:L2_KUNNR,L2_LIFNR,L2_VBELN ,L2_POSNR.
L2_INDEX1 = SY-TABIX.

*----->存储地点说明
SELECT SINGLE lgobe FROM t001l INTO gt_mb52_2-lgobe
WHERE lgort EQ gt_mb52_2-lgort .

*----->储格 、DF 存储位置等级
SELECT SINGLE lgpbe from mard INTO
(gt_mb52_2-lgpbe)
WHERE matnr EQ gt_mb52_2-matnr AND
WERKS EQ P_WERKS2.

*-----> MRP控制员
SELECT SINGLE dispo FROM marc INTO gt_mb52_2-dispo
WHERE matnr EQ gt_mb52_2-matnr AND
WERKS EQ P_WERKS2.

*---->物料说明
SELECT single maktx FROM makt
INTO GT_MB52_2-maktx
WHERE makt~matnr eq GT_MB52_2-matnr and
spras = sy-langu .
*--->币别
SELECT SINGLE WAERS INTO GT_MB52_2-WAERS
FROM MSEG
WHERE MATNR EQ GT_MB52_2-MATNR AND
WERKS EQ P_WERKS2.

*--->储存地 2
* 1.特别库存 O W
* 2. 消耗品昌 217G-B (三角采购在途仓)
* 3. 原材料 217G-B (三角采购在途仓)
IF GT_MB52_2-SOBKZ EQ 'W'.

GT_MB52_2-LGORT2 = '210G'.
gt_mb52_2-ssnum = gt_mb52_2-kunnr.
ELSEIF GT_MB52_2-SOBKZ EQ 'O'.
gt_mb52_2-lgort2 = 'WIP-OUT'.
gt_mb52_2-ssnum = gt_mb52_2-lifnr.
ENDIF.

IF ( GT_MB52_2-SOBKZ(1) NE 'W'
AND NOT ( GT_MB52_2-SOBKZ(1) EQ 'O' ) )
AND ( GT_MB52_2-LGORT CS '2W'
OR GT_MB52_2-LGORT EQ '217G' ).

IF GT_MB52_2-MATNR+0(1) EQ 'Z'. "料号开头是 Z
GT_MB52_2-LGORT2 = '217G-B'.
ELSE.
GT_MB52_2-LGORT2 ='217G-A'.
ENDIF.
ELSEIF GT_MB52_2-SOBKZ(1) NE 'W'
AND NOT ( GT_MB52_2-SOBKZ(1) EQ 'O').
GT_MB52_2-LGORT2 = GT_MB52_2-LGORT.
ENDIF.

* 求平均值
CLEAR:factor.
CLEAR: l_lbkum2,l_salk32,l_matnr2.

CONCATENATE in_datum(4) '0' in_datum+4(2) INTO l_fiscye.
SELECT SUM( vmsl ) SUM( hsl ) INTO ( l_lbkum2,l_salk32 )
FROM acdoca_m_extract
WHERE fiscyearper LE l_fiscye
AND bwkey EQ p_werks2
AND matnr EQ gt_mb52_2-matnr.

IF l_lbkum2 EQ '0' .
factor = '0'.
ELSE.
factor = l_salk32 / l_lbkum2.
ENDIF.

gt_mb52_2-price = factor .

*--->未限制 & 品质检验中
GT_MB52_2-LABST_INSME = GT_MB52_2-LABST + GT_MB52_2-INSME .

*--->金额
gt_mb52_2-hsl = gt_mb52_2-labst_insme * factor.

CLEAR: gt_t001l.

gt_t001l-lgort2 = gt_mb52_2-lgort2.
APPEND gt_t001l.

MODIFY GT_MB52_2 INDEX L2_INDEX1.
ENDLOOP.

**---> MB52 2000汇总
* SORT gt_t001l by lgort2 DESCENDING.
* DELETE ADJACENT DUPLICATES FROM gt_t001l COMPARING lgort2.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form SET_300
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SET_300 USING in_datum.
DATA: l_fiscye LIKE acdoca_m_extract-fiscyearper,
l_lbkum2 LIKE mbewh-lbkum,
l_salk32 LIKE mbewh-salk3.

DATA:l_MBS LIKE mara-matnr.

APPEND LINES OF g_ebew3[] to gt_mb52_3[].
APPEND LINES OF g_mslb3[] to gt_mb52_3[].
APPEND LINES OF g_msku3[] to gt_mb52_3[].

LOOP AT GT_MB52_3.
CLEAR:L3_KUNNR,L3_LIFNR,L3_VBELN ,L3_POSNR.
L3_INDEX1 = SY-TABIX.

*---->物料说明
SELECT single maktx FROM makt
INTO GT_MB52_3-maktx
WHERE makt~matnr eq GT_MB52_3-matnr and
spras = sy-langu .

*----->存储地点说明
SELECT SINGLE lgobe FROM t001l INTO gt_mb52_3-lgobe
WHERE lgort EQ gt_mb52_3-lgort .

*-----> 储格
SELECT SINGLE lgpbe FROM mard INTO
( gt_mb52_3-lgpbe )
WHERE matnr EQ gt_mb52_3-matnr
and WERKS EQ P_WERKS3.

*-----> MRP控制员
SELECT SINGLE dispo FROM marc INTO gt_mb52_3-dispo
WHERE matnr EQ gt_mb52_3-matnr
and WERKS EQ P_WERKS2.

*--->MBS 库存
CLEAR:l_MBS.
SELECT SINGLE matnr FROM zmmr03_mbs
INTO l_MBS
WHERE matnr EQ gt_mb52_3-matnr.
IF l_MBS IS NOT INITIAL.
GT_MB52_3-MB_ZWHCODE = 'MBS库存'.
ENDIF.

*--->WH CODE & MBS 库存
IF GT_MB52_3-MB_ZWHCODE EQ 'MBS库存'.
GT_MB52_3-zwhcode = 'MBS库存'.
ELSE.
GT_MB52_3-zwhcode = GT_MB52_3-s_zwhcode.
ENDIF.

*--->币别
SELECT SINGLE WAERS INTO GT_MB52_3-WAERS
FROM MSEG
WHERE MATNR EQ GT_MB52_3-MATNR AND
WERKS EQ P_WERKS3.
*--->值未限制

CLEAR: factor,l_salk32.

CONCATENATE in_datum(4) '0' in_datum+4(2) INTO l_fiscye.
SELECT SUM( vmsl ) SUM( hsl ) INTO ( l_lbkum2,l_salk32 )
FROM acdoca_m_extract
WHERE fiscyearper LE l_fiscye
AND bwkey EQ p_werks3
AND matnr EQ gt_mb52_3-matnr.

IF l_lbkum2 EQ '0' .
factor = '0'.
ELSE.
factor = l_salk32 / l_lbkum2.
ENDIF.
gt_mb52_3-price = factor .

gt_mb52_3-labst_insme = gt_mb52_3-labst + gt_mb52_3-insme.
gt_mb52_3-salk3 = gt_mb52_3-labst_insme * factor.

MODIFY GT_MB52_3 INDEX L3_INDEX1.
ENDLOOP.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form SET_PERIOD
*&---------------------------------------------------------------------*
*& text 动态获取周期
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM set_period .
DATA: l_tdate LIKE sy-datum,
l_tatum LIKE sy-datum,
l_datum LIKE sy-datum,
l_week LIKE scal-week,
l_seqno LIKE gt_period-seqno,
l_berid LIKE mdlg-berid,
l_months TYPE i VALUE 0.

CLEAR:gt_period,gt_period[].
*describe table gt_num2 lines lv_num2." 获取内表数据有多少条数

LOOP AT gt_num1.
l_endate = gt_num1-lifab.
exit.
ENDLOOP.
SORT gt_num1 by lifab ASCENDING.
LOOP AT gt_num1.
l_sdate = gt_num1-lifab(6) && '01'.
exit.
ENDLOOP.
PERFORM set_date USING l_sdate l_endate CHANGING lv_date." 计算两端时间相差 个月
lv_num1 = lv_date .

LOOP AT gt_num2.
l_endate = gt_num2-lifab.
exit.
ENDLOOP.
SORT gt_num2 by lifab ASCENDING.
LOOP AT gt_num2.
l_sdate = gt_num2-lifab(6) && '01'.
exit.
ENDLOOP.
PERFORM set_date USING l_sdate l_endate CHANGING lv_date." 计算两端时间相差 个月
lv_num2 = lv_date .

LOOP AT gt_num3.
l_endate = gt_num3-lifab.
exit.
ENDLOOP.
SORT gt_num3 by lifab ASCENDING.
LOOP AT gt_num3.
l_sdate = gt_num3-lifab(6) && '01'.
exit.
ENDLOOP.
PERFORM set_date USING l_sdate l_endate CHANGING lv_date." 计算两端时间相差 个月
lv_num3 = lv_date .

LOOP AT gt_num.
l_endate = gt_num-lifab.
exit.
ENDLOOP.
SORT gt_num by lifab ASCENDING.
LOOP AT gt_num.
l_sdate = gt_num-lifab(6) && '01'.
exit.
ENDLOOP.
PERFORM set_date USING l_sdate l_endate CHANGING lv_date." 计算两端时间相差 个月
lv_num = lv_date .

*p_sdate = p_sdate+0(6) && '01'.
*PERFORM set_date." 计算两端时间相差 个月
"库存范例周期
IF l_existed NE '1'.
lv_num = lv_num + 1.
l_tatum = date3.
ELSE.
l_tatum = date4.
ENDIF.
DO lv_num TIMES.
add 1 TO l_seqno.
PERFORM get_first_few_months USING l_tatum l_months
CHANGING l_tdate. " 获取前几个月的日期
l_sdate = l_tdate(6) && '01'. " 第一天
PERFORM get_lastdate_of_month USING l_sdate " 日期最后一天
CHANGING l_tdate.
MOVE:l_tdate TO gt_period-datum,
l_seqno TO gt_period-seqno,
l_sdate TO gt_period-sdate,
l_tdate TO gt_period-tdate.
CONCATENATE l_tdate(4) '/' l_tdate+4(2) INTO gt_period-ptext.
CONCATENATE 'M' gt_period-ptext
INTO gt_period-ptext SEPARATED BY space.
APPEND gt_period. CLEAR: gt_period.
l_months = l_months + 1.
ENDDO.

" 100 动态日期
CLEAR:l_seqno,l_tdate,l_sdate,l_tdate,l_months.
IF l_existed1 NE '1'.
lv_num1 = lv_num1 + 1.
l_tatum = date3.
ELSE.
l_tatum = date4.
ENDIF.

DO lv_num1 TIMES.
add 1 TO l_seqno.
PERFORM get_first_few_months USING l_tatum l_months
CHANGING l_tdate. " 获取前几个月的日期
l_sdate = l_tdate(6) && '01'. " 第一天
PERFORM get_lastdate_of_month USING l_sdate " 日期最后一天
CHANGING l_tdate.
MOVE:l_tdate TO gt_period1-datum,
l_seqno TO gt_period1-seqno,
l_sdate TO gt_period1-sdate,
l_tdate TO gt_period1-tdate.
CONCATENATE l_tdate(4) '/' l_tdate+4(2) INTO gt_period1-ptext.
CONCATENATE 'M' gt_period1-ptext
INTO gt_period1-ptext SEPARATED BY space.
APPEND gt_period1. CLEAR: gt_period1.
l_months = l_months + 1.
ENDDO.

" 200 动态日期
CLEAR:l_seqno,l_tdate,l_sdate,l_tdate,l_months.
IF l_existed2 NE '1'.
lv_num2 = lv_num2 + 1.
l_tatum = date3.
ELSE.
l_tatum = date4.
ENDIF.

DO lv_num2 TIMES.
add 1 TO l_seqno.
PERFORM get_first_few_months USING l_tatum l_months
CHANGING l_tdate. " 获取前几个月的日期
l_sdate = l_tdate(6) && '01'. " 第一天
PERFORM get_lastdate_of_month USING l_sdate " 日期最后一天
CHANGING l_tdate.
MOVE:l_tdate TO gt_period2-datum,
l_seqno TO gt_period2-seqno,
l_sdate TO gt_period2-sdate,
l_tdate TO gt_period2-tdate.
CONCATENATE l_tdate(4) '/' l_tdate+4(2) INTO gt_period2-ptext.
CONCATENATE 'M' gt_period2-ptext
INTO gt_period2-ptext SEPARATED BY space.
APPEND gt_period2. CLEAR: gt_period2.
l_months = l_months + 1.
ENDDO.

" 300 动态日期
CLEAR:l_seqno,l_tdate,l_sdate,l_tdate,l_months.
IF l_existed2 NE '1'.
lv_num3 = lv_num3 + 1.
l_tatum = date3.
ELSE.
l_tatum = date4.
ENDIF.

DO lv_num3 TIMES.
add 1 TO l_seqno.
PERFORM get_first_few_months USING l_tatum l_months
CHANGING l_tdate. " 获取前几个月的日期
l_sdate = l_tdate(6) && '01'. " 第一天
PERFORM get_lastdate_of_month USING l_sdate " 日期最后一天
CHANGING l_tdate.
MOVE:l_tdate TO gt_period3-datum,
l_seqno TO gt_period3-seqno,
l_sdate TO gt_period3-sdate,
l_tdate TO gt_period3-tdate.
CONCATENATE l_tdate(4) '/' l_tdate+4(2) INTO gt_period3-ptext.
CONCATENATE 'M' gt_period3-ptext
INTO gt_period3-ptext SEPARATED BY space.
APPEND gt_period3. CLEAR: gt_period3.
l_months = l_months + 1.
ENDDO.

SORT gt_period by seqno datum.
SORT gt_period1 by seqno datum.
SORT gt_period2 by seqno datum.
SORT gt_period3 by seqno datum.
*---设置数据类型
CLEAR:gt_dtype,gt_dtype[].
MOVE:'01' TO gt_dtype-dtype,
'库存金额' TO gt_dtype-dtext.
APPEND gt_dtype.CLEAR:gt_dtype.

MOVE:'02' TO gt_dtype-dtype,
'库存金额' TO gt_dtype-dtext.
APPEND gt_dtype.CLEAR:gt_dtype.

MOVE:'03' TO gt_dtype-dtype,
'库存金额' TO gt_dtype-dtext.
APPEND gt_dtype.CLEAR:gt_dtype.

MOVE:'04' TO gt_dtype-dtype,
'库存金额' TO gt_dtype-dtext.
APPEND gt_dtype.CLEAR:gt_dtype.

MOVE:'05' TO gt_dtype-dtype,
'库存金额' TO gt_dtype-dtext.
APPEND gt_dtype.CLEAR:gt_dtype.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form GET_LASTDATE_OF_MONTH
*&---------------------------------------------------------------------*
*& text 获取月份的最后一天
*&---------------------------------------------------------------------*
*& --> L_SDATE
*& <-- L_TDATE
*&---------------------------------------------------------------------*
FORM get_lastdate_of_month USING in_sdate
ex_tdate.
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
day_in = in_sdate
IMPORTING
last_day_of_month = ex_tdate
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form set_date
*&---------------------------------------------------------------------*
*& text 两个时间段相差多少个月
*&---------------------------------------------------------------------*
*& --> L_SDATE
*& <-- L_TDATE
*&--------------------------------------------------------------------*
FORM set_date USING min_sdate max_endate ex_tdate.
CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
EXPORTING
i_date_from = min_sdate
i_date_to = max_endate
i_flg_separate = ' ' "是否单独计算 若有标识,则返回两日期相差的天数
IMPORTING
* e_days = days "返回天数:638
e_months = ex_tdate. "返回月数:21
* e_years = years. "返回年数:2
ENDFORM.

*&---------------------------------------------------------------------*
*& Form Get_first_few_months
*&---------------------------------------------------------------------*
*& text 获取前几个月的日期
*&---------------------------------------------------------------------*
*& --> L_SDATE
*& <-- L_TDAT
*&---------------------------------------------------------------------*
FORM get_first_few_months USING in_sdate in_months
ex_tdate.

CALL FUNCTION 'RSARCH_DATE_SHIFT'
EXPORTING
I_DATE = in_sdate"P_SY_DATUM
I_SHIFT = in_months "月份数
I_SHIFT_UNIT = 'MON'
I_OPTION = 'LT'
IMPORTING
E_DATE = ex_tdate"P_SY_DATUM
EXCEPTIONS
ILLEGAL_SHIFT_UNIT = 1
OUT_OF_BOUNDS = 2
ILLEGAL_OPTION = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form ROUND
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> L_SALK3
*&---------------------------------------------------------------------*
FORM ROUND USING L_SALK3 TYPE f.

CALL FUNCTION 'ROUND'
EXPORTING
decimals = 14 " 保留多少位小数
input = l_salk3
sign = '-' " + 向上取舍 - 向下取舍 (负数也一样)
IMPORTING
output = l_salk3 " 输出返回结果
EXCEPTIONS
input_invalid = 1
overflow = 2
type_invalid = 3
OTHERS = 4.

ENDFORM.

FORM download_successful_1.

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = P_FPATH2
FILETYPE = 'DAT'
CODEPAGE = '8404' "中文乱码
WRITE_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = down_mb52_1 " 下载的内容
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.

IF SY-SUBRC = 0.
MESSAGE S001 WITH '下载成功'.
ELSE.
MESSAGE S001 WITH '下载失败'.
ENDIF.

ENDFORM.

"下载成功
FORM download_successful_2.

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = P_FPATH2
FILETYPE = 'DAT'
CODEPAGE = '8404' "中文乱码
WRITE_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = down_mb52_2 " 下载的内容
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.

IF SY-SUBRC = 0.
MESSAGE S001 WITH '下载成功'.
ELSE.
MESSAGE S001 WITH '下载失败'.
ENDIF.

ENDFORM.

FORM download_successful_3.

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = P_FPATH2
FILETYPE = 'DAT'
CODEPAGE = '8404' "中文乱码
WRITE_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = down_mb52_3 " 下载的内容
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.

IF SY-SUBRC = 0.
MESSAGE S001 WITH '下载成功'.
ELSE.
MESSAGE S001 WITH '下载失败'.
ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form WRITE_MAIL_BODY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> GT_OBJTXT
*& --> P_
*&---------------------------------------------------------------------*
FORM WRITE_MAIL_BODY TABLES I_OBJTXT USING IN_TXT.

I_OBJTXT = IN_TXT. "標題
APPEND I_OBJTXT.
CLEAR I_OBJTXT.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form DAOWN_MB52
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM donw_mb52 USING lv_datum .

IF gt_mb52_1[] is not INITIAL.
CLEAR:down_mb52_1.
*-->标题
down_mb52_1-C1 = '存储地点'.
down_mb52_1-C2 = '工厂'.
down_mb52_1-C3 = '物料类型'.
down_mb52_1-C4 = '物料群组'.
down_mb52_1-C5 = '料号'.
down_mb52_1-C6 = '料号说明'.
down_mb52_1-C7 = '存储位置说明'.
down_mb52_1-C8 = '储格'.
down_mb52_1-C9 = '未限制'.
down_mb52_1-C10 = '值未限制'.
down_mb52_1-C11 = '特别库存'.
down_mb52_1-C12 = '品质检验中'.
down_mb52_1-C13 = '限制使用库存'.
down_mb52_1-C14 = '值已限制'.
down_mb52_1-C15 = '已冻结'.
down_mb52_1-C16 = '冻结库存值'.
down_mb52_1-C17 = '退货'.
down_mb52_1-C18 = '冻结退货值'.
down_mb52_1-C19 = 'MRP控制员'.
down_mb52_1-C20 = '评估GR冻结库存值'.
down_mb52_1-C21 = '已评估的收货冻结库储'.
down_mb52_1-C23 = '特殊库存号码'.
down_mb52_1-C24 = '单位'.
down_mb52_1-C25 = '币别'.
* down_mb52_1-C26 = '销售库存'.
* down_mb52_1-C27 = '评估库存'.
* down_mb52_1-C28 = '异动平均价格'.
* down_mb52_1-C29 = '标准价格'.

APPEND down_mb52_1.
CLEAR down_mb52_1.
*-->表内容
LOOP AT gt_mb52_1 WHERE
( labst > 0 OR insme > 0 OR retme > 0 OR speme > 0 OR einme > 0 ).
move:
gt_mb52_1-lgort to down_mb52_1-c1,
gt_mb52_1-werks to down_mb52_1-c2,
gt_mb52_1-mtart to down_mb52_1-c3,
gt_mb52_1-matkl to down_mb52_1-c4,
gt_mb52_1-matnr to down_mb52_1-c5,
gt_mb52_1-maktx to down_mb52_1-c6,
gt_mb52_1-lgobe to down_mb52_1-c7,
gt_mb52_1-lgpbe to down_mb52_1-c8,
gt_mb52_1-labst to down_mb52_1-c9,
gt_mb52_1-salk3 to down_mb52_1-c10,
gt_mb52_1-sobkz to down_mb52_1-c11,
gt_mb52_1-insme to down_mb52_1-c12,
gt_mb52_1-retme to down_mb52_1-c13,
gt_mb52_1-einme to down_mb52_1-c14,
gt_mb52_1-salk3_1 to down_mb52_1-c15,
gt_mb52_1-speme to down_mb52_1-c16,
gt_mb52_1-salk3_2 to down_mb52_1-c17,
gt_mb52_1-retme to down_mb52_1-c18,
gt_mb52_1-salk3_3 to down_mb52_1-c19,
gt_mb52_1-dispo to down_mb52_1-c20,
gt_mb52_1-salk3_4 to down_mb52_1-c21,
gt_mb52_1-bwesb to down_mb52_1-c22,
gt_mb52_1-ssnum to down_mb52_1-c23,
gt_mb52_1-meins to down_mb52_1-c24,
gt_mb52_1-waers to down_mb52_1-c25.
* gt_mb52_1-lbkum_e to down_mb52_1-c26,
* gt_mb52_1-lbkum_m to down_mb52_1-c27,
* gt_mb52_1-price to down_mb52_1-c28,
* gt_mb52_1-stprs to down_mb52_1-c29.
APPEND down_mb52_1.
CLEAR: down_mb52_1.
ENDLOOP.

* CONCATENATE L_PATH '2000公司厂商明细.xls' INTO L_PATH.
CONCATENATE P_FPATH1 sy-datum '_100_' lv_datum '期物料明细.xls' INTO P_FPATH2.
PERFORM download_successful_1." 下载
ENDIF.
IF gt_mb52_2[] is not INITIAL.
CLEAR:down_mb52_2 .
*-->标题
down_mb52_2-C1 = '存储地点II'.
down_mb52_2-C2 = '呆滞期'.
down_mb52_2-C3 = '工厂'.
down_mb52_2-C4 = '物料类型'.
down_mb52_2-C5 = '物料群组'.
down_mb52_2-C6 = '料号'.
down_mb52_2-C7 = '物料说明'.
down_mb52_2-C8 = '存储地点'.
down_mb52_2-C9 = '存储位置说明'.
down_mb52_2-C10 = '储格'.
down_mb52_2-C11 = '值未限制'.
down_mb52_2-C12 = '特别库存'.
down_mb52_2-C13 = '限制使用库存'.
down_mb52_2-C14 = '值已限制'.
down_mb52_2-C15 = '已冻结'.
down_mb52_2-C16 = '冻结库存值'.
down_mb52_2-C17 = '退货'.
down_mb52_2-C18 = '冻结退货值'.
down_mb52_2-C19 = '评估GR冻结库存'.
down_mb52_2-C20 = '已评估的收货冻结库存值'.
down_mb52_2-C21 = '特殊库存号码'.
down_mb52_2-C22 = 'DF 存储位置等级'.
down_mb52_2-C23 = '单位'.
down_mb52_2-C24 = '币别'.
down_mb52_2-C25 = '未限制' .
down_mb52_2-C26 = '品质检验中' .
down_mb52_2-C27 = 'MRP控制员' .
down_mb52_2-C28 = '未限制 + 品质检验中' .
down_mb52_2-C29 = '单价' .
down_mb52_2-C30 = '金额' .
* down_mb52_2-C31 = '异动平均价格' .
* down_mb52_2-C32 = '标准价格' .
APPEND down_mb52_2.
CLEAR down_mb52_2.
*-->表内容
LOOP AT gt_mb52_2 WHERE labst_insme > 0.
move:
gt_mb52_2-lgort2 to down_mb52_2-c1,
gt_mb52_2-text to down_mb52_2-c2,
gt_mb52_2-werks to down_mb52_2-c3,
gt_mb52_2-mtart to down_mb52_2-c4,
gt_mb52_2-matkl to down_mb52_2-c5,

gt_mb52_2-matnr to down_mb52_2-c6,
gt_mb52_2-maktx to down_mb52_2-c7,
gt_mb52_2-lgort to down_mb52_2-c8,
gt_mb52_2-lgobe to down_mb52_2-c9,
gt_mb52_2-lgpbe to down_mb52_2-c10,

gt_mb52_2-salk3 to down_mb52_2-c11,
gt_mb52_2-sobkz to down_mb52_2-c12,
gt_mb52_2-einme to down_mb52_2-c13,
gt_mb52_2-salk3_1 to down_mb52_2-c14,
gt_mb52_2-speme to down_mb52_2-c15,

gt_mb52_2-salk3_2 to down_mb52_2-c16,
gt_mb52_2-retme to down_mb52_2-c17,
gt_mb52_2-salk3_3 to down_mb52_2-c18,
gt_mb52_2-salk3_4 to down_mb52_2-c19,
gt_mb52_2-bwesb to down_mb52_2-c20,

gt_mb52_2-ssnum to down_mb52_2-c21,
gt_mb52_2-lvorm to down_mb52_2-c22,
gt_mb52_2-meins to down_mb52_2-c23,
gt_mb52_2-waers to down_mb52_2-c24,
gt_mb52_2-labst to down_mb52_2-c25,

gt_mb52_2-insme to down_mb52_2-c26,
gt_mb52_2-einme to down_mb52_2-c27,
gt_mb52_2-labst_insme to down_mb52_2-c28,
gt_mb52_2-price to down_mb52_2-c29,
gt_mb52_2-hsl to down_mb52_2-c30.

* gt_mb52_2-price1 to down_mb52_2-c31,
* gt_mb52_2-stprs to down_mb52_2-c32.
APPEND down_mb52_2.
CLEAR: down_mb52_2.
ENDLOOP.
CONCATENATE P_FPATH1 sy-datum '_200_' lv_datum '期物料明细.xls' INTO P_FPATH2.
PERFORM download_successful_2." 下载
ENDIF.

IF gt_mb52_3[] is not INITIAL.
CLEAR:down_mb52_3.
*-->标题
down_mb52_3-C1 = 'WH CODE'.
down_mb52_3-C2 = '工厂'.
down_mb52_3-C3 = '物料类型'.
down_mb52_3-C4 = '物料群组'.
down_mb52_3-C5 = '物料'.
down_mb52_3-C6 = 'MBS库存'.
down_mb52_3-C7 = 'WH code + MBS库存'.
down_mb52_3-C8 = '物料说明'.
down_mb52_3-C9 = '存储地点'.
down_mb52_3-C10 = '存储位置说明'.
down_mb52_3-C11 = '储格'.
down_mb52_3-C12 = '未限制'.
down_mb52_3-C13 = '值未限制'.
down_mb52_3-C14 = '特别库存'.
down_mb52_3-C15 = '品质检验中'.
down_mb52_3-C16 = '限制使用的库存'.
down_mb52_3-C17 = '值已限制'.
down_mb52_3-C18 = '已冻结'.
down_mb52_3-C19 = '冻结库存值'.
down_mb52_3-C20 = '退货'.
down_mb52_3-C21 = '冻结退货值'.
down_mb52_3-C22 = 'MRP控制员'.
down_mb52_3-C23 = '评估GR冻结库存值'.
down_mb52_3-C24 = '已评估的收货冻结库存'.
down_mb52_3-C25 = '特殊库存号码'.
down_mb52_3-C26 = '单位'.
down_mb52_3-C27 = '币别'.
* down_mb52_3-C28 = '异动平均价格'.
* down_mb52_3-C29 = '标准价格'.
APPEND down_mb52_3.
CLEAR down_mb52_3.
*-->表内容
LOOP AT gt_mb52_3 WHERE
( labst > 0 OR insme > 0 OR retme > 0 OR speme > 0 OR einme > 0 ).
move:
gt_mb52_3-zwhcode to down_mb52_3-c1,
gt_mb52_3-werks to down_mb52_3-c2,
gt_mb52_3-mtart to down_mb52_3-c3,
gt_mb52_3-matkl to down_mb52_3-c4,
gt_mb52_3-matnr to down_mb52_3-c5,
gt_mb52_3-mb_zwhcode to down_mb52_3-c6,
gt_mb52_3-s_zwhcode to down_mb52_3-c7,
gt_mb52_3-maktx to down_mb52_3-c8,
gt_mb52_3-lgort to down_mb52_3-c9,
gt_mb52_3-lgobe to down_mb52_3-c10,
gt_mb52_3-lgpbe to down_mb52_3-c11,
gt_mb52_3-labst to down_mb52_3-c12,
gt_mb52_3-salk3 to down_mb52_3-c13,
gt_mb52_3-sobkz to down_mb52_3-c14,
gt_mb52_3-insme to down_mb52_3-c15,
gt_mb52_3-einme to down_mb52_3-c16,
gt_mb52_3-salk3_1 to down_mb52_3-c17,
gt_mb52_3-speme to down_mb52_3-c18,
gt_mb52_3-salk3_2 to down_mb52_3-c19,
gt_mb52_3-retme to down_mb52_3-c20,
gt_mb52_3-salk3_3 to down_mb52_3-c21,
gt_mb52_3-dispo to down_mb52_3-c22,
gt_mb52_3-salk3_4 to down_mb52_3-c23,
gt_mb52_3-bwesb to down_mb52_3-c24,
gt_mb52_3-ssnum to down_mb52_3-c25,
gt_mb52_3-meins to down_mb52_3-c26,
gt_mb52_3-waers to down_mb52_3-c27.
* gt_mb52_3-price to down_mb52_3-c28,
* gt_mb52_3-stprs to down_mb52_3-c29.

APPEND down_mb52_3.
CLEAR: down_mb52_3.
ENDLOOP.
CONCATENATE P_FPATH1 sy-datum '_300_' lv_datum '期物料明细.xls' INTO P_FPATH2.
PERFORM download_successful_3." 下载
ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form NEW_AREA3_MAIL
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> ID_3
*& --> LV_NULL
*&---------------------------------------------------------------------*
FORM NEW_AREA3_MAIL USING in_ID_3
in_NULL.
DATA: l_past_field(50). "往期栏位
DATA: l_whcode(50),
l_value(50),
l_value1(50),
l_line TYPE string.
DATA: l_num TYPE i,
do_num TYPE i.
*上传 excel 中没有储存地
IF sum_300[] is not INITIAL.
LOOP AT sum_300 WHERE zwhcode NE 'MBS库存'.
in_ID_3 = in_ID_3 + 1.
l_num = '88'.
l_line = l_whcode = sum_300-zwhcode.
LOOP AT write_zmmr03_stok WHERE zwhcode EQ l_whcode.
l_value = write_zmmr03_stok-salk3.
l_value1 = write_zmmr03_stok-text.
ENDLOOP.
* l_seqno = gt_period3-seqno.
CONCATENATE l_line l_value l_value1 INTO l_line SEPARATED BY gc_tab.
*--> 斷行
CONCATENATE g_string_3 l_line gc_crlf INTO g_string_3.
ENDLOOP.

IF in_null NE '1' AND l_num EQ '88'.

DO 3 TIMES.
do_num = do_num + 1.
IF do_num EQ '1'.
ASSIGN COMPONENT 'LGORT2' OF STRUCTURE <g_wa3> TO <g_field3>.
l_line = '合计'.
l_whcode = '3_sum1'.
LOOP AT write_zmmr03_stok WHERE zwhcode EQ l_whcode.
l_value = write_zmmr03_stok-salk3.
l_value1 = write_zmmr03_stok-text.
ENDLOOP.
CONCATENATE l_line l_value l_value1 INTO l_line SEPARATED BY gc_tab.
*--> 斷行
CONCATENATE g_string_3 l_line gc_crlf INTO g_string_3.

ELSEIF do_num EQ '2'.
LOOP AT write_zmmr03_stok WHERE zwhcode EQ l_whcode.
l_value = write_zmmr03_stok-salk3.
l_value1 = write_zmmr03_stok-text.
ENDLOOP.
CONCATENATE l_line l_value l_value1 INTO l_line SEPARATED BY gc_tab.
*--> 斷行
CONCATENATE g_string_3 l_line gc_crlf INTO g_string_3.

ELSE.
l_line = ''.
l_whcode = '3_sum2'.
LOOP AT write_zmmr03_stok WHERE zwhcode EQ l_whcode.
l_value = write_zmmr03_stok-salk3.
l_value1 = write_zmmr03_stok-text.
ENDLOOP.
CONCATENATE l_line l_value l_value1 INTO l_line SEPARATED BY gc_tab.
*--> 斷行
CONCATENATE g_string_3 l_line gc_crlf INTO g_string_3.

ENDIF.
ENDDO.
ENDIF.
ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form SET_FIYEAR
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SET_FIYEAR .
DATA: l_sdate LIKE sy-datum,
l_endate LIKE sy-datum,
l_tdate LIKE sy-datum, " 前几个月的日期
lv_date TYPE i,
l_months TYPE i,
l_index TYPE sy-tabix,
l_seqno LIKE gt_period-seqno.

*-->获取选择屏期间获取最后一天
DATA: L_FIYEAR TYPE SY-DATUM.
DATA: L_Start TYPE SY-DATUM.

L_Start = P_Start+0(4) && P_Start+5(2) && '01'.
IF L_Start LE '00000001'.
L_Start = '20180101'.
ENDIF.
*CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
* EXPORTING
* day_in = L_Start "输入日期
* IMPORTING
* last_day_of_month = date4_s "返回日期:20140131
* EXCEPTIONS
* day_in_no_date = 1
* OTHERS = 2.
date4_s = L_Start.
date4_day = L_FIYEAR = P_FIYEAR+0(4) && P_FIYEAR+5(2) && '01'.
CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = L_FIYEAR "输入日期
IMPORTING
last_day_of_month = date4 "返回日期:20140131
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.

PERFORM set_date USING L_Start L_FIYEAR CHANGING lv_date." 计算两端时间相差 个月
lv_date = lv_date + 1.
DO lv_date TIMES.

PERFORM get_first_few_months USING L_FIYEAR l_months
CHANGING l_tdate. " 获取前几个月的日期
l_sdate = l_tdate(6) && '01'. " 第一天
PERFORM get_lastdate_of_month USING l_sdate " 日期最后一天
CHANGING l_tdate.
gt_datum1-opedatem = l_sdate.
gt_datum1-enddatem = l_tdate.
APPEND gt_datum1. CLEAR: gt_datum1.
l_months = l_months + 1.
ENDDO.

" 获取数据周期
LOOP AT FIYEAR.
Have_data = 'Y'. " 弹框是否下载明细
*FIYEAR-sign I 包含 E 排除
*FIYEAR-option BT 范围之间 EQ 等于 NB 范围以外 GE 大于等于 GT 大于 LT 小于 LE 小于等于 NE 不等于
IF FIYEAR-low+4(1) NE '0' OR FIYEAR-high+4(1) NE '0'
OR FIYEAR-low+5(2) > '12' OR FIYEAR-high+5(2) > '12'
OR ( FIYEAR-low+5(2) EQ '00' AND FIYEAR-low NE '0000000' )
OR ( FIYEAR-high+5(2) EQ '00' AND FIYEAR-high NE '0000000').
MESSAGE S001 WITH '明细周期输入有误,提示:_ _ _ _ 001~ _ _ _ _ 012之间' DISPLAY LIKE 'E'.
Stop.
ENDIF.
IF FIYEAR-option EQ 'BT'.
l_sdate = FIYEAR-low(4) && FIYEAR-low+5(2) && '01' ." 底
l_endate = FIYEAR-high(4) && FIYEAR-high+5(2) && '01' ." 高
PERFORM set_date USING l_sdate l_endate CHANGING lv_date." 计算两端时间相差 个月

* ---> 获取需要明细的日期
CLEAR: l_seqno,l_months.
lv_date = lv_date + 1 .
DO lv_date TIMES.
add 1 TO l_seqno.
PERFORM get_first_few_months USING l_endate l_months
CHANGING l_tdate. " 获取前几个月的日期
l_sdate = l_tdate(6) && '01'. " 第一天
PERFORM get_lastdate_of_month USING l_sdate " 日期最后一天
CHANGING l_tdate.

gt_datum-text1 = fiyear-sign."标志
gt_datum-text2 = 'EQ'."fiyear-option."选项
gt_datum-opedatem = l_sdate. " 开始日期
gt_datum-enddatem = l_tdate. " 结束日期

APPEND gt_datum.
l_months = l_months + 1.
ENDDO.
ELSEIF FIYEAR-option EQ 'NB'.
l_sdate = FIYEAR-low(4) && FIYEAR-low+5(2) && '01' ." 底
l_endate = FIYEAR-high(4) && FIYEAR-high+5(2) && '01' ." 高
PERFORM set_date USING l_sdate l_endate CHANGING lv_date." 计算两端时间相差 个月

* ---> 获取需要明细的日期
CLEAR:l_seqno.
lv_date = lv_date + 1 .
DO lv_date TIMES.
add 1 TO l_seqno.
PERFORM get_first_few_months USING l_endate l_months
CHANGING l_tdate. " 获取前几个月的日期
l_sdate = l_tdate(6) && '01'. " 第一天
PERFORM get_lastdate_of_month USING l_sdate " 日期最后一天
CHANGING l_tdate.

gt_datum-text1 = fiyear-sign."标志
gt_datum-text2 = 'NE'."fiyear-option."选项
gt_datum-opedatem = l_sdate. " 开始日期
gt_datum-enddatem = l_tdate. " 结束日期

APPEND gt_datum.
l_months = l_months + 1.
ENDDO.
ELSE.
gt_datum-text1 = fiyear-sign."标志
gt_datum-text2 = fiyear-option."选项
gt_datum-opedatem = fiyear-low+0(4) && fiyear-low+5(2) && '01'. " 开始日期
gt_datum-enddatem = fiyear-low+0(4) && fiyear-low+5(2) && '01'. " 结束日期
APPEND gt_datum.
ENDIF.
ENDLOOP.

IF Have_data EQ 'Y'.
PERFORM Have_data CHANGING p_return." 选择屏弹框
CLEAR: Have_data.
ENDIF.

* IF i_elikz EQ 'X'. " 下限日期决定是否跑最新呆滞期
" 最后一期需要跑名细资料
LOOP AT gt_datum WHERE opedatem EQ L_FIYEAR.
l_index = '1'.
ENDLOOP.
IF l_index NE '1'.
gt_datum-text1 = 'I'."标志
gt_datum-text2 = 'EQ'."选项
gt_datum-opedatem = date4(6) && '01'. " 开始日期
gt_datum-enddatem = date4. " 结束日期

APPEND gt_datum.
ENDIF.
* ENDIF.

SORT gt_datum by opedatem ASCENDING.
PERFORM set_period1." 动态获取周期
ENDFORM.

*&---------------------------------------------------------------------*
*& Form GT_DETAIL
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM gt_Detail .
DATA:b_wersks1(4),
b_wersks2(4),
b_wersks3(4),
l_index1 LIKE sy-tabix.

DATA: lv_datum LIKE sy-datum," 明细周期变量
lv_datum1 LIKE sy-datum. " 选择屏周期变量
*DATA:BEGIN OF gt_datum occurs 0,
* text1(10),"选项
* text2(10),"选项
* opedatem LIKE sy-datum," 开始日期
* enddatem LIKE sy-datum," 结束日期
*END OF gt_datum.
*gt_bukrs
IF gt_bukrs[] is INITIAL.
b_wersks1 = '100'.
b_wersks2 = '200'.
b_wersks3 = '300'.
* ELSE.
* LOOP AT gt_bukrs.
* CASE gt_bukrs-opewerks.
* WHEN '100'.
* b_wersks1 = gt_bukrs-opewerks.
* WHEN '200'.
* b_wersks2 = gt_bukrs-opewerks.
* WHEN '300'.
* b_wersks3 = gt_bukrs-opewerks.
* ENDCASE.
* ENDLOOP.
ENDIF.

LOOP AT gt_datum WHERE text2 NE 'NE'.

* 选择屏期间
IF gt_datum-text1 EQ 'E' AND
( gt_datum-text2 EQ 'LE'
OR gt_datum-text2 EQ 'LT' ). " 小于 或 小于等于

lv_datum = gt_datum-opedatem .
IF gt_datum-text2 EQ 'LE' .
LOOP AT gt_datum1 WHERE opedatem > lv_datum.
lv_datum1 = gt_datum1-opedatem.
* 循环获取往期数据
LOOP AT gt_datum WHERE text2 NE 'NE'
AND opedatem EQ lv_datum1.

PERFORM text_script USING
b_wersks1 b_wersks2
b_wersks3 gt_datum-opedatem.

" 下载明细
IF p_return EQ '1'.
PERFORM donw_mb52 USING gt_datum-opedatem. " 下载数据
ENDIF.
IF gt_datum-opedatem NE date4_day.
CLEAR:gt_mb52_1[],gt_mb52_2[],gt_mb52_3[],
sum_100[],sum_200[],sum_300[],
sum_100_1[],sum_200_1[],sum_300_1[],
g_mslb1[],g_mslb2[],g_mslb3[],
g_msku1[],g_msku2[],g_msku3[],
g_ebew1[],g_ebew2[],g_ebew3[].
ENDIF.
ENDLOOP.
ENDLOOP.
ELSE.
LOOP AT gt_datum1 WHERE opedatem >= lv_datum.
lv_datum1 = gt_datum1-opedatem.
* 循环获取往期数据
LOOP AT gt_datum WHERE text2 NE 'NE' AND opedatem EQ lv_datum1.
PERFORM text_script USING
b_wersks1 b_wersks2
b_wersks3 gt_datum-opedatem.
" 下载明细
IF p_return EQ '1'.
PERFORM donw_mb52 USING gt_datum-opedatem. " 下载数据
ENDIF.

IF gt_datum-opedatem NE date4_day.
CLEAR:gt_mb52_1[],gt_mb52_2[],gt_mb52_3[],
sum_100[],sum_200[],sum_300[],
sum_100_1[],sum_200_1[],sum_300_1[],
g_mslb1[],g_mslb2[],g_mslb3[],
g_msku1[],g_msku2[],g_msku3[],
g_ebew1[],g_ebew2[],g_ebew3[].
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.

ELSEIF gt_datum-text1 EQ 'E'
AND ( gt_datum-text2 EQ 'GE'
OR gt_datum-text2 EQ 'GT' ).

lv_datum = gt_datum-opedatem .
IF gt_datum-text2 EQ 'GE' .
LOOP AT gt_datum1 WHERE opedatem < lv_datum.
lv_datum1 = gt_datum1-opedatem.
* 循环获取往期数据
LOOP AT gt_datum WHERE text2 NE 'NE'
AND opedatem EQ lv_datum1.

PERFORM text_script USING
b_wersks1 b_wersks2
b_wersks3 gt_datum-opedatem.
" 下载明细
IF p_return EQ '1'.
PERFORM donw_mb52 USING gt_datum-opedatem. " 下载数据
ENDIF.

IF gt_datum-opedatem NE date4_day.
CLEAR:gt_mb52_1[],gt_mb52_2[],gt_mb52_3[],
sum_100[],sum_200[],sum_300[],
sum_100_1[],sum_200_1[],sum_300_1[],
g_mslb1[],g_mslb2[],g_mslb3[],
g_msku1[],g_msku2[],g_msku3[],
g_ebew1[],g_ebew2[],g_ebew3[].
ENDIF.
ENDLOOP.
ENDLOOP.
ELSE.
LOOP AT gt_datum1 WHERE opedatem <= lv_datum.
lv_datum1 = gt_datum1-opedatem.
* 循环获取往期数据
LOOP AT gt_datum WHERE text2 NE 'NE'
AND opedatem EQ lv_datum1.

PERFORM text_script USING
b_wersks1 b_wersks2
b_wersks3 gt_datum-opedatem.

" 下载明细
IF p_return EQ '1'.
PERFORM donw_mb52 USING gt_datum-opedatem. " 下载数据
ENDIF.
IF gt_datum-opedatem NE date4_day.
CLEAR:gt_mb52_1[],gt_mb52_2[],gt_mb52_3[],
sum_100[],sum_200[],sum_300[],
sum_100_1[],sum_200_1[],sum_300_1[],
g_mslb1[],g_mslb2[],g_mslb3[],
g_msku1[],g_msku2[],g_msku3[],
g_ebew1[],g_ebew2[],g_ebew3[].
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
ELSEIF gt_datum-text1 EQ 'I' AND
( gt_datum-text2 EQ 'LE'
OR gt_datum-text2 EQ 'LT' ). " 小于 或 小于等于.

lv_datum = gt_datum-opedatem .
IF gt_datum-text2 EQ 'LE' .
LOOP AT gt_datum1 WHERE opedatem <= lv_datum.
lv_datum1 = gt_datum1-opedatem.
* 循环获取往期数据
LOOP AT gt_datum WHERE text2 NE 'NE'
AND opedatem EQ lv_datum1.

PERFORM text_script USING
b_wersks1 b_wersks2
b_wersks3 gt_datum-opedatem.

" 下载明细
IF p_return EQ '1'.
PERFORM donw_mb52 USING gt_datum-opedatem. " 下载数据
ENDIF.

IF gt_datum-opedatem NE date4_day.
CLEAR:gt_mb52_1[],gt_mb52_2[],gt_mb52_3[],
sum_100[],sum_200[],sum_300[],
sum_100_1[],sum_200_1[],sum_300_1[],
g_mslb1[],g_mslb2[],g_mslb3[],
g_msku1[],g_msku2[],g_msku3[],
g_ebew1[],g_ebew2[],g_ebew3[].
ENDIF.
ENDLOOP.
ENDLOOP.
ELSE.
LOOP AT gt_datum1 WHERE opedatem < lv_datum.
lv_datum1 = gt_datum1-opedatem.
* 循环获取往期数据
LOOP AT gt_datum WHERE text2 NE 'NE'
AND opedatem EQ lv_datum1.

PERFORM text_script USING
b_wersks1 b_wersks2
b_wersks3 gt_datum-opedatem.
" 下载明细
IF p_return EQ '1'.
PERFORM donw_mb52 USING gt_datum-opedatem. " 下载数据
ENDIF.

IF gt_datum-opedatem NE date4_day.
CLEAR:gt_mb52_1[],gt_mb52_2[],gt_mb52_3[],
sum_100[],sum_200[],sum_300[],
sum_100_1[],sum_200_1[],sum_300_1[],
g_mslb1[],g_mslb2[],g_mslb3[],
g_msku1[],g_msku2[],g_msku3[],
g_ebew1[],g_ebew2[],g_ebew3[].
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
ELSEIF gt_datum-text1 EQ 'I'
AND ( gt_datum-text2 EQ 'GE'
OR gt_datum-text2 EQ 'GT' ).

lv_datum = gt_datum-opedatem .
IF gt_datum-text2 EQ 'GE' .
LOOP AT gt_datum1 WHERE opedatem >= lv_datum.
lv_datum1 = gt_datum1-opedatem.
* 循环获取往期数据
LOOP AT gt_datum WHERE text2 NE 'NE'
AND opedatem EQ lv_datum1.

PERFORM text_script USING
b_wersks1 b_wersks2
b_wersks3 gt_datum-opedatem.
" 下载明细
IF p_return EQ '1'.
PERFORM donw_mb52 USING gt_datum-opedatem. " 下载数据
ENDIF.

IF gt_datum-opedatem NE date4_day.
CLEAR:gt_mb52_1[],gt_mb52_2[],gt_mb52_3[],
sum_100[],sum_200[],sum_300[],
sum_100_1[],sum_200_1[],sum_300_1[],
g_mslb1[],g_mslb2[],g_mslb3[],
g_msku1[],g_msku2[],g_msku3[],
g_ebew1[],g_ebew2[],g_ebew3[].
ENDIF.
ENDLOOP.
ENDLOOP.
ELSE.
LOOP AT gt_datum1 WHERE opedatem > lv_datum.
lv_datum1 = gt_datum1-opedatem.
* 循环获取往期数据
LOOP AT gt_datum WHERE text2 NE 'NE'
AND opedatem EQ lv_datum1.

PERFORM text_script USING
b_wersks1 b_wersks2
b_wersks3 gt_datum-opedatem.
" 下载明细
IF p_return EQ '1'.
PERFORM donw_mb52 USING gt_datum-opedatem. " 下载数据
ENDIF.

IF gt_datum-opedatem NE date4_day.
CLEAR:gt_mb52_1[],gt_mb52_2[],gt_mb52_3[],
sum_100[],sum_200[],sum_300[],
sum_100_1[],sum_200_1[],sum_300_1[],
g_mslb1[],g_mslb2[],g_mslb3[],
g_msku1[],g_msku2[],g_msku3[],
g_ebew1[],g_ebew2[],g_ebew3[].
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
ELSEIF gt_datum-text1 EQ 'I' AND gt_datum-text2 EQ 'EQ' .

lv_datum = gt_datum-opedatem .
LOOP AT gt_datum1 WHERE opedatem = lv_datum.
lv_datum1 = gt_datum1-opedatem.
* 循环获取往期数据
LOOP AT gt_datum WHERE text2 NE 'NE'
AND opedatem EQ lv_datum1.

PERFORM text_script USING
b_wersks1 b_wersks2
b_wersks3 gt_datum-opedatem.
" 下载明细
IF p_return EQ '1'.
PERFORM donw_mb52 USING gt_datum-opedatem. " 下载数据
ENDIF.

IF gt_datum-opedatem NE date4_day.
CLEAR:gt_mb52_1[],gt_mb52_2[],gt_mb52_3[],
sum_100[],sum_200[],sum_300[],
sum_100_1[],sum_200_1[],sum_300_1[],
g_mslb1[],g_mslb2[],g_mslb3[],
g_msku1[],g_msku2[],g_msku3[],
g_ebew1[],g_ebew2[],g_ebew3[].
ENDIF.
ENDLOOP.
ENDLOOP.
ELSEIF gt_datum-text1 EQ 'I' AND gt_datum-text2 EQ 'NE' .
lv_datum = gt_datum-opedatem .
LOOP AT gt_datum1 WHERE opedatem NE lv_datum.
lv_datum1 = gt_datum1-opedatem.
* 循环获取往期数据
LOOP AT gt_datum WHERE text2 NE 'NE'
AND opedatem EQ lv_datum1.

PERFORM text_script USING
b_wersks1 b_wersks2
b_wersks3 gt_datum-opedatem.
" 下载明细
IF p_return EQ '1'.
PERFORM donw_mb52 USING gt_datum-opedatem. " 下载数据
ENDIF.

IF gt_datum-opedatem NE date4_day.
CLEAR:gt_mb52_1[],gt_mb52_2[],gt_mb52_3[],
sum_100[],sum_200[],sum_300[],
sum_100_1[],sum_200_1[],sum_300_1[],
g_mslb1[],g_mslb2[],g_mslb3[],
g_msku1[],g_msku2[],g_msku3[],
g_ebew1[],g_ebew2[],g_ebew3[].
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form INT_WERKS
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> L_WERKS
*&---------------------------------------------------------------------*
FORM INT_WERKS USING in_sign in_option in_werks.

gt_bukrs-text1 = p_werks-sign.
gt_bukrs-text2 = p_werks-option.
gt_bukrs-opewerks = in_werks.
gt_bukrs-endwerks = in_werks.
APPEND gt_bukrs.
CLEAR: gt_bukrs.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form TEXT_SCRIPT
*&---------------------------------------------------------------------*
*& text 脚本
*&---------------------------------------------------------------------*
*& --> B_WERKS1
*& --> B_WERKS2
*& --> B_WERKS3
*& --> GT_DATUM
*&---------------------------------------------------------------------*
FORM TEXT_SCRIPT USING b_wersks1 b_wersks2 b_wersks3 in_datum.
*--->等于下限日期时跑全部明细资料 (新资料写入SAP)
DATA:en_datum LIKE sy-datum.

DATA: lv1_labst LIKE mardh-labst,
lv2_labst LIKE mardh-labst,
lv3_labst LIKE mardh-labst.

DATA:gr_data1 TYPE REF TO data,
gr_data2 TYPE REF TO data,
gr_data3 TYPE REF TO data.

IF in_datum EQ date4_day .
b_wersks1 = '100'.
b_wersks2 = '200'.
b_wersks3 = '300'.
ENDIF.

CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
EXPORTING
day_in = in_datum "输入日期
IMPORTING
last_day_of_month = en_datum "返回日期:20140131
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.

*----->1000
SELECT * FROM MARDH
INNER JOIN mara ON mara~matnr EQ mardh~matnr
INTO CORRESPONDING FIELDS OF table gt_mb52_1 "一般
WHERE mardh~werks EQ b_wersks1
AND mardh~lfgja EQ gt_datum-opedatem(4)
AND mardh~lfmon EQ gt_datum-opedatem+4(2)
AND ( mardh~labst > 0 OR mardh~umlme > 0
OR mardh~insme > 0 OR mardh~einme > 0
OR mardh~speme > 0 OR mardh~retme > 0
OR mardh~vklab > 0 OR mardh~vkuml > 0 )
AND mardh~matnr in s_matnr.

SELECT mslbh~matnr mslbh~werks
mslbh~sobkz mslbh~lifnr
lblab as labst lbins as insme
lbein as einme lbuml as bwesb
mara~mtart mara~matkl
mara~meins
FROM mslbh
INNER JOIN mara ON mara~matnr EQ mslbh~matnr
INTO CORRESPONDING FIELDS OF table g_mslb1 " O
WHERE werks EQ b_wersks1 AND
lfgja EQ gt_datum-opedatem(4) AND
lfmon EQ gt_datum-opedatem+4(2) AND
( lblab > 0 OR lbins > 0
OR lbein > 0 OR lbuml > 0 )
AND mslbh~matnr in s_matnr.

SELECT mskuh~matnr mskuh~werks
mskuh~sobkz mskuh~kunnr
kulab as labst kuins as insme
kuein as einme kuuml as bwesb
mara~mtart mara~matkl
mara~meins
FROM mskuh
INNER JOIN mara ON mara~matnr EQ mskuh~matnr
INTO CORRESPONDING FIELDS OF table g_msku1 " W
WHERE werks EQ b_wersks1 AND
lfgja EQ gt_datum-opedatem(4) AND
lfmon EQ gt_datum-opedatem+4(2) AND
( kulab > 0 OR kuins > 0
OR kuein > 0 OR kuuml > 0 )
AND mskuh~matnr in s_matnr.

SELECT mskah~matnr mskah~werks
mskah~sobkz mskah~vbeln
mskah~posnr
kalab as labst kains as insme
kaein as einme kaspe as speme
lgort as lgort
mara~mtart mara~matkl
mara~meins
FROM mskah
INNER JOIN mara ON mara~matnr EQ mskah~matnr
INTO CORRESPONDING FIELDS OF table g_ebew1 " E
WHERE werks EQ b_wersks1 AND
lfgja EQ gt_datum-opedatem(4) AND
lfmon EQ gt_datum-opedatem+4(2) AND
( kalab > 0 OR kains > 0 OR kaein > 0 )
AND mskah~matnr in s_matnr.

* -----> 2000
SELECT * FROM MARDH
INNER JOIN mara ON mara~matnr EQ mardh~matnr
INTO CORRESPONDING FIELDS OF table gt_mb52_2 "一般
WHERE mardh~werks EQ b_wersks2
AND mardh~lfgja EQ gt_datum-opedatem(4)
AND mardh~lfmon EQ gt_datum-opedatem+4(2)
AND ( mardh~labst > 0 OR mardh~umlme > 0
OR mardh~insme > 0 OR mardh~einme > 0
OR mardh~speme > 0 OR mardh~retme > 0
OR mardh~vklab > 0 OR mardh~vkuml > 0 )
AND mardh~matnr in s_matnr.
* AND makt~spras = @sy-langu.

SELECT mslbh~matnr mslbh~werks
mslbh~sobkz mslbh~lifnr
lblab as labst lbins as insme
lbein as einme lbuml as bwesb
mara~mtart mara~matkl
mara~meins
FROM mslbh
INNER JOIN mara ON mara~matnr EQ mslbh~matnr
INTO CORRESPONDING FIELDS OF table g_mslb2 " O
WHERE werks EQ b_wersks2 AND
lfgja EQ gt_datum-opedatem(4) AND
lfmon EQ gt_datum-opedatem+4(2) AND
( lblab > 0 OR lbins > 0
OR lbein > 0 OR lbuml > 0 )
AND mslbh~matnr in s_matnr.

SELECT mskuh~matnr mskuh~werks
mskuh~sobkz mskuh~kunnr
kulab as labst kuins as insme
kuein as einme kuuml as bwesb
mara~mtart mara~matkl
mara~meins
FROM mskuh
INNER JOIN mara ON mara~matnr EQ mskuh~matnr
INTO CORRESPONDING FIELDS OF table g_msku2 " W
WHERE werks EQ b_wersks2 AND
lfgja EQ gt_datum-opedatem(4) AND
lfmon EQ gt_datum-opedatem+4(2) AND
( kulab > 0 OR kuins > 0
OR kuein > 0 OR kuuml > 0 )
AND mskuh~matnr in s_matnr.

SELECT mskah~matnr mskah~werks
mskah~sobkz mskah~vbeln
mskah~posnr
kalab as labst kains as insme
kaein as einme kaspe as speme
lgort as lgort
mara~mtart mara~matkl
mara~meins
FROM mskah
INNER JOIN mara ON mara~matnr EQ mskah~matnr
INTO CORRESPONDING FIELDS OF table g_ebew2 " E
WHERE werks EQ b_wersks2 AND
lfgja EQ gt_datum-opedatem(4) AND
lfmon EQ gt_datum-opedatem+4(2) AND
( kalab > 0 OR kains > 0 OR kaein > 0 )
AND mskah~matnr in s_matnr.

* -----> 3000
SELECT mardh~matnr mardh~werks
mardh~lgort mardh~insme
mardh~einme mardh~speme
mardh~retme "mardh~vklab
mardh~labst mara~mtart
mara~matkl mara~zwhcode as s_zwhcode
mara~meins
FROM MARDH
INNER JOIN mara ON mara~matnr EQ mardh~matnr
INTO CORRESPONDING FIELDS OF table gt_mb52_3 "一般
WHERE mardh~werks EQ b_wersks3
AND mardh~lfgja EQ gt_datum-opedatem(4)
AND mardh~lfmon EQ gt_datum-opedatem+4(2)
AND ( mardh~labst > 0 OR mardh~umlme > 0
OR mardh~insme > 0 OR mardh~einme > 0
OR mardh~speme > 0 OR mardh~retme > 0
OR mardh~vklab > 0 OR mardh~vkuml > 0 )
AND mardh~matnr in s_matnr.
* AND makt~spras = sy-langu.

SELECT mslbh~matnr mslbh~werks
mslbh~sobkz mslbh~lifnr
lblab as labst lbins as insme
lbein as einme lbuml as bwesb
mara~mtart mara~matkl
mara~zwhcode as s_zwhcode
mara~meins
FROM mslbh
INNER JOIN mara ON mara~matnr EQ mslbh~matnr
INTO CORRESPONDING FIELDS OF table g_mslb3 " O
WHERE mslbh~werks EQ b_wersks3 AND
mslbh~lfgja EQ gt_datum-opedatem(4) AND
mslbh~lfmon EQ gt_datum-opedatem+4(2) AND
( lblab > 0 OR lbins > 0
OR lbein > 0 OR lbuml > 0 )
AND mslbh~matnr in s_matnr.

SELECT mskuh~matnr mskuh~werks
mskuh~sobkz mskuh~kunnr
kulab as labst kuins as insme
kuein as einme kuuml as bwesb
mara~mtart mara~matkl
mara~zwhcode as s_zwhcode
mara~meins
FROM mskuh
INNER JOIN mara ON mara~matnr EQ mskuh~matnr
INTO CORRESPONDING FIELDS OF table g_msku3 " W
WHERE werks EQ b_wersks3 AND
lfgja EQ gt_datum-opedatem(4) AND
lfmon EQ gt_datum-opedatem+4(2) AND
( kulab > 0 OR kuins > 0
OR kuein > 0 OR kuuml > 0 )
AND mskuh~matnr in s_matnr.

SELECT mskah~matnr mskah~werks
mskah~sobkz mskah~vbeln
mskah~posnr
kalab as labst kains as insme
kaein as einme kaspe as speme
lgort as lgort
mara~mtart mara~matkl
mara~zwhcode as s_zwhcode
mara~meins
FROM mskah
INNER JOIN mara ON mara~matnr EQ mskah~matnr
INTO CORRESPONDING FIELDS OF table g_ebew3 " E
WHERE werks EQ b_wersks3 AND
lfgja EQ gt_datum-opedatem(4) AND
lfmon EQ gt_datum-opedatem+4(2) AND
( kalab > 0 OR kains > 0 OR kaein > 0 )
AND mskah~matnr in s_matnr.

PERFORM set_100 USING in_datum.
PERFORM set_200 USING in_datum.
PERFORM set_300 USING in_datum.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form HAVE_DATA
*&---------------------------------------------------------------------*
*& text 选择屏弹框
*&---------------------------------------------------------------------*
*& --> HAVE_DATA
*&---------------------------------------------------------------------*
FORM HAVE_DATA CHANGING in_return.
DATA: G_RETURN TYPE C .

CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
* TITLEBAR = '是需要这几个月资料明细'
* DIAGNOSE_OBJECT = ' '
TEXT_QUESTION = '明细是否需要下载Web或本端档案'
* TEXT_BUTTON_1 = 'Ja'(001)
ICON_BUTTON_1 = '下载'
* TEXT_BUTTON_2 = 'Nein'(002)
ICON_BUTTON_2 = '不需要下载 '
DEFAULT_BUTTON = '1'
DISPLAY_CANCEL_BUTTON = 'X'
* USERDEFINED_F1_HELP = ' '
START_COLUMN = 25
START_ROW = 6
* POPUP_TYPE =
* IV_QUICKINFO_BUTTON_1 = ' '
* IV_QUICKINFO_BUTTON_2 = ' '
IMPORTING
ANSWER = G_RETURN
* TABLES
* PARAMETER =
EXCEPTIONS
TEXT_NOT_FOUND = 1
OTHERS = 2 .
IF G_RETURN EQ 'A'.
stop.
ENDIF.
in_return = G_RETURN.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form SET_PERIOD1
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM SET_PERIOD1 .
DATA:l_tdate LIKE sy-datum,
l_months TYPE i,
lv_date2 TYPE i,
l_seqno LIKE gt_period-seqno.

*-->获取选择屏期间获取最后一天

DATA: L_Start TYPE SY-DATUM.

L_Start = P_Start+0(4) && P_Start+5(2) && '01'.
L_FIYEAR = P_FIYEAR+0(4) && P_FIYEAR+5(2) && '01'.

PERFORM set_date USING L_Start L_FIYEAR
CHANGING lv_date2." 计算两端时间相差 个月

CLEAR:l_seqno.
lv_date2 = lv_date2 + 1.
DO lv_date2 TIMES.
add 1 TO l_seqno.
PERFORM get_first_few_months USING L_FIYEAR l_months
CHANGING l_tdate. " 获取前几个月的日期
l_sdate = l_tdate(6) && '01'. " 第一天
PERFORM get_lastdate_of_month USING l_sdate " 日期最后一天
CHANGING l_tdate.
MOVE:l_tdate TO gt_period2-datum,
l_seqno TO gt_period2-seqno,
l_sdate TO gt_period2-sdate,
l_tdate TO gt_period2-tdate.
CONCATENATE l_tdate(4) '/' l_tdate+4(2) INTO gt_period2-ptext.
CONCATENATE 'M' gt_period2-ptext
INTO gt_period2-ptext SEPARATED BY space.
APPEND gt_period2. CLEAR: gt_period2.
l_months = l_months + 1.
ENDDO.

gt_period[] = gt_period1[] = gt_period3[] = gt_period2[].
ENDFORM.

MM52 历史库存及历史金额查询-LMLPHP

05-11 13:21