Skip to Content

  Here is the Sample code to display the ALV Grid in the vertical format .

*&———————————————————————*

*& Report  ZPMR0_TEST

*&

*&———————————————————————*

*&

*&

*&———————————————————————*

REPORT  ZPMR0_TEST.

TYPE-POOLS: slis.                      ” ALV Global types

TABLES : qmih .

DATA:  X TYPE C,

      C_EQUNR TYPE EQKT-EQUNR,

      C1_EQUNR TYPE EQKT-EQUNR,

      C2_EQUNR TYPE EQKT-EQUNR.

“”””””””””””””””””””””””””””””””””””””””””””NO OF COUNT”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””

DATA : BREAKDOWN TYPE I.

“””””””””””””””””””””””””””””””””””””””””””””MTTR CALCULATIONS””””””””””””””””””””””””””””””””””””””””””””””””””””

DATA : MTTR_DIFF TYPE TVRO-FAHZTD,

       V_TOTAL(8) TYPE N,

       HH TYPE HOURS,

       MM TYPE MINUTES,

       SS TYPE SECONDS,

       SEC TYPE SECONDS,

       TOTAL_SEC TYPE SECONDS,

       MTTR_TOTAL(10) TYPE C,

       MTTR_SEC(2) TYPE N,

       MTTR_HOURS(8) TYPE C,

       MTTR_MIN1 TYPE MINUTES,

       MTTR_FINAL_MIN(2) TYPE N,

       FINAL_MTTR(15) TYPE C.

“”””””””””””””””””””””””””””””””””””””””””””””MTBR CALCULTATIONS”””””””””””””””””””””””””””””””””””””””””””””””””

DATA : MTBR_DIFF TYPE I,

       MTBR_TOTAL(10) TYPE C,

       DAYS_TOTAL(8) TYPE N,

       MTBR_HOURS(8) TYPE C,

       MTBR_MIN TYPE MINUTES,

       MTBR_SEC(2) TYPE N,

       MTBR_FINAL_MIN(2) TYPE N,

       C_MTBR(15) TYPE C.

“”””””””””””””””””””””””””””””””””””””””””””””””MTTBR TOTAL DAYS “”””””””””””””””””””””””””””””””””””””””””””””””

DATA : MTBR_TOTAL_DAYS(5) TYPE N,

       ONE_DAY TYPE I,

       ONE_DAY_SEC TYPE I.

TYPES : BEGIN OF TY_FINAL,

          EQUNR TYPE EQKT-EQUNR,   “EQUIPMENT NUMBER

          EQKTU TYPE EQKT-EQKTU,   “EQUIPMENT DESCRIPTION

          IWERK TYPE QMIH-IWERK,   “Planning Plant

          MSAUS TYPE QMIH-MSAUS,    “BREAKDOWN INDICATOR

          AUSVN TYPE QMIH-AUSVN,   “START DATE

          AUSBS TYPE QMIH-AUSBS,   “END DATE

          AUZTV TYPE QMIH-AUZTV,   “START TIME

          AUZTB TYPE QMIH-AUZTB,   “END TIME

          COUNT TYPE I,

          STARTDATE TYPE QMIH-AUSVN,

          ENDDATE TYPE QMIH-AUSBS,

          MTTR(15) TYPE C,

          MTBR(15) TYPE C,

          TOTAL_SEC TYPE SECONDS,

        END OF TY_FINAL.

SELECT-OPTIONS: SO_EQUNR FOR QMIH-EQUNR OBLIGATORY.

SELECT-OPTIONS: SO_AUSVN FOR QMIH-AUSVN OBLIGATORY,

                SO_IWERK FOR QMIH-IWERK.

DATA gt_data TYPE STANDARD TABLE OF ty_final WITH HEADER LINE.

*———————————————————————*

  1. INITIALIZATION.

*———————————————————————*

START-OF-SELECTION.

  PERFORM f_read_data.

  PERFORM f_display_data.

*———————————————————————*

*      Form f_read_data

*———————————————————————*

FORM f_read_data.

*  BREAK-POINT.

SELECT EQKT~EQUNR

         EQKT~EQKTU

         QMIH~IWERK

         QMIH~MSAUS

         QMIH~AUSVN

         QMIH~AUSBS

         QMIH~AUZTV

         QMIH~AUZTB

         INTO TABLE gt_data

         FROM QMIH

         INNER JOIN EQKT ON QMIH~EQUNR = EQKT~EQUNR

         WHERE QMIH~EQUNR IN SO_EQUNR

         AND IWERK IN SO_IWERK

         AND AUSVN IN SO_AUSVN .

   IF SY-SUBRC NE 0.

    MESSAGE E001(00) WITH ‘No Values for This Equipment Number’.

  ENDIF .

  CLEAR TOTAL_SEC.

  CLEAR BREAKDOWN.

  CLEAR DAYS_TOTAL.

  ONE_DAY = ’24’.

  ONE_DAY_SEC = ONE_DAY * 3600 .

  LOOP AT gt_data .

    PERFORM CALCULATION.

  ENDLOOP.

