Skip to Content
avatar image
Former Member

[ALV] Text in color and bold

Hello,

I have an ALV Grid and I would like one cell, with text color in red and in bold.

I'm in OOP's with CL_GUI_ALV_GRID.

I've tried like that :

CONSTANTS :
            c_bold(4)           TYPE x       VALUE '00000020',
            c_red(4)            TYPE x       VALUE '00000017'.

*-LAYOUT
  fe_layout-cwidth_opt = c_x.
  fe_layout-no_rowmark = c_x.
  fe_layout-info_fname = 'ROW_COLOR'.
  fe_layout-stylefname = 'CELLS_STYLES'.

*-OUTTAB
  clear we_style.
  we_style-fieldname = 'XXXXX'.
  we_style-style = c_bold.
  we_style-style = c_red.
  insert we_style into table we_outtab-cells_styles.

It doesne't work. The bold put the text color in black.

There is a solution ?

Thank you.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 09, 2009 at 04:48 AM

    Hello Bernard

    I checked my sample report and it shows that '00000037' yields the text in bold and red.

    '00000037' = '00000020' + '00000017'   !!!

    Below you find a modified version of the sample report:

    ...
      BREAK-POINT.
      CONSTANTS :
          c_bold(4)           TYPE x       VALUE '00000020',
          c_red(4)            TYPE x       VALUE '00000017'.
    
      CLEAR: ls_outtab2.
      REFRESH: lt_celltab.
    
      ls_outtab2-maxlen = 0.
      ls_outtab2-style  = c_bold.
      ls_outtab2-style2 = c_red.
    
      ls_style-style = c_bold + c_red.
      INSERT ls_style INTO TABLE lt_celltab.
      ls_outtab2-celltab = lt_celltab.
    
      INSERT ls_outtab2 INTO gt_outtab2 INDEX 1.
    
    
    ENDFORM.                    " FILL_OUTTAB2
    

    Entire report:

    *&---------------------------------------------------------------------*
    *& Report  ZUS_SDN_ALV_STYLE_LIST
    *&
    *&---------------------------------------------------------------------*
    *& Thread: [ALV] Text in color and bold
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1191290"></a>
    *&
    *& Thread: color alv list display
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1072435"></a>
    *&
    *& Thread: Hiliting the Specific rows in ALV grid
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1062831"></a>
    *&
    *& Thread: Reg... coloring of rows
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1041516"></a>
    *&
    *& Thread: Painting cell in alv with objects
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1029759"></a>
    *&
    *& Thread: styles
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="830498"></a>
    *&
    *& Thread: Is it possible to assign color to manually modified record in tabcontrol?
    *& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="878289"></a>
    *&---------------------------------------------------------------------*
    *& The report generates style values and shows their effect in ALV grid.
    *&---------------------------------------------------------------------*
    
    
    REPORT  zus_sdn_alv_cell_style_2.
    
    
    TYPE-POOLS: abap.
    
    
    TYPES: BEGIN OF ty_s_outtab.
    INCLUDE TYPE knb1.
    TYPES: celltab TYPE lvc_t_styl. " cell style
    TYPES: END OF ty_s_outtab.
    TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
    WITH DEFAULT KEY.
    
    
    
    TYPES: BEGIN OF ty_s_outtab2.
    INCLUDE TYPE lvc_s_styl.
    TYPES: celltab TYPE lvc_t_styl. " cell style
    TYPES: END OF ty_s_outtab2.
    TYPES: ty_t_outtab2 TYPE STANDARD TABLE OF ty_s_outtab2
    WITH DEFAULT KEY.
    
    DATA:
    gs_layout TYPE lvc_s_layo,
    gs_variant TYPE disvariant,
    gt_fcat TYPE lvc_t_fcat.
    
    DATA:
    gt_outtab TYPE ty_t_outtab,
    gt_outtab2  TYPE ty_t_outtab2.
    
    
    PARAMETERS:
      p_rows    TYPE i DEFAULT 200.
    
    
    START-OF-SELECTION.
    
      SELECT * FROM knb1 UP TO 100 ROWS
      INTO CORRESPONDING FIELDS OF TABLE gt_outtab
      WHERE bukrs = '1000'.
    
    **  data: gr_kunnr    type RANGE OF kunnr.
    **  SELECT kunnr as low from knb1 into CORRESPONDING FIELDS OF TABLE gr_kunnr
    **    WHERE bukrs = '1000'.
    
      PERFORM set_layout_and_variant.
      PERFORM set_cell_style.
    
    **  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    **    EXPORTING
    **      i_structure_name = 'KNB1'
    **      i_grid_title     = 'Cell Styles'
    **      is_layout_lvc    = gs_layout
    **      i_save           = 'A'
    **      is_variant       = gs_variant
    **    TABLES
    **      t_outtab         = gt_outtab
    **    EXCEPTIONS
    **      program_error    = 1
    **      OTHERS           = 2.
    **  IF sy-subrc = 0.
    **  ENDIF.
    
    
      PERFORM fill_outtab2.
    **  PERFORM fill_fieldcatalog_2.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          i_structure_name = 'LVC_S_STYL'
          i_grid_title     = 'Cell Styles'
          is_layout_lvc    = gs_layout
          i_save           = 'A'
          is_variant       = gs_variant
    *      IT_FIELDCAT_LVC  = gt_fcat
        TABLES
          t_outtab         = gt_outtab2
        EXCEPTIONS
          program_error    = 1
          OTHERS           = 2.
      IF sy-subrc = 0.
      ENDIF.
    
    END-OF-SELECTION.
    
    
    *&---------------------------------------------------------------------
    *& Form SET_LAYOUT_AND_VARIANT
    *&---------------------------------------------------------------------
    
    FORM set_layout_and_variant .
    
      CLEAR: gs_layout,
      gs_variant.
    
      gs_layout-cwidth_opt = abap_true.
      gs_layout-stylefname = 'CELLTAB'.
    
      gs_variant-report = syst-repid.
      gs_variant-handle = 'STYL'.
    
    ENDFORM. " SET_LAYOUT_AND_VARIANT
    
    
    *&---------------------------------------------------------------------*
    *&      Form  set_cell_style
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM set_cell_style .
    
    * define local data
      CONSTANTS:
      lc_style_bold TYPE int4 VALUE '00000121',
      lc_style_red TYPE int4 VALUE '00000087',
      lc_style_cursive TYPE int4 VALUE '00008700',
      lc_style_underline_faint TYPE int4 VALUE '00008787',
      lc_style_underline TYPE int4 VALUE '00008707',
      lc_style_underline_red TYPE int4 VALUE '00008007'.
    
      DATA:
      ls_outtab TYPE ty_s_outtab,
      ls_style TYPE lvc_s_styl,
      lt_celltab TYPE lvc_t_styl.
    
    
      CLEAR: ls_style.
      ls_style-fieldname = 'BUKRS'.
      ls_style-style = '00000011'.    " make contents invisible
      INSERT ls_style INTO TABLE lt_celltab.
    
    **  CLEAR: ls_style.
    **  ls_style-fieldname = 'BUKRS'.
    **  ls_style-style = lc_style_bold.
    **  INSERT ls_style INTO TABLE lt_celltab.
    ***
    **  CLEAR: ls_style.
    **  ls_style-fieldname = 'KUNNR'.
    **  ls_style-style = lc_style_red.
    **  INSERT ls_style INTO TABLE lt_celltab.
    ***
    **  CLEAR: ls_style.
    **  ls_style-fieldname = 'ERDAT'.
    **  ls_style-style = lc_style_cursive.
    **  INSERT ls_style INTO TABLE lt_celltab.
    ***
    **  CLEAR: ls_style.
    **  ls_style-fieldname = 'ERNAM'.
    **  ls_style-style = lc_style_underline.
    **  INSERT ls_style INTO TABLE lt_celltab.
    
    
    
    
      ls_outtab-celltab = lt_celltab.
      MODIFY gt_outtab FROM ls_outtab
      TRANSPORTING celltab
      WHERE ( bukrs = '1000' ).
    
    ENDFORM. " SET_CELL_STYLE
    *&---------------------------------------------------------------------*
    *&      Form  FILL_OUTTAB2
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM fill_outtab2 .
    * define local data
      DATA: ls_outtab2  TYPE ty_s_outtab2,
            ld_num8(8)  TYPE n,
            ld_idx      TYPE i,
            ld_fname    TYPE fieldname,
            ld_perc     TYPE i,
            ld_text(50) TYPE c.
    
      DATA:
      ls_style TYPE lvc_s_styl,
      lt_celltab TYPE lvc_t_styl.
    
      FIELD-SYMBOLS: <ld_style>  TYPE lvc_style.
    
      ld_num8 = 0.
    
    
      DO p_rows TIMES.
        WRITE syst-index TO ld_text NO-ZERO.
        CONDENSE ld_text NO-GAPS.
        ld_perc = ( syst-index * 100 ) / p_rows.
        CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
          EXPORTING
            percentage = ld_perc
            text       = ld_text.
    
    
        CLEAR: ls_style,
           ls_outtab2.
        REFRESH: lt_celltab.
    
        ls_outtab2-maxlen = syst-index.
        MOVE ld_num8 TO ls_outtab2-style.
        ls_style-style = ls_outtab2-style.
    
        INSERT ls_style INTO TABLE lt_celltab.
        ls_outtab2-celltab = lt_celltab.
    
        APPEND ls_outtab2 TO gt_outtab2.
    
        ADD 1 TO ld_num8.
      ENDDO.
    
      BREAK-POINT.
      CONSTANTS :
          c_bold(4)           TYPE x       VALUE '00000020',
          c_red(4)            TYPE x       VALUE '00000017'.
    
      CLEAR: ls_outtab2.
      REFRESH: lt_celltab.
    
      ls_outtab2-maxlen = 0.
      ls_outtab2-style  = c_bold.
      ls_outtab2-style2 = c_red.
    
      ls_style-style = c_bold + c_red.
      INSERT ls_style INTO TABLE lt_celltab.
      ls_outtab2-celltab = lt_celltab.
    
      INSERT ls_outtab2 INTO gt_outtab2 INDEX 1.
    
    
    ENDFORM.                    " FILL_OUTTAB2
    *&---------------------------------------------------------------------*
    *&      Form  FILL_FIELDCATALOG_2
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM fill_fieldcatalog_2 .
    * define local data
      DATA: ls_fcat TYPE lvc_s_fcat,
            lt_fcat TYPE lvc_t_fcat.
    
      DATA: ld_fname  TYPE fieldname.
    
    
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
    *     I_BUFFER_ACTIVE              =
          i_structure_name             = 'LVC_S_STYL'
    *     I_CLIENT_NEVER_DISPLAY       = 'X'
    *     I_BYPASSING_BUFFER           =
    *     I_INTERNAL_TABNAME           =
        CHANGING
          ct_fieldcat                  = lt_fcat
        EXCEPTIONS
          inconsistent_interface       = 1
          program_error                = 2
          OTHERS                       = 3.
      IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
      DELETE lt_fcat WHERE ( fieldname NE 'STYLE' ).
    
      READ TABLE lt_fcat INTO ls_fcat INDEX 1.
    
      DO 16 TIMES.
        ls_fcat-fieldname = 'STYLE'.
        ls_fcat-col_pos = syst-index.
    
        WRITE syst-index TO ld_fname NO-ZERO.
        CONDENSE ld_fname NO-GAPS.
        CONCATENATE ls_fcat-fieldname ld_fname INTO ls_fcat-fieldname.
    
        APPEND ls_fcat TO gt_fcat.
      ENDDO.
    
    ENDFORM.                    " FILL_FIELDCATALOG_2
    

    Regards

    Uwe

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 08, 2009 at 02:01 PM
    DATA BEGIN OF gt_list OCCURS 0 .
        INCLUDE STRUCTURE SFLIGHT .
    DATA rowcolor(4) TYPE c .
    DATA cellcolors TYPE lvc_t_scol .
    DATA END OF gt_list .
    DATA ls_cellcolor TYPE lvc_s_scol .
    ...
      READ TABLE gt_list INDEX 5 .
        ls_cellcolor-fname = 'SEATSOCC' .
        ls_cellcolor-color-col = '7' .
        ls_cellcolor-color-int = '1' .
        APPEND ls_cellcolor TO gt_list-cellcolors .
      MODIFY gt_list INDEX 5 .
    

    Code Formatted by: Alvaro Tejada Galindo on Jan 8, 2009 10:49 AM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 08, 2009 at 02:04 PM

    HI.

    Bold letter is not possible in ALV.but Inverse and Intensify only available.

    REgards.

    Jay

    Edited by: Jay on Jan 8, 2009 3:04 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 08, 2009 at 02:08 PM

    hi

    this code will help you

    REPORT ZEX_ALV1 .
    
    *&---------------------------------------------------------------------*
    *& ABAPLOVERS ALV GRID COLOR DEMO                                      *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    
    type-pools: slis.                                 "ALV Declarations
    
    *Data Declaration------------------------------------------------------*
    *Types
    TYPES: BEGIN OF ty_one,
      Column1(10),
      Column2(10),
      Column3(10),
      Column4(10),
      line_color(4) type c,     "For storing Row Color Attributes
     END OF ty_one.
    * Internal Table Declaration-------------------------------------------*
    DATA: int_tab TYPE STANDARD TABLE OF ty_one INITIAL SIZE 0.
    
    * Work Area Declaration------------------------------------------------*
    DATA:  wa_one TYPE ty_one.
    
    *ALV data declarations
    data: fieldcatalog type slis_t_fieldcat_alv with header line,
          gd_tab_group type slis_t_sp_group_alv,
          gd_layout    type slis_layout_alv,
          gd_repid     like sy-repid.
    
    
    
    *Start-of-selection---------------------------------------------------*.
    START-OF-SELECTION.
    * Select the desired data. In this example we will not select anything
    
    * Buils Table
    perform build_table.
    
    * Build the Catelog---------------------------------------------------*
    perform build_fieldcatalog.
    
    * Build the Layout----------------------------------------------------*
    perform build_layout.
    
    * Display the ALV-----------------------------------------------------*
    perform display_alv_report.
    
    
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_FIELDCATALOG
    *&---------------------------------------------------------------------*
    *       Build Fieldcatalog for ALV Report
    *----------------------------------------------------------------------*
    form build_fieldcatalog.
    
      fieldcatalog-fieldname    = 'Column1'.
      fieldcatalog-seltext_m    = 'Col1'.
      fieldcatalog-col_pos      = 0.
      fieldcatalog-outputlen    = 10.
      fieldcatalog-emphasize    = 'X'.
      fieldcatalog-key          = 'X'.
    
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'Column2'.
      fieldcatalog-seltext_m   = 'Col2'.
      fieldcatalog-col_pos     = 1.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'Column3'.
      fieldcatalog-seltext_m   = 'Col3'.
      fieldcatalog-col_pos     = 2.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'Column4'.
      fieldcatalog-seltext_m   = 'COl4'.
      fieldcatalog-col_pos     = 3.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
      fieldcatalog-fieldname   = 'Column5'.
      fieldcatalog-seltext_m   = 'Col5'.
      fieldcatalog-col_pos     = 4.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    
    endform.                    " BUILD_FIELDCATALOG
    
    
    *&---------------------------------------------------------------------*
    *&      Form  BUILD_LAYOUT
    *&---------------------------------------------------------------------*
    *       Build layout for ALV grid report
    *----------------------------------------------------------------------*
    form build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
    
    * Set layout field for color attributes
      gd_layout-info_fieldname =      'LINE_COLOR'.
    
    endform.                    " BUILD_LAYOUT
    
    
    *&---------------------------------------------------------------------*
    *&      Form  DISPLAY_ALV_REPORT
    *&---------------------------------------------------------------------*
    *       Display report using ALV grid
    *----------------------------------------------------------------------*
    form display_alv_report.
      gd_repid = sy-repid.
      call function 'REUSE_ALV_GRID_DISPLAY'
           exporting
                 i_callback_program      = gd_repid
    *            i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM
    *            i_callback_user_command = 'USER_COMMAND'
    *            i_grid_title           = outtext
                 is_layout               = gd_layout
                 it_fieldcat             = fieldcatalog[]
    *            it_special_groups       = gd_tabgroup
    *            IT_EVENTS                = GT_XEVENTS
                 i_save                  = 'X'
    *            is_variant              = z_template
    
           tables
                t_outtab                = int_tab
           exceptions
                program_error           = 1
                others                  = 2.
      if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.
    endform.                    " DISPLAY_ALV_REPORT
    
    
    *&---------------------------------------------------------------------*
    *&      Form  DATA_RETRIEVAL
    *&---------------------------------------------------------------------*
    
    *----------------------------------------------------------------------*
    form Build_Table.
    data: ld_color(1) type c.
    
    Move: ' ' to wa_one.
    Append wa_one to int_tab.
    Append wa_one to int_tab.
    Append wa_one to int_tab.
    Append wa_one to int_tab.
    Append wa_one to int_tab.
    
    *Populate field with color attributes
    loop at int_tab into wa_one.
    * Populate color variable with colour properties
    * Char 1 = C (This is a color property)
    * Char 2 = 3 (Color codes: 1 - 7)
    * Char 3 = Intensified on/off ( 1 or 0 )
    * Char 4 = Inverse display on/off ( 1 or 0 )
    *           i.e. wa_ekko-line_color = 'C410'
      ld_color = ld_color + 1.
    
    * Only 7 colours so need to reset color value
      if ld_color = 8.
        ld_color = 1.
      endif.
      concatenate 'C' ld_color '10' into wa_one-line_color.
      modify int_tab from wa_one.
    endloop.
    endform.                    "
    

    Code Formatted by: Alvaro Tejada Galindo on Jan 8, 2009 10:49 AM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 08, 2009 at 02:12 PM

    try below code

    for displaying the color

    concatenate 'c' 6 '01' into workarea (in which table u need to display color )

    modify table into workarea transpoting (give which field u need get color ) depends up on ur requirement .

    6 means color which u want . u can define 1- 7 colors

    01 means intensified or non-intensified by giving 01 or 10 .

    Edited by: Premchander Arumugam on Jan 8, 2009 7:43 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 08, 2009 at 04:23 PM

    Your answers work about background cell color. Not about the text color in the cells.

    It's possible to set the text in red. It's possible to set the text in bold. Look at my code.

    Now the twice is impossible. There is a mistake in my code.

    *-OUTTAB
      clear we_style.
      we_style-fieldname = 'XXXXX'.
      we_style-style = c_bold.
      we_style-style2 = c_red.   "here => style2
      insert we_style into table we_outtab-cells_styles.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello Bernard

      You may have a look at my sample report ZUS_SDN_ALV_CELL_STYLE_2 in thread

      By playing around I found the following constants:

      *&---------------------------------------------------------------------*
      *&      Form  set_cell_style
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      FORM set_cell_style .
       
      * define local data
        CONSTANTS:
        lc_style_bold TYPE int4 VALUE '00000121',
        lc_style_red TYPE int4 VALUE '00000087',
        lc_style_cursive TYPE int4 VALUE '00008700',
        lc_style_underline_faint TYPE int4 VALUE '00008787',
        lc_style_underline TYPE int4 VALUE '00008707',
        lc_style_underline_red TYPE int4 VALUE '00008007'.
      ...
      

      Regards

      Uwe

  • avatar image
    Former Member
    Jan 09, 2009 at 10:33 AM

    OK Thank you very much, it works !

    Add comment
    10|10000 characters needed characters exceeded