REPORT zalvgrid NO STANDARD PAGE HEADING.
*&---------------------------------------------------------------------*
*&  Written By    : Sheila Titchener - www.iconet-ltd.co.uk
&   Date          : January 2006
*&
*&---------------------------------------------------------------------*
*  Includes logo and white background - optimized field size
*&---------------------------------------------------------------------*
* ALV
TYPE-POOLS: slis.
*----------------
* extracted Notification date
TYPES: BEGIN OF ty_data,
       qmnum TYPE qmnum,
       qmdat TYPE qmdat,
       mzeit TYPE mzeit,
       erdat TYPE erdat,
       erzeit TYPE erzeit,
       ernam TYPE ernam,
       END OF ty_data.

* ALV print table
TYPES: BEGIN OF ty_out,
       qmnum TYPE qmnum,
       qmdat TYPE qmdat,
       mzeit TYPE mzeit,
       erdat TYPE erdat,
       erzeit TYPE erzeit,
       ernam TYPE ernam,
       END OF ty_out.
*----------------------------------------------------------------------*
DATA: viqmel TYPE viqmel.
*----------------------------------------------------------------------*
* Internal tables and their work areas
*----------------------------------------------------------------------*
DATA: w_data TYPE ty_data,
      t_data TYPE TABLE OF ty_data.
DATA: w_out TYPE ty_out,
      t_out TYPE TABLE OF ty_out.
*----------------------------------------------------------------------*
* Headings.
*----------------------------------------------------------------------*
DATA: BEGIN OF h1,
      print_date(10),
      sdate(10),
      END OF h1.
*
*----------------------------------------------------------------------*
* Data for ALV
*----------------------------------------------------------------------*
INCLUDE <icon>.
INCLUDE <symbol>.
*---------
CONSTANTS:
*---------
gc_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.

DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,
      gs_layout   TYPE slis_layout_alv,
      gs_print    TYPE slis_print_alv,
      gt_sort     TYPE slis_t_sortinfo_alv,
      gt_sp_group TYPE slis_t_sp_group_alv,
      gt_events   TYPE slis_t_event.
*
DATA: g_repid LIKE sy-repid.
DATA: gt_list_top_of_page TYPE slis_t_listheader.

DATA:       g_save(1) TYPE c.
*----------------------------------------------------------------------*
* Report Selections
*----------------------------------------------------------------------*
PARAMETERS: plant LIKE viqmel-iwerk VALUE CHECK OBLIGATORY
                                    MEMORY ID wrk,
            sorg LIKE vbak-vkorg OBLIGATORY MEMORY ID vko.

SELECTION-SCREEN SKIP 1.

SELECT-OPTIONS: wkcentre FOR viqmel-arbpl,
                nottype FOR viqmel-qmart,
                notnum FOR viqmel-qmnum,
                crdate FOR viqmel-erdat NO-EXTENSION,
                createby FOR viqmel-ernam.


*-------
* MACROS
*-------
* FIELD CATALOGUE ENTRY FOR Keyed FIELDS
DEFINE catfield.
*----------------
* 1= Fieldname,  2= Description, 3=Key
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = &1.
  ls_fieldcat-key          = &3.
  ls_fieldcat-hotspot       = &3.
* ls_fieldcat-key_sel      = 'X'.
  ls_fieldcat-tabname    = 'T_OUT'.
* Output length will be optimised by ALV
*  ls_fieldcat-outputlen = '6'.
  ls_fieldcat-seltext_m = &2.
  append ls_fieldcat to gt_fieldcat.
* color   C or X   1-9 = color number 0/1 intensified 0/1 inverse
  ls_fieldcat-emphasize = 'C100'.
END-OF-DEFINITION.
*----------------
* FIELD CATALOGUE ENTRY FOR SUMMED FIELDS
DEFINE catsum.
*----------------
* 1= Fieldname,  2= color, 3= Description,
  clear ls_fieldcat.
  ls_fieldcat-fieldname    = &1.
  ls_fieldcat-do_sum       = 'X'.
  ls_fieldcat-key_sel      = 'X'.
  ls_fieldcat-tabname    = 'T_OUT'.
  ls_fieldcat-emphasize = &2.
  ls_fieldcat-seltext_m = &3.
  append ls_fieldcat to gt_fieldcat.
