‎2007 Sep 28 11:22 AM
‎2007 Sep 28 11:28 AM
‎2007 Sep 28 11:28 AM
‎2007 Sep 28 11:35 AM
Hi
This is the function module used in CS15 and you can pass the material
required and loop the output whatever is out of this
function module to be again passed on to it back. By passing this you can get each level of components and move up until the end.
It will give you where the material is used at different levels
Reward if usefull
Rgds
Raghav T
‎2007 Sep 28 11:39 AM
hi
good
go through this code
report z.
Explode assembly (including phantom assemblies up to last level) * Explode assembly (including phantom assemblies up to last level)
parameters: p_werks like t001w-werks obligatory, parameters: p_werks like t001w-werks obligatory,
p_matnr like mara-matnr obligatory. p_matnr like mara-matnr obligatory.
constants c_x value 'X'. constants c_x value 'X'.
data: begin of it_comp occurs 0, data: begin of it_comp occurs 0,
idnrk like stpox-idnrk, idnrk stpox-idnrk like,
ojtxp like stpox-ojtxp, ojtxp stpox-ojtxp like,
menge like stpox-menge, menge stpox-menge like,
meins like stpox-meins, meins stpox-meins like,
matkl like stpox-matmk, matkl stpox-matmk like,
end of it_comp. end of it_comp.
data: w_topmat like cstmat, data: w_topmat cstmat like,
*********************************
start-of-selection.
*********************************
perform explode_assembly. explode_assembly perform.
end-of-selection.
perform write_report. write_report perform.
top-of-page.
perform print_header. perform print_header.
&----
form print_header. print_header form.
write: /(18) 'Component'(h00), write: (18) 'Component' (h00)
(40) 'Description'(h01), (40) 'Description' (h01)
'Mat.Group'(h02), 'Mat.Group' (h02)
(18) 'Quantity'(h03). (18) 'Quantity' (h03).
uline.
endform.
&----
form write_report. write_report form.
write: / w_topmat-matnr under text-h00 color col_heading, write: / w_topmat-matnr under text-h00 col_heading color,
w_topmat-maktx under text-h01 color col_heading. w_topmat-maktx under text-h01 col_heading color.
loop at it_comp. at it_comp loop.
write: / write: /
it_comp-idnrk under text-h00, it_comp-idnrk under text-h00,
it_comp-ojtxp under text-h01, it_comp-ojtxp under text-h01,
it_comp-matkl under text-h02, it_comp-matkl under text-h02,
it_comp-menge unit it_comp-meins under text-h03, it_comp-menge unit it_comp-meins under text-h03,
it_comp-meins.
endloop.
uline.
endform.
&----
form explode_assembly. explode_assembly form.
data: it_stb like stpox occurs 0 with header line, data: it_stb like stpox occurs 0 with header line,
it_stb2 like stpox occurs 0 with header line, it_stb2 like stpox occurs 0 with header line,
it_stb3 like stpox occurs 0 with header line, it_stb3 like stpox occurs 0 with header line,
w_msg(255) type c. w_msg (255) type c.
Explode highest level: * Explode highest level:
call function 'CS_BOM_EXPL_MAT_V2' call function 'CS_BOM_EXPL_MAT_V2'
exporting
capid = 'PP01' capid = 'PP01'
cuols = c_x cuols = c_x
datuv = sy-datum datuv = sy-datum
knfba = c_x knfba = c_x
ksbvo = c_x ksbvo = c_x
mbwls = c_x mbwls = c_x
mdmps = c_x mdmps = c_x
mtnrv = p_matnr mtnrv = p_matnr
werks = p_werks werks = p_werks
importing
topmat = w_topmat topmat = w_topmat
tables
stb = it_stb stb = it_stb
exceptions
alt_not_found = 1 alt_not_found = 1
call_invalid = 2 call_invalid = 2
material_not_found = 3 material_not_found = 3
missing_authorization = 4 missing_authorization = 4
no_bom_found = 5 no_bom_found = 5
no_plant_data = 6 no_plant_data = 6
no_suitable_bom_found = 7 no_suitable_bom_found = 7
conversion_error = 8 conversion_error = 8
others = 9. others = 9.
if sy-subrc <> 0. if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno id message sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
into w_msg. w_msg into.
write: / w_msg. write: / w_msg.
exit.
endif.
Don't process documents * Do not process documents
delete it_stb where idnrk is initial. delete it_stb where idnrk is initial.
Don't process valid from furure: * Do not valid from furure process:
delete it_stb where datuv >= sy-datum. delete it_stb where datuv> = sy-datum.
Explode phantom assemblies up to last level * Explode phantom assemblies up to last level
do.
it_stb2[] = it_stb[]. it_stb2 it_stb = [] [].
delete it_stb2 where dumps is initial. delete it_stb2 where dumps is initial.
if it_stb2[] is initial. if it_stb2 [] is initial.
exit.
endif.
delete it_stb where not dumps is initial. delete it_stb dumps is not where initial.
loop at it_stb2. at it_stb2 loop.
call function 'CS_BOM_EXPL_MAT_V2' call function 'CS_BOM_EXPL_MAT_V2'
exporting
capid = 'PP01' capid = 'PP01'
cuols = c_x cuols = c_x
datuv = sy-datum datuv = sy-datum
knfba = c_x knfba = c_x
ksbvo = c_x ksbvo = c_x
mbwls = c_x mbwls = c_x
mdmps = c_x mdmps = c_x
mtnrv = it_stb2-idnrk mtnrv = it_stb2-idnrk
werks = p_werks werks = p_werks
tables
stb = it_stb3 stb = it_stb3
exceptions
alt_not_found = 1 alt_not_found = 1
call_invalid = 2 call_invalid = 2
material_not_found = 3 material_not_found = 3
missing_authorization = 4 missing_authorization = 4
no_bom_found = 5 no_bom_found = 5
no_plant_data = 6 no_plant_data = 6
no_suitable_bom_found = 7 no_suitable_bom_found = 7
conversion_error = 8 conversion_error = 8
others = 9. others = 9.
if sy-subrc <> 0. if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno id message sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
into w_msg. w_msg into.
write: / w_msg. write: / w_msg.
else.
delete it_stb3 where idnrk is initial. delete it_stb3 where idnrk is initial.
loop at it_stb3. at it_stb3 loop.
multiply it_stb3-menge by it_stb2-menge. multiply by it_stb3-menge it_stb2-menge.
modify it_stb3 transporting menge. menge modify it_stb3 transporting.
endloop.
append lines of it_stb3 to it_stb. append lines of it_stb3 to it_stb.
endif.
endloop.
enddo.
Build table of components collecting the same components from * Build table collecting components of the same components from
all levels * all levels
loop at it_stb. at it_stb loop.
it_comp-matkl = it_stb-matmk. it_comp-matkl = it_stb-matmk.
it_comp-idnrk = it_stb-idnrk. it_comp-idnrk = it_stb-idnrk.
it_comp-ojtxp = it_stb-ojtxp. it_comp-ojtxp = it_stb-ojtxp.
it_comp-menge = it_stb-menge. it_comp-menge = it_stb-menge.
it_comp-meins = it_stb-meins. it_comp-meins = it_stb-meins.
collect it_comp. it_comp collect.
clear it_comp. it_comp clear.
endloop.
endform.
reward point if helpful.
thanks
mrutyun^
‎2007 Sep 28 11:43 AM
go through this sample code u will get some thing out of this piece of code
tables : mara, marm, marc, stko,stpo, kotd001, kondd.
*Main Block
selection-screen begin of block b1 with frame title text-001.
select-options : s_matnr for mara-matnr,
s_mtart for mara-mtart,
s_matkl for mara-matkl,
s_werks for marc-werks default '0365',
s_meins for mara-meins no intervals no-extension
default 'GLF',
s_fmeins for mara-meins no intervals no-extension
default 'UNT'.
s_stlty for stko-stlty.
parameters: p_datub like rc29l-datub,
p_datuv like rc29l-datuv.
*CR 44081 08/30/2004
selection-screen skip.
parameters : p_vkorg type vkorg default '0101',
p_vtweg type vtweg default '01',
p_capid type capid default 'PI01',
p_stlan type stlan default ' '.
*selection-screen begin of line.
*selection-screen comment text-050.
parameters : p_rvrel type rvrel default ' ' as checkbox,
p_SANFR type SANFE default 'X' AS CHECKBOX,
*selection-screen end of line.
p_mehrs type mehrs as checkbox,
p_except as checkbox.
*CR 44081 08/30/2004
selection-screen end of block b1.
selection-screen skip.
selection-screen begin of block b2 with frame title text-002.
parameters: rb_tdn radiobutton group rad default 'X',
rb_btup radiobutton group rad.
selection-screen skip.
*CR 44081 08/30/2004
*parameters : p_uom as checkbox default 'X'.
*parameters : p_uom as checkbox .
*CR 44081 08/30/2004
selection-screen end of block b2.
types : begin of t_matnr,
matnr type mara-matnr, "Material
mtart type mara-mtart, "Material type
matkl type mara-matkl, "Material group
meins type mara-meins, "Base unit of measure
prdha type mara-prdha, "Prod hierarchy
werks type marc-werks, "Plant
sobsl type marc-sobsl, "Procurement key
end of t_matnr.
data: i_matnr type standard table of t_matnr with default key,
it_matnr type standard table of t_matnr with default key,
bit_matnr type standard table of t_matnr with default key,
b_matnr type t_matnr,
h_matnr type t_matnr.
*BOM
data : h_cstmat type cstmat,
i_stb type standard table of stpox with default key,
h_stb type stpox.
*Alt uom
types : begin of t_marm,
matnr type marm-matnr,
meinh type marm-meinh,
end of t_marm.
data: i_marm type sorted table of t_marm with unique default key,
h_marm type t_marm.
*Final table
types : begin of t_final,
fmatnr type mara-matnr, "find matnr
stlnr type stko-stlnr, "BOM
werks type marc-werks, "pLANT
lkmatnr(8), "Legacy Material
kmatnr type mara-matnr, "Material
kmaktx type makt-maktx, "Description
matkl type mara-matkl, "Group
mtart type mara-mtart, "Type
prdha type mara-prdha, "PROD HIERARCHY
kmeins type mara-meins, "Base unit
kmenge type stpo-menge, "Base quantity
cidnrk type stpo-idnrk, "Component
cmaktx type makt-maktx, "Description
lcmatnr(8), "Legacy Mat erial
cmtart type mara-mtart, "Material type
cmatkl type mara-matkl, "Material group
cprdha type mara-prdha, "Material prod hier
cmeins type mara-meins, "Component uom
cmenge type stpo-menge, "Component quantity
akmenge type stpo-menge, "Alternate for kit
acmenge type stpo-menge, "Alternate for component
ameins type mara-meins, "Alternate for both
kkmenge type stpo-menge, "Addition for the header
kcmenge type stpo-menge, "Addition for the calc
matdet(18) type c,
mat_acmenge type stpo-menge, "Alternate UoM for Mat Det
namat(18) type c,
namat_acmenge type stpo-menge, "Alternate UoM for Black Box
sobsl type marc-sobsl, "Procurement type
end of t_final.
data: i_final type standard table of t_final with default key,
h_final type t_final.
*CR 44081 08/30/2004
data vt_menge type stpo-menge.
*CR 44081 08/30/2004
*Bottom up
data : i_cscmat type standard table of cscmat with default key,
h_cscmat type cscmat,
i_cscequi type standard table of cscequi with default key,
h_cscequi type cscequi,
i_cscknd type standard table of cscknd with default key,
h_cscknd type cscknd,
i_cscstd type standard table of cscstd with default key,
h_cscstd type cscstd,
i_csctpl type standard table of csctpl with default key,
h_csctpl type csctpl,
i_stpov type standard table of stpov with default key,
b_stpov type standard table of stpov with default key,
bh_stpov type stpov,
h_stpov type stpov.
*Translator
*DATA: g_translate TYPE REF TO z20215_translator.
*DATA: v_prod TYPE mg_loctxt,
v_pack TYPE mg_loctxt.
*CR 44081 08/30/2004
types: begin of t_comp,
matnr type matnr,
mtart type mtart,
matkl type matkl,
end of t_comp.
data: i_comp type standard table of t_comp with default key,
h_comp type t_comp.
*Get procurement type
types : begin of t_sobsl,
matnr type matnr,
sobsl type sobsl,
end of t_sobsl.
data: i_sobsl type standard table of t_sobsl with default key,
h_sobsl type t_sobsl.
*CR 44081 08/30/2004
*ALV
data: g_grid type ref to cl_gui_alv_grid,
g_container type ref to cl_gui_custom_container,
g_layout type lvc_s_layo ,
g_fieldcatalog type lvc_t_fcat,
wa_catalog type lvc_s_fcat,
g_sort type lvc_t_sort with header line,
ls_variant like disvariant,
g_top_of_page type slis_t_listheader,
gs_variant type disvariant, "for parameter IS_VARIANT
x_save value 'A', "for Parameter I_SAVE
g_events type slis_t_event with header line.
data: g_repid type sy-repid.
ranges: r_matnr for mara-matnr occurs 0.
define m_fc.
wa_catalog-fieldname = &1.
wa_catalog-ref_field = &2.
wa_catalog-ref_table = &3.
*wa_catalog-scrtext_s =
wa_catalog-scrtext_m =
wa_catalog-scrtext_l = &4.
wa_catalog-key = &5.
wa_catalog-do_sum = &6.
wa_catalog-no_out = &7.
append wa_catalog to g_fieldcatalog.
clear wa_catalog.
end-of-definition.
start-of-selection.
*Authorization check
perform f_check_authorization tables s_werks.
*--Get Material
perform f_get_matnr. "Get material
perform f_get_matnr_new tables i_matnr
s_matnr
s_mtart
s_matkl
s_werks.
if rb_tdn = 'X'. "TOP DOWN
*--Get BOM details beginning from kit
perform f_get_bom. "Bom
perform f_get_new_bom tables i_matnr.
elseif rb_btup = 'X'.
*--Get BOM details from the components
perform f_get_kit_from_comp.
endif.
Begin of Changes CR 52909
perform modify_final.
end of changes CR 52909
end-of-selection.
*--Create field catalog
perform f_fieldcatalog.
*--Set sort critiera
perform f_sort.
*--Set alv grid
perform f_show_grid.
*Call container
call screen 100.
*----
*
FORM F_gET_KIT_FROM_COMP *
*----
*
........ *
*----
*
form f_get_kit_from_comp.
loop at i_matnr into b_matnr.
refresh: i_stpov.
clear h_stpov.
perform f_where_used
tables i_stpov
i_cscequi
i_cscknd
i_cscmat
i_cscstd
i_csctpl
using p_datub
p_datuv
b_matnr-matnr
p_stlan
b_matnr-werks.
if sy-subrc <> 0.
else.
refresh: s_matnr,
s_mtart,
s_werks,
s_matkl.
*get the kits into the table
loop at i_stpov into h_stpov.
perform f_find_more using h_stpov-matnr b_matnr-werks.
if sy-subrc = 0.
else.
*Say no higher level kit was found, so the existing kit should be
*reported
s_matnr-low = h_stpov-matnr.
s_matnr-sign = 'I'.
s_matnr-option = 'EQ'.
append s_matnr.
clear s_matnr.
endif.
endloop.
*Refresh the table list
perform f_get_matnr_new tables it_matnr
s_matnr
s_mtart
s_matkl
s_werks.
loop at it_matnr into h_matnr .
if h_matnr-mtart <> 'YKIT'.
perform f_find_more using h_matnr-matnr h_matnr-werks.
if sy-subrc = 0.
perform f_get_matnr_new tables bit_matnr
s_matnr
s_mtart
s_matkl
s_werks.
if sy-subrc = 0.
append lines of bit_matnr to it_matnr.
else.
append h_matnr to bit_matnr.
endif.
endif.
else.
append h_matnr to bit_matnr.
endif.
endloop.
*Get the details
sort bit_matnr. "D48K960269
delete adjacent duplicates from bit_matnr comparing all fields.
"D48K960269
perform f_get_new_bom tables bit_matnr.
endif.
endloop.
endform.
*----
*
FORM F_SORT *
*----
*
........ *
*----
*
form f_sort.
refresh g_sort.
if rb_tdn = 'X'. "TOP DOWN
*Sort by kit
g_sort-spos = '1'.
g_sort-fieldname = 'STLNR'.
g_sort-up = 'X'.
g_sort-subtot = 'X'.
append g_sort.
elseif rb_btup = 'X'.
*Sort by component
g_sort-spos = '1'.
g_sort-fieldname = 'FMATNR'.
g_sort-up = 'X'.
append g_sort.
*Sort 2nd by kit
g_sort-spos = '2'.
g_sort-fieldname = 'STLNR'.
g_sort-subtot = 'X'.
g_sort-up = 'X'.
append g_sort.
endif.
*set layout
g_layout-cwidth_opt = 'X'.
g_layout-zebra = 'X'.
set variant
clear gs_variant.
'gs_variant' must at least contain the report-id to allow
saving a variant.
g_repid = sy-repid.
§ 2.At least field REPORT of this structure has to be filled!
gs_variant-report = g_repid.
endform.
*----
*
FORM f_show_grid *
*----
*
........ *
*----
*
form f_show_grid.
*Create instance
if g_grid is initial.
create object g_grid
exporting
i_parent = g_container.
endif.
*Grid
call method g_grid->set_table_for_first_display
exporting
is_layout = g_layout
is_variant = gs_variant
i_save = x_save
changing
it_outtab = i_final[]
it_fieldcatalog = g_fieldcatalog
it_sort = g_sort[]
IT_FILTER =
exceptions
invalid_parameter_combination = 1
program_error = 2
others = 3.
if sy-subrc <> 0.
message e000 with text-028. "'Error during ALV Grid Creation.'.
endif.
endform.
*----
*
FORM f_fieldcatalog *
*----
*
........ *
*----
*
form f_fieldcatalog.
*Component
if rb_tdn = 'X'.
m_fc 'FMATNR' 'MATNR' 'MARA' text-003 'X' ' ' 'X'.
elseif rb_btup = 'X'.
m_fc 'FMATNR' 'MATNR' 'MARA' text-003 'X' ' ' ' '.
endif.
*Kit
m_fc 'STLNR' 'STLNR' 'STKO' text-004 'X' ' ' ' '.
*Plant
m_fc 'WERKS' 'WERKS' 'STKO' text-005 'X' ' ' ' '.
*Legacy Material no
m_fc 'LKMATNR' 'CHAR08' ' ' text-006 ' ' ' ' ''.
*Kit material
m_fc 'KMATNR' '' '' text-007 ' ' ' ' ''.
*Description
m_fc 'KMAKTX' ' MAKTX' 'MAKT' text-008 ' ' ' ' ''.
*Material group
m_fc 'MATKL' '' '' text-009 ' ' ' ' ''.
*Material Type
m_fc 'MTART' '' '' text-010 ' ' ' ' ''.
*Product hierarchy
m_fc 'PRDHA' '' '' text-011 ' ' ' ' ''.
*Unit of measure
m_fc 'KMEINS' '' '' text-012 ' ' ' ' ''.
*Quantity
m_fc 'KMENGE' '' '' text-013 ' ' 'X' ''.
*SAP Component
m_fc 'CIDNRK' '' '' text-014 ' ' ' ' '' .
*Legacy material number
m_fc 'LCMATNR' 'CHAR08' ' ' text-015 ' ' ' ' ''.
*Material description
m_fc 'CMAKTX' '' '' text-016 ' ' ' ' '' .
*Material group
m_fc 'CMTART' '' '' text-017 ' ' ' ' '' .
*Material type
m_fc 'CMATKL' '' '' text-018 ' ' ' ' '' .
*Material unit
m_fc 'CMEINS' '' '' text-019 ' ' ' ' ''.
*Quantity
m_fc 'CMENGE' '' '' text-020 ' ' 'X' ''.
*Converted in auom qty for kit
m_fc 'AKMENGE' ' ' ' ' text-021 ' ' 'X' ''.
*Converted in auom for component
m_fc 'ACMENGE' '' '' text-022 ' ' 'X' ''.
*Converted auom unit
m_fc 'AMEINS' ' ' ' ' text-023 ' ' ' ' ''.
*Factor with kit unit into account
m_fc 'KKMENGE' '' '' text-029 ' ' 'X' ' '.
*Factor with component unit into account
m_fc 'KCMENGE' '' '' text-024 ' ' 'X' ''.
*Product
m_fc 'SOBSL' 'SOBSL' 'MARC' text-025 ' ' ' ' ' '.
*Material determination code
m_fc 'MATDET' 'CHAR10' ' ' text-026 ' ' ' ' ' '.
*AUoM of Material determination code
m_fc 'MAT_ACMENGE' '' '' text-030 ' ' 'X' ''.
*ZNAXlate code
m_fc 'NAMAT' 'CHAR10' ' ' text-027 ' ' ' ' ' '.
*AUoM of Black Box material
m_fc 'NAMAT_ACMENGE' '' '' text-040 ' ' 'X' ''.
endform.
*----
*
FORM f_Get_marm *
*----
*
........ *
*----
*
--> p_matnr *
*----
*
form f_get_marm using p_matnr p_menge p_meinh p_type .
data: vf_lfimg type lfimg value 1,
vt_lfimg type lfimg.
*Refresh and clear
refresh i_marm.
clear i_marm.
*Select
select matnr meinh
into table i_marm
from marm
where matnr = p_matnr
and meinh in s_meins.
*Address the issue
loop at i_marm into h_marm.
if p_uom eq 'X'.
*IF from material master conversion required
perform f_convert_uom using h_marm-matnr
'1'
'UNT'
s_fmeins-low
'GLF'
s_meins-low
changing vt_lfimg.
else.
**IF bom conversion required
perform f_convert_uom using h_marm-matnr
p_menge
p_meinh
h_marm-meinh
changing vt_lfimg.
endif.
*No data found
if sy-subrc <> 0.
else.
*If from top down
if h_cstmat-stlnr is initial.
move :
h_stpov-stlnr to h_final-stlnr,
h_stpov-matnr to h_final-kmatnr,
h_stpov-werks to h_final-werks,
h_stpov-ojtxb to h_final-kmaktx.
*CR 44081 08/30/2004
perform f_legacy using '0101' '01' ' ' h_stpov-matnr ' '
perform f_legacy using p_vkorg p_vtweg ' ' ' ' h_stpov-matnr
*CR 44081 08/30/2004
changing h_final-lkmatnr h_final-matdet
h_final-namat.
else.
*If from bottom up
move:
h_cstmat-stlnr to h_final-stlnr, "BOM
h_cstmat-matnr to h_final-kmatnr, "Material
h_cstmat-werks to h_final-werks, "Plant
h_cstmat-maktx to h_final-kmaktx. "Description
*CR 44081 08/30/2004
perform f_legacy using '0101' '01' ' ' h_cstmat-matnr ' '
perform f_legacy using p_vkorg p_vtweg ' ' ' ' h_stpov-matnr
*CR 44081 08/30/2004
changing h_final-lkmatnr h_final-matdet
h_final-namat.
endif.
if not h_cstmat-stlnr is initial.
move:
h_matnr-prdha to h_final-prdha, "PROD HIERARCHY
h_matnr-matkl to h_final-matkl, "Group
h_matnr-mtart to h_final-mtart. "Type
endif.
*Seggregate betn Component and KIT
if p_type = 'C'.
h_final-acmenge = vt_lfimg .
if not h_stpov-bmeng is initial.
*Only to be double sure
if not h_stpov-bmeng = 0.
h_final-kcmenge = vt_lfimg / h_stpov-bmeng.
endif.
elseif not h_cstmat-bmeng is initial.
*Only to be double sure
if not h_cstmat-bmeng = 0.
h_final-kcmenge = vt_lfimg / h_cstmat-bmeng.
endif.
endif.
move:
h_stb-idnrk to h_final-cidnrk, "Component
h_stb-ojtxp to h_final-cmaktx, "Description
h_stb-meins to h_final-cmeins, "Component uom
h_stb-menge to h_final-cmenge.
*Material
select single mtart matkl
into (h_final-cmtart , h_final-cmatkl)
from mara
where matnr = h_final-cidnrk.
if sy-subrc ne 0.
clear : h_final-cmtart,
h_final-cmatkl.
endif.
*Get procurement type
select single sobsl into h_final-sobsl
from marc
where matnr = h_final-cidnrk
and werks = h_stb-werks.
if sy-subrc ne 0.
clear h_final-sobsl.
endif.
perform f_legacy using '0101' '01' '' h_final-kmatnr h_final-cidnrk
perform f_legacy using p_vkorg p_vtweg '' h_final-kmatnr
h_final-cidnrk
changing h_final-lcmatnr h_final-matdet
h_final-namat.
elseif p_type = 'K'.
if h_cstmat-bmein is initial.
move:
h_stpov-bmein to h_final-kmeins,
h_stpov-bmeng to h_final-kmenge.
h_final-akmenge = vt_lfimg.
else.
move:
h_cstmat-bmein to h_final-kmeins, "Base unit
h_cstmat-bmeng to h_final-kmenge. "Base quantity
h_final-akmenge = vt_lfimg .
endif.
endif.
h_final-ameins = h_marm-meinh.
insert h_final into table i_final.
clear h_final.
endif.
endloop.
endform.
*----
*
FORM f_get_bom *
*----
*
........ *
*----
*
form f_get_bom.
loop at i_matnr into h_matnr.
refresh : i_stb.
clear : h_cstmat.
*Date is required if no date entered take system date
if p_datuv is initial.
p_datuv = sy-datum.
endif.
*Explode bom
call function 'CS_BOM_EXPL_MAT_V2'
exporting
capid = 'Y000'
datuv = p_datuv
mtnrv = h_matnr-matnr
postp = 'L' "Item Category / Stock Item
stlal = '01' "BOM Alternative
werks = h_matnr-werks
importing
topmat = h_cstmat
tables
stb = i_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
conversion_error = 8
others = 9.
if sy-subrc <> 0.
else.
perform f_get_marm using h_cstmat-matnr
h_cstmat-bmeng
h_cstmat-bmein
'K'.
endif.
loop at i_stb into h_stb.
perform f_get_marm using h_stb-idnrk h_stb-menge h_stb-meins 'C'.
endloop.
endloop.
endform.
*----
*
FORM f_get_matnr *
*----
*
*----
*
form f_get_matnr.
*Get materials
select mara~matnr
mara~mtart
mara~matkl
mara~meins
mara~prdha
marc~werks
marc~sobsl
into table i_matnr
from mara inner join marc
on maramatnr = marcmatnr
where
mara~matnr in s_matnr and
mara~mtart in s_mtart and
mara~matkl in s_matkl and
marc~werks in s_werks.
if sy-subrc ne 0.
stop.
endif.
endform.
*&----
*
*& Module STATUS_0100 OUTPUT
*&----
*
text
*----
*
module status_0100 output.
*PF Status
set pf-status 'Z21424R_BOM'.
set titlebar '100'.
*Get container
if g_container is initial.
create object g_container
exporting
container_name = 'ALV_CONT'
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
if sy-subrc ne 0.
endif.
endif.
endmodule. " STATUS_0100 OUTPUT
*&----
*
*& Module USER_COMMAND_0100 INPUT
*&----
*
text
*----
*
module user_command_0100 input.
case sy-ucomm.
when 'BACK'.
if not g_container is initial.
call method g_container->free
exceptions
cntl_system_error = 1
cntl_error = 2.
if sy-subrc <> 0.
message a000.
endif.
endif.
leave to screen 0.
when others.
endcase.
endmodule. " USER_COMMAND_0100 INPUT
*&----
*
*& Form F_PREPARE_LAYOUT
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
form f_prepare_layout.
g_repid = sy-repid.
**-Field catalog
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = g_repid
i_internal_tabname = 'I_FINAL'
i_inclname = g_repid
changing
ct_fieldcat = g_fieldcatalog
exceptions
inconsistent_interface = 1
program_error = 2
others = 3.
endform. " F_PREPARE_LAYOUT
*&----
*
*& Form F_BOM_EXPLODE
*&----
*
text
*----
*
-->P_I_STB text
-->P_P_DATUV text
-->P_P_STLAL text
-->P_H_MATNR_MATNR text
-->P_H_MATNR_WERKS text
<--P_H_CSTMAT text
*----
*
form f_bom_explode tables p_i_stb structure stpox
using value(p_p_datuv)
p_p_stlal
p_h_matnr_matnr
p_h_matnr_werks
changing p_h_cstmat.
if p_p_datuv is initial.
p_p_datuv = sy-datum.
endif.
*BOM
call function 'CS_BOM_EXPL_MAT_V2'
exporting
capid = 'Y000'
datuv = p_p_datuv
mtnrv = p_h_matnr_matnr
stlal = p_p_stlal "BOM Alternative
werks = p_h_matnr_werks
importing
topmat = p_h_cstmat
tables
stb = p_i_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
conversion_error = 8
others = 9.
endform. " F_BOM_EXPLODE
*&----
*
*& Form F_CONVERT_UOM
*&----
*
text
*----
*
-->P_H_MARM_MATNR text
-->P_P_MENGE text
-->P_P_MEINH text
-->P_H_MARM_MEINH text
<--P_VT_LFIMG text
*----
*
form f_convert_uom using p_h_marm_matnr
p_p_menge
p_p_meinh
p_h_marm_meinh
changing p_vt_lfimg.
clear p_vt_lfimg.
call function 'Y_CONVERT_MATERIAL_UOM_QTY'
exporting
p_matnr = p_h_marm_matnr
from_qty = p_p_menge
from_uom = p_p_meinh
to_uom = p_h_marm_meinh
importing
to_qty = p_vt_lfimg
exceptions
conversion_not_successful = 1
others = 2.
endform. " F_CONVERT_UOM
*----
*
FORM F_LEGACY *
*----
*
........ *
*----
*
--> P_VKORG *
--> P_VTWEG *
--> P_KUNNR *
--> P_ZKITNO *
--> P_MATNR *
--> P_SPECIFCNR *
*----
*
form f_legacy using p_vkorg
p_vtweg
p_kunnr
p_zkitno
p_matnr
changing p_specifcnr
p_matdet
p_naxlate.
data:
v_nom TYPE zspcfnr,
v_matnr type mara-matnr,
c_kunnr type kunnr value '1058',
v_kit type mara-matnr, "CR 44081 08/30/2004
c_matnr(18) type c.
*Set one field of material
clear v_matnr.
*For KIT
if p_matnr is initial.
*CR 44081 08/30/2004 D48K960269
v_matnr = p_zkitno.
c_matnr = p_zkitno.
write p_zkitno to c_matnr no-zero.
clear v_kit.
SELECT SINGLE * "legacykitnr into v_nom
FROM zknmt
WHERE vkorg = p_vkorg
AND vtweg = p_vtweg
and kunnr = c_kunnr
AND zkitno = c_matnr
AND matnr EQ space.
IF sy-subrc NE 0.
CLEAR p_specifcnr.
ELSE.
p_specifcnr = zknmt-legacykitnr.
ENDIF.
*For Component
*CR 44081 08/30/2004 D48K960269
else.
v_kit = p_zkitno.
v_matnr = p_matnr.
clear : p_specifcnr,
p_matdet,
p_naxlate.
CALL FUNCTION 'Z_21254_MATERIAL_MAPPING'
EXPORTING
p_vkorg = p_vkorg
p_vtweg = p_vtweg
p_kunnr = p_kunnr
**CR 44081 08/30/2004
p_zkitno = p_zkitno
p_zkitno = v_kit
**CR 44081 08/30/2004
p_matnr = v_matnr "p_matnr
IMPORTING
P_KUNNR_OUT =
P_GENERICNR =
p_specificnr = v_nom
P_SPECIFICDESC =
EXCEPTIONS
no_mapping_found = 1
invalid_mapping = 2
OTHERS = 3
.
if sy-subrc <> 0.
clear p_specifcnr.
else.
p_specifcnr = v_nom.
endif.
endif. "CR 44081 08/30/2004
*Material determination
select single *
from kondd where
smatn = v_matnr.
if sy-subrc eq 0.
select single matwa into p_matdet
from kotd001
where kappl = 'V'
and kschl = 'A001'
and knumh = kondd-knumh
and datbi >= sy-datum
and datab <= sy-datum.
if sy-subrc <> 0.
clear p_matdet.
endif.
endif.
*Get from translator of ZNABLKBOX
IF g_translate IS INITIAL.
CREATE OBJECT g_translate.
ENDIF.
CLEAR:
v_prod,
v_pack.
CALL METHOD g_translate->rxlate_material
EXPORTING
co_code = '0101'
sap_material = v_matnr
IMPORTING
product = v_prod
package = v_pack
MATERIAL =
EXCEPTIONS
not_found = 1
OTHERS = 2
.
IF sy-subrc <> 0.
CLEAR: v_prod,
v_pack,
p_naxlate.
ELSE.
CONCATENATE v_prod v_pack INTO p_naxlate .
CONDENSE p_naxlate.
ENDIF.
endform.
*&----
*
*& Form F_GET_NEW_BOM
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
form f_get_new_bom tables p_i_matnr structure h_matnr.
data: c_10 type stko-datuv,
c_12(12).
loop at p_i_matnr into h_matnr.
refresh : i_stb.
clear : h_cstmat.
*Date is required if no date entered take system date
if p_datuv is initial.
p_datuv = sy-datum.
endif.
*Explode bom
call function 'CS_BOM_EXPL_MAT_V2'
exporting
capid = p_capid
datuv = p_datuv
mktls = 'X'
mehrs = p_mehrs
mtnrv = h_matnr-matnr
rvrel = p_rvrel
stlan = p_stlan
svwvo = 'X'
werks = h_matnr-werks
vrsvo = 'X'
importing
topmat = h_cstmat
tables
stb = i_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
conversion_error = 8
others = 9.
if sy-subrc <> 0.
else.
clear h_final.
****BOTTOM UP APPROACH
if rb_btup = 'X'.
h_final-fmatnr = b_matnr-matnr.
endif.
****KIT PROCESSING
*Begin transfer to the final table
move: h_cstmat-stlnr to h_final-stlnr, "BOM
h_cstmat-matnr to h_final-kmatnr, "Material
*BOM Quantity and unit
h_cstmat-bmein to h_final-kmeins, "Base unit
h_cstmat-bmeng to h_final-kmenge, "Base quantity
*other details
h_cstmat-werks to h_final-werks, "Plant
h_cstmat-maktx to h_final-kmaktx. "Description
*Convert to the required unit of measure
perform f_get_marm_new using h_cstmat-matnr
h_cstmat-bmeng
s_fmeins-low
' '
changing h_final-akmenge
h_final-ameins
h_final-kkmenge.
*Convert to legacy
perform f_legacy using p_vkorg "'0101' "Sales org
p_vtweg "'01' " DC
' ' "Customer
h_cstmat-matnr "KIT
' ' "Component
h_cstmat-matnr "Material/Component
changing
h_final-lkmatnr
h_final-matdet
h_final-namat.
*Transfer to Final Table
move: h_matnr-prdha to h_final-prdha, "PROD HIERARCHY
h_matnr-matkl to h_final-matkl, "Group
h_matnr-mtart to h_final-mtart. "Type
*Insert
insert h_final into table i_final.
clear: h_final-akmenge,
h_final-kmenge,
h_final-kkmenge.
endif.
****COMPONENT PROCESSING
*Material
if not i_stb[] is initial.
refresh i_comp.
select matnr mtart matkl
into table i_comp
from mara
for all entries in i_stb
where matnr = i_stb-idnrk.
sort i_comp.
endif.
*Get sobsl
if not i_stb[] is initial.
refresh i_sobsl.
select matnr sobsl
into table i_sobsl
from marc
for all entries in i_stb
where matnr = i_stb-idnrk
and werks = i_stb-werks.
sort i_sobsl.
endif.
loop at i_stb into h_stb.
clear h_final.
move: h_stb-idnrk to h_final-cidnrk, "Component
h_stb-ojtxp to h_final-cmaktx, "Description
h_stb-meins to h_final-cmeins, "Component uom
h_stb-menge to h_final-cmenge.
h_stb-mnglg to h_final-cmenge.
*Convert to the required unit of measure
perform f_get_marm_new using h_stb-idnrk
h_stb-menge
s_fmeins-low
'C'
changing h_final-acmenge
h_final-ameins
h_final-kcmenge.
*Convert to legacy code
perform f_legacy using p_vkorg "Sales org
p_vtweg "DC
'' "Customer
h_cstmat-matnr "KIT
h_stb-idnrk "Material/Component
changing h_final-lcmatnr
h_final-matdet
h_final-namat.
*Component type etc
read table i_comp into h_comp with key matnr = h_stb-idnrk
binary search.
if sy-subrc = 0.
h_final-cmtart = h_comp-mtart.
h_final-cmatkl = h_comp-matkl.
else.
clear : h_final-cmtart,
h_final-cmatkl.
endif.
*component sobsl
read table i_sobsl into h_sobsl with key matnr = h_stb-idnrk
binary search.
if sy-subrc = 0.
h_final-sobsl = h_sobsl-sobsl.
clear h_sobsl.
else.
clear h_final-sobsl.
endif.
*Transfer to final table
insert h_final into table i_final.
clear : h_final-cidnrk,
h_final-cmaktx,
h_final-cmeins,
h_final-cmenge,
h_final-kcmenge.
endloop.
endloop.
endform. " F_GET_NEW_BOM
*&----
*
*& Form F_GET_MARM_NEW
*&----
*
text
*----
*
-->P_H_CSTMAT_MATNR text
-->P_H_CSTMAT_BMENG text
-->P_H_CSTMAT_BMEIN text
-->P_1903 text
*----
*
form f_get_marm_new using p_h_cstmat_matnr
p_h_cstmat_bmeng
p_h_cstmat_bmein
value(p_1903)
changing vt_meng
vt_mein
tv_meng.
clear : vt_meng, tv_meng, vt_mein.
data: m_meins type meins,
m_fmeins type meins,
m_menge type stpo-menge.
if p_buom = 'X'.
select single meins into m_fmeins
from mara
where matnr = p_h_cstmat_matnr.
if sy-subrc <> 0.
m_meins = ''.
endif.
m_meins = s_meins-low.
m_menge = 1.
m_fmeins = s_fmeins-low.
perform f_convert_uom using p_h_cstmat_matnr
m_menge
m_fmeins
m_meins
changing tv_meng.
clear : m_menge, m_fmeins, m_meins.
if p_uom = 'X'. "Convert to base unit of measure
m_menge = 1. "Convert everything from 1 to the base uom
m_fmeins = s_fmeins-low.
m_meins = s_meins-low.
else.
m_menge = 1. "Convert everything from 1 to the base uom
m_menge = p_h_cstmat_bmeng.
m_fmeins = s_fmeins-low.
m_meins = s_meins-low.
endif.
*Convert to the required unit of measure
perform f_convert_uom using p_h_cstmat_matnr
m_menge
p_h_cstmat_bmein
m_fmeins
m_meins
changing vt_meng.
if sy-subrc = 0.
vt_mein = m_meins.
else.
*If unit of measure is not found then blank it out so that it stands out
vt_mein = ' '.
endif.
endif .
endform. " F_GET_MARM_NEW
*&----
*
*& Form F_GET_MATNR_NEW
*&----
*
text
*----
*
-->P_I_MATNR[] text
*----
*
form f_get_matnr_new tables p_i_matnr structure h_matnr
p_s_matnr structure s_matnr
p_s_mtart structure s_mtart
p_s_matkl structure s_matkl
p_s_werks structure s_werks.
refresh p_i_matnr.
select mara~matnr
mara~mtart
mara~matkl
mara~meins
mara~prdha
marc~werks
marc~sobsl
into table p_i_matnr
from mara inner join marc
on maramatnr = marcmatnr
where
mara~matnr in p_s_matnr and
mara~mtart in p_s_mtart and
mara~matkl in p_s_matkl and
marc~werks in p_s_werks.
if sy-subrc ne 0.
endif.
endform. " F_GET_MATNR_NEW
*&----
*
*& Form F_WHERE_USED
*&----
*
text
*----
*
-->P_P_DATUB text
-->P_P_DATUV text
-->P_B_MATNR_MATNR text
-->P_P_STLAL text
-->P_B_MATNR_WERKS text
-->P_I_STPOV text
-->P_I_CSCEQUI text
-->P_I_CSCKND text
-->P_I_CSCMAT text
-->P_I_CSCSTD text
-->P_I_CSCTPL text
*----
*
form f_where_used tables p_i_stpov structure stpov
p_i_cscequi structure cscequi
p_i_cscknd structure cscknd
p_i_cscmat structure cscmat
p_i_cscstd structure cscstd
p_i_csctpl structure csctpl
using p_p_datub
p_p_datuv
p_b_matnr_matnr
p_p_stlal
p_b_matnr_werks.
refresh :
p_i_stpov,
p_i_cscequi,
p_i_cscknd,
p_i_cscmat,
p_i_cscstd,
p_i_csctpl.
call function 'CS_WHERE_USED_MAT'
exporting
datub = p_p_datub
datuv = p_p_datuv
matnr = p_b_matnr_matnr
POSTP = ' '
RETCODE_ONLY = ' '
stlan = p_p_stlal
werks = p_b_matnr_werks
MCLMT = '8'
MNSTL = ' '
MXSTL = ' '
STLTP = ' '
NEWSI = ' '
IMPORTING
TOPMAT =
tables
wultb = p_i_stpov
equicat = p_i_cscequi
kndcat = p_i_cscknd
matcat = p_i_cscmat
stdcat = p_i_cscstd
tplcat = p_i_csctpl
PRJCAT =
exceptions
call_invalid = 1
material_not_found = 2
no_where_used_rec_found = 3
no_where_used_rec_selected = 4
no_where_used_rec_valid = 5
others = 6
.
endform. " F_WHERE_USED
*&----
*
*& Form F_CHECK_AUTHORIZATION
*&----
*
text
*----
*
-->P_S_WERKS text
*----
*
form f_check_authorization tables p_s_werks structure s_werks.
data: begin of i_werks occurs 0,
werks type werks,
end of i_werks.
data: dsp_actvt(2) type c value '03'.
if p_s_werks[] is initial.
authority-check object 'C_STUE_WRK'
id 'ACTVT' field dsp_actvt
id 'CSWRK' dummy.
if sy-subrc <> 0. "HGA072824
MESSAGE e523 WITH 'E:' ' ' .
else. "HGA072824
leave. "HGA072824
endif. "HGA072824
else.
select werks into table i_werks
from t001w
where werks in s_werks.
if sy-subrc = 0.
loop at i_werks.
authority-check object 'C_STUE_WRK'
id 'ACTVT' field dsp_actvt
id 'CSWRK' field i_werks-werks.
if sy-subrc <> 0.
MESSAGE e523 WITH 'E:' i_werks-werks. "HGA072824
else. "HGA072824
leave. "HGA072824
endif. "HGA072824
endloop.
endif.
endif.
endform. " F_CHECK_AUTHORIZATION
*&----
*
*& Form F_FIND_MORE
*&----
*
text
*----
*
--> p1 text
<-- p2 text
*----
*
form f_find_more using p_matnr
p_werks.
perform f_where_used
tables b_stpov
i_cscequi
i_cscknd
i_cscmat
i_cscstd
i_csctpl
using p_datub
p_datuv
p_matnr
p_stlan
p_werks.
if sy-subrc = 0.
loop at b_stpov into bh_stpov.
s_matnr-low = bh_stpov-matnr.
s_matnr-sign = 'I'.
s_matnr-option = 'EQ'.
append s_matnr.
clear s_matnr.
endloop.
endif.
endform. " F_FIND_MORE
*&----
*
*& Form MODIFY_FINAL
*&----
*
text
*----
*
form modify_final.
data: l_tabix like sy-tabix,
l_matnr like kotd001-matwa,
l_kitsum like h_final-akmenge,
l_partsum like h_final-acmenge,
l_final like h_final.
loop at i_final into h_final.
l_tabix = sy-tabix.
The prior logic before this change procures the NA Black Box material
in a wrong manner, hence clearing the entire column
clear h_final-namat.
if not h_final-lcmatnr is initial.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = h_final-lcmatnr
importing
output = l_matnr.
Populating Material Determination
clear h_final-matdet.
select knumh
into kotd001-knumh
from kotd001 up to 1 rows
where kappl = 'V'
and kschl = 'A001'
and matwa = l_matnr.
endselect.
if sy-subrc = 0.
select single smatn into kondd-smatn
from kondd
where knumh = kotd001-knumh.
if sy-subrc = 0.
h_final-matdet = kondd-smatn.
endif.
endif.
Getting the AUoM for Mat Det
if not h_final-matdet is initial.
perform get_auom changing h_final-matdet
h_final-mat_acmenge.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = h_final-matdet
importing
output = h_final-matdet.
endif.
Procuring the Black Box Material
clear h_final-namat.
SELECT to_val1 INTO h_final-namat
FROM znablackbx UP TO 1 ROWS
WHERE obj_id = 'MATNR'
AND co_code = '0101'
AND from_val1 = l_matnr+10(4)
AND from_val2 = l_matnr+14(4).
ENDSELECT.
if not h_final-namat is initial.
perform get_auom changing h_final-namat
h_final-namat_acmenge.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = h_final-namat
importing
output = h_final-namat.
endif.
endif.
modify i_final from h_final index l_tabix.
Comparing Sum of KIT and Part. If not equal then they are displayed
if not p_except is initial.
if not l_tabix = 1.
l_tabix = l_tabix - 1.
read table i_final index l_tabix into l_final.
if l_final-kmatnr <> h_final-kmatnr.
if l_kitsum = l_partsum.
r_matnr-low = l_final-kmatnr.
r_matnr-sign = 'I'.
r_matnr-option = 'EQ'.
append r_matnr. clear r_matnr.
endif.
clear: l_kitsum,
l_partsum.
endif.
endif.
l_kitsum = l_kitsum + h_final-akmenge.
l_partsum = l_partsum + h_final-acmenge.
endif.
at last.
read table i_final into h_final index sy-tabix.
if l_kitsum = l_partsum.
r_matnr-low = h_final-kmatnr.
r_matnr-sign = 'I'.
r_matnr-option = 'EQ'.
append r_matnr. clear r_matnr.
endif.
endat.
endloop.
if not p_except is initial and not r_matnr[] is initial.
delete i_final where kmatnr in r_matnr.
endif.
endform. " MODIFY_FINAL
*&----
*
*& Form GET_AUOM
*&----
*
text
*----
*
form get_auom changing p_matnr type marm-matnr
p_auom type stpo-menge.
data: begin of i_marm occurs 0,
meinh like marm-meinh,
umrez like marm-umrez,
umren like marm-umren,
end of i_marm.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = p_matnr
importing
output = p_matnr.
select meinh umrez umren
into table i_marm
from marm
where matnr = p_matnr
and meinh in ('GLF', 'EA', 'UNT').
read table i_marm with key meinh = 'GLF'.
if sy-subrc = 0 and not i_marm-umrez is initial.
p_auom = i_marm-umren / i_marm-umrez.
endif.
read table i_marm with key meinh = 'UNT'.
if sy-subrc = 0 and not i_marm-umren is initial.
p_auom = ( p_auom * i_marm-umrez ) / i_marm-umren.
endif.
endform. " GET_AUOM