Application Development 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: 

How to color cells in dynamic alv ??

former_member186143
Active Contributor
0 Kudos

I have searched for coloring individual alv cells but I can't find how to implement this with dynamic alv ?

somehow I have to add the table to the fieldcat for the alv since I have no structure defined but I can't find how to add this table to the fieldcats ??

and since I have 2 fieldcats , 1 for the reuse_alv and 1 for creating the dynamic table I'curious on which one to add this field.

I tried with

is_lvc_cat-tech = 'X'.

is_lvc_cat-fieldname = 'TCOLOR'.

is_lvc_cat-ref_field = 'TCOLOR'.

is_lvc_cat-ref_table = 'LVC_T_SCOL'.

is_lvc_cat-scrtext_s = is_lvc_cat-scrtext_m =

is_lvc_cat-scrtext_l = 'kleur'.

APPEND is_lvc_cat TO it_lvc_cat.

but somehow it is not working yet

I get the error 'LVC_T_SCOL' it the type of table without a head

kind regards

arthur

8 REPLIES 8

Former Member
0 Kudos

HI,

This is the sample example for coloring single cell.

tables: vbak.

type-pools: slis.

selection-screen: begin of block b1.

select-options: cust for vbak-kunnr.

selection-screen: end of block b1.

types: begin of ty_vbak,

vbeln type vbeln_va,

erdat type erdat,

ernam type ernam,

netwr type netwr_ak,

end of ty_vbak.

types: begin of ty_vbak1,

vbeln type vbeln_va,

erdat type erdat,

ernam type ernam,

netwr type netwr_ak,

tabcolor type lvc_t_scol,

end of ty_vbak1.

data: i_vbak type table of ty_vbak,

w_vbak type ty_vbak,

i_fieldcat type lvc_t_fcat, "slis_t_fieldcat_alv,

i_vbak1 type table of ty_vbak1,

w_vbak1 type ty_vbak1.

data: ls_layout type lvc_s_layo.

select vbeln erdat ernam netwr from vbak into table i_vbak where kunnr in cust.

perform fieldcat.

perform display.

&----


*& Form fieldcat

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form fieldcat .

data: w_fieldcat type line of lvc_t_fcat.

clear w_fieldcat.

w_fieldcat-fieldname = 'VBELN'.

w_fieldcat-tabname = 'I_VBAK'.

w_fieldcat-seltext = 'DOCUMENT NUMBER'.

append w_fieldcat to i_fieldcat.

clear w_fieldcat.

w_fieldcat-fieldname = 'ERDAT'.

w_fieldcat-tabname = 'I_VBAK'.

w_fieldcat-seltext = 'CREATED ON'.

append w_fieldcat to i_fieldcat.

clear w_fieldcat.

w_fieldcat-fieldname = 'ERNAM'.

w_fieldcat-tabname = 'I_VBAK'.

w_fieldcat-seltext = 'CREATED BY'.

append w_fieldcat to i_fieldcat.

clear w_fieldcat.

w_fieldcat-fieldname = 'NETWR'.

w_fieldcat-tabname = 'I_VBAK'.

w_fieldcat-seltext = 'NET PRICE'.

append w_fieldcat to i_fieldcat.

endform. " fieldcat

&----


*& Form display

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form display .

data: ls_tabcolor type lvc_s_scol.

loop at i_vbak into w_vbak.

if sy-tabix <> 3.

clear ls_tabcolor.

ls_tabcolor-fname = 'VBELN'.

ls_tabcolor-color-col = 1. " Blue.

ls_tabcolor-color-int = 0.

ls_tabcolor-color-inv = 0.

insert ls_tabcolor into table w_vbak1-tabcolor.

clear ls_tabcolor.

ls_tabcolor-fname = 'ERDAT'.

ls_tabcolor-color-col = 2. " Blue.

ls_tabcolor-color-int = 0.

ls_tabcolor-color-inv = 0.

insert ls_tabcolor into table w_vbak1-tabcolor.

clear ls_tabcolor.

ls_tabcolor-fname = 'ERNAM'.

ls_tabcolor-color-col = 3. " Blue.

ls_tabcolor-color-int = 0.