END-OF-DEFINITION.
*---------------------------------------------------------------------*
INITIALIZATION.
*----------------------------------------------------------------------*
  g_repid = sy-repid.
* set to-date as today
  crdate-high = sy-datum.
  crdate-option = 'EQ'.
  crdate-sign = 'I'.
  APPEND crdate TO crdate.

  REFRESH gt_fieldcat.
  PERFORM e01_fieldcat_init .
  PERFORM e03_eventtab_build USING gt_events[].
  PERFORM e06_t_sort_build   USING gt_sort[].
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON plant.
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
START-OF-SELECTION.
*----------------------------------------------------------------------*
  PERFORM e04_comment_build  USING gt_list_top_of_page[].

  PERFORM selection.

*----------------------------------------------------------------------*
END-OF-SELECTION.
*----------------------------------------------------------------------*
  PERFORM e05_layout_build USING gs_layout.     "wg. Parameters
* Call ABAP/4 List Viewer
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            i_background_id    = 'WHITE'
            i_callback_program = g_repid
            i_callback_user_command = 'USER_COMMAND'
            is_layout          = gs_layout
            it_fieldcat        = gt_fieldcat[]
*           i_save             = 'A'
            is_print           = gs_print
            it_events          = gt_events[]
       TABLES
            t_outtab           = t_out.
*---------------------------------------------------------------------*
*       FORM E01_FIELDCAT_INIT                                        *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  E01_LT_FIELDCAT                                               *
*---------------------------------------------------------------------*
FORM e01_fieldcat_init.
  DATA: ls_fieldcat TYPE slis_fieldcat_alv.
* BASIC FIELDS
  catfield 'QMNUM'    text-024 'X'.
  catfield 'QMDAT'    text-023 ' '.
  catfield 'MZEIT'    text-022 ' '.
  catfield 'ERDAT'    text-021 ' '.
  catfield 'ERZEIT'   text-020 ' '.
  catfield 'ERNAM'    text-019 ' '.

ENDFORM.
*---------------------------------------------------------------------*
*       FORM E02_DATA_ADD                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->                                                                *
*---------------------------------------------------------------------*
FORM e02_data_add .

  LOOP AT t_data INTO w_data.
    MOVE-CORRESPONDING w_data TO w_out.
    PERFORM get_disp_task.
    PERFORM get_tsrl_status.
    APPEND w_out TO t_out.
  ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM E03_EVENTTAB_BUILD                                       *
*---------------------------------------------------------------------*
*       Set up TOP-OF-PAGE event processing                           *
*---------------------------------------------------------------------*
*  -->  E03_LT_EVENTS                                                 *
*---------------------------------------------------------------------*
FORM e03_eventtab_build USING e03_lt_events TYPE slis_t_event.
  DATA: ls_event TYPE slis_alv_event.
*
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
       EXPORTING
            i_list_type = 0
       IMPORTING
            et_events   = e03_lt_events.
  READ TABLE e03_lt_events WITH KEY name =  slis_ev_top_of_page
                           INTO ls_event.
  IF sy-subrc = 0.
    MOVE gc_formname_top_of_page TO ls_event-form.
    APPEND ls_event TO e03_lt_events.
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM E04_COMMENT_BUILD                                        *
*---------------------------------------------------------------------*
*       Create Headings
*
*---------------------------------------------------------------------*
*  -->  E04_LT_TOP_OF_PAGE                                            *
*---------------------------------------------------------------------*
FORM e04_comment_build USING e04_lt_top_of_page TYPE slis_t_listheader.
  DATA: ls_line TYPE slis_listheader.
  DATA: l_date(10).
*
* Title Typ H
  CLEAR ls_line.
  ls_line-typ  = 'H'.
  ls_line-info = sy-title.
  APPEND ls_line TO e04_lt_top_of_page.

