Skip to Content
0

Changing ALV field style in multiple columns.

Jan 19 at 04:00 PM

52

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Sandra Rossi Jan 19 at 04:46 PM
0

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.
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Sandra:

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

Thanks again,

Luis

1