ls_tabcolor-color-inv = 0.

insert ls_tabcolor into table w_vbak1-tabcolor.

clear ls_tabcolor.

ls_tabcolor-fname = 'NETWR'.

ls_tabcolor-color-col = 4. " Blue.

ls_tabcolor-color-int = 0.

ls_tabcolor-color-inv = 0.

insert ls_tabcolor into table w_vbak1-tabcolor.

move-corresponding w_vbak to w_vbak1.

append w_vbak1 to i_vbak1.

else.

clear ls_tabcolor.

ls_tabcolor-fname = 'VBELN'.

ls_tabcolor-color-col = 1. " Blue.

ls_tabcolor-color-int = 0.

ls_tabcolor-color-inv = 0.

insert ls_tabcolor into table w_vbak1-tabcolor.

clear ls_tabcolor.

ls_tabcolor-fname = 'ERDAT'.

ls_tabcolor-color-col = 2. " Blue.

ls_tabcolor-color-int = 0.

ls_tabcolor-color-inv = 0.

insert ls_tabcolor into table w_vbak1-tabcolor.

clear ls_tabcolor.

ls_tabcolor-fname = 'ERNAM'.

ls_tabcolor-color-col = 3. " Blue.

ls_tabcolor-color-int = 0.

ls_tabcolor-color-inv = 0.

insert ls_tabcolor into table w_vbak1-tabcolor.

clear ls_tabcolor.

ls_tabcolor-fname = 'NETWR'.

ls_tabcolor-color-col = 6. " Blue.

ls_tabcolor-color-int = 0.

ls_tabcolor-color-inv = 0.

insert ls_tabcolor into table w_vbak1-tabcolor.

move-corresponding w_vbak to w_vbak1.

append w_vbak1 to i_vbak1.

endif.

clear w_vbak.

clear w_vbak1.

endloop.

**

**CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    • EXPORTING

      • I_INTERFACE_CHECK = ' '

      • I_BYPASSING_BUFFER = ' '

      • I_BUFFER_ACTIVE = ' '

    • I_CALLBACK_PROGRAM = SY-REPID

      • I_CALLBACK_PF_STATUS_SET = ' '

      • I_CALLBACK_USER_COMMAND = ' '

      • I_CALLBACK_TOP_OF_PAGE = ' '

      • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

      • I_CALLBACK_HTML_END_OF_LIST = ' '

      • I_STRUCTURE_NAME =

      • I_BACKGROUND_ID = ' '

      • I_GRID_TITLE =

      • I_GRID_SETTINGS =

      • IS_LAYOUT =

    • IT_FIELDCAT = I_FIELDCAT

      • IT_EXCLUDING =

      • IT_SPECIAL_GROUPS =

      • IT_SORT =

      • IT_FILTER =

      • IS_SEL_HIDE =

      • I_DEFAULT = 'X'

      • I_SAVE = ' '

      • IS_VARIANT =

      • IT_EVENTS =

      • IT_EVENT_EXIT =

      • IS_PRINT =

      • IS_REPREP_ID =

      • I_SCREEN_START_COLUMN = 0

      • I_SCREEN_START_LINE = 0

      • I_SCREEN_END_COLUMN = 0

      • I_SCREEN_END_LINE = 0

      • I_HTML_HEIGHT_TOP = 0

      • I_HTML_HEIGHT_END = 0

      • IT_ALV_GRAPHICS =

      • IT_HYPERLINK =

      • IT_ADD_FIELDCAT =

      • IT_EXCEPT_QINFO =

      • IR_SALV_FULLSCREEN_ADAPTER =

      • IMPORTING

      • E_EXIT_CAUSED_BY_CALLER =

      • ES_EXIT_CAUSED_BY_USER =

    • TABLES

    • T_OUTTAB = I_VBAK1

      • 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.

ls_layout-ctab_fname = 'TABCOLOR'.

call function 'REUSE_ALV_GRID_DISPLAY_LVC'

exporting

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

i_callback_program = sy-repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

is_layout_lvc = ls_layout

it_fieldcat_lvc = i_fieldcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS_LVC =

  • IT_SORT_LVC =

  • IT_FILTER_LVC =

  • IT_HYPERLINK =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

