Application Development and Automation 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: 
Read only

sorting issues in alv oops

Former Member
0 Likes
2,979

Hi All,

Greetings for the Day!!!

am using alv oops for displaying output..

BEFORE sorting my internal table looks like below in the output.....

for example

A

B

C

D

E

F

AFTER sorting the internal table in the output .display.,, the internal table shows like below

F

E

D

C

B

A

but when i call the method set_table_for_first_display ,after sorting the in the output display ....,the internal table remains as like before

A

B

C

D

E

F....

it should be lke

F

E

D

C

B

A .....

kindly suggest me the alternatives.pls

Regards

Jack

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,653

Are you saying that you are calling the set_table_for_first_display method more than one time? During each PBO execution? If so, don't. Do a check before you create the objects in the PBO, if they are not initial, do not re-create them.

Regards,

Rich Heilman

4 REPLIES 4
Read only

MarcinPciak
Active Contributor
0 Likes
1,653

You are using ASCENDING sorting type and should be DESCENDING . What I understand is that you want to do sorting in the output (manually in frontend). Therefore you need to use descending sorting option (icon).

If you want to do this using code then use below


"fill the ls_sort strcutre 
data: ls_sort type lvc_s_sort.

ls_sort-fieldname = 'FIELDNAME_TO_SORT'.
ls_sort-down = 'X'. "you need descending sorting, not ascending so this one should be used

"then simply pass it to 
call method grid->set_table_for_first_display
....
 sort = ls_sort

"the output will show rows sorted descending

Regards

Marcin

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,654

Are you saying that you are calling the set_table_for_first_display method more than one time? During each PBO execution? If so, don't. Do a check before you create the objects in the PBO, if they are not initial, do not re-create them.

Regards,

Rich Heilman

Read only

0 Likes
1,653

For example....

DATA: lo_alv_grid            TYPE REF TO cl_gui_alv_grid.
DATA: lo_form_alv_container  TYPE REF TO cl_gui_custom_container.

* Create Controls
    IF lo_form_alv_container IS INITIAL.  "<-- Check if already created

      CREATE OBJECT lo_form_alv_container
        EXPORTING
          container_name = 'FORMULA_CONTAINER'.

* Create control based ALV grid
      CREATE OBJECT lo_alv_grid
        EXPORTING
          i_parent = lo_form_alv_container.

....

* set for first display
      lo_alv_grid->set_table_for_first_display(
                EXPORTING
                   is_layout            = ls_layout
                   it_toolbar_excluding = lt_exclude
                CHANGING
                   it_outtab            = lt_formulas[]
                   it_fieldcatalog      = lt_fieldcat[] ).

    ELSE.
      lo_alv_grid->refresh_table_display( ).    "<-- If so, just refresh
    ENDIF.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,653

Hi,

set_table_for_first_display has to be called only once. to retain sorting order and filter call refresh_table_display.

However if there is any structure changes on your ALV or for field catalog changes, you have to make a call again to Set_table_for_first_display, in th at case, you will loose the sort order set by the user previously.

Regards,

Bhuvana