Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the header in SALV?

fredericbasilius
Participant

Hi,

I am using SALV for displaying the report. My requirement is that I need to display header for the ALV displayed. So I used method "set_list_header" as shown below.

DATA: lr_display   TYPE REF TO cl_salv_display_settings,

            lv_header  TYPE        c LENGTH 150.

             lr_display = lr_table->get_display_settings( ).


             lr_display->set_striped_pattern( con_x ).


             lv_header = 'Test Header'.

             IF lv_header IS NOT INITIAL.

                 lr_display->set_list_header( lv_header ).

             ENDIF.

But the problem here is that the list header length is limited to 70 characters. So i used the SET_TOP_OF_LIST

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.

     LO_H_LABEL = LO_HEADER->CREATE_LABEL( ROW = 1 COLUMN = 1 ).

     LO_H_LABEL->SET_TEXT( lv_header ).


* Set the top of list using the header for Online

     lr_table->SET_TOP_OF_LIST( LO_HEADER ).

* Set the top of list using the header for Print

     lr_table->SET_TOP_OF_LIST_PRINT( LO_HEADER ).


But now the header is not getting displayed.


Kindly help.


Regards,

FB

1 ACCEPTED SOLUTION

fredericbasilius
Participant

Hi,

Thanks Naveen and Gayatri for your suggestion.

While debugging  an exception was shown like ' For full screens and list only'. I think top of page is not applicable for ALV displayed in the subscreen. So I resolved this by using the splitter container. The custom container was split into two container, one for ALV and one for displaying a header text. Thus resolved the requirement.

Regards,

FB

6 REPLIES 6

Former Member

Hi Fredric,

The second case that you provided works perfectly fine in my case.

But you may also try the code snippet below:


DATA:

          lo_header  TYPE REF TO cl_salv_form_layout_grid,

          lo_h_label TYPE REF TO cl_salv_form_label.

DATA:  lv_text TYPE char100.

*   header object

   CREATE OBJECT lo_header.

   lv_text = 'Test report'.


*   information in Bold

   lo_h_label = lo_header->create_label( row = 1   column = 1 ).

   lo_h_label->set_text( lv_text ).


*   set the top of list using the header.

   g_alv->set_top_of_list( lo_header ).

*

*   set the top of list using the header for Print.

   g_alv->set_top_of_list_print( lo_header ).

It might work!

Hope this helps!


Regards,

Gayatri

0 Kudos

Hi Gayatri,

Thank for your suggestion.I tried the above solution but its not working for me. Do i have to enable any other configurations like layout or alv funtions or something , so that the header should be displayed. I am new to SALV.

Regards,

FB

former_member196601
Active Participant
0 Kudos

Hi Fredric,

Please try something like below code:

DATA: lv_text       TYPE string,

         ls_message    TYPE ty_message,

         lt_message    TYPE ty_t_message,

         lo_salv_table TYPE REF TO cl_salv_table.

   lt_message  = it_message.

   TRY.

       CALL METHOD cl_salv_table=>factory

         IMPORTING

           r_salv_table = lo_salv_table

         CHANGING

           t_table      = gt_alv_output.

     CATCH cx_salv_msg .

   ENDTRY.

   PERFORM report_header USING lt_message

                      CHANGING lo_salv_table.

   lo_salv_table->display( ).


*&---------------------------------------------------------------------*

*&      Form  REPORT_HEADER

*&---------------------------------------------------------------------*

*       Display report header

*----------------------------------------------------------------------*

FORM report_header USING it_message     TYPE ty_t_message

                 CHANGING co_salv_table  TYPE REF TO cl_salv_table.

*-- ALV Header declarations

   DATA: lv_lines        TYPE i,

         lv_linesc(10)   TYPE c,

         lv_row          TYPE i,

         lv_column       TYPE i,

         lv_date_from    TYPE char10,

         lv_date_to      TYPE char10,

         lv_text         TYPE char255,

         ls_message      TYPE ty_message,

         lo_header       TYPE REF TO  cl_salv_form_element,

         lo_layout_grid  TYPE REF TO cl_salv_form_layout_grid,

         lo_layout_mgrid TYPE REF TO cl_salv_form_layout_grid,

         lo_value        TYPE REF TO cl_salv_form_header_info.

*-- Creating the layout object

   CREATE OBJECT lo_layout_mgrid.

*-- Setting the Header Text

   lo_layout_mgrid->create_grid( EXPORTING row    = 1

                                           column = 1

                                 RECEIVING r_value = lo_layout_grid ).

   lo_layout_grid->create_label( row     = 1

                                 column  = 1

                                 text    = 'Results').

   lo_layout_mgrid->create_grid( EXPORTING row     = 2

                                           column  = 1

                                 RECEIVING r_value = lo_layout_grid ).

   lv_row = lv_row + 1.

   lo_layout_grid->create_label( row     = lv_row

                                 column  = 1

                                 text    = 'Date:' ).

   lo_layout_grid->create_text( row      = lv_row

                                column   = 2

                                text     = sy-datum ).

   lv_row = lv_row + 1.

   lo_layout_grid->create_label( row     = lv_row

                                 column  = 1

                                 text    = 'Run by' ).

   lo_layout_grid->create_text( row      = lv_row

                                column   = 2

                                text     = sy-uname ).

   lo_header = lo_layout_mgrid.

   co_salv_table->set_top_of_list( lo_header ).


endform.



Thanks,

Naveen

0 Kudos

Hi Naveen,

I tried the above solution but its not working.

I am displaying the alv in a Subscreen inside tabstrip. Any idea on the issues related to this ?

fredericbasilius
Participant

Hi,

Thanks Naveen and Gayatri for your suggestion.

While debugging  an exception was shown like ' For full screens and list only'. I think top of page is not applicable for ALV displayed in the subscreen. So I resolved this by using the splitter container. The custom container was split into two container, one for ALV and one for displaying a header text. Thus resolved the requirement.

Regards,

FB

0 Kudos

Thank you Fredric for sharing your solution too!