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

Posted by Krishh Webworld | 10:56 AM | , , | 0 comments »

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.
*
DATA: lo_functions TYPE REF TO cl_salv_functions_list.
* Default Functions
lo_functions = co_alv->get_functions( ).
lo_functions->set_default( abap_true ).
*
ENDMETHOD. "set_pf_status
*
METHOD set_top_of_page.
*
DATA: lo_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_label( row = 1 column = 1 ).
lo_h_label->set_text( 'Header in Bold' ).
*
* information in tabular format
lo_h_flow = lo_header->create_flow( row = 2 column = 1 ).
lo_h_flow->create_text( text = 'This is text of flow' ).
*
lo_h_flow = lo_header->create_flow( row = 3 column = 1 ).
lo_h_flow->create_text( text = 'Number of Records in the output' ).
*
lo_h_flow = lo_header->create_flow( row = 3 column = 2 ).
lo_h_flow->create_text( text = 20 ).
*
* set the top of list using the header for Online.

co_alv->set_top_of_list( lo_header ).
*
* set the top of list using the header for Print.
co_alv->set_top_of_list_print( lo_header ).
*
ENDMETHOD. "set_top_of_page
*
METHOD set_end_of_page.
*
DATA: lo_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_label( row = 1 column = 1 ).
lo_f_label->set_text( 'Footer .. here it goes' ).

*
* tabular information
lo_f_flow = lo_footer->create_flow( row = 2 column = 1 ).
lo_f_flow->create_text( text = 'This is text of flow in footer' ).

*
lo_f_flow = lo_footer->create_flow( row = 3 column = 1 ).
lo_f_flow->create_text( text = 'Footer number' ).
*
lo_f_flow = lo_footer->create_flow( row = 3 column = 2 ).
lo_f_flow->create_text( text = 1 ).
*
* Online footer
co_alv->set_end_of_list( lo_footer ).
*
* Footer in print
co_alv->set_end_of_list_print( lo_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.

0 comments

Archives

Subscribe Now: Feed Icon