Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Sorts in ALV OO (cl_salv_table) - Problem

Former Member
0 Kudos

Hey guys!

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!

regards Matthias

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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?

Andrew

4 REPLIES 4

Former Member
0 Kudos

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?

Andrew

Former Member
0 Kudos

First of all, thanks for the reply. Yes, the filters could be the next problem, but I haven't tested it yet as I'm stuck with the sorts...

So you mean I should get the sorts-object in the event-handler on_user_command and then sort my internal table on the information I got from that or is it possible to sort the internal table every time the ALV is sorted?

regards, Matthias

Former Member
0 Kudos

I sorted the my internal table in the event-handler and now it works. I also tried the filters, they didn't affect the row number.

Former Member
0 Kudos

Hi Matthias

I do have a question to another thread - the issue with ALV_DATA_EXPORT - can you sent me your example how you solved this

Many thanks