*Purpose: Created Customized Report with Reference to MB5B T-code with Material Type and days as a Selection Criteria- for Displaying Slow Moving and NoN Moving Stock in ALV GRID .
*Logic: Keeping Opening and Closing Stock not Equal to Zero, issue and Receipts Equal To Zero.
REPORT z_inventory_Details NOSTANDARDPAGE HEADING.
TABLES: mara,
mbew,
mard,
mkpf,
makt,
bapifvdexp_vzzbepp.
TYPE-POOLS:slis.
TYPES: BEGINOF ty_mara,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
ersda TYPE mara-ersda,
lbkum TYPE mbew-lbkum,
salk3 TYPE mbew-salk3,
ENDOF ty_mara.
TYPES: BEGINOF ty_mbew,
matnr TYPE mbew-matnr,
bwkey TYPE mbew-bwkey,
lvorm TYPE mbew-lvorm,
lbkum TYPE mbew-lbkum,
salk3 TYPE mbew-salk3,
ENDOF ty_mbew.
TYPES: BEGINOF ty_bsim,
matnr TYPE bsim-matnr,
bwkey TYPE bsim-bwkey,
dmbtr TYPE bsim-dmbtr,
menge TYPE bsim-menge,
meins TYPE bsim-meins,
blart TYPE bsim-blart,
belnr TYPE bsim-belnr,
gjahr TYPE bsim-gjahr,
shkzg TYPE bsim-shkzg,
ENDOF ty_bsim.
TYPES: BEGINOF ty_mseg,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
mblnr TYPE mseg-mblnr,
mjahr TYPE mseg-mjahr,
bwart TYPE mseg-bwart,
werks TYPE mseg-werks,
lgort TYPE mseg-lgort,
dmbtr TYPE mseg-dmbtr,
menge TYPE mseg-menge,
meins TYPE mseg-meins,
budat TYPE mkpf-budat,
ebeln TYPE mseg-ebeln,
aufnr TYPE mseg-aufnr,
ENDOF ty_mseg.
TYPES: BEGINOF ty_bkpf,
bukrs TYPE bkpf-bukrs,
belnr TYPE bkpf-belnr,
gjahr TYPE bkpf-gjahr,
blart TYPE bkpf-blart,
bldat TYPE bkpf-bldat,
awkey TYPE bkpf-awkey,
ENDOF ty_bkpf.
TYPES: BEGINOF ty_temp,
matnr TYPE bsim-matnr,
bwkey TYPE bsim-bwkey,
budat TYPE bsim-budat,
ENDOF ty_temp.
TYPES: BEGINOF ty_tab,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
ersda TYPE mara-ersda,
mblnr TYPE mseg-mblnr,
mjahr TYPE mseg-mjahr,
bwart TYPE mseg-bwart,
werks TYPE mseg-werks,
lgort TYPE mseg-lgort,
dmbtr TYPE mseg-dmbtr,
menge TYPE mseg-menge,
meins TYPE mseg-meins,
budat TYPE mkpf-budat,
lbkum TYPE mbew-lbkum,
salk3 TYPE mbew-salk3,
ebeln TYPE mseg-ebeln,
aufnr TYPE mseg-aufnr,
maktx TYPE makt-maktx,
lv_date TYPE d,
ENDOF ty_tab.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
wa_fcat TYPE slis_fieldcat_alv,
it_layout TYPE slis_layout_alv.
DATA: variant TYPE disvariant,
lv_lines TYPEi,
lv_per TYPE f,
lv_remaining TYPEi,
p VALUE'1',
lv_date TYPE dats,
lv_text TYPEc LENGTH 80.
DATA: it_mseg TYPETABLEOF ty_mseg,
wa_mseg TYPE ty_mseg,
it_bsim TYPETABLEOF ty_bsim,
wa_bsim TYPE ty_bsim,
it_mbew TYPETABLEOF ty_mbew,
wa_mbew TYPE ty_mbew,
it_bkpf TYPETABLEOF ty_bkpf,
wa_bkpf TYPE ty_bkpf,
it_mara TYPESTANDARDTABLEOF ty_mara,
wa_mara TYPE ty_mara,
it_temp TYPETABLEOF ty_temp,
wa_temp TYPE ty_temp,
it_tab TYPETABLEOF ty_tab,
wa_tab TYPE ty_tab.
SELECTION-SCREENBEGINOF TABBED BLOCK tabb1 FOR5LINES.
SELECTION-SCREEN TAB (20) t1 USER-COMMAND ucomm1
DEFAULTSCREEN101.
SELECTION-SCREEN TAB (20) t2 USER-COMMAND ucomm2
DEFAULTSCREEN102.
SELECTION-SCREENENDOFBLOCK tabb1.
SELECTION-SCREENBEGINOFSCREEN101AS SUBSCREEN.
SELECT-OPTIONS: s_matnr FOR mara-matnr,
s_mtart FOR mara-mtart,
s_days FOR bapifvdexp_vzzbepp-num4 NO-EXTENSION NO INTERVALS
DEFAULT180.
SELECTION-SCREENENDOFSCREEN101.
SELECTION-SCREENBEGINOFSCREEN102AS SUBSCREEN.
SELECT-OPTIONS:
s_date FOR mkpf-budat.
SELECTION-SCREENENDOFSCREEN102.
INITIALIZATION.
t1 = 'Selection-Screen'.
t2 = 'Sub-Screen'.
START-OF-SELECTION.
PERFORMclear.
PERFORMdata-fetch.
PERFORM fcat.
PERFORM layout.
PERFORM display.
*&---------------------------------------------------------------------*
*& Form clear
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORMclear.
CLEAR: it_mara, it_bsim, it_mseg, lv_date.
REFRESH: it_mara, it_bsim, it_mseg.
IF s_days IS NOT INITIAL AND s_date IS INITIAL.
lv_date = sy-datum - s_days-low.
MOVE lv_date TO s_date-low.
ENDIF.
IF s_date ISNOTINITIAL.
CLEAR: s_days,lv_date.
ENDIF.
ENDFORM. "clear
*&---------------------------------------------------------------------*
*& Form DATA-FETCH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORMdata-fetch.
SELECT mara~matnr
mara~mtart
mara~ersda
mbew~lbkum
mbew~salk3
INTOTABLE it_mara
FROM mara AS mara
JOIN mbew AS mbew
ON mara~matnr = mbew~matnr
WHERE mara~matnr IN s_matnr
AND mara~mtart IN s_mtart
AND mbew~bwkey = 'PALM'.
SORT it_mara BY lbkum ASCENDING.
DELETE it_mara WHERE lbkum = ' '.
SORT it_mara BY matnr mtart ASCENDING.
DELETEADJACENTDUPLICATESFROM it_mara COMPARINGALLFIELDS.
DESCRIBETABLE it_mara LINES lv_lines.
IF lv_lines < p.
MESSAGE'No data Found'TYPE'I'.
LEAVE LIST-PROCESSING.
EXIT.
ENDIF.
LOOPAT it_mara INTO wa_mara.
lv_per = sy-tabix / lv_lines * 100.
lv_remaining = lv_lines - sy-tabix.
WRITE lv_remaining TO lv_text LEFT-JUSTIFIED.
CONCATENATE'Processing remaining'(005) lv_text 'items'(007)
INTO lv_text SEPARATEDBY space.
CALLFUNCTION'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = lv_per
text = lv_text.
wa_tab-lbkum = wa_mara-lbkum.
wa_tab-salk3 = wa_mara-salk3.
CLEAR:it_bsim. REFRESH it_bsim.
SELECT matnr
bwkey
dmbtr
menge
meins
blart
belnr
gjahr
shkzg
FROM bsim
INTOTABLE it_bsim
WHERE matnr = wa_mara-matnr
AND bwkey = 'PALM'
AND budat >= s_date-low
%_HINTS ORACLE 'INDEX("BSIM" "BSIM~ZBS")'.
if sy-subrc = 0.
CLEAR: wa_mara.
ENDIF.
IF wa_mara ISNOTINITIAL.
SELECT mara~matnr
mara~mtart
mseg~mblnr
mseg~mjahr
mseg~bwart
mseg~werks
mseg~lgort
mseg~dmbtr
mseg~menge
mseg~meins
mkpf~budat
mseg~ebeln
mseg~aufnr
INTOTABLE it_mseg
FROM mara AS mara JOIN mseg AS mseg
ON mara~matnr = mseg~matnr
JOIN mkpf AS mkpf
ON mseg~mandt = mkpf~mandt
AND mseg~mblnr = mkpf~mblnr
AND mseg~mjahr = mkpf~mjahr
WHERE mara~matnr = wa_mara-matnr
AND mara~mtart = wa_mara-mtart
AND mseg~werks = 'PALM'
AND mkpf~budat GE s_date-low.
IF sy-subrc = 0.
LOOPAT it_mseg INTO wa_mseg.
IF ( wa_mseg-bwart = '101') OR ( wa_mseg-bwart = '561') OR ( wa_mseg-bwart = '701') OR ( wa_mseg-bwart = '261')
OR ( wa_mseg-bwart = '201') OR ( wa_mseg-bwart = '702').
CLEAR wa_mseg.
ENDIF.
CHECK wa_mseg IS NOT INITIAL.
wa_tab-matnr = wa_mseg-matnr.
wa_tab-lv_date = s_date-low.
wa_tab-lgort = wa_mseg-lgort.
wa_tab-mtart = wa_mseg-mtart.
wa_tab-ebeln = wa_mseg-ebeln.
wa_tab-aufnr = wa_mseg-aufnr.
APPEND wa_tab TO it_tab.
CLEAR wa_tab.
ENDLOOP.
ENDIF.
wa_tab-matnr = wa_mara-matnr.
wa_tab-mtart = wa_mara-mtart.
wa_tab-ersda = wa_mara-ersda.
CLEAR: makt.
SELECTSINGLE maktx FROM makt INTO (wa_tab-maktx)
WHERE matnr = wa_mara-matnr.
IF wa_tab-lgort IS INITIAL.
CLEAR: mard.
SELECTSINGLE LGORT FROM MARD INTO WA_TAB-LGORT
WHERE matnr = wa_tab-matnr
AND labst = wa_tab-lbkum
AND werks = 'PALM'
%_HINTS ORACLE 'INDEX("MARD" "MARD~ZMD")'.
endif.
wa_tab-lv_date = s_date-low.
APPEND wa_tab TO it_tab.
CLEAR wa_tab.
ENDIF.
CLEAR: wa_mara.
ENDLOOP.
ENDFORM. "DATA-FETCH
*&---------------------------------------------------------------------*
*& Form fcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM fcat.
wa_fcat-fieldname = 'LV_DATE'.
wa_fcat-seltext_m = 'Start.Date'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'LGORT'.
wa_fcat-seltext_m = 'Storage Location'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-seltext_m = 'Material No'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'MAKTX'.
wa_fcat-seltext_m = 'Material Descrip'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'ERSDA'.
wa_fcat-seltext_m = 'Mat.created.Date'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'MTART'.
wa_fcat-seltext_m = 'Material Type'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'LBKUM'.
wa_fcat-seltext_m = ' Tot.Qty'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'SALK3'.
wa_fcat-seltext_m = 'Inventory Value '.
wa_fcat-do_sum = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'AUFNR'.
wa_fcat-seltext_m = 'Productionorder .No'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
wa_fcat-fieldname = 'EBELN'.
wa_fcat-seltext_m = 'Purchase order .No'.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
ENDFORM. "fcat
*&---------------------------------------------------------------------*
*& Form LAYOUT
*&---------------------------------------------------------------------*
FORM layout.
it_layout-zebra = 'X'.
it_layout-colwidth_optimize = 'X'.
ENDFORM. "LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY
*&---------------------------------------------------------------------*
FORM display.
CALLFUNCTION'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = it_layout
it_fieldcat = it_fcat
i_save = 'A'
is_variant = variant
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_tab
EXCEPTIONS
program_error = 1
OTHERS = 2
.
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. "display