Skip to Content
0
Former Member
Sep 10, 2010 at 01:56 PM

Change Column property for ALV using FACTORY method

4811 Views

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