REUSE_ALV_LIST_DISPLAY- 19

light11Triggering TOP_OF_PAGE event in list ALV by EVENTS table

 

 

 

The previous post REUSE_ALV_LIST_DISPLAY- 18 shows how to calculate total and subtotal using the field catalog and sort table. This post shows how to make the TOP_OF_PAGE event in list ALV.


Code Snippet:


———-data declarations——–
TYPE-POOLS: slis.
TYPES: BEGIN OF ty_flight,
box.
INCLUDE STRUCTURE spfli.
TYPES: END OF ty_flight.
DATA: lt_spfli TYPE TABLE OF ty_flight.
DATA: ls_spfli TYPE ty_flight.
DATA: ls_layout TYPE slis_layout_alv.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: lt_events TYPE slis_t_event.   ” Declare for to trigger the event
DATA: lt_list_comment TYPE slis_t_listheader.
———————————–

START-OF-SELECTION.
PERFORM build_data.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM build_events.
PERFORM display_list_alv.

&————————————————-
& Form BUILD_DATA
&————————————————-*
FORM build_data.
SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE lt_spfli.
ENDFORM. ” BUILD_DATA

&———————————————————————
& Form BUILD_FIELDCATALOG
&———————————————————————
FORM build_fieldcatalog.
DATA: ls_fieldcat TYPE LINE OF slis_t_fieldcat_alv.
CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE’
EXPORTING
i_program_name = sy-cprog
I_INTERNAL_TABNAME =
i_structure_name = ‘SPFLI’
* I_CLIENT_NEVER_DISPLAY = ‘X’
* I_INCLNAME =
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.

ENDFORM. ” BUILD_FIELDCATALOG

&————————————————–
& Form BUILD_LAYOUT
&————————————————–
FORM build_layout.
ls_layout-zebra = ‘X’.
ls_layout-box_fieldname = ‘BOX’.
ls_layout-detail_popup = ‘X’.
ls_layout-detail_titlebar = ‘Detailed Flight Info’.
ls_layout-f2code = ‘&ETA’.
ls_layout-window_titlebar = ‘Flight Info’.
ENDFORM. ” BUILD_LAYOUT
&——————————————————
& Form BUILD_EVENTS
&——————————————————
FORM build_events.
DATA: ls_events TYPE slis_alv_event.

” Read all the events of list ALV
CALL FUNCTION ‘REUSE_ALV_EVENTS_GET’
EXPORTING
i_list_type = 0              ” 0- means list ALV
IMPORTING
et_events = lt_events.

” Build the LT_EVENTS table with the event name and subroutine name
READ TABLE lt_events INTO ls_events WITH KEY name = slis_ev_top_of_page.
IF sy-subrc = 0.
ls_events-form = ‘TOP_OF_PAGE’.   ” this is going to be a subroutine name
APPEND ls_events TO lt_events.
ENDIF.
ENDFORM. ” BUILD_EVENTS
&—————————————————
& Form DISPLAY_LIST_ALV
&—————————————————-*
FORM display_list_alv.

CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’
EXPORTING
i_callback_program = sy-cprog
” i_structure_name = ‘SPFLI’
is_layout = ls_layout
it_fieldcat = lt_fieldcat
it_events = lt_events
TABLES
t_outtab = lt_spfli
EXCEPTIONS
program_error = 1
OTHERS = 2.
CASE sy-subrc.
WHEN 1.
MESSAGE ‘Program Error’ TYPE ‘I’.
WHEN OTHERS.
ENDCASE.
ENDFORM. ” DISPLAY_LIST_ALV
&—————————————————
& Form TOP_OF_PAGE
&—————————————————-*
FORM top_of_page.

Use the below code to display text in the top of page of the ALV

DATA: ls_list_comment TYPE slis_listheader.
ls_list_comment-typ = ‘H’.
ls_list_comment-info = ‘Flight Information Details’.
APPEND ls_list_comment TO lt_list_comment.
CLEAR ls_list_comment.

ls_list_comment-typ = ‘S’.
ls_list_comment-key = ‘Distance Details’.
ls_list_comment-info = ‘All Flight Distance’.
APPEND ls_list_comment TO lt_list_comment.
CLEAR ls_list_comment.

ls_list_comment-typ = ‘A’.
ls_list_comment-info = ‘Flight may be delayed’.
APPEND ls_list_comment TO lt_list_comment.

CALL FUNCTION ‘REUSE_ALV_COMMENTARY_WRITE’
EXPORTING
it_list_commentary = lt_list_comment.

ENDFORM.


Constants available for events

8.jpg

Program Output:

9.jpg


 

Advertisements

One thought on “REUSE_ALV_LIST_DISPLAY- 19

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s