<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Color Codes for ALV in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523949#M847633</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you write the word "color" at code, and click on F1 over the word, you can get help about this values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dhruv Shah&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 04 Mar 2008 11:53:04 GMT</pubDate>
    <dc:creator>dhruv_shah3</dc:creator>
    <dc:date>2008-03-04T11:53:04Z</dc:date>
    <item>
      <title>Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523945#M847629</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to show the colored rows on ALV depending on conditions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Depending upon the conditions, row may have different colors.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, from where I can find that color codes (Like for Green - Color Code is 'C500')?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I anyone have the Codes please provide the color Code else, please provide the reference link or reference Document.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Waiting for reply.&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Thanks and Best regards,&lt;/P&gt;&lt;P&gt;Prasad&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2008 11:48:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523945#M847629</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-04T11:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523946#M847630</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Prasad,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Please check the program  &lt;STRONG&gt;SHOWCOLO&lt;/STRONG&gt; , you will get the required info&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2008 11:51:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523946#M847630</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-04T11:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523947#M847631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Chk for this sample code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You will get a better idea.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT zalv.

*****************************************************************
* Use of colours in ALV grid (cell, line and column) *
*****************************************************************

* Table
TABLES : mara.

* Type
TYPES : BEGIN OF ty_mara,
matnr LIKE mara-matnr,
matkl LIKE mara-matkl,
counter(4) TYPE n,
free_text(15) TYPE c,
color_line(4) TYPE c, " Line color
color_cell TYPE lvc_t_scol, " Cell color
END OF ty_mara.

* Structures
DATA : wa_mara TYPE ty_mara,
wa_fieldcat TYPE lvc_s_fcat,
is_layout TYPE lvc_s_layo,
wa_color TYPE lvc_s_scol.

* Internal table
DATA : it_mara TYPE STANDARD TABLE OF ty_mara,
it_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,
it_color TYPE TABLE OF lvc_s_scol.

* Variables
DATA : okcode LIKE sy-ucomm,
w_alv_grid TYPE REF TO cl_gui_alv_grid,
w_docking_container TYPE REF TO cl_gui_docking_container.


PARAMETERS : p_column AS CHECKBOX,
p_line AS CHECKBOX,
p_cell AS CHECKBOX.

START-OF-SELECTION.
PERFORM get_data.

END-OF-SELECTION.

PERFORM fill_catalog.
PERFORM fill_layout.

CALL SCREEN 2000.
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Module status_2000 OUTPUT
*&amp;amp;--------------------------------------------------------------*
* text
*---------------------------------------------------------------*
MODULE status_2000 OUTPUT.

SET PF-STATUS '2000'.

ENDMODULE. " status_2000 OUTPUT
*&amp;amp;---------------------------------------------------------------*
*&amp;amp; Module user_command_2000 INPUT
*&amp;amp;---------------------------------------------------------------*
* text
*----------------------------------------------------------------*
MODULE user_command_2000 INPUT.

DATA : w_okcode LIKE sy-ucomm.

MOVE okcode TO w_okcode.
CLEAR okcode.

CASE w_okcode.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.

ENDMODULE. " user_command_2000 INPUT
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Module alv_grid OUTPUT
*&amp;amp;--------------------------------------------------------------*
* text
*---------------------------------------------------------------*
MODULE alv_grid OUTPUT.

IF w_docking_container IS INITIAL.
PERFORM create_objects.
PERFORM display_alv_grid.
ENDIF.

ENDMODULE. " alv_grid OUTPUT
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Form create_objects
*&amp;amp;--------------------------------------------------------------*
* text
*---------------------------------------------------------------*
* --&amp;gt; p1 text
* &amp;lt;-- p2 text *---------------------------------------------------------------* FORM create_objects. * Ratio must be included in [5..95] CREATE OBJECT w_docking_container EXPORTING ratio = 95 EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 others = 6. CREATE OBJECT w_alv_grid EXPORTING i_parent = w_docking_container. ENDFORM. " create_objects *&amp;amp;--------------------------------------------------------------* *&amp;amp; Form display_alv_grid *&amp;amp;--------------------------------------------------------------* * text *---------------------------------------------------------------* * --&amp;gt; p1 text
* &amp;lt;-- p2 text *---------------------------------------------------------------* FORM display_alv_grid. CALL METHOD w_alv_grid-&amp;gt;set_table_for_first_display
EXPORTING
is_layout = is_layout
CHANGING
it_outtab = it_mara
it_fieldcatalog = it_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.

