*&---------------------------------------------------------------------*
*& Progarm : ZPPR017 Author : Jimmy Wong
*& Created : 18 Oct 2012 App : PP
*& Title : Material requirement(INBV77)
*& Description : Material requirement(INBV77)
*& T457T AR OrdRes OrderRes (per month request qty) production order
*& BB SubReq SubcReqmt production order 外发
*& PP IndReq IndReqmt plan order
*& SB DepReq DependReq plan order
*&---------------------------------------------------------------------*
*& Version Author Date description
*& Jimmy 18 Oct 2012 the first version
*& M1 Jimmy 13 Mar 2013 add By Week method
*& the last update time 2013.03.13 18:00
*&---------------------------------------------------------------------*
report zppr017 no standard page heading.
*&---------------------------------------------------------------------*
* database table
*&---------------------------------------------------------------------*
tables : mara,marc.
*&---------------------------------------------------------------------*
* internal table & variables
*&---------------------------------------------------------------------*
data:begin of wa_itab occurs 0,
werks like marc-werks,
matnr like mara-matnr,
clabs like mchb-clabs, "On Hand qty
menge like ekpo-menge, "On Order Qty
bstmi like marc-bstmi, "Minimum Lot Size
bstrf like marc-bstrf, "Rounding value
plifz like marc-plifz, "Planned Deliv. Time
verpr like mbew-verpr, "net price
peinh like mbew-peinh,
mfrnr like mara-mfrnr, "Order No.
mfrpn like mara-mfrpn, "Manufacturer
zzcw type p, " CW
zzrw type p, "RW
lifnr like lfa1-lifnr,
name1 like lfa1-name1,
m_matnr type c length 255,
jan like ekpo-menge,
feb like ekpo-menge,
mar like ekpo-menge,
apr like ekpo-menge,
may like ekpo-menge,
jun like ekpo-menge,
jul like ekpo-menge,
aug like ekpo-menge,
sep like ekpo-menge,
oct like ekpo-menge,
nov like ekpo-menge,
dec like ekpo-menge,
meins like mara-meins,
slabs like mkol-slabs,
menge_p like ekpo-menge, "Production order Qty
kdmat like knmt-kdmat, "Customer Material
end of wa_itab.
data: it_itab like wa_itab occurs 0 with header line.
data: it_matnr like zpp_bom_fg occurs 0 with header line.
data: it_matnr2 like zpp_bom_fg occurs 0 with header line.
data: it_matnr3 like zpp_bom_fg occurs 0 with header line.
data: it_mrp_list like bapi_mrp_ind_lines occurs 0 with header line.
data:begin of it_handqty1 occurs 0,
werks like marc-werks,
matnr like mara-matnr,
lgort like mchb-lgort ,
charg like mchb-charg ,
clabs like mchb-clabs, "On Hand qty
end of it_handqty1.
data: it_handqty like it_handqty1 occurs 0 with header line.
data:begin of it_verpr occurs 0,
werks like marc-werks,
matnr like mara-matnr,
vprsv like mbew-vprsv,
verpr like mbew-verpr, "net price
stprs like mbew-stprs ,
peinh like mbew-peinh,
end of it_verpr.
data: begin of it_mkol1 occurs 0 ,
matnr like mkol-matnr,
werks like mkol-werks,
lgort like mkol-lgort,
charg like mkol-charg,
sobkz like mkol-sobkz,
lifnr like mkol-lifnr,
slabs like mkol-slabs,
end of it_mkol1.
data:it_mkol like it_mkol1 occurs 0 with header line.
data:lv_first type sy-datum,
lv_last type sy-datum,
lv_week_f type kweek,
lv_week_t type kweek,
lv_month(2) type c,
lv_firstmonth(2) type c.
data: begin of it_field occurs 0,
index type i,
fieldname(10) type c,
fielddesc(40) type c,
end of it_field.
data:begin of it_info_rec occurs 0,
matnr like mara-matnr,
werks like ekpo-werks,
zzcw like zmmt_info_rec-zzcw,
zzrw like zmmt_info_rec-zzrw ,
end of it_info_rec.
data:begin of it_lifnr occurs 0,
matnr like mara-matnr,
werks like marc-werks,
lifnr like lfa1-lifnr,
name1 like lfa1-name1,
end of it_lifnr.
data:begin of it_knmt occurs 0,
matnr like mara-matnr,
vkorg like knmt-vkorg,
kdmat like knmt-kdmat ,
end of it_knmt.
data: begin of it_down occurs 0,
line type c length 10000,
end of it_down .
data:lv_string type string.
data:lv_type type string.
types:lv_types type string.
data: gv_file like rlgrap-filename.
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
wa_hier type slis_fieldcat_alv .
field-symbols: <dyn_table> type standard table, "Dynamic internal table name
<dyn_wa> type any, "Field symbol to create work area
<dyn_field> type any. "Field symbol to assign values
data: dy_table type ref to data,
dy_line type ref to data,
it_structure type lvc_t_fcat,
wa_structure type lvc_s_fcat.
define create_stru.
wa_structure-fieldname = &1.
wa_structure-inttype = &2.
wa_structure-intlen = &3.
wa_structure-datatype = &4.
wa_structure-decimals = &5.
append wa_structure to it_structure.
end-of-definition.
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.
*----------------------------------------------------------------------*
* Parameter & Select-Options *
*----------------------------------------------------------------------*
selection-screen begin of block 1 with frame title text-001.
select-options : s_werks for marc-werks obligatory default '8101'.
select-options : s_matnr for mara-matnr.
select-options : s_mtart for mara-mtart.
select-options : ms_werks for marc-werks no-display.
parameters p_date type pam_month obligatory .
parameters: p_txt as checkbox .
parameters: p_file like rlgrap-filename default 'C:\temp' .
selection-screen end of block 1.
selection-screen begin of block 2 with frame title text-002. "M1 add
parameters: p_month radiobutton group gp1,
p_week radiobutton group gp1.
selection-screen end of block 2.
initialization .
concatenate sy-datum+0(4) sy-datum+4(2) into p_date.
at selection-screen on value-request for p_file.
perform f4_filename using p_file .
*&---------------------------------------------------------------------*
* start of process
*&---------------------------------------------------------------------*
start-of-selection.
perform get_data.
if wa_itab[] is initial .
message 'No Record Found' type 'I'.
exit.
endif.
if p_month = 'X'. "M1 add
perform get_date.
perform get_date_fieldname.
if p_txt = 'X'.
perform add_header.
endif.
perform get_other_data.
perform process_data.
perform free_table.
endif.
*M1 add
if p_week = 'X'.
perform create_structure_w.
if p_txt = 'X'.
perform add_header.
endif.
perform create_dynamic_table_w.
perform get_other_data.
perform process_data_w.
perform free_table.
endif.
*M1 End
if p_txt = 'X'.
perform download_local.
else.
perform dispaly_data.
endif.
end-of-selection.
*&---------------------------------------------------------------------*
*& Form GET_DATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_date .
data:lv_year(4) type c.
concatenate p_date '01' into lv_first. "current Month first day
lv_year = p_date+0(4) + 1 .
concatenate lv_year+0(4) p_date+4(2) '01' into lv_last.
lv_firstmonth = p_date+4(2).
endform. " GET_DATE
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
clear:wa_itab.
refresh:wa_itab.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Getting Data........'.
select a~matnr b~werks b~bstmi b~bstrf b~plifz a~mfrnr a~mfrpn a~meins
into corresponding fields of table wa_itab
from mara as a inner join marc as b on a~matnr = b~matnr
where a~matnr in s_matnr
and b~werks in s_werks
and a~mtart in s_mtart.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form GET_OTHER_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_other_data .
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Getting Base Data........'.
sort wa_itab by matnr werks.
select matnr werks lgort charg sobkz lifnr slabs
into corresponding fields of table it_mkol1
from mkol
for all entries in wa_itab
where matnr = wa_itab-matnr
and werks = wa_itab-werks
and slabs > 0.
loop at it_mkol1.
it_mkol-matnr = it_mkol1-matnr.
it_mkol-werks = it_mkol1-werks.
it_mkol-slabs = it_mkol1-slabs.
collect it_mkol.
clear :it_mkol.
endloop.
sort it_mkol by matnr werks.
select matnr bwkey as werks vprsv verpr stprs peinh
into corresponding fields of table it_verpr
from mbew
for all entries in wa_itab
where matnr = wa_itab-matnr
and bwkey = wa_itab-werks.
sort it_verpr by matnr werks.
select matnr werks zzcw zzrw
into corresponding fields of table it_info_rec
from zmmt_info_rec
for all entries in wa_itab
where matnr = wa_itab-matnr
and werks = wa_itab-werks.
sort it_info_rec by matnr werks.
select a~matnr a~werks a~lifnr b~name1
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 wa_itab
where a~matnr = wa_itab-matnr
and a~werks = wa_itab-werks
and a~autet = '1'.
sort it_lifnr by matnr werks.
if p_week = 'X'.
select matnr vkorg kdmat
into corresponding fields of table it_knmt
from knmt
for all entries in wa_itab
where vkorg = wa_itab-werks
and vtweg = '10'
and matnr = wa_itab-matnr.
sort it_knmt by matnr vkorg.
endif.
endform. " GET_OTHER_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form process_data .
data:lv_strmatnr type string.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Processing Data........'.
loop at wa_itab.
move-corresponding wa_itab to it_itab.
"Unrestricted-Use Consignment
read table it_mkol with key matnr = it_itab-matnr
werks = it_itab-werks binary search.
if sy-subrc eq 0.
it_itab-slabs = it_mkol-slabs .
endif.
"net price
read table it_verpr with key matnr = it_itab-matnr
werks = it_itab-werks binary search.
if sy-subrc eq 0.
it_itab-peinh = it_verpr-peinh .
if it_verpr-vprsv = 'V'.
it_itab-verpr = it_verpr-verpr .
else.
it_itab-verpr = it_verpr-stprs .
endif.
endif.
"cw rw
read table it_info_rec with key matnr = it_itab-matnr werks = it_itab-werks binary search.
if sy-subrc eq 0.
it_itab-zzcw = it_info_rec-zzcw.
it_itab-zzrw = it_info_rec-zzrw .
endif.
"vendor vendor name
read table it_lifnr with key matnr = it_itab-matnr
werks = it_itab-werks binary search.
if sy-subrc eq 0.
it_itab-lifnr = it_lifnr-lifnr.
it_itab-name1 = it_lifnr-name1.
endif.
call function 'BAPI_MATERIAL_MRP_LIST'
exporting
material = it_itab-matnr
plant = it_itab-werks
tables
mrp_ind_lines = it_mrp_list.
* " On hand qty = mmbe Unrestricted use
loop at it_mrp_list where ( mrp_element_ind = 'WB' or mrp_element_ind = 'PB' ) and rec_reqd_qty > 0 ."and avail_date < lv_last.
it_itab-clabs = it_itab-clabs + it_mrp_list-rec_reqd_qty .
endloop.
* "On Order qty = mmbe On Order
loop at it_mrp_list where ( mrp_element_ind = 'BE' or mrp_element_ind = 'LA' ) and rec_reqd_qty > 0 ."and avail_date < lv_last.
it_itab-menge = it_itab-menge + it_mrp_list-rec_reqd_qty .
endloop.
delete it_mrp_list where avail_date >= lv_last "avail_date < lv_first or
or ( mrp_element_ind ne 'AR'
and mrp_element_ind ne 'BB'
and mrp_element_ind ne 'PP'
and mrp_element_ind ne 'SB') .
if not it_mrp_list[] is initial.
loop at it_mrp_list.
if it_mrp_list-avail_date < lv_first.
lv_month = lv_firstmonth.
else.
lv_month = it_mrp_list-avail_date+4(2).
endif.
case lv_month.
when '01'.
it_itab-jan = it_itab-jan + abs( it_mrp_list-rec_reqd_qty ).
when '02'.
it_itab-feb = it_itab-feb + abs( it_mrp_list-rec_reqd_qty ).
when '03'.
it_itab-mar = it_itab-mar + abs( it_mrp_list-rec_reqd_qty ).
when '04'.
it_itab-apr = it_itab-apr + abs( it_mrp_list-rec_reqd_qty ).
when '05'.
it_itab-may = it_itab-may + abs( it_mrp_list-rec_reqd_qty ).
when '06'.
it_itab-jun = it_itab-jun + abs( it_mrp_list-rec_reqd_qty ).
when '07'.
it_itab-jul = it_itab-jul + abs( it_mrp_list-rec_reqd_qty ).
when '08'.
it_itab-aug = it_itab-aug + abs( it_mrp_list-rec_reqd_qty ).
when '09'.
it_itab-sep = it_itab-sep + abs( it_mrp_list-rec_reqd_qty ).
when '10'.
it_itab-oct = it_itab-oct + abs( it_mrp_list-rec_reqd_qty ).
when '11'.
it_itab-nov = it_itab-nov + abs( it_mrp_list-rec_reqd_qty ).
when '12'.
it_itab-dec = it_itab-dec + abs( it_mrp_list-rec_reqd_qty ).
endcase.
" Where use
perform get_where_used_data using it_mrp_list-elemnt_data.
endloop.
endif.
"where used
perform get_where_used changing lv_strmatnr.
it_itab-m_matnr = lv_strmatnr.
append it_itab.
if p_txt = 'X'.
lv_type = it_itab-werks.
perform get_string using lv_type
changing lv_string.
perform tranfer_material using it_itab-matnr 'X' changing lv_type.
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-clabs .
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-menge .
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-slabs.
perform get_string using lv_type
changing lv_string.
loop at it_field.
case it_field-fielddesc.
when 'Jan'.
lv_type = it_itab-jan.
when 'Feb'.
lv_type = it_itab-feb.
when 'Mar'.
lv_type = it_itab-mar.
when 'Apr'.
lv_type = it_itab-apr.
when 'May'.
lv_type = it_itab-may.
when 'Jun'.
lv_type = it_itab-jun.
when 'Jul'.
lv_type = it_itab-jul.
when 'Aug'.
lv_type = it_itab-aug.
when 'Sep'.
lv_type = it_itab-sep.
when 'Oct'.
lv_type = it_itab-oct.
when 'Nov'.
lv_type = it_itab-nov.
when 'Dec'.
lv_type = it_itab-dec.
endcase.
perform get_string using lv_type
changing lv_string.
endloop.
lv_type = it_itab-bstmi .
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-bstrf.
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-plifz.
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-verpr.
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-peinh.
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-mfrpn.
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-mfrnr.
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-zzcw.
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-zzrw.
perform get_string using lv_type
changing lv_string.
lv_type = it_itab-name1.
perform get_string using lv_type
changing lv_string.
perform get_string using lv_strmatnr
changing lv_string.
it_down-line = lv_string.
condense it_down .
append it_down .
endif.
clear: it_itab,it_matnr,it_matnr[],it_mrp_list,it_mrp_list[],
it_matnr2,it_matnr2[],lv_strmatnr,lv_string,
it_matnr3,it_matnr3[].
endloop.
endform. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form tranfer_material
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_OLD text
* -->P_OUTPUT text
* -->P_NEW text
*----------------------------------------------------------------------*
form tranfer_material using p_old
p_output
changing p_new .
if p_output = 'X'.
call function 'CONVERSION_EXIT_MATN1_OUTPUT'
exporting
input = p_old
importing
output = p_new.
else.
data:lv_input type c length 50.
lv_input = p_old.
translate lv_input to upper case.
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = lv_input
importing
output = p_new
exceptions
length_error = 1
others = 2.
if sy-subrc <> 0.
endif.
endif.
endform. "tranfer_material
*&---------------------------------------------------------------------*
*& Form GET_DATE_FIELDNAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_date_fieldname .
data:lv_date type sy-datum,
lv_en_month(3) type c.
lv_date = lv_first.
clear:it_field,it_field[].
while lv_date < lv_last.
lv_month = lv_date+4(2) .
perform get_en_month using lv_month
changing lv_en_month.
it_field-index = it_field-index + 1.
it_field-fieldname = lv_en_month.
translate it_field-fieldname to upper case.
it_field-fielddesc = lv_en_month.
append it_field.
perform get_next_month using lv_date 1 changing lv_date.
endwhile.
endform. " GET_DATE_FIELDNAME
*&---------------------------------------------------------------------*
*& Form get_last_day
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FROM text
* -->P_TO text
*----------------------------------------------------------------------*
form get_next_month using p_from
p_month
changing p_to.
call function 'BKK_ADD_MONTH_TO_DATE'
exporting
months = p_month
olddate = p_from
importing
newdate = p_to.
endform. "get_last_day
*&---------------------------------------------------------------------*
*& Form GET_EN_MONTH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LV_MONTH text
*----------------------------------------------------------------------*
form get_en_month using p_month
changing p_en_month.
case p_month.
when '01'.
p_en_month = 'Jan'.
when '02'.
p_en_month = 'Feb'.
when '03'.
p_en_month = 'Mar'.
when '04'.
p_en_month = 'Apr'.
when '05'.
p_en_month = 'May'.
when '06'.
p_en_month = 'Jun'.
when '07'.
p_en_month = 'Jul'.
when '08'.
p_en_month = 'Aug'.
when '09'.
p_en_month = 'Sep'.
when '10'.
p_en_month = 'Oct'.
when '11'.
p_en_month = 'Nov'.
when '12'.
p_en_month = 'Dec'.
endcase.
endform. " GET_EN_MONTH
*&---------------------------------------------------------------------*
*& Form DISPALY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form dispaly_data .
refresh: fc_hier.
alv_field 'WERKS' 'Plant' '' '6' 'L' '' '' ''.
alv_field 'MATNR' 'Material' '' '18' 'L' '' 'MARA' 'MATNR'.
if p_week = 'X'.
alv_field 'KDMAT' '' 'Customer Material' '15' 'L' '' '' ''.
endif.
alv_field 'CLABS' '' 'On Hand Qty' '15' 'R' '' '' ''.
alv_field 'MENGE' '' 'On Order Qty' '15' 'R' '' '' ''.
alv_field 'SLABS' '' 'Unrestr. Consignment' '15' 'R' '' '' ''.
if p_week = 'X'.
alv_field 'MENGE_P' '' 'Prod Order Qty' '15' 'R' '' '' ''.
endif.
loop at it_field.
alv_field it_field-fieldname it_field-fielddesc '' '12' 'R' '' '' ''.
endloop.
alv_field 'BSTMI' '' 'Minimum Lot Size' '' 'R' '' '' ''.
alv_field 'BSTRF' '' 'Rounding value' '' 'R' '' '' ''.
alv_field 'PLIFZ' '' 'Planned Deliv. Time' '' 'L' '' '' ''.
alv_field 'VERPR' 'Net Price' '' '' 'R' '' '' ''.
alv_field 'PEINH' 'Price Unit' '' '' 'R' '' '' ''.
alv_field 'MFRPN' '' 'Order No.' '' 'L' '' '' ''.
alv_field 'MFRNR' '' 'Manufacturer' '' 'L' '' '' ''.
alv_field 'ZZCW' 'Can Win' '' '' 'R' '' '' ''.
alv_field 'ZZRW' 'Res. Win' '' '' 'R' '' '' ''.
alv_field 'NAME1' '' 'Vendor Name' '20' 'L' '' '' ''.
alv_field 'M_MATNR' '' 'Where Used' '50' 'L' '' '' ''.
if p_month = 'X'.
perform display_alv tables fc_hier it_itab using 'A'.
endif.
if p_week = 'X'.
perform display_alv tables fc_hier <dyn_table> using 'A'.
endif.
endform. " DISPALY_DATA
*&---------------------------------------------------------------------*
*& Form f4_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_FILENAME text
*----------------------------------------------------------------------*
form f4_filename using p_filename.
call function 'F4_FILENAME'
* EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME =
importing
file_name = p_filename.
endform. " F4_FILENAME
*&---------------------------------------------------------------------*
*& Form ADD_HEADER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form add_header .
perform get_string using 'Plant' changing lv_string.
perform get_string using 'Material' changing lv_string.
if p_week = 'X'.
perform get_string using 'Cust Material' changing lv_string.
endif.
perform get_string using 'On Hand Qty' changing lv_string.
perform get_string using 'On Order Qty' changing lv_string.
perform get_string using 'Unrestr. Consignment' changing lv_string.
if p_week = 'X'.
perform get_string using 'Prod Order Qty' changing lv_string.
endif.
loop at it_field.
lv_type = it_field-fielddesc .
perform get_string using lv_type changing lv_string.
endloop.
perform get_string using 'Minimum Lot Size' changing lv_string.
perform get_string using 'Rounding value' changing lv_string.
perform get_string using 'Planned Deliv. Time' changing lv_string.
perform get_string using 'Net Price' changing lv_string.
perform get_string using 'Price Unit' changing lv_string.
perform get_string using 'Order No' changing lv_string.
perform get_string using 'Manufacturer' changing lv_string.
perform get_string using 'Can Win' changing lv_string.
perform get_string using 'Res. Win' changing lv_string.
perform get_string using 'Vendor Name' changing lv_string.
perform get_string using 'Where Used' changing lv_string.
it_down-line = lv_string.
condense it_down .
append it_down .
clear:it_down ,lv_string.
endform. " ADD_HEADER
*&---------------------------------------------------------------------*
*& Form GET_STRING
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LV_TYPE text
* <--P_LV_STRING text
*----------------------------------------------------------------------*
form get_string using p_type type lv_types
changing p_string.
shift p_type right deleting trailing space.
shift p_type left deleting leading space.
if p_string is initial.
p_string = p_type.
else.
concatenate p_string
p_type
into p_string separated by cl_abap_char_utilities=>horizontal_tab.
endif.
condense p_string.
endform. " GET_STRING
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_LOCAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form download_local .
data: lv_filename type string.
perform get_file.
lv_filename = gv_file.
call function 'GUI_DOWNLOAD'
exporting
filename = lv_filename
filetype = 'ASC'
write_field_separator = 'X'
tables
data_tab = it_down
exceptions
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
others = 22.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " DOWNLOAD_LOCAL
*&---------------------------------------------------------------------*
*& Form GET_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_file .
data: wa_key(30) type c.
data: lv_i type i.
data: lv_c(1) type c.
data: wa_date(8) type c.
data: wa_time like sy-uzeit.
data: lv_char type c.
wa_date = sy-datum.
wa_time = sy-uzeit.
concatenate 'ZPPR017' wa_date wa_time into wa_key.
concatenate wa_key '.txt' into wa_key.
lv_i = strlen( p_file ).
lv_i = lv_i - 1 .
if lv_i > 1.
lv_c = p_file+lv_i(1).
endif.
* if p_test = 'X'.
lv_char = '\' .
* else.
* lv_char = '/' .
* endif.
if lv_c eq lv_char.
concatenate p_file wa_key into gv_file.
else.
concatenate p_file lv_char wa_key into gv_file.
endif.
endform. " GET_FILE
*&---------------------------------------------------------------------*
*& Form GET_ZVFG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_MATNR2_MATNR_C text
* <--P_LV_STRMATNR text
*----------------------------------------------------------------------*
form get_zvfg using p_matnr_c
changing p_strmatnr.
data: lv_matnr type c length 18.
if p_txt = 'X'.
lv_matnr = p_matnr_c.
else.
lv_matnr = p_matnr_c+5(4).
endif.
read table it_matnr3 with key matnr_c = lv_matnr.
if sy-subrc ne 0.
if p_strmatnr is initial.
p_strmatnr = lv_matnr.
else.
concatenate p_strmatnr ',' lv_matnr into p_strmatnr.
endif.
it_matnr3-matnr_c = lv_matnr.
collect it_matnr3.
clear:it_matnr3.
endif.
endform. " GET_ZVFG
*&---------------------------------------------------------------------*
*& Form CREATE_STRUCTURE_W
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form create_structure_w .
data: l_fname_i type i,
l_week(2),
g_week(3),
l_year(4),
lv_str type i,
l_fname type lvc_fname.
create_stru 'WERKS' 'C' '4' '' '' .
create_stru 'MATNR' 'C' '20' '' '' .
create_stru 'KDMAT' 'C' '20' '' '' .
create_stru 'CLABS' 'P' '20' 'DEC' '3' .
create_stru 'MENGE' 'P' '20' 'DEC' '3' .
create_stru 'SLABS' 'P' '20' 'DEC' '3' .
create_stru 'MENGE_P' 'P' '20' 'DEC' '3' .
l_week = p_date+4(2).
l_year = p_date+0(4).
lv_week_f = p_date.
l_fname_i = p_date.
perform get_first_date_by_week using lv_week_f changing lv_first.
do 52 times.
lv_str = strlen( l_week ).
if lv_str = 1.
concatenate '0' l_week into g_week.
else.
g_week = l_week .
endif.
concatenate l_year g_week into lv_week_t .
l_fname = l_fname_i.
condense l_fname.
it_field-index = it_field-index + 1.
it_field-fieldname = l_fname.
concatenate 'W' l_fname into it_field-fielddesc .
collect it_field.
create_stru l_fname 'P' '20' 'DEC' '3' .
l_week = l_week + 1.
l_fname_i = l_fname_i + 1.
if l_week = 53.
l_year = l_year + 1.
l_week = '01'.
concatenate l_year l_week into l_fname.
l_fname_i = l_fname.
endif.
enddo.
perform get_first_date_by_week using lv_week_t changing lv_last.
lv_last = lv_last + 6.
create_stru 'BSTMI' 'P' '13' 'DEC' '' .
create_stru 'BSTRF' 'P' '13' 'DEC' '' .
create_stru 'PLIFZ' 'P' '3' 'DEC' '' .
create_stru 'VERPR' 'P' '20' 'DEC' '2' .
create_stru 'PEINH' 'P' '20' 'DEC' '' .
create_stru 'MFRPN' 'C' '40' '' '' .
create_stru 'MFRNR' 'C' '10' '' '' .
create_stru 'ZZCW' 'C' '3' '' '' .
create_stru 'ZZRW' 'C' '3' '' '' .
create_stru 'NAME1' 'C' '20' '' '' .
create_stru 'M_MATNR' 'C' '255' '' '' .
endform. " CREATE_STRUCTURE_W
*&---------------------------------------------------------------------*
*& Form CREATE_DYNAMIC_TABLE_W
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form create_dynamic_table_w .
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_structure
importing
ep_table = dy_table.
assign dy_table->* to <dyn_table>. " 用表类型指针 <dyn_table> 指向 数据对象的内容.
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
endform. " CREATE_DYNAMIC_TABLE_W
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA_W
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form process_data_w .
data:lv_strmatnr type string,
lv_week type kweek,
lv_week_c type c length 6.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Processing Data........'.
loop at wa_itab.
assign component 'WERKS' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-werks.
assign component 'MATNR' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-matnr.
"customer material
assign component 'KDMAT' of structure <dyn_wa> to <dyn_field>.
read table it_knmt with key matnr = wa_itab-matnr vkorg = wa_itab-werks binary search.
if sy-subrc eq 0.
<dyn_field> = it_knmt-kdmat.
endif.
"Unrestricted-Use Consignment
assign component 'SLABS' of structure <dyn_wa> to <dyn_field>.
read table it_mkol with key matnr = wa_itab-matnr
werks = wa_itab-werks binary search.
if sy-subrc eq 0.
<dyn_field> = it_mkol-slabs.
endif.
assign component 'BSTMI' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-bstmi.
assign component 'BSTRF' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-bstrf.
assign component 'PLIFZ' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-plifz.
"net price
read table it_verpr with key matnr = wa_itab-matnr
werks = wa_itab-werks binary search.
if sy-subrc eq 0.
wa_itab-peinh = it_verpr-peinh .
if it_verpr-vprsv = 'V'.
wa_itab-verpr = it_verpr-verpr .
else.
wa_itab-verpr = it_verpr-stprs .
endif.
endif.
assign component 'VERPR' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-verpr.
assign component 'PEINH' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-peinh.
assign component 'MFRPN' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-mfrpn.
assign component 'MFRNR' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-mfrnr.
"cw rw
read table it_info_rec with key matnr = wa_itab-matnr werks = wa_itab-werks binary search.
if sy-subrc eq 0.
wa_itab-zzcw = it_info_rec-zzcw.
wa_itab-zzrw = it_info_rec-zzrw .
endif.
assign component 'ZZCW' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-zzcw.
assign component 'ZZRW' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-zzrw.
"vendor vendor name
read table it_lifnr with key matnr = wa_itab-matnr
werks = wa_itab-werks binary search.
if sy-subrc eq 0.
wa_itab-lifnr = it_lifnr-lifnr.
wa_itab-name1 = it_lifnr-name1.
endif.
assign component 'NAME1' of structure <dyn_wa> to <dyn_field>.
<dyn_field> = wa_itab-name1.
call function 'BAPI_MATERIAL_MRP_LIST'
exporting
material = wa_itab-matnr
plant = wa_itab-werks
tables
mrp_ind_lines = it_mrp_list.
* " On hand qty = mmbe Unrestricted use
assign component 'CLABS' of structure <dyn_wa> to <dyn_field>.
loop at it_mrp_list where ( mrp_element_ind = 'WB' or mrp_element_ind = 'PB' ) and rec_reqd_qty > 0 ."and avail_date < lv_last.
<dyn_field> = <dyn_field> + it_mrp_list-rec_reqd_qty .
endloop.
* "On Order qty = mmbe On Order
assign component 'MENGE' of structure <dyn_wa> to <dyn_field>.
loop at it_mrp_list where ( mrp_element_ind = 'BE' or mrp_element_ind = 'LA' ) and rec_reqd_qty > 0 ."and avail_date < lv_last.
<dyn_field> = <dyn_field> + it_mrp_list-rec_reqd_qty .
endloop.
assign component 'MENGE_P' of structure <dyn_wa> to <dyn_field>.
delete it_mrp_list where avail_date > lv_last "
or ( mrp_element_ind ne 'AR'
and mrp_element_ind ne 'BB'
and mrp_element_ind ne 'PP'
and mrp_element_ind ne 'SB') .
loop at it_mrp_list where mrp_element_ind = 'AR' or mrp_element_ind = 'BB' .
<dyn_field> = <dyn_field> + abs( it_mrp_list-rec_reqd_qty ) .
endloop.
if not it_mrp_list[] is initial.
loop at it_mrp_list.
if it_mrp_list-mrp_element_ind = 'PP' or it_mrp_list-mrp_element_ind = 'SB'.
perform get_week using it_mrp_list-avail_date changing lv_week .
if lv_week < lv_week_f.
lv_week_c = lv_week_f.
else.
lv_week_c = lv_week .
endif.
assign component lv_week_c of structure <dyn_wa> to <dyn_field>.
<dyn_field> = <dyn_field> + abs( it_mrp_list-rec_reqd_qty ).
endif.
" Where use
perform get_where_used_data using it_mrp_list-elemnt_data.
endloop.
endif.
assign component 'M_MATNR' of structure <dyn_wa> to <dyn_field>.
perform get_where_used changing lv_strmatnr.
<dyn_field> = lv_strmatnr.
if p_txt = 'X'.
loop at it_structure into wa_structure.
assign component wa_structure-fieldname of structure <dyn_wa> to <dyn_field>.
if wa_structure-fieldname = 'MATNR'.
perform tranfer_material using <dyn_field> 'X' changing lv_type.
else.
lv_type = <dyn_field>.
endif.
perform get_string using lv_type changing lv_string.
endloop.
it_down-line = lv_string.
condense it_down .
append it_down .
endif.
append <dyn_wa> to <dyn_table>.
clear: <dyn_wa>,it_matnr,it_matnr[],it_mrp_list,it_mrp_list[],
it_matnr2,it_matnr2[],lv_strmatnr,lv_string,
it_matnr3,it_matnr3[].
endloop.
endform. " PROCESS_DATA_W
*&---------------------------------------------------------------------*
*& Form get_first_date_by_week
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WEEK text
* -->P_DATE text
*----------------------------------------------------------------------*
form get_first_date_by_week using p_week
changing p_date .
call function 'HRIQ_WEEK_GET_FIRST_DAY'
exporting
week = p_week
importing
date = p_date
exceptions
week_invalid = 1
others = 2.
endform. "get_first_date_by_week
*&---------------------------------------------------------------------*
*& Form get_week
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_DATE text
* -->P_WEEK text
*----------------------------------------------------------------------*
form get_week using p_date
changing p_week.
call function 'GET_WEEK_INFO_BASED_ON_DATE'
exporting
date = p_date
importing
week = p_week
* monday =
* sunday =
.
endform. "get_week
*&---------------------------------------------------------------------*
*& Form GET_WHERE_USED
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_LV_STRMATNR text
*----------------------------------------------------------------------*
form get_where_used changing p_strmatnr.
if it_matnr2[] is not initial.
loop at it_matnr2.
if it_matnr2-matnr+0(2) = '80'.
perform get_zvfg using it_matnr2-matnr_c
changing p_strmatnr .
else.
call function 'ZGET_MAT_BOM_SELECT_WHERE_USED'
exporting
material = it_matnr2-matnr
plant = wa_itab-werks
materialtype = 'ZVFG'
tables
it_matnr = it_matnr.
if it_matnr[] is not initial.
loop at it_matnr.
perform get_zvfg using it_matnr-matnr_c
changing p_strmatnr .
endloop.
endif.
endif.
clear: it_matnr,it_matnr[].
endloop.
endif.
endform. " GET_WHERE_USED
*&---------------------------------------------------------------------*
*& Form FREE_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form free_table .
free:it_handqty1,it_handqty,it_verpr,it_info_rec,
it_lifnr,it_mkol,it_mkol1,it_matnr2,it_matnr3,
it_knmt.
endform. " FREE_TABLE
*&---------------------------------------------------------------------*
*& Form GET_WHERE_USED_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_MRP_LIST_ELEMNT_DATA text
*----------------------------------------------------------------------*
form get_where_used_data using p_matnr.
data:lv_len type i,
wa_matnr like mara-matnr.
lv_len = strlen( p_matnr ).
if lv_len > 9.
condense p_matnr.
perform tranfer_material using p_matnr ''
changing wa_matnr .
read table it_matnr2 with key matnr = wa_matnr .
if sy-subrc ne 0.
it_matnr2-matnr = wa_matnr .
it_matnr2-matnr_c = it_mrp_list-elemnt_data.
collect it_matnr2.
clear:it_matnr2.
endif.
endif.
endform. " GET_WHERE_USED_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
tables
t_outtab = itab[]
exceptions
program_error = 1
others = 2.
endform. "display_alv