i_save = 'X'

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT_LVC =

  • IS_REPREP_ID_LVC =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IT_EXCEPT_QINFO_LVC =

  • IR_SALV_FULLSCREEN_ADAPTER =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

tables

t_outtab = i_vbak1

  • 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

reward if useful,

thanks and regards

Former Member
0 Kudos

Hi,

Check the below link.

[http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm|http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm]

Example

BCALV_GRID_VERIFY

Reward if found helpful

Regards,

Boobalan Suburaj

Former Member
0 Kudos

hi,

hope it is helpful.

Coloring It is possible to paint some cells, rows, and columns through the ALV Grid control. Basically, with no additional effort, if you set a column to be a key column it is automatically colored. To paint we have the following procedures.

Coloring an Entire Column To make an entire column be painted with the color you

want, you can use the u201Cemphasizeu201D option of the field catalog. Simply assign a color code to this field of the row added for your column. Color codes are constructed as follows:

Cxyz

Color numbers

1/0: inverse on/off

1/0: intensified on/off

Color numbers are:

x Color Intended for

1 gray-blue headers

2 light gray list bodies

3 yellow totals

4 blue-green key columns

5 green positive threshold value

6 red negative threshold value

7 orange Control levels

The u201Ckey settingu201D made via the field u201Ckeyu201D of the field catalog overrides this setting. So if you want this color to be colored different than the key color, you should set the u201Ckeyu201D field to space while generating the field catalog. However, then there may be some side effects on column orders. You can set the column order as you want at the frontend. But if this is not suitable for you, then unset all key settings and do all coloring and ordering as you want. Be careful that the function module generating the field catalog will always set the key properties of key fields.

Coloring an Entire Row

Coloring a row is a bit (really a bit) more complicated. To enable row coloring, you should add an additional field to your list data table. It should be of character type and length at least 4. This field will contain the color code for the row. So, letu2019s modify declaration of our list data table u201Cgt_listu201D.

--- Internal table holding list data

DATA BEGIN OF itab_list OCCURS 0 .

INCLUDE STRUCTURE MARA.

DATA rowcolor(4) TYPE c .

DATA END OF gt_list .

As you guess, you should fill the color code to this field. Its format will be the same as explained before To make ALV Grid know that you have loaded the color data for the row to this field, pass the name of the field containing color codes to the field u201CINFO_FNAMEu201D of the layout structure.

ps_layout-info_fname = <field_name_containing_color_codes>. u201Ce.g. u2018ROWCOLORu2019

You can fill that field anytime during execution. But, of course, due to the flow logic of screens, it will be reflected to your list display as soon as an ALV refresh occurs.

Coloring Individual Cells

This is the last point about coloring procedures for the ALV

Grid. The procedure is similar to coloring an entire row. However, since an individual cell canbe addressed with two parameters we will need something more. We will define table type structure to be included into the structure of the list data table. The structure that should be included must be of type u201CLVC_T_SCOLu201D. For each cell column, append a line to this inner table which also contains the column name at field u201Cfnameu201D. Again key field coloring will override your settings. Thatu2019s why we have another field in this inner table called u201Cnokeycolu201D. For each field represented in the inner table, set this field to u2018Xu2019 to prevent overriding of key color settings. In this procedure, again we must tell the control the name of the inner table containing color data. The field u201CCTAB_FNAMEu201D of the layout structure is used for this purpose.

We can use this approach for coloring an entire row or coloumn but will be more time consuming and not recommended

--- Internal table holding list data

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 itab_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 itab_list INDEX 5 .

reward if helpful,

regards,

srishti

Former Member
0 Kudos

0 Kudos

most of the links I have already investigated. but the problem is how do I add the color structure to a non existing structure which is build by adding the fieldcat

