SALV Table 5 – Add Header (Top of page) & Footer (End of Page)

By | September 24, 2008 | SALV Table, SALV Tutorial, Tutorials | 118,764 | 12

Today we will discuss how to add the Header and Footer using the SALV model. In ALV, header (top-of-page) and footer (end-of-page) play important role in presentation of the data. Header and footer are imortant when we need to print the report and use it for later decisions. Assume the report which has only columns and no information. Does it really define “Information”? – NO. So, let’s get started on how to create Header and Footer.

Header and Footer both can be created using the class reference CL_SALV_FORM_LAYOUT_GRID. We will create:
– A reference of the class CL_SALV_FORM_LAYOUT_GRID
– Use methods of this reference to create a Lables & Flow.
– Set this reference into the main ALV object (reference to CL_SALV_TABLE).

Labels are useful to generate the text output in intensified or Bold letters. This can be used to print the Header, like – Sales Revenue Report. We can also use this kind of lables in the Footer section to highlight the total amount of all orders – for example. Flow is useful to dispaly the information in the tabular format. This flow can be used to display the Selection parameters, selected rows etc.

Here is the code snippet to which provides the ADD-ON code to our Base program. The base program can be found in the SALV Model 1: Normal ALV Table Display .

UML diagram for the test program will be like:

Code Snippet to generate Header & Footer

*$*$*.....CODE_ADD_1 - Begin..................................1..*$*$*
*
*    In this section we will define the private methods which can
*      be implemented to set the properties of the ALV and can be
*      called in the
*
  PRIVATE SECTION.
*   Default Pf Status
    METHODS:
      set_pf_status
        CHANGING
          co_alv TYPE REF TO cl_salv_table.
*   Set Top of page
    METHODS:
      set_top_of_page
        CHANGING
          co_alv TYPE REF TO cl_salv_table.
*
*   Set End of page
    METHODS:
      set_end_of_page
        CHANGING
          co_alv TYPE REF TO cl_salv_table.
*
*$*$*.....CODE_ADD_1 - End....................................1..*$*$*
*
*$*$*.....CODE_ADD_2 - Begin..................................2..*$*$*
*
*    In this area we will call the methods which will set the
*      different properties to the ALV
*
*   Setting up the default PF status
    CALL METHOD set_pf_status
      CHANGING
        co_alv o_alv.
*
*   Calling the top of page method
    CALL METHOD me->set_top_of_page
      CHANGING
        co_alv o_alv.
*
*   Calling the End of Page method
    CALL METHOD me->set_end_of_page
      CHANGING
        co_alv o_alv.
*
*$*$*.....CODE_ADD_2 - End....................................2..*$*$*
*
*$*$*.....CODE_ADD_3 - Begin..................................3..*$*$*
*
*    In this area we will implement the methods which are defined in
*      the class definition
*
  METHOD set_pf_status.
*
    DATAlo_functions TYPE REF TO cl_salv_functions_list.
*   Default Functions
    lo_functions co_alv->get_functions).
    lo_functions->set_defaultabap_true ).
*
  ENDMETHOD.                    "set_pf_status
*
  METHOD set_top_of_page.
*
    DATAlo_header  TYPE REF TO cl_salv_form_layout_grid,
          lo_h_label TYPE REF TO cl_salv_form_label,
          lo_h_flow  TYPE REF TO cl_salv_form_layout_flow.
*
*   header object
    CREATE OBJECT lo_header.
*
*   To create a Lable or Flow we have to specify the target
*     row and column number where we need to set up the output
*     text.
*
*   information in Bold
    lo_h_label lo_header->create_labelrow column ).
    lo_h_label->set_text'Header in Bold' ).
*
*   information in tabular format
    lo_h_flow lo_header->create_flowrow 2  column ).
    lo_h_flow->create_texttext 'This is text of flow' ).
*
    lo_h_flow lo_header->create_flowrow 3  column ).
    lo_h_flow->create_texttext 'Number of Records in the output' ).
*
    lo_h_flow lo_header->create_flowrow 3  column ).
    lo_h_flow->create_texttext 20 ).
*
*   set the top of list using the header for Online.
    co_alv->set_top_of_listlo_header ).
*
*   set the top of list using the header for Print.
    co_alv->set_top_of_list_printlo_header ).
*
  ENDMETHOD.                    "set_top_of_page
*
  METHOD set_end_of_page.
