Tuesday, 20 May 2014

MR Results using OOP

*&---------------------------------------------------------------------*
*& Report  ZMTR_READ_RESULT_OOP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZMTR_READ_RESULT_OOP .


TYPE-POOLS: SLIS.
TABLES : EANL,ERCH.

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

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME  TITLE TEXT-001.
SELECT-OPTIONS : S_INST FOR EANL-ANLAGE no-EXTENSION,                  "Installation number
                  S_CONT FOR ERCH-VERTRAG no-EXTENSION,                "Contarct
                  S_PORT FOR ERCH-PORTION no-EXTENSION,                "Portion
                  S_PART FOR ERCH-GPARTNER no-EXTENSION.               "Business Partner
SELECTION-SCREEN END OF BLOCK B1.

***********END OF SELECTION SCREEN*****************



TYPES : BEGIN OF TY_ERCH ,
        BELNR TYPE ERCH-BELNR,                           " Billing doc no
        GPARTNER  TYPE ERCH-GPARTNER,                    " Businee partner
        VERTRAG TYPE ERCH-VERTRAG,                       " Contract
        PORTION TYPE ERCH-PORTION,                       "Portinon
        ABLEINH  TYPE ERCH-ABLEINH,                      " Meter reading Unit
      END OF TY_ERCH.

TYPES : BEGIN OF TY_EABL,
        ABLBELNR TYPE EABL-ABLBELNR,                    " Internal MR doc num
        GERNR TYPE EABL-GERNR,                          " Device
        EQUNR TYPE EABL-EQUNR,                          " Euipment
        ZWNUMMER TYPE EABL-ZWNUMMER,                    "Register
        ADAT TYPE EABL-ADAT,                            "  MR date
        ADATSOLL TYPE EABL-ADATSOLL,                    "  Scheduled MRD
        V_ZWSTAND TYPE EABL-V_ZWSTAND,                  " Pd MR Reading
        N_ZWSTAND TYPE  EABL-N_ZWSTAND,                 "Pd MR Reading
      END OF TY_EABL.

TYPES : BEGIN OF TY_EABLG,
        ABLBELNR TYPE EABLG-ABLBELNR,                    " Internal MR doc num
        ANLAGE TYPE  EABLG-ANLAGE,                       " Installation
        ABLESGR TYPE  EABLG-ABLESGR,                     " MR Reason
        ABLEINH TYPE EABLG-ABLEINH,                      " MR Unit
        END OF TY_EABLG.

TYPES : BEGIN OF TY_EVER,
        VERTRAG TYPE EVER-VERTRAG,                      "Contract
        ANLAGE TYPE EVER-ANLAGE,                        " Installation
 END OF TY_EVER.

TYPES : BEGIN OF TY_FINAL,
       PORTION TYPE ERCH-PORTION,                              "Portion
       MRUNIT TYPE ERCH-ABLEINH,                               "MR Unit
       BP TYPE GPARTNER,                                       "Business Partner
       CONTRACT TYPE VERTRAG,                                  "Contract
       INSTALLATION TYPE ANLAGE,                               "Installation
       DEVICE TYPE GERAET,                                     "Device
       EQUIPMENT TYPE EQUNR,                                   "Equipment
       REGISTER TYPE E_ZWNUMMER,                               "Register
       MR_DATE TYPE ADAT,                                      "Meter Reading date
       SCHEDULED_MRD TYPE ADATSOLL,                            "Scheduled MR Date
       METER_REASON TYPE ABLESGR,                              "MR REason
       METER_READING TYPE READINGRESULT,                       "Metre Reading
 END OF TY_FINAL.



*****************Internal Table Decleration********************
DATA : IT_EVER TYPE TABLE OF TY_EVER.
DATA  : IT_ERCH TYPE TABLE OF  TY_ERCH,                          "Billing Doc. Data Internal Table
        WA_ERCH TYPE TY_ERCH.                                    "Billing Doc. Data Work area
DATA  : IT_EABL TYPE TABLE OF  TY_EABL,                          " MR Document Internal Table
        WA_EABL TYPE TY_EABL.                                    " MR Document Work area
DATA  : IT_EABLG TYPE TABLE OF  TY_EABLG,                        " MR Reasons in MR Document Internal Table
        WA_EABLG TYPE TY_EABLG.                                  " MR Reasons in MR Document Work area
DATA : IT_FINAL TYPE TABLE OF TY_FINAL,                          " Final Internal Table
       WA_FINAL TYPE TY_FINAL.                                   " Final Work area


DATA  : IT_FCAT TYPE TABLE OF LVC_S_FCAT,
        WA_FCAT TYPE LVC_S_FCAT.

****************End Of Decleration******************************

DATA : ALV_GRID TYPE REF TO CL_GUI_ALV_GRID,
      ALV_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER.



START-OF-SELECTION.