*  WA_FINAL-STARTDATE = SO_AUSVN-LOW.

*  WA_FINAL-ENDDATE = SO_AUSVN-HIGH.

  SORT gt_data DESCENDING BY EQUNR COUNT MSAUS .

  DELETE ADJACENT DUPLICATES FROM gt_data COMPARING EQUNR IWERK.

  SORT gt_data ASCENDING BY EQUNR.

  LOOP AT gt_data .

    PERFORM FINAL_CALCULATION.

  ENDLOOP.

  1. ENDFORM.                               ” F_READ_DATA

*———————————————————————*

*      Form F_DISPLAY_DATA

*———————————————————————*

FORM f_display_data.

  DATA:

    l_column TYPE sy-tabix,

    lp_struct TYPE REF TO data,

    lp_table TYPE REF TO data,      ” Pointer to dynamic table

    ls_lvc_cat TYPE lvc_s_fcat,

    lt_lvc_cat TYPE lvc_t_fcat,       ” Field catalog

    lt_fcat TYPE slis_t_fieldcat_alv,  ” Field catalog

    ls_fieldcat TYPE slis_fieldcat_alv,

    lt_fieldcat TYPE slis_t_fieldcat_alv,  ” Field catalog

    ls_layout TYPE slis_layout_alv.

  FIELD-SYMBOLS :

    <header>       TYPE ANY,

    <field_header> TYPE ANY,

    <field_qmih>  TYPE ANY,

    <lt_data>      TYPE table.         ” Data to display

  ls_lvc_cat-fieldname = ‘COLUMNTEXT’.

  ls_lvc_cat-ref_table = ‘LVC_S_DETA’.

  APPEND ls_lvc_cat TO lt_lvc_cat.

  ls_fieldcat-fieldname = ‘COLUMNTEXT’.

  ls_fieldcat-ref_tabname = ‘LVC_S_DETA’.

  ls_fieldcat-key  = ‘X’.

  APPEND ls_fieldcat TO lt_fieldcat.

  DESCRIBE TABLE gt_data.

  DO sy-tfill TIMES.

*   For each line, a column ‘VALUEx’ is created in the fieldcatalog

*   Build Fieldcatalog

    WRITE sy-index TO ls_lvc_cat-fieldname LEFT-JUSTIFIED.

    CONCATENATE ‘VALUE’ ls_lvc_cat-fieldname

           INTO ls_lvc_cat-fieldname.

    ls_lvc_cat-ref_field = ‘VALUE’.

    ls_lvc_cat-ref_table = ‘LVC_S_DETA’.

    APPEND ls_lvc_cat TO lt_lvc_cat.

*   Build Fieldcatalog

    CLEAR ls_fieldcat.

    ls_fieldcat-fieldname = ls_lvc_cat-fieldname.

    ls_fieldcat-ref_fieldname = ‘VALUE’.

    ls_fieldcat-ref_tabname = ‘LVC_S_DETA’.

    APPEND ls_fieldcat TO lt_fieldcat.

  ENDDO.

* Create internal table

  CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING it_fieldcatalog = lt_lvc_cat

    IMPORTING ep_table = lp_table.

  ASSIGN lp_table->* TO <lt_data>.

* Create structure = structure of the internal table

  CREATE DATA lp_struct LIKE LINE OF <lt_data>.

  ASSIGN lp_struct->* TO <header>.

