*&---------------------------------------------------------------------*
*& Progarm : ZPPR044 Author : Jimmy Wong
*& Created : 15 Apr 2013 App : MM
*& Title : Material Where-Used List
*& Description : Material Where-Used List
*&---------------------------------------------------------------------*
*& Version Author Date description
*& Jimmy 15 Apr 2013 the first version
*& the last update time 2013.04.15 18:00
*&---------------------------------------------------------------------*
report zppr044 no standard page heading.
tables:mast.
data: begin of it_matnr occurs 0 ,
werks like mast-werks,
matnr like mast-matnr,
matnr_l like mast-matnr,
level like stpov-level,
end of it_matnr.
data: it_matnr1 like table of it_matnr with header line.
data: begin of ltb occurs 0.
include structure stpov.
data: end of ltb.
data: begin of equicat occurs 0. "YHG110068
include structure cscequi. "YHG110068
data: end of equicat .
data: begin of kndcat occurs 0. "YHG110068
include structure cscknd. "YHG110068
data: end of kndcat .
data: begin of matcat occurs 0. "YHG110068
include structure cscmat. "YHG110068
data: end of matcat . "YHG110068
data: begin of stdcat occurs 0. "YHG110068
include structure cscstd. "YHG110068
data: end of stdcat .
data: begin of tplcat occurs 0. "YHG110068
include structure csctpl. "YHG110068
data: end of tplcat .
data: begin of itab occurs 0 ,
level like stpov-level,
werks like mast-werks,
matnr_l like mast-matnr,
matnr like mast-matnr,
bmeng like stpov-bmeng,
bmein like stpov-bmein,
menge like stpov-menge,
meins like stpov-meins,
ojtxb like stpov-ojtxb,
posnr like stpov-posnr,
preis like stpov-preis,
peinh like stpov-peinh,
waers like stpov-waers,
stlan like stpov-stlan,
end of itab.
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
wa_hier type slis_fieldcat_alv .
define alv_field.
clear:wa_hier.
wa_hier-fieldname = &1.
wa_hier-seltext_m = &2.
wa_hier-seltext_l = &3.
wa_hier-outputlen = &4.
wa_hier-just = &5.
wa_hier-do_sum = &6.
wa_hier-ref_tabname = &7 .
wa_hier-ref_fieldname = &8 .
append wa_hier to fc_hier.
end-of-definition.
selection-screen begin of block sel1 with frame title text-001.
select-options : s_werks for mast-werks default '8101', "Plant
s_matnr for mast-matnr.
parameters: p_datuv like stpo-datuv default sy-datum,
p_datub like stpo-datuv default sy-datum,
p_80 like csdata-xfeld ,
p_mehrs like csdata-xfeld.
selection-screen end of block sel1.
start-of-selection.
perform get_material.
perform get_data.
if itab[] is initial.
message i003(zmm).
exit.
endif.
perform display_data.
*&---------------------------------------------------------------------*
*& Form GET_MATERIAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_material .
select distinct a~werks b~idnrk as matnr b~idnrk as matnr_l into table it_matnr1
from mast as a inner join stpo as b on a~stlnr = b~stlnr
where a~werks in s_werks
and b~idnrk in s_matnr.
delete it_matnr1 where matnr is initial.
endform. " GET_MATERIAL
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
it_matnr[] = it_matnr1[].
refresh: it_matnr1.
sort it_matnr by werks matnr.
loop at it_matnr.
call function 'CS_WHERE_USED_MAT'
exporting
datub = p_datub
datuv = p_datuv
matnr = it_matnr-matnr
werks = it_matnr-werks
tables
wultb = ltb
equicat = equicat "YHG110068
kndcat = kndcat "YHG110068
matcat = matcat "YHG110068
stdcat = stdcat "YHG110068
tplcat = tplcat "YHG110068
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.
if ltb[] is not initial.
loop at ltb.
check not ltb-stlnr is initial.
if not ltb-sumfg = 'x'.
move-corresponding ltb to itab.
itab-matnr_l = it_matnr-matnr_l.
itab-level = it_matnr-level + 1.
it_matnr1-werks = it_matnr-werks.
it_matnr1-matnr = ltb-matnr.
it_matnr1-matnr_l = it_matnr-matnr_l.
it_matnr1-level = it_matnr-level + 1.
if p_80 = 'X'.
if itab-matnr+0(2) = '80'.
append: itab.
endif.
else.
append: itab.
endif.
append: it_matnr1.
endif.
clear: itab,it_matnr1.
endloop.
endif.
clear:ltb,ltb[].
endloop.
refresh : it_matnr.
if p_mehrs = 'X'.
if it_matnr1[] is not initial.
perform get_data.
endif.
endif.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_data .
refresh: fc_hier.
alv_field 'WERKS' '' 'Plant' '6' 'L' '' '' ''.
alv_field 'LEVEL' '' 'Level' '6' 'R' '' '' ''.
alv_field 'MATNR_L' '' 'Material' '20' 'L' '' 'MARA' 'MATNR'.
alv_field 'MATNR' '' 'Component' '20' 'L' '' 'MARA' 'MATNR'.
alv_field 'OJTXB' '' 'Component Desc' '20' 'L' '' '' ''.
alv_field 'POSNR' '' 'Item' '6' 'L' '' '' ''.
alv_field 'BMENG' '' 'Required Qty' '13' 'R' '' '' ''.
alv_field 'BMEIN' '' 'Unit' '6' 'L' '' '' ''.
alv_field 'MENGE' '' 'Resulting Qty' '13' 'R' '' '' ''.
alv_field 'MEINS' '' 'Base Unit' '6' 'L' '' '' ''.
sort itab by werks matnr_l level.
perform display_alv tables fc_hier itab using 'A'.
endform. " DISPLAY_DATA
*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FC_HIER text
* -->ITAB text
* -->P_SAVE text
*----------------------------------------------------------------------*
form display_alv tables fc_hier itab
using p_save .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = fc_hier[]
i_save = p_save
i_callback_program = sy-repid
* it_sort = sort[]
tables
t_outtab = itab[]
exceptions
program_error = 1
others = 2.
endform. "display_alv
*& Progarm : ZPPR044 Author : Jimmy Wong
*& Created : 15 Apr 2013 App : MM
*& Title : Material Where-Used List
*& Description : Material Where-Used List
*&---------------------------------------------------------------------*
*& Version Author Date description
*& Jimmy 15 Apr 2013 the first version
*& the last update time 2013.04.15 18:00
*&---------------------------------------------------------------------*
report zppr044 no standard page heading.
tables:mast.
data: begin of it_matnr occurs 0 ,
werks like mast-werks,
matnr like mast-matnr,
matnr_l like mast-matnr,
level like stpov-level,
end of it_matnr.
data: it_matnr1 like table of it_matnr with header line.
data: begin of ltb occurs 0.
include structure stpov.
data: end of ltb.
data: begin of equicat occurs 0. "YHG110068
include structure cscequi. "YHG110068
data: end of equicat .
data: begin of kndcat occurs 0. "YHG110068
include structure cscknd. "YHG110068
data: end of kndcat .
data: begin of matcat occurs 0. "YHG110068
include structure cscmat. "YHG110068
data: end of matcat . "YHG110068
data: begin of stdcat occurs 0. "YHG110068
include structure cscstd. "YHG110068
data: end of stdcat .
data: begin of tplcat occurs 0. "YHG110068
include structure csctpl. "YHG110068
data: end of tplcat .
data: begin of itab occurs 0 ,
level like stpov-level,
werks like mast-werks,
matnr_l like mast-matnr,
matnr like mast-matnr,
bmeng like stpov-bmeng,
bmein like stpov-bmein,
menge like stpov-menge,
meins like stpov-meins,
ojtxb like stpov-ojtxb,
posnr like stpov-posnr,
preis like stpov-preis,
peinh like stpov-peinh,
waers like stpov-waers,
stlan like stpov-stlan,
end of itab.
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
wa_hier type slis_fieldcat_alv .
define alv_field.
clear:wa_hier.
wa_hier-fieldname = &1.
wa_hier-seltext_m = &2.
wa_hier-seltext_l = &3.
wa_hier-outputlen = &4.
wa_hier-just = &5.
wa_hier-do_sum = &6.
wa_hier-ref_tabname = &7 .
wa_hier-ref_fieldname = &8 .
append wa_hier to fc_hier.
end-of-definition.
selection-screen begin of block sel1 with frame title text-001.
select-options : s_werks for mast-werks default '8101', "Plant
s_matnr for mast-matnr.
parameters: p_datuv like stpo-datuv default sy-datum,
p_datub like stpo-datuv default sy-datum,
p_80 like csdata-xfeld ,
p_mehrs like csdata-xfeld.
selection-screen end of block sel1.
start-of-selection.
perform get_material.
perform get_data.
if itab[] is initial.
message i003(zmm).
exit.
endif.
perform display_data.
*&---------------------------------------------------------------------*
*& Form GET_MATERIAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_material .
select distinct a~werks b~idnrk as matnr b~idnrk as matnr_l into table it_matnr1
from mast as a inner join stpo as b on a~stlnr = b~stlnr
where a~werks in s_werks
and b~idnrk in s_matnr.
delete it_matnr1 where matnr is initial.
endform. " GET_MATERIAL
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
it_matnr[] = it_matnr1[].
refresh: it_matnr1.
sort it_matnr by werks matnr.
loop at it_matnr.
call function 'CS_WHERE_USED_MAT'
exporting
datub = p_datub
datuv = p_datuv
matnr = it_matnr-matnr
werks = it_matnr-werks
tables
wultb = ltb
equicat = equicat "YHG110068
kndcat = kndcat "YHG110068
matcat = matcat "YHG110068
stdcat = stdcat "YHG110068
tplcat = tplcat "YHG110068
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.
if ltb[] is not initial.
loop at ltb.
check not ltb-stlnr is initial.
if not ltb-sumfg = 'x'.
move-corresponding ltb to itab.
itab-matnr_l = it_matnr-matnr_l.
itab-level = it_matnr-level + 1.
it_matnr1-werks = it_matnr-werks.
it_matnr1-matnr = ltb-matnr.
it_matnr1-matnr_l = it_matnr-matnr_l.
it_matnr1-level = it_matnr-level + 1.
if p_80 = 'X'.
if itab-matnr+0(2) = '80'.
append: itab.
endif.
else.
append: itab.
endif.
append: it_matnr1.
endif.
clear: itab,it_matnr1.
endloop.
endif.
clear:ltb,ltb[].
endloop.
refresh : it_matnr.
if p_mehrs = 'X'.
if it_matnr1[] is not initial.
perform get_data.
endif.
endif.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_data .
refresh: fc_hier.
alv_field 'WERKS' '' 'Plant' '6' 'L' '' '' ''.
alv_field 'LEVEL' '' 'Level' '6' 'R' '' '' ''.
alv_field 'MATNR_L' '' 'Material' '20' 'L' '' 'MARA' 'MATNR'.
alv_field 'MATNR' '' 'Component' '20' 'L' '' 'MARA' 'MATNR'.
alv_field 'OJTXB' '' 'Component Desc' '20' 'L' '' '' ''.
alv_field 'POSNR' '' 'Item' '6' 'L' '' '' ''.
alv_field 'BMENG' '' 'Required Qty' '13' 'R' '' '' ''.
alv_field 'BMEIN' '' 'Unit' '6' 'L' '' '' ''.
alv_field 'MENGE' '' 'Resulting Qty' '13' 'R' '' '' ''.
alv_field 'MEINS' '' 'Base Unit' '6' 'L' '' '' ''.
sort itab by werks matnr_l level.
perform display_alv tables fc_hier itab using 'A'.
endform. " DISPLAY_DATA
*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->FC_HIER text
* -->ITAB text
* -->P_SAVE text
*----------------------------------------------------------------------*
form display_alv tables fc_hier itab
using p_save .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = fc_hier[]
i_save = p_save
i_callback_program = sy-repid
* it_sort = sort[]
tables
t_outtab = itab[]
exceptions
program_error = 1
others = 2.
endform. "display_alv