PERFORM GET_DATA.
PERFORM FCAT.

CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_9000 OUTPUT.
  SET PF-STATUS 'ZMENU'.
  SET TITLEBAR 'ZTITTLE'.

ENDMODULE.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.
IF SY-UCOMM  = 'BACK'.
LEAVE TO SCREEN 0.
ENDIF.
ENDMODULE.                 " USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM DISPLAY .


CREATE OBJECT ALV_CONT
  EXPORTING
*    PARENT                      =
    CONTAINER_NAME              = 'ALV_CONTAINER'
*    STYLE                       =
*    LIFETIME                    = lifetime_default
*    REPID                       =
*    DYNNR                       =
*    NO_AUTODEF_PROGID_DYNNR     =
*  EXCEPTIONS
*    CNTL_ERROR                  = 1
*    CNTL_SYSTEM_ERROR           = 2
*    CREATE_ERROR                = 3
*    LIFETIME_ERROR              = 4
*    LIFETIME_DYNPRO_DYNPRO_LINK = 5
*    others                      = 6
    .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CREATE OBJECT ALV_GRID
  EXPORTING
*    I_SHELLSTYLE      = 0
*    I_LIFETIME        =
    I_PARENT          = ALV_CONT
*    I_APPL_EVENTS     = space
*    I_PARENTDBG       =
*    I_APPLOGPARENT    =
*    I_GRAPHICSPARENT  =
*    I_NAME            =
*    I_FCAT_COMPLETE   = SPACE
*  EXCEPTIONS
*    ERROR_CNTL_CREATE = 1
*    ERROR_CNTL_INIT   = 2
*    ERROR_CNTL_LINK   = 3
*    ERROR_DP_CREATE   = 4
*    others            = 5
    .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

if it_final is NOT INITIAL .
CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
  EXPORTING
*    I_BUFFER_ACTIVE               =
*    I_BYPASSING_BUFFER            =
*    I_CONSISTENCY_CHECK           =
*    I_STRUCTURE_NAME              =
*    IS_VARIANT                    =
*    I_SAVE                        =
    I_DEFAULT                     = 'X'
**    IS_LAYOUT                     = IT_FCAT
*    IS_PRINT                      =
*    IT_SPECIAL_GROUPS             =
*    IT_TOOLBAR_EXCLUDING          =
*    IT_HYPERLINK                  =
*    IT_ALV_GRAPHICS               =
*    IT_EXCEPT_QINFO               =
*    IR_SALV_ADAPTER               =
  CHANGING
    IT_OUTTAB                     = IT_FINAL
    IT_FIELDCATALOG               = IT_FCAT
*    IT_SORT                       =
*    IT_FILTER                     =
*  EXCEPTIONS
*    INVALID_PARAMETER_COMBINATION = 1
*    PROGRAM_ERROR                 = 2
*    TOO_MANY_LINES                = 3
*    others                        = 4
        .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
else.
  MESSAGE text-002 TYPE 'I'.
  ENDIF.
ENDFORM.                    " DISPLAY
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_DATA .
IF S_INST IS NOT INITIAL .


    SELECT VERTRAG
             ANLAGE
             FROM EVER
             INTO TABLE IT_EVER
             WHERE ANLAGE IN S_INST .
    IF S_INST IS NOT INITIAL AND S_CONT IS NOT INITIAL.
      CLEAR IT_EVER.
      SELECT  VERTRAG
        ANLAGE
        FROM EVER
        INTO TABLE IT_EVER
        WHERE ANLAGE  IN S_INST AND VERTRAG IN S_CONT.

    ENDIF.
    IF IT_EVER IS NOT INITIAL .
      SELECT  ABLBELNR
              ANLAGE          " INSTALLATION
              ABLESGR         " MR REASON
              ABLEINH
              FROM EABLG
              INTO TABLE IT_EABLG
             FOR ALL ENTRIES IN IT_EVER
              WHERE ANLAGE = IT_EVER-ANLAGE.
****            WHERE ANLAGE IN S_INST AND ABLESGR = '01'.
    ENDIF.
    IF  IT_EABLG IS NOT INITIAL.

      SELECT ABLBELNR
              GERNR
              EQUNR
              ZWNUMMER
              ADAT
              ADATSOLL
              V_ZWSTAND
              N_ZWSTAND
              FROM EABL
              INTO TABLE IT_EABL
              FOR ALL ENTRIES IN IT_EABLG
              WHERE ABLBELNR = IT_EABLG-ABLBELNR.

    ENDIF.
    IF IT_EVER IS NOT INITIAL.
      SELECT BELNR
           GPARTNER
           VERTRAG
           PORTION
           ABLEINH
           FROM ERCH
           INTO TABLE IT_ERCH FOR ALL ENTRIES IN IT_EVER
            WHERE VERTRAG = IT_EVER-VERTRAG
            AND SIMULATION = '' .
    ENDIF.
  ELSEIF S_CONT IS NOT INITIAL.
    SELECT  VERTRAG
            ANLAGE
            FROM EVER
            INTO TABLE IT_EVER
            WHERE VERTRAG IN S_CONT.
    IF IT_EVER IS NOT INITIAL.
      PERFORM MR_DATA.
    ENDIF.


    SELECT BELNR
         GPARTNER
         VERTRAG
         PORTION
         ABLEINH
         FROM ERCH
         INTO TABLE IT_ERCH FOR ALL ENTRIES IN IT_EVER
          WHERE VERTRAG = IT_EVER-VERTRAG
          AND SIMULATION = '' .
  ENDIF.