* head 1
  CLEAR ls_line.
* Plant
  ls_line-key = text-101.
  ls_line-info = plant.
  ls_line-typ  = 'S'.
  APPEND ls_line TO e04_lt_top_of_page.

* Sales Org
  ls_line-key = text-102.
  ls_line-info = sorg.
  APPEND ls_line TO e04_lt_top_of_page.
* Maintenance Work Centre
  IF NOT wkcentre[] IS INITIAL.
    ls_line-key = text-105.
    ls_line-info = wkcentre-low.
    APPEND ls_line TO e04_lt_top_of_page.
  ENDIF.
* Notification Type
  IF NOT nottype[] IS INITIAL.
    ls_line-key = text-106.
    ls_line-info = nottype-low.
    APPEND ls_line TO e04_lt_top_of_page.
  ENDIF.
* Notification Number
  IF NOT notnum[] IS INITIAL.
    ls_line-key = text-107.
    ls_line-info = notnum-low.
    APPEND ls_line TO e04_lt_top_of_page.
  ENDIF.
* Created From
  ls_line-key = text-103.
  WRITE crdate-low TO l_date DD/MM/YYYY.
  ls_line-info = l_date.
  APPEND ls_line TO e04_lt_top_of_page.
* Created to
  ls_line-key = text-104.
  WRITE crdate-high TO l_date DD/MM/YYYY.
  ls_line-info = l_date.
  APPEND ls_line TO e04_lt_top_of_page.

*

ENDFORM.
*---------------------------------------------------------------------*
*       FORM E05_LAYOUT_BUILD                                         *
*---------------------------------------------------------------------*
*      ALV Layout options                                             *
*---------------------------------------------------------------------*
*  <->  E05_LS_LAYOUT                                                 *
*---------------------------------------------------------------------*
FORM e05_layout_build USING e05_ls_layout TYPE slis_layout_alv.
  e05_ls_layout-zebra             = 'X'.
  e05_ls_layout-colwidth_optimize = 'X'.
*  e05_ls_layout-lights_fieldname = 'LIGHTS'.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM E06_T_SORT_BUILD                                         *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  E06_LT_SORT                                                   *
*---------------------------------------------------------------------*
FORM e06_t_sort_build USING e06_lt_sort TYPE slis_t_sortinfo_alv.
*  DATA: ls_sort TYPE slis_sortinfo_alv.
ENDFORM.
*---------------------------------------------------------------------*
FORM user_command  USING r_ucomm LIKE sy-ucomm
       rs_selfield TYPE slis_selfield.
*---------------------------------------------------------------------*
* called by ALV list viewer
*-----------------------------------------------------------------------
  CASE rs_selfield-sel_tab_field.
    WHEN 'T_OUT-QMNUM'.
      SET PARAMETER ID 'IQM' FIELD rs_selfield-value.
      CALL TRANSACTION 'IW53' AND SKIP FIRST SCREEN.
  ENDCASE.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM SELECTION                                                *
*---------------------------------------------------------------------*
*      Select data from CATSDB                                           *
*---------------------------------------------------------------------*
FORM selection.

  SELECT  * FROM viqmel

           INTO CORRESPONDING FIELDS OF TABLE t_data
                      WHERE iwerk = plant
                            AND vkorg = sorg
                            AND arbpl IN wkcentre
                            AND qmart IN nottype
                            AND qmnum IN notnum
                            AND erdat IN crdate
                            AND ernam IN createby.
*
  PERFORM e02_data_add.
ENDFORM.
*---------------------------------------------------------------------*
*       FORM TOP_OF_PAGE                                              *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
FORM top_of_page.
* create logo in transaction OAER - Business Documents
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
       EXPORTING
            i_logo             = 'LOGO'
            it_list_commentary = gt_list_top_of_page.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  get_disp_task
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_disp_task.

ENDFORM.                    " get_disp_task
*&---------------------------------------------------------------------*
*&      Form  get_tsrl_status
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_tsrl_status.

ENDFORM.                    " get_tsrl_status