ENDFORM. " display_alv_grid
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Form get_data
*&amp;amp;--------------------------------------------------------------*
* text
*---------------------------------------------------------------*
* --&amp;gt; p1 text
* &amp;lt;-- p2 text *---------------------------------------------------------------* FORM get_data. SELECT * FROM mara UP TO 5 ROWS. CLEAR : wa_mara-color_line, wa_mara-color_cell. MOVE-CORRESPONDING mara TO wa_mara. ADD 1 TO wa_mara-counter. MOVE 'Blabla' TO wa_mara-free_text. IF wa_mara-counter = '0002' AND p_line = 'X'. * Color line MOVE 'C410' TO wa_mara-color_line. ELSEIF wa_mara-counter = '0004' AND p_cell = 'X'. * Color cell MOVE 'FREE_TEXT' TO wa_color-fname. MOVE '5' TO wa_color-color-col. MOVE '1' TO wa_color-color-int. MOVE '1' TO wa_color-color-inv. APPEND wa_color TO it_color. wa_mara-color_cell[] = it_color[]. ENDIF. APPEND wa_mara TO it_mara. ENDSELECT. ENDFORM. " get_data *&amp;amp;--------------------------------------------------------------* *&amp;amp; Form fill_catalog *&amp;amp;--------------------------------------------------------------* * text *---------------------------------------------------------------* * --&amp;gt; p1 text
* &amp;lt;-- p2 text *---------------------------------------------------------------* FORM fill_catalog. ***************************************************************** * Colour code : * * Colour is a 4-char field where : * * - 1st char = C (color property) * * - 2nd char = color code (from 0 to 7) * * 0 = background color * * 1 = blue * * 2 = gray * * 3 = yellow * * 4 = blue/gray * * 5 = green * * 6 = red * * 7 = orange * * - 3rd char = intensified (0=off, 1=on) * * - 4th char = inverse display (0=off, 1=on) * * * * Colour overwriting priority : * * 1. Line * * 2. Cell * * 3. Column * ***************************************************************** DATA : w_position TYPE i VALUE '1'. CLEAR wa_fieldcat. MOVE w_position TO wa_fieldcat-col_pos. MOVE 'MATNR' TO wa_fieldcat-fieldname. MOVE 'MARA' TO wa_fieldcat-ref_table. MOVE 'MATNR' TO wa_fieldcat-ref_field. APPEND wa_fieldcat TO it_fieldcat. ADD 1 TO w_position. CLEAR wa_fieldcat. MOVE w_position TO wa_fieldcat-col_pos. MOVE 'MATKL' TO wa_fieldcat-fieldname. MOVE 'MARA' TO wa_fieldcat-ref_table. MOVE 'MATKL' TO wa_fieldcat-ref_field. * Color column IF p_column = 'X'. MOVE 'C610' TO wa_fieldcat-emphasize. ENDIF. APPEND wa_fieldcat TO it_fieldcat. ADD 1 TO w_position. CLEAR wa_fieldcat. MOVE w_position TO wa_fieldcat-col_pos. MOVE 'COUNTER' TO wa_fieldcat-fieldname. MOVE 'N' TO wa_fieldcat-inttype. MOVE '4' TO wa_fieldcat-intlen. MOVE 'Counter' TO wa_fieldcat-coltext. APPEND wa_fieldcat TO it_fieldcat. ADD 1 TO w_position. CLEAR wa_fieldcat. MOVE w_position TO wa_fieldcat-col_pos. MOVE 'FREE_TEXT' TO wa_fieldcat-fieldname. MOVE 'C' TO wa_fieldcat-inttype. MOVE '20' TO wa_fieldcat-intlen. MOVE 'Text' TO wa_fieldcat-coltext. APPEND wa_fieldcat TO it_fieldcat. ENDFORM. " fill_catalog *&amp;amp;--------------------------------------------------------------* *&amp;amp; Form fill_layout *&amp;amp;--------------------------------------------------------------* * text *---------------------------------------------------------------* * --&amp;gt; p1 text
* &amp;lt;-- p2 text *---------------------------------------------------------------* FORM fill_layout. * Field that identify color line in internal table MOVE 'COLOR_LINE' TO is_layout-info_fname. * Field that identify cell color in inetrnal table MOVE 'COLOR_CELL' TO is_layout-ctab_fname. ENDFORM. " fill_layout Flow logic code Code: PROCESS BEFORE OUTPUT. MODULE status_2000. MODULE alv_grid. PROCESS AFTER INPUT. MODULE user_command_2000.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this solves your concern.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Vinayak&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code Formatted by: Alvaro Tejada Galindo on Mar 4, 2008 2:13 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2008 11:51:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523947#M847631</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-04T11:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523948#M847632</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here is a code for coloring rows in ALV...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;U can change as per ur need......&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
TABLES:     ekko.
 
TYPE-POOLS: slis.                                 "ALV Declarations
 
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
  line_color(4) TYPE c,     "Used to store row color attributes
 END OF t_ekko.
 
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
      wa_ekko TYPE t_ekko.
 
*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.
 
  PERFORM data_retrieval.
  PERFORM build_fieldcatalog.
  PERFORM build_layout.
  PERFORM display_alv_report.
 
 
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  BUILD_FIELDCATALOG
*&amp;amp;---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
FORM build_fieldcatalog.
 
  fieldcatalog-fieldname   = 'EBELN'.
  fieldcatalog-seltext_m   = 'Purchase Order'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
 
  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-seltext_m   = 'PO Item'.
  fieldcatalog-col_pos     = 1.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
 
  fieldcatalog-fieldname   = 'STATU'.
  fieldcatalog-seltext_m   = 'Status'.
  fieldcatalog-col_pos     = 2.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
 
  fieldcatalog-fieldname   = 'AEDAT'.
  fieldcatalog-seltext_m   = 'Item change date'.
  fieldcatalog-col_pos     = 3.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
 
  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material Number'.
  fieldcatalog-col_pos     = 4.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
 
  fieldcatalog-fieldname   = 'MENGE'.
  fieldcatalog-seltext_m   = 'PO quantity'.
  fieldcatalog-col_pos     = 5.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
 
  fieldcatalog-fieldname   = 'MEINS'.
  fieldcatalog-seltext_m   = 'Order Unit'.
  fieldcatalog-col_pos     = 6.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
 
  fieldcatalog-fieldname   = 'NETPR'.
  fieldcatalog-seltext_m   = 'Net Price'.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-datatype     = 'CURR'.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
 
  fieldcatalog-fieldname   = 'PEINH'.
  fieldcatalog-seltext_m   = 'Price Unit'.
  fieldcatalog-col_pos     = 8.
  APPEND fieldcatalog TO fieldcatalog.
  CLEAR  fieldcatalog.