* Create field catalog from dictionary structure

   ls_FIELDCAT-FIELDNAME  = ‘EQUNR’.

  ls_FIELDCAT-SELTEXT_M  = ‘Equipment Number’.

  ls_FIELDCAT-REF_TABNAME = ‘EQKT’.

  ls_FIELDCAT-COL_POS    = 0.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘EQKTU’.

  ls_FIELDCAT-SELTEXT_M  = ‘Equipment Description’.

  ls_FIELDCAT-REF_TABNAME = ‘EQKT’.

  ls_FIELDCAT-COL_POS    = 1.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘IWERK’.

  ls_FIELDCAT-SELTEXT_M  = ‘Plant’.

  ls_FIELDCAT-REF_TABNAME = ‘QMIH’.

  ls_FIELDCAT-COL_POS    = 2.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘MSAUS’.

  ls_FIELDCAT-SELTEXT_M  = ‘Breakdown Indicator’.

  ls_FIELDCAT-REF_TABNAME = ‘QMIH’.

  ls_FIELDCAT-COL_POS    = 3.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘STARTDATE’.

  ls_FIELDCAT-SELTEXT_M  = ‘Start of Malfunction(D)’.

  ls_FIELDCAT-COL_POS    = 4.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘ENDDATE’.

  ls_FIELDCAT-SELTEXT_M  = ‘End of Malfunction(D)’.

  ls_FIELDCAT-COL_POS    = 5.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘STARTDATE’.

  ls_FIELDCAT-SELTEXT_M  = ‘Start of Malfunction(T)’.

  ls_FIELDCAT-COL_POS    = 6.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘ENDDATE’.

  ls_FIELDCAT-SELTEXT_M  = ‘End of Malfunction(T)’.

  ls_FIELDCAT-COL_POS    = 7.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘COUNT’.

  ls_FIELDCAT-SELTEXT_M  = ‘Breakdowns’.

  ls_FIELDCAT-COL_POS    = 8.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘MTTR’.

  ls_FIELDCAT-SELTEXT_L  = ‘Mean Time to Repair in Hours’.

  ls_FIELDCAT-COL_POS    = 9.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘MTBR’.

  ls_FIELDCAT-SELTEXT_L  = ‘Mean Time to Breakdown in Hours’.

  ls_FIELDCAT-COL_POS    = 10.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  DESCRIBE TABLE lt_fcat.

* Fill the internal to display <lt_data>

  DO sy-tfill TIMES.

    IF sy-index = 1.

      READ TABLE lt_fcat INTO ls_fieldcat INDEX 1.

      IF ls_fieldcat-fieldname = ‘MANDT’.

*       If 1st column is MANDT, it’s not displayed

        CONTINUE.

      ENDIF.

    ENDIF.

*   For each field of GT_DATA

    ASSIGN COMPONENT 1 OF STRUCTURE <header> TO <field_header>.

    IF sy-subrc NE 0. EXIT .ENDIF.

    READ TABLE lt_fcat INTO ls_fieldcat INDEX sy-index.

*   Fill 1st column

    <field_header> = ls_fieldcat-seltext_m.

    IF <field_header> IS INITIAL.

      <field_header> = ls_fieldcat-fieldname.

    ENDIF.

    LOOP AT gt_data.

      l_column = sy-tabix + 1.

      ASSIGN COMPONENT sy-index OF STRUCTURE gt_data TO <field_qmih>.

      IF sy-subrc NE 0. EXIT .ENDIF.

      ASSIGN COMPONENT l_column OF STRUCTURE <header> TO <field_header>.

      IF sy-subrc NE 0. EXIT .ENDIF.

      WRITE <field_qmih> TO <field_header> LEFT-JUSTIFIED.

    ENDLOOP.

    APPEND <header> TO <lt_data>.

  ENDDO.

  ls_layout-colwidth_optimize = ‘X’.

  ls_layout-no_colhead = ‘X’.

  ls_layout-zebra = ‘X’.

  CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’

       EXPORTING

            is_layout   = ls_layout

            it_fieldcat = lt_fieldcat

       TABLES

            t_outtab    = <lt_data>.

  1. ENDFORM.                               ” F_DISPLAY_DATA

*&———————————————————————*

*&      Form CALCULATION

*&———————————————————————*

*       text

*———————————————————————-*

*  –> p1        text

*  <– p2        text

*———————————————————————-*

FORM CALCULATION .

*if equipment number changes variables are cleared

  X = ( SY-TABIX MOD 2 ).

  IF X = 0 .

    C2_EQUNR = gt_data-EQUNR.

  ELSE.

    C1_EQUNR = gt_data-EQUNR.

  ENDIF.

  IF C1_EQUNR NE C2_EQUNR AND SY-TABIX NE 1.

    CLEAR TOTAL_SEC.

    CLEAR BREAKDOWN.

    CLEAR DAYS_TOTAL.

  ENDIF.

  IF gt_data-MSAUS = ‘X’ .

    BREAKDOWN = BREAKDOWN + 1.

  ENDIF.

*  IF SY-TABIX = ‘1’ .

*    V_STARTDATE = WA_FINAL-AUSVN.

*  ENDIF .

  IF gt_data-AUSVN EQ ‘00000000’ OR

     gt_data-AUSBS EQ ‘00000000’ OR

     gt_data-AUZTV EQ ‘000000’ OR

     gt_data-AUZTB EQ ‘000000’ .

    V_TOTAL = ‘0’.

  ELSEIF gt_data-MSAUS = ‘X’ .