***********   portion  ***************************
  IF S_PORT IS NOT INITIAL.
    SELECT BELNR
           GPARTNER
           VERTRAG
           PORTION
           ABLEINH
           FROM ERCH
           INTO TABLE IT_ERCH                                                                                                                                               "#EC CI_NOFIELD
           WHERE PORTION IN S_PORT.


     IF S_PORT IS NOT INITIAL AND S_PART IS NOT INITIAL .
      CLEAR it_erch.
      SELECT BELNR
         GPARTNER
         VERTRAG
         PORTION
         ABLEINH                                                                                                                                                                   "#EC CI_NOFIELD
         FROM ERCH
         INTO TABLE IT_ERCH
         WHERE PORTION IN S_PORT
         AND GPARTNER IN S_PART.
    ENDIF.

    IF S_PORT IS NOT INITIAL AND S_INST IS NOT INITIAL.
      SELECT BELNR
       GPARTNER
       VERTRAG
       PORTION
       ABLEINH
       FROM ERCH
       INTO TABLE IT_ERCH FOR ALL ENTRIES IN IT_EVER
        WHERE VERTRAG = IT_EVER-VERTRAG
        AND SIMULATION = ''
        AND PORTION IN S_PORT
        AND GPARTNER IN S_PART.
    ENDIF.

    CLEAR :IT_EVER,IT_EABLG,IT_EABL.
    IF  IT_ERCH IS NOT INITIAL .
      SELECT VERTRAG
             ANLAGE
             FROM EVER
             INTO TABLE IT_EVER
             FOR ALL ENTRIES IN IT_ERCH WHERE VERTRAG = IT_ERCH-VERTRAG.
    ENDIF.
    IF IT_EVER IS NOT INITIAL.
      PERFORM MR_DATA.
    ENDIF.
  ELSEIF S_PART IS NOT INITIAL"""""""""" partnter

    CLEAR :it_ever,it_eablg,it_eabl.
    SELECT BELNR
          GPARTNER
          VERTRAG
          PORTION
          ABLEINH
          FROM ERCH
          INTO TABLE IT_ERCH
          WHERE GPARTNER IN S_PART.
                                                                                                                                              ""#EC CI_NOFIELD
    IF  IT_ERCH IS NOT INITIAL .
      SELECT VERTRAG
             ANLAGE FROM EVER
             INTO TABLE IT_EVER
             FOR ALL ENTRIES IN IT_ERCH
             WHERE VERTRAG = IT_ERCH-VERTRAG.
    ENDIF.

    IF IT_EVER IS NOT INITIAL.
      PERFORM MR_DATA.
    ENDIF.
  ENDIF.





  LOOP AT  IT_EABL INTO WA_EABL.


    WA_FINAL-DEVICE = WA_EABL-GERNR.
    WA_FINAL-EQUIPMENT = WA_EABL-EQUNR.
    WA_FINAL-REGISTER = WA_EABL-ZWNUMMER.
    WA_FINAL-MR_DATE =  WA_EABL-ADAT.
    WA_FINAL-SCHEDULED_MRD = WA_EABL-ADATSOLL.
    WA_FINAL-METER_READING = WA_EABL-V_ZWSTAND + WA_EABL-N_ZWSTAND.



    READ TABLE IT_EABLG INTO WA_EABLG WITH KEY ABLBELNR = WA_EABL-ABLBELNR.
    WA_FINAL-INSTALLATION = WA_EABLG-ANLAGE.
    WA_FINAL-METER_REASON = WA_EABLG-ABLESGR.
    WA_FINAL-MRUNIT  = WA_EABLG-ABLEINH.



    READ TABLE IT_ERCH INTO WA_ERCH WITH KEY ABLEINH = WA_EABLG-ABLEINH.

    WA_FINAL-PORTION = WA_ERCH-PORTION.
    WA_FINAL-BP = WA_ERCH-GPARTNER.
    WA_FINAL-CONTRACT = WA_ERCH-VERTRAG.



    APPEND WA_FINAL TO IT_FINAL.
    CLEAR WA_FINAL.

  ENDLOOP.
ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  MR_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM MR_DATA .
CLEAR : it_eablg,it_eabl.
  SELECT ABLBELNR
         ANLAGE          " INSTALLATION
         ABLESGR         " MR REASON
         ABLEINH         " MR UNIT
          FROM EABLG
         INTO TABLE IT_EABLG
         FOR ALL ENTRIES IN IT_EVER
         WHERE ANLAGE = IT_EVER-ANLAGE ."AND ABLESGR = '01'.

  IF  IT_EABLG IS NOT INITIAL.
    SELECT ABLBELNR                                                   " INTERNAL MR ID
           GERNR                                                      "DEVICE
           EQUNR                                                      "EUIPMENT NUMBER
           ZWNUMMER                                                   "REGISTER
           ADAT                                                       " MR DATE
           ADATSOLL                                                   " SCHEDULED MR DATE
           V_ZWSTAND                                                  " PD METRE READING
           N_ZWSTAND                                                  " DEC METER READING
           FROM EABL INTO TABLE IT_EABL
           FOR ALL ENTRIES IN IT_EABLG
           WHERE ABLBELNR = IT_EABLG-ABLBELNR.
  ENDIF.
ENDFORM.                    " MR_DATA
*&---------------------------------------------------------------------*
*&      Form  FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FCAT .

  WA_FCAT-COL_POS = '1'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
*  WA_FCAT-REF_TABNAME = 'ERCH'.
  WA_FCAT-FIELDNAME = 'PORTION'.
  WA_FCAT-SCRTEXT_M = 'PORTION'.


  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.


  WA_FCAT-COL_POS = '2'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
  WA_FCAT-FIELDNAME = 'MRUNIT'.
  WA_FCAT-SCRTEXT_M = 'MR UNIT'.

  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = '3'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
  WA_FCAT-REF_TABLE = 'ERCH'.
  WA_FCAT-FIELDNAME = 'BP'.
  WA_FCAT-SCRTEXT_M = 'BUSPAR'
.

  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = '4'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
  WA_FCAT-REF_TABLE = 'ERCH'.
  WA_FCAT-FIELDNAME = 'CONTRACT'.
  WA_FCAT-SCRTEXT_M = 'CONTRACT'.

  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = '5'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
  WA_FCAT-REF_TABLE = 'DBERCHZ1'.
  WA_FCAT-FIELDNAME = 'INSTALLATION'.
  WA_FCAT-SCRTEXT_M = 'INSTALLATION NUM'.
  WA_FCAT-OUTPUTLEN = 15.

  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.


  WA_FCAT-COL_POS = '6'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
  WA_FCAT-REF_TABLE = 'DBERCHZ3'.
  WA_FCAT-FIELDNAME = 'DEVICE'.
  WA_FCAT-SCRTEXT_M = 'DEVICE'.
  WA_FCAT-OUTPUTLEN = 18.


  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = '7'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
  WA_FCAT-REF_TABLE = 'DBERCHZ3'.
  WA_FCAT-FIELDNAME = 'EQUIPMENT'.
  WA_FCAT-SCRTEXT_M = 'EQUIPMENT'.
  WA_FCAT-OUTPUTLEN = 18.


  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.


  WA_FCAT-COL_POS = '8'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
  WA_FCAT-REF_TABLE = 'DBERCHZ3'.
  WA_FCAT-FIELDNAME = 'REGISTER'.
  WA_FCAT-SCRTEXT_M = 'REGISTER'.


  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = '9'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
  WA_FCAT-REF_TABLE = 'EABL'.
  WA_FCAT-FIELDNAME = 'MR_DATE'.
  WA_FCAT-SCRTEXT_M = 'MR DATE'.


  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = '10'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
  WA_FCAT-REF_TABLE = 'EABL'.
  WA_FCAT-FIELDNAME = 'SCHEDULED_MRD'.
  WA_FCAT-SCRTEXT_M = 'SHEDULE MRDATE'.


  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS = '11'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
  WA_FCAT-REF_TABLE = 'DBERCHZ3'.
  WA_FCAT-FIELDNAME = 'METER_REASON'.
  WA_FCAT-SCRTEXT_M = 'MR REASON'.

  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.



  WA_FCAT-COL_POS = '12'.
  WA_FCAT-TABNAME = 'IT_FINAL'.
  WA_FCAT-REF_TABLE = 'DBERCHZ3'.
  WA_FCAT-FIELDNAME = 'METER_READING'.
  WA_FCAT-SCRTEXT_M = 'METER READ'.


  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

ENDFORM.                    " FCAT
*&---------------------------------------------------------------------*
*&      Module  CREATE_OBJ  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE CREATE_OBJ OUTPUT.
PERFORM DISPLAY.
ENDMODULE.                 " CREATE_OBJ  OUTPUT

No comments:

Post a Comment