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: 

Changing ALV field style in multiple columns.

luis_rod
Participant
0 Kudos
1,778

Hi all,


First of all, a disclaimer: I’m quite the SAP rookie as my ABAP knowledge is mostly self-taught (I’m really a Db2 guy, but one has to deal with the cards one is given to…).


O.k. To the point:


I have an ALV (shown with REUSE_ALV_GRID_DISPLAY_LVC) where, according to some parameters, I need to disable a couple of columns. Something like (in pseudo-code):

IF  <alv>-dat1 is X.
  Disable <alv>-col1, <alv>-col2.
ENDIF.

Good. So I wrote the following code (after filling up the ALV, but before I created the field catalog):


(my alv field style column is defined as: field_style TYPE lvc_t_styl )

DATA ls_stylerow TYPE lvc_s_styl .
  LOOP AT gt_alv ASSIGNING <gt>.
    IF <gt>-condition1 = abap_true .       
      ls_stylerow-fieldname = 'COLUMN1' .
      ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
      APPEND ls_stylerow  TO <gt>-field_style.
      ls_stylerow-fieldname = 'COLUMN2' .
      ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
      APPEND ls_stylerow  TO <gt>-field_style.
    ENDIF.
  ENDLOOP.

When I try to execute it I get a dump at the second append that states:

ITAB_ILLEGAL_SORT_ORDER
A line is to be inserted or changed at position 1 in the sorted
 internal table (type SORTED_TABLE)
  "\PROGRAM=ZPROGRAM\DATA=GT_ALV[49]-FIELD_STYLE".
 In doing so, the sorting sequence - determined by the table key - was
 destroyed.


So, What I’m doing wrong?


Thanks in advance,
Luis

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos
267

You'll need to read carefully the ABAP documentation.

It's a "sorted table" (declared with DATA ... TYPE SORTED TABLE OF ... or typed with an existing sorted table type).

So, you shouldn't use APPEND ls_stylerow TO<gt>-field_style. Don't ask me why it's not checked at runtime.

Instead, use:

INSERT ls_stylerow INTO TABLE <gt>-field_style.
2 REPLIES 2

Sandra_Rossi
Active Contributor
0 Kudos
268

You'll need to read carefully the ABAP documentation.

It's a "sorted table" (declared with DATA ... TYPE SORTED TABLE OF ... or typed with an existing sorted table type).

So, you shouldn't use APPEND ls_stylerow TO<gt>-field_style. Don't ask me why it's not checked at runtime.

Instead, use:

INSERT ls_stylerow INTO TABLE <gt>-field_style.

267

Sandra:

Thanks!! That's the answer I needed. Worked like a charm.

Thanks again,

Luis