*DIFFERENCE IN HOURS

    CALL FUNCTION ‘SD_CALC_DURATION_FROM_DATETIME’

      EXPORTING

        I_DATE1                = gt_data-AUSVN

        I_TIME1                = gt_data-AUZTV

        I_DATE2                = gt_data-AUSBS

        I_TIME2                = gt_data-AUZTB

     IMPORTING

       E_TDIFF                = MTTR_DIFF

*   E_DATE2_EARLY          =

     EXCEPTIONS

       INVALID_DATETIME       = 1

       OTHERS                 = 2

              .

    IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

*FOR MTBR IN DAYS.

“”””””””””””””””””””””””””””””””””””””””””CALCULATING HH:MM:SS TO SECONDS”””””””””””””””””””””””””””””””””””””””

    V_TOTAL = MTTR_DIFF.

    HH = V_TOTAL+0(4) .

    MM = V_TOTAL+4(2).

    SS = V_TOTAL+6(2).

    SEC = HH * 60 * 60 + MM * 60 + SS.

    TOTAL_SEC = TOTAL_SEC + SEC.

  ENDIF.

  gt_data-TOTAL_SEC = TOTAL_SEC.

  gt_data-COUNT = BREAKDOWN.

  gt_data-STARTDATE = SO_AUSVN-LOW.

  gt_data-ENDDATE = SO_AUSVN-HIGH.

  MODIFY gt_data INDEX SY-TABIX.

  1. ENDFORM.                    ” CALCULATION

*&———————————————————————*

*&      Form FINAL_CALCULATION

*&———————————————————————*

*       text

*———————————————————————-*

*  –> p1        text

*  <– p2        text

*———————————————————————-*

FORM FINAL_CALCULATION .

IF gt_data-TOTAL_SEC = ‘0’ OR gt_data-COUNT = ‘0’ OR gt_data-AUSVN = ‘0’ OR gt_data-AUSBS = ‘0’ .

    MTTR_TOTAL = ‘0’.

  ELSEIF gt_data-MSAUS = ‘X’ .

     MTTR_TOTAL = gt_data-TOTAL_SEC / gt_data-COUNT.

  ENDIF .

  MTTR_SEC = MTTR_TOTAL MOD 60 .

  MTTR_MIN1 = MTTR_TOTAL DIV 60 .

  MTTR_FINAL_MIN = MTTR_MIN1 MOD 60 .

  MTTR_HOURS = MTTR_MIN1 DIV 60 .

  CONCATENATE MTTR_HOURS+0(8) ‘:’ MTTR_FINAL_MIN+0(2) ‘:’ MTTR_SEC+0(2) INTO FINAL_MTTR.

  gt_data-MTTR = FINAL_MTTR.

  CALL FUNCTION ‘HR_99S_INTERVAL_BETWEEN_DATES’

    EXPORTING

     BEGDA           = gt_data-STARTDATE

      ENDDA           = gt_data-ENDDATE

*   TAB_MODE        = ‘ ‘

   IMPORTING

     DAYS            = MTBR_DIFF

*   C_WEEKS         =

*   C_MONTHS        =

*   C_YEARS         =

*   WEEKS           =

*   MONTHS          =

*   YEARS           =

*   D_MONTHS        =

*   MONTH_TAB       =

            .

*&———————————————————————*

*& Report  ZPMR0_TEST

*&

*&———————————————————————*

*&

*&

*&———————————————————————*

REPORT  ZPMR0_TEST.

TYPE-POOLS: slis.                      ” ALV Global types

TABLES : qmih .

DATA:  X TYPE C,

      C_EQUNR TYPE EQKT-EQUNR,

      C1_EQUNR TYPE EQKT-EQUNR,

      C2_EQUNR TYPE EQKT-EQUNR.

“”””””””””””””””””””””””””””””””””””””””””””NO OF COUNT”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””

DATA : BREAKDOWN TYPE I.

“””””””””””””””””””””””””””””””””””””””””””””MTTR CALCULATIONS””””””””””””””””””””””””””””””””””””””””””””””””””””””

DATA : MTTR_DIFF TYPE TVRO-FAHZTD,

       V_TOTAL(8) TYPE N,

       HH TYPE HOURS,

       MM TYPE MINUTES,

       SS TYPE SECONDS,

       SEC TYPE SECONDS,

       TOTAL_SEC TYPE SECONDS,

       MTTR_TOTAL(10) TYPE C,

       MTTR_SEC(2) TYPE N,

       MTTR_HOURS(8) TYPE C,

       MTTR_MIN1 TYPE MINUTES,

       MTTR_FINAL_MIN(2) TYPE N,

       FINAL_MTTR(15) TYPE C.

“”””””””””””””””””””””””””””””””””””””””””””””MTBR CALCULTATIONS””””””””””””””””””””””””””””””””””””””””””””””””””””””

DATA : MTBR_DIFF TYPE I,

       MTBR_TOTAL(10) TYPE C,

       DAYS_TOTAL(8) TYPE N,

       MTBR_HOURS(8) TYPE C,

       MTBR_MIN TYPE MINUTES,

       MTBR_SEC(2) TYPE N,

       MTBR_FINAL_MIN(2) TYPE N,

       C_MTBR(15) TYPE C.

“”””””””””””””””””””””””””””””””””””””””””””””””MTTBR TOTAL DAYS “””””””””””””””””””””””””””””””””””””””””””””””””””””

DATA : MTBR_TOTAL_DAYS(5) TYPE N,

       ONE_DAY TYPE I,

       ONE_DAY_SEC TYPE I.

TYPES : BEGIN OF TY_FINAL,

          EQUNR TYPE EQKT-EQUNR,   “EQUIPMENT NUMBER

          EQKTU TYPE EQKT-EQKTU,   “EQUIPMENT DESCRIPTION

          IWERK TYPE QMIH-IWERK,   “Planning Plant

          MSAUS TYPE QMIH-MSAUS,    “BREAKDOWN INDICATOR

          AUSVN TYPE QMIH-AUSVN,   “START DATE

          AUSBS TYPE QMIH-AUSBS,   “END DATE

          AUZTV TYPE QMIH-AUZTV,   “START TIME

          AUZTB TYPE QMIH-AUZTB,   “END TIME

          COUNT TYPE I,

          STARTDATE TYPE QMIH-AUSVN,

          ENDDATE TYPE QMIH-AUSBS,

          MTTR(15) TYPE C,

          MTBR(15) TYPE C,

          TOTAL_SEC TYPE SECONDS,

        END OF TY_FINAL.

SELECT-OPTIONS: SO_EQUNR FOR QMIH-EQUNR OBLIGATORY.

SELECT-OPTIONS: SO_AUSVN FOR QMIH-AUSVN OBLIGATORY,

                SO_IWERK FOR QMIH-IWERK.

DATA gt_data TYPE STANDARD TABLE OF ty_final WITH HEADER LINE.

*———————————————————————*

  1. INITIALIZATION.

*———————————————————————*

START-OF-SELECTION.

  PERFORM f_read_data.

  PERFORM f_display_data.

*———————————————————————*

*      Form f_read_data

*———————————————————————*

FORM f_read_data.

*  BREAK-POINT.

SELECT EQKT~EQUNR

         EQKT~EQKTU

         QMIH~IWERK

         QMIH~MSAUS

         QMIH~AUSVN

         QMIH~AUSBS

         QMIH~AUZTV

         QMIH~AUZTB

         INTO TABLE gt_data

         FROM QMIH

         INNER JOIN EQKT ON QMIH~EQUNR = EQKT~EQUNR

         WHERE QMIH~EQUNR IN SO_EQUNR

         AND IWERK IN SO_IWERK

         AND AUSVN IN SO_AUSVN .

   IF SY-SUBRC NE 0.

    MESSAGE E001(00) WITH ‘No Values for This Equipment Number’.

  ENDIF .

  CLEAR TOTAL_SEC.

  CLEAR BREAKDOWN.

  CLEAR DAYS_TOTAL.

  ONE_DAY = ’24’.

  ONE_DAY_SEC = ONE_DAY * 3600 .

  LOOP AT gt_data .

    PERFORM CALCULATION.

  ENDLOOP.

*  WA_FINAL-STARTDATE = SO_AUSVN-LOW.

*  WA_FINAL-ENDDATE = SO_AUSVN-HIGH.

  SORT gt_data DESCENDING BY EQUNR COUNT MSAUS .

  DELETE ADJACENT DUPLICATES FROM gt_data COMPARING EQUNR IWERK.

  SORT gt_data ASCENDING BY EQUNR.

  LOOP AT gt_data .

    PERFORM FINAL_CALCULATION.

  ENDLOOP.

  1. ENDFORM.                               ” F_READ_DATA

*———————————————————————*

*      Form F_DISPLAY_DATA

*———————————————————————*

