BOM展开实例
report Z_PP_FIND_MULTBOM_MAT no standard page heading
message-id YMM
line-count 81
line-size 650. "207
************************************************************************
*INCLUDE
************************************************************************
include <LINE>.
************************************************************************
*DDIC
************************************************************************
tables:MARA,MARC,BKPF,MARD,MAST.
************************************************************************
*ALV层级关系定义
************************************************************************
type-pools: SLIS.
data: WT_FIELDCAT type SLIS_T_FIELDCAT_ALV,
WT_LAYOUT type SLIS_LAYOUT_ALV,
WT_EVENTS type SLIS_T_EVENT.
data: WS_EVENTS like line of WT_EVENTS,
IT_SORT type SLIS_T_SORTINFO_ALV with header line. "ALV 排序内表
************************************************************************
*DATA
************************************************************************
data: begin of WT_ITAB occurs 10,
MATNR like MARA-MATNR, "父件物料编码
IDNRK like MARA-MATNR, "子件物料编码
OJTXP like MAKT-MAKTX, "子件物料描述
MEINS like MARA-MEINS, "子件计量单位
MNGLG like STPOX-MNGLG,"子件用量
LABST like MARD-LABST, "子件库存量
LABST_01 like MARD-LABST, "附加工厂一库存量
LABST_02 like MARD-LABST. "附加工厂二库存量
data: end of WT_ITAB.
selection-screen begin of block B1 with frame title TEXT-001.
parameters: P_WERKS like MAST-WERKS obligatory default '2001'.
select-options: P_MATNR for MAST-MATNR. "物料号
parameters: P_STLAN like MAST-STLAN default '1',"BOM 用途
P_BMENG like STKO-BMENG,"需求数量
X_WERKS like MARC-WERKS obligatory default '2001',
Z_WERKS like MARC-WERKS obligatory default '2001'.
selection-screen end of block B1.
selection-screen begin of block B2 with frame title TEXT-002.
parameters: P_SING radiobutton group RAD1 default 'X'. "单层bom
parameters: P_MULT radiobutton group RAD1. "多层bom
selection-screen end of block B2.
initialization.
start-of-selection.
*得到物料的子项目
perform GET_DATA.
*打印该BOM的数据
perform PRINT_ALV_DATA.
end-of-selection.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form GET_DATA .
*数据定义
data: begin of WTL_MATNR occurs 0,
WERKS like MARC-WERKS,
MATNR like MARA-MATNR.
data: end of WTL_MATNR.
*展开BOM的字阶
data: WTL_STB like STPOX occurs 10 with header line.
select WERKS MATNR
appending corresponding fields of table WTL_MATNR
from MAST
where MATNR in P_MATNR
and WERKS eq P_WERKS.
*根据选项产生不同BOM的结构
*展多层BOM
if P_MULT eq 'X'.
loop at WTL_MATNR.
refresh WTL_STB.
clear WTL_STB.
call function 'CS_BOM_EXPL_MAT_V2'
exporting
CAPID = 'PP01' "BOM Application
DATUV = SY-DATUM "有效开始日
EMENG = P_BMENG "BASE QUANTITY数量
MTNRV = WTL_MATNR-MATNR
"MATERAILNUMBER物料
STLAN = P_STLAN "bom用途
* STLAL = P_STLAL
* CUOBJ = CUOBJ
MKTLS = 'X'
MEHRS = 'X' "多阶层bom展开
WERKS = WTL_MATNR-WERKS "'PDGM'工厂
tables
STB = WTL_STB "展开明细
exceptions
ALT_NOT_FOUND = 1
CALL_INVALID = 2
MATERIAL_NOT_FOUND = 3
MISSING_AUTHORIZATION = 4
NO_BOM_FOUND = 5
NO_PLANT_DATA = 6
NO_SUITABLE_BOM_FOUND = 7
others = 8.
if SY-SUBRC eq 0.
loop at WTL_STB.
WT_ITAB-MATNR = WTL_MATNR-MATNR.
WT_ITAB-OJTXP = WTL_STB-OJTXP.
WT_ITAB-IDNRK = WTL_STB-IDNRK.
WT_ITAB-MEINS = WTL_STB-MEINS.
WT_ITAB-MNGLG = WTL_STB-MNGLG.
* P_ITAB_ITEM-STLAL = -STLAL.
* P_ITAB_ITEM-STUFE = STB-STUFE.
*查找物料的库存
perform GET_KCDATA using WT_ITAB-IDNRK
changing WT_ITAB-LABST
WT_ITAB-LABST_01
WT_ITAB-LABST_02.
shift WT_ITAB-MATNR left deleting leading '0'. "去0
shift WT_ITAB-IDNRK left deleting leading '0'.
append WT_ITAB.
clear WT_ITAB.
endloop.
endif.
endloop.
endif.
*展单层BOM
if P_SING eq 'X'.
loop at WTL_MATNR.
call function 'CS_BOM_EXPL_MAT_V2'
exporting
CAPID = 'PP01' "BOM Application
DATUV = SY-DATUM
EMENG = P_BMENG "BASE QUANTITY
MTNRV = WTL_MATNR-MATNR "MATERAIL NUMBER
STLAN = P_STLAN
* STLAL = P_STLAL
* CUOBJ = CUOBJ
* MKTLS = 'X'
* MEHRS = 'X'
WERKS = WTL_MATNR-WERKS "'PDGM'
tables
STB = WTL_STB
exceptions
ALT_NOT_FOUND = 1
CALL_INVALID = 2
MATERIAL_NOT_FOUND = 3
MISSING_AUTHORIZATION = 4
NO_BOM_FOUND = 5
NO_PLANT_DATA = 6
NO_SUITABLE_BOM_FOUND = 7
others = 8.
if SY-SUBRC eq 0.
loop at WTL_STB.
WT_ITAB-MATNR = WTL_MATNR-MATNR.
WT_ITAB-OJTXP = WTL_STB-OJTXP.
WT_ITAB-IDNRK = WTL_STB-IDNRK.
WT_ITAB-MEINS = WTL_STB-MEINS.
WT_ITAB-MNGLG = WTL_STB-MNGLG.
* P_ITAB_ITEM-STLAL = -STLAL.
* P_ITAB_ITEM-STUFE = STB-STUFE.
perform GET_KCDATA using WT_ITAB-IDNRK
changing WT_ITAB-LABST
WT_ITAB-LABST_01
WT_ITAB-LABST_02.
shift WT_ITAB-MATNR left deleting leading '0'. "去0
shift WT_ITAB-IDNRK left deleting leading '0'.
append WT_ITAB.
clear WT_ITAB.
endloop.
endif.
endloop.
endif.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PRINT_ALV_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form PRINT_ALV_DATA .
data: WLT_FIELDCAT like line of WT_FIELDCAT.
* PERFORM FILL_EVENTCAT_ALV.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'MATNR'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '父件物料编码'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'IDNRK'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件物料编码'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'OJTXP'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件物料描述'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'MEINS'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '单位'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'MNGLG'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件用量'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = ' LABST'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件库存量'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'LABST_01'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '附加工厂一库存量'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'LABST_02'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '附加工厂二库存量'.
append WLT_FIELDCAT to WT_FIELDCAT.
WT_LAYOUT-ZEBRA = 'X'.
WT_LAYOUT-F2CODE = '&ETA'.
WT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
I_CALLBACK_PROGRAM = SY-CPROG
IS_LAYOUT = WT_LAYOUT
I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE'
* I_callback_pf_status_set = 'STANDARD1'
I_DEFAULT = 'X'
I_SAVE = 'X'
* I_CALLBACK_USER_COMMAND = 'PROCESS_USER_COMMAND'
IT_FIELDCAT = WT_FIELDCAT[]
IT_EVENTS = WT_EVENTS
tables
T_OUTTAB = WT_ITAB.
endform. " PRINT_ALV_DATA
*---------------------------------------------------------------------*
* FORM ALV_TOP_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> R_DYDO *
* --> TO *
* --> CL_DD_DOCUMENT *
*---------------------------------------------------------------------*
form ALV_TOP_OF_PAGE using CL_DD type ref to CL_DD_DOCUMENT.
* SET PF-STATUS 'STANDARD1'.
data: M_P type I.
data: M_BUFF type STRING.
*表头其实完全可以是一个html文件,自己使用html语言进行格式控制
M_BUFF = '<html>'.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
* CONCATENATE '<body bgcolor="#008000">' INTO M_BUFF.
*
** M_BUFF = '<body background="BACKGROUND.GIF">'.
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
M_BUFF = '<center><font size="5">库存配套分析表</font></center>'.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
** CONCATENATE '客户名称:' KNA1-NAME1 KNA1-NAME2 '<BR>' INTO M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
*
** CONCATENATE 'SAP报价单号:' WT_VBAP_01-VBELN '<BR>' INTO M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
* CONCATENATE '字段说明:1)交货已完成:X代表已经全部服务确认' '<BR>'
*INTO M_BUFF.
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
**文字移动
* CONCATENATE '<marquee
*behavior=alternate>啦啦啦,我来回走耶!</marquee> ' '<BR>' INTO
*M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
* CONCATENATE '选择参数:为1 删除交货已完成 为2 删除相等无误的 为3
*删除完成以及无误的' '<BR>' INTO M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
* SELECT SINGLE * FROM T001
* WHERE BUKRS = WS_VBELN
* AND SPRAS = '1'.
*
concatenate '报表日期 :' SY-DATUM '<BR>' into M_BUFF.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
data: WTL_NAME1 like T001W-NAME1.
clear WTL_NAME1.
select single NAME1
into WTL_NAME1
from T001W
where WERKS eq P_WERKS.
concatenate '工 厂:' P_WERKS WTL_NAME1 '<BR>' into M_BUFF.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
data: WTL_NAME2 like T001W-NAME1.
clear WTL_NAME2.
select single NAME1
into WTL_NAME2
from T001W
where WERKS eq X_WERKS.
concatenate '附加工厂1:' X_WERKS WTL_NAME2 '<BR>' into M_BUFF.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
data: WTL_NAME3 like T001W-NAME1.
clear WTL_NAME3.
select single NAME1
into WTL_NAME3
from T001W
where WERKS eq Z_WERKS.
concatenate '附加工厂2:' Z_WERKS WTL_NAME3 '<BR>' into M_BUFF.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
* M_BUFF = '</body>'.
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
*
M_BUFF = '</html>'.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
endform. "ALV_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form GET_KCDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WT_ITAB_IDNRK text
* <--P_WT_ITAB_LABST text
* <--P_WT_ITAB_LABST_01 text
* <--P_WT_ITAB_LABST_02 text
*----------------------------------------------------------------------*
form GET_KCDATA using P_WT_ITAB_IDNRK
changing P_WT_ITAB_LABST
P_WT_ITAB_LABST_01
P_WT_ITAB_LABST_02.
data: WTL_RESULT type C.
clear WTL_RESULT.
data: begin of WTL_ITAB_101 occurs 0,
MANDT like MARD-MANDT,
MATNR like MARD-MATNR,
WERKS like MARD-WERKS,
LGORT like MARD-LGORT,
LABST like MARD-LABST,
INSME like MARD-INSME,
DISKZ like MARD-DISKZ,
KLABS like MARD-KLABS.
data: end of WTL_ITAB_101.
select MANDT MATNR WERKS LGORT INSME LABST DISKZ KLABS
from MARD
into corresponding fields of table WTL_ITAB_101
where WERKS eq P_WERKS
and MATNR = P_WT_ITAB_IDNRK
and DISKZ <> '1'
order by MATNR .
P_WT_ITAB_LABST = 0.
* KSTOR = 0.
if WTL_ITAB_101[] is initial.
P_WT_ITAB_LABST = 0.
* KSTOR = 0.
endif.
loop at WTL_ITAB_101 .
P_WT_ITAB_LABST = P_WT_ITAB_LABST + WTL_ITAB_101-LABST +
WTL_ITAB_101-KLABS.
* KSTOR = KSTOR + ITAB_101-LABST + ITAB_101-klabs.
endloop.
*检查物料的工厂是否存在
perform CHECK_MAT using P_WT_ITAB_IDNRK
X_WERKS
changing WTL_RESULT.
*检查参考工厂1的库存
if WTL_RESULT ne 'X'.
select MANDT MATNR WERKS LGORT INSME LABST DISKZ KLABS
from MARD
into corresponding fields of table WTL_ITAB_101
where WERKS eq X_WERKS
and MATNR = P_WT_ITAB_IDNRK
and DISKZ <> '1'
order by MATNR .
if WTL_ITAB_101[] is initial.
P_WT_ITAB_LABST_01 = 0.
* KSTOR = 0.
endif.
loop at WTL_ITAB_101.
P_WT_ITAB_LABST_01 = P_WT_ITAB_LABST_01 + WTL_ITAB_101-LABST +
WTL_ITAB_101-KLABS.
* KSTOR = KSTOR + ITAB_101-LABST + ITAB_101-klabs.
endloop.
endif.
*检查参考工厂2
perform CHECK_MAT using P_WT_ITAB_IDNRK
Z_WERKS
changing WTL_RESULT.
*从参考工厂2中取数据
if WTL_RESULT ne 'X'.
select MANDT MATNR WERKS LGORT INSME LABST DISKZ KLABS
from MARD
into corresponding fields of table WTL_ITAB_101
where WERKS eq Z_WERKS
and MATNR = P_WT_ITAB_IDNRK
and DISKZ <> '1'
order by MATNR .
if WTL_ITAB_101[] is initial.
P_WT_ITAB_LABST_02 = 0.
* KSTOR = 0.
endif.
loop at WTL_ITAB_101.
P_WT_ITAB_LABST_02 = P_WT_ITAB_LABST_02 + WTL_ITAB_101-LABST +
WTL_ITAB_101-KLABS.
* KSTOR = KSTOR + ITAB_101-LABST + ITAB_101-klabs.
endloop.
endif.
endform. " GET_KCDATA
*&---------------------------------------------------------------------*
*& Form CHECK_MAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_CH_ITEM text
* -->P_X_WERKS text
* <--P_WTL_RESULT text
*----------------------------------------------------------------------*
form CHECK_MAT using P_CH_ITEM
P_X_WERKS
changing P_WTL_RESULT.
if P_X_WERKS ne P_WERKS.
select single *
from MARC
where MATNR eq P_CH_ITEM
and WERKS eq P_X_WERKS.
if SY-SUBRC ne SPACE.
P_WTL_RESULT = 'X'.
endif.
else.
P_WTL_RESULT = 'X'.
endif.
endform. " CHECK_MAT
message-id YMM
line-count 81
line-size 650. "207
************************************************************************
*INCLUDE
************************************************************************
include <LINE>.
************************************************************************
*DDIC
************************************************************************
tables:MARA,MARC,BKPF,MARD,MAST.
************************************************************************
*ALV层级关系定义
************************************************************************
type-pools: SLIS.
data: WT_FIELDCAT type SLIS_T_FIELDCAT_ALV,
WT_LAYOUT type SLIS_LAYOUT_ALV,
WT_EVENTS type SLIS_T_EVENT.
data: WS_EVENTS like line of WT_EVENTS,
IT_SORT type SLIS_T_SORTINFO_ALV with header line. "ALV 排序内表
************************************************************************
*DATA
************************************************************************
data: begin of WT_ITAB occurs 10,
MATNR like MARA-MATNR, "父件物料编码
IDNRK like MARA-MATNR, "子件物料编码
OJTXP like MAKT-MAKTX, "子件物料描述
MEINS like MARA-MEINS, "子件计量单位
MNGLG like STPOX-MNGLG,"子件用量
LABST like MARD-LABST, "子件库存量
LABST_01 like MARD-LABST, "附加工厂一库存量
LABST_02 like MARD-LABST. "附加工厂二库存量
data: end of WT_ITAB.
selection-screen begin of block B1 with frame title TEXT-001.
parameters: P_WERKS like MAST-WERKS obligatory default '2001'.
select-options: P_MATNR for MAST-MATNR. "物料号
parameters: P_STLAN like MAST-STLAN default '1',"BOM 用途
P_BMENG like STKO-BMENG,"需求数量
X_WERKS like MARC-WERKS obligatory default '2001',
Z_WERKS like MARC-WERKS obligatory default '2001'.
selection-screen end of block B1.
selection-screen begin of block B2 with frame title TEXT-002.
parameters: P_SING radiobutton group RAD1 default 'X'. "单层bom
parameters: P_MULT radiobutton group RAD1. "多层bom
selection-screen end of block B2.
initialization.
start-of-selection.
*得到物料的子项目
perform GET_DATA.
*打印该BOM的数据
perform PRINT_ALV_DATA.
end-of-selection.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form GET_DATA .
*数据定义
data: begin of WTL_MATNR occurs 0,
WERKS like MARC-WERKS,
MATNR like MARA-MATNR.
data: end of WTL_MATNR.
*展开BOM的字阶
data: WTL_STB like STPOX occurs 10 with header line.
select WERKS MATNR
appending corresponding fields of table WTL_MATNR
from MAST
where MATNR in P_MATNR
and WERKS eq P_WERKS.
*根据选项产生不同BOM的结构
*展多层BOM
if P_MULT eq 'X'.
loop at WTL_MATNR.
refresh WTL_STB.
clear WTL_STB.
call function 'CS_BOM_EXPL_MAT_V2'
exporting
CAPID = 'PP01' "BOM Application
DATUV = SY-DATUM "有效开始日
EMENG = P_BMENG "BASE QUANTITY数量
MTNRV = WTL_MATNR-MATNR
"MATERAILNUMBER物料
STLAN = P_STLAN "bom用途
* STLAL = P_STLAL
* CUOBJ = CUOBJ
MKTLS = 'X'
MEHRS = 'X' "多阶层bom展开
WERKS = WTL_MATNR-WERKS "'PDGM'工厂
tables
STB = WTL_STB "展开明细
exceptions
ALT_NOT_FOUND = 1
CALL_INVALID = 2
MATERIAL_NOT_FOUND = 3
MISSING_AUTHORIZATION = 4
NO_BOM_FOUND = 5
NO_PLANT_DATA = 6
NO_SUITABLE_BOM_FOUND = 7
others = 8.
if SY-SUBRC eq 0.
loop at WTL_STB.
WT_ITAB-MATNR = WTL_MATNR-MATNR.
WT_ITAB-OJTXP = WTL_STB-OJTXP.
WT_ITAB-IDNRK = WTL_STB-IDNRK.
WT_ITAB-MEINS = WTL_STB-MEINS.
WT_ITAB-MNGLG = WTL_STB-MNGLG.
* P_ITAB_ITEM-STLAL = -STLAL.
* P_ITAB_ITEM-STUFE = STB-STUFE.
*查找物料的库存
perform GET_KCDATA using WT_ITAB-IDNRK
changing WT_ITAB-LABST
WT_ITAB-LABST_01
WT_ITAB-LABST_02.
shift WT_ITAB-MATNR left deleting leading '0'. "去0
shift WT_ITAB-IDNRK left deleting leading '0'.
append WT_ITAB.
clear WT_ITAB.
endloop.
endif.
endloop.
endif.
*展单层BOM
if P_SING eq 'X'.
loop at WTL_MATNR.
call function 'CS_BOM_EXPL_MAT_V2'
exporting
CAPID = 'PP01' "BOM Application
DATUV = SY-DATUM
EMENG = P_BMENG "BASE QUANTITY
MTNRV = WTL_MATNR-MATNR "MATERAIL NUMBER
STLAN = P_STLAN
* STLAL = P_STLAL
* CUOBJ = CUOBJ
* MKTLS = 'X'
* MEHRS = 'X'
WERKS = WTL_MATNR-WERKS "'PDGM'
tables
STB = WTL_STB
exceptions
ALT_NOT_FOUND = 1
CALL_INVALID = 2
MATERIAL_NOT_FOUND = 3
MISSING_AUTHORIZATION = 4
NO_BOM_FOUND = 5
NO_PLANT_DATA = 6
NO_SUITABLE_BOM_FOUND = 7
others = 8.
if SY-SUBRC eq 0.
loop at WTL_STB.
WT_ITAB-MATNR = WTL_MATNR-MATNR.
WT_ITAB-OJTXP = WTL_STB-OJTXP.
WT_ITAB-IDNRK = WTL_STB-IDNRK.
WT_ITAB-MEINS = WTL_STB-MEINS.
WT_ITAB-MNGLG = WTL_STB-MNGLG.
* P_ITAB_ITEM-STLAL = -STLAL.
* P_ITAB_ITEM-STUFE = STB-STUFE.
perform GET_KCDATA using WT_ITAB-IDNRK
changing WT_ITAB-LABST
WT_ITAB-LABST_01
WT_ITAB-LABST_02.
shift WT_ITAB-MATNR left deleting leading '0'. "去0
shift WT_ITAB-IDNRK left deleting leading '0'.
append WT_ITAB.
clear WT_ITAB.
endloop.
endif.
endloop.
endif.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PRINT_ALV_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form PRINT_ALV_DATA .
data: WLT_FIELDCAT like line of WT_FIELDCAT.
* PERFORM FILL_EVENTCAT_ALV.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'MATNR'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '父件物料编码'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'IDNRK'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件物料编码'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'OJTXP'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件物料描述'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'MEINS'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '单位'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'MNGLG'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件用量'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = ' LABST'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '子件库存量'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'LABST_01'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '附加工厂一库存量'.
append WLT_FIELDCAT to WT_FIELDCAT.
clear WLT_FIELDCAT.
WLT_FIELDCAT-FIELDNAME = 'LABST_02'.
WLT_FIELDCAT-TABNAME = 'WT_ITAB'.
WLT_FIELDCAT-NO_OUT = ' '.
WLT_FIELDCAT-SELTEXT_L = '附加工厂二库存量'.
append WLT_FIELDCAT to WT_FIELDCAT.
WT_LAYOUT-ZEBRA = 'X'.
WT_LAYOUT-F2CODE = '&ETA'.
WT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
I_CALLBACK_PROGRAM = SY-CPROG
IS_LAYOUT = WT_LAYOUT
I_CALLBACK_HTML_TOP_OF_PAGE = 'ALV_TOP_OF_PAGE'
* I_callback_pf_status_set = 'STANDARD1'
I_DEFAULT = 'X'
I_SAVE = 'X'
* I_CALLBACK_USER_COMMAND = 'PROCESS_USER_COMMAND'
IT_FIELDCAT = WT_FIELDCAT[]
IT_EVENTS = WT_EVENTS
tables
T_OUTTAB = WT_ITAB.
endform. " PRINT_ALV_DATA
*---------------------------------------------------------------------*
* FORM ALV_TOP_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> R_DYDO *
* --> TO *
* --> CL_DD_DOCUMENT *
*---------------------------------------------------------------------*
form ALV_TOP_OF_PAGE using CL_DD type ref to CL_DD_DOCUMENT.
* SET PF-STATUS 'STANDARD1'.
data: M_P type I.
data: M_BUFF type STRING.
*表头其实完全可以是一个html文件,自己使用html语言进行格式控制
M_BUFF = '<html>'.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
* CONCATENATE '<body bgcolor="#008000">' INTO M_BUFF.
*
** M_BUFF = '<body background="BACKGROUND.GIF">'.
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
M_BUFF = '<center><font size="5">库存配套分析表</font></center>'.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
** CONCATENATE '客户名称:' KNA1-NAME1 KNA1-NAME2 '<BR>' INTO M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
*
** CONCATENATE 'SAP报价单号:' WT_VBAP_01-VBELN '<BR>' INTO M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
* CONCATENATE '字段说明:1)交货已完成:X代表已经全部服务确认' '<BR>'
*INTO M_BUFF.
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
**文字移动
* CONCATENATE '<marquee
*behavior=alternate>啦啦啦,我来回走耶!</marquee> ' '<BR>' INTO
*M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
* CONCATENATE '选择参数:为1 删除交货已完成 为2 删除相等无误的 为3
*删除完成以及无误的' '<BR>' INTO M_BUFF.
*
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
* SELECT SINGLE * FROM T001
* WHERE BUKRS = WS_VBELN
* AND SPRAS = '1'.
*
concatenate '报表日期 :' SY-DATUM '<BR>' into M_BUFF.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
data: WTL_NAME1 like T001W-NAME1.
clear WTL_NAME1.
select single NAME1
into WTL_NAME1
from T001W
where WERKS eq P_WERKS.
concatenate '工 厂:' P_WERKS WTL_NAME1 '<BR>' into M_BUFF.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
data: WTL_NAME2 like T001W-NAME1.
clear WTL_NAME2.
select single NAME1
into WTL_NAME2
from T001W
where WERKS eq X_WERKS.
concatenate '附加工厂1:' X_WERKS WTL_NAME2 '<BR>' into M_BUFF.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
data: WTL_NAME3 like T001W-NAME1.
clear WTL_NAME3.
select single NAME1
into WTL_NAME3
from T001W
where WERKS eq Z_WERKS.
concatenate '附加工厂2:' Z_WERKS WTL_NAME3 '<BR>' into M_BUFF.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
* M_BUFF = '</body>'.
* CALL METHOD CL_DD->HTML_INSERT
* EXPORTING
* CONTENTS = M_BUFF
* CHANGING
* POSITION = M_P.
*
M_BUFF = '</html>'.
call method CL_DD->HTML_INSERT
exporting
CONTENTS = M_BUFF
changing
POSITION = M_P.
endform. "ALV_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form GET_KCDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WT_ITAB_IDNRK text
* <--P_WT_ITAB_LABST text
* <--P_WT_ITAB_LABST_01 text
* <--P_WT_ITAB_LABST_02 text
*----------------------------------------------------------------------*
form GET_KCDATA using P_WT_ITAB_IDNRK
changing P_WT_ITAB_LABST
P_WT_ITAB_LABST_01
P_WT_ITAB_LABST_02.
data: WTL_RESULT type C.
clear WTL_RESULT.
data: begin of WTL_ITAB_101 occurs 0,
MANDT like MARD-MANDT,
MATNR like MARD-MATNR,
WERKS like MARD-WERKS,
LGORT like MARD-LGORT,
LABST like MARD-LABST,
INSME like MARD-INSME,
DISKZ like MARD-DISKZ,
KLABS like MARD-KLABS.
data: end of WTL_ITAB_101.
select MANDT MATNR WERKS LGORT INSME LABST DISKZ KLABS
from MARD
into corresponding fields of table WTL_ITAB_101
where WERKS eq P_WERKS
and MATNR = P_WT_ITAB_IDNRK
and DISKZ <> '1'
order by MATNR .
P_WT_ITAB_LABST = 0.
* KSTOR = 0.
if WTL_ITAB_101[] is initial.
P_WT_ITAB_LABST = 0.
* KSTOR = 0.
endif.
loop at WTL_ITAB_101 .
P_WT_ITAB_LABST = P_WT_ITAB_LABST + WTL_ITAB_101-LABST +
WTL_ITAB_101-KLABS.
* KSTOR = KSTOR + ITAB_101-LABST + ITAB_101-klabs.
endloop.
*检查物料的工厂是否存在
perform CHECK_MAT using P_WT_ITAB_IDNRK
X_WERKS
changing WTL_RESULT.
*检查参考工厂1的库存
if WTL_RESULT ne 'X'.
select MANDT MATNR WERKS LGORT INSME LABST DISKZ KLABS
from MARD
into corresponding fields of table WTL_ITAB_101
where WERKS eq X_WERKS
and MATNR = P_WT_ITAB_IDNRK
and DISKZ <> '1'
order by MATNR .
if WTL_ITAB_101[] is initial.
P_WT_ITAB_LABST_01 = 0.
* KSTOR = 0.
endif.
loop at WTL_ITAB_101.
P_WT_ITAB_LABST_01 = P_WT_ITAB_LABST_01 + WTL_ITAB_101-LABST +
WTL_ITAB_101-KLABS.
* KSTOR = KSTOR + ITAB_101-LABST + ITAB_101-klabs.
endloop.
endif.
*检查参考工厂2
perform CHECK_MAT using P_WT_ITAB_IDNRK
Z_WERKS
changing WTL_RESULT.
*从参考工厂2中取数据
if WTL_RESULT ne 'X'.
select MANDT MATNR WERKS LGORT INSME LABST DISKZ KLABS
from MARD
into corresponding fields of table WTL_ITAB_101
where WERKS eq Z_WERKS
and MATNR = P_WT_ITAB_IDNRK
and DISKZ <> '1'
order by MATNR .
if WTL_ITAB_101[] is initial.
P_WT_ITAB_LABST_02 = 0.
* KSTOR = 0.
endif.
loop at WTL_ITAB_101.
P_WT_ITAB_LABST_02 = P_WT_ITAB_LABST_02 + WTL_ITAB_101-LABST +
WTL_ITAB_101-KLABS.
* KSTOR = KSTOR + ITAB_101-LABST + ITAB_101-klabs.
endloop.
endif.
endform. " GET_KCDATA
*&---------------------------------------------------------------------*
*& Form CHECK_MAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_CH_ITEM text
* -->P_X_WERKS text
* <--P_WTL_RESULT text
*----------------------------------------------------------------------*
form CHECK_MAT using P_CH_ITEM
P_X_WERKS
changing P_WTL_RESULT.
if P_X_WERKS ne P_WERKS.
select single *
from MARC
where MATNR eq P_CH_ITEM
and WERKS eq P_X_WERKS.
if SY-SUBRC ne SPACE.
P_WTL_RESULT = 'X'.
endif.
else.
P_WTL_RESULT = 'X'.
endif.
endform. " CHECK_MAT