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: 

Change Column property for ALV using FACTORY method

Former Member
0 Kudos

Hi,

Please find the code below, there is no change for the Column header names.

Kindly guide me.


*- Final Internal Table
Types:
        BEGIN OF gy_final,
          vstel   TYPE vstel,         "Shipping Point
          matnr   TYPE matnr,         "Material Number
          maktx   TYPE maktx,         "Material Description
          profl   TYPE adge_profl,    "Dangerous Goods Indicator Profile
          lfimg   TYPE lfimg,         "Actual quan delivered (in sales units)
          packm   TYPE matnr,     
          pakwt   TYPE lfimg,
          qpackm  TYPE lfimg,     "Quantity of packing material
          pmatty  TYPE mtart,     "Type of packing material
        END OF gy_final,

CONSTANTS:
        lc_error            TYPE symsgty VALUE 'E'.

  DATA:
        lt_columns          TYPE REF TO   cl_salv_columns_table,
*- Individual Column
        lt_column           TYPE REF TO   cl_salv_column,
        lt_salv_not_found   TYPE REF TO   cx_salv_not_found,
        lt_salv_msg         TYPE REF TO   cx_salv_msg,
*- Exception class
        lv_msg              TYPE          string,
        lv_col_l            TYPE          scrtext_l,
        lv_col_m            TYPE          scrtext_m,
        lv_col_s            TYPE          scrtext_s.


*- Get all the Columns
  lt_columns = pi_alv_output->get_columns( ).
*- Set Column optimization
  lt_columns->set_optimize( 'X' ).

*- Change the properties of Individual Columns
  TRY.
*- 'LFIMG' = Quantity delivered
      CLEAR lv_col_m.
      lt_column = lt_columns->get_column( 'LFIMG' ).
      lv_col_m = text-001.
      lt_column->set_medium_text( lv_col_m ).
      lt_column->set_output_length( 25 ).

*- Catch the Exceptions
    CATCH cx_salv_not_found INTO lt_salv_not_found.
      lv_msg = lt_salv_not_found->get_text( ).
      MESSAGE lv_msg TYPE lc_error.
  ENDTRY.

  TRY.
*- 'PACKM' = Packing Material
      CLEAR lv_col_m.
      lt_column = lt_columns->get_column( 'PACKM' ).
      lv_col_m = text-002.
      lt_column->set_medium_text( lv_col_m ).
      lt_column->set_output_length( 25 ).

*- Catch the Exceptions
    CATCH cx_salv_not_found INTO lt_salv_not_found.
      lv_msg = lt_salv_not_found->get_text( ).
      MESSAGE lv_msg TYPE lc_error.
  ENDTRY.

  TRY.
*- 'PAKWT' = Packaging Weight in KG
      CLEAR lv_col_l.
      lt_column = lt_columns->get_column( 'PAKWT' ).
      lv_col_m = text-005.
      lt_column->set_long_text( lv_col_l ).
      lt_column->set_output_length( 30 ).

*- Catch the Exceptions
    CATCH cx_salv_not_found INTO lt_salv_not_found.
      lv_msg = lt_salv_not_found->get_text( ).
      MESSAGE lv_msg TYPE lc_error.
  ENDTRY.


  TRY.
*- 'QPACKM' = Packing Material Quan.
      CLEAR lv_col_l.
      lt_column = lt_columns->get_column( 'QPACKM' ).
      lv_col_l = text-003.
      lt_column->set_long_text( lv_col_l ).
      lt_column->set_output_length( 30 ).
*- Catch the Exceptions
    CATCH cx_salv_not_found INTO lt_salv_not_found.
      lv_msg = lt_salv_not_found->get_text( ).
      MESSAGE lv_msg TYPE lc_error.
  ENDTRY.

  TRY.
*- 'PMATTY' = Packing Material Type
      CLEAR lv_col_l.
      lt_column = lt_columns->get_column( 'PMATTY' ).
      lv_col_l = text-004.
      lt_column->set_long_text( lv_col_l ).
      lt_column->set_output_length( 30 ).
*- Catch the Exceptions
    CATCH cx_salv_not_found INTO lt_salv_not_found.
      lv_msg = lt_salv_not_found->get_text( ).
      MESSAGE lv_msg TYPE lc_error.
  ENDTRY .

Edited by: Raj on Sep 10, 2010 7:27 PM

5 REPLIES 5

kesavadas_thekkillath
Active Contributor
0 Kudos

Try avoiding this line.

lt_columns->set_optimize( 'X' ).

naimesh_patel
Active Contributor
0 Kudos

Try to set all the three text for the Column using the methods SET_SHORT_TEXT, SET_MEDIUM_TEXT & SET_LONG_TEXT. You can also check this blog post: http://help-abap.blogspot.com/2008/09/salv-model-7-changing-column-settings.html

Regards,

Naimesh Patel

0 Kudos

Hello Raj

Naimesh has paved the way for you. On ERP 6.0 you will sample report SALV_DEMO_TABLE_COLUMNS teaching you a lot about column settings, e.g.:


...
*... §4.1 set exception column
  try.
      lr_columns->set_exception_column( 'EXCEPTION' ).
    catch cx_salv_data_error.                           "#EC NO_HANDLER
  endtry.
  try.
      lr_column ?= lr_columns->get_column( 'EXCEPTION' ).
      lr_column->set_short_text( 'MY EXCEPT' ).
      lr_column->set_medium_text( 'MY EXCEPTION' ).
      lr_column->set_long_text( 'MY EXCEPTION COLUMN' ).
    catch cx_salv_not_found.                            "#EC NO_HANDLER
  endtry.

*... §4.9 set icon tooltips
  data: lr_functional_settings type ref to cl_salv_functional_settings.

  lr_functional_settings = gr_table->get_functional_settings( ).

  perform set_tooltips using lr_functional_settings.

*... §4.2 set icon column
  try.
      lr_column ?= lr_columns->get_column( 'ICON' ).
      lr_column->set_icon( if_salv_c_bool_sap=>true ).
      lr_column->set_long_text( 'ICON' ).
    catch cx_salv_not_found.                            "#EC NO_HANDLER
  endtry.

*... §4.3 set symbol column
...

Regards

Uwe

anesh_kumar
Active Participant
0 Kudos

Hi

maintain null value to both medium and short text

than you can see long text for all the fields

see the below code

l_column->set_long_text( 'this is long text' ).

l_column->set_medium_text( ' ' ).

l_column->set_short_text( ' ' ).

Let me know how it goes

Regards

Former Member
0 Kudos

Thanks for all your comments. I have maintained space for long and short. And finally I got the column property changed.