Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

CL_SALV_* classes and fixing columns.

Hi All -

I'm having some trouble with the new OO-ALV classes.

I'm trying to fix the first column in place so that when the user scrolls, the column stays there. In the function module based ALV model, I could just set the fix_column field in the field catalog.

I had thought that the set_key() method of the column object along with the set_key_fixation() of the columns attributes would do it, but I can't it to work.

I can freeze the field manually if I run the report and right click on the column I want to freeze, but I'd like to default it that way in the code.

Do you guys see anything wrong with my code below? Am I missing something?

Thanks in advance.

-Bryan

*----------------------------------------------------------------------*
*   Data definition
*----------------------------------------------------------------------*
* ALV variables.
DATA: oref_table          TYPE REF TO cl_salv_table,
      oref_functions      TYPE REF TO cl_salv_functions,
      oref_columns        TYPE REF TO cl_salv_columns_table,
      oref_column         TYPE REF TO cl_salv_column_table,
      oref_layout         TYPE REF TO cl_salv_layout,
      oref_display        TYPE REF TO cl_salv_display_settings,
      oref_sorts          TYPE REF TO cl_salv_sorts,
      oref_aggregations   TYPE REF TO cl_salv_aggregations,
      g_repid             TYPE sy-repid,
      g_layout_key        TYPE salv_s_layout_key,
      g_layout            TYPE salv_s_layout,
      gt_columns          TYPE salv_t_column_ref.

*----------------------------------------------------------------------*
*   Initialization
*----------------------------------------------------------------------*
INITIALIZATION.

  g_repid = sy-repid.

* instantiate the table and the layout in the initialization section
* so we can use a method of the layout class for the f4 help.
  TRY .
      cl_salv_table=>factory(
        IMPORTING
          r_salv_table   = oref_table
        CHANGING
          t_table        = gt_output
             ).
    CATCH cx_salv_msg.

  ENDTRY.

  oref_layout = oref_table->get_layout( ).
  g_layout_key-report = g_repid.
  oref_layout->set_key( g_layout_key ).

* only let the user save user-specific layouts - this needs to be set in
* init for the f4 to work right
  oref_layout->set_save_restriction( cl_salv_layout=>restrict_user_dependant ).

*----------------------------------------------------------------------*
*   At selection-screen
*----------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.
* call the f4 help and set the layout variable.
  g_layout = oref_layout->f4_layouts( ).
  p_vari = g_layout-layout.

*----------------------------------------------------------------------*
*   END-OF-SELECTION
*----------------------------------------------------------------------*
END-OF-SELECTION.

  PERFORM display_alv.

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV
*&---------------------------------------------------------------------*
*       Call ALV related functions.
*----------------------------------------------------------------------*
FORM display_alv .


* create the fucntion object and force all to available.
  oref_functions = oref_table->get_functions( ).
  oref_functions->set_all( abap_true ).

* create the display settings object and set the various attributes
  oref_display = oref_table->get_display_settings( ).
  oref_display->set_striped_pattern( cl_salv_display_settings=>true ).
  oref_display->set_fit_column_to_table_size( cl_salv_display_settings=>true ).
  oref_display->set_list_header( 'Complaints Reporting' ).

* create the columns object and apply the ddic structure to the otuput
  oref_columns = oref_table->get_columns( ).
  oref_columns->apply_ddic_structure( name = c_structure ).
  oref_columns->set_key_fixation( ).

* lock the notification number column
  TRY .
      oref_column ?= oref_columns->get_column( 'QMNUM' ).
    CATCH cx_salv_not_found.
  ENDTRY.
  IF oref_column IS BOUND.
    oref_column->set_key( ).
    oref_column->set_key_presence_required( ).
  ENDIF.

* set the data in the table.
  TRY .
      oref_table->set_data( CHANGING t_table = gt_output   ).
    CATCH cx_salv_no_new_data_allowed.

  ENDTRY.

* set the layout variant if one has been chosen.
  IF NOT p_vari IS INITIAL.
    oref_layout->set_initial_layout( value = p_vari   ).
  ELSE.

* update sort info
    oref_sorts = oref_table->get_sorts( ).
    TRY .
        oref_sorts->add_sort( columnname = 'QMNUM'  ).
      CATCH cx_salv_data_error.
      CATCH cx_salv_not_found.
      CATCH cx_salv_existing.

    ENDTRY.
  ENDIF.

* display the table.
  oref_table->display( ).

ENDFORM.                    " DISPLAY_ALV

Tags:
Not what you were looking for? View more on this topic or Ask a question