Events in REUSE_ALV_LIST_DISPLAY


*&---------------------------------------------------------------------*
*& Report  ZELVR_TEST1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZELVR_TEST1.

TABLES : mseg.

TYPE-POOLS : slis.

DATA : BEGIN OF itab OCCURS 0,
       mblnr         LIKE mseg-mblnr,
       matnr         LIKE mseg-matnr,
       werks         LIKE mseg-werks,
       menge         LIKE mseg-menge,
       line_color(4) TYPE c,
      END OF itab.

DATA : t_fcat TYPE slis_t_fieldcat_alv,
      t_eve TYPE slis_t_event,
      t_subtot TYPE slis_t_sortinfo_alv,
      subtot LIKE LINE OF t_subtot,
      wa_fcat LIKE LINE OF t_fcat,
      gd_layout    TYPE slis_layout_alv.

DATA : gt_menge LIKE mseg-menge,
      st_menge LIKE mseg-menge.

SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : doc FOR mseg-mblnr.
SELECTION-SCREEN : END OF BLOCK blk1.

INITIALIZATION.
 PERFORM build_cat USING t_fcat.
 PERFORM build_eve.
 PERFORM build_layout.

START-OF-SELECTION.
 PERFORM get_data.
 PERFORM display.

*&---------------------------------------------------------------------*
*&      Form  build_cat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->TEMP_FCAT  text
*----------------------------------------------------------------------*
FORM build_cat USING temp_fcat TYPE slis_t_fieldcat_alv.

 wa_fcat-tabname   = 'ITAB'.
 wa_fcat-fieldname = 'MBLNR'.
 wa_fcat-seltext_m = 'Material Doc.'.
 wa_fcat-outputlen = 10.
 APPEND wa_fcat TO temp_fcat.
 CLEAR wa_fcat.

 wa_fcat-tabname   = 'ITAB'.
 wa_fcat-fieldname = 'MATNR'.
 wa_fcat-seltext_m = 'Material'.
 wa_fcat-outputlen = 18.
 APPEND wa_fcat TO temp_fcat.
 CLEAR wa_fcat.

 wa_fcat-tabname   = 'ITAB'.
 wa_fcat-fieldname = 'WERKS'.
 wa_fcat-seltext_m = 'Plant'.
 wa_fcat-outputlen = 4.
 APPEND wa_fcat TO temp_fcat.
 CLEAR wa_fcat.

 wa_fcat-tabname  = 'ITAB'.
 wa_fcat-fieldname = 'MENGE'.
 wa_fcat-seltext_m = 'Quantity'.
 wa_fcat-outputlen = 17.
 wa_fcat-do_sum = 'Y'.
 APPEND wa_fcat TO temp_fcat.
 CLEAR wa_fcat.

 subtot-spos = 1.
 subtot-fieldname = 'MBLNR'.
 subtot-tabname = 'ITAB'.
*  subtot-up = 'X'.
*  subtot-group = 'X'.
 subtot-subtot = 'X'.
*  subtot-expa = 'X'.
 APPEND subtot TO t_subtot.


ENDFORM.                    "build_cat

*&---------------------------------------------------------------------*
*&      Form  build_eve
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM build_eve.

 DATA : wa_eve TYPE slis_alv_event.

 CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
   EXPORTING
     i_list_type     = 0
   IMPORTING
     et_events       = t_eve
   EXCEPTIONS
     list_type_wrong = 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.

 READ TABLE t_eve WITH KEY name =  slis_ev_top_of_page
                        INTO wa_eve.
 IF sy-subrc = 0.
   MOVE 'TOP_OF_PAGE' TO wa_eve-form.
   APPEND wa_eve TO t_eve.
 ENDIF.

 READ TABLE t_eve INTO wa_eve WITH KEY name = 'END_OF_LIST'.
 IF sy-subrc = 0.
   wa_eve-form = 'END_OF_PAGE'.
   MODIFY t_eve FROM wa_eve INDEX sy-tabix.
 ENDIF.


ENDFORM.                    "build_eve
*&---------------------------------------------------------------------*
*&      Form  build_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM build_layout.

 gd_layout-no_input          = 'X'.
 gd_layout-colwidth_optimize = 'X'.
 gd_layout-info_fieldname    = 'LINE_COLOR'.
 gd_layout-subtotals_text    = 'SUBTOTAL'.
 gd_layout-totals_text       = 'TOTAL'.

ENDFORM.                    " BUILD_LAYOUT

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_data.

 SELECT mblnr matnr werks menge FROM mseg INTO CORRESPONDING FIELDS OF TABLE itab WHERE mblnr IN doc.

 SORT itab BY mblnr.

ENDFORM.                    "get_data

*&---------------------------------------------------------------------*
*&      Form  display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM display.

 CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
     i_callback_program = SY-REPID
     is_layout          = gd_layout
     it_fieldcat        = t_fcat
     it_sort            = t_subtot
     it_events          = t_eve
   TABLES
     t_outtab           = itab.
 IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
 ENDIF.

ENDFORM.                    "display

*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM top_of_page.

*ALV Header declarations
 DATA: t_header TYPE slis_t_listheader,
       wa_header TYPE slis_listheader,
       t_line LIKE wa_header-info,
       ld_lines TYPE i,
       ld_linesc(10) TYPE c.

* Title
 wa_header-typ  = 'H'.
 wa_header-info = 'MSEG Table Report'.
 APPEND wa_header TO t_header.
 CLEAR wa_header.

* Date
 wa_header-typ  = 'S'.
 wa_header-key = 'Date: '.
 CONCATENATE  sy-datum+6(2) '.'
              sy-datum+4(2) '.'
              sy-datum(4) INTO wa_header-info.   "todays date
 APPEND wa_header TO t_header.
 CLEAR: wa_header.

* Total No. of Records Selected
 DESCRIBE TABLE itab LINES ld_lines.
 ld_linesc = ld_lines.
 CONCATENATE 'Total No. of Records Selected: ' ld_linesc
                   INTO t_line SEPARATED BY space.
 wa_header-typ  = 'A'.
 wa_header-info = t_line.
 APPEND wa_header TO t_header.
 CLEAR: wa_header, t_line.

 CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
   EXPORTING
     it_list_commentary = t_header.
*            i_logo             = 'Z_LOGO'.

ENDFORM.                    "top_of_page

*&---------------------------------------------------------------------*
*&      Form  end_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM end_of_page.

 WRITE:/ 'Vimal Raj'.

ENDFORM.                    "end_of_page


OUTPUT


Share this

Related Posts