here as an example 2 static fields which are assigned to the the fieldcats



  is_lvc_cat-fieldname = 'VALIDITYDATE'.
  is_lvc_cat-ref_field = 'VALIDITYDATE'.
  is_lvc_cat-ref_table = 'BAPI7013_1'.
  is_lvc_cat-scrtext_s  = is_lvc_cat-scrtext_m =
  is_lvc_cat-scrtext_l  = 'Datum'.
  APPEND is_lvc_cat TO it_lvc_cat.

  is_fieldcat-fieldname     = 'VALIDITYDATE'.
  is_fieldcat-ref_fieldname = 'VALIDITYDATE'.
  is_fieldcat-ref_tabname   = 'BAPI7013_1'.
  is_fieldcat-outputlen     = 10.
  is_fieldcat-seltext_s = is_fieldcat-seltext_m =
                          is_fieldcat-seltext_l = 'Datum'.
  APPEND is_fieldcat TO it_fieldcat.


  is_lvc_cat-fieldname = 'WEEK'.
  is_lvc_cat-ref_field = 'WEEK'.
  is_lvc_cat-ref_table = 'SCAL'.
  is_lvc_cat-scrtext_s  = is_lvc_cat-scrtext_m =
  is_lvc_cat-scrtext_l  = 'Week'.
  APPEND is_lvc_cat TO it_lvc_cat.

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_lvc_cat
    IMPORTING
      ep_table        = ta_output.

* Create a new Line with the same structure of the table.
  ASSIGN ta_output->* TO <ta_output>.
  CREATE DATA new_line LIKE LINE OF <ta_output>.
  ASSIGN new_line->* TO <l_line>.

Somehow I have to add the color field to ta_output before it is assigned to the fields-symbol

I tried


*kleur
*  is_lvc_cat-tech = 'X'.
*  is_lvc_cat-fieldname = 'TCOLOR'.
*  is_lvc_cat-ref_field = 'TCOLOR'.
*  is_lvc_cat-ref_table = 'LVC_T_SCOL'.
*  is_lvc_cat-scrtext_s  = is_lvc_cat-scrtext_m =
*  is_lvc_cat-scrtext_l  = 'kleur'.
*  APPEND is_lvc_cat TO it_lvc_cat.
*
*  is_fieldcat-tech     = 'X'.
*  is_fieldcat-fieldname     = 'TCOLOR'.
*  is_fieldcat-ref_fieldname = 'TCOLOR'.
*  is_fieldcat-ref_tabname   = 'LVC_T_SCOL'.
*  is_fieldcat-outputlen     = 10.
*  is_fieldcat-seltext_s = is_fieldcat-seltext_m =
*                          is_fieldcat-seltext_l = 'kleur'.


*  APPEND is_fieldcat TO it_fieldcat.

but this code is not working (so it was also * )

0 Kudos

The issue could be as simple as realizing that the color struture is actually a table in your output structure. Basically an Internal table within an internal table.


DATA:
  col_rec         TYPE lvc_s_scol.
DATA ls_cellcolor TYPE lvc_s_scol .

DATA:
  BEGIN OF out_rec,
    leadid        TYPE zleadid,
    ltype         TYPE zlmltype,
    status        TYPE zlmstatus,
    ct            TYPE lvc_t_scol,
  END OF out_rec,
  it_out          LIKE STANDARD TABLE OF out_rec.

Later in the code, I do this to set the color


  SELECT leadid ltype status
    INTO (out_rec-leadid,
           out_rec-ltype,
           out_rec-status)
    FROM zlmlead.

    CLEAR ls_cellcolor.
    ls_cellcolor-fname = 'STATUS' .
    REFRESH out_rec-ct.
    CASE out_rec-status.
      WHEN 'CA001'.
        ls_cellcolor-color-col = '1' .
        ls_cellcolor-color-int = '0' .
      WHEN OTHERS.
        ls_cellcolor-color-col = '6' .
        ls_cellcolor-color-int = '1' .
    ENDCASE.
    APPEND ls_cellcolor TO out_rec-ct.  "<==  Note that this a table within IT_OUT.
    APPEND out_rec TO it_out.

Probably should mention this as well.. in the building of the LAYOUT,


FORM layout_build
    USING e05_ls_layout TYPE slis_layout_alv.
*
  CLEAR e05_ls_layout.
