cancel
Showing results for 
Search instead for 
Did you mean: 

ALV event ON_CLICK -> find out selected row?

daniel_humberg
Contributor
0 Kudos

I have an ALV table and in one of the columns I display a linkToAction in each cell.

When the link is clicked, i go to the ON_CLICK event handler and try to find out, which row is selected.

For this, I can take the attribute "INDEX" of the parameter "R_PARAM", and read the context with the given index.


 METHOD alv_event_on_click .
   DATA lo_nd_my_node    TYPE REF TO if_wd_context_node.
   DATA lt_my_table          TYPE wd_this->elements_my_table.
   DATA ls_my_structure    TYPE wd_this->element_my_struture.

*  click on prduct standard name link
   IF r_param->attribute = 'NAME_OF_THE_COLUMN'.

       lo_nd_my_node = wd_context->get_child_node( name = wd_this->wdctx_my_node ).
       lo_nd_my_node->get_static_attributes_table( IMPORTING table = lt_my_table ). "this is not sorted!!!!

       lo_nd_my_node->set_lead_selection_index( index = r_param->index ).
       READ TABLE lt_my_table INTO ls_my_structure INDEX r_param->index. "lt_my_table table might be sorted differently!!!!
       IF sy-subrc = 0.
         wd_this->do_something_with( ls_my_strcture ).
       ENDIF.
   ENDIF.
 ENDMETHOD.

However, this does not work when I sort the ALV before!

For a strange reason, the table that I get from the context is not sorted the same way as the data in the ALV.

What can I do?

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Daniel,

Do you use the sort of the ALV or do you sort the data in the node from within your coding.

I have just tested an example where i used the ALV sorting. When i retrieve the table, it's sorted exaclty the same as in my ALV.

I assume the node you are reading is also the one that is mapped to the ALV?

Regards,

Jos

daniel_humberg
Contributor
0 Kudos

Hi Jos,

thx for the analysis.

I use the built-in sort function of the ALV.

And yes, the node that I am reading is the same that is bound to the ALV.

(this node has an external mapping to a node in another component).

Regards,

Daniel

Former Member
0 Kudos

Hi Daniel,

I don't know if the external mapping messes things up.

Perhaps you could try the following:

lo_nd_my_node->get_static_attributes(

EXPORTING

index = r_param->index

IMPORTING

static_attributes = ls_my_structure ).

It could be that passing the data towards your internal table doesn't take over the sort.

If you try debugging and check out the contents of the node, are they sorted correctly or not?

Regards and good luck.

Jos

daniel_humberg
Contributor
0 Kudos

Hi Jos,

I tried your suggestion, but it leads to the same problem.

I debugged into the method as suggested, and I saw that the table inside the context-node is not sorted in the same way than the ALV, but that is still has the initial sorting. Any other idea?

Thx for any help, and best regards,

Daniel

Former Member
0 Kudos

Hi Daniel,

Too bad the previous options didn't work out.

Have you tried the same without the external mapping?

Perhaps this external mapping and sorting don't work together properly.

What i can imagine is that the sorting that is done by the ALV component isn't passed back towards the external context node and therefore isn't sorted at the time you try to read the correct record.

Regards and good luck.

Jos

daniel_humberg
Contributor
0 Kudos

Hi Jos,

i found the reason. There was another context node that was disturbing the sorting.

So it has nothing to do with external context mapping.

I rewarded the points and will set the question to answered.

Thx for the help,

Daniel

Former Member
0 Kudos

Hi Daniel,

I'm glad you sorted it out.

Thanks for the points and good luck!

Jos