************************************************************************
* Report Name : Z_MM_RP_MONTHLY_GRN_REGISTER *
* Description : Material Management: Monthly GRN Register *
* This report displays the following: *
* 1) GRN Number *
* 2) Posting date in the document(Date) *
* 3) Reference document number(Invoice No) *
* 4) Purchasing Document Number(PO No) *
* 5) Date on which the rec was created(PO Date) *
* 6) Material Description in Short *
* 7) GRN Value in Rs. *
* 8) Material Grp Description *
* 9) Vendor Name *
* based on Plant,Material Document No, *
* Purchasing Document No,Material Group *
* Vendor No and Posting period *
* Functional : *
* Developer : *
* Development class : Z_MSGCLASS *
************************************************************************
REPORT Z_MM_RP_MONTHLY_GRN_REGISTER NO STANDARD PAGE HEADING
MESSAGE-ID Z_MSGCLASS
LINE-COUNT 80
LINE-SIZE 132.
*----------------------------------------------------------------------*
* TYPE-POOLS
*----------------------------------------------------------------------*
TYPE-POOLS: SLIS. " ALV Global types
*----------------------------------------------------------------------*
* DATABASE TABLES
*----------------------------------------------------------------------*
TABLES : MKPF, " Header: Material Document
MSEG, " Document Segment: Material
EKPO, " Purchasing Document Item
LFA1, " Vendor Master
S062. " Object type and manufacturer
*----------------------------------------------------------------------*
* INTERNAL TABLE DECLARATIONS
*----------------------------------------------------------------------*
*---- Internal table to hold Header: Material Document
DATA: BEGIN OF IT_MKPF OCCURS 10,
MBLNR LIKE MKPF-MBLNR, " Material Document No (GRN No)
MJAHR LIKE MKPF-MJAHR, " Material doc. year
BLART LIKE MKPF-BLART, " Document type
BUDAT LIKE MKPF-BUDAT, " Posting date in the document
XBLNR LIKE MKPF-XBLNR, " Reference document number(Inv No)
END OF IT_MKPF.
*---- Internal table to hold Document Segment: Material
DATA: BEGIN OF IT_MSEG OCCURS 10,
MBLNR LIKE MSEG-MBLNR, " Material Document No (GRN No)
MJAHR LIKE MSEG-MJAHR, " Material doc. year
MATNR LIKE MSEG-MATNR, " Material no
WERKS LIKE MSEG-WERKS, " Plant
LIFNR LIKE MSEG-LIFNR, " Vendor's account number
EBELN LIKE MSEG-EBELN, " Purchasing Document Number
GJAHR LIKE MSEG-GJAHR, " Fiscal year
BUKRS LIKE MSEG-BUKRS, " Company Code
END OF IT_MSEG.
*---- Internal table to hold Purchasing Document Header
DATA: BEGIN OF IT_EKKO OCCURS 10,
EBELN LIKE EKKO-EBELN, " Purchasing Document Number
BUKRS LIKE EKKO-BUKRS, " Company Code
AEDAT LIKE EKKO-AEDAT, " Date on which the rec was created (Date)
FRGKE LIKE EKKO-FRGKE, " Release indicator: purchasing document
END OF IT_EKKO.
*---- Internal table to hold Purchasing Document Item
DATA: BEGIN OF IT_EKPO OCCURS 10,
EBELN LIKE EKPO-EBELN, " Purchasing Document Number
TXZ01 LIKE EKPO-TXZ01, " Material Description in Short
MATNR LIKE EKPO-MATNR, " Material Number
BUKRS LIKE EKPO-BUKRS, " Company Code
WERKS LIKE EKPO-WERKS, " Plant
MATKL LIKE EKPO-MATKL, " Material group
END OF IT_EKPO.
*---- Internal table to hold Material Group Descriptions
DATA: BEGIN OF IT_T023T OCCURS 10,
MATKL LIKE T023T-MATKL, " Material Group
WGBEZ LIKE T023T-WGBEZ, " Material Group Description
END OF IT_T023T.
*---- Internal table to hold Vendor Master
DATA: BEGIN OF IT_LFA1 OCCURS 10,
LIFNR LIKE LFA1-LIFNR, " Vendor's account number
NAME1 LIKE LFA1-NAME1, " Vendor Name
END OF IT_LFA1.
*---- Internal table to hold Accounting Document Header
DATA: BEGIN OF IT_BKPF OCCURS 10,
BUKRS LIKE BKPF-BUKRS, " Company Code
BELNR LIKE BKPF-BELNR, " Accounting document number
GJAHR LIKE BKPF-GJAHR, " Fiscal year
XBLNR LIKE BKPF-XBLNR, " Reference document number(Invoice No)
AWKEY LIKE BKPF-AWKEY, " Object key
END OF IT_BKPF.
*---- Internal table to hold Accounting Document Segment
DATA: BEGIN OF IT_BSEG OCCURS 10,
BUKRS LIKE BSEG-BUKRS, " Company Code
BELNR LIKE BSEG-BELNR, " Accounting document number
GJAHR LIKE BSEG-GJAHR, " Fiscal year
BSCHL LIKE BSEG-BSCHL, " Posting key
SHKZG LIKE BSEG-SHKZG, " Debit/credit indicator
DMBTR LIKE BSEG-DMBTR, " Amt in local curr(GRN Value in Rs.)
MATNR LIKE BSEG-MATNR, " Material Number
WERKS LIKE BSEG-WERKS, " Plant
EBELN LIKE BSEG-EBELN, " PO.Number
END OF IT_BSEG.
*---- Internal table to hold Output Data
DATA: BEGIN OF IT_ALV OCCURS 10,
MBLNR LIKE MKPF-MBLNR, " Material Document No (GRN No)
BUDAT LIKE MKPF-BUDAT, " Posting date in the document
XBLNR LIKE MKPF-XBLNR, " Reference document number(Invoice No)
EBELN LIKE MSEG-EBELN, " Purchasing Document Number
WERKS LIKE MSEG-WERKS, " Plant
AEDAT LIKE EKKO-AEDAT, " Date on which the rec was created (Date)
TXZ01 LIKE EKPO-TXZ01, " Material Description in Short
DMBTR LIKE MSEG-DMBTR, " GRN Value in Rs.
WGBEZ LIKE T023T-WGBEZ, " Material Grp Description
LIFNR LIKE MSEG-LIFNR, " Vendor No
NAME1 LIKE LFA1-NAME1, " Vendor Name
END OF IT_ALV.
*----------------------------------------------------------------------*
* DATA DECLARATIONS RELATED TO ALV
*----------------------------------------------------------------------*
DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, " Fieldcat table
FIELDCAT_LN LIKE LINE OF FIELDCAT, " Line of Fieldcat
V_FIELD TYPE SLIS_FIELDNAME, " Name of field
V_COL_POS TYPE I , " Column Position
V_PGM LIKE SY-REPID, " Program Name
V_FIELD_VALUE(20), " Value of Field
V_DDICTXT(1), " Text type Indicator
V_SELTEXT(30), " Selection Text
V_TABLE_NAME(10). " Table name
*----------------------------------------------------------------------*
* CONSTANTS
*----------------------------------------------------------------------*
CONSTANTS: C_BLART LIKE MKPF-BLART VALUE 'WE', " Document type
C_BSCHL LIKE BSEG-BSCHL VALUE '89', " Posting Key
C_AWTYP LIKE ACCDN-AWTYP VALUE 'MKPF', " Reference procedure
C_FRGKE LIKE EKKO-FRGKE VALUE '2'. " Release indicator: Purchasing document
*----------------------------------------------------------------------*
* DATA DECLARATIONS
*----------------------------------------------------------------------*
DATA : V_MESG(200), " Message variable
V_TODATE TYPE D, " To Date
V_FROMDATE TYPE D, " From Date
V_PDATE_LOW(10), " Posting To-Date
V_PDATE_HIGH(10), " Posting From-Date
V_BELNR LIKE BKPF-BELNR, " Accounting Document no
V_DAYS TYPE P VALUE 01, " No.of Days
V_DATFM LIKE USR01-DATFM, " Date format
V_DS TYPE C. " Seperation Of Date
*----------------------------------------------------------------------*
* FLAGS *
*----------------------------------------------------------------------*
DATA: V_FLAG(1). " Flag for Selection Criteria
*----------------------------------------------------------------------*
* SELECTION SCREEN
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK SCR1 WITH FRAME TITLE TEXT-111.
SELECT-OPTIONS : S_WERKS FOR MSEG-WERKS OBLIGATORY, " Plant
S_MBLNR FOR MKPF-MBLNR, " No of material document
S_EBELN FOR MSEG-EBELN, " Purchasing Document No
S_MATKL FOR EKPO-MATKL, " Material Group
S_LIFNR FOR LFA1-LIFNR. " Vendor No
PARAMETERS: P_SPBUP LIKE S062-SPBUP OBLIGATORY. " Posting period - analyze
SELECTION-SCREEN END OF BLOCK SCR1.
*----------------------------------------------------------------------*
* AT SELECTION SCREEN
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON S_WERKS.
*--- Perform to validate the Plant
PERFORM VALIDATE_WERKS.
AT SELECTION-SCREEN ON S_MBLNR.
*--- Perform to validate the No of material document
PERFORM VALIDATE_MBLNR.
AT SELECTION-SCREEN ON S_EBELN.
*--- Perform to validate the Purchasing Document Number
PERFORM VALIDATE_EBELN.
AT SELECTION-SCREEN ON S_MATKL.
*--- Perform to validate the Material Group
PERFORM VALIDATE_MATKL.
AT SELECTION-SCREEN ON S_LIFNR.
*--- Perform to validate the Vendor No
PERFORM VALIDATE_LIFNR.
*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
*--- Perform to get Posting period - analyze
PERFORM POSTING_PERIOD.
*--- Perform to get Header: Material Document
PERFORM GET_MKPF_DATA.
*--- Perform to get Document Segment: Material
PERFORM GET_MSEG_DATA.
*--- Perform to get Purchasing Document Header
PERFORM GET_EKKO_DATA.
*--- Perform to get Purchasing Document Item
PERFORM GET_EKPO_DATA.
*--- Perform to get Material Group Descriptions
PERFORM GET_T023T_DATA.
*--- Perform to get Vendor Master
PERFORM GET_LFA1_DATA.
*--- Perform to get Accounting Document Header
PERFORM GET_BKPF_DATA.
*--- Perform to get Accounting Document Segment
PERFORM GET_BSEG_DATA.
*--- Perform to get the data into a IT table
PERFORM STORE_DATA.
*----------------------------------------------------------------------*
* END-OF-SELECTION *
*----------------------------------------------------------------------*
END-OF-SELECTION.
*--- Check if Selection Criteria is valid
IF V_FLAG = SPACE.
*--- Build Field Catalogs
PERFORM BUILD_FIELDCAT.
*--- Start List Viewer
PERFORM START_LIST_VIEWER.
ENDIF.
*&---------------------------------------------------------------------*
*& Form POSTING_PERIOD
*&---------------------------------------------------------------------*
* To get Posting period - analyze
*----------------------------------------------------------------------*
FORM POSTING_PERIOD .
*--- Perform to get posting from-date
PERFORM GET_DATE USING V_DAYS CHANGING V_FROMDATE .
*--- Perform to get no.of days of the month
PERFORM GET_NO_OF_DAYS.
*--- Perform to get posting to-date
PERFORM GET_DATE USING V_DAYS CHANGING V_TODATE.
*--- Perform to get posting period date
PERFORM GET_POSTING_PERIOD_DATE.
ENDFORM. " POSTING_PERIOD
*&---------------------------------------------------------------------*
*& Form GET_POSTING_DATE
*&---------------------------------------------------------------------*
* To get no.of days of the month
*----------------------------------------------------------------------*
FORM GET_NO_OF_DAYS.
DATA: LV_DATE TYPE D.
MOVE V_FROMDATE TO LV_DATE.
CALL FUNCTION 'HR_E_NUM_OF_DAYS_OF_MONTH'
EXPORTING
P_FECHA = LV_DATE
IMPORTING
NUMBER_OF_DAYS = V_DAYS.
ENDFORM. " GET_POSTING_DATE
*&---------------------------------------------------------------------*
*& Form GET_DATE
*&---------------------------------------------------------------------*
* To get Posting from-date
*----------------------------------------------------------------------*
FORM GET_DATE USING F_DAYS CHANGING F_DATE.
DATA: LV_DAYS(2) TYPE N.
MOVE F_DAYS TO LV_DAYS.
CONCATENATE P_SPBUP+0(4) P_SPBUP+4(2) LV_DAYS INTO F_DATE.
ENDFORM. " GET_DATE
*&---------------------------------------------------------------------*
*& Form GET_POSTING_PERIOD_DATE
*&---------------------------------------------------------------------*
* To get Posting period date
*----------------------------------------------------------------------*
FORM GET_POSTING_PERIOD_DATE.
*--- Perform to get the user defaults
PERFORM GET_USER_DEFAULT_SETTINGS.
CASE V_DATFM.
WHEN '1' OR '4'.
V_DS = '.'.
WHEN '2' OR '5'.
V_DS = '/'.
WHEN '3' OR '6'.
V_DS = '-'.
ENDCASE.
IF V_DATFM = '1'.
CONCATENATE V_FROMDATE+6(2) V_DS
V_FROMDATE+4(2) V_DS
V_FROMDATE+0(4)
INTO V_PDATE_LOW.
*--- Perform to get Internal Date Format For From Date
PERFORM DATE_TO_INTERNAL_FORMAT CHANGING V_PDATE_LOW.
CONCATENATE V_TODATE+6(2) V_DS
V_TODATE+4(2) V_DS
V_TODATE+0(4)
INTO V_PDATE_HIGH.
*--- Perform to get Internal Date Format For To Date
PERFORM DATE_TO_INTERNAL_FORMAT CHANGING V_PDATE_HIGH.
ENDIF.
IF V_DATFM = '2' OR
V_DATFM = '3'.
CONCATENATE V_FROMDATE+4(2) V_DS
V_FROMDATE+6(2) V_DS
V_FROMDATE+0(4)
INTO V_PDATE_LOW.
*--- Perform to get Internal Date Format For From Date
PERFORM DATE_TO_INTERNAL_FORMAT CHANGING V_PDATE_LOW.
CONCATENATE V_TODATE+4(2) V_DS
V_TODATE+6(2) V_DS
V_TODATE+0(4)
INTO V_PDATE_HIGH.
*--- Perform to get Internal Date Format For To Date
PERFORM DATE_TO_INTERNAL_FORMAT CHANGING V_PDATE_HIGH.
ELSEIF V_DATFM > 3.
CONCATENATE V_FROMDATE+0(4) V_DS
V_FROMDATE+4(2) V_DS
V_FROMDATE+6(2)
INTO V_PDATE_LOW.
*--- Perform to get Internal Date Format For From Date
PERFORM DATE_TO_INTERNAL_FORMAT CHANGING V_PDATE_LOW.
CONCATENATE V_TODATE+0(4) V_DS
V_TODATE+4(2) V_DS
V_TODATE+6(2)
INTO V_PDATE_HIGH.
*--- Perform to get Internal Date Format For To Date
PERFORM DATE_TO_INTERNAL_FORMAT CHANGING V_PDATE_HIGH.
ENDIF.
ENDFORM. " GET_POSTING_PERIOD_DATE
*&---------------------------------------------------------------------*
*& Form DATE_TO_INTERNAL_FORMAT
*&---------------------------------------------------------------------*
* To convert the date into internal format
*----------------------------------------------------------------------*
FORM DATE_TO_INTERNAL_FORMAT CHANGING F_DATE.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
DATE_EXTERNAL = F_DATE
* ACCEPT_INITIAL_DATE =
IMPORTING
DATE_INTERNAL = F_DATE
* EXCEPTIONS
* DATE_EXTERNAL_IS_INVALID = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
ENDIF.
ENDFORM. " DATE_TO_INTERNAL_FORMAT
*&---------------------------------------------------------------------*
*& Form GET_MKPF_DATA
*&---------------------------------------------------------------------*
* To get Header: Material Document
*----------------------------------------------------------------------*
FORM GET_MKPF_DATA.
*---- Select construct to get the Material Document
SELECT MBLNR MJAHR BLART BUDAT XBLNR
FROM MKPF
INTO TABLE IT_MKPF
WHERE MBLNR IN S_MBLNR
AND BLART = C_BLART
AND BUDAT >= V_PDATE_LOW
AND BUDAT <= V_PDATE_HIGH. IF SY-SUBRC <> 0.
*--- Message if no data exists with the selection criteria.
V_MESG = 'No data exists with the selection criteria'(001).
MESSAGE I002(Z_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ENDIF.
ENDFORM. " GET_MKPF_DATA
*&---------------------------------------------------------------------*
*& Form GET_MSEG_DATA
*&---------------------------------------------------------------------*
* To get Document Segment: Material
*----------------------------------------------------------------------*
FORM GET_MSEG_DATA.
*--- Check for a valid Material Document
IF NOT IT_MKPF[] IS INITIAL.
SELECT MBLNR MJAHR MATNR WERKS LIFNR EBELN GJAHR BUKRS
FROM MSEG
INTO TABLE IT_MSEG
FOR ALL ENTRIES IN IT_MKPF
WHERE MBLNR = IT_MKPF-MBLNR
AND MJAHR = IT_MKPF-MJAHR
AND WERKS IN S_WERKS
AND LIFNR IN S_LIFNR
AND EBELN IN S_EBELN.
IF SY-SUBRC <> 0.
*--- Message if no data exists with the selection criteria.
V_MESG = 'No data exists with the selection criteria'(001).
MESSAGE I002(Z_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ELSE.
DELETE ADJACENT DUPLICATES FROM IT_MSEG COMPARING MBLNR EBELN.
ENDIF.
ENDIF.
ENDFORM. " GET_MSEG_DATA
*&---------------------------------------------------------------------*
*& Form GET_EKKO_DATA
*&---------------------------------------------------------------------*
* To get Purchasing Document Header
*----------------------------------------------------------------------*
FORM GET_EKKO_DATA.
*--- Check for a valid Purchasing Document Header
IF NOT IT_MSEG[] IS INITIAL.
SELECT EBELN BUKRS AEDAT
FROM EKKO
INTO TABLE IT_EKKO
FOR ALL ENTRIES IN IT_MSEG
WHERE EBELN = IT_MSEG-EBELN
AND BUKRS = IT_MSEG-BUKRS
AND FRGKE = C_FRGKE.
IF SY-SUBRC <> 0.
*--- Message if no data exists with the selection criteria.
V_MESG = 'No data exists with the selection criteria'(001).
MESSAGE I002(Z_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ENDIF.
ENDIF.
ENDFORM. " GET_EKKO_DATA
*&---------------------------------------------------------------------*
*& Form GET_EKPO_DATA
*&---------------------------------------------------------------------*
* To get Purchasing Document Item
*----------------------------------------------------------------------*
FORM GET_EKPO_DATA.
*--- Check for a valid Purchasing Document Item
IF NOT IT_EKKO[] IS INITIAL.
SELECT EBELN TXZ01 MATNR BUKRS WERKS MATKL
FROM EKPO
INTO TABLE IT_EKPO
FOR ALL ENTRIES IN IT_EKKO
WHERE EBELN = IT_EKKO-EBELN
AND BUKRS = IT_EKKO-BUKRS
AND MATKL IN S_MATKL.
IF SY-SUBRC <> 0.
*--- Message if no data exists with the selection criteria.
V_MESG = 'No data exists with the selection criteria'(001).
MESSAGE I002(Z_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ENDIF.
ENDIF.
ENDFORM. " GET_EKPO_DATA
*&---------------------------------------------------------------------*
*& Form GET_T023T_DATA
*&---------------------------------------------------------------------*
* To get Material Group Descriptions
*----------------------------------------------------------------------*
FORM GET_T023T_DATA.
*---- Select construct to get the Material Grp Desc
IF NOT IT_EKPO[] IS INITIAL.
SELECT MATKL WGBEZ
FROM T023T
INTO TABLE IT_T023T
FOR ALL ENTRIES IN IT_EKPO
WHERE MATKL = IT_EKPO-MATKL
AND SPRAS = SY-LANGU.
IF SY-SUBRC <> 0.
*--- Message if no data exists with the selection criteria.
V_MESG = 'No data exists with the selection criteria'(001).
MESSAGE I002(Z_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ENDIF.
ENDIF.
ENDFORM. " GET_T023T_DATA
*&---------------------------------------------------------------------*
*& Form GET_LFA1_DATA
*&---------------------------------------------------------------------*
* To get Vendor Master
*----------------------------------------------------------------------*
FORM GET_LFA1_DATA.
*--- Check for a valid Vendor
IF NOT IT_MSEG[] IS INITIAL.
SELECT LIFNR NAME1
FROM LFA1
INTO TABLE IT_LFA1
FOR ALL ENTRIES IN IT_MSEG
WHERE LIFNR = IT_MSEG-LIFNR.
IF SY-SUBRC <> 0.
*--- Message if no data exists with the selection criteria.
V_MESG = 'No data exists with the selection criteria'(001).
MESSAGE I002(Z_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ENDIF.
ENDIF.
ENDFORM. " GET_LFA1_DATA
*&---------------------------------------------------------------------*
*& Form GET_BKPF_DATA
*&---------------------------------------------------------------------*
* To get Accounting Document Header
*----------------------------------------------------------------------*
FORM GET_BKPF_DATA.
DATA: BEGIN OF IT_MAT_DOCS OCCURS 0,
AWKEY LIKE BKPF-AWKEY,
END OF IT_MAT_DOCS.
DATA: LV_AWKEY LIKE BKPF-AWKEY.
*--- Check for a valid Material Document
IF NOT IT_MKPF[] IS INITIAL.
LOOP AT IT_MKPF.
CONCATENATE IT_MKPF-MBLNR IT_MKPF-MJAHR INTO LV_AWKEY.
IT_MAT_DOCS-AWKEY = LV_AWKEY.
APPEND IT_MAT_DOCS.
CLEAR IT_MAT_DOCS.
ENDLOOP.
ENDIF.
*--- Check for a valid Accounting Document Header
IF NOT IT_MAT_DOCS[] IS INITIAL.
DELETE ADJACENT DUPLICATES FROM IT_MAT_DOCS.
SELECT BUKRS BELNR GJAHR XBLNR AWKEY
FROM BKPF
INTO TABLE IT_BKPF
FOR ALL ENTRIES IN IT_MAT_DOCS
WHERE AWKEY = IT_MAT_DOCS-AWKEY
AND AWTYP = 'MKPF'.
IF SY-SUBRC <> 0.
*--- Message if no data exists with the selection criteria.
V_MESG = 'No data exists with the selection criteria'(001).
MESSAGE I002(Z_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ENDIF.
ENDIF.
ENDFORM. " GET_BKPF_DATA
*&---------------------------------------------------------------------*
*& Form GET_BSEG_DATA
*&---------------------------------------------------------------------*
* To get Accounting Document Segment
*----------------------------------------------------------------------*
FORM GET_BSEG_DATA.
*--- Check for a valid Accounting Document Segment
IF NOT IT_BKPF[] IS INITIAL.
SELECT BUKRS BELNR GJAHR BSCHL SHKZG DMBTR MATNR WERKS
FROM BSEG
INTO TABLE IT_BSEG
FOR ALL ENTRIES IN IT_BKPF
WHERE BUKRS = IT_BKPF-BUKRS
AND BELNR = IT_BKPF-BELNR
AND GJAHR = IT_BKPF-GJAHR
AND SHKZG = 'S'.
IF SY-SUBRC <> 0.
*--- Message if no data exists with the selection criteria.
V_MESG = 'No data exists with the selection criteria'(001).
MESSAGE I002(Z_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ENDIF.
ENDIF.
ENDFORM. " GET_BSEG_DATA
*&---------------------------------------------------------------------*
*& Form STORE_DATA
*&---------------------------------------------------------------------*
* To Display The Data
*----------------------------------------------------------------------*
FORM STORE_DATA.
DATA : LV_FLAG,
LV_ACC_IND,
LV_AWKEY LIKE BKPF-AWKEY.
CLEAR IT_MKPF.
*--- Loop through 'IT_MSEG' to format the report ouput table IT_ALV
LOOP AT IT_MKPF.
IT_ALV-MBLNR = IT_MKPF-MBLNR.
IT_ALV-XBLNR = IT_MKPF-XBLNR.
CLEAR IT_MSEG.
*--- Read to get the Header: Material Document
LOOP AT IT_MSEG WHERE MBLNR = IT_MKPF-MBLNR
AND GJAHR = IT_MKPF-MJAHR.
IT_ALV-BUDAT = IT_MKPF-BUDAT.
IT_ALV-WERKS = IT_MSEG-WERKS.
IT_ALV-LIFNR = IT_MSEG-LIFNR.
CLEAR IT_EKKO.
*--- Read to get the Document Segment: Material
READ TABLE IT_EKKO WITH KEY EBELN = IT_MSEG-EBELN.
IF SY-SUBRC = 0.
IT_ALV-AEDAT = IT_EKKO-AEDAT.
ENDIF.
CLEAR IT_EKPO.
*--- Loop is used to get Purchasing Document Item
LOOP AT IT_EKPO WHERE EBELN = IT_EKKO-EBELN
AND BUKRS = IT_MSEG-BUKRS
AND WERKS = IT_MSEG-WERKS.
IF LV_FLAG = SPACE.
IT_ALV-EBELN = IT_MSEG-EBELN.
IT_ALV-TXZ01 = IT_EKPO-TXZ01.
CLEAR IT_LFA1.
*--- Read to get the Vendor Master
READ TABLE IT_LFA1 WITH KEY LIFNR = IT_MSEG-LIFNR.
IF SY-SUBRC = 0.
IT_ALV-NAME1 = IT_LFA1-NAME1.
ENDIF.
CLEAR IT_T023T.
*--- Read to get the Material Group Descriptions
READ TABLE IT_T023T WITH KEY MATKL = IT_EKPO-MATKL.
IF SY-SUBRC = 0.
IT_ALV-WGBEZ = IT_T023T-WGBEZ.
ENDIF.
LV_FLAG = 'X'.
ENDIF.
CLEAR IT_BKPF.
CONCATENATE IT_MKPF-MBLNR IT_MKPF-MJAHR INTO LV_AWKEY.
CLEAR LV_ACC_IND.
*--- Read to get the Object Key
READ TABLE IT_BKPF WITH KEY AWKEY = LV_AWKEY.
IF SY-SUBRC = 0.
LV_ACC_IND = 'X'.
CLEAR IT_BSEG.
*--- Loop is used to get the Accounting Document Segment
LOOP AT IT_BSEG WHERE BELNR = IT_BKPF-BELNR
AND GJAHR = IT_BKPF-GJAHR
AND MATNR = IT_EKPO-MATNR
AND WERKS = IT_EKPO-WERKS.
IT_ALV-DMBTR = IT_ALV-DMBTR + IT_BSEG-DMBTR.
ENDLOOP.
ENDIF.
ENDLOOP.
IF LV_ACC_IND = 'X'.
APPEND IT_ALV.
CLEAR IT_ALV.
ENDIF.
CLEAR LV_FLAG.
ENDLOOP.
CLEAR V_BELNR.
CLEAR LV_FLAG.
*--- Fill output internal table
CLEAR IT_ALV.
ENDLOOP.
CLEAR IT_ALV.
ENDFORM. " STORE_DATA
*&---------------------------------------------------------------------*
*& Form GET_ACCT_DOC_NO
*&---------------------------------------------------------------------*
* To get Accounting Document no. for the Material document no
*----------------------------------------------------------------------*
FORM GET_ACCT_DOC_NO CHANGING F_BELNR.
DATA: LV_ACCDN LIKE ACCDN OCCURS 0 WITH HEADER LINE.
DATA: LV_AWORG LIKE ACCDN-AWORG.
MOVE IT_MKPF-MJAHR TO LV_AWORG.
CALL FUNCTION 'FI_DOCUMENT_FIND_FOR_INTERFACE'
EXPORTING
I_AWTYP = C_AWTYP
I_AWREF = IT_MKPF-MBLNR
I_AWORG = LV_AWORG
* I_AWSYS =
* I_BUKRS =
TABLES
E_ACCDN = LV_ACCDN
* I_ACCDN =
EXCEPTIONS
NO_DOC_FOUND = 1
OTHERS = 2
.
IF SY-SUBRC = 0.
READ TABLE LV_ACCDN INDEX 1.
IF SY-SUBRC = 0.
F_BELNR = LV_ACCDN-BELNR.
ENDIF.
ELSE.
F_BELNR = SPACE.
ENDIF.
ENDFORM. " GET_ACCT_DOC_NO
*&---------------------------------------------------------------------*
*& Form VALIDATE_WERKS
*&---------------------------------------------------------------------*
* To Validate the Plant
*----------------------------------------------------------------------*
FORM VALIDATE_WERKS.
DATA: LV_WERKS LIKE MSEG-WERKS. " Plant
*--- Check for a valid Plant
IF NOT S_WERKS[] IS INITIAL.
SELECT SINGLE WERKS
INTO LV_WERKS
FROM T001W
WHERE WERKS IN S_WERKS.
IF SY-SUBRC <> 0.
*--- Message to enter Valid Plant
V_MESG = 'Enter a Valid Plant'(002).
MESSAGE I002(Z_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_WERKS
*&---------------------------------------------------------------------*
*& Form VALIDATE_MBLNR
*&---------------------------------------------------------------------*
* To Validate the Number of Material Document
*----------------------------------------------------------------------*
FORM VALIDATE_MBLNR.
DATA: LV_MBLNR LIKE MKPF-MBLNR. " Number of material document
*--- Check for a valid Material Document
IF NOT S_MBLNR[] IS INITIAL.
*--- Select construct against the chk table for a No of material doc
SELECT SINGLE MBLNR
INTO LV_MBLNR
FROM MKPF
WHERE MBLNR IN S_MBLNR.
IF SY-SUBRC <> 0.
*--- Message to enter a valid Number of Material Document
MESSAGE I002(Z_MSGCLASS)
WITH 'Enter a valid Number of Material Document'(003).
V_FLAG = 'X'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_MBLNR
*&---------------------------------------------------------------------*
*& Form VALIDATE_EBELN
*&---------------------------------------------------------------------*
* To Validate the Purchasing Document Number
*----------------------------------------------------------------------*
FORM VALIDATE_EBELN.
DATA: LV_EBELN LIKE MSEG-EBELN. " Purchasing Document Number
*--- Check for a valid Purchasing document
IF NOT S_EBELN[] IS INITIAL.
*--- Select construct against the chk table for a Purchasing Document Number
SELECT SINGLE EBELN
INTO LV_EBELN
FROM EKKO
WHERE EBELN IN S_EBELN.
IF SY-SUBRC <> 0.
*--- Message to enter a Valid Purchase Order No
V_MESG = 'Enter a Valid Purchase Order No'(004).
MESSAGE I002(Z_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_EBELN
*&---------------------------------------------------------------------*
*& Form VALIDATE_MATKL
*&---------------------------------------------------------------------*
* To Validate the Material Group
*----------------------------------------------------------------------*
FORM VALIDATE_MATKL.
DATA: LV_MATKL LIKE EKPO-MATKL. " Material Group
*--- Check for a valid Material Group
IF NOT S_MATKL[] IS INITIAL.
*--- Select construct against the chk table for a Material Group
SELECT SINGLE MATKL
INTO LV_MATKL
FROM T023
WHERE MATKL IN S_MATKL.
IF SY-SUBRC <> 0.
*--- Message to enter a Valid Material Group
V_MESG = 'Enter a Valid Material Group'(005).
MESSAGE I002(Z_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_MATKL
*&---------------------------------------------------------------------*
*& Form VALIDATE_LIFNR
*&---------------------------------------------------------------------*
* To Validate the Vendor Number
*----------------------------------------------------------------------*
FORM VALIDATE_LIFNR.
DATA: LV_LIFNR LIKE LFA1-LIFNR. " Vendor Number
*--- Check for a valid Vendor
IF NOT S_LIFNR[] IS INITIAL.
*--- Select construct against the chk table for a Vendor Number
SELECT SINGLE LIFNR
INTO LV_LIFNR
FROM LFA1
WHERE LIFNR IN S_LIFNR.
IF SY-SUBRC <> 0.
*--- Message to enter a Valid Vendor Number
V_MESG = 'Enter a Valid Vendor Number'(006).
MESSAGE I002(ZL_MSGCLASS) WITH V_MESG.
V_FLAG = 'X'.
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_LIFNR
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
** To fill the Fieldcat
*----------------------------------------------------------------------*
FORM BUILD_FIELDCAT .
V_PGM = SY-REPID.
*---- Assigning the Fieldcat elements for the field Material Document No.
V_FIELD = 'MBLNR'.
V_TABLE_NAME = 'MKPF'.
V_DDICTXT = 'S'.
FIELDCAT_LN-SELTEXT_S = 'GRN No'(007).
PERFORM FIELDCAT_FILL USING V_FIELD V_TABLE_NAME V_DDICTXT.
*---- Assigning the Fieldcat elements for the field Posting date in the document .
V_FIELD = 'BUDAT'.
V_TABLE_NAME = 'MKPF'.
V_DDICTXT = 'S'.
FIELDCAT_LN-SELTEXT_S = 'DATE'(008).
PERFORM FIELDCAT_FILL USING V_FIELD V_TABLE_NAME V_DDICTXT.
*---- Assigning the Fieldcat elements for the field Reference document number(Inv No).
V_FIELD = 'XBLNR'.
V_TABLE_NAME = 'MKPF'.
V_DDICTXT = 'S'.
FIELDCAT_LN-SELTEXT_S = 'Invoice Number'(009).
PERFORM FIELDCAT_FILL USING V_FIELD V_TABLE_NAME V_DDICTXT.
*---- Assigning the Fieldcat elements for the field Purchasing Document Number.
V_FIELD = 'EBELN'.
V_TABLE_NAME = 'MSEG'.
V_DDICTXT = 'S'.
FIELDCAT_LN-SELTEXT_S = 'PO No'(010).
PERFORM FIELDCAT_FILL USING V_FIELD V_TABLE_NAME V_DDICTXT.
*---- Assigning the Fieldcat elements for the field Date on which the rec was created(Po Date).
V_FIELD = 'AEDAT'.
V_TABLE_NAME = 'EKKO'.
V_DDICTXT = 'S'.
FIELDCAT_LN-SELTEXT_S = 'PO Date'(011).
PERFORM FIELDCAT_FILL USING V_FIELD V_TABLE_NAME V_DDICTXT.
*---- Assigning the Fieldcat elements for the field Material Description in Short.
V_FIELD = 'TXZ01'.
V_TABLE_NAME = 'EKPO'.
V_DDICTXT = 'L'.
FIELDCAT_LN-SELTEXT_L = 'Material Description in Short'(012).
PERFORM FIELDCAT_FILL USING V_FIELD V_TABLE_NAME V_DDICTXT.
*---- Assigning the Fieldcat elements for the field GRN Value in Rs.
V_FIELD = 'DMBTR'.
V_TABLE_NAME = 'MSEG'.
V_DDICTXT = 'L'.
FIELDCAT_LN-SELTEXT_L = 'GRN Value in Rs.'(013).
PERFORM FIELDCAT_FILL USING V_FIELD V_TABLE_NAME V_DDICTXT.
*---- Assigning the Fieldcat elements for the field Material Group Description.
V_FIELD = 'WGBEZ'.
V_TABLE_NAME = 'T023T'.
V_DDICTXT = 'L'.
FIELDCAT_LN-SELTEXT_L = 'Material Group Description'(014).
PERFORM FIELDCAT_FILL USING V_FIELD V_TABLE_NAME V_DDICTXT.
*---- Assigning the Fieldcat elements for the field Vendor Name.
V_FIELD = 'NAME1'.
V_TABLE_NAME = 'LFA1'.
V_DDICTXT = 'L'.
FIELDCAT_LN-SELTEXT_L = 'Vendor Name'(015).
PERFORM FIELDCAT_FILL USING V_FIELD V_TABLE_NAME V_DDICTXT.
ENDFORM. " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& Form START_LIST_VIEWER
*&---------------------------------------------------------------------*
* To get ALV List Viewer
*----------------------------------------------------------------------*
FORM START_LIST_VIEWER.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
I_CALLBACK_PROGRAM = V_PGM
* I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
* I_STRUCTURE_NAME =
* IS_LAYOUT =
IT_FIELDCAT = FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = 'A'
* 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
* IR_SALV_LIST_ADAPTER =
* IT_EXCEPT_QINFO =
* I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_ALV
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDFORM. " START_LIST_VIEWER
*&---------------------------------------------------------------------*
*& Form FIELDCAT_FILL
*&---------------------------------------------------------------------*
* To set the properties of the FIELDCAT
*----------------------------------------------------------------------*
FORM FIELDCAT_FILL USING FIELD_VALUE
F_TABLE_NAME
F_DDICTXT.
ADD 1 TO V_COL_POS.
*----- Assigning the respective values to the Fieldcat
FIELDCAT_LN-REF_TABNAME = F_TABLE_NAME.
FIELDCAT_LN-FIELDNAME = FIELD_VALUE.
FIELDCAT_LN-DDICTXT = F_DDICTXT.
FIELDCAT_LN-KEY = SPACE.
FIELDCAT_LN-DO_SUM = SPACE.
FIELDCAT_LN-COL_POS = V_COL_POS.
FIELDCAT_LN-NO_OUT = SPACE.
FIELDCAT_LN-QFIELDNAME = SPACE.
FIELDCAT_LN-HOTSPOT = SPACE.
*----- Appending the values to Fieldcat
APPEND FIELDCAT_LN TO FIELDCAT.
CLEAR FIELDCAT_LN.
ENDFORM. " FIELDCAT_FILL
*&---------------------------------------------------------------------*
*& Form GET_USER_DEFAULT_SETTINGS
*&---------------------------------------------------------------------*
* To get the user default date settings
*----------------------------------------------------------------------*
FORM GET_USER_DEFAULT_SETTINGS.
*--- Select construct to get the user default date settings
SELECT SINGLE DATFM
INTO V_DATFM
FROM USR01
WHERE BNAME = SY-UNAME.
IF SY-SUBRC = 0.
*--- Do Nothing
ENDIF.
ENDFORM. " GET_USER_DEFAULT_SETTINGS
Monday, November 5, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment