Header and Footer in Object Oriented ALV

Header and Footer in Object Oriented ALV

The class used for creating texts for Header and Footer in the below program is CL_SALV_FORM_LAYOUT_GRID.

The below methods are used to set the text in different formats

  • CREATE_HEADER_INFORMATION – To display main heading
  • CREATE_LABEL – To display bold text
  • CREATE_TEXT – To display normal text

The ALV table class CL_SALV_TABLE has below methods to set the header and footer of ALV report.

  • SET_TOP_OF_LIST
  • SET_END_OF_LIST

The below program gives an idea on how to create header and footer for ALV report. If you need to use different footer you have to create separate header, label and text for footer and pass it to SET_END_OF_LIST method.


REPORT ztest_ppk.

DATA: lo_alv   TYPE REF TO cl_salv_table.

DATA: lv_count TYPE i.

DATA: lo_grid_layout TYPE REF TO cl_salv_form_layout_grid,
      l_text         TYPE string.

START-OF-SELECTION.

  SELECT * FROM spfli INTO TABLE @DATA(lt_spfli).

  IF sy-subrc IS INITIAL.

    cl_salv_table=>factory(
      IMPORTING
        r_salv_table   = lo_alv
      CHANGING
        t_table        = lt_spfli[]
    ).

    CREATE OBJECT lo_grid_layout.

    l_text = 'Flight Schedule Report'.

*-- Create Heading
    lo_grid_layout->create_header_information(
      EXPORTING
        row     = 1
        column  = 3
        text    = l_text ).

*-- Create Label for Bold Text
    lo_grid_layout->create_label(
      EXPORTING
        row         = 2
        column      = 1
        text        = 'Number of records found' ).

    DESCRIBE TABLE lt_spfli LINES lv_count.

*-- Create normal text
    lo_grid_layout->create_text(
      EXPORTING
        row         = 2
        column      = 2
        text        = lv_count
        tooltip     = lv_count ).

    lo_grid_layout->create_label(
      EXPORTING
        row         = 3
        column      = 1
        text        = 'Date' ).

    lo_grid_layout->create_text(
      EXPORTING
        row         = 3
        column      = 2
        text        = sy-datum ).

    lo_alv->set_top_of_list( value = lo_grid_layout ). "Header
    lo_alv->set_end_of_list( value = lo_grid_layout ). "Footer

    lo_alv->display( ).

  ENDIF.

Output:












Post a Comment

Previous Post Next Post