FORM f_display_data.

  DATA:

    l_column TYPE sy-tabix,

    lp_struct TYPE REF TO data,

    lp_table TYPE REF TO data,      ” Pointer to dynamic table

    ls_lvc_cat TYPE lvc_s_fcat,

    lt_lvc_cat TYPE lvc_t_fcat,       ” Field catalog

    lt_fcat TYPE slis_t_fieldcat_alv,  ” Field catalog

    ls_fieldcat TYPE slis_fieldcat_alv,

    lt_fieldcat TYPE slis_t_fieldcat_alv,  ” Field catalog

    ls_layout TYPE slis_layout_alv.

  FIELD-SYMBOLS :

    <header>       TYPE ANY,

    <field_header> TYPE ANY,

    <field_qmih>  TYPE ANY,

    <lt_data>      TYPE table.         ” Data to display

  ls_lvc_cat-fieldname = ‘COLUMNTEXT’.

  ls_lvc_cat-ref_table = ‘LVC_S_DETA’.

  APPEND ls_lvc_cat TO lt_lvc_cat.

  ls_fieldcat-fieldname = ‘COLUMNTEXT’.

  ls_fieldcat-ref_tabname = ‘LVC_S_DETA’.

  ls_fieldcat-key  = ‘X’.

  APPEND ls_fieldcat TO lt_fieldcat.

  DESCRIBE TABLE gt_data.

  DO sy-tfill TIMES.

*   For each line, a column ‘VALUEx’ is created in the fieldcatalog

*   Build Fieldcatalog

    WRITE sy-index TO ls_lvc_cat-fieldname LEFT-JUSTIFIED.

    CONCATENATE ‘VALUE’ ls_lvc_cat-fieldname

           INTO ls_lvc_cat-fieldname.

    ls_lvc_cat-ref_field = ‘VALUE’.

    ls_lvc_cat-ref_table = ‘LVC_S_DETA’.

    APPEND ls_lvc_cat TO lt_lvc_cat.

*   Build Fieldcatalog

    CLEAR ls_fieldcat.

    ls_fieldcat-fieldname = ls_lvc_cat-fieldname.

    ls_fieldcat-ref_fieldname = ‘VALUE’.

    ls_fieldcat-ref_tabname = ‘LVC_S_DETA’.

    APPEND ls_fieldcat TO lt_fieldcat.

  ENDDO.

* Create internal table

  CALL METHOD cl_alv_table_create=>create_dynamic_table

    EXPORTING it_fieldcatalog = lt_lvc_cat

    IMPORTING ep_table = lp_table.

  ASSIGN lp_table->* TO <lt_data>.

* Create structure = structure of the internal table

  CREATE DATA lp_struct LIKE LINE OF <lt_data>.

  ASSIGN lp_struct->* TO <header>.

* Create field catalog from dictionary structure

   ls_FIELDCAT-FIELDNAME  = ‘EQUNR’.

  ls_FIELDCAT-SELTEXT_M  = ‘Equipment Number’.

  ls_FIELDCAT-REF_TABNAME = ‘EQKT’.

  ls_FIELDCAT-COL_POS    = 0.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘EQKTU’.

  ls_FIELDCAT-SELTEXT_M  = ‘Equipment Description’.

  ls_FIELDCAT-REF_TABNAME = ‘EQKT’.

  ls_FIELDCAT-COL_POS    = 1.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘IWERK’.

  ls_FIELDCAT-SELTEXT_M  = ‘Plant’.

  ls_FIELDCAT-REF_TABNAME = ‘QMIH’.

  ls_FIELDCAT-COL_POS    = 2.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘MSAUS’.

  ls_FIELDCAT-SELTEXT_M  = ‘Breakdown Indicator’.

  ls_FIELDCAT-REF_TABNAME = ‘QMIH’.

  ls_FIELDCAT-COL_POS    = 3.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘STARTDATE’.

  ls_FIELDCAT-SELTEXT_M  = ‘Start of Malfunction(D)’.

  ls_FIELDCAT-COL_POS    = 4.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘ENDDATE’.

  ls_FIELDCAT-SELTEXT_M  = ‘End of Malfunction(D)’.

  ls_FIELDCAT-COL_POS    = 5.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘STARTDATE’.

  ls_FIELDCAT-SELTEXT_M  = ‘Start of Malfunction(T)’.

  ls_FIELDCAT-COL_POS    = 6.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘ENDDATE’.

  ls_FIELDCAT-SELTEXT_M  = ‘End of Malfunction(T)’.

  ls_FIELDCAT-COL_POS    = 7.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘COUNT’.

  ls_FIELDCAT-SELTEXT_M  = ‘Breakdowns’.

  ls_FIELDCAT-COL_POS    = 8.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘MTTR’.

  ls_FIELDCAT-SELTEXT_L  = ‘Mean Time to Repair in Hours’.

  ls_FIELDCAT-COL_POS    = 9.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  ls_FIELDCAT-FIELDNAME  = ‘MTBR’.

  ls_FIELDCAT-SELTEXT_L  = ‘Mean Time to Breakdown in Hours’.

  ls_FIELDCAT-COL_POS    = 10.

  APPEND ls_FIELDCAT TO lt_fcat.

  CLEAR ls_FIELDCAT.

  DESCRIBE TABLE lt_fcat.