*
  e05_ls_layout-f2code = 'DISP'.
  e05_ls_layout-colwidth_optimize = 'X'.
  e05_ls_layout-zebra = 'X'.
  e05_ls_layout-detail_popup = 'X'.
  e05_ls_layout-detail_initial_lines = 'X'.
  e05_ls_layout-detail_titlebar = 'Demo for Coloring ALV Cells'.
  e05_ls_layout-coltab_fieldname = 'CT'.    "<== this is very important

The color table does not get any Field Catalog info at all. This code takes care of it.

Edited by: Paul Chapman on Jun 3, 2008 9:07 AM

0 Kudos

thanks Paul you're answer came close but not close enough

problem is that the function that creates the dynamic table is feeded with a fieldcatalog whether you use it or not further on in the alv.

the answer to the problem was quite simple. I had to refer to the color field of an existing structure which had the reference to lvc_t_scol.

ofcourse I could have used an existing structure to refer to but decided to make a new structure instead.

in ZALV_TECHFIELDS' I have defined a field color with element lvc_t_scol.

is_lvc_cat-tech = 'X'.

is_lvc_cat-fieldname = 'TCOLOR'.

is_lvc_cat-ref_field = 'COLOR'.

is_lvc_cat-ref_table = 'ZALV_TECHFIELDS'.

is_lvc_cat-scrtext_s = is_lvc_cat-scrtext_m =

is_lvc_cat-scrtext_l = 'kleur'.

APPEND is_lvc_cat TO it_lvc_cat.

and it is working perfectly

READ TABLE ta_ptreq_all WITH KEY pernr = h_formfield_pernr begda = h_datum.

IF sy-subrc = 0.

col_rec-color-col = '5' .

col_rec-color-int = '0' .

ELSE.

col_rec-color-col = '5' .

col_rec-color-int = '1' .

ENDIF.

ASSIGN COMPONENT 'TCOLOR' OF STRUCTURE <l_line> TO <ta_color>.

APPEND col_rec TO <ta_color> .

kind regards

arthur de smidt.

Edited by: A. de Smidt on Jun 5, 2008 11:58 AM

Edited by: A. de Smidt on Jun 6, 2008 4:41 PM

Former Member
0 Kudos

The follow program demonstrates how to change the colour of individual rows of an ALV grid. Changes required

from a basic ALV grid include adding a new field to ALV grid data table(it_ekko), Populating this field with color

attribute and adding an entry to layout control table.

&----


*& Report ZDEMO_ALVGRID *

*& *

&----


*& *

*& Example of a simple ALV Grid Report *

*& ................................... *

*& *

*& The basic ALV grid, Enhanced to display each row in a different *

*& colour *

&----


REPORT zdemo_alvgrid .

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.

&----


*& Form BUILD_FIELDCATALOG

&----


  • Build Fieldcatalog for ALV Report

----


form build_fieldcatalog.

  • There are a number of ways to create a fieldcat.

  • For the purpose of this example i will build the fieldcatalog manualy

  • by populating the internal table fields individually and then

  • appending the rows. This method can be the most time consuming but can

  • also allow you more control of the final product.

  • Beware though, you need to ensure that all fields required are

  • populated. When using some of functionality available via ALV, such as

  • total. You may need to provide more information than if you were

  • simply displaying the result

  • I.e. Field type may be required in-order for

  • the 'TOTAL' function to work.

fieldcatalog-fieldname = 'EBELN'.

fieldcatalog-seltext_m = 'Purchase Order'.

fieldcatalog-col_pos = 0.

fieldcatalog-outputlen = 10.

fieldcatalog-emphasize = 'X'.

fieldcatalog-key = 'X'.

  • fieldcatalog-do_sum = 'X'.

  • fieldcatalog-no_zero = 'X'.

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

&----


*& 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 row attributes(i.e. color)

gd_layout-info_fieldname = 'LINE_COLOR'.

  • gd_layout-totals_only = 'X'.

  • gd_layout-f2code = 'DISP'. "Sets fcode for when double

  • "click(press f2)

  • gd_layout-zebra = 'X'.

  • gd_layout-group_change_edit = 'X'.

  • gd_layout-header_text = 'helllllo'.

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 = 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

&----


*& Form DATA_RETRIEVAL

&----


  • 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

thanks

reward if useful

Richa