Skip to Content

Changing ALV field style in multiple columns.

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 19 at 04:46 PM

    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.
    Add comment
    10|10000 characters needed characters exceeded