5

How can I use color value variable? For example, this works for me:

write:/10  'test' COLOR COL_HEADING.

I thoght that colours are integers so I tried:

data:
gv_mycolor type I.
gv_mycolor = 5.
write:/10  'test' COLOR gv_mycolor.

the second code gives me an error: "Color gv_mycolor is not expected; only 1 to 7 or the relevant color IDs are allowed. Statement

FORMAT COLOR = gv_mycolor.

works for me, I have problem just with write statement.

Can anybody help?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
tomas.teicher
  • 913
  • 3
  • 13
  • 26

3 Answers3

8
DATA colour TYPE i VALUE 2.

WRITE:/10  'test' COLOR = colour .

You MUST use an equal sign, and that's all there is to it... ABAP and it's funny statements :P

vlad-ardelean
  • 7,480
  • 15
  • 80
  • 124
  • I'm really tempted to rate this -1 instead of +1, just because it helps people create more unmaintainable list code :-) – vwegert Apr 24 '13 at 06:06
  • lol, please spare me :P I promiss I try to use the new stuff as much as I can. I come from the Java world, the `WRITE` statement still horrifies me. – vlad-ardelean Apr 24 '13 at 06:21
  • You have my reluctant vote :), given that you have answered the actual question. Anyhow having spend the last two weeks on HRFORMS, it has taken the top spot for things that have to die a slow and horrible death. So I will give ABAP lists a reprieve for now :) – Esti Apr 24 '13 at 07:31
  • Dunno about HRForms, but SAPScript is the worst of what i've seen so far :P – vlad-ardelean Jul 12 '13 at 13:13
0

Edit: First part of the answer is hidden as it is incorrect - see Vlad's comment & answer

Short answer to your question: The syntax does not allow you to do this as per the compiler message. The best you can do is to combine the FORMAT and WRITE statements in a macro, but this is very old-school, and will probably not teach you too much that is relevant.

Have a look at package SLIS where there are many examples (BCALV_GRID*) of how to implement ALV lists and grids. These are used much more frequently, even in Web Dynpro. The CL_SALV* classes also provides a nice simplified (and supported) interface to implement ALV grids. (See this answer for a full example).

Community
  • 1
  • 1
Esti
  • 3,677
  • 8
  • 35
  • 57
0

You can achieve a basic pallet of colors using the COLOR attribute.

Here is the sample code:

 WRITE: '|......TESTMODE......|' COLOR = 1, /.
 WRITE: '|......TESTMODE......|' COLOR = 2, /.
 WRITE: '|......TESTMODE......|' COLOR = 3, /.
 WRITE: '|......TESTMODE......|' COLOR = 4, /.
 WRITE: '|......TESTMODE......|' COLOR = 5, /.
 WRITE: '|......TESTMODE......|' COLOR = 6, /.
 WRITE: '|......TESTMODE......|' COLOR = 7, /.

And the output:

Output code WRITE color

Frontmaniaac
  • 221
  • 3
  • 14