* Fill the internal to display <lt_data>

  DO sy-tfill TIMES.

    IF sy-index = 1.

      READ TABLE lt_fcat INTO ls_fieldcat INDEX 1.

      IF ls_fieldcat-fieldname = ‘MANDT’.

*       If 1st column is MANDT, it’s not displayed

        CONTINUE.

      ENDIF.

    ENDIF.

*   For each field of GT_DATA

    ASSIGN COMPONENT 1 OF STRUCTURE <header> TO <field_header>.

    IF sy-subrc NE 0. EXIT .ENDIF.

    READ TABLE lt_fcat INTO ls_fieldcat INDEX sy-index.

*   Fill 1st column

    <field_header> = ls_fieldcat-seltext_m.

    IF <field_header> IS INITIAL.

      <field_header> = ls_fieldcat-fieldname.

    ENDIF.

    LOOP AT gt_data.

      l_column = sy-tabix + 1.

      ASSIGN COMPONENT sy-index OF STRUCTURE gt_data TO <field_qmih>.

      IF sy-subrc NE 0. EXIT .ENDIF.

      ASSIGN COMPONENT l_column OF STRUCTURE <header> TO <field_header>.

      IF sy-subrc NE 0. EXIT .ENDIF.

      WRITE <field_qmih> TO <field_header> LEFT-JUSTIFIED.

    ENDLOOP.

    APPEND <header> TO <lt_data>.

  ENDDO.

  ls_layout-colwidth_optimize = ‘X’.

  ls_layout-no_colhead = ‘X’.

  ls_layout-zebra = ‘X’.

  CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’

       EXPORTING

            is_layout   = ls_layout

            it_fieldcat = lt_fieldcat

       TABLES

            t_outtab    = <lt_data>.

  1. ENDFORM.                               ” F_DISPLAY_DATA

*&———————————————————————*

*&      Form CALCULATION

*&———————————————————————*

*       text

*———————————————————————-*

*  –> p1        text

*  <– p2        text

*———————————————————————-*

FORM CALCULATION .

*if equipment number changes variables are cleared

  X = ( SY-TABIX MOD 2 ).

  IF X = 0 .

    C2_EQUNR = gt_data-EQUNR.

  ELSE.

    C1_EQUNR = gt_data-EQUNR.

  ENDIF.

  IF C1_EQUNR NE C2_EQUNR AND SY-TABIX NE 1.

    CLEAR TOTAL_SEC.

    CLEAR BREAKDOWN.

    CLEAR DAYS_TOTAL.

  ENDIF.

  IF gt_data-MSAUS = ‘X’ .

    BREAKDOWN = BREAKDOWN + 1.

  ENDIF.

*  IF SY-TABIX = ‘1’ .

*    V_STARTDATE = WA_FINAL-AUSVN.

*  ENDIF .

  IF gt_data-AUSVN EQ ‘00000000’ OR

     gt_data-AUSBS EQ ‘00000000’ OR

     gt_data-AUZTV EQ ‘000000’ OR

     gt_data-AUZTB EQ ‘000000’ .

    V_TOTAL = ‘0’.

  ELSEIF gt_data-MSAUS = ‘X’ .

*DIFFERENCE IN HOURS

    CALL FUNCTION ‘SD_CALC_DURATION_FROM_DATETIME’

      EXPORTING

        I_DATE1                = gt_data-AUSVN

        I_TIME1                = gt_data-AUZTV

        I_DATE2                = gt_data-AUSBS

        I_TIME2                = gt_data-AUZTB

     IMPORTING

       E_TDIFF                = MTTR_DIFF

*   E_DATE2_EARLY          =

     EXCEPTIONS

       INVALID_DATETIME       = 1

       OTHERS                 = 2

              .

    IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

*FOR MTBR IN DAYS.

