&———————————————————————*
*& Report Z01_DEMO_ALV_HEADER
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT z01_demo_alv_header.
TYPE-POOLS: slis. ” SLIS contains all the ALV data types
*&———————————————————————*
*& Data Declaration
*&———————————————————————*
DATA: lt_sflight TYPE TABLE OF sflight.
DATA: g_repid   TYPE sy-repid.
*ALV Header declarations
DATA: lt_header        TYPE slis_t_listheader,
              ls_header       TYPE slis_listheader,
              lt_line             LIKE ls_header-info,
              lv_lines          TYPE i,
              lv_linesc(10) TYPE c.
*&———————————————————————*
*& START-OF-SELECTION
*&———————————————————————*
START-OF-SELECTION.
g_repid = sy-repid.
*&—– Fetch data from the database —–*
SELECT *
     FROM sflight
     INTO TABLE lt_sflight.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
     EXPORTING
          i_callback_program = g_repid
          i_callback_top_of_page = ‘TOP-OF-PAGE’
          i_structure_name = ‘SFLIGHT’
     TABLES
          t_outtab = lt_sflight.
*———————————————————–*
* Form TOP-OF-PAGE
* Generating Report Header
*———————————————————–*
FORM top-of-page.
*&—– Alv report header —–*
* Title
ls_header-typ = ‘H’.
ls_header-info = ‘SFLIGHT Table Report’.
APPEND ls_header TO lt_header.
CLEAR ls_header.
* Date
ls_header-typ = ‘S’.
ls_header-key = ‘Date: ‘.
CONCATENATE sy-datum+6(2) ‘.’
sy-datum+4(2) ‘.’
sy-datum(4) INTO ls_header-info. “todays date
APPEND ls_header TO lt_header.
CLEAR: ls_header.
* Total No. of Records Selected
DESCRIBE TABLE lt_sflight LINES lv_lines.
lv_linesc = lv_lines.
CONCATENATE ‘Total No. of Records Selected: ‘ lv_linesc
INTO lt_line SEPARATED BY space.
ls_header-typ = ‘A’.
ls_header-info = lt_line.
APPEND ls_header TO lt_header.
CLEAR: ls_header, lt_line.
*&—– Pass data and field catalog to ALV function module —–*
CALL FUNCTION ‘REUSE_ALV_COMMENTARY_WRITE’
     EXPORTING
          it_list_commentary = lt_header.
ENDFORM. “top-of-page




Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP S/4 HANA Logistics Team Lead
Contact : serkurumsal@yandex.com