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: 

Dynamically format colors in lists

Former Member
0 Kudos

I would like to dynamically set a color for a single in a list.

Ie rather than code:

If var = 'x'. write l_field color col_negative.

elseif var = 'y' write l_field color col_total.

elseif var = 'z' write l_field color col_group.

endif.

I would like to code it as follows:

data: l_color(10) type c.

if l_var = 'x'.

move 'col_negative' to l_color.

elseif l_var = 'y' move 'col_total to l_color.

elseif l_var = 'z' move 'col_group' to l_color.

endif.

write: l_field color l_color.

The color command does not seem to like being passed a variable, rather it has to be told explicitly what the color should be set at.

Is there a way around this?

1 ACCEPTED SOLUTION

LucianoBentiveg
Active Contributor
0 Kudos

No, like you say: the color command does not support passed variables.

5 REPLIES 5

LucianoBentiveg
Active Contributor
0 Kudos

No, like you say: the color command does not support passed variables.

0 Kudos

Thanks for your replies. I suspected that I could not pass a variable to the color command - you have confirmed that for me.

0 Kudos

Check this report...You might find it helpfull:


REPORT Z_ATG_DUMMY.

DATA I TYPE I VALUE 0.
DATA COL(15) TYPE C.

WRITE:/9 'INTENSIFIED ON',27 'INTENSIFIED OFF',48 'INVERSE'.

SKIP 2.

WHILE I < 8.

  CASE I.
    WHEN 0. COL = 'COL_BACKGROUND '.
    WHEN 1. COL = 'COL_HEADING '.
    WHEN 2. COL = 'COL_NORMAL '.
    WHEN 3. COL = 'COL_TOTAL '.
    WHEN 4. COL = 'COL_KEY '.
    WHEN 5. COL = 'COL_POSITIVE '.
    WHEN 6. COL = 'COL_NEGATIVE '.
    WHEN 7. COL = 'COL_GROUP '.
  ENDCASE.

  FORMAT INTENSIFIED COLOR = I.

  WRITE: /(4) I, AT 7 SY-VLINE,
  COL, SY-VLINE,
  COL INTENSIFIED OFF, SY-VLINE,
  COL INVERSE.

  I = I + 1.

ENDWHILE.

Greetings,

Blag.

0 Kudos

Alvaro,

Thanks for that, but what I am trying to do is a little complicated. When a user clicks on a field in a list I want to change the color of that field depending on the field value. To achieve this I am using the command

MODIFY CURRENT LINE FIELD FORMAT itab-field

COLOR COL_KEY INTENSIFIED ON.

It would be much neater if I could achieve this by passing a variable to the "color" command but it seems this is not possible.

To make things even more complicated I have to get the fieldname which has been clicked on using "get_cursor". The "format" part of the above command will also not accept a variable so it seems this too will have to be hard coded.

former_member583013
Active Contributor
0 Kudos

To color a report, you must use...


FORMAT COLOR X.
FORMAT COLOR OFF.

Where 'X' is a number going from 0 to 7...If I'm not wrong -:P

Greetings,

Blag.