Вы находитесь на странице: 1из 11

*&---------------------------------------------------------------------*

*& Report ZANILS8


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zmr_inventory_ageing_report NO STANDARD PAGE HEADING .
**---------------------------------------------------------------------*
** MODULE MM *
**---------------------------------------------------------------------*
** Objective: To display the details of the materials for which *
** stock is present. *
** *
** Program : Updates Tables ( ) Downloads data ( ) *
** Outputs list ( X ) *
** *
** Technical Spec No: TS_ ZMR_INVENTORY_AGEING_REPORT *
** DATE Created 23/11/2004 *
** Author Bhawit Kumar *
** Location SISL/Mumbai *
** *
** REQUEST CLIENT USER DATE *
** FH1K902261 300 SISLUSER 23/11/2004 *
**---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Types *
*---------------------------------------------------------------------*
TYPES: BEGIN OF ty_mard,
matnr LIKE mard-matnr,
werks LIKE mard-werks,
lgort LIKE mard-lgort,
END OF ty_mard.
TYPES: BEGIN OF ty_mchb,
charg LIKE mchb-charg,
clabs LIKE mchb-clabs,
cumlm LIKE mchb-cumlm,
cinsm LIKE mchb-cinsm,
ceinm LIKE mchb-ceinm,
cspem LIKE mchb-cspem,
cretm LIKE mchb-cretm,
END OF ty_mchb.
*TYPES: BEGIN OF ty_mchb,
* charg LIKE mchb-charg,
* clabs LIKE mchb-clabs,
* cumlm LIKE mchb-cumlm,
* cinsm LIKE mchb-cinsm,
* ceinm LIKE mchb-ceinm,
* cspem LIKE mchb-cspem,
* cretm LIKE mchb-cretm,
* cvmla LIKE mchb-cvmla,
* cvmum LIKE mchb-cvmum,
* cvmin LIKE mchb-cvmin,
* cvmei LIKE mchb-cvmei,
* cvmsp LIKE mchb-cvmsp,
* cvmre LIKE mchb-cvmre,
*END OF ty_mchb.
TYPES: BEGIN OF ty_data,
matnr LIKE mard-matnr,
maktx LIKE makt-maktx,
werks LIKE mard-werks,
lgort TYPE mard-lgort,
charg LIKE mchb-charg,
tot LIKE mchb-cvmei,
END OF ty_data.
TYPES : BEGIN OF ty_rep,
matnr LIKE mard-matnr,
maktx LIKE makt-maktx,
werks LIKE mard-werks,
lgort TYPE mard-lgort,
charg LIKE mchb-charg,
budat LIKE mkpf-budat,
tot LIKE mchb-cvmei,
verpr LIKE mbew-verpr,
price LIKE mbew-verpr,
admdate LIKE mkpf-budat,
ndate TYPE i,
sdate TYPE i,
END OF ty_rep.
*---------------------------------------------------------------------*
* TYPE-POOLS *
*---------------------------------------------------------------------*
TYPE-POOLS: slis.
*---------------------------------------------------------------------*
* Data Declarations *
*---------------------------------------------------------------------*
DATA w_maktx LIKE makt-maktx.
DATA w_tot1 LIKE mchb-cvmei.
DATA w_mblnr LIKE mseg-mblnr.
DATA w_budat LIKE mkpf-budat.
DATA w_mjahr LIKE mseg-mjahr.
DATA w_verpr LIKE mbew-verpr.
DATA w_price LIKE mbew-verpr.
DATA w_mtart LIKE mara-mtart.
DATA w_date LIKE mkpf-budat.
DATA w_id LIKE sy-repid.
DATA itab_fcat TYPE slis_t_fieldcat_alv.
DATA wa_fcat TYPE slis_fieldcat_alv.
DATA w_title TYPE sy-title VALUE 'INVENTORY AGEING REPORT'.
DATA w_matnr TYPE mara-matnr.
DATA w_plant TYPE mard-werks.
DATA w_flag TYPE c VALUE 'X'.
*---------------------------------------------------------------------*
* Internal tables *
*---------------------------------------------------------------------*
DATA it_mard TYPE TABLE OF ty_mard.
DATA wa_mard LIKE LINE OF it_mard.
DATA it_mchb TYPE TABLE OF ty_mchb.
DATA wa_mchb LIKE LINE OF it_mchb.
DATA it_data TYPE TABLE OF ty_data.
DATA wa_data LIKE LINE OF it_data.
DATA it_rep TYPE TABLE OF ty_rep.
DATA wa_rep LIKE LINE OF it_rep.
*---------------------------------------------------------------------*
* SELECTION SCREEN *
*---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK w_b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : so_matnr FOR w_matnr ,
so_plant FOR w_plant.
SELECTION-SCREEN END OF BLOCK w_b1.
***********************************************************************
* S T A R T O F S E L E C T I O N *
***********************************************************************
START-OF-SELECTION.
IF so_matnr IS INITIAL.
so_matnr-low = '*'.
so_matnr-sign = 'I'.
so_matnr-option = 'CP'.
APPEND so_matnr.
ENDIF.
IF so_plant IS INITIAL.
so_plant-low = '*'.
so_plant-sign = 'I'.
so_plant-option = 'CP'.
APPEND so_plant.
ENDIF.
BREAK-POINT.
SELECT matnr werks lgort FROM mard INTO CORRESPONDING FIELDS OF
TABLE it_mard WHERE
matnr IN so_matnr.
* AND werks IN so_plant.
*( labst NE ' ' OR umlme NE ' ' OR
* insme NE ' ' OR einme NE ' ' OR speme NE ' ' OR
* retme NE ' ' )
* SELECT matnr werks lgort FROM mard INTO CORRESPONDING FIELDS OF
* TABLE it_mard WHERE ( labst NE ' ' OR umlme NE ' ' OR
* insme NE ' ' OR einme NE ' ' OR speme NE ' ' OR
* retme NE ' ' OR vmlab NE ' ' OR vmuml NE ' ' OR
* vmins NE ' ' OR vmein NE ' ' OR vmspe NE ' ' OR
* vmret NE ' ' )
* AND matnr IN so_matnr
* AND werks IN so_plant.
SORT it_mard BY matnr werks lgort ASCENDING.
DELETE ADJACENT DUPLICATES FROM it_mard COMPARING ALL FIELDS.
LOOP AT it_mard INTO wa_mard.
SELECT SINGLE maktx FROM makt INTO w_maktx
WHERE matnr = wa_mard-matnr.
SELECT charg clabs cumlm cinsm ceinm cspem cretm
FROM mchb INTO CORRESPONDING FIELDS OF TABLE
it_mchb WHERE matnr = wa_mard-matnr
AND werks = wa_mard-werks
AND lgort = wa_mard-lgort.
* SELECT charg clabs cumlm cinsm ceinm cspem cretm cvmla
* cvmum cvmin cvmei cvmsp cvmre
* FROM mchb INTO CORRESPONDING FIELDS OF TABLE
* it_mchb WHERE matnr = wa_mard-matnr
* AND werks = wa_mard-werks
* AND lgort = wa_mard-lgort.
LOOP AT it_mchb INTO wa_mchb.
w_tot1 = wa_mchb-clabs + wa_mchb-cumlm + wa_mchb-cinsm + wa_mchb-ceinm
+ wa_mchb-cspem + wa_mchb-cretm.
* w_tot1 = wa_mchb-clabs + wa_mchb-cumlm + wa_mchb-cinsm + wa_mchb-ceinm
* + wa_mchb-cspem + wa_mchb-cretm + wa_mchb-cvmla + wa_mchb-cvmum +
* wa_mchb-cvmin + wa_mchb-cvmei + wa_mchb-cvmsp + wa_mchb-cvmre.
IF w_tot1 EQ '0'.
CONTINUE.
ENDIF.
wa_data-matnr = wa_mard-matnr.
wa_data-maktx = w_maktx.
wa_data-werks = wa_mard-werks.
wa_data-lgort = wa_mard-lgort.
wa_data-charg = wa_mchb-charg.
wa_data-tot = w_tot1.
APPEND wa_data TO it_data.
CLEAR wa_data.
CLEAR wa_mchb.
CLEAR w_tot1.
ENDLOOP.
CLEAR: w_maktx,
wa_mard.
ENDLOOP.
CLEAR wa_data.
SORT it_data BY matnr ASCENDING.
LOOP AT it_data INTO wa_data.
CLEAR w_flag.
SELECT SINGLE mblnr mjahr FROM mseg INTO
(w_mblnr , w_mjahr)
WHERE bwart = '101'
AND matnr = wa_data-matnr
AND werks = wa_data-werks
AND charg = wa_data-charg.
IF sy-subrc NE '0'.
w_flag = 'Y'.
SELECT SINGLE mblnr mjahr FROM mseg INTO
(w_mblnr , w_mjahr)
WHERE bwart = '561'
AND matnr = wa_data-matnr
AND werks = wa_data-werks
AND charg = wa_data-charg.
ENDIF.
SELECT SINGLE budat FROM mkpf INTO w_budat
WHERE mblnr = w_mblnr
AND mjahr = w_mjahr.
SELECT SINGLE verpr FROM mbew INTO w_verpr
WHERE matnr = wa_data-matnr
AND bwkey = wa_data-werks.
w_price = w_verpr * wa_data-tot.
SELECT SINGLE mtart FROM mara INTO w_mtart
WHERE matnr = wa_data-matnr.
IF w_mtart EQ 'ZPCM'.
CLEAR: w_mblnr,
w_mjahr.
SELECT SINGLE mblnr mjahr FROM mseg INTO
(w_mblnr , w_mjahr)
WHERE bwart = '101'
AND matnr = wa_data-matnr
AND werks = '3000'
AND charg = wa_data-charg.
IF sy-subrc NE '0'.
w_flag = 'Y'.
ENDIF.
SELECT SINGLE budat FROM mkpf INTO w_date
WHERE mblnr = w_mblnr
AND mjahr = w_mjahr.
wa_rep-matnr = wa_data-matnr.
wa_rep-maktx = wa_data-maktx.
wa_rep-werks = wa_data-werks.
wa_rep-lgort = wa_data-lgort.
wa_rep-charg = wa_data-charg.
wa_rep-budat = w_budat.
wa_rep-tot = wa_data-tot.
wa_rep-verpr = w_verpr.
wa_rep-price = w_price.
wa_rep-admdate = w_date.
wa_rep-ndate = sy-datum - w_date.
wa_rep-sdate = sy-datum - w_budat.
IF w_flag EQ 'Y'.
CLEAR: wa_rep-admdate,
wa_rep-ndate.
ENDIF.
APPEND wa_rep TO it_rep.
CLEAR w_flag.
* ELSEIF w_mtart EQ 'ZFG'.
* CLEAR: w_mblnr,
* w_mjahr.
*
* SELECT SINGLE mblnr mjahr FROM mseg INTO
* (w_mblnr , w_mjahr)
* WHERE bwart = '101'
* AND matnr = wa_data-matnr
* AND werks = 'INC1'
* AND charg = wa_data-charg.
* IF sy-subrc NE '0'.
* w_flag = 'Y'.
* ENDIF.
*
*
* SELECT SINGLE budat FROM mkpf INTO w_date
* WHERE mblnr = w_mblnr
* AND mjahr = w_mjahr.
*
* wa_rep-matnr = wa_data-matnr.
* wa_rep-maktx = wa_data-maktx.
* wa_rep-werks = wa_data-werks.
* wa_rep-lgort = wa_data-lgort.
* wa_rep-charg = wa_data-charg.
* wa_rep-budat = w_budat.
* wa_rep-tot = wa_data-tot.
* wa_rep-verpr = w_verpr.
* wa_rep-price = w_price.
* wa_rep-admdate = w_date.
* wa_rep-ndate = sy-datum - w_date.
* wa_rep-sdate = sy-datum - w_budat.
*
* IF w_flag EQ 'Y'.
* CLEAR: wa_rep-admdate,
* wa_rep-ndate.
* ENDIF.
*
* APPEND wa_rep TO it_rep.
*
* CLEAR w_flag.
*
* ELSEIF ( w_mtart NE 'HAWA' AND w_mtart NE 'FERT' ).
*
* CLEAR: w_mblnr,
* w_mjahr,
* w_budat,
* wa_data,
* w_flag,
* w_date,
* w_price,
* w_verpr,
* wa_rep.
*
* CONTINUE.
ENDIF.
CLEAR: w_mblnr,
w_mjahr,
w_budat,
wa_data,
w_date,
w_price,
w_verpr,
wa_rep.
ENDLOOP.
CLEAR: it_data,
wa_data.
CLEAR : so_plant,
so_matnr.
REFRESH : so_plant,
so_matnr.
***********************************************************************
* END OF S E L E C T I O N *
***********************************************************************
END-OF-SELECTION.
* CREATING THE FIELD CATALOG
PERFORM w_fieldcat_create .
w_id = sy-repid.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = w_id
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_STRUCTURE_NAME =
* IS_LAYOUT =
it_fieldcat = itab_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_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
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_rep
* 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.
CLEAR: it_rep,
so_plant,
so_matnr,
w_id.
REFRESH: so_plant,
so_matnr.
*&---------------------------------------------------------------------*
*& Form w_fieldcat_create
*&---------------------------------------------------------------------*
* SUBROUTINE TO CREATE THE FIELD CATALOGUE FOR ALV OUTPUT *
*----------------------------------------------------------------------*
FORM w_fieldcat_create.
CLEAR wa_fcat.
wa_fcat-col_pos = 1.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-seltext_l = 'Material No'.
wa_fcat-outputlen = '18'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 2.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'MAKTX'.
wa_fcat-seltext_l = 'Material Description'.
wa_fcat-outputlen = '40'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 3.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'WERKS'.
wa_fcat-seltext_l = 'Plant'.
wa_fcat-outputlen = '5'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 4.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'LGORT'.
wa_fcat-seltext_l = 'Storage location'.
wa_fcat-outputlen = '17'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 5.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'CHARG'.
wa_fcat-seltext_l = 'Batch number'.
wa_fcat-outputlen = '12'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 6.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'BUDAT'.
wa_fcat-seltext_l = 'Date Of Receipt'.
wa_fcat-outputlen = '15'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 7.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'TOT'.
wa_fcat-seltext_l = 'Stock Quantity'.
wa_fcat-outputlen = '18'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 8.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'VERPR'.
wa_fcat-seltext_l = 'Moving Average Price'.
wa_fcat-outputlen = '21'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 9.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'PRICE'.
wa_fcat-seltext_l = 'Stock Value'.
wa_fcat-outputlen = '15'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 10.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'ADMDATE'.
wa_fcat-seltext_l = 'Actual Date Of Mfg/Import'.
wa_fcat-outputlen = '25'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 11.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'NDATE'.
wa_fcat-seltext_l = 'No Of Days Lying In Stock' .
wa_fcat-outputlen = '26'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
wa_fcat-col_pos = 12.
wa_fcat-tabname = 'ITAB_REP'.
wa_fcat-fieldname = 'SDATE'.
wa_fcat-seltext_l = 'No Of Days Lying In Location' .
wa_fcat-outputlen = '30'.
APPEND wa_fcat TO itab_fcat.
CLEAR wa_fcat.
ENDFORM. " w_fieldcat_create