THE REPOT PROVIDES INFORMATION ON AGING OF FSE

*&---------------------------------------------------------------------*
*& Report Z_M_S_FSE_AGEING *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
* Author : Sambasivarao. M *
* Date : 05 May 2006 *
* Description : The report provides information on Aging of FSE *
*& holding Stock. *
*&---------------------------------------------------------------------*
*Change History
*----------------------------------------------------------------------*
*USER | date | Detailed Description
*----------------------------------------------------------------------*
* | |
* | |
* | |
* | |
* | |
* | |
*----------------------------------------------------------------------*
REPORT Z_M_S_FSE_AGEING
MESSAGE-ID K6
LINE-SIZE 190
NO STANDARD PAGE HEADING.

************************************************************************
* DECLARATION OF TABLES *
************************************************************************
TABLES: MSKU, " Special Stocks with Customer
MAKT, " Material Descriptions
MARA, " General Material Data
T001W, " Plants/Branches
KNA1, " General Data in Customer Master
MSEG, " Document Segment: Material
MKPF, " Header: Material Document
LIPS, " SD document: Delivery: Item data
VBAP, " Sales Document: Item Data
T005T, " Country Names
T005U. " Taxes: Region Key: Texts

************************************************************************
* HEADER *
************************************************************************

INCLUDE ZPAGEHDR1.

************************************************************************
* DATA DECLARATIONS *
************************************************************************

******************** Main Data Selection********************************

DATA: BEGIN OF ITAB OCCURS 0,
MBLNR LIKE MSEG-MBLNR, " Reference Number
KUNNR LIKE MSKU-KUNNR, " Customer Number
NAME1_K LIKE KNA1-NAME1, " Customer Name
MATNR LIKE MSKU-MATNR, " Material
MAKTX LIKE MAKT-MAKTX, " Material Description
KULAB LIKE MSKU-KULAB, " Stock with FSE
MEINS LIKE MARA-MEINS, " UOM
WERKS LIKE MSKU-WERKS, " Plant
LFGJA LIKE MSKU-LFGJA, " Fiscal Year
* name1_w LIKE t001w-name1, " Plant Name
KBETR LIKE KONP-KBETR, " Unit Price
COST LIKE KONP-KBETR, " Extended Cost
BUDAT LIKE MKPF-BUDAT, " Transaction Date
DAYS TYPE I, " Outstanding Days
REGIO LIKE KNA1-REGIO, " Region
LAND1 LIKE KNA1-LAND1, " Country
END OF ITAB.

* DATA: BEGIN OF LIST OCCURS 0.
* INCLUDE STRUCTURE ITAB.
* DATA: END OF LIST.
*
* DATA: BEGIN OF HEADER OCCURS 0,
* KUNNR LIKE KNA1-KUNNR,
* NAME1_K LIKE KNA1-NAME1,
* END OF HEADER.
*
DATA: BEGIN OF MAKT_KEY OCCURS 0,
MATNR LIKE MAKT-MATNR,
END OF MAKT_KEY.
DATA: BEGIN OF IMAKT OCCURS 0,
MATNR LIKE MAKT-MATNR,
MAKTX LIKE MAKT-MAKTX,
END OF IMAKT.
DATA: BEGIN OF MARA_KEY OCCURS 0,
MATNR LIKE MARA-MATNR,
END OF MARA_KEY.
DATA: BEGIN OF IMARA OCCURS 0,
MATNR LIKE MARA-MATNR,
MEINS LIKE MARA-MEINS,
END OF IMARA.
DATA: BEGIN OF T001W_KEY OCCURS 0,
WERKS LIKE T001W-WERKS,
END OF T001W_KEY.
DATA: BEGIN OF IT001W OCCURS 0,
WERKS LIKE T001W-WERKS,
NAME1 LIKE T001W-NAME1,
END OF IT001W.
DATA: BEGIN OF KNA1_KEY OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
END OF KNA1_KEY.
DATA: BEGIN OF IKNA1 OCCURS 0,
KUNNR LIKE KNA1-KUNNR,
NAME1 LIKE KNA1-NAME1,
REGIO LIKE KNA1-REGIO,
LAND1 LIKE KNA1-LAND1,
END OF IKNA1.


************************************************************************
* SELECTION SCREEN *
************************************************************************

SELECTION-SCREEN: BEGIN OF BLOCK DBA WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : MATNR FOR MARA-MATNR,
WERKS FOR T001W-WERKS MEMORY ID WRK,
* charg FOR msku-charg,
KUNNR FOR MSKU-KUNNR.
* PARAMETERS: sobkz_w LIKE am07m-kukns AS CHECKBOX DEFAULT 'X',
* sobkz_v LIKE am07m-lhgut AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN: END OF BLOCK DBA.

************************************************************************
* INPUT SCREEN VALIDATIONS *
************************************************************************

************************* Validating MATNR ***************************

AT SELECTION-SCREEN ON MATNR.
IF NOT MATNR-LOW IS INITIAL.
PERFORM MATNR_VALID USING MATNR-LOW.
ENDIF.

IF NOT MATNR-HIGH IS INITIAL.
PERFORM MATNR_VALID USING MATNR-HIGH.
ENDIF.

************************* Validating WERKS ***************************

AT SELECTION-SCREEN ON WERKS.
IF NOT WERKS-LOW IS INITIAL.
PERFORM WERKS_VALID USING WERKS-LOW.
ENDIF.

IF NOT WERKS-HIGH IS INITIAL.
PERFORM WERKS_VALID USING WERKS-HIGH.
ENDIF.

************************* Validating KUNNR ***************************

AT SELECTION-SCREEN ON KUNNR.
IF NOT KUNNR-LOW IS INITIAL.
PERFORM KUNNR_VALID USING KUNNR-LOW.
ENDIF.

IF NOT KUNNR-HIGH IS INITIAL.
PERFORM KUNNR_VALID USING KUNNR-HIGH.
ENDIF.


************************************************************************
* START OF SELECTION *
************************************************************************
START-OF-SELECTION.

************************* Main Data Selection **************************

PERFORM GET_DATA.

PERFORM PRINT_DETAILS.

************************************************************************
* TOP OF PAGE - HEADER *
************************************************************************

TOP-OF-PAGE.

PERFORM HEADER USING SY-TITLE ' '.
PERFORM REPORT_HEADER.

*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text *----------------------------------------------------------------------* FORM GET_DATA . SELECT * FROM MSKU INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE MATNR IN MATNR AND WERKS IN WERKS * AND charg IN charg * AND sobkz IN sobkz AND SOBKZ EQ 'W' " Select only consignment AND KUNNR IN KUNNR AND KULAB GT '0'. * Additional info: material text, plant name, debitor name LOOP AT ITAB. MAKT_KEY-MATNR = ITAB-MATNR. COLLECT MAKT_KEY. MARA_KEY-MATNR = ITAB-MATNR. COLLECT MARA_KEY. T001W_KEY-WERKS = ITAB-WERKS. COLLECT T001W_KEY. KNA1_KEY-KUNNR = ITAB-KUNNR. COLLECT KNA1_KEY. ENDLOOP. READ TABLE MAKT_KEY INDEX 1. IF SY-SUBRC = 0. SELECT MATNR MAKTX INTO CORRESPONDING FIELDS OF TABLE IMAKT FROM MAKT FOR ALL ENTRIES IN MAKT_KEY WHERE MATNR = MAKT_KEY-MATNR AND SPRAS = SY-LANGU. SORT IMAKT BY MATNR. ENDIF. READ TABLE MARA_KEY INDEX 1. IF SY-SUBRC = 0. SELECT MATNR MEINS INTO CORRESPONDING FIELDS OF TABLE IMARA FROM MARA FOR ALL ENTRIES IN MARA_KEY WHERE MATNR = MARA_KEY-MATNR. SORT IMARA BY MATNR. ENDIF. READ TABLE T001W_KEY INDEX 1. IF SY-SUBRC = 0. SELECT WERKS NAME1 INTO CORRESPONDING FIELDS OF TABLE IT001W FROM T001W FOR ALL ENTRIES IN T001W_KEY WHERE WERKS = T001W_KEY-WERKS. SORT IT001W BY WERKS. ENDIF. READ TABLE KNA1_KEY INDEX 1. IF SY-SUBRC = 0. SELECT KUNNR NAME1 REGIO LAND1 INTO CORRESPONDING FIELDS OF TABLE IKNA1 FROM KNA1 FOR ALL ENTRIES IN KNA1_KEY WHERE KUNNR = KNA1_KEY-KUNNR. SORT IKNA1 BY KUNNR. ENDIF. LOOP AT ITAB. READ TABLE IMAKT WITH KEY MATNR = ITAB-MATNR BINARY SEARCH. IF SY-SUBRC = 0. ITAB-MAKTX = IMAKT-MAKTX. ENDIF. READ TABLE IMARA WITH KEY MATNR = ITAB-MATNR BINARY SEARCH. IF SY-SUBRC = 0. ITAB-MEINS = IMARA-MEINS. ENDIF. * READ TABLE it001w WITH KEY werks = itab-werks BINARY SEARCH. * IF sy-subrc = 0. itab-name1_w = it001w-name1. ENDIF. READ TABLE IKNA1 WITH KEY KUNNR = ITAB-KUNNR BINARY SEARCH. IF SY-SUBRC = 0. ITAB-NAME1_K = IKNA1-NAME1. ITAB-REGIO = IKNA1-REGIO. ITAB-LAND1 = IKNA1-LAND1. ENDIF. MODIFY ITAB. ENDLOOP. SORT ITAB BY KUNNR MATNR. LOOP AT ITAB. SELECT SINGLE * FROM MSEG INTO CORRESPONDING FIELDS OF MSEG WHERE MATNR EQ ITAB-MATNR AND WERKS EQ ITAB-WERKS AND * MJAHR EQ ITAB-LFGJA AND SOBKZ EQ 'W' AND " Select only Consignment BWART EQ '631' AND KUNNR EQ ITAB-KUNNR. IF SY-SUBRC EQ 0. MOVE MSEG-MBLNR TO ITAB-MBLNR. SELECT SINGLE * FROM MKPF INTO CORRESPONDING FIELDS OF MKPF WHERE MBLNR EQ MSEG-MBLNR AND MJAHR EQ MSEG-MJAHR. IF SY-SUBRC EQ 0. MOVE MKPF-BUDAT TO ITAB-BUDAT. PERFORM RETRIEVE_PRICE. ELSE. CLEAR MKPF. ENDIF. ELSE. CLEAR MSEG. ENDIF. ITAB-DAYS = SY-DATUM - ITAB-BUDAT. MODIFY ITAB INDEX SY-TABIX. ENDLOOP. ENDFORM. " GET_DATA * *&---------------------------------------------------------------------* *& Form retrieve_price *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text
* <-- p2 text *----------------------------------------------------------------------* FORM RETRIEVE_PRICE . SELECT SINGLE * FROM LIPS INTO CORRESPONDING FIELDS OF LIPS WHERE VBELN EQ MKPF-XBLNR. IF SY-SUBRC EQ 0. SELECT SINGLE * FROM VBAP INTO CORRESPONDING FIELDS OF VBAP WHERE VBELN EQ LIPS-VGBEL AND MATNR EQ ITAB-MATNR. IF SY-SUBRC EQ 0. MOVE VBAP-NETPR TO ITAB-KBETR. ITAB-COST = ITAB-KULAB * ITAB-KBETR. ELSE. CLEAR VBAP. ENDIF. ELSE. CLEAR LIPS. ENDIF. ENDFORM. " retrieve_price *&---------------------------------------------------------------------* *& Form PRINT_DETAILS *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text
* <-- p2 text *----------------------------------------------------------------------* FORM PRINT_DETAILS . * FORMAT COLOR 2 INTENSIFIED OFF. CLEAR ITAB. LOOP AT ITAB. SELECT SINGLE * FROM T005T WHERE SPRAS EQ SY-LANGU AND LAND1 EQ ITAB-LAND1. IF SY-SUBRC NE 0. CLEAR T005T. ELSE. TRANSLATE T005T-LANDX TO UPPER CASE. ENDIF. SELECT SINGLE * FROM T005U WHERE SPRAS EQ SY-LANGU AND LAND1 EQ ITAB-LAND1 AND BLAND EQ ITAB-REGIO. IF SY-SUBRC NE 0. CLEAR T005U. ENDIF. WRITE:/(01) '|' NO-GAP, (10) ITAB-MBLNR NO-GAP, '|' NO-GAP, (10) ITAB-KUNNR NO-GAP, '|' NO-GAP, (30) ITAB-NAME1_K NO-GAP, '|' NO-GAP, (18) ITAB-MATNR NO-GAP, '|' NO-GAP, (13) ITAB-KULAB NO-GAP, '|' NO-GAP, (03) ITAB-MEINS NO-GAP, '|' NO-GAP, (05) ITAB-WERKS NO-GAP, '|' NO-GAP, (16) ITAB-KBETR NO-GAP, '|' NO-GAP, (16) ITAB-COST NO-GAP, '|' NO-GAP, (10) ITAB-BUDAT NO-GAP, '|' NO-GAP, (10) ITAB-DAYS NO-GAP, '|' NO-GAP, (20) T005U-BEZEI NO-GAP, '|' NO-GAP, (15) T005T-LANDX NO-GAP, '|' NO-GAP. ENDLOOP. ULINE. ENDFORM. " PRINT_DETAILS *&---------------------------------------------------------------------* *& Form report_header *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text
* <-- p2 text *----------------------------------------------------------------------* FORM REPORT_HEADER . SKIP. ULINE. FORMAT COLOR 1. WRITE:/(01) '|' NO-GAP, (10) 'Ref. No.' NO-GAP, '|' NO-GAP, (10) 'Customer' NO-GAP, '|' NO-GAP, (30) 'Name' NO-GAP, '|' NO-GAP, (18) 'Material' NO-GAP, '|' NO-GAP, (13) 'Quantity' RIGHT-JUSTIFIED NO-GAP, '|' NO-GAP, (03) 'BuN' NO-GAP, '|' NO-GAP, (05) 'Plant' NO-GAP, '|' NO-GAP, (16) 'Unit Cost' RIGHT-JUSTIFIED NO-GAP, '|' NO-GAP, (16) 'Extended Cost' RIGHT-JUSTIFIED NO-GAP, '|' NO-GAP, (10) 'Trans.Date' NO-GAP, '|' NO-GAP, (10) 'Outst.Days' NO-GAP, '|' NO-GAP, (20) 'Region' NO-GAP, '|' NO-GAP, (15) 'Country' NO-GAP, '|' NO-GAP. ULINE. ENDFORM. " report_header *&---------------------------------------------------------------------* *& Form MATNR_VALID *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->P_MATNR_LOW text
*----------------------------------------------------------------------*
FORM MATNR_VALID USING P_MATNR.
SELECT SINGLE * FROM MARA WHERE MATNR EQ P_MATNR.
IF SY-SUBRC NE 0.
MESSAGE E001 WITH TEXT-013.
STOP.
ENDIF.

ENDFORM. " MATNR_VALID
*&---------------------------------------------------------------------*
*& Form WERKS_VALID
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WERKS_LOW text
*----------------------------------------------------------------------*
FORM WERKS_VALID USING P_WERKS.
SELECT SINGLE * FROM T001W WHERE WERKS EQ P_WERKS.
IF SY-SUBRC NE 0.
MESSAGE E001 WITH TEXT-014.
STOP.
ENDIF.


ENDFORM. " WERKS_VALID
*&---------------------------------------------------------------------*
*& Form KUNNR_VALID
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_KUNNR_LOW text
*----------------------------------------------------------------------*
FORM KUNNR_VALID USING P_KUNNR.
SELECT SINGLE * FROM KNA1 WHERE KUNNR EQ P_KUNNR.
IF SY-SUBRC NE 0.
MESSAGE E001 WITH TEXT-015.
STOP.
ENDIF.

ENDFORM. " KUNNR_VALID