cancel
Showing results for 
Search instead for 
Did you mean: 

Get column index

RicardoRomero_1
Active Contributor
0 Kudos

Hi all,

I have a table with several columns, in each column i have the same action for the event onEnter.

I want to know the index of the column that has triggered the event.

I've debugged the method and I think the attribute that has the index is _PERS_INDEX of class cl_wd_table_column. But this attribute is protected and I couldn't find a public method for retrieve it.

Do you know how can I get this index?

I've tried to use a local class that inherit from the class CL_WD_TABLE_COLUMN for get the protected attribute. I've created a public method for get the index but by the moment doesn't work, there is a casting error:

During a 'CAST' operation ('?=' oder 'MOVE ? TO')a type conflict occurred. The source type '\CLASS=CL_WD_TABLE_COLUMN' is not compatible for assigning with the target type '\FUNCTION-POOL=ZTEST_FG

\CLASS=LCL_COLUMN

This is my code:

Method onEnter

    DATA: lo_ui_elem TYPE REF TO cl_wd_input_field,
        lo_ui_col  TYPE REF TO cl_wd_table_column,
        lo_ui_table TYPE REF TO cl_wd_table.
 
DATA: lv_index TYPE i.
  
  lo_ui_elem ?= wd_this->main_view->get_element( id ).
  lo_ui_col ?= lo_ui_elem->get__parent( ).

  CALL FUNCTION 'ZGET_COLUMN_INDEX'
    EXPORTING
      io_column       = lo_ui_col
   IMPORTING
     EV_INDEX        = lv_index.

FM ZGET_COLUMN_INDEX

   FUNCTION ZGET_COLUMN_INDEX.
*"----------------------------------------------------------------------
*"*"Interfase local
*"  IMPORTING
*"     REFERENCE(IO_COLUMN) TYPE REF TO  CL_WD_TABLE_COLUMN
*"  EXPORTING
*"     REFERENCE(EV_INDEX) TYPE  I
*"----------------------------------------------------------------------

  DATA: lo_column TYPE REF TO lcl_column,
        lo_cast_error TYPE REF TO cx_sy_move_cast_error,
        lv_text TYPE string,
        lv_longtext TYPE string.

  TRY.
    lo_column ?= io_column.   "Here is the casting error
    CATCH cx_sy_move_cast_error INTO lo_cast_error.
          lv_text = lo_cast_error->IF_MESSAGE~GET_TEXT( ).
          lv_longtext = lo_cast_error->IF_MESSAGE~GET_LONGTEXT( ).
  ENDTRY.

  ev_index = lo_column->get_index( ).

ENDFUNCTION.

Local class in TOP include

   CLASS lcl_column DEFINITION INHERITING FROM CL_WD_TABLE_COLUMN.
  PUBLIC SECTION.
    METHODS: get_index RETURNING VALUE(index) TYPE i.
ENDCLASS.


CLASS lcl_column IMPLEMENTATION.
METHOD get_index.

   index = _pers_index.

ENDMETHOD.
ENDCLASS.

Do you know how to do it? or what i'm doing wrong in my code?

Regards,

Ricardo.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

I think you can look at the attribute, parameters in wdevents which will have the id /context element from which you should be able to find

thanks

RicardoRomero_1
Active Contributor
0 Kudos

Hi Chinna and Erhan, thanks for your answers.

I've already checked the attributes id and context element but I couldn't find a proper way to get the column index.

EDIT: I think I have the way to obtain it, I can use the method get_columns of the table UI and check each one by the ID of the column.

chengalarayulu
Active Contributor
0 Kudos

Ricardo,

1. Get the TableUI Element reference, CL_WD_TABLE

2. Call the method GET_COLUMN which returns CL_WD_TABLE_COLUMN ---           <lr_selected_column>

3. Call the method  GET_COLUMNS which returns table of CL_WD_TABLE_COLUMN

4.

     Loop at <table_columns> into <ls_table_column>.

    

          if <ls_table_column> eq <lr_selected_column>.

               lv_index = sy-tabix.

               exit.

          endif.

     endloop.

Hope this may help you.

RicardoRomero_1
Active Contributor
0 Kudos

Hi Chengalarayulu,

Thanks, I've just thought the same solution.

Former Member
0 Kudos

Hi,

You can get column name. Does that fulfill your requirement?    

RicardoRomero_1
Active Contributor
0 Kudos

Nop, I need the index because the user can change the order of the columns in run time, but I can get this index with the way explained above by Chengalarayulu. Thanks !

Former Member
0 Kudos

I dont have access now but you can try to pass ui params in method. While creating event you can set it by a checkbox.