“”””””””””””””””””””””””””””””””””””””””””CALCULATING HH:MM:SS TO SECONDS”””””””””””””””””””””””””””””””””””””””

    V_TOTAL = MTTR_DIFF.

    HH = V_TOTAL+0(4) .

    MM = V_TOTAL+4(2).

    SS = V_TOTAL+6(2).

    SEC = HH * 60 * 60 + MM * 60 + SS.

    TOTAL_SEC = TOTAL_SEC + SEC.

  ENDIF.

  gt_data-TOTAL_SEC = TOTAL_SEC.

  gt_data-COUNT = BREAKDOWN.

  gt_data-STARTDATE = SO_AUSVN-LOW.

  gt_data-ENDDATE = SO_AUSVN-HIGH.

  MODIFY gt_data INDEX SY-TABIX.

  1. ENDFORM.                    ” CALCULATION

*&———————————————————————*

*&      Form FINAL_CALCULATION

*&———————————————————————*

*       text

*———————————————————————-*

*  –> p1        text

*  <– p2        text

*———————————————————————-*

FORM FINAL_CALCULATION .

IF gt_data-TOTAL_SEC = ‘0’ OR gt_data-COUNT = ‘0’ OR gt_data-AUSVN = ‘0’ OR gt_data-AUSBS = ‘0’ .

    MTTR_TOTAL = ‘0’.

  ELSEIF gt_data-MSAUS = ‘X’ .

     MTTR_TOTAL = gt_data-TOTAL_SEC / gt_data-COUNT.

  ENDIF .

  MTTR_SEC = MTTR_TOTAL MOD 60 .

  MTTR_MIN1 = MTTR_TOTAL DIV 60 .

  MTTR_FINAL_MIN = MTTR_MIN1 MOD 60 .

  MTTR_HOURS = MTTR_MIN1 DIV 60 .

  CONCATENATE MTTR_HOURS+0(8) ‘:’ MTTR_FINAL_MIN+0(2) ‘:’ MTTR_SEC+0(2) INTO FINAL_MTTR.

  gt_data-MTTR = FINAL_MTTR.

  CALL FUNCTION ‘HR_99S_INTERVAL_BETWEEN_DATES’

    EXPORTING

     BEGDA           = gt_data-STARTDATE

      ENDDA           = gt_data-ENDDATE

*   TAB_MODE        = ‘ ‘

   IMPORTING

     DAYS            = MTBR_DIFF

*   C_WEEKS         =

*   C_MONTHS        =

*   C_YEARS         =

*   WEEKS           =

*   MONTHS          =

*   YEARS           =

*   D_MONTHS        =

*   MONTH_TAB       =

            .

  DAYS_TOTAL = MTBR_DIFF.

  IF DAYS_TOTAL = ‘0’ OR

     gt_data-COUNT = ‘0’ OR

     gt_data-TOTAL_SEC = ‘0’ .

    MTBR_TOTAL = ‘0’ .

  ELSE .

    MTBR_TOTAL = ( ( DAYS_TOTAL * ONE_DAY_SEC ) – gt_data-TOTAL_SEC ) / gt_data-COUNT .

  ENDIF .

  MTBR_MIN = MTBR_TOTAL DIV 60 .

  MTBR_SEC = MTBR_TOTAL MOD 60 .

  MTBR_FINAL_MIN = MTBR_MIN MOD 60 .

  MTBR_HOURS = MTBR_MIN DIV 60 .

  CONCATENATE MTBR_HOURS+0(8) ‘:’ MTBR_FINAL_MIN+0(2) ‘:’ MTBR_SEC+0(2) INTO C_MTBR.

  gt_data-MTBR = C_MTBR.

  MODIFY gt_data FROM gt_data INDEX SY-TABIX.

  1. ENDFORM.                    ” FINAL_CALCULATION

  DAYS_TOTAL = MTBR_DIFF.

  IF DAYS_TOTAL = ‘0’ OR

     gt_data-COUNT = ‘0’ OR

     gt_data-TOTAL_SEC = ‘0’ .

    MTBR_TOTAL = ‘0’ .

  ELSE .

    MTBR_TOTAL = ( ( DAYS_TOTAL * ONE_DAY_SEC ) – gt_data-TOTAL_SEC ) / gt_data-COUNT .

  ENDIF .

  MTBR_MIN = MTBR_TOTAL DIV 60 .

  MTBR_SEC = MTBR_TOTAL MOD 60 .

  MTBR_FINAL_MIN = MTBR_MIN MOD 60 .

  MTBR_HOURS = MTBR_MIN DIV 60 .

  CONCATENATE MTBR_HOURS+0(8) ‘:’ MTBR_FINAL_MIN+0(2) ‘:’ MTBR_SEC+0(2) INTO C_MTBR.

  gt_data-MTBR = C_MTBR.

  MODIFY gt_data FROM gt_data INDEX SY-TABIX.

  1. ENDFORM.                    ” FINAL_CALCULATION

Output :


To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply