Skip to Content
author's profile photo Former Member
Former Member

Opening Stock and Closing Stock

Hi,

I have one requirement to get a opening stock and closing stock of all materials, based on the plant date and mat type.

Could u tell me the flow of tables one by one

Its is possible to get the opening stock and closing stock of all materials.

Please Guide Me.

Thanks & Regards,

Dhanush.S.T

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • author's profile photo Former Member
    Former Member
    Posted on Apr 02, 2008 at 09:56 AM

    go through this....

    *&----


    *

    *& Report Z_OPEN_CLOSE *

    *& *

    *&----


    *

    *& *

    *& *

    *&----


    *

    REPORT Z_OPEN_CLOSE 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_SPMON0(4) = S_BUDAT-LOW0(4).

    P_SPMON4(2) = S_BUDAT-LOW4(2).

    ELSE.

    P_SPMON0(4) = S_BUDAT-LOW0(4).

    P_SPMON4(2) = S_BUDAT-LOW4(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-LOW4(2) = S_BUDAT-LOW4(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-LOW4(2) = S_BUDAT-LOW4(2).

    R_BUDAT-LOW = S_BUDAT-LOW.

    MODIFY R_BUDAT.

    ENDIF.

    IF R_BUDAT-HIGH4(2) = S_BUDAT-HIGH4(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_SPMON0(4) = S_BUDAT-LOW0(4).

    P_SPMON4(2) = S_BUDAT-LOW4(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 für 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: .

    • 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-LOW6(2) '/' S_BUDAT-LOW4(2) '/'

    S_BUDAT-LOW+0(4) INTO LOW.

    CONCATENATE S_BUDAT-HIGH6(2) '/' S_BUDAT-HIGH4(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

    ( BUDAT0(4) EQ I_FINALT-MONTH0(4) AND

    BUDAT4(2) EQ I_FINALT-MONTH5(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_SPMON0(4) '.' P_SPMON4(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 MKPFMBLNR = MSEGMBLNR

    AND MKPFMJAHR = MSEGMJAHR

    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 (

    ( BUDAT4(2) GT P_SPMON4(2) AND

    MJAHR EQ P_SPMON+0(4) ) OR

    ( BUDAT4(2) LE P_SPMON4(2) AND

    MJAHR NE P_SPMON+0(4) ) OR

    ( BUDAT4(2) GE P_SPMON4(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

    ( BUDAT4(2) NE P_SPMON4(2) OR

    ( BUDAT4(2) EQ P_SPMON4(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

    *&----


    *

    • text

    *----


    *

    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'.

    FrwCAT1-OUTPUTLEN = '000003'.

    FCAT1-JUST = 'L'.

    d

    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

    rewards plzz.........

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.