cancel
Showing results for 
Search instead for 
Did you mean: 

ALV ON_LEAD_SELECT not working after column sort

former_member182048
Active Contributor
0 Kudos

Hey there,

We have recently applied SP 13 and on testing of some of our custom WDABAP applications we have found a unique error. This has been raised through OSS and has come back as a consulting problem.

I am hoping that someone has faced the same issue or is able to help.

The problem

On ALV event ON_LEAD_SELECT we change some context values

- this works fine however if we use column sort and then ON_LEAD_SELECT the context changes take affect but the row is not selected.

Steps to replicate

1. Copy SALV_WD_TEST_SIMPLE1 -> YALV_WD_TEST_SIMPLE1

2. In the CC create a method

TABLE_ON_LEAD_SELECT of type 'Event Handler' subscribing to INTERFACECONTROLLER->ON_LEAD_SELECT

3. Add the following code to affect a simple context change

DATA: lr_table TYPE REF TO if_salv_wd_table_lead_select,

lr_node TYPE REF TO if_wd_context_node,

lr_element TYPE REF TO if_wd_context_element,

ls_row TYPE salv_wd_s_test,

l_index TYPE i.

lr_table ?= r_param.

l_index = lr_table->index.

lr_node ?= wd_context->get_child_node( 'TEST_DATA' ).

lr_element = lr_node->get_element( index = l_index ).

lr_element->get_static_attributes( IMPORTING static_attributes = ls_row ).

ls_row-field3 = l_index.

lr_element->set_static_attributes( EXPORTING static_attributes = ls_row ).

4. Create an application for the WD and activate and run

try selecting a row, you will notice that the change takes affect and the row is select.

Now try sort a column and reselect, the change has taken but the row is not selected.

Any help well be appreciated.

Cheers

JSP

Edited by: JSP on Mar 12, 2008 12:11 PM

Just found that the same issue was occuring in salv_wd_test_table_edit2 when you choose the option

BIND_TABLE() at WDDOMODIFY and sort a column

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hey,

Your very nearly on the right right track. Instead of your TABLE_ON_LEAD_SELECT event handler you should handle the sort with method ON_FUNCTION_AFTER

type: Event Handler

performed: ON_STD_FUNCTION_AFTE

controller: INTERFACECONTROLLER

component: USAGE_ALV.

here's my sample code to set the lead selection after a sort to the first row ( index 1 ).

data:
    lo_nd_vcats type ref to if_wd_context_node,
    lo_nd_vendors type ref to if_wd_context_node,
    lo_nd_prodcats type ref to if_wd_context_node,
    lo_el_prodcats type ref to if_wd_context_element.
  
case r_param->id.
    when if_salv_wd_c_std_functions=>sort_define.

*       navigate from <CONTEXT> to <VCATS> via lead selection
      lo_nd_vcats = wd_context->get_child_node( name = wd_this->wdctx_vcats ).

*       navigate from <VCATS> to <VENDORS> via lead selection
      lo_nd_vendors = lo_nd_vcats->get_child_node( name = wd_this->wdctx_vendors ).

*       navigate from <VENDORS> to <PRODCATS> via lead selection
      lo_nd_prodcats = lo_nd_vendors->get_child_node( name = wd_this->wdctx_prodcats ).

*       access <PRODCATS> via index
       lo_el_prodcats = lo_nd_prodcats->get_element( index = 1 ).

       lo_nd_prodcats->set_lead_selection( element = lo_el_prodcats ).

    when others.
*  other event processing here...
  endcase.

Hope this fixes your problem,

Damian.

Former Member
0 Kudos

Hi,

To retrive the selected rows of the table after any operation on the table, you can use the following methods of IF_WD_CONTEXT_NODE

SET_LEAD_SELECTION

SET_LEAD_SELECTION_INDEX

SET_SELECTED

to reset the selected nodes.

You will need to collect the index or reference of the selected rows before any operation is performed.

Hope this helps.

Regards,

Kinshuk

former_member182048
Active Contributor
0 Kudos

Hi Kinsuk,

Thanks for your suggestions, I tried them

lr_node->set_lead_selection( lr_element ).

lr_node->set_lead_selection_index( l_index ).

lr_node->set_selected( EXPORTING flag = abap_true index = l_index ).

No luck.

cheers

jsp

Former Member
0 Kudos

Hi Jsp,

Check the code below, it works fine for me.

DATA:lr_current_node    TYPE REF TO if_wd_context_node,
       lr_current_element TYPE REF TO if_wd_context_element.


  lr_current_node    = wd_context->get_child_node( 'CON1' ).
* get the element(s) to bind 

  lr_current_node->bind_element( lr_current_element ).
  *lr_current_node->set_lead_selection( lr_current_element ).*

lr_current_element is the reference to the selected node before any operation on table. you might have to store these references before hand by creating a node in the context having a single attribute of type ref to if_wd_context_element. and later loop through this context table to set the lead selection.

Hope this helps.

Regards,

Kinshuk

former_member182048
Active Contributor
0 Kudos

Hi kinshuk,

Doesnt that defeat the purpose of having on lead select in ALV?

Cheers

jsp