This website is not affiliated with, sponsored by, or approved by SAP AG.

change title of each column in a ALV cl_salv_table

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Re: change title of each column in a ALV cl_salv_table

Postby Grogan » Sun Jan 04, 2015 3:07 pm

Method GET_COLUMN is passed the technical column name, not a title or description. As far as I know a column should always have a technical name.

Note that CL_SALV_COLUMNS_TABLE has a table attribute T_COLUMNS and a method GET to return it. This consists of the technical column name and a reference to CL_SALV_COLUMN. You can use this method call or just inspect the attibute contents in the debugger to confirm your column names.
Grogan

Award cash if useful.
Grogan
 
Posts: 365
Joined: Thu Aug 04, 2005 7:16 pm
Location: Australia

Re: change title of each column in a ALV cl_salv_table

Postby Grogan » Mon Jan 05, 2015 3:41 pm

Correct - when I said "CL_SALV_COLUMNS_TABLE" I was referring generically to the class. In your example this means object reference variable "COLUMNS".

I don't believe you can align ALV headers and data separately. Alignment always applies to the whole column: both header and data.

Cheers,
Grogan

Award cash if useful.
Grogan
 
Posts: 365
Joined: Thu Aug 04, 2005 7:16 pm
Location: Australia

Re: change title of each column in a ALV cl_salv_table

Postby asix78 » Fri Jan 23, 2015 8:38 am

Code: Select all
*&---------------------------------------------------------------------*
*&      Form  mode_view_grid_display
*&---------------------------------------------------------------------*
*       Show grid
*----------------------------------------------------------------------*
FORM mode_view_grid_display.

  DATA:
    lr_salv             TYPE REF TO cl_salv_table,
    lr_layout           TYPE REF TO cl_salv_layout,
    lr_display_settings TYPE REF TO cl_salv_display_settings,
    lr_functions        TYPE REF TO cl_salv_functions_list,
    ls_key              TYPE salv_s_layout_key,
    lr_columns          TYPE REF TO cl_salv_columns_table,
    lr_column           TYPE REF TO cl_salv_column_table,
    lt_column_table     TYPE salv_t_column_ref,
    lv_text_s           TYPE scrtext_s,
    lv_text_m           TYPE scrtext_m,
    lv_text_l           TYPE scrtext_l,
    lv_text             TYPE char100.
  FIELD-SYMBOLS:
    <column_table>      TYPE salv_s_column_ref.

  TRY.
      CALL METHOD cl_salv_table=>factory
        IMPORTING
          r_salv_table = lr_salv
        CHANGING
          t_table      = gt_outtab_view.
    CATCH cx_salv_msg .
  ENDTRY.

  lr_display_settings = lr_salv->get_display_settings( ).
  lr_display_settings->set_list_header( 'Requisites in SAP HR'(h01) ).

  ls_key-report = sy-repid.
  ls_key-handle = '0001'.
  lr_layout = lr_salv->get_layout( ).
  lr_layout->set_save_restriction( if_salv_c_layout=>restrict_user_independant ).
  lr_layout->set_key( ls_key ).
  lr_layout->set_default( abap_on ).

  lr_functions = lr_salv->get_functions( ).
  lr_functions->set_all( ).

  lr_columns = lr_salv->get_columns( ).
  lt_column_table[] = lr_columns->get( ).
  LOOP AT lt_column_table ASSIGNING <column_table>.
    lr_column ?= lr_columns->get_column( <column_table>-columnname ).

    CASE <column_table>-columnname.
      WHEN 'TCODE'.     lv_text = 'Retail'(f02).
      WHEN 'TNAME'.     lv_text = 'NameRet'(f03).
      WHEN 'KPP00'.     lv_text = 'Code 1'(f04).
      WHEN 'OKATO'.     lv_text = 'Code 2'(f05).
      WHEN 'LNAAM'.     lv_text = 'Name'(f06).
      WHEN 'KNAAM'.     lv_text = 'Number'(f07).
      WHEN 'LIFNR'.     lv_text = 'Contragent'(f08).
      WHEN 'OBJID'.     lr_column->set_technical( if_salv_c_bool_sap=>true ).
      WHEN 'TELNR'.     lv_text = 'Telephone number'(f14).
      WHEN OTHERS. CONTINUE.
    ENDCASE.

    lv_text_s = lv_text.   lr_column->set_short_text( lv_text_s ).
    lv_text_m = lv_text.   lr_column->set_medium_text( lv_text_m ).
    lv_text_l = lv_text.   lr_column->set_long_text( lv_text_l ).
  ENDLOOP.

  lr_salv->display( ).

ENDFORM.                    "mode_view_grid_display
asix78
 
Posts: 3
Joined: Fri Jan 23, 2015 7:29 am


Return to ABAP

Who is online

Users browsing this forum: No registered users and 11 guests





loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.