*
    DATAlo_footer  TYPE REF TO cl_salv_form_layout_grid,
          lo_f_label TYPE REF TO cl_salv_form_label,
          lo_f_flow  TYPE REF TO cl_salv_form_layout_flow.
*
*   footer object
    CREATE OBJECT lo_footer.
*
*   information in bold
    lo_f_label lo_footer->create_labelrow column ).
    lo_f_label->set_text'Footer .. here it goes' ).
*
*   tabular information
    lo_f_flow lo_footer->create_flowrow 2  column ).
    lo_f_flow->create_texttext 'This is text of flow in footer' ).
*
    lo_f_flow lo_footer->create_flowrow 3  column ).
    lo_f_flow->create_texttext 'Footer number' ).
*
    lo_f_flow lo_footer->create_flowrow 3  column ).
    lo_f_flow->create_texttext ).
*
*   Online footer
    co_alv->set_end_of_listlo_footer ).
*
*   Footer in print
    co_alv->set_end_of_list_printlo_footer ).
*
  ENDMETHOD.                    "set_end_of_page
*
*$*$*.....CODE_ADD_3 - End....................................3..*$*$*

This code will generate output like this:

When you print this output, it will generate a spool like:

All SALV discussions can be found under Tutorials > SALV Table Display

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

12 Comments

  • Anonymous

    how to add empty line

  • how to add empty line

    Try to add the blank line.

    Regards,
    Naimesh Patel

  • Hats off Naimesh. Nice blog.
    thanq
    SAP ABAPer, SDN

  • Does this work if you CL_SALV_TABLE is not in fullscreen mode – but inside a container?

    My Top of List header only shows if I create my ALV using
    cl_salv_table=>factory(
    IMPORTING
    r_salv_table = gr_table
    CHANGING
    t_table = t_outtab
    ).

    If I put it in a docking container the header doesn't appear.

    cl_salv_table=>factory(
    EXPORTING
    r_container = me->custom_container
    IMPORTING
    r_salv_table = gr_table
    CHANGING
    t_table = t_outtab
    ).

    Any advice?

  • Hello Paul,

    You asked:
    Does this work if you CL_SALV_TABLE is not in fullscreen mode – but inside a container?

    Unfortunatly, this doesn't work with Grid ALV.

    Regards,
    Naimesh Patel

  • Anonymous

    What ever Field is displaying in ALV is from table , if in case i want to use my own defined Field in ALV. How to manage that in Field Catalog?

  • how to increase the size of header???

  • Hello Patel,

    thank you for your example. I have a question though: I would like to add a logo in the header, unfortunately I did not make it, maybe you have an idea?
    Thanks in advance
    Samir

  • Hello Samir,

    You have asked: I have a question though: I would like to add a logo in the header, unfortunately I did not make it, maybe you have an idea?
    Unfortunately, it is not possible, but is can be achieved using workaround. Please read through the bottom section of this blog post:
    SALV Table Display – Editable SALV Model (Overcome the restriction of SALV Model)

    Regards,
    Naimesh Patel

  • Anonymous

    Hello Patel,

    i like your blog, is very important. but cann you help me please.
    I would like to make an upload of a picture/logo to use in ALV (with OO) report (Header)!!! I know It is possible but I don´t remember how to do this!! Can you help me??

    Thanks
    Verena

  • Anonymous

    Hi Naimesh Patel,

    I have a few questions:

    1. When I generate the ALV with the look&feel; of an ALV Grid, whenever I want to print, it prints in the ALV list format. I am assuming that this is inpossible to overcome. Am I right?

    2. When I print the ALV, it generates an ALV list and sends it to spool with left margin zero. Is it possible to add suppose 1-2 CM of left margin?

    3. Is it possible to define the page size of the ALV List that will be sent to spool, and display the page number on header?

    Thank you in advance for yout feedback,

    Keep up the good work, your blog is very good,

    Kind Regards,

    João Cabrita

  • Hello João Cabrita,

    As per my understanding:
    1. ALV Grid Print – No. System will always generate a List for printing. The ALV Grid is more for better interaction.

    2. Margin on Left while printing – I am not sure if it possible or not..

    3a. Page Size – Yes. we can set the pagesize while generating the ALV. Check the program BCALV_TEST_GRID_PRINT. You need to use the FM SET_PRINT_PARAMETERS to set the print parameters.

    3b. Page Number – You can use the Event PRINT_TOP_OF_LIST to print the Page Number.

    Regards,
    Naimesh Patel

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.