*&---------------------------------------------------------------------*
*& Report ZTEST135
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report ztest135 no standard page heading.
*data:lv_price type c.
*authority-check object 'ZTEST01'
* id 'ACTVT' field '02'.
*if sy-subrc eq 0.
* lv_price = 'X'.
*endif.
*
*WRITE: lv_price .
type-pools: slis.
tables: mast, "BOM 链接物料
mara, "常规物料数据
stko, "BOM 表头
makt. "物料描述
data: stb like stpox occurs 0 with header line,
wa_alv_field type slis_fieldcat_alv, "列描述内表,列清单
wa_alv_fieldcat type slis_t_fieldcat_alv, "定义内表
layout type slis_layout_alv,
gs_layout type slis_layout_alv,
gt_list_top_of_page type slis_t_listheader,
counter type i value 0,
g_repid like sy-repid,
dc(1) type c value 'X', "是否多层展开默为多层展开
g_user_command type slis_formname value 'USER_COMMAND'.
data: begin of selpool.
include structure cstmat.
data: end of selpool.
data: dstst_flg like csdata-xfeld. "BOM 帮助字段
data: begin of it_data occurs 0,
level(20) type c,
stufe like stpox-stufe, "层次
matnr like mara-matnr, "父件物料编码
ojtxb(80) type c, "父件物料描述
bmeng type i, "BOM 中的基本数量
idnrk like stpox-idnrk, "子件物料编码
ojtxp(80) type c, "子件物料描述
alprf like stpo-alprf, "优先级
ewahr like stpo-ewahr, "使用可能性
stlan like stpox-stlan, "BOM 用途
stlal like stpox-stlal, "可选的BOM
alpgr like stpox-alpgr, "替代组
mtart like stpox-mtart, "物料类型
mmein like stpox-mmein, "基本计量单位
stprs like stpox-stprs, "标准价格
mnglg like stpox-mnglg, "以基本计量单位为准的已计算的组件数量
mngko like stpox-mngko, "以组件计量单位为准的已计算的组件数量
menge like stpox-menge, "组件数量
datuv like stpox-datuv, "开始生效/有效截止日期
aennr like stpox-aennr, "更改编号
andat like stpox-andat, "日期记录创建于
annam like stpox-annam, "创建记录的用户
ausch like stpox-ausch, "工序报废
avoau like stpox-avoau, "工序废品
ntgew like mara-ntgew, "净重
brgew like mara-brgew, "毛重
weigh like mara-brgew, "重量 = BOM 用量 * 单重
stawn like marc-stawn, "外贸的商品代码和进口代码
stawt(200) type c, "海关编码描述
sel type c,
end of it_data.
data: begin of matcat occurs 50.
include structure cscmat.
data: end of matcat.
data: begin of mats.
include structure cscmat.
data: end of mats.
data: begin of dllh_data,
matnr like mara-matnr, "物料编码
bmeng type i, "BOM 中的基本数量
end of dllh_data.
data: tdllh_data like dllh_data occurs 0.
data: begin of wlxx_data,
matnr like mara-matnr, "物料编码
normt like mara-normt, "延伸机种,即机型
maktx(80) type c, "物料描述
groes like mara-groes, "描述补充
ntgew like mara-ntgew, "净重
brgew like mara-brgew, "毛重
stawn like marc-stawn, "外贸的商品代码和进口代码
end of wlxx_data.
data: twlxx_data like wlxx_data occurs 0.
data: begin of hgbm_data,
stawn like t604t-stawn, "外贸的商品代码和进口代码
text1(200) type c, "描述
text2 like t604t-text2, "描述
text3 like t604t-text3, "描述
text4 like t604t-text4, "描述
text5 like t604t-text5, "描述
text6 like t604t-text6, "描述
text7 like t604t-text7, "描述
end of hgbm_data.
data: thgbm_data like hgbm_data occurs 0.
selection-screen begin of block scr1 with frame title text-001.
parameters :
pm_werks like marc-werks memory id wrk.
*SELECT-OPTIONS: S_WERKS FOR MAST-WERKS DEFAULT '2021'. "
**工厂
select-options: s_matnr for mara-matnr, "
*成品编码
s_mtart for mara-mtart, "
*物料类型
s_matkl for mara-matkl, "
*物料组
s_maktx for makt-maktx, "
*物料描述
s_normt for mara-normt. "
*机型
parameters: p_emeng like stko-bmeng ,"OBLIGATORY DEFAULT '1', "Required quantity
p_stlan like mast-stlan default '1'. "BOM 用途
selection-screen skip 1.
parameters:rb_mcb radiobutton group rg1 default 'X', "多层展开
rb_scb radiobutton group rg1. "单层展开
selection-screen skip 1.
parameters:rb_ytd radiobutton group rg2 default 'X', "有替代料
rb_wtd radiobutton group rg2. "无替代料
selection-screen skip 1.
parameters:rb_all radiobutton group rg3, "显示所有列
rb_hgy radiobutton group rg3 default 'X'. "仅显示海关专用列
selection-screen skip 1.
parameters:rb_ybc radiobutton group rg4, "仅计算原材料重量
rb_wbc radiobutton group rg4 default 'X'. "计算所有物料重量
selection-screen end of block scr1.
initialization.
g_repid = sy-repid.
start-of-selection.
select mara~matnr
into corresponding fields of table tdllh_data "取得物料编码内表
from mara
inner join makt on mara~matnr = makt~matnr
where mara~matnr in s_matnr and mara~mtart in s_mtart and mara~normt
in s_normt and makt~maktx in s_maktx and mara~matkl in s_matkl and makt~spras = sy-langu.
sort tdllh_data by matnr.
select t604t~stawn t604t~text1 t604t~text2 t604t~text3 t604t~text4 t604t~text5 t604t~text6 t604t~text7
into table thgbm_data "取得海关编码及描述内表
from t604t
where t604t~spras = sy-langu.
sort thgbm_data by stawn.
loop at thgbm_data into hgbm_data.
concatenate hgbm_data-text1 hgbm_data-text2 hgbm_data-text3 hgbm_data-text4 hgbm_data-text5 hgbm_data-text6 hgbm_data-text7 into hgbm_data-text1.
modify thgbm_data from hgbm_data.
endloop.
if rb_mcb = ''. "如果选择为单层展开则把原来的默认值由X 改为空
dc = ''.
endif.
clear: dllh_data.
loop at tdllh_data into dllh_data. "循环每个物料号
clear: stb.
call function 'CS_BOM_EXPL_MAT_V2'
exporting
capid = 'PP01' "BOM 应用程序
datuv = sy-datum "有效起始日
emeng = p_emeng " 基本数量 Required quantity STKO-BMENG
mtnrv = dllh_data-matnr "成品号或半成品号
stlan = '1' "BOM 用途,1 代表生产
stlal = '' "可选BOM
mktls = 'X'
mehrs = dc "是否多层展开,'X' 代表多层
rndkz = '1' "Round off: ' '=always, '1'=never, '2'=only levels > 1 是否取整
werks = pm_werks "工厂
importing
topmat = selpool "开始BOM 展开的物料显示
dstst = dstst_flg "BOM 帮助字段
tables
stb = stb
matcat = matcat "下面含有组件的物料存放在该内表对应 STB-TTIDX 在类别表内的索引﹐标志直属哪个物料下的 BOM
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.
loop at stb.
it_data-stufe = stb-stufe. "层次
it_data-ojtxb = stb-ojtxb. "父件描述
it_data-bmeng = selpool-bmeng.
it_data-idnrk = stb-idnrk. "子件编码
it_data-ojtxp = stb-ojtxp. "子件描述
it_data-alprf = stb-alprf. "优先级
it_data-ewahr = stb-ewahr. "使用可能性
it_data-stlan = stb-stlan. "BOM 用途
it_data-stlal = stb-stlal. "可选的BOM
it_data-alpgr = stb-alpgr. "替代组
it_data-mtart = stb-mtart. "物料类型
it_data-mmein = stb-mmein. "基本计量单位
it_data-stprs = stb-stprs. "标准价格
it_data-mnglg = stb-mnglg. "以基本计量单位为准的已计算的组件数量
it_data-mngko = stb-mngko. "以组件计量单位为准的已计算的组件数量
it_data-menge = stb-menge. "组件数量
it_data-ausch = stb-ausch. "工序报废
it_data-avoau = stb-avoau. "工序废品
it_data-datuv = stb-datuv. "生效日期
it_data-stawn = stb-stawn. "外贸的商品代码和进口代码
it_data-aennr = stb-aennr. "更改编号
it_data-andat = stb-andat. "创建于
it_data-annam = stb-annam. "创建者
read table matcat into mats with key index = stb-ttidx. " 根据STB-TTIDX 找MATCAT 中对应的 INDEX 可以得到其相对的上阶物料号
it_data-matnr = mats-matnr. "相对的父件编码
append it_data.
endloop.
endloop.
*SORT IT_DATA BY MATNR STUFE ALPGR ALPRF IDNRK. "按成品号层 次 号 替 代组优先级 原料号排序
if rb_wtd = ''. "如果选择无替代料则把替代料删除
delete it_data where alpgr <> '' and alprf <> '1'. "ALPGR 替代组 ALPRF 为优先组 1 为第一优先使用可性为 100 视为主料
endif.
select mara~matnr mara~normt makt~maktx mara~groes mara~ntgew mara~brgew marc~stawn
into table twlxx_data "取得物料信息
from mara
inner join makt on mara~matnr = makt~matnr
inner join marc on mara~matnr = marc~matnr
where makt~spras = sy-langu and marc~werks = '1000'.
sort twlxx_data by matnr.
loop at it_data.
clear: wlxx_data,hgbm_data.
read table twlxx_data into wlxx_data with key matnr = it_data-idnrk
binary search.
concatenate wlxx_data-maktx wlxx_data-groes into wlxx_data-maktx.
it_data-ojtxp = wlxx_data-maktx. "连接后的完全的组件物料描述
it_data-ntgew = wlxx_data-ntgew.
if rb_wbc = 'X' and it_data-mtart <> '805'.
it_data-weigh = it_data-mngko * wlxx_data-ntgew.
endif.
modify it_data.
endloop.
loop at it_data.
clear: wlxx_data,hgbm_data.
read table twlxx_data into wlxx_data with key matnr = it_data-matnr
binary search.
concatenate wlxx_data-maktx wlxx_data-groes into wlxx_data-maktx.
it_data-ojtxb = wlxx_data-maktx. "连接后的完全的父件物料描述
read table thgbm_data into hgbm_data with key stawn = it_data-stawn
binary search.
it_data-stawt = hgbm_data-text1. "根据海关编码得到相应的描述
data : temp type i.
clear :temp , it_data-level.
temp = it_data-stufe.
do temp times.
concatenate '.' it_data-level into it_data-level.
enddo.
data c(10) type c.
clear c.
c = it_data-stufe.
concatenate it_data-level c into it_data-level.
condense it_data-level no-gaps.
modify it_data.
endloop.
perform comment_build changing gt_list_top_of_page[].
perform sub_fieldcat.
perform layout_init changing gs_layout.
call function 'REUSE_ALV_GRID_DISPLAY' "调用ALV 显示表单数据
exporting
i_callback_program = sy-repid
i_callback_top_of_page = 'TOP_OF_PAGE'
it_fieldcat = wa_alv_fieldcat
is_layout = gs_layout
i_callback_user_command = g_user_command
tables
t_outtab = it_data
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
*&---------------------------------------------------------------------*
*& Form SUB_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form sub_fieldcat.
perform add_field using 'LEVEL' '层次' 'C111' 'X'.
perform add_field using 'MATNR' '父件编码' 'C111' 'X'.
perform add_field using 'OJTXB' '父件描述' 'C111' 'X'.
perform add_field using 'BMENG' '基本数量' 'C602' 'X'.
perform add_field using 'IDNRK' '子件编码' 'C111' 'X'.
perform add_field using 'OJTXP' '子件描述' 'C111' 'X'.
* PERFORM ADD_FIELD USING 'MNGLG' 'MNGLG' 'C111' 'X'.
perform add_field using 'MNGKO' '用量' 'C111' 'X'.
perform add_field using 'NTGEW' '单重' 'C111' 'X'.
perform add_field using 'WEIGH' '重量' 'C111' 'X'.
perform add_field using 'STAWN' '海关编码' 'C111' ''. "外贸的商品代码和进口代码显示前导 0
perform add_field using 'STAWT' '描述' 'C111' 'X'. "外贸的商品代码和进口代码描述
if rb_all = 'X'.
perform add_field using 'MENGE' '组件数量' 'C111' 'X'.
perform add_field using 'MMEIN' '基本计量单位' 'C111' 'X'.
perform add_field using 'ALPGR' '替代组' 'C111' ''.
perform add_field using 'ALPRF' '优先级' 'C111' 'X'.
perform add_field using 'EWAHR' '使用可能性' 'C111' 'X'.
perform add_field using 'MTART' '物料类型' 'C111' 'X'.
perform add_field using 'AVOAU' '工序废品' 'C111' 'X'.
perform add_field using 'AUSCH' '工序报废' 'C111' 'X'.
perform add_field using 'STLAN' 'BOM 用途' 'C111' 'X'.
perform add_field using 'STLAL' '可选的BOM' 'C111' 'X'.
perform add_field using 'DATUV' '生效日期' 'C111' 'X'.
perform add_field using 'AENNR' '更改编号' 'C111' 'X'.
perform add_field using 'ANDAT' '创建于' 'C111' 'X'.
perform add_field using 'ANNAM' '创建者' 'C111' 'X'.
endif.
endform. "SUB_FIELDCAT
*&---------------------------------------------------------------------*
*& Form ADD_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->I_FIELDNAME text
* -->I_TEXT text
* -->I_NO text
* -->I_ZERO text
*----------------------------------------------------------------------*
form add_field using i_fieldname type slis_fieldname i_text type string i_no type c i_zero type c.
clear wa_alv_field.
wa_alv_field-fieldname = i_fieldname.
wa_alv_field-tabname = 'IT_DATA'.
wa_alv_field-ddictxt = 'L'.
wa_alv_field-no_zero = i_zero. "为空时显示前导0 为X 时不显示前导0
wa_alv_field-seltext_l = i_text.
if wa_alv_field-fieldname = 'BMENG'.
wa_alv_field-emphasize = 'C602'.
endif.
if wa_alv_field-fieldname = 'MNGKO'.
wa_alv_field-emphasize = 'C510'.
endif.
append wa_alv_field to wa_alv_fieldcat.
endform. "ADD_FIELD
*&---------------------------------------------------------------------*
*& Form LAYOUT_INIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RS_LAYOUT text
*----------------------------------------------------------------------*
form layout_init changing rs_layout type slis_layout_alv.
rs_layout-colwidth_optimize = 'X'.
rs_layout-box_fieldname = 'SEL'.
rs_layout-zebra = 'X'.
rs_layout-detail_popup = 'X'.
endform. "LAYOUT_INIT
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = gt_list_top_of_page.
endform. "TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form COMMENT_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->LT_TOP_OF_PAGE text
*----------------------------------------------------------------------*
form comment_build changing lt_top_of_page type slis_t_listheader.
data ls_line type slis_listheader.
clear ls_line.
ls_line-typ = 'H'.
ls_line-info = 'BOM 展开'.
append ls_line to lt_top_of_page.
clear ls_line.
ls_line-typ = 'S'.
ls_line-key = '做成时间:'.
ls_line-info = sy-datum.
append ls_line to lt_top_of_page.
ls_line-key = '做成者:'.
ls_line-info = sy-uname.
append ls_line to lt_top_of_page.
endform. "COMMENT_BUILD
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.
when '&IC1'. " SAP STANDARD CODE FOR DOUBLE-CLICKING
if rs_selfield-sel_tab_field = 'IT_DATA-MATNR'.
set parameter id 'MAT' field rs_selfield-value.
call transaction 'CS03' and skip first screen.
endif.
if rs_selfield-sel_tab_field = 'IT_DATA-IDNRK'.
set parameter id 'MAT' field rs_selfield-value.
call transaction 'MM03' and skip first screen.
endif.
if rs_selfield-sel_tab_field = 'IT_DATA-MBLNR'.
set parameter id 'MBN' field rs_selfield-value.
call transaction 'MB51' and skip first screen.
endif.
endcase.
endform. "USER_COMMAND
*& Report ZTEST135
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report ztest135 no standard page heading.
*data:lv_price type c.
*authority-check object 'ZTEST01'
* id 'ACTVT' field '02'.
*if sy-subrc eq 0.
* lv_price = 'X'.
*endif.
*
*WRITE: lv_price .
type-pools: slis.
tables: mast, "BOM 链接物料
mara, "常规物料数据
stko, "BOM 表头
makt. "物料描述
data: stb like stpox occurs 0 with header line,
wa_alv_field type slis_fieldcat_alv, "列描述内表,列清单
wa_alv_fieldcat type slis_t_fieldcat_alv, "定义内表
layout type slis_layout_alv,
gs_layout type slis_layout_alv,
gt_list_top_of_page type slis_t_listheader,
counter type i value 0,
g_repid like sy-repid,
dc(1) type c value 'X', "是否多层展开默为多层展开
g_user_command type slis_formname value 'USER_COMMAND'.
data: begin of selpool.
include structure cstmat.
data: end of selpool.
data: dstst_flg like csdata-xfeld. "BOM 帮助字段
data: begin of it_data occurs 0,
level(20) type c,
stufe like stpox-stufe, "层次
matnr like mara-matnr, "父件物料编码
ojtxb(80) type c, "父件物料描述
bmeng type i, "BOM 中的基本数量
idnrk like stpox-idnrk, "子件物料编码
ojtxp(80) type c, "子件物料描述
alprf like stpo-alprf, "优先级
ewahr like stpo-ewahr, "使用可能性
stlan like stpox-stlan, "BOM 用途
stlal like stpox-stlal, "可选的BOM
alpgr like stpox-alpgr, "替代组
mtart like stpox-mtart, "物料类型
mmein like stpox-mmein, "基本计量单位
stprs like stpox-stprs, "标准价格
mnglg like stpox-mnglg, "以基本计量单位为准的已计算的组件数量
mngko like stpox-mngko, "以组件计量单位为准的已计算的组件数量
menge like stpox-menge, "组件数量
datuv like stpox-datuv, "开始生效/有效截止日期
aennr like stpox-aennr, "更改编号
andat like stpox-andat, "日期记录创建于
annam like stpox-annam, "创建记录的用户
ausch like stpox-ausch, "工序报废
avoau like stpox-avoau, "工序废品
ntgew like mara-ntgew, "净重
brgew like mara-brgew, "毛重
weigh like mara-brgew, "重量 = BOM 用量 * 单重
stawn like marc-stawn, "外贸的商品代码和进口代码
stawt(200) type c, "海关编码描述
sel type c,
end of it_data.
data: begin of matcat occurs 50.
include structure cscmat.
data: end of matcat.
data: begin of mats.
include structure cscmat.
data: end of mats.
data: begin of dllh_data,
matnr like mara-matnr, "物料编码
bmeng type i, "BOM 中的基本数量
end of dllh_data.
data: tdllh_data like dllh_data occurs 0.
data: begin of wlxx_data,
matnr like mara-matnr, "物料编码
normt like mara-normt, "延伸机种,即机型
maktx(80) type c, "物料描述
groes like mara-groes, "描述补充
ntgew like mara-ntgew, "净重
brgew like mara-brgew, "毛重
stawn like marc-stawn, "外贸的商品代码和进口代码
end of wlxx_data.
data: twlxx_data like wlxx_data occurs 0.
data: begin of hgbm_data,
stawn like t604t-stawn, "外贸的商品代码和进口代码
text1(200) type c, "描述
text2 like t604t-text2, "描述
text3 like t604t-text3, "描述
text4 like t604t-text4, "描述
text5 like t604t-text5, "描述
text6 like t604t-text6, "描述
text7 like t604t-text7, "描述
end of hgbm_data.
data: thgbm_data like hgbm_data occurs 0.
selection-screen begin of block scr1 with frame title text-001.
parameters :
pm_werks like marc-werks memory id wrk.
*SELECT-OPTIONS: S_WERKS FOR MAST-WERKS DEFAULT '2021'. "
**工厂
select-options: s_matnr for mara-matnr, "
*成品编码
s_mtart for mara-mtart, "
*物料类型
s_matkl for mara-matkl, "
*物料组
s_maktx for makt-maktx, "
*物料描述
s_normt for mara-normt. "
*机型
parameters: p_emeng like stko-bmeng ,"OBLIGATORY DEFAULT '1', "Required quantity
p_stlan like mast-stlan default '1'. "BOM 用途
selection-screen skip 1.
parameters:rb_mcb radiobutton group rg1 default 'X', "多层展开
rb_scb radiobutton group rg1. "单层展开
selection-screen skip 1.
parameters:rb_ytd radiobutton group rg2 default 'X', "有替代料
rb_wtd radiobutton group rg2. "无替代料
selection-screen skip 1.
parameters:rb_all radiobutton group rg3, "显示所有列
rb_hgy radiobutton group rg3 default 'X'. "仅显示海关专用列
selection-screen skip 1.
parameters:rb_ybc radiobutton group rg4, "仅计算原材料重量
rb_wbc radiobutton group rg4 default 'X'. "计算所有物料重量
selection-screen end of block scr1.
initialization.
g_repid = sy-repid.
start-of-selection.
select mara~matnr
into corresponding fields of table tdllh_data "取得物料编码内表
from mara
inner join makt on mara~matnr = makt~matnr
where mara~matnr in s_matnr and mara~mtart in s_mtart and mara~normt
in s_normt and makt~maktx in s_maktx and mara~matkl in s_matkl and makt~spras = sy-langu.
sort tdllh_data by matnr.
select t604t~stawn t604t~text1 t604t~text2 t604t~text3 t604t~text4 t604t~text5 t604t~text6 t604t~text7
into table thgbm_data "取得海关编码及描述内表
from t604t
where t604t~spras = sy-langu.
sort thgbm_data by stawn.
loop at thgbm_data into hgbm_data.
concatenate hgbm_data-text1 hgbm_data-text2 hgbm_data-text3 hgbm_data-text4 hgbm_data-text5 hgbm_data-text6 hgbm_data-text7 into hgbm_data-text1.
modify thgbm_data from hgbm_data.
endloop.
if rb_mcb = ''. "如果选择为单层展开则把原来的默认值由X 改为空
dc = ''.
endif.
clear: dllh_data.
loop at tdllh_data into dllh_data. "循环每个物料号
clear: stb.
call function 'CS_BOM_EXPL_MAT_V2'
exporting
capid = 'PP01' "BOM 应用程序
datuv = sy-datum "有效起始日
emeng = p_emeng " 基本数量 Required quantity STKO-BMENG
mtnrv = dllh_data-matnr "成品号或半成品号
stlan = '1' "BOM 用途,1 代表生产
stlal = '' "可选BOM
mktls = 'X'
mehrs = dc "是否多层展开,'X' 代表多层
rndkz = '1' "Round off: ' '=always, '1'=never, '2'=only levels > 1 是否取整
werks = pm_werks "工厂
importing
topmat = selpool "开始BOM 展开的物料显示
dstst = dstst_flg "BOM 帮助字段
tables
stb = stb
matcat = matcat "下面含有组件的物料存放在该内表对应 STB-TTIDX 在类别表内的索引﹐标志直属哪个物料下的 BOM
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.
loop at stb.
it_data-stufe = stb-stufe. "层次
it_data-ojtxb = stb-ojtxb. "父件描述
it_data-bmeng = selpool-bmeng.
it_data-idnrk = stb-idnrk. "子件编码
it_data-ojtxp = stb-ojtxp. "子件描述
it_data-alprf = stb-alprf. "优先级
it_data-ewahr = stb-ewahr. "使用可能性
it_data-stlan = stb-stlan. "BOM 用途
it_data-stlal = stb-stlal. "可选的BOM
it_data-alpgr = stb-alpgr. "替代组
it_data-mtart = stb-mtart. "物料类型
it_data-mmein = stb-mmein. "基本计量单位
it_data-stprs = stb-stprs. "标准价格
it_data-mnglg = stb-mnglg. "以基本计量单位为准的已计算的组件数量
it_data-mngko = stb-mngko. "以组件计量单位为准的已计算的组件数量
it_data-menge = stb-menge. "组件数量
it_data-ausch = stb-ausch. "工序报废
it_data-avoau = stb-avoau. "工序废品
it_data-datuv = stb-datuv. "生效日期
it_data-stawn = stb-stawn. "外贸的商品代码和进口代码
it_data-aennr = stb-aennr. "更改编号
it_data-andat = stb-andat. "创建于
it_data-annam = stb-annam. "创建者
read table matcat into mats with key index = stb-ttidx. " 根据STB-TTIDX 找MATCAT 中对应的 INDEX 可以得到其相对的上阶物料号
it_data-matnr = mats-matnr. "相对的父件编码
append it_data.
endloop.
endloop.
*SORT IT_DATA BY MATNR STUFE ALPGR ALPRF IDNRK. "按成品号层 次 号 替 代组优先级 原料号排序
if rb_wtd = ''. "如果选择无替代料则把替代料删除
delete it_data where alpgr <> '' and alprf <> '1'. "ALPGR 替代组 ALPRF 为优先组 1 为第一优先使用可性为 100 视为主料
endif.
select mara~matnr mara~normt makt~maktx mara~groes mara~ntgew mara~brgew marc~stawn
into table twlxx_data "取得物料信息
from mara
inner join makt on mara~matnr = makt~matnr
inner join marc on mara~matnr = marc~matnr
where makt~spras = sy-langu and marc~werks = '1000'.
sort twlxx_data by matnr.
loop at it_data.
clear: wlxx_data,hgbm_data.
read table twlxx_data into wlxx_data with key matnr = it_data-idnrk
binary search.
concatenate wlxx_data-maktx wlxx_data-groes into wlxx_data-maktx.
it_data-ojtxp = wlxx_data-maktx. "连接后的完全的组件物料描述
it_data-ntgew = wlxx_data-ntgew.
if rb_wbc = 'X' and it_data-mtart <> '805'.
it_data-weigh = it_data-mngko * wlxx_data-ntgew.
endif.
modify it_data.
endloop.
loop at it_data.
clear: wlxx_data,hgbm_data.
read table twlxx_data into wlxx_data with key matnr = it_data-matnr
binary search.
concatenate wlxx_data-maktx wlxx_data-groes into wlxx_data-maktx.
it_data-ojtxb = wlxx_data-maktx. "连接后的完全的父件物料描述
read table thgbm_data into hgbm_data with key stawn = it_data-stawn
binary search.
it_data-stawt = hgbm_data-text1. "根据海关编码得到相应的描述
data : temp type i.
clear :temp , it_data-level.
temp = it_data-stufe.
do temp times.
concatenate '.' it_data-level into it_data-level.
enddo.
data c(10) type c.
clear c.
c = it_data-stufe.
concatenate it_data-level c into it_data-level.
condense it_data-level no-gaps.
modify it_data.
endloop.
perform comment_build changing gt_list_top_of_page[].
perform sub_fieldcat.
perform layout_init changing gs_layout.
call function 'REUSE_ALV_GRID_DISPLAY' "调用ALV 显示表单数据
exporting
i_callback_program = sy-repid
i_callback_top_of_page = 'TOP_OF_PAGE'
it_fieldcat = wa_alv_fieldcat
is_layout = gs_layout
i_callback_user_command = g_user_command
tables
t_outtab = it_data
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
*&---------------------------------------------------------------------*
*& Form SUB_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form sub_fieldcat.
perform add_field using 'LEVEL' '层次' 'C111' 'X'.
perform add_field using 'MATNR' '父件编码' 'C111' 'X'.
perform add_field using 'OJTXB' '父件描述' 'C111' 'X'.
perform add_field using 'BMENG' '基本数量' 'C602' 'X'.
perform add_field using 'IDNRK' '子件编码' 'C111' 'X'.
perform add_field using 'OJTXP' '子件描述' 'C111' 'X'.
* PERFORM ADD_FIELD USING 'MNGLG' 'MNGLG' 'C111' 'X'.
perform add_field using 'MNGKO' '用量' 'C111' 'X'.
perform add_field using 'NTGEW' '单重' 'C111' 'X'.
perform add_field using 'WEIGH' '重量' 'C111' 'X'.
perform add_field using 'STAWN' '海关编码' 'C111' ''. "外贸的商品代码和进口代码显示前导 0
perform add_field using 'STAWT' '描述' 'C111' 'X'. "外贸的商品代码和进口代码描述
if rb_all = 'X'.
perform add_field using 'MENGE' '组件数量' 'C111' 'X'.
perform add_field using 'MMEIN' '基本计量单位' 'C111' 'X'.
perform add_field using 'ALPGR' '替代组' 'C111' ''.
perform add_field using 'ALPRF' '优先级' 'C111' 'X'.
perform add_field using 'EWAHR' '使用可能性' 'C111' 'X'.
perform add_field using 'MTART' '物料类型' 'C111' 'X'.
perform add_field using 'AVOAU' '工序废品' 'C111' 'X'.
perform add_field using 'AUSCH' '工序报废' 'C111' 'X'.
perform add_field using 'STLAN' 'BOM 用途' 'C111' 'X'.
perform add_field using 'STLAL' '可选的BOM' 'C111' 'X'.
perform add_field using 'DATUV' '生效日期' 'C111' 'X'.
perform add_field using 'AENNR' '更改编号' 'C111' 'X'.
perform add_field using 'ANDAT' '创建于' 'C111' 'X'.
perform add_field using 'ANNAM' '创建者' 'C111' 'X'.
endif.
endform. "SUB_FIELDCAT
*&---------------------------------------------------------------------*
*& Form ADD_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->I_FIELDNAME text
* -->I_TEXT text
* -->I_NO text
* -->I_ZERO text
*----------------------------------------------------------------------*
form add_field using i_fieldname type slis_fieldname i_text type string i_no type c i_zero type c.
clear wa_alv_field.
wa_alv_field-fieldname = i_fieldname.
wa_alv_field-tabname = 'IT_DATA'.
wa_alv_field-ddictxt = 'L'.
wa_alv_field-no_zero = i_zero. "为空时显示前导0 为X 时不显示前导0
wa_alv_field-seltext_l = i_text.
if wa_alv_field-fieldname = 'BMENG'.
wa_alv_field-emphasize = 'C602'.
endif.
if wa_alv_field-fieldname = 'MNGKO'.
wa_alv_field-emphasize = 'C510'.
endif.
append wa_alv_field to wa_alv_fieldcat.
endform. "ADD_FIELD
*&---------------------------------------------------------------------*
*& Form LAYOUT_INIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->RS_LAYOUT text
*----------------------------------------------------------------------*
form layout_init changing rs_layout type slis_layout_alv.
rs_layout-colwidth_optimize = 'X'.
rs_layout-box_fieldname = 'SEL'.
rs_layout-zebra = 'X'.
rs_layout-detail_popup = 'X'.
endform. "LAYOUT_INIT
*&---------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form top_of_page.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = gt_list_top_of_page.
endform. "TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form COMMENT_BUILD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->LT_TOP_OF_PAGE text
*----------------------------------------------------------------------*
form comment_build changing lt_top_of_page type slis_t_listheader.
data ls_line type slis_listheader.
clear ls_line.
ls_line-typ = 'H'.
ls_line-info = 'BOM 展开'.
append ls_line to lt_top_of_page.
clear ls_line.
ls_line-typ = 'S'.
ls_line-key = '做成时间:'.
ls_line-info = sy-datum.
append ls_line to lt_top_of_page.
ls_line-key = '做成者:'.
ls_line-info = sy-uname.
append ls_line to lt_top_of_page.
endform. "COMMENT_BUILD
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.
when '&IC1'. " SAP STANDARD CODE FOR DOUBLE-CLICKING
if rs_selfield-sel_tab_field = 'IT_DATA-MATNR'.
set parameter id 'MAT' field rs_selfield-value.
call transaction 'CS03' and skip first screen.
endif.
if rs_selfield-sel_tab_field = 'IT_DATA-IDNRK'.
set parameter id 'MAT' field rs_selfield-value.
call transaction 'MM03' and skip first screen.
endif.
if rs_selfield-sel_tab_field = 'IT_DATA-MBLNR'.
set parameter id 'MBN' field rs_selfield-value.
call transaction 'MB51' and skip first screen.
endif.
endcase.
endform. "USER_COMMAND