ENDFORM.                    " BUILD_FIELDCATALOG
 
 
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  BUILD_LAYOUT
*&amp;amp;---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
FORM build_layout.
 
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-info_fieldname =      'LINE_COLOR'.
 
ENDFORM.                    " BUILD_LAYOUT
 
 
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  DISPLAY_ALV_REPORT
*&amp;amp;---------------------------------------------------------------------*
*       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
      is_layout          = gd_layout
      it_fieldcat        = fieldcatalog[]
      i_save             = 'X'
    TABLES
      t_outtab           = it_ekko
    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
 
 
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  DATA_RETRIEVAL
*&amp;amp;---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM data_retrieval.
  DATA: ld_color(1) TYPE c.
 
  SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
   UP TO 10 ROWS
    FROM ekpo
    INTO TABLE it_ekko.
 
*Populate field with color attributes
 
  LOOP AT it_ekko INTO wa_ekko.
 
* 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_ekko-line_color.
*  wa_ekko-line_color = 'C410'.
    MODIFY it_ekko FROM wa_ekko.
  ENDLOOP.
ENDFORM.                    " DATA_RETRIEVAL
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;lt;REMOVED BY MODERATOR&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Chandru&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Alvaro Tejada Galindo on Mar 4, 2008 2:14 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2008 11:52:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523948#M847632</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-04T11:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523949#M847633</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you write the word "color" at code, and click on F1 over the word, you can get help about this values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Dhruv Shah&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2008 11:53:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523949#M847633</guid>
      <dc:creator>dhruv_shah3</dc:creator>
      <dc:date>2008-03-04T11:53:04Z</dc:date>
    </item>
    <item>
      <title>Re: Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523950#M847634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;check if this helps u.&lt;/P&gt;&lt;P&gt;ALV COLURING SAMPLE CODE &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT zalv.

*****************************************************************
* Use of colours in ALV grid (cell, line and column) *
*****************************************************************

* Table
TABLES : mara.

* Type
TYPES : BEGIN OF ty_mara,
matnr LIKE mara-matnr,
matkl LIKE mara-matkl,
counter(4) TYPE n,
free_text(15) TYPE c,
color_line(4) TYPE c, " Line color
color_cell TYPE lvc_t_scol, " Cell color
END OF ty_mara.

* Structures
DATA : wa_mara TYPE ty_mara,
wa_fieldcat TYPE lvc_s_fcat,
is_layout TYPE lvc_s_layo,
wa_color TYPE lvc_s_scol.

* Internal table
DATA : it_mara TYPE STANDARD TABLE OF ty_mara,
it_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,
it_color TYPE TABLE OF lvc_s_scol.

* Variables
DATA : okcode LIKE sy-ucomm,
w_alv_grid TYPE REF TO cl_gui_alv_grid,
w_docking_container TYPE REF TO cl_gui_docking_container.


PARAMETERS : p_column AS CHECKBOX,
p_line AS CHECKBOX,
p_cell AS CHECKBOX.

START-OF-SELECTION.
PERFORM get_data.

END-OF-SELECTION.

PERFORM fill_catalog.
PERFORM fill_layout.

CALL SCREEN 2000.
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Module status_2000 OUTPUT
*&amp;amp;--------------------------------------------------------------*
* text
*---------------------------------------------------------------*
MODULE status_2000 OUTPUT.

SET PF-STATUS '2000'.

ENDMODULE. " status_2000 OUTPUT
*&amp;amp;---------------------------------------------------------------*
*&amp;amp; Module user_command_2000 INPUT
*&amp;amp;---------------------------------------------------------------*
* text
*----------------------------------------------------------------*
MODULE user_command_2000 INPUT.

DATA : w_okcode LIKE sy-ucomm.

MOVE okcode TO w_okcode.
CLEAR okcode.

CASE w_okcode.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.

ENDMODULE. " user_command_2000 INPUT
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Module alv_grid OUTPUT
*&amp;amp;--------------------------------------------------------------*
* text
*---------------------------------------------------------------*
MODULE alv_grid OUTPUT.

IF w_docking_container IS INITIAL.
PERFORM create_objects.
PERFORM display_alv_grid.
ENDIF.

ENDMODULE. " alv_grid OUTPUT
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Form create_objects
*&amp;amp;--------------------------------------------------------------*
* text
*---------------------------------------------------------------*
* --&amp;gt; p1 text
* &amp;lt;-- p2 text *---------------------------------------------------------------* FORM create_objects. * Ratio must be included in [5..95] CREATE OBJECT w_docking_container EXPORTING ratio = 95 EXCEPTIONS cntl_error = 1 cntl_system_error = 2 create_error = 3 lifetime_error = 4 lifetime_dynpro_dynpro_link = 5 others = 6. CREATE OBJECT w_alv_grid EXPORTING i_parent = w_docking_container. ENDFORM. " create_objects *&amp;amp;--------------------------------------------------------------* *&amp;amp; Form display_alv_grid *&amp;amp;--------------------------------------------------------------* * text *---------------------------------------------------------------* * --&amp;gt; p1 text
* &amp;lt;-- p2 text *---------------------------------------------------------------* FORM display_alv_grid. CALL METHOD w_alv_grid-&amp;gt;set_table_for_first_display
EXPORTING
is_layout = is_layout
CHANGING
it_outtab = it_mara
it_fieldcatalog = it_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.

