Skip to Content
-1
Jun 10, 2022 at 09:42 AM

How to print footer in ALV report

138 Views

Hello Everyone,

I have seen so many questions were raised on how to print footer in ALV. I checked all answers and did code but still it is not working. Hence I raised this question again. I want to print page number on each page using end_of_page.

Please note it's end_of_page not end_of_list. Because end_of_list is working for me and using that i can not print page number.

Here is my code.

TABLES: mara.
TYPE-POOLS:slis.
TYPES:
BEGIN OF ty_mara,
matnr TYPE matnr,
ersda TYPE ersda,
ernam TYPE ernam,
mtart TYPE mtart,
mbrsh TYPE mbrsh,
END OF ty_mara.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
it_mara TYPE TABLE OF ty_mara,
it_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,
gd_print TYPE slis_print_alv1,
wa_event TYPE slis_alv_event,
gt_events TYPE slis_t_event.
SELECT-OPTIONS: matnr FOR mara-matnr.
INITIALIZATION.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = gt_events[]
* EXCEPTIONS
* LIST_TYPE_WRONG = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
READ TABLE gt_events WITH KEY name = 'END_OF_PAGE' INTO wa_event.
IF sy-subrc = 0.
MOVE 'END_OF_PAGE' TO wa_event-form.
APPEND wa_event TO gt_events.
ENDIF.
gd_print-reserve_lines = '3'. "Lines reserved for footer
gd_print-no_coverpage = 'X'.
START-OF-SELECTION.
SELECT
matnr
ersda
ernam
mtart
mbrsh
FROM mara
INTO TABLE it_mara WHERE matnr IN matnr.
wa_fieldcat-fieldname = 'MATNR'. " Fieldname in the data table
wa_fieldcat-seltext_m = 'Material NO'. " Column description in the output
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'ERSDA'.
wa_fieldcat-seltext_m = 'Created On'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'ERNAM'.
wa_fieldcat-seltext_m = 'Created By'.
APPEND wa_fieldcat TO it_fieldcat.
wa_fieldcat-fieldname = 'MTART'.
wa_fieldcat-seltext_m = 'Material Type'.
APPEND wa_fieldcat TO it_fieldcat.


  wa_fieldcat-fieldname = 'ERSDA'.
wa_fieldcat-seltext_m = 'Industial Sector'.
APPEND wa_fieldcat TO it_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = 'X'
i_bypassing_buffer = 'X'
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
i_callback_top_of_page = 'TOP'
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
it_fieldcat = it_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
i_default = 'X'
* I_SAVE = ' '
* IS_VARIANT =
it_events = gt_events[]
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* O_PREVIOUS_SRAL_HANDLER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = it_mara
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
FORM top.
wa_header-typ = 'S'.
wa_header-info = 'Material Data'.
wa_header-key = 'Material Data'.
APPEND wa_header TO it_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_header
* I_LOGO =
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.
ENDFORM.
FORM end_of_page.
WRITE: sy-uline(50).
SKIP.
WRITE:/40 'Page:', sy-pagno .
ENDFORM.