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 Center Align Header Text in SALV

spartans007
Participant
0 Kudos
521

Hello,

I am facing an issue to set my header text in center.

I want to center align my text. How do i get my header text exactly in the center?

I have attached my code below. I tried Multiple ways but the position my text did not change. I want to align the header text in the center.

Thank You.

 METHOD display_alv.
*Create alv object.
    TRY.
        CALL METHOD cl_salv_table=>factory
          IMPORTING
            r_salv_table = lo_gr_alv
          CHANGING
            t_table      = gt_finanl.

      CATCH cx_salv_msg.
    ENDTRY.

    lo_gr_alv->set_screen_status( pfstatus      = 'STANDARD_FULLSCREEN'
                                  report        = 'SAPLSLVC_FULLSCREEN'
                                  set_functions = lo_gr_alv->c_functions_all
                                    ).

* Show all alv functions.
    lo_gr_functions = lo_gr_alv->get_functions( ).
    lo_gr_functions->set_all( abap_true ).
    lo_gr_functions->set_export_wordprocessor( abap_true ).

* Fit the columns
    lo_columns = lo_gr_alv->get_columns( ).
    lo_columns->set_optimize( abap_true ).


** Code to remove coloumn or change text for reference
*   try.
*       Lo_column ?= lo_columns->get_column( 'mandt' ).
*       Lo_column->set_visible( if_salv_c_bool_sap=>false ).
**      Lo_column->set_long_text( 'mytitle' ).
**      Lo_column->set_medium_text( 'mytitle' ).
**      Lo_column->set_short_text( 'mytitle' ).
*     Catch cx_salv_not_found.
*     Catch cx_salv_existing.
*     Catch cx_salv_data_error.
*   Endtry.

* header object
    CREATE OBJECT lo_header.

* Information in bold
    lo_h_label = lo_header->create_label( row = 1 column = 3 ).
    lo_h_label->set_text( gc_header ).

    lv_text = TEXT-100 && p_name.
    lo_h_label = lo_header->create_label( row = 2 column = 1 ).
    lo_h_label->set_text( lv_text ).

* Set the top of list using the header.
    lo_gr_alv->set_top_of_list( lo_header ).
* Set the top of list using the header for print.
    lo_gr_alv->set_top_of_list_print( lo_header ).

    lr_layout = lo_gr_alv->get_layout( ).
    ls_key-report = sy-repid.
*  If uv_change_mode = abap_true.
    ls_key-handle = 'h0ch'.
    lr_layout->set_key( ls_key ).
    lr_layout->set_default( abap_true ).
    lr_layout->set_save_restriction( '3' ).

* Display alv
    lo_gr_alv->display( ).
  ENDMETHOD.
ENDCLASS.

<br>
1 REPLY 1

Sandra_Rossi
Active Contributor
462

That's not supported by SALV (as many other things), only directly with the OCX control (via CL_GUI_ALV_GRID).

Style values are defined in the include <CL_ALV_CONTROL>. It has been already discussed in the forum, so I let you search.

Accessing the control (CL_GUI_ALV_GRID instance) from SALV has been already discussed too.