ENDFORM. " display_alv_grid
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Form get_data
*&amp;amp;--------------------------------------------------------------*
* text
*---------------------------------------------------------------*
* --&amp;gt; p1 text
* &amp;lt;-- p2 text *---------------------------------------------------------------* FORM get_data. SELECT * FROM mara UP TO 5 ROWS. CLEAR : wa_mara-color_line, wa_mara-color_cell. MOVE-CORRESPONDING mara TO wa_mara. ADD 1 TO wa_mara-counter. MOVE 'Blabla' TO wa_mara-free_text. IF wa_mara-counter = '0002' AND p_line = 'X'. * Color line MOVE 'C410' TO wa_mara-color_line. ELSEIF wa_mara-counter = '0004' AND p_cell = 'X'. * Color cell MOVE 'FREE_TEXT' TO wa_color-fname. MOVE '5' TO wa_color-color-col. MOVE '1' TO wa_color-color-int. MOVE '1' TO wa_color-color-inv. APPEND wa_color TO it_color. wa_mara-color_cell[] = it_color[]. ENDIF. APPEND wa_mara TO it_mara. ENDSELECT. ENDFORM. " get_data *&amp;amp;--------------------------------------------------------------* *&amp;amp; Form fill_catalog *&amp;amp;--------------------------------------------------------------* * text *---------------------------------------------------------------* * --&amp;gt; p1 text
* &amp;lt;-- p2 text *---------------------------------------------------------------* FORM fill_catalog. ***************************************************************** * Colour code : * * Colour is a 4-char field where : * * - 1st char = C (color property) * * - 2nd char = color code (from 0 to 7) * * 0 = background color * * 1 = blue * * 2 = gray * * 3 = yellow * * 4 = blue/gray * * 5 = green * * 6 = red * * 7 = orange * * - 3rd char = intensified (0=off, 1=on) * * - 4th char = inverse display (0=off, 1=on) * * * * Colour overwriting priority : * * 1. Line * * 2. Cell * * 3. Column * ***************************************************************** DATA : w_position TYPE i VALUE '1'. CLEAR wa_fieldcat. MOVE w_position TO wa_fieldcat-col_pos. MOVE 'MATNR' TO wa_fieldcat-fieldname. MOVE 'MARA' TO wa_fieldcat-ref_table. MOVE 'MATNR' TO wa_fieldcat-ref_field. APPEND wa_fieldcat TO it_fieldcat. ADD 1 TO w_position. CLEAR wa_fieldcat. MOVE w_position TO wa_fieldcat-col_pos. MOVE 'MATKL' TO wa_fieldcat-fieldname. MOVE 'MARA' TO wa_fieldcat-ref_table. MOVE 'MATKL' TO wa_fieldcat-ref_field. * Color column IF p_column = 'X'. MOVE 'C610' TO wa_fieldcat-emphasize. ENDIF. APPEND wa_fieldcat TO it_fieldcat. ADD 1 TO w_position. CLEAR wa_fieldcat. MOVE w_position TO wa_fieldcat-col_pos. MOVE 'COUNTER' TO wa_fieldcat-fieldname. MOVE 'N' TO wa_fieldcat-inttype. MOVE '4' TO wa_fieldcat-intlen. MOVE 'Counter' TO wa_fieldcat-coltext. APPEND wa_fieldcat TO it_fieldcat. ADD 1 TO w_position. CLEAR wa_fieldcat. MOVE w_position TO wa_fieldcat-col_pos. MOVE 'FREE_TEXT' TO wa_fieldcat-fieldname. MOVE 'C' TO wa_fieldcat-inttype. MOVE '20' TO wa_fieldcat-intlen. MOVE 'Text' TO wa_fieldcat-coltext. APPEND wa_fieldcat TO it_fieldcat. ENDFORM. " fill_catalog *&amp;amp;--------------------------------------------------------------* *&amp;amp; Form fill_layout *&amp;amp;--------------------------------------------------------------* * text *---------------------------------------------------------------* * --&amp;gt; p1 text
* &amp;lt;-- p2 text *---------------------------------------------------------------* FORM fill_layout. * Field that identify color line in internal table MOVE 'COLOR_LINE' TO is_layout-info_fname. * Field that identify cell color in inetrnal table MOVE 'COLOR_CELL' TO is_layout-ctab_fname. ENDFORM. " fill_layout Flow logic code Code: PROCESS BEFORE OUTPUT. MODULE status_2000. MODULE alv_grid. PROCESS AFTER INPUT. MODULE user_command_2000. 
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;lt;REMOVED BY MODERATOR&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Thnaks &amp;amp; regards&lt;/P&gt;&lt;P&gt;Sravani .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Alvaro Tejada Galindo on Mar 4, 2008 2:15 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2008 11:54:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523950#M847634</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-04T11:54:14Z</dc:date>
    </item>
    <item>
      <title>Re: Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523951#M847635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;Color a Column Value in ALV Report &lt;/P&gt;&lt;P&gt;Example of how to color a column value in ALV Report. &lt;/P&gt;&lt;P&gt;REPORT  z_colour NO STANDARD PAGE HEADING  . &lt;/P&gt;&lt;P&gt;TABLES :pa0002. &lt;/P&gt;&lt;P&gt;  TYPE-POOLS: slis.                 "ALV Declarations &lt;/P&gt;&lt;P&gt;DATA : BEGIN OF it OCCURS 0, &lt;/P&gt;&lt;P&gt;      pernr LIKE pa0001-pernr, &lt;/P&gt;&lt;P&gt;      rufnm LIKE pa0002-rufnm, &lt;/P&gt;&lt;P&gt;      cell_colour TYPE lvc_t_scol,    "Cell colour &lt;/P&gt;&lt;P&gt;       END OF it. &lt;/P&gt;&lt;P&gt;SELECTION-SCREEN BEGIN OF BLOCK main WITH FRAME. &lt;/P&gt;&lt;P&gt;SELECT-OPTIONS :s_pnum  FOR pa0002-pernr . &lt;/P&gt;&lt;P&gt;SELECTION-SCREEN END OF BLOCK main. &lt;/P&gt;&lt;P&gt;*ALV data declarations &lt;/P&gt;&lt;P&gt;DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH &lt;/P&gt;&lt;P&gt;HEADER LINE, &lt;/P&gt;&lt;P&gt;      gd_layout    TYPE slis_layout_alv, &lt;/P&gt;&lt;P&gt;      gd_repid     LIKE sy-repid, &lt;/P&gt;&lt;P&gt;      gt_sort     TYPE slis_t_sortinfo_alv. &lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;To colour a cell. &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  DATA ls_cellcolour TYPE lvc_s_scol. &lt;/P&gt;&lt;P&gt;START-OF-SELECTION. &lt;/P&gt;&lt;P&gt;  PERFORM data_retrieval. &lt;/P&gt;&lt;P&gt;  PERFORM build_fieldcatalog. &lt;/P&gt;&lt;P&gt;  PERFORM build_layout. &lt;/P&gt;&lt;P&gt;  PERFORM display_alv_report. &lt;/P&gt;&lt;P&gt;END-OF-SELECTION. &lt;/P&gt;&lt;P&gt;  FREE : it. &lt;/P&gt;&lt;P&gt;FORM build_fieldcatalog . &lt;/P&gt;&lt;P&gt;  fieldcatalog-fieldname   = 'PERNR'. &lt;/P&gt;&lt;P&gt;  fieldcatalog-seltext_m   = 'Personnel No.'. &lt;/P&gt;&lt;P&gt;  fieldcatalog-col_pos     =  0. &lt;/P&gt;&lt;P&gt;  APPEND fieldcatalog TO fieldcatalog. &lt;/P&gt;&lt;P&gt;  CLEAR  fieldcatalog. &lt;/P&gt;&lt;P&gt;  fieldcatalog-fieldname   = 'RUFNM'. &lt;/P&gt;&lt;P&gt;  fieldcatalog-seltext_m   = 'Name'. &lt;/P&gt;&lt;P&gt;  fieldcatalog-col_pos     =  0. &lt;/P&gt;&lt;P&gt;  APPEND fieldcatalog TO fieldcatalog. &lt;/P&gt;&lt;P&gt;  CLEAR  fieldcatalog. &lt;/P&gt;&lt;P&gt;ENDFORM. &lt;/P&gt;&lt;P&gt;FORM build_layout . &lt;/P&gt;&lt;P&gt;  gd_layout-no_input          = 'X'. &lt;/P&gt;&lt;P&gt;  gd_layout-colwidth_optimize = 'X'. &lt;/P&gt;&lt;P&gt;  gd_layout-totals_text       = 'Totals'(256). &lt;/P&gt;&lt;P&gt;  gd_layout-coltab_fieldname = 'CELL_COLOUR'. &lt;/P&gt;&lt;P&gt;ENDFORM.                    " build_layout &lt;/P&gt;&lt;P&gt;FORM display_alv_report . &lt;/P&gt;&lt;P&gt;  gd_repid = sy-repid. &lt;/P&gt;&lt;P&gt;  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' &lt;/P&gt;&lt;P&gt;    EXPORTING &lt;/P&gt;&lt;P&gt;      i_callback_program       = gd_repid &lt;/P&gt;&lt;P&gt;      is_layout                = gd_layout &lt;/P&gt;&lt;P&gt;      it_fieldcat              = fieldcatalog[] &lt;/P&gt;&lt;P&gt;      i_save                   = 'A' &lt;/P&gt;&lt;P&gt;    TABLES &lt;/P&gt;&lt;P&gt;      t_outtab                 = it &lt;/P&gt;&lt;P&gt;    EXCEPTIONS &lt;/P&gt;&lt;P&gt;      program_error            = 1 &lt;/P&gt;&lt;P&gt;      OTHERS                   = 2. &lt;/P&gt;&lt;P&gt;  IF sy-subrc &amp;lt;&amp;gt; 0. &lt;/P&gt;&lt;P&gt;  ENDIF. &lt;/P&gt;&lt;P&gt;ENDFORM.                    " display_alv_report &lt;/P&gt;&lt;P&gt;FORM data_retrieval . &lt;/P&gt;&lt;P&gt;select pernr rufnm from pa0002 into corresponding &lt;/P&gt;&lt;P&gt;fields of table it where pernr in s_pnum. &lt;/P&gt;&lt;P&gt;  LOOP AT it. &lt;/P&gt;&lt;P&gt;*Now based on the value of the field pernr we can &lt;/P&gt;&lt;P&gt;change the cell colour of the field rufnm or pernr. &lt;/P&gt;&lt;P&gt;    IF it-pernr eq '10001' . &lt;/P&gt;&lt;P&gt;      ls_cellcolour-fname = 'RUFNM'. &lt;/P&gt;&lt;P&gt;      ls_cellcolour-color-col = '5'. &lt;/P&gt;&lt;P&gt;      ls_cellcolour-color-int = '1'. &lt;/P&gt;&lt;P&gt;      ls_cellcolour-color-inv = '0'. &lt;/P&gt;&lt;P&gt;      APPEND ls_cellcolour TO it-cell_colour. &lt;/P&gt;&lt;P&gt;      IF sy-subrc EQ 0. &lt;/P&gt;&lt;P&gt;        MODIFY it. &lt;/P&gt;&lt;P&gt;      ENDIF. &lt;/P&gt;&lt;P&gt;    ENDIF. &lt;/P&gt;&lt;P&gt;  ENDLOOP. &lt;/P&gt;&lt;P&gt;ENDFORM. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope it will help you&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sreelatha Gullapalli&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2008 11:55:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523951#M847635</guid>
      <dc:creator>sreelatha_gullapalli</dc:creator>
      <dc:date>2008-03-04T11:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523952#M847636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Syntax of color     value in     col color &lt;/P&gt;&lt;P&gt;&lt;SPAN __jive_macro_name="COL_BACKGROUND"&gt;&lt;/SPAN&gt;   0           GUI-specific &lt;/P&gt;&lt;P&gt;{ 1 | COL_HEADING }  1           Gray-blue &lt;/P&gt;&lt;P&gt;{ 2 | COL_NORMAL }   2           Light gray &lt;/P&gt;&lt;P&gt;{ 3 | COL_TOTAL }    3           Yellow &lt;/P&gt;&lt;P&gt;{ 4 | COL_KEY }      4           Blue-green &lt;/P&gt;&lt;P&gt;{ 5 | COL_POSITIVE } 5           Green &lt;/P&gt;&lt;P&gt;{ 6 | COL_NEGATIVE } 6           Red &lt;/P&gt;&lt;P&gt;{ 7 | COL_GROUP }    7           Violet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2008 11:57:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523952#M847636</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-04T11:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523953#M847637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Column and Row are colored with a coded color &amp;#145;Cxyz&amp;#146;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    Where C: Color (coding must begin with C)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;                 X: Color Number&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;                 Y: Bold&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;                 Z: Inverse. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;check out this link it might be helping you&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.saptechnical.com/Tutorials/ALV/ColorSALV/Demo.htm" target="test_blank"&gt;http://www.saptechnical.com/Tutorials/ALV/ColorSALV/Demo.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2008 11:59:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523953#M847637</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-04T11:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523954#M847638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;/P&gt;&lt;P&gt;these are the links&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.sap.com/www.sap-img.com/abap/sample-alv-heading-in-alv.htm" target="test_blank"&gt;www.sap-img.com/abap/sample-alv-heading-in-alv.htm&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A href="https://community.sap.com/www.sap-img.com/abap/line-color-in-alv-example.htm" target="test_blank"&gt;www.sap-img.com/abap/line-color-in-alv-example.htm&lt;/A&gt; &lt;/P&gt;&lt;P&gt;abap-gallery.blogspot.com/2007/07/change-layout-format-in-alv.html &lt;/P&gt;&lt;P&gt;&lt;A href="https://community.sap.com/www.erpgenie.com/abap/controls/alvgrid.htm" target="test_blank"&gt;www.erpgenie.com/abap/controls/alvgrid.htm&lt;/A&gt; &lt;/P&gt;&lt;P&gt;sap.niraj.tripod.com/id64.html &lt;/P&gt;&lt;P&gt;&lt;A href="https://community.sap.com/www.alvrobot.com.ar/tutorial.php" target="test_blank"&gt;www.alvrobot.com.ar/tutorial.php&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A class="jive_macro jive_macro_thread" href="https://community.sap.com/" __jive_macro_name="thread" modifiedtitle="true" __default_attr="746240"&gt;&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A href="https://community.sap.com/www.sapdesignguild.org/editions/edition9/leading_article.asp" target="test_blank"&gt;www.sapdesignguild.org/editions/edition9/leading_article.asp&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2008 11:59:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523954#M847638</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-04T11:59:54Z</dc:date>
    </item>
    <item>
      <title>Re: Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523955#M847639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The follow program demonstrates how to change the colour of individual rows of an ALV grid. Changes required&lt;/P&gt;&lt;P&gt;from a basic ALV grid include adding a new field to ALV grid data table(it_ekko), Populating this field with color&lt;/P&gt;&lt;P&gt;attribute and adding an entry to layout control table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp; Report  ZDEMO_ALVGRID                                               *&lt;/P&gt;&lt;P&gt;*&amp;amp;                                                                     *&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;                                                                     *&lt;/P&gt;&lt;P&gt;*&amp;amp; Example of a simple ALV Grid Report                                 *&lt;/P&gt;&lt;P&gt;*&amp;amp; ...................................                                 *&lt;/P&gt;&lt;P&gt;*&amp;amp;                                                                     *&lt;/P&gt;&lt;P&gt;*&amp;amp; The basic ALV grid, Enhanced to display each row in a different     *&lt;/P&gt;&lt;P&gt;*&amp;amp; colour                                                              *&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT  zdemo_alvgrid                 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TABLES:     ekko.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;type-pools: slis.                                 "ALV Declarations&lt;/P&gt;&lt;P&gt;*Data Declaration&lt;/P&gt;&lt;P&gt;*----&lt;/P&gt;&lt;HR originaltext="-----------" /&gt;&lt;P&gt;TYPES: BEGIN OF t_ekko,&lt;/P&gt;&lt;P&gt;  ebeln TYPE ekpo-ebeln,&lt;/P&gt;&lt;P&gt;  ebelp TYPE ekpo-ebelp,&lt;/P&gt;&lt;P&gt;  statu TYPE ekpo-statu,&lt;/P&gt;&lt;P&gt;  aedat TYPE ekpo-aedat,&lt;/P&gt;&lt;P&gt;  matnr TYPE ekpo-matnr,&lt;/P&gt;&lt;P&gt;  menge TYPE ekpo-menge,&lt;/P&gt;&lt;P&gt;  meins TYPE ekpo-meins,&lt;/P&gt;&lt;P&gt;  netpr TYPE ekpo-netpr,&lt;/P&gt;&lt;P&gt;  peinh TYPE ekpo-peinh,&lt;/P&gt;&lt;P&gt;  line_color(4) type c,     "Used to store row color attributes&lt;/P&gt;&lt;P&gt; END OF t_ekko.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,&lt;/P&gt;&lt;P&gt;      wa_ekko TYPE t_ekko.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*ALV data declarations&lt;/P&gt;&lt;P&gt;data: fieldcatalog type slis_t_fieldcat_alv with header line,&lt;/P&gt;&lt;P&gt;      gd_tab_group type slis_t_sp_group_alv,&lt;/P&gt;&lt;P&gt;      gd_layout    type slis_layout_alv,&lt;/P&gt;&lt;P&gt;      gd_repid     like sy-repid.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;************************************************************************&lt;/P&gt;&lt;P&gt;*Start-of-selection.&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;perform data_retrieval.&lt;/P&gt;&lt;P&gt;perform build_fieldcatalog.&lt;/P&gt;&lt;P&gt;perform build_layout.&lt;/P&gt;&lt;P&gt;perform display_alv_report.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  BUILD_FIELDCATALOG&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Build Fieldcatalog for ALV Report&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form build_fieldcatalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;There are a number of ways to create a fieldcat.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;For the purpose of this example i will build the fieldcatalog manualy&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;by populating the internal table fields individually and then&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;appending the rows. This method can be the most time consuming but can&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;also allow you  more control of the final product.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Beware though, you need to ensure that all fields required are&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;populated. When using some of functionality available via ALV, such as&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;total. You may need to provide more information than if you were&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;simply displaying the result&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;              I.e. Field type may be required in-order for&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;                   the 'TOTAL' function to work.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  fieldcatalog-fieldname   = 'EBELN'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-seltext_m   = 'Purchase Order'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-col_pos     = 0.&lt;/P&gt;&lt;P&gt;  fieldcatalog-outputlen   = 10.&lt;/P&gt;&lt;P&gt;  fieldcatalog-emphasize   = 'X'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-key         = 'X'.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; fieldcatalog-do_sum      = 'X'.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; fieldcatalog-no_zero     = 'X'.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  append fieldcatalog to fieldcatalog.&lt;/P&gt;&lt;P&gt;  clear  fieldcatalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  fieldcatalog-fieldname   = 'EBELP'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-seltext_m   = 'PO Item'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-col_pos     = 1.&lt;/P&gt;&lt;P&gt;  append fieldcatalog to fieldcatalog.&lt;/P&gt;&lt;P&gt;  clear  fieldcatalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  fieldcatalog-fieldname   = 'STATU'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-seltext_m   = 'Status'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-col_pos     = 2.&lt;/P&gt;&lt;P&gt;  append fieldcatalog to fieldcatalog.&lt;/P&gt;&lt;P&gt;  clear  fieldcatalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  fieldcatalog-fieldname   = 'AEDAT'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-seltext_m   = 'Item change date'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-col_pos     = 3.&lt;/P&gt;&lt;P&gt;  append fieldcatalog to fieldcatalog.&lt;/P&gt;&lt;P&gt;  clear  fieldcatalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  fieldcatalog-fieldname   = 'MATNR'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-seltext_m   = 'Material Number'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-col_pos     = 4.&lt;/P&gt;&lt;P&gt;  append fieldcatalog to fieldcatalog.&lt;/P&gt;&lt;P&gt;  clear  fieldcatalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  fieldcatalog-fieldname   = 'MENGE'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-seltext_m   = 'PO quantity'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-col_pos     = 5.&lt;/P&gt;&lt;P&gt;  append fieldcatalog to fieldcatalog.&lt;/P&gt;&lt;P&gt;  clear  fieldcatalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  fieldcatalog-fieldname   = 'MEINS'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-seltext_m   = 'Order Unit'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-col_pos     = 6.&lt;/P&gt;&lt;P&gt;  append fieldcatalog to fieldcatalog.&lt;/P&gt;&lt;P&gt;  clear  fieldcatalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  fieldcatalog-fieldname   = 'NETPR'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-seltext_m   = 'Net Price'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-col_pos     = 7.&lt;/P&gt;&lt;P&gt;  fieldcatalog-outputlen   = 15.&lt;/P&gt;&lt;P&gt;  fieldcatalog-datatype     = 'CURR'.&lt;/P&gt;&lt;P&gt;  append fieldcatalog to fieldcatalog.&lt;/P&gt;&lt;P&gt;  clear  fieldcatalog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  fieldcatalog-fieldname   = 'PEINH'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-seltext_m   = 'Price Unit'.&lt;/P&gt;&lt;P&gt;  fieldcatalog-col_pos     = 8.&lt;/P&gt;&lt;P&gt;  append fieldcatalog to fieldcatalog.&lt;/P&gt;&lt;P&gt;  clear  fieldcatalog.&lt;/P&gt;&lt;P&gt;endform.                    " BUILD_FIELDCATALOG&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  BUILD_LAYOUT&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Build layout for ALV grid report&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form build_layout.&lt;/P&gt;&lt;P&gt;  gd_layout-no_input          = 'X'.&lt;/P&gt;&lt;P&gt;  gd_layout-colwidth_optimize = 'X'.&lt;/P&gt;&lt;P&gt;  gd_layout-totals_text       = 'Totals'(201).&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Set layout field for row attributes(i.e. color) &lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  gd_layout-info_fieldname =      'LINE_COLOR'.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; gd_layout-totals_only        = 'X'.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; gd_layout-f2code            = 'DISP'.  "Sets fcode for when double&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;                                        "click(press f2)&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; gd_layout-zebra             = 'X'.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; gd_layout-group_change_edit = 'X'.&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; gd_layout-header_text       = 'helllllo'.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;endform.                    " BUILD_LAYOUT&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  DISPLAY_ALV_REPORT&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Display report using ALV grid&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form display_alv_report.&lt;/P&gt;&lt;P&gt;  gd_repid = sy-repid.&lt;/P&gt;&lt;P&gt;  call function 'REUSE_ALV_GRID_DISPLAY'&lt;/P&gt;&lt;P&gt;       exporting&lt;/P&gt;&lt;P&gt;            i_callback_program      = gd_repid&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;           i_callback_top_of_page   = 'TOP-OF-PAGE'  "see FORM&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;           i_callback_user_command = 'USER_COMMAND'&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;           i_grid_title           = outtext&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;            is_layout               = gd_layout&lt;/P&gt;&lt;P&gt;            it_fieldcat             = fieldcatalog[]&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;           it_special_groups       = gd_tabgroup&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;           IT_EVENTS                = GT_XEVENTS&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;            i_save                  = 'X'&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;           is_variant              = z_template&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       tables&lt;/P&gt;&lt;P&gt;            t_outtab                = it_ekko&lt;/P&gt;&lt;P&gt;       exceptions&lt;/P&gt;&lt;P&gt;            program_error           = 1&lt;/P&gt;&lt;P&gt;            others                  = 2.&lt;/P&gt;&lt;P&gt;  if sy-subrc &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;endform.                    " DISPLAY_ALV_REPORT&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*&amp;amp;      Form  DATA_RETRIEVAL&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;amp;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;      Retrieve data form EKPO table and populate itab it_ekko&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;----&lt;/STRONG&gt;&lt;/P&gt;&lt;HR originaltext="-----------------------------------------------------------------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;form data_retrieval.&lt;/P&gt;&lt;P&gt;data: ld_color(1) type c.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;select ebeln ebelp statu aedat matnr menge meins netpr peinh&lt;/P&gt;&lt;P&gt; up to 10 rows&lt;/P&gt;&lt;P&gt;  from ekpo&lt;/P&gt;&lt;P&gt;  into table it_ekko.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Populate field with color attributes&lt;/P&gt;&lt;P&gt;loop at it_ekko into wa_ekko.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Populate color variable with colour properties&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Char 1 = C (This is a color property)&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Char 2 = 3 (Color codes: 1 - 7)&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Char 3 = Intensified on/off ( 1 or 0 )&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Char 4 = Inverse display on/off ( 1 or 0 )&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;          i.e. wa_ekko-line_color = 'C410'&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  ld_color = ld_color + 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Only 7 colours so need to reset color value&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  if ld_color = 8.&lt;/P&gt;&lt;P&gt;    ld_color = 1.&lt;/P&gt;&lt;P&gt;  endif.&lt;/P&gt;&lt;P&gt;  concatenate 'C' ld_color '10' into wa_ekko-line_color.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt; wa_ekko-line_color = 'C410'.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  modify it_ekko from wa_ekko.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;endform.                    " DATA_RETRIEVAL&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Mar 2008 12:03:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523955#M847639</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-04T12:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Color Codes for ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523956#M847640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice answers, very usefull !&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks to all repliers,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a nice day.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Aug 2014 10:24:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/color-codes-for-alv/m-p/3523956#M847640</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-08-05T10:24:38Z</dc:date>
    </item>
  </channel>
</rss>

