Wednesday, October 22, 2008

Display footer info in ALV Grid

By Joyjit Ghosh.

Steps:

Step1: Populate the ALV event table with 'END_OF_LIST' event

Step2: Populate the footer text in to an internal table which is of type

slis_t_listheader.

Step3: Create a subroutine with name 'END_OF_LIST' and with in this form we have to call the function module ‘REUSE_ALV_COMMENTARY_WRITE’.

Step4: Now call the function module REUSE_ALV_GRID_DISPLAY’ to display the ALV report. Whenever ‘END_OF_LIST' event is get fired it executes the subroutine END_OF_LIST and displays the text into the footer of the ALV GRID.

Code:

*&---------------------------------------------------------------------*

*& Report Z_TEST_ALV

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT z_test_alv.

TYPE-POOLS: slis.

DATA: i_mara TYPE STANDARD TABLE OF mara INITIAL SIZE 0.

DATA i_events TYPE slis_t_event.

DATA: i_end_of_page TYPE slis_t_listheader.

DATA: w_events TYPE slis_alv_event.

DATA: v_repid LIKE sy-repid.

START-OF-SELECTION.

SELECT * FROM

mara INTO TABLE i_mara

UP TO 100 ROWS.

CHECK sy-subrc = 0.

PERFORM populate_alv_event.

PERFORM comment_build USING i_end_of_page[].

PERFORM display_grid.

*&---------------------------------------------------------------------*

*& Form POPULATE_ALV_EVENT

*&---------------------------------------------------------------------*

FORM populate_alv_event .

* Populate event table

w_events-name = 'END_OF_LIST'.

w_events-form = 'END_OF_LIST'.

APPEND w_events TO i_events.

ENDFORM. " POPULATE_ALV_EVENT

*&---------------------------------------------------------------------*

*& Form COMMENT_BUILD

*&---------------------------------------------------------------------*

FORM comment_build USING p_i_end_of_page TYPE slis_t_listheader.

DATA: ls_line TYPE slis_listheader.

REFRESH p_i_end_of_page.

CLEAR ls_line.

ls_line-typ = 'H'.

ls_line-info = 'This is end of list'(001).

APPEND ls_line TO p_i_end_of_page.

ENDFORM. " COMMENT_BUILD

*&---------------------------------------------------------------------*

*& Form end_of_list

*&---------------------------------------------------------------------*

FORM end_of_list.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = i_end_of_page.

ENDFORM. "end_of_list

*&---------------------------------------------------------------------*

*& Form DISPLAY_GRID

*&---------------------------------------------------------------------*

FORM display_grid .

v_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = v_repid

i_structure_name = 'MARA'

it_events = i_events

TABLES

t_outtab = i_mara

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

ENDIF.

ENDFORM. " DISPLAY_GRID

Output:

3 comments:

pirdhee said...

Thanks...its very useful to me as newbie.. :)

sapinterviewquestions said...

very helpful...!!! Thanks a Lot.

sumeet yadav said...

thnks man very usefull tut.