title: ALV Column Text and Color won't change
body: <p>I got a SAP ALV problem.
  I want to change the text and the color of a column.
  It works if I call the column directly ('BONUS') but when I
  use it within a DO-clause and concatenate the name of the column it won't work
  for some reason.
  Though the column is found and the attributes are changed, at least this is what I see in while debugging.</p>
  
  <p>I hope someone can help me out here.</p>
  
  <p>The following is a part of my coding where the attributes should be changed.</p>
  
  <pre><code>        Data: Count Type i.
    DATA: h_fieldname TYPE char30.
    DATA: col_s         TYPE scrtext_s.
  
    DATA: col_m         TYPE scrtext_m.
  
    DATA: col_l         TYPE scrtext_l.
  
    DATA: colname(30) TYPE c.
  
  DATA: lr_functions TYPE REF TO cl_salv_functions_list.
  
   DATA: gr_columns    TYPE REF TO cl_salv_columns_table.
  
   DATA: gr_column     TYPE REF TO cl_salv_column_table.
  
  DATA: alv TYPE REF TO cl_salv_table.
  
    lv_color_red-col = 7.
    lv_color_red-int = 1.
    lv_color_red-inv = 0.
  
    lv_color_blue-col = 4.
    lv_color_blue-int = 1.
    lv_color_blue-inv = 0.
  
    lv_color_green-col = 5.
    lv_color_green-int = 1.
    lv_color_green-inv = 0.
              DO gv_row_count TIMES.
  
            ADD 1 TO count.
            new = count.
  
            CLEAR: h_fieldname, colname.
            CONCATENATE 'JAHR' new 'P' INTO h_fieldname.
            CONCATENATE 'Jahr' new INTO colname.
            col_s = colname.
            col_m = colname.
            col_l = colname.
            gr_column ?= gr_columns-&gt;get_column( h_fieldname ).
            gr_column-&gt;set_short_text( col_s ).
            gr_column-&gt;set_medium_text( col_m ).
            gr_column-&gt;set_long_text( col_l ).
            gr_column-&gt;set_color( lv_color_blue ).
  
            CLEAR: h_fieldname, colname.
            CONCATENATE 'JAHR' new 'W' INTO h_fieldname.
            CONCATENATE 'Jahr' new INTO colname.
            col_s = colname.
            col_m = colname.
            col_l = colname.
            gr_column ?= gr_columns-&gt;get_column( h_fieldname ).
            gr_column-&gt;set_short_text( col_s ).
            gr_column-&gt;set_medium_text( col_m ).
            gr_column-&gt;set_long_text( col_l ).
          ENDDO.
  </code></pre>
  
  <p>I'm posting the code of both methods. The first one is building a fieldcatalog an creating a global table so the fieldcatalog could be used in the second method. This one should fill the fieldcatalog, configure the ALV (like column texts and colors) and display the result.</p>
  
  <pre><code>EDIT: Here are also the attributes etc. used inside the methods:
    data GT_DATATAB type ref to DATA .
    class ZCL_BONUS_PROCESSING definition load .
    data GT_STANDARD type ZCL_BONUS_PROCESSING=&gt;TTY_FINAL_STANDARD .
    data GT_ADVANCED type ZCL_BONUS_PROCESSING=&gt;TTY_FINAL_ADVANCED .
    data GV_ROW_COUNT type I .
  
  
  METHOD build_fieldcatalog.
  
    FIELD-SYMBOLS: &lt;t_itab&gt; TYPE table.
    DATA: t_fieldcat  TYPE lvc_t_fcat.
    DATA: s_fieldcat  TYPE LINE OF lvc_t_fcat.
    DATA: count TYPE i.
  *  DATA: new(2) TYPE c.
    DATA: new TYPE string.
    DATA: final_count TYPE i.
    DATA: h_fieldname TYPE char30.
  
    " Personalnummer
    CLEAR: s_fieldcat.
    s_fieldcat-fieldname  = 'PERNR'.
    s_fieldcat-ref_table  = 'P0000'.
    s_fieldcat-ref_field  = 'PERNR'.
    s_fieldcat-key        = 'X'.
    APPEND s_fieldcat TO t_fieldcat.
  
    " Zielbonus
    CLEAR: s_fieldcat.
    s_fieldcat-fieldname  = 'BONUS'.
    s_fieldcat-inttype = 'C'.
    s_fieldcat-outputlen = '15'.
  *  s_fieldcat-ref_table  = 'P0014'.
  *  s_fieldcat-ref_field  = 'YY_BETRAG'.
    s_fieldcat-key        = 'X'.
    APPEND s_fieldcat TO t_fieldcat.
  
    " Bonusanspruch
    CLEAR: s_fieldcat.
    s_fieldcat-fieldname  = 'BONAN'.
    s_fieldcat-inttype = 'C'.
    s_fieldcat-outputlen = '15'.
  *  s_fieldcat-ref_table  = 'P0014'.
  *  s_fieldcat-ref_field  = 'YY_BETRAG'.
    s_fieldcat-key        = ''.
    APPEND s_fieldcat TO t_fieldcat.
  
    " Anspruch
    CLEAR: s_fieldcat.
    s_fieldcat-fieldname  = 'ANSPR'.
  *  s_fieldcat-ref_table  = 'P0008'.
  *  s_fieldcat-ref_field  = 'TRFGR'.
    s_fieldcat-inttype = 'C'.
    s_fieldcat-outputlen = '1'.
    s_fieldcat-key        = ''.
    APPEND s_fieldcat TO t_fieldcat.
  
    " Sonderregelung
    CLEAR: s_fieldcat.
    s_fieldcat-fieldname  = 'SONDE'.
    s_fieldcat-inttype    = 'I'.
    s_fieldcat-outputlen  = '1'.
    s_fieldcat-key        = ''.
    APPEND s_fieldcat TO t_fieldcat.
  
    " Kommentar
    CLEAR: s_fieldcat.
    s_fieldcat-fieldname  = 'COMM'.
    s_fieldcat-inttype    = 'C'.
    s_fieldcat-outputlen  = '50'.
    s_fieldcat-key        = ''.
    APPEND s_fieldcat TO t_fieldcat.
  
    " Mitarbeiterkreis
    CLEAR: s_fieldcat.
    s_fieldcat-fieldname  = 'PERSK'.
    s_fieldcat-ref_table  = 'P0001'.
    s_fieldcat-ref_field  = 'PERSK'.
    s_fieldcat-key        = 'X'.
    APPEND s_fieldcat TO t_fieldcat.
  
    count = 0.
  
    DO gv_row_count TIMES.
  
      ADD 1 TO count.
      new = count.
  
      " Lohnart (Jahr) Prozent
      CLEAR: h_fieldname.
      CONCATENATE 'JAHRP' new INTO h_fieldname.
      CONDENSE h_fieldname NO-GAPS.
      CLEAR: s_fieldcat.
      s_fieldcat-fieldname  = h_fieldname.
  *    s_fieldcat-ref_table  = 'PZI02'.
  *    s_fieldcat-ref_field  = 'ANZHL'.
      s_fieldcat-inttype    = 'C'.
      s_fieldcat-outputlen  = '15'.
      s_fieldcat-coltext    = h_fieldname.
      s_fieldcat-seltext    = h_fieldname.
      s_fieldcat-key        = ''.
      APPEND s_fieldcat TO t_fieldcat.
  
      " Lohnart (Jahr) Währung
      CLEAR: h_fieldname.
      CONCATENATE 'JAHRW' new INTO h_fieldname.
      CONDENSE h_fieldname NO-GAPS.
      CLEAR: s_fieldcat.
      s_fieldcat-fieldname  = h_fieldname.
  *    s_fieldcat-ref_table  = 'P0014'.
  *    s_fieldcat-ref_field  = 'YY_BETRAG'.
      s_fieldcat-inttype    = 'C'.
      s_fieldcat-outputlen  = '15'.
      s_fieldcat-coltext    = h_fieldname.
      s_fieldcat-seltext    = h_fieldname.
      s_fieldcat-key        = ''.
      APPEND s_fieldcat TO t_fieldcat.
  
    ENDDO.
  
    " Probezeit
    CLEAR: s_fieldcat.
    s_fieldcat-fieldname  = 'PROBE'.
    s_fieldcat-inttype    = 'D'.
    s_fieldcat-outputlen  = '10'.
    s_fieldcat-key        = ''.
    s_fieldcat-col_opt    = 'X'.
    APPEND s_fieldcat TO t_fieldcat.
  
  * Datentabelle aus Feldkatalog erstellen
    CALL METHOD cl_alv_table_create=&gt;create_dynamic_table
      EXPORTING
        it_fieldcatalog = t_fieldcat
      IMPORTING
        ep_table        = gt_datatab.
  
  ENDMETHOD.
  
  
  METHOD fill_and_display_alv.
  
    DATA: lstab     TYPE REF TO data.
    DATA: lv_offset TYPE i.
    DATA: dat       TYPE begda.
  *  DATA: new(2) TYPE c.
    DATA: new TYPE string.
    DATA: count TYPE i.
    DATA: h_fieldname TYPE char30.
    DATA: col_s         TYPE scrtext_s.
    DATA: col_m         TYPE scrtext_m.
    DATA: col_l         TYPE scrtext_l.
    DATA: colname TYPE char30.
    DATA: lr_functions TYPE REF TO cl_salv_functions_list.
    DATA: gr_columns    TYPE REF TO cl_salv_columns_table.
    DATA: gr_column     TYPE REF TO cl_salv_column_table.
    DATA: alv TYPE REF TO cl_salv_table.
    DATA: exc TYPE REF TO cx_salv_msg.
  *  DATA: t_standard TYPE TABLE OF sty_standard.
    DATA: s_standard TYPE zcl_bonus_data_collect=&gt;sty_final_standard.
  *  DATA: t_advanced TYPE TABLE OF sty_advanced.
    DATA: s_advanced TYPE zcl_bonus_data_collect=&gt;sty_final_advanced.
  
    DATA: lv_color_red TYPE lvc_s_colo.
    DATA: lv_color_blue TYPE lvc_s_colo.
    DATA: lv_color_green TYPE lvc_s_colo.
  
    lv_color_red-col = 7.
    lv_color_red-int = 1.
    lv_color_red-inv = 0.
  
    lv_color_blue-col = 4.
    lv_color_blue-int = 1.
    lv_color_blue-inv = 0.
  
    lv_color_green-col = 5.
    lv_color_green-int = 1.
    lv_color_green-inv = 0.
  
    FIELD-SYMBOLS: &lt;ls_itab&gt; TYPE ANY,
                   &lt;ls_comp&gt; TYPE ANY.
    FIELD-SYMBOLS: &lt;t_itab&gt; TYPE table.
  
  
  * Datentabelle füllen
    ASSIGN gt_datatab-&gt;* TO &lt;t_itab&gt;.
    cl_salv_table=&gt;factory( IMPORTING r_salv_table = alv  CHANGING t_table = &lt;t_itab&gt; ).
  
  * Zeilenstruktur erzeugen
    CREATE DATA lstab LIKE LINE OF &lt;t_itab&gt;.
    ASSIGN lstab-&gt;* TO &lt;ls_itab&gt;.
  
    LOOP AT gt_standard INTO s_standard.
  
      CLEAR: s_advanced, &lt;ls_itab&gt;.
  
      " Personalnummer
      lv_offset = 1.
      ASSIGN COMPONENT lv_offset OF STRUCTURE &lt;ls_itab&gt; TO &lt;ls_comp&gt;.
      IF sy-subrc EQ 0.
        &lt;ls_comp&gt; = s_standard-pernr.
      ENDIF.
  
      " Zielbonus
      lv_offset = 2.
      ASSIGN COMPONENT lv_offset OF STRUCTURE &lt;ls_itab&gt; TO &lt;ls_comp&gt;.
      IF sy-subrc EQ 0.
        &lt;ls_comp&gt; = s_standard-ziel_bonus.
      ENDIF.
  
      " Höhe des Anspruchs auf Zielbonus
      lv_offset = 3.
      ASSIGN COMPONENT lv_offset OF STRUCTURE &lt;ls_itab&gt; TO &lt;ls_comp&gt;.
      IF sy-subrc EQ 0.
        &lt;ls_comp&gt; = s_standard-ziel_bonus_anspruch.
      ENDIF.
  
      " Anspruch
      lv_offset = 4.
      ASSIGN COMPONENT lv_offset OF STRUCTURE &lt;ls_itab&gt; TO &lt;ls_comp&gt;.
      IF sy-subrc EQ 0.
        &lt;ls_comp&gt; = s_standard-anspruch.
      ENDIF.
  
      " Sonderregelung
      lv_offset = 5.
      ASSIGN COMPONENT lv_offset OF STRUCTURE &lt;ls_itab&gt; TO &lt;ls_comp&gt;.
      IF sy-subrc EQ 0.
        &lt;ls_comp&gt; = s_standard-sonderreg.
      ENDIF.
  
      " Kommentar
      lv_offset = 6.
      ASSIGN COMPONENT lv_offset OF STRUCTURE &lt;ls_itab&gt; TO &lt;ls_comp&gt;.
      IF sy-subrc EQ 0.
        &lt;ls_comp&gt; = s_standard-comm.
      ENDIF.
  
      " Mitarbeiterkreis
      lv_offset = 7.
      ASSIGN COMPONENT lv_offset OF STRUCTURE &lt;ls_itab&gt; TO &lt;ls_comp&gt;.
      IF sy-subrc EQ 0.
        &lt;ls_comp&gt; = s_standard-persk.
      ENDIF.
  
      " Beginn Zeitintervalle
      LOOP AT gt_advanced INTO s_advanced WHERE pernr = s_standard-pernr.
  
        ADD 1 TO lv_offset.
  
        " Beschäftigungsgrad
        ASSIGN COMPONENT lv_offset OF STRUCTURE &lt;ls_itab&gt; TO &lt;ls_comp&gt;.
        IF sy-subrc EQ 0.
          &lt;ls_comp&gt; = s_advanced-year_percent.
        ENDIF.
  
        ADD 1 TO lv_offset.
  
        " Bonuswert (Basiswert)
        ASSIGN COMPONENT lv_offset OF STRUCTURE &lt;ls_itab&gt; TO &lt;ls_comp&gt;.
        IF sy-subrc EQ 0.
          &lt;ls_comp&gt; = s_advanced-year_quantity.
        ENDIF.
  
      ENDLOOP.
  
      lv_offset = gv_row_count * 2 + 7.
  
  
      ADD 1 TO lv_offset.
  
      " Probezeit
      ASSIGN COMPONENT lv_offset OF STRUCTURE &lt;ls_itab&gt; TO &lt;ls_comp&gt;.
      IF sy-subrc EQ 0.
        &lt;ls_comp&gt; = s_standard-probez.
      ENDIF.
  
      ADD 1 TO lv_offset.
  
  * Struktur dem Feldkatalog übergeben
      APPEND &lt;ls_itab&gt; TO &lt;t_itab&gt;.
  
      TRY .
  
  ** Funktionsleiste
          lr_functions = alv-&gt;get_functions( ).
          lr_functions-&gt;set_all( if_salv_c_bool_sap=&gt;true ).
          lr_functions-&gt;set_print( if_salv_c_bool_sap=&gt;true ).
  
  ** Optimierung der Spaltengröße
          gr_columns = alv-&gt;get_columns( ).
          gr_columns-&gt;set_optimize( abap_true ).
  
  
          count = 0.
          DO gv_row_count TIMES.
  
            ADD 1 TO count.
            new = count.
  
            CLEAR: h_fieldname, colname.
            CONCATENATE 'JAHRP' new INTO h_fieldname.
            CONDENSE h_fieldname NO-GAPS.
            CONCATENATE 'Jahr' new INTO colname.
            CONDENSE colname NO-GAPS.
            col_s = colname.
            col_m = colname.
            col_l = colname.
            gr_column ?= gr_columns-&gt;get_column( columnname = h_fieldname ).
            gr_column-&gt;set_short_text( col_s ).
            gr_column-&gt;set_medium_text( col_m ).
            gr_column-&gt;set_long_text( col_l ).
            gr_column-&gt;set_color( lv_color_blue ).
  
            CLEAR: h_fieldname, colname.
            CONCATENATE 'JAHRW' new INTO h_fieldname.
            CONDENSE h_fieldname NO-GAPS.
            CONCATENATE 'Jahr' new INTO colname.
            CONDENSE colname NO-GAPS.
            col_s = colname.
            col_m = colname.
            col_l = colname.
            gr_column ?= gr_columns-&gt;get_column( columnname = h_fieldname ).
            gr_column-&gt;set_short_text( col_s ).
            gr_column-&gt;set_medium_text( col_m ).
            gr_column-&gt;set_long_text( col_l ).
          ENDDO.
  
        CATCH cx_salv_msg INTO exc.
          MESSAGE exc TYPE 'I' DISPLAY LIKE 'E'.
  
      ENDTRY.
  
    ENDLOOP.
  
    cl_salv_table=&gt;factory( IMPORTING r_salv_table = alv  CHANGING t_table = &lt;t_itab&gt; ).
  
  * Funktionsleiste
    lr_functions = alv-&gt;get_functions( ).
    lr_functions-&gt;set_all( if_salv_c_bool_sap=&gt;true ).
    lr_functions-&gt;set_print( if_salv_c_bool_sap=&gt;true ).
  
  * Optimierung der Spaltengröße
    gr_columns = alv-&gt;get_columns( ).
    gr_columns-&gt;set_optimize( abap_true ).
  
  * Titel
    gr_column ?= gr_columns-&gt;get_column( 'BONUS' ).
    gr_column-&gt;set_short_text( 'Zielbonus' ).
    gr_column-&gt;set_medium_text( 'Zielbonus' ).
    gr_column-&gt;set_long_text( 'Aliq. Zielbonus' ).
    gr_column-&gt;set_color( lv_color_red ).
  
    gr_column ?= gr_columns-&gt;get_column( 'BONAN' ).
    gr_column-&gt;set_short_text( 'B.anspruch' ).
    gr_column-&gt;set_medium_text( 'Bonusanspruch' ).
    gr_column-&gt;set_long_text( 'Bonusanspruch' ).
  
    gr_column ?= gr_columns-&gt;get_column( 'ANSPR' ).
    gr_column-&gt;set_short_text( 'Anspruch' ).
    gr_column-&gt;set_medium_text( 'Anspruch' ).
    gr_column-&gt;set_long_text( 'Anspruch' ).
  
    gr_column ?= gr_columns-&gt;get_column( 'SONDE' ).
    gr_column-&gt;set_short_text( 'Sond.reg.' ).
    gr_column-&gt;set_medium_text( 'Sonderregel.' ).
    gr_column-&gt;set_long_text( 'Sonderregelung' ).
  
    gr_column ?= gr_columns-&gt;get_column( 'COMM' ).
    gr_column-&gt;set_short_text( 'Komm.' ).
    gr_column-&gt;set_medium_text( 'Kommentar' ).
    gr_column-&gt;set_long_text( 'Kommentar' ).
  
    gr_column ?= gr_columns-&gt;get_column( 'PROBE' ).
    gr_column-&gt;set_short_text( 'Probez.' ).
    gr_column-&gt;set_medium_text( 'Probezeit' ).
    gr_column-&gt;set_long_text( 'Probezeit' ).
    gr_column-&gt;set_color( lv_color_green ).
  
  
    alv-&gt;display( ).
  
  ENDMETHOD.
  </code></pre>