SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Calculation of opening stock of a material



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Sat Oct 06, 2007 1:04 am    Post subject: Calculation of opening stock of a material Reply with quote

Use the tables MARA MARD MKPF MSEG to take the qty related fields
You can make use of the FM: MB_READ_MATERIAL_STOCKS

Code:
*----------------------------------------------------------------------*
report yw2stk message-id yw2 line-size 231 line-count 45
no standard page heading.
*----------------------------------------------------------------------*
* Type Declaration *
*----------------------------------------------------------------------*
type-pools slis.
*----------------------------------------------------------------------*
* Tables *
*----------------------------------------------------------------------*
tables: mkpf, " Material Document: Header Data
mseg, " Material Document: Item Data
mara,
mard,
s031,
ekko,
ekpo,
likp,
makt,
j_1iwrkcus,
t001w,
wb2_v_mkpf_mseg2,
mmim_rep_print,
yw2_stkmovements,
yplnt,
mardh.
*----------------------------------------------------------------------*
* Internal Tables *
*----------------------------------------------------------------------*
data: i_werks like j_1iwrkcus occurs 0 with header line.
data: begin of i_yplnt occurs 0,
pplnt like yplnt-pplnt,
wplnt like yplnt-wplnt,
end of i_yplnt.
data: begin of i_mkpf occurs 0,
mblnr like mkpf-mblnr,
mjahr like mkpf-mjahr,
budat like mkpf-budat,
vgart like mkpf-vgart,
bwart like mseg-bwart,
matnr like mseg-matnr,
werks like mseg-werks,
lgort like mseg-lgort,
menge like mseg-menge,
meins like mseg-meins,
kunnr like mseg-kunnr,
zeile like mseg-zeile,
xauto like mseg-xauto,
shkzg like mseg-shkzg,
matnr1 like mseg-matnr,
end of i_mkpf.
data: begin of i_mardh occurs 0,
werks like mardh-werks,
meins like mara-meins,
matnr like mardh-matnr,
lgort like mardh-lgort,
labst like mardh-labst,
lfgja like mardh-lfgja, "Added -MB
lfmon like mardh-lfmon, "Added -MB
perio(6),
insme like mardh-labst,
einme like mardh-labst,
speme like mardh-labst,
retme like mardh-labst,
o_stk like mardh-labst, " Opening Stock
c_stk like mardh-labst, " Closing Stock
end of i_mardh.
data: begin of i_mard occurs 0,
werks like mard-werks,
matnr like mard-matnr,
lgort like mard-lgort,
labst like mard-labst,
insme like mard-labst,
meins like mara-meins,
einme like mard-labst,
speme like mard-labst,
retme like mard-labst,
end of i_mard.
data: i_mard1 like i_mard occurs 0 with header line.
data: i_mardh1 like i_mardh occurs 0 with header line.
data: begin of i_mkpf1 occurs 0,
mblnr like mkpf-mblnr,
werks like mseg-werks,
matnr like mseg-matnr,
budat like mkpf-budat,
bwart like mseg-bwart,
mjahr like mkpf-mjahr,
vgart like mkpf-vgart,
lgort like mseg-lgort,
menge like mseg-menge,
meins like mseg-meins,
xauto like mseg-xauto,
shkzg like mseg-shkzg,
end of i_mkpf1.
data: begin of i_mkpf2 occurs 0,
werks like mseg-werks,
matnr like mseg-matnr,
budat like mkpf-budat,
bwart like mseg-bwart,
mjahr like mkpf-mjahr,
vgart like mkpf-vgart,
lgort like mseg-lgort,
menge like mseg-menge,
meins like mseg-meins,
xauto like mseg-xauto,
end of i_mkpf2.
data: begin of i_final5 occurs 0,
werks like mseg-werks, " Plant
matnr like mseg-matnr, " Material
lgort like mseg-lgort, " Storage Location
budat like mkpf-budat, " Posting Date
mtart like mara-mtart, " Material Type
spmon like s031-spmon, " Month
maktx like makt-maktx, " Description
* meins(3), " UOM
meins like mseg-meins,
o_stk like mardh-labst, " opening stock
trecep like mardh-labst, " total receipts
produ like mardh-labst, " Net Receipts - Production
recep like mardh-labst, " Net Receipts - Receipts
sal_ret like mardh-labst, " Net Receipts - Sales Return
tdisp like mardh-labst, " total dispatches
custmr like mardh-labst, " Net Dispatches - Customers
oplant like mardh-labst, " Net Dispatches - To Other Plant
tloss like mardh-labst, " Total Loss
trloss like mardh-labst, " Transit Loss
whloss like mardh-labst, " Warehouse Loss
c_stk like mardh-labst, " Closing Stock
trfstk like mardh-labst, "Transfer stock
menge like mseg-menge,
othadj like mardh-labst,
end of i_final5.
data: begin of i_final occurs 0,
werks like mseg-werks, " Plant
matnr like mseg-matnr, " Material
budat like mkpf-budat, " Posting Date
mtart like mara-mtart, " Material Type
spmon like s031-spmon, " Month
maktx like makt-maktx, " Description
* meins(3), " UOM
meins like mseg-meins,
o_stk like mardh-labst, " opening stock
trecep like mardh-labst, " total receipts
produ like mardh-labst, " Net Receipts - Production
recep like mardh-labst, " Net Receipts - Receipts
sal_ret like mardh-labst, " Net Receipts - Sales Return
tdisp like mardh-labst, " total dispatches
custmr like mardh-labst, " Net Dispatches - Customers
oplant like mardh-labst, " Net Dispatches - To Other Plant
trfstk like mardh-labst, "Material Transfer stock
trloss like mardh-labst, " Transit Loss
whloss like mardh-labst, " Warehouse Loss
tloss like mardh-labst, " Total Loss
c_stk like mardh-labst, " Closing Stock
othadj like mardh-labst,
end of i_final.
data: i_final1 like i_final occurs 0 with header line.
data: begin of i_final_temp occurs 0,
werks like mseg-werks, " Plant
matnr like mseg-matnr, " Material
mtart like mara-mtart, " Material Type
maktx like makt-maktx, " Description
meins like mseg-meins,
o_stk like mardh-labst, " opening stock
trecep like mardh-labst, " total receipts
produ like mardh-labst, " Net Receipts - Production
recep like mardh-labst, " Net Receipts - Receipts
sal_ret like mardh-labst, " Net Receipts - Sales Return
tdisp like mardh-labst, " total dispatches
custmr like mardh-labst, " Net Dispatches - Customers
oplant like mardh-labst, " Net Dispatches - To Other Plant
trfstk like mardh-labst, "Material Transfer stock
trloss like mardh-labst, " Transit Loss
whloss like mardh-labst, " Warehouse Loss
tloss like mardh-labst, " Total Loss
c_stk like mardh-labst, " Closing Stock
othadj like mardh-labst,
end of i_final_temp.
* For Materials
data: begin of i_mara occurs 0,
matnr type mara-matnr,
mtart type mara-mtart,
meins like mara-meins,
labst type mard-labst,
maktx like makt-maktx,
end of i_mara.
data: begin of i_stkmvmnts occurs 0,
bwart like mseg-bwart,
shkzg like mseg-shkzg,
vzbew like yw2_stkmovements-vzbew,
end of i_stkmvmnts.
data: begin of i_finalt occurs 0,
werks like mseg-werks, " Plant
matnr like mseg-matnr, " Material
budat like mkpf-budat, " Posting Date
mtart like mara-mtart, " Material Type
spmon like s031-spmon, " Month
maktx like makt-maktx, " Description
* meins(3), " UOM
meins like mseg-meins,
o_stk like mardh-labst, " opening stock
trecep like mardh-labst, " total receipts
produ like mardh-labst, " Net Receipts - Production
recep like mardh-labst, " Net Receipts - Receipts
sal_ret like mardh-labst, " Net Receipts - Sales Return
tdisp like mardh-labst, " total dispatches
custmr like mardh-labst, " Net Dispatches - Customers
oplant like mardh-labst, " Net Dispatches - To Other Plant
trfstk like mardh-labst, "Material Transfer stock
trloss like mardh-labst, " Transit Loss
whloss like mardh-labst, " Warehouse Loss
tloss like mardh-labst, " Total Loss
c_stk like mardh-labst, " Closing Stock
othadj like mardh-labst,
month(8) ,
end of i_finalt.
data: imkpft like i_mkpf occurs 0 with header line.
data: imkpft1 like i_mkpf1 occurs 0 with header line.
data: imardt like i_mard occurs 0 with header line.
data: imardht like i_mardh occurs 0 with header line.
data: t_final like i_mkpf occurs 0 with header line.
data: imkpft2 like i_mkpf occurs 0 with header line.
* FCAT is used for the field catalog
data: fcat type table of slis_fieldcat_alv with non-unique default key
with header line initial size 0,
* for excluding the ICONs from the application toolbar
fexc type table of slis_extab with non-unique default key
with header line initial size 0,
* FS_LAYO is used for Grid Layout
fs_layo type slis_layout_alv,
* FEVENTS to handle the events TOP OF PAGE & USER_COMMAND
fevents type table of slis_alv_event with non-unique default key
with header line initial size 0,
* FHEADER is used for List header
fheader type table of slis_listheader with non-unique default key
with header line initial size 0,
* sort is used for sorting
fsort type table of slis_sortinfo_alv with non-unique default key
with header line initial size 0,
fcat1 type table of slis_fieldcat_alv with non-unique default key
with header line initial size 0,
fs_layo1 type slis_layout_alv,
gt_list_top_of_page1 type slis_t_listheader,
fevents1 type table of slis_alv_event with non-unique default key
with header line initial size 0,
fheader1 type table of slis_listheader with non-unique default key
with header line initial size 0,
g_statu_071 type slis_formname value 'Z_PFSTATUS',
alv_variant1 like disvariant.
*----------------------------------------------------------------------*
* Variable Declaration *
*----------------------------------------------------------------------*
types: trff_type_dec_6_5(6) type p decimals 5.
data: fyear(4),
mon(2),
fyear1(4),
mon1(2),
obal like mard-labst,
cbal like mard-labst,
index type i,
count,
count1 type i,
o_stk type p decimals 3,
c_stk type p decimals 3,
v_mjahr like mkpf-mjahr,
months type trff_type_dec_6_5,
month type i.
* Global variables for handling ALV functionality
data: alv_keyinfo type slis_keyinfo_alv,
alv_variant like disvariant,
alv_layout type slis_layout_alv,
alv_repid like sy-repid,
alv_print type slis_print_alv,
alv_detail_func(30),
alv_default_variant like disvariant-variant,
alv_colourize_fields like mmim_rep_print-color.
ranges: r_budat for mkpf-budat.
*Added by Prabhu for year on 26.4.05.
data: idate like r_budat occurs 0 with header line.
*----------------------------------------------------------------------*
* Selection Screen Elements *
*----------------------------------------------------------------------*
selection-screen begin of block blk with frame title text-001.
select-options: s_werks for mard-werks obligatory
no intervals.
parameter: p_spmon like s031-spmon no-display .
select-options: s_matnr for mara-matnr obligatory,
s_lgort for mseg-lgort no-extension no intervals,
s_mblnr for mkpf-mblnr,
s_budat for mkpf-budat obligatory .
selection-screen end of block blk.
selection-screen begin of block blk3 with frame title text-004.
parameter : mtart like mara-mtart
default 'FERT' no-display.
selection-screen end of block blk3.
selection-screen begin of block blk2 with frame title text-003.
selection-screen end of block blk2.
* ADDED BY PRABHU FOR DAY-WISE REPORT.
selection-screen begin of block b3 with frame title text-007.
parameters: d1 radiobutton group p1 default 'X',
m1 radiobutton group p1,
y1 radiobutton group p1.
selection-screen end of block b3.
selection-screen begin of block b2 with frame title text-006.
parameters: alv_def like disvariant-variant.
selection-screen end of block b2.
data: s_budat1 like s_budat occurs 0 with header line."prabhu
*----------------------------------------------------------------------*
* Initialization *
*----------------------------------------------------------------------*
initialization.
perform alv_init.
at selection-screen on value-request for alv_def.
perform alv_f4.
*----------------------------------------------------------------------
*
* At Selection Screen
*
*----------------------------------------------------------------------
*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_spmon.
* PERFORM monat_f4.
*
*----------------------------------------------------------------------*
* At Selection Screen *
*----------------------------------------------------------------------*
at selection-screen.
* checking for the layout
perform alv_check.
* authorisation check for the Plant
* PERFORM auth_check.
* Validation for the Plant
perform validity_check.
if mtart ne 'FERT'.
message e041 with 'Material Type must be FERT Only...'.
endif.
if d1 = 'X'." On 26.4.05.
p_spmon+0(4) = s_budat-low+0(4).
p_spmon+4(2) = s_budat-low+4(2).
else.
p_spmon+0(4) = s_budat-low+0(4).
p_spmon+4(2) = s_budat-low+4(2).
endif.
loop at s_budat.
if s_budat-high is initial.
s_budat-high = s_budat-low.
modify s_budat.
endif.
endloop.
idate-low = s_budat-low.
idate-high = s_budat-high.
call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
exporting
i_date_from = idate-low
i_date_to = idate-high
importing
* E_DAYS =
e_months = month
* E_YEARS =
.
data: i(3) type c.
i = s_budat-low+4(2).
clear: r_budat.
refresh: r_budat.
*added by Prabhu for Only for Oneday.on 18.5.5
if month eq '0'.
month = month + 1.
endif.
*added by Prabhu for Only for Oneday.on 18.5.5
do month times.
r_budat-low = s_budat-low.
append r_budat.
enddo.
i = 0.
loop at r_budat.
r_budat-low+4(2) = s_budat-low+4(2) + i.
i = i + 1.
r_budat-low+6(2) = '01'.
modify r_budat.
endloop.
loop at r_budat.
call function 'RP_LAST_DAY_OF_MONTHS'
exporting
day_in = r_budat-low
importing
last_day_of_month = r_budat-high
* EXCEPTIONS
* DAY_IN_NO_DATE = 1
* OTHERS = 2
.
modify r_budat.
endloop.
loop at r_budat.
if r_budat-low+4(2) = s_budat-low+4(2).
r_budat-low = s_budat-low.
modify r_budat.
endif.
if r_budat-high+4(2) = s_budat-high+4(2).
r_budat-high = s_budat-high.
modify r_budat.
endif.
* For Summary on 26.4.05.
if y1 = 'X'.
clear r_budat.
refresh r_budat.
r_budat-low = s_budat-low.
r_budat-high = s_budat-high.
append r_budat.
clear r_budat.
endif.
endloop.
*----------------------------------------------------------------------*
* At Selection Screen *
*----------------------------------------------------------------------*
at selection-screen output.
*----------------------------------------------------------------------*
* Start of Selection *
*----------------------------------------------------------------------*
start-of-selection.
v_mjahr = p_spmon+0(4).
* Get plant distinction warehouse/production
perform get_plant_distinction.
* Collect the data from various tables
perform getdata_fg_stock.
* here the number of rows in the output table is found
perform output_table_check.
* here the top of the page code is written, that is to be displayed
* in the output
perform z_top_of_page.
* here ALV layout properties are set
perform z_layout_settings.
* ALV EVENTS for TOP OF PAGE and for USER COMMAND
perform z_alv_events.
* The field catalog is defined for the Primary List is defined in
* the subroutine CREATE_FIELD_CATALOG include program ZPRRDOCR_FCAT
perform z_create_field_catalog.
* This is for displaying the output
perform z_reuse_alv_grid_display.
*&---------------------------------------------------------------------*
*& Form getdata_fg_stock
*&---------------------------------------------------------------------*
* Getting data from standard tables
*----------------------------------------------------------------------*
form getdata_fg_stock.
* For getting the Start date & end date of the month
* PERFORM get_month_dates.
* Getting the Opening Stock from MARDH table
if mon eq '01'.
mon1 = mon.
fyear1 = fyear.
mon = '12'.
fyear = fyear - 1.
else.
mon1 = mon.
fyear1 = fyear.
mon = mon - 1.
fyear = fyear.
endif.
perform get_records_from_db.
*added for Month Summary on 26.4.05.
loop at r_budat.
s_budat-low = r_budat-low.
s_budat-high = r_budat-high.
*for Month
p_spmon+0(4) = s_budat-low+0(4).
p_spmon+4(2) = s_budat-low+4(2).
*for summary.
if y1 = 'X'.
loop at s_budat.
s_budat1-sign = 'I'.
s_budat1-option = 'NB'.
s_budat1-low = s_budat-low.
s_budat1-high = s_budat-high.
append s_budat1.
clear s_budat1.
endloop.
endif.
imkpft[] = i_mkpf[].
imkpft2[] = i_mkpf[].
imardt[] = i_mard[].
imardht[] = i_mardh[].
perform month_wise.
perform process_movements.
perform calculate_opening_stock.
perform update_non_transaction_itms.
perform delete_empty_records.
clear: imardht,imardt,imkpft1,imkpft,i_final,i_final5.
refresh: imardht,imardt,imkpft1,i_final,i_final5,imkpft.
endloop.
clear: r_budat.
refresh: r_budat.
*end of changes for month.
endform. " getdata_fg_stock
*---------------------------------------------------------------------*
* FORM MONAT_F4 *
*---------------------------------------------------------------------*
* F4-Hilfe fur Monat *
*---------------------------------------------------------------------*
form monat_f4.
data: begin of mf_dynpfields occurs 1.
include structure dynpread.
data: end of mf_dynpfields.
data: mf_returncode like sy-subrc,
mf_monat like isellist-month,
mf_hlp_repid like sy-repid.
field-symbols: <mf_feld>.
* Wert von Dynpro lesen
get cursor field mf_dynpfields-fieldname.
append mf_dynpfields.
mf_hlp_repid = sy-repid.
do 2 times.
call function 'DYNP_VALUES_READ'
exporting
dyname = mf_hlp_repid
dynumb = sy-dynnr
tables
dynpfields = mf_dynpfields
exceptions
invalid_abapworkarea = 01
invalid_dynprofield = 02
invalid_dynproname = 03
invalid_dynpronummer = 04
invalid_request = 05
no_fielddescription = 06
undefind_error = 07.
if sy-subrc = 3.
* Aktuelles Dynpro ist Wertemengenbild
mf_hlp_repid = 'SAPLALDB'.
else.
read table mf_dynpfields index 1.
* Unterstriche durch Blanks ersetzen
translate mf_dynpfields-fieldvalue using '_ '.
exit.
endif.
enddo.
if sy-subrc = 0.
* Konvertierung ins interne Format
call function 'CONVERSION_EXIT_PERI_INPUT'
exporting
input = mf_dynpfields-fieldvalue
importing
output = mf_monat
exceptions
error_message = 1.
if mf_monat is initial.
* Monat ist initial => Vorschlagswert aus akt. Datum ableiten
mf_monat = sy-datlo(6).
endif.
call function 'POPUP_TO_SELECT_MONTH'
exporting
actual_month = mf_monat
importing
selected_month = mf_monat
return_code = mf_returncode
exceptions
factory_calendar_not_found = 01
holiday_calendar_not_found = 02
month_not_found = 03.
if sy-subrc = 0 and mf_returncode = 0.
* ASSIGN (MF_DYNPFIELDS-FIELDNAME) TO <MF_FELD>. " ==>> note 148804
* <MF_FELD> = MF_MONAT.
call function 'CONVERSION_EXIT_PERI_OUTPUT'
exporting
input = mf_monat
importing
output = mf_dynpfields-fieldvalue.
collect mf_dynpfields.
call function 'DYNP_VALUES_UPDATE'
exporting
dyname = mf_hlp_repid
dynumb = sy-dynnr
tables
dynpfields = mf_dynpfields
exceptions
invalid_abapworkarea = 01
invalid_dynprofield = 02
invalid_dynproname = 03
invalid_dynpronummer = 04
invalid_request = 05
no_fielddescription = 06
undefind_error = 07. "<<== note 148804
endif.
endif.
endform. "MONAT_F4
*&---------------------------------------------------------------------*
*& Form get_month_dates
*&---------------------------------------------------------------------*
* Calculating the Month Start & End Date
*----------------------------------------------------------------------*
form get_month_dates.
if m1 = 'X'.
fyear = p_spmon+0(4).
mon = p_spmon+4(2).
concatenate fyear mon '01' into r_budat-low.
r_budat-sign = 'I'.
r_budat-option = 'BT'.
call function 'BKK_GET_MONTH_LASTDAY'
exporting
i_date = r_budat-low
importing
e_date = r_budat-high.
append r_budat.
clear s_budat.
refresh s_budat.
s_budat-sign = 'I'.
s_budat-option = 'BT'.
s_budat-low = r_budat-low.
s_budat-high = r_budat-high.
append s_budat.
else.
fyear = p_spmon+0(4).
mon = p_spmon+4(2).
concatenate fyear mon '01' into r_budat-low.
r_budat-sign = 'I'.
r_budat-option = 'BT'.
call function 'BKK_GET_MONTH_LASTDAY'
exporting
i_date = r_budat-low
importing
e_date = r_budat-high.
append r_budat.
endif.
endform. " get_month_dates
*&---------------------------------------------------------------------*
*& Form output_table_Check
*&---------------------------------------------------------------------*
* checking for records for output
*----------------------------------------------------------------------*
form output_table_check .
describe table i_finalt lines index.
if index eq 0.
message i041 with text-005.
leave list-processing.
endif.
endform. "OUTPUT_TABLE_CHECK
*&---------------------------------------------------------------------*
*& Form Z_TOP_OF_PAGE
*&---------------------------------------------------------------------*
* for setting the details in the top of page *
*----------------------------------------------------------------------*
* has no formal paramters *
*----------------------------------------------------------------------*
form z_top_of_page.
data: v_mon(2),
v_yr(40),
v_fin(18),
v_fin1(48),
low(10),
high(10).
v_mon = p_spmon+4(2).
v_yr = p_spmon+0(4).
fheader-typ = 'H'.
fheader-info = 'Stock Register Report (FG Stock)'.
append fheader.
clear fheader.
*if m1 = 'X'.
* CONCATENATE 'Month = ' v_mon '.' v_yr INTO v_fin.
* fheader-typ = 'H'.
* fheader-info = v_fin.
* APPEND fheader.
* CLEAR fheader.
*endif."prabhu on 18.5.5
if d1 = 'X'.
clear s_budat.
loop at s_budat.
concatenate s_budat-low+6(2) '/' s_budat-low+4(2) '/'
s_budat-low+0(4) into low.
concatenate s_budat-high+6(2) '/' s_budat-high+4(2) '/'
s_budat-high+0(4) into high.
concatenate 'Date = ' low ' - ' high into v_fin1.
fheader-typ = 'H'.
fheader-info = v_fin1.
append fheader.
clear fheader.
endloop.
endif.
endform. " Z_TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form Z_LAYOUT_SETTINGS
*&---------------------------------------------------------------------*
* this is done for setting the properties for the layout of the *
* grid *
*----------------------------------------------------------------------*
* has no formal paramters *
*----------------------------------------------------------------------*
form z_layout_settings.
fs_layo-zebra = 'X'. " Output in Zebra pattern
fs_layo-detail_popup = 'X'. " A popup window appears to give
fs_layo-detail_titlebar = text-022.
fs_layo-colwidth_optimize = 'X'.
endform. " Z_LAYOUT_SETTINGS
*&---------------------------------------------------------------------*
*& Form Z_ALV_EVENTS
*&---------------------------------------------------------------------*
* This is used for handling the events TOP OF PAGE and the USER *
* COMMAND event *
*----------------------------------------------------------------------*
* has no formal paramters *
*----------------------------------------------------------------------*
form z_alv_events.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = fevents[].
read table fevents with key name = 'TOP_OF_PAGE'.
if sy-subrc = 0.
fevents-form = 'Z_TOPOFPAGE'.
modify fevents index sy-tabix.
clear fevents.
endif.
read table fevents with key name = 'USER_COMMAND'.
if sy-subrc = 0.
fevents-form = 'Z_USER_COMMAND'.
modify fevents index sy-tabix.
clear fevents.
endif.
endform. "Z_ALV_EVENTS
*&---------------------------------------------------------------------*
*& Form Z_CREATE_FIELD_CATALOG
*&---------------------------------------------------------------------*
* here the field catalog is created for the primary list *
*----------------------------------------------------------------------*
* no formal parameters *
*----------------------------------------------------------------------*
form z_create_field_catalog.
* for the Plant
fcat-fieldname = 'WERKS'.
fcat-key = 'X'.
fcat-outputlen = '000005'.
fcat-just = 'L'.
fcat-seltext_m = 'Plant'.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'CHAR'.
append fcat.
clear fcat.
* for the Material Type
fcat-fieldname = 'MTART'.
fcat-key = 'X'.
fcat-outputlen = '000006'.
fcat-just = 'L'.
fcat-seltext_m = 'MatTyp'.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'CHAR'.
append fcat.
clear fcat.
* for the Material No.
fcat-fieldname = 'MATNR'.
fcat-key = 'X'.
* fcat-hotspot = 'X'.
fcat-outputlen = '000018'.
fcat-just = 'L'.
fcat-seltext_m = 'Material'.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'CHAR'.
append fcat.
clear fcat.
* for the Material Description
fcat-fieldname = 'MAKTX'.
fcat-key = ''.
fcat-outputlen = '000040'.
fcat-just = 'L'.
fcat-seltext_m = 'Description'.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'CHAR'.
append fcat.
clear fcat.
* for the Unit of Measure
fcat-fieldname = 'MEINS'.
fcat-key = ''.
fcat-outputlen = '03'.
fcat-just = 'C'.
fcat-seltext_m = 'UOM'.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'UNIT'.
append fcat.
clear fcat.
* for the Plant
fcat-fieldname = 'MONTH'.
fcat-key = 'X'.
fcat-outputlen = '08'.
fcat-just = 'L'.
fcat-seltext_m = 'MONTH'.
fcat-ddictxt = 'M'.
fcat-inttype = 'C'.
fcat-datatype = 'CHAR'.
append fcat.
clear fcat.
* for the Opening Stock
fcat-fieldname = 'C_STK'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Opening Stock'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
* fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* for the Total Receipts
fcat-fieldname = 'TRECEP'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Total Receipts'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* for the Production
fcat-fieldname = 'PRODU'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Production'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* for the Other Plant Receipts
fcat-fieldname = 'RECEP'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Othr Plnt Recpts'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* Sales Return
fcat-fieldname = 'SAL_RET'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Sales Return'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* Total Dispatches
fcat-fieldname = 'TDISP'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Total Dispatches'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* Distributor Dispatches
fcat-fieldname = 'CUSTMR'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Distr Dispatches/HLL'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* Other Plants Dispatches
fcat-fieldname = 'OPLANT'.
fcat-hotspot = ' '.
fcat-outputlen = '000020'.
fcat-just = 'L'.
fcat-seltext_m = 'Othr Plnt Dispatches'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* Material Transfer
fcat-fieldname = 'TRFSTK'.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'M.Transfer'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* Transit Loss
fcat-fieldname = 'TRLOSS'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Transit Loss'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* Warehouse Loss
fcat-fieldname = 'WHLOSS'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Warehouse Loss'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* Total Loss
fcat-fieldname = 'TLOSS'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Total Loss'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* Closing Stock
fcat-fieldname = 'O_STK'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Closing Stock'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
* fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
* for the Other Plant Receipts
fcat-fieldname = 'OTHADJ'.
fcat-hotspot = ' '.
fcat-outputlen = '000016'.
fcat-just = 'L'.
fcat-seltext_m = 'Othr Adjst'.
fcat-ddictxt = 'M'.
fcat-inttype = 'Q'.
fcat-datatype = 'QUAN'.
fcat-do_sum = 'X'.
fcat-just = 'R'.
fcat-no_zero = 'X'.
append fcat.
clear fcat.
endform. " Z_CREATE_FIELD_CATALOG
*&---------------------------------------------------------------------*
*& Form Z_REUSE_ALV_GRID_DISPLAY
*&---------------------------------------------------------------------*
* here the function module REUSE_ALV_GRID_DISPLAY function module *
* is called. The inputs given to it are as follows: *
* W_REPID : contains the Report Name *
* USER_COMMAND : is set as default *
* FS_LAYO : Here the layout related properties are set *
* FCAT : here the field catalog is create for the output *
* fields *
* FEXCLUDE : Some Application toolbar links are deactivated *
* here *
* FEVENTS : Here top of Page & User command events are defined*
* IT_AFPO : It is the table which contains the data to be *
* displayed in the output *
*----------------------------------------------------------------------*
* has no formal paramters *
*----------------------------------------------------------------------*
form z_reuse_alv_grid_display.
data: begin of i_maktx occurs 0,
matnr like makt-matnr,
maktx like makt-maktx,
end of i_maktx,
v_temp(18).
if not i_finalt[] is initial.
select matnr
maktx
into table i_maktx
from makt
for all entries in i_finalt
where makt~matnr = i_finalt-matnr.
endif.
sort i_maktx by matnr.
loop at i_finalt.
read table i_maktx with key matnr = i_finalt-matnr
binary search.
if sy-subrc = 0.
i_finalt-maktx = i_maktx-maktx.
modify i_finalt.
endif.
endloop.
sort i_finalt by matnr.
delete i_finalt where matnr eq ''.
data: lv_repid like sy-repid.
lv_repid = sy-repid.
data: v_matnr(18).
loop at i_finalt.
call function 'CONVERSION_EXIT_MATN1_OUTPUT'
exporting
input = i_finalt-matnr
importing
output = v_matnr.
i_finalt-matnr = v_matnr.
modify i_finalt.
endloop.
sort i_finalt by matnr month.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = lv_repid
i_callback_user_command = 'Z_USER_COMMAND'
is_layout = fs_layo
it_fieldcat = fcat[]
it_excluding = fexc[]
it_sort = fsort[]
i_default = 'X'
i_save = 'U'
is_variant = alv_variant
it_events = fevents[]
tables
t_outtab = i_finalt[].
endform. " Z_REUSE_ALV_GRID_DISPLAY
*&---------------------------------------------------------------------*
*& Form Z_TOPOFPAGE
*&---------------------------------------------------------------------*
* This Subroutine is called Dynamically *
* This is for creating the headings of the output fields *
*----------------------------------------------------------------------*
* has no formal paramters *
*----------------------------------------------------------------------*
form z_topofpage. "#EC NEEDED
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = fheader[].
endform. " FORM Z_TOPOFPAGE
*&---------------------------------------------------------------------*
*& Form Z_USER_COMMAND
*&---------------------------------------------------------------------*
* This Subroutine is called Dynamically *
* if the user double clicks the Production Order Number or the *
* Material Number, the Complete transaction details will be *
* displayed *
*----------------------------------------------------------------------*
* R_UCOMM *
* RS_SELFIELD *
*----------------------------------------------------------------------*
form z_user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield. "#EC NEEDED
check r_ucomm = '&IC1'. "User Double Clicked on Some field
check not rs_selfield-value is initial.
loop at imkpft2.
perform remove_zeros using imkpft2-matnr
changing imkpft2-matnr1.
modify imkpft2.
endloop.
sort imkpft2 by budat matnr werks.
case rs_selfield-fieldname.
when 'MATNR'.
read table i_finalt index rs_selfield-tabindex.
if d1 = 'X' or m1 ='X'.
loop at imkpft2 where matnr1 = i_finalt-matnr and
werks = i_finalt-werks and
( budat+0(4) eq i_finalt-month+0(4) and
budat+4(2) eq i_finalt-month+5(2) ) .
move imkpft2 to t_final.
append t_final.
clear t_final.
endloop.
elseif y1 = 'X'.
loop at imkpft2 where matnr1 = i_finalt-matnr and
werks = i_finalt-werks and
budat in s_budat.
move imkpft2 to t_final.
append t_final.
clear t_final.
endloop.
endif.
sort t_final by budat matnr werks.
perform display_alv1 using t_final.
endcase.
endform. " FORM Z_USER_COMMAND
*&---------------------------------------------------------------------*
*& Form ALV_F4
*&---------------------------------------------------------------------*
form alv_f4.
alv_variant-report = alv_repid.
call function 'REUSE_ALV_VARIANT_F4'
exporting
is_variant = alv_variant
i_save = 'A'
importing
es_variant = alv_variant
exceptions
not_found = 2.
if sy-subrc = 2.
message id sy-msgid type 'S' number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
alv_def = alv_variant-variant.
endif.
endform. "alv_f4
*&---------------------------------------------------------------------*
*& Form ALV_INIT
*&---------------------------------------------------------------------*
form alv_init.
clear: alv_keyinfo, alv_variant, alv_layout, alv_print.
clear alv_def.
alv_repid = sy-repid.
clear alv_variant.
alv_variant-report = alv_repid.
call function 'REUSE_ALV_VARIANT_DEFAULT_GET'
exporting
i_save = 'A'
changing
cs_variant = alv_variant
exceptions
not_found = 2.
if sy-subrc = 0.
alv_def = alv_variant-variant.
move alv_variant-variant to alv_default_variant.
endif.
* Printing settings
alv_layout-get_selinfos = 'X'.
alv_layout-group_change_edit = 'X'.
select single * from mmim_rep_print where report = sy-repid.
if sy-subrc = 0.
if mmim_rep_print-selinfo = 'X'.
alv_print-no_print_selinfos = ' '.
else.
alv_print-no_print_selinfos = 'X'.
endif.
if mmim_rep_print-coverpage = 'X'.
alv_print-no_coverpage = ' '.
else.
alv_print-no_coverpage = 'X'.
endif.
if mmim_rep_print-listinfo = 'X'.
alv_print-no_print_listinfos = ' '.
else.
alv_print-no_print_listinfos = 'X'.
endif.
if mmim_rep_print-gridcontrol = 'X'.
alv_detail_func = 'REUSE_ALV_GRID_DISPLAY'.
else.
alv_detail_func = 'REUSE_ALV_LIST_DISPLAY'.
endif.
if mmim_rep_print-color = 'X'.
clear alv_colourize_fields.
else.
move 'X' to alv_colourize_fields.
endif.
else.
move 'X' to alv_colourize_fields.
alv_print-no_print_selinfos = 'X'.
alv_print-no_coverpage = ' '.
alv_print-no_print_listinfos = 'X'.
alv_detail_func = 'REUSE_ALV_LIST_DISPLAY'.
endif.
endform. "ALV_INIT
*--------------------------------------------------------------------*
*& Form AUTH_CHECK
*&---------------------------------------------------------------------*
* for checking authorisations
*----------------------------------------------------------------------*
form auth_check.
data: begin of i_auth occurs 0,
werks like t001w-werks,
end of i_auth.
select werks
into table i_auth
from t001w
where werks in s_werks.
loop at i_auth.
authority-check object 'Z_PLNT_AUT'
id 'ACTVT' field '03'
id 'WERKS' field i_auth-werks.
if sy-subrc ne 0 .
message e398(00) with
'User' sy-uname 'not authorised for Plant' i_auth-werks.
endif.
endloop.
endform. " AUTH_CHECK
*&---------------------------------------------------------------------*
*& Form VALIDITY_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form validity_check.
loop at s_werks.
select single * from t001w
where werks = s_werks-low.
if sy-subrc eq 4 .
message e398(00) with
'Plant' s_werks-low 'Does not Exist' .
endif.
endloop .
endform. " VALIDITY_CHECK
*&---------------------------------------------------------------------*
*& Form alv_check
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form alv_check.
alv_variant-report = alv_repid.
alv_variant-variant = alv_def.
if not alv_def is initial.
call function 'REUSE_ALV_VARIANT_EXISTENCE'
exporting
i_save = 'A'
changing
cs_variant = alv_variant
exceptions
others = 1.
if sy-subrc <> 0.
message e321(m7) with alv_def alv_repid.
endif. " IF sy-subrc <> 0.
else.
* the user wants no initial display variant
if not alv_default_variant is initial.
* but the SAP-LIST-VIEWER will apply the existing
* initial display variant / emerge warning 393 ?
call function 'ME_CHECK_T160M'
exporting
i_arbgb = 'M7'
i_msgnr = '393'
exceptions
nothing = 0
others = 1.
if sy-subrc <> 0.
message w393(m7) with alv_default_variant.
endif.
endif.
endif.
endform. "alv_check
*&---------------------------------------------------------------------*
*& Form delete_empty_records
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form delete_empty_records .
* deleting the records with empty quantities
loop at i_final.
if i_final-o_stk eq 0 and
i_final-trecep eq 0 and
i_final-produ eq 0 and
i_final-recep eq 0 and
i_final-sal_ret eq 0 and
i_final-tdisp eq 0 and
i_final-custmr eq 0 and
i_final-oplant eq 0 and
i_final-tloss eq 0 and
i_final-trloss eq 0 and
i_final-whloss eq 0 and
i_final-othadj eq 0 and
i_final-c_stk eq 0.
delete i_final.
clear i_final.
endif.
move-corresponding i_final to i_finalt.
*For Month
if y1 ne 'X'.
concatenate p_spmon+0(4) '.' p_spmon+4(2)
into i_finalt-month.
else.
concatenate p_spmon+0(4) '.' '00'
into i_finalt-month.
endif.
append i_finalt.
clear i_finalt.
endloop.
endform. " delete_empty_records
*&---------------------------------------------------------------------*
*& Form calculate_opening_stock
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form calculate_opening_stock .
loop at imardht.
at new matnr.
i_final-matnr = imardht-matnr.
i_final-werks = imardht-werks.
i_final-meins = imardht-meins.
i_final-mtart = mtart.
append i_final.
endat.
endloop.
sort i_final by werks matnr.
loop at i_final.
read table imardht with key matnr = i_final-matnr
werks = i_final-werks.
if sy-subrc eq 0.
if d1 = 'X'.
obal = imardht-labst + imardht-o_stk + imardht-c_stk.
cbal = imardht-labst + imardht-c_stk .
else.
obal = imardht-labst .
cbal = imardht-labst + imardht-c_stk .
endif.
i_final-c_stk = cbal.
i_final-o_stk = obal.
modify i_final.
endif.
endloop.
loop at i_final.
loop at i_final5 where matnr = i_final-matnr and
werks = i_final-werks.
i_final-produ = i_final-produ + i_final5-produ.
i_final-recep = i_final-recep + i_final5-recep.
i_final-sal_ret = i_final-sal_ret + i_final5-sal_ret.
i_final-custmr = i_final-custmr + i_final5-custmr.
i_final-oplant = i_final-oplant + i_final5-oplant.
i_final-whloss = i_final-whloss + i_final5-whloss.
i_final-trloss = i_final-trloss + i_final5-trloss.
i_final-trfstk = i_final-trfstk + i_final5-trfstk.
i_final-othadj = i_final-othadj + i_final5-othadj.
modify i_final.
endloop.
*-------------------Total Receipts------------*
i_final-trecep = i_final-produ
+ i_final-recep
+ i_final-sal_ret.
*-------------------Total Dispatches-----------*
i_final-tdisp = i_final-custmr
+ i_final-oplant.
*---------------------Total Loss----------------*
i_final-tloss = i_final-trloss
+ i_final-whloss.
modify i_final.
endloop.
endform. " calculate_opening_stock
*&---------------------------------------------------------------------*
*& Form update_non_transaction_itms
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form update_non_transaction_itms .
* Pushing NON TRANSACTION ITEMS TO i_final table
loop at imardht.
read table i_final with key matnr = imardht-matnr
werks = imardht-werks .
if sy-subrc ne 0.
clear i_final. "Added by manisha for correction
i_final-matnr = imardht-matnr.
i_final-werks = imardht-werks.
i_final-spmon = p_spmon.
i_final-mtart = mtart.
i_final-c_stk = imardht-labst + imardht-c_stk.
i_final-o_stk = i_final-c_stk.
i_final-meins = imardht-meins.
append i_final.
clear i_final.
endif.
endloop.
endform. " update_non_transaction_itms
*&---------------------------------------------------------------------*
*& Form get_records_from_DB
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_records_from_db .
data: wa_mtart like mara-mtart .
data: i_mard1 like i_mard occurs 0 with header line.
data: i_mardh2 like i_mardh1 occurs 0 with header line.
* added by prabhu .
select matnr mtart meins from mara
into corresponding fields of table i_mara
where matnr in s_matnr and
mtart = 'FERT'.
*added by prabu for performance.
sort i_mara by matnr.
delete adjacent duplicates from i_mara comparing matnr.
sort i_mara by matnr.
* end of changes by prabhu for CPO.
select bwart shkzg vzbew
from yw2_stkmovements
into table i_stkmvmnts.
* Getting the Stocks from the MARD table for the Previous Months
* for Slow Moving Materials
select mard~matnr
mard~werks
mard~lgort
mard~labst
mard~insme
mard~einme "+
mard~speme "+
mard~retme "-
from mard
into corresponding fields of table i_mard
for all entries in i_mara
where mard~matnr eq i_mara-matnr
and mard~werks in s_werks
and mard~lgort in s_lgort.
* added by prabhu for CPO.
sort i_mard by matnr.
loop at i_mard.
read table i_mara with key matnr = i_mard-matnr.
if sy-subrc ne 0.
delete i_mard.
else.
i_mard-meins = i_mara-meins.
modify i_mard.
endif.
endloop.
* getting the details from the MKPF & MSEG table
if not i_mard[] is initial.
select mkpf~mblnr
mkpf~mjahr
mkpf~vgart
mkpf~budat
mseg~zeile
mseg~bwart
mseg~xauto
mseg~matnr
mseg~werks
mseg~lgort
mseg~shkzg
mseg~menge
mseg~meins
from mkpf as mkpf inner join
mseg as mseg
on mkpf~mblnr = mseg~mblnr
and mkpf~mjahr = mseg~mjahr
into corresponding fields of table i_mkpf
for all entries in i_mard
where
mkpf~budat ge s_budat-low
and mseg~matnr eq i_mard-matnr
and mseg~werks eq i_mard-werks
and mseg~lgort ne ''.
endif.
endform. " get_records_from_DB
*&---------------------------------------------------------------------*
*& Form process_movements
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form process_movements .
data: wa_maktx like makt-maktx.
loop at imkpft where budat in s_budat.
if imkpft-shkzg = 'S'.
imkpft-menge = imkpft-menge * ( -1 ).
modify imkpft.
else.
endif.
endloop.
loop at imkpft where budat in s_budat.
i_final5-werks = imkpft-werks.
i_final5-lgort = imkpft-lgort.
i_final5-matnr = imkpft-matnr.
* GET SIGN.
read table i_stkmvmnts with key bwart = imkpft-bwart
shkzg = imkpft-shkzg.
if sy-subrc = 0.
if i_stkmvmnts-vzbew = '+'.
i_final5-menge = imkpft-menge .
else.
i_final5-menge = imkpft-menge * ( -1 ).
endif.
* not to consider movements not found in y table
else.
* i_final5-menge = imkpft-menge.
clear i_final5-menge.
endif."prabhu.
case imkpft-bwart.
* PRODUCTION - 1
when '101' or '102' .
i_final5-produ = i_final5-produ + i_final5-menge.
* SALES RETURNS - 3
when '653' or '654'.
i_final5-sal_ret = i_final5-sal_ret + i_final5-menge.
* CUSTOMER DISPATCHES - 5
when '624' or '625' or '601' or '602' or '951' or '952'
or '645' or '646' .
i_final5-custmr = i_final5-custmr + i_final5-menge.
* OTHER PLANT DISPATCHES - 6 / RECEIPTS - 2
when '641' or '941' or '643'.
if imkpft-shkzg = 'H'.
i_final5-oplant = i_final5-oplant + i_final5-menge.
else.
i_final5-recep = i_final5-recep + i_final5-menge.
endif.
when '642' or '942' or '644'.
if imkpft-shkzg = 'S'.
i_final5-oplant = i_final5-oplant + i_final5-menge.
else.
i_final5-recep = i_final5-recep + i_final5-menge.
endif.
* TRANSIT LOSS
when '251' or '252' or 'Z51' or 'Z52'.
i_final5-trloss = i_final5-trloss + i_final5-menge.
* WAREHOUSE LOSS
when '551' or '552' or 'Y51' or 'Y52' or '555' or '556'.
i_final5-whloss = i_final5-whloss + i_final5-menge.
* TRANSFER STOCK
when '309' or '310'.
i_final5-trfstk = i_final5-trfstk + i_final5-menge.
* OTHER ADJUSTMENTS
when others.
i_final5-othadj = i_final5-othadj + i_final5-menge.
endcase.
* Added by prabhu on 12.3.05 CPO.
*read table i_final5 with key matnr = imkpft-matnr.
*if sy-subrc ne 0.
i_final5-meins = imkpft-meins.
i_final5-budat = imkpft-budat.
append i_final5.
clear i_final5.
*endif.
endloop.
sort i_final5 by werks matnr budat ascending.
endform. " process_movements
*----------------------------------------------------------------------*
*----------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Form get_plant_distinction
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_plant_distinction .
select pplnt wplnt from yplnt
into corresponding fields of table i_yplnt where
pplnt in s_werks.
select pplnt wplnt from yplnt
appending corresponding fields of table i_yplnt where
wplnt in s_werks.
endform. " get_plant_distinction
*
*----------------------------------------------------------------------*
*----------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Form month_wise
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form month_wise .
if y1 = ''.
loop at imkpft where (
( budat+4(2) gt p_spmon+4(2) and
mjahr eq p_spmon+0(4) ) or
( budat+4(2) le p_spmon+4(2) and
mjahr ne p_spmon+0(4) ) or
( budat+4(2) ge p_spmon+4(2) and
mjahr ne p_spmon+0(4) ) ).
imkpft1-mjahr = imkpft-mjahr.
imkpft1-mblnr = imkpft-mblnr.
imkpft1-budat = imkpft-budat.
imkpft1-vgart = imkpft-vgart.
imkpft1-bwart = imkpft-bwart.
imkpft1-matnr = imkpft-matnr.
imkpft1-werks = imkpft-werks.
imkpft1-lgort = imkpft-lgort.
imkpft1-menge = imkpft-menge.
imkpft1-meins = imkpft-meins.
imkpft1-xauto = imkpft-xauto.
imkpft1-shkzg = imkpft-shkzg.
append imkpft1.
clear imkpft1.
endloop.
else.
loop at imkpft where budat in s_budat1.
imkpft1-mjahr = imkpft-mjahr.
imkpft1-mblnr = imkpft-mblnr.
imkpft1-budat = imkpft-budat.
imkpft1-vgart = imkpft-vgart.
imkpft1-bwart = imkpft-bwart.
imkpft1-matnr = imkpft-matnr.
imkpft1-werks = imkpft-werks.
imkpft1-lgort = imkpft-lgort.
imkpft1-menge = imkpft-menge.
imkpft1-meins = imkpft-meins.
imkpft1-xauto = imkpft-xauto.
imkpft1-shkzg = imkpft-shkzg.
append imkpft1.
clear imkpft1.
endloop.
endif.
sort imkpft1 by werks matnr budat bwart ascending.
loop at imardt.
at new matnr .
imardht-matnr = imardt-matnr.
imardht-werks = imardt-werks.
append imardht.
clear imardht.
endat.
endloop.
loop at imardht.
loop at imardt where matnr = imardht-matnr and
werks = imardht-werks.
imardht-matnr = imardt-matnr.
imardht-werks = imardt-werks.
imardht-lgort = imardt-lgort.
imardht-labst = imardt-labst + imardt-einme +
imardt-speme + imardt-retme + imardht-labst +
imardt-insme.
imardht-meins = imardt-meins.
modify imardht.
endloop.
endloop.
* sorting the data by matnr werks lgort.
sort imardht by werks lgort matnr.
* to get closing stock.
sort imkpft1 by matnr.
data: begin of data occurs 0,
lgort like mard-lgort,
matnr like mard-matnr,
labst like mard-labst,
werks like mard-werks,
end of data.
loop at imardt.
at new matnr.
data-lgort = imardt-lgort.
data-matnr = imardt-matnr.
data-werks = imardt-werks.
append data.
clear data.
endat.
endloop.
sort imkpft1 by matnr shkzg.
loop at imkpft1.
if imkpft1-shkzg = 'S'.
imkpft1-menge = imkpft1-menge * ( -1 ).
modify imkpft1.
else.
endif.
endloop.
sort imkpft1 by matnr budat.
loop at imardht.
loop at imkpft1 where matnr = imardht-matnr and
werks = imardht-werks .
imardht-labst = imardht-labst + imkpft1-menge.
modify imardht.
endloop.
modify imardht.
endloop.
sort imkpft by matnr budat.
if y1 =''.
delete imkpft where
( budat+4(2) ne p_spmon+4(2) or
( budat+4(2) eq p_spmon+4(2) and
mjahr ne p_spmon+0(4) ) ) or
( budat+4(2) gt p_spmon and
mjahr ne p_spmon+0(4) ) .
else.
delete imkpft where budat in s_budat1.
endif.
*for Closing stock.
loop at imkpft.
if imkpft-shkzg = 'S'.
imkpft-menge = imkpft-menge * ( -1 ).
modify imkpft.
endif.
endloop.
if d1 = 'X'.
loop at imardht.
loop at imkpft where matnr = imardht-matnr and
werks = imardht-werks.
imardht-c_stk = imardht-c_stk + imkpft-menge.
modify imardht.
endloop.
endloop.
*for day cal only on 19.4.5
loop at imardht.
loop at imkpft where matnr = imardht-matnr and
budat in s_budat and
werks = imardht-werks .
imardht-o_stk = imardht-o_stk - imkpft-menge.
modify imardht.
endloop.
endloop.
else.
loop at imardht.
loop at imkpft where matnr = imardht-matnr and
werks = imardht-werks.
imardht-c_stk = imardht-c_stk + imkpft-menge.
modify imardht.
endloop.
endloop.
endif.
endform. " month_wise
form z_alv_events1.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = fevents1[].
read table fevents with key name = 'TOP_OF_PAGE'.
if sy-subrc = 0.
fevents-form = 'Z_TOPOFPAGE'.
* fevents-form = 'Z_LIST'.
modify fevents index sy-tabix.
clear fevents.
endif. " IF SY-SUBRC = 0.
* Drill down
read table fevents with key name = 'USER_COMMAND'.
if sy-subrc = 0.
fevents-form = 'Z_USER_COMMAND1'.
modify fevents index sy-tabix.
clear fevents1.
endif.
endform. "Z_ALV_EVENTS
* Drill Down In Alv
form z_user_command1 using r_ucomm like sy-ucomm
rs_selfield type slis_selfield. "#EC NEEDED
*sel_tab_field type slis_sel_tab_field
check r_ucomm = '&IC1'. "User Double Clicked on Some field
check not rs_selfield-value is initial.
case rs_selfield-fieldname.
endcase.
endform. "Z_USER_COMMAND
*&---------------------------------------------------------------------*
*& Form display_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_alv1 using p_t_final.
data:
lv_repid like sy-repid.
clear: fcat1.
perform create_fieldcat1.
perform z_alv_events1.
lv_repid = sy-repid.
sort t_final by matnr budat werks .
data: w_matnr(18).
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = lv_repid
i_callback_user_command = 'Z_USER_COMMAND'
is_layout = fs_layo1
it_fieldcat = fcat1[]
i_default = 'X'
i_save = 'U'
it_events = fevents1[]
tables
t_outtab = t_final[].
clear: fcat1,t_final.
refresh: fcat1,t_final.
endform. " display_alv
*&---------------------------------------------------------------------*
*& Form create_fieldcat
*&---------------------------------------------------------------------*
* Create a field catalogue for Alv Report
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form create_fieldcat1 .
* for the Material No.
fcat1-fieldname = 'MATNR'.
fcat1-key = 'X'.
* fcat-hotspot = 'X'.
fcat1-outputlen = '00006'.
fcat1-just = 'L'.
fcat1-seltext_m = 'Material'.
fcat1-ddictxt = 'M'.
fcat1-inttype = 'C'.
fcat1-datatype = 'CHAR'.
append fcat1.
clear fcat1.
* for the Plant
fcat1-fieldname = 'WERKS'.
fcat1-key = 'X'.
fcat1-outputlen = '000005'.
fcat1-just = 'L'.
fcat1-seltext_m = 'Plant'.
fcat1-ddictxt = 'M'.
fcat1-inttype = 'C'.
fcat1-datatype = 'CHAR'.
append fcat1.
clear fcat1.
* for the MatDoc
fcat1-fieldname = 'MBLNR'.
fcat1-outputlen = '000010'.
fcat1-just = 'L'.
fcat1-seltext_m = 'Mat.Doc'.
fcat1-ddictxt = 'M'.
fcat1-inttype = 'C'.
fcat1-datatype = 'CHAR'.
append fcat1.
clear fcat1.
* for the Date
fcat1-fieldname = 'BUDAT'.
fcat1-outputlen = '000010'.
fcat1-just = 'L'.
fcat1-seltext_m = 'Mat.Date'.
fcat1-ddictxt = 'M'.
fcat1-inttype = 'D'.
fcat1-datatype = 'DATS'.
append fcat1.
clear fcat1.
* for the MOVETYPE
fcat1-fieldname = 'BWART'.
fcat1-outputlen = '000003'.
fcat1-just = 'L'.
fcat1-seltext_m = 'Move.TyPE'.
fcat1-ddictxt = 'M'.
fcat1-inttype = 'C'.
fcat1-datatype = 'CHAR'.
append fcat1.
clear fcat1.
* for the MOVETYPE
fcat1-fieldname = 'MENGE'.
fcat1-outputlen = '000013'.
fcat1-just = 'R'.
fcat1-seltext_m = 'Move.TyPE'.
fcat1-ddictxt = 'M'.
fcat1-inttype = 'Q'.
fcat1-datatype = 'QUAN'.
append fcat1.
clear fcat1.
endform. " create_fieldcat
**&---------------------------------------------------------------------
**
**& Form remove_zeros
**&---------------------------------------------------------------------
**
** text
**----------------------------------------------------------------------
**
** -->P_I_VBAK_DETAIL_MATNR text
** <--P_I_VBAK_DETAIL_MATNR text
**----------------------------------------------------------------------
*
form remove_zeros using p_imkpft2-matnr
changing p_imkpft2-matnr1.
call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = imkpft2-matnr
importing
output = imkpft2-matnr1.
endform. " remove_zeros
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.