Application Development and Automation 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: 
Read only

Color using in string

Former Member
0 Likes
1,410

Dear experts,

I do have a situation where I replace all not digits and (;,) with blank:

REPLACE ALL OCCURRENCES OF REGEX  '[^\d;,]' IN v_record WITH ''.


But I'd like not just replace the symbols by '' but also color them by any color...


Could you give me some advice to do this in the best way?


BR


Denis

8 REPLIES 8
Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
1,347

Simple string does not have any color property. How do you want print it with color? As HTML, with WRITE, or...?

Check sample program DEMO_REGEX_TOY it does what you want and outputs colored result as HTML.

-- Tomas --
Read only

0 Likes
1,347

Well the backround is following:

I upload an csv-file like this:

And to avoid uploading of not digits I replace them:

REPLACE ALL OCCURRENCES OF REGEX  '[^\d;,]' IN v_record WITH ''.


I display the results by using of REUSE _ALV_GRID_DISPLAY:


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

   EXPORTING

     i_callback_program       = v_repid

     i_grid_title             = v_grid_title

     i_save                   = 'A'

     i_structure_name         = 'zst_preisupload'

     is_layout                = v_layout

     i_callback_pf_status_set = 'STANDARD'

     i_callback_user_command  = 'USER_COMMAND'

   TABLES

     t_outtab                 = ta_csv_data

   EXCEPTIONS

     program_error            = 1

     OTHERS                   = 2.


Is there may be an alternative possibility to mark "bad" fields by color?



Read only

0 Likes
1,347

Sure. You can check sy-subrc after REPLACE (F1 for subrc values 0,2,4,8) and if pattern match, then change color of cell in ALV

-- Tomas --
Read only

0 Likes
1,347

Thank you for the responce, Tomas,

I kind of not following you right now...could you may be give me an code example of what you mean?

Read only

0 Likes
1,347

LOOP AT data.

     REPLACE ALL OCCURRENCES OF REGEX...

     IF sy-subrc = ... "if regex found

          "color cell here

     ENDIF.

ENDLOOP.

"display ALV here

-- Tomas --
Read only

0 Likes
1,347

Hi Denis,

how to color single cells can be found in several threads here in SCN like

http://scn.sap.com/thread/3286590

SCN search will give you more results for that.

Regards,

Klaus

Read only

0 Likes
1,347

"color cell here


But exactly this part is not so clear for me.

Read only

0 Likes
1,347

Klaus already answered it. By searching "REUSE_ALV_GRID_DISPLAY color cell" you would find answers all over SCN or Google


color TYPE lvc_t_scol                          "add this to itab structure

...

ls_layout-coltab_fieldname = 'COLOR'.     "set color field in ALV layout

...

DATA: ls_color TYPE lvc_s_scol.

...

"setting cell color:

ls_color-fname = 'MATNR'.

ls_color-color-col = '5'.

ls_color-color-int = '1'.

ls_color-color-inv = '0'.

APPEND ls_color TO itab-color.

"display ALV

-- Tomas --