*&---------------------------------------------------------------------*
*& Progarm : ZPPR021 Author : Jimmy Wong
*& Created : 31 Oct 2012 App : PP
*& Title : Master Schedule Detail Report
*& Description : Master Schedule Detail Report
*&---------------------------------------------------------------------*
*& Version Author Date description
*& Jimmy 31 Oct 2012 the first version
*& the last update time 2012.10.31 18:00
*&---------------------------------------------------------------------*
report zppr021 no standard page heading.
*&---------------------------------------------------------------------*
* database table
*&---------------------------------------------------------------------*
tables : mara,marc.
*&---------------------------------------------------------------------*
* internal table & variables
*&---------------------------------------------------------------------*
data: begin of it_pr occurs 0,
dat00 like mdez-dat00,
sort1 type c,
sort2 type c length 2,
banfn like eban-banfn,
bnfpo like eban-bnfpo,
umdat like mdez-umdat,
matnr like ekpo-matnr,
mng01 like mdez-mng01,
mng02 like mdez-mng02,
maktx like makt-maktx,
werks like ekpo-werks,
dat02 like mdps-dat02,
meins like mara-meins,
bstmi like marc-bstmi, "Minimum Lot Size
bstrf like marc-bstrf, "Rounding value
end of it_pr.
data:it_req like it_pr occurs 0 with header line.
data:begin of itab occurs 0,
banfn like eban-banfn, "pr
bnfpo like eban-bnfpo, "PR item
matnr like ekpo-matnr, "material
maktx like makt-maktx, "desc
werks like ekpo-werks, "plant
mng01 like mdez-mng01, "Planned qty
mng03 like mdez-mng02, "Actual req qty
mng04 like mdez-mng02, "Net req. qty
meins like mara-meins, "Unit
dat02 like mdps-dat02, "Release date
datdt like mdez-dat00, "Dute date
umdat like mdez-umdat, "Reschedule date
verpr like mbew-verpr, "net price
peinh like ekpo-peinh, "price unit
netwr like ekpo-netwr, "Net cost
bstmi like marc-bstmi, "Minimum Lot Size
bstrf like marc-bstrf, "Rounding value
lifnr like lfa1-lifnr, "100% vendor code
name_v like lfa1-name1, "vendor name
end of itab.
data:begin of it_matnr occurs 0,
matnr like marc-matnr,
plwrk like marc-werks,
end of it_matnr.
data:lv_len type i,
lv_banfn like eban-banfn,
lv_bnfpo like eban-bnfpo,
lv_mng01 like mdez-mng01,
lv_mng02 like mdez-mng02,
lv_type type c length 2.
data:lt_mdkp like bapi_mrp_list .
data: it_mrp_list like bapi_mrp_ind_lines occurs 0 with header line.
data:begin of it_makt occurs 0,
matnr like makt-matnr,
maktx like makt-maktx,
end of it_makt.
data:begin of it_mbew occurs 0,
matnr like makt-matnr,
werks like ekpo-werks,
verpr like mbew-verpr, "net price
peinh like ekpo-peinh, "price unit
end of it_mbew.
data:begin of it_lifnr occurs 0,
matnr like mara-matnr,
werks like marc-werks,
lifnr like lfa1-lifnr,
name1 like lfa1-name1,
flifn like eord-flifn,
autet like eord-autet,
end of it_lifnr.
data:lv_total_line type i,
lv_line type p decimals 3.
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
wa_hier type slis_fieldcat_alv .
*----------------------------------------------------------------------*
* Parameter & Select-Options *
*----------------------------------------------------------------------*
selection-screen begin of block 1 with frame title text-001.
parameters: p_frgdt like eban-frgdt default sy-datum obligatory.
select-options : s_werks for marc-werks .
select-options : s_matnr for mara-matnr.
selection-screen end of block 1.
*&---------------------------------------------------------------------*
* start of process
*&---------------------------------------------------------------------*
start-of-selection.
perform get_matnr.
if it_matnr[] is initial .
message 'No Record Found' type 'I'.
exit.
endif.
perform get_mrp_list.
if it_pr[] is initial .
message 'No Record Found' type 'I'.
exit.
endif.
perform process_data.
perform display_data.
end-of-selection.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_matnr .
select matnr plwrk
into corresponding fields of table it_matnr
from mdkp
where dtart = 'MD'
and matnr in s_matnr
and plwrk in s_werks
and plscn = '000'.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form GET_MRP_LIST
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_mrp_list .
describe table it_matnr lines lv_total_line.
loop at it_matnr.
lv_line = sy-tabix / lv_total_line * 100.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
percentage = lv_line
text = 'Get Data........'.
call function 'BAPI_MATERIAL_MRP_LIST'
exporting
material = it_matnr-matnr
plant = it_matnr-plwrk
importing
mrp_list = lt_mdkp
tables
mrp_ind_lines = it_mrp_list.
check sy-subrc eq 0.
read table it_mrp_list with key mrp_element_ind = 'BA'.
loop at it_mrp_list.
if it_mrp_list-mrp_element_ind = 'BA'.
lv_len = strlen( it_mrp_list-elemnt_data ).
it_pr-dat00 = it_mrp_list-avail_date.
if lv_len >= 16.
it_pr-banfn = it_mrp_list-elemnt_data+0(10).
it_pr-bnfpo = it_mrp_list-elemnt_data+11(5).
endif.
it_pr-matnr = it_matnr-matnr.
it_pr-mng01 = it_mrp_list-rec_reqd_qty .
it_pr-mng02 = it_mrp_list-avail_qty1.
it_pr-umdat = it_mrp_list-resched_date .
it_pr-werks = it_matnr-plwrk.
it_pr-sort1 = it_mrp_list-sortind_01 .
it_pr-sort2 = it_mrp_list-sortind_02 .
it_pr-dat02 = it_mrp_list-start_date .
it_pr-meins = lt_mdkp-base_uom .
it_pr-bstmi = lt_mdkp-minlotsize .
it_pr-bstrf = lt_mdkp-round_val.
lv_banfn = it_pr-banfn.
lv_bnfpo = it_pr-bnfpo.
lv_mng01 = it_pr-mng01.
lv_mng02 = it_pr-mng02 - it_pr-mng01.
lv_type = 'PR'.
append it_pr.
elseif it_mrp_list-rec_reqd_qty < 0 .
if lv_banfn is not initial and lv_bnfpo is not initial.
if lv_mng02 > 0.
lv_mng02 = lv_mng02 + it_mrp_list-rec_reqd_qty .
if lv_mng02 < 0.
it_mrp_list-rec_reqd_qty = lv_mng02.
endif.
endif.
if lv_mng02 < 0 or ( lv_mng02 = 0 and lv_type = 'PR' ) .
it_pr-dat00 = it_mrp_list-avail_date.
it_pr-mng01 = it_mrp_list-rec_reqd_qty .
it_pr-mng02 = it_mrp_list-avail_qty1.
it_pr-matnr = it_matnr-matnr.
it_pr-werks = it_matnr-plwrk.
it_pr-sort1 = it_mrp_list-sortind_01 .
it_pr-sort2 = it_mrp_list-sortind_02 .
it_pr-banfn = lv_banfn .
it_pr-bnfpo = lv_bnfpo.
* append it_pr.
move-corresponding it_pr to it_req.
append it_req.
endif.
clear:lv_type.
endif.
endif.
clear:it_pr,it_req.
endloop.
clear:it_mrp_list,lv_banfn,lv_bnfpo,lv_mng01,lv_mng02,lt_mdkp.
refresh:it_mrp_list.
endloop.
endform. " GET_MRP_LIST
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form process_data .
sort it_pr by dat00 sort1 sort2.
sort it_req by dat00 sort1 sort2.
select matnr maktx
into corresponding fields of table it_makt
from makt
for all entries in it_pr
where matnr = it_pr-matnr.
sort it_makt by matnr.
select matnr bwkey as werks verpr peinh
into corresponding fields of table it_mbew
from mbew
for all entries in it_pr
where matnr = it_pr-matnr
and bwkey = it_pr-werks.
sort it_mbew by matnr werks.
select distinct a~matnr a~werks a~lifnr b~name1 a~flifn a~autet
into corresponding fields of table it_lifnr
from eord as a inner join lfa1 as b on a~lifnr = b~lifnr
for all entries in it_pr
where a~matnr = it_pr-matnr
and a~werks = it_pr-werks.
sort it_lifnr by matnr werks.
describe table it_pr lines lv_total_line.
loop at it_pr.
lv_line = sy-tabix / lv_total_line * 100.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
percentage = lv_line
text = 'Get Data........'.
move-corresponding it_pr to itab.
"Actual req qty Dute date
read table it_req with key banfn = itab-banfn bnfpo = itab-bnfpo.
if sy-subrc eq 0.
itab-datdt = it_req-dat00.
loop at it_req where banfn = itab-banfn and bnfpo = itab-bnfpo.
itab-mng03 = itab-mng03 + it_req-mng01.
endloop.
itab-mng03 = 0 - itab-mng03.
endif.
"Net req. qty
itab-mng04 = itab-mng01 - itab-mng03.
"Desc
read table it_makt with key matnr = itab-matnr binary search.
if sy-subrc eq 0.
itab-maktx = it_makt-maktx.
endif.
"net price
read table it_mbew with key matnr = itab-matnr werks = itab-werks binary search.
if sy-subrc eq 0.
itab-verpr = it_mbew-verpr.
itab-peinh = it_mbew-peinh.
if itab-peinh ne 0.
itab-netwr = itab-verpr * itab-mng04 / it_mbew-peinh.
endif.
endif.
"vendor vendor name
read table it_lifnr with key matnr = itab-matnr
werks = itab-werks
autet = '1'.
if sy-subrc eq 0.
itab-lifnr = it_lifnr-lifnr.
itab-name_v = it_lifnr-name1.
else.
read table it_lifnr with key matnr = itab-matnr
werks = itab-werks
flifn = 'X'.
if sy-subrc eq 0.
itab-lifnr = it_lifnr-lifnr.
itab-name_v = it_lifnr-name1.
else.
read table it_lifnr with key matnr = itab-matnr
werks = itab-werks.
if sy-subrc eq 0.
itab-lifnr = it_lifnr-lifnr.
itab-name_v = it_lifnr-name1.
endif.
endif.
endif.
append itab.
clear:itab.
endloop.
free:it_lifnr,it_makt,it_mbew ,it_pr,it_req,it_mrp_list.
endform. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_data .
define alv_field.
clear:wa_hier.
wa_hier-col_pos = &1.
wa_hier-fieldname = &2.
wa_hier-seltext_m = &3.
wa_hier-seltext_l = &4.
wa_hier-outputlen = &5.
wa_hier-just = &6.
wa_hier-do_sum = &7.
wa_hier-ref_tabname = &8 .
wa_hier-ref_fieldname = &9 .
append wa_hier to fc_hier.
end-of-definition.
refresh: fc_hier.
alv_field '1' 'BANFN' 'PR No.' '' '10' 'L' '' '' ''.
alv_field '2' 'BNFPO' 'PR Item' '' '7' 'L' '' '' ''.
alv_field '3' 'WERKS' 'Plant' '' '5' 'L' '' '' ''.
alv_field '4' 'MATNR' 'Material' '' '18' 'L' '' 'MARA' 'MATNR'.
alv_field '5' 'MAKTX' '' 'Material Desc' '20' 'L' '' '' ''.
alv_field '6' 'MNG01' 'Planned qty' '' '15' 'R' '' '' ''.
alv_field '7' 'MNG03' '' 'Actual req qty' '15' 'R' '' '' ''.
alv_field '8' 'MNG04' 'Net req. qty' '' '15' 'R' '' '' ''.
alv_field '9' 'MEINS' 'Unit' '' '4' 'L' '' '' ''.
alv_field '10' 'DAT02' '' 'Release date' '10' 'L' '' '' ''.
alv_field '11' 'DATDT' 'Dute date' '' '10' 'L' '' '' ''.
alv_field '12' 'UMDAT' '' 'Reschedule date' '10' 'L' '' '' ''.
alv_field '13' 'VERPR' 'Net price' '' '10' 'R' '' '' ''.
alv_field '14' 'PEINH' 'Price unit' '' '10' 'R' '' '' ''.
alv_field '14' 'NETWR' 'Net cost' '' '15' 'R' '' '' ''.
alv_field '16' 'BSTRF' '' 'Rounding value' '10' 'R' '' '' ''.
alv_field '17' 'BSTMI' '' 'Minimum Lot size' '10' 'R' '' '' ''.
alv_field '18' 'LIFNR' '' '100% Vendor code' '10' 'L' '' 'LFA1' 'LIFNR'.
alv_field '19' 'NAME_V' '' 'Vendor Name' '20' 'L' '' '' ''.
sort itab by matnr.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = fc_hier[]
i_save = 'A'
i_callback_program = sy-repid
tables
t_outtab = itab[]
exceptions
program_error = 1
others = 2.
endform. " DISPLAY_DATA