Sorts in ALV OO (cl_salv_table) - Problem
I have a serious problem using an ALV for displaying an internal table. I have added a user-defined function (on_user_command) that triggers the event added_function and is executed by clicking on a user-defined button.
In this function I read the selected row of the alv (selection-mode is single-select):
lr_selections = mr_alv->get_selections( ).
lt_rows = lr_selections->get_selected_rows( ).
READ TABLE lt_rows INTO lv_row_idx INDEX 1.
With this row index I now read the primary key of my internal table:
DATA ls_compl LIKE LINE OF mr_compl_table. READ TABLE mr_compl_table INDEX lv_row_idx INTO ls_compl. lv_trkorr = ls_compl-trkorr.
Then I do the further processing with the primary key (lv_trkorr). The problem now is, that when the user sorted the ALV, the index of the selected row isn't the same as the original row index in my internal table and so I get the wrong primary key.
Do you guys have any idea of how to solve this?
I thought about 2 possibilities, but have no idea how to implement them:
1) read the internal table that is used in ALV-Class directly (not my own internal table)
2) when the ALV-Table is sorted (or edited in another way) do the same manipulations on my internal table
I hope you can give me a hint/sample coding how to solve this problem.
Thanks in advance!
One option might be to use the GET_SORTS method to find how the display is currently sorted and use this to sort your internal table into the same order.
I would also ask does a filter applied by the user have the same effect - changing the index if some rows have been hidden. If so you may also need to use GET_FILTERS to cope with this?