*&---------------------------------------------------------------------*
*& Progarm : ZMMR030 Author : Jimmy Wong
*& Created : 07 Jan 2013 App : MM
*& Title : Detail inventory report
*& Description : Detail inventory report
*&---------------------------------------------------------------------*
*& Version Author Date description
*& Jimmy 07 Jan 2013 the first version
*& the last update time 2013.01.07 10:00
*&---------------------------------------------------------------------*
report zmmr030 no standard page heading.
tables:mchb,marc,mara,v_t604.
data:begin of itab occurs 0,
matnr like mara-matnr, "material
werks like marc-werks, "Plant
lgort type c length 10 , "location
charg like mchb-charg , "Batch
clabs like mchb-clabs, "
maktx like makt-maktx,
stawn like marc-stawn,
text1 like t604t-text1,
text2 like t604t-text2,
text7 like t604t-text7,
meins like mara-meins,
ntgew like mara-ntgew,
gewei like mara-gewei,
end of itab.
data:begin of it_mchb occurs 0,
matnr like mara-matnr, "material
werks like marc-werks, "Plant
lgort type c length 10 , "location
charg like mchb-charg , "Batch
clabs like mchb-clabs, "
meins like mara-meins,
end of it_mchb.
data:it_mchb1 like it_mchb occurs 0 with header line.
data:it_mara like mara occurs 0 with header line.
data:it_marc like marc occurs 0 with header line.
data:it_t604t like t604t occurs 0 with header line.
data:begin of it_makt occurs 0,
matnr like makt-matnr,
maktx like makt-maktx,
end of it_makt.
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
wa_hier type slis_fieldcat_alv .
data:lv_total_line type i,
lv_line type p decimals 3.
*&---------------------------------------------------------------------*
* parameter & select-options
*&---------------------------------------------------------------------*
selection-screen begin of block 1 with frame title text-010.
select-options: s_werks for marc-werks. "Plant
select-options: s_lgort for mchb-lgort. "Location
select-options: s_matnr for mara-matnr. "material code"
select-options: s_mtart for mara-mtart. "Material Type
select-options: s_charg for mchb-charg. "Batch
selection-screen end of block 1.
*&---------------------------------------------------------------------*
* start of process
*&---------------------------------------------------------------------*
start-of-selection.
perform get_onhand_qty.
if it_mchb[] is initial .
message i003(zmm).
exit.
endif.
perform get_other_data.
perform process_data.
perform display_data.
end-of-selection.
*&---------------------------------------------------------------------*
*& Form GET_ONHAND_QTY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_onhand_qty .
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Getting Data........'.
" main stock
select a~charg a~matnr a~werks a~lgort a~clabs
into corresponding fields of table it_mchb1
from mchb as a
inner join mara as b on a~matnr = b~matnr
where a~matnr in s_matnr
and a~werks in s_werks
and a~lgort in s_lgort
and a~charg in s_charg
and a~clabs > 0
and b~mtart in s_mtart.
" project stock - Q
select a~charg a~matnr a~werks a~lgort a~prlab as clabs
appending corresponding fields of table it_mchb1
from mspr as a
inner join mara as b on a~matnr = b~matnr
where a~matnr in s_matnr
and a~werks in s_werks
and a~lgort in s_lgort
and a~charg in s_charg
and a~prlab > 0
and b~mtart in s_mtart.
" project stock - W
select a~charg a~matnr a~werks a~kulab as clabs a~kunnr as lgort
appending corresponding fields of table it_mchb1
from msku as a
inner join mara as b on a~matnr = b~matnr
where a~matnr in s_matnr
and a~werks in s_werks
and a~charg in s_charg
and a~kulab > 0
and b~mtart in s_mtart.
" project stock - K
select a~charg a~matnr a~werks a~lgort a~slabs as clabs
appending corresponding fields of table it_mchb1
from mkol as a
inner join mara as b on a~matnr = b~matnr
where a~matnr in s_matnr
and a~werks in s_werks
and a~lgort in s_lgort
and a~charg in s_charg
and a~slabs > 0
and b~mtart in s_mtart.
" project stock - O
select a~charg a~matnr a~werks a~lblab as clabs a~lifnr as lgort
appending corresponding fields of table it_mchb1
from mslb as a
inner join mara as b on a~matnr = b~matnr
where a~matnr in s_matnr
and a~werks in s_werks
and a~charg in s_charg
and a~lblab > 0
and b~mtart in s_mtart.
loop at it_mchb1.
move-corresponding it_mchb1 to it_mchb.
collect it_mchb.
clear:it_mchb.
endloop.
endform. " GET_ONHAND_QTY
*&---------------------------------------------------------------------*
*& Form GET_OTHER_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_other_data .
sort it_mchb by matnr werks.
select *
into corresponding fields of table it_t604t
from t604t
where spras = sy-langu .
sort it_t604t by land1 stawn .
select *
into table it_mara
from mara
for all entries in it_mchb
where matnr = it_mchb-matnr.
sort it_mara by matnr .
select *
into table it_marc
from marc
for all entries in it_mchb
where matnr = it_mchb-matnr
and werks = it_mchb-werks.
sort it_marc by matnr werks.
select matnr maktx
into table it_makt
from makt
for all entries in it_mchb
where matnr = it_mchb-matnr.
sort it_makt by matnr .
endform. " GET_OTHER_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form process_data .
describe table it_mchb lines lv_total_line.
loop at it_mchb.
lv_line = sy-tabix / lv_total_line * 100.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
percentage = lv_line
text = 'Processing Data........'.
move-corresponding it_mchb to itab.
" material desc
read table it_makt with key matnr = itab-matnr binary search.
if sy-subrc eq 0.
itab-maktx = it_makt-maktx.
endif.
read table it_mara with key matnr = itab-matnr binary search.
if sy-subrc eq 0.
itab-meins = it_mara-meins.
itab-ntgew = it_mara-ntgew.
itab-gewei = it_mara-gewei.
endif.
read table it_marc with key matnr = itab-matnr werks = itab-werks binary search.
if sy-subrc eq 0.
itab-stawn = it_marc-stawn .
read table it_t604t with key stawn = itab-stawn.
if sy-subrc eq 0.
itab-text1 = it_t604t-text1 .
itab-text2 = it_t604t-text2 .
itab-text7 = it_t604t-text7 .
endif.
endif.
append itab.
clear:itab.
endloop.
endform. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_data .
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.
refresh: fc_hier.
alv_field 'WERKS' 'Plant' '' '5' 'L' '' '' ''.
alv_field 'MATNR' 'Material' '' '18' 'L' '' 'MARA' 'MATNR'.
alv_field 'MAKTX' '' 'Material desc' '20' 'L' '' '' ''.
alv_field 'TEXT2' '' 'Customer code' '10' 'L' '' '' ''.
alv_field 'TEXT1' '' 'Chinese desc' '15' 'L' '' '' ''.
alv_field 'STAWN' '' 'HS Code' '15' 'L' '' '' ''.
alv_field 'LGORT' '' 'Storage location' '10' 'L' '' '' ''.
alv_field 'CHARG' '' 'Batch' '10' 'L' '' '' ''.
alv_field 'MEINS' '' 'Stocking UM' '8' 'L' '' '' ''.
alv_field 'CLABS' '' 'Onhand qty' '12' 'R' '' '' ''.
alv_field 'TEXT7' '' 'Customs UM' '6' 'L' '' '' ''.
alv_field 'NTGEW' '' 'Unit weight' '10' 'R' '' '' ''.
alv_field 'GEWEI' '' 'Weight unit' '6' 'L' '' '' ''.
sort itab by matnr werks.
free :it_mchb,it_mchb1,it_mara,it_marc,it_t604t,it_makt.
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.
if sy-subrc ne 0.
write: sy-msgv1,sy-msgv2, sy-msgv3, sy-msgv4.
endif.
endform. " DISPLAY_DATA