Coloring an individual cell in factory method

hi
i generate a report using factory method by passing one internal table ti it
now i want to color particular cells based on some condition.
color is red. any pointers...pls provide code if you have.
thnks in advance.

hi,
check this..
*& Report  Y_TEST
REPORT  y_test.
TABLES: mara.
DATA: str1 TYPE string,
      str2 TYPE string,
      str3 TYPE string,
      str4 TYPE lvc_title,
      num TYPE i,
      c1(5) TYPE c.
DATA: value1 TYPE salv_s_layout,
      key TYPE salv_s_layout_key VALUE sy-repid,
      tool TYPE lvc_tip,
      col TYPE lvc_s_colo,
      cell TYPE salv_t_cell.
DATA: gr_table TYPE REF TO cl_salv_table,
      gr_functions TYPE REF TO cl_salv_functions,
      gr_layout TYPE REF TO cl_salv_layout,
      gr_display TYPE REF TO cl_salv_display_settings,
      gr_column TYPE REF TO cl_salv_column_table,
      gr_columns TYPE REF TO cl_salv_columns_table,
      gr_aggregations TYPE REF TO cl_salv_aggregations,
      gr_aggregation TYPE REF TO cl_salv_aggregation,
      gr_selections TYPE REF TO cl_salv_selections,
      gr_sorts TYPE REF TO cl_salv_sorts.
DATA: it_mseg TYPE STANDARD TABLE OF mseg WITH HEADER LINE.
SELECT * FROM mseg INTO CORRESPONDING FIELDS OF TABLE it_mseg  WHERE werks = 'KWWK' AND matnr NE ' '.
*--ALV display-------------------------------------------------*
cl_salv_table=>factory(
IMPORTING r_salv_table = gr_table
CHANGING t_table = it_mseg[] ).   "gr_table Instance created
*---Setting the ALV toolbar-------------------------------------*
gr_functions = gr_table->get_functions( ).   "gr_functions instance created
gr_functions->set_all( abap_true ).
*---Setting the Layout------------------------------------------*
gr_layout = gr_table->get_layout( ).
*gr_layout->set_key( key ).
gr_layout->set_save_restriction( ).
*---Setting the header------------------------------------------*
gr_display = gr_table->get_display_settings( ).
str1 = 'Display of MSEG Table'.
str2 = '-'.
DESCRIBE TABLE it_mseg LINES num.
c1 = num.
str3 = ' Rows are Selected'.
CONCATENATE str1 str2 c1 str3 INTO str4.
gr_display->set_list_header( str4 ).
*---Zebra-------------------------------------------------------*
gr_display->set_striped_pattern( 'X' ).
*---Deactivating horizontal line--------------------------------*
gr_display->set_horizontal_lines( ' ' ).
*---Deactivating vertical line----------------------------------*
*gr_display->set_vertical_lines( ' ' ).
*---Set color to Column-----------------------------------------*
*col-col = 3.
*col-int = 1.
*col-inv = 1.
*gr_columns = gr_table->get_columns( ).
*gr_column ?= gr_columns->get_column( 'LAEDA' ).
*gr_column->set_color( col ).
*col-col = 5.
*col-int = 1.
*col-inv = 1.
*gr_columns = gr_table->get_columns( ).
*gr_column ?= gr_columns->get_column( 'ERNAM' ).
*gr_column->set_color( col ).
col-col = 4.
col-int = 0.
col-inv = 1.
gr_columns = gr_table->get_columns( ).
gr_column ?= gr_columns->get_column( 'BWART' ).
gr_column->set_color( col ).
gr_column->set_alignment( '3' ).
gr_column->set_tooltip( 'helllooooo' ).
*----Set key column----------------------------------------------*
gr_columns->set_key_fixation( 'X' ).
*----Setting total-----------------------------------------------*
gr_aggregations = gr_table->get_aggregations( ).
gr_aggregation = gr_aggregations->add_aggregation( 'MENGE' ).
gr_aggregation->set( if_salv_c_aggregation=>total ).
gr_aggregations = gr_table->get_aggregations( ).
gr_aggregation = gr_aggregations->add_aggregation( 'DMBTR' ).
gr_aggregation->set( if_salv_c_aggregation=>total ).
*----Selection---------------------------------------------------*
gr_selections = gr_table->get_selections( ).
gr_selections->set_selection_mode( cl_salv_selections=>if_salv_c_selection_mode~cell ).
*----Setting of sort & subtotal column---------------------------------------*
gr_sorts = gr_table->get_sorts( ).
gr_sorts->add_sort( columnname = 'MATNR' subtotal = 'X').
*gr_sorts->get_subtotals( ).
gr_table->display( ).
Arunima

Similar Messages

  • How do you change the colors of individual cells within a 2D array?

    How do you change the colors of individual cells within a 2D array of numeric indicators?
    I want the VI to check a data value and if it is failing, white out a square at a specific index coordinate.  I have it working with color boxes, but I'm not sure how to use the property node function, to change the color of individual cells, by coordinates.
    I have attached the VI using color boxes. If you run the VI, the box corresponding to the Step control should turn white.
    I want to do the same thing, using numeric indicator boxes inside the array.
    Thanks for any suggestions...
    Attachments:
    Fill DME matrix.vi ‏95 KB

    Get rid of all these sequences! That's just bad form.
    Your code has a few logical problems. Why do you create a boolean array if you later only look at the last element (Yes, the FOR loop does nothing useful, except in the last iteration because your outputs are not indexing. All other iterations are useless, you only get the result of the last array element. My guess is that you want to color the index white if at least one of the numbers is out if range. Right?
    It is an absolute nightmare to manage all your numeric labels. Just read them from a 2D array. Now you can simply find the index of the matched elements and don't have to spend hours editing case structure conditions.
    Attached is a simple example how you would do what I meant (LV7.1). Modify as needed.
    Message Edited by altenbach on 04-04-2006 02:04 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Fill_2DME_matrixMOD.vi ‏70 KB

  • Change the background color of a cell in JTable

    Hi all,
    How can I change the background color of individual cell in JTable. I need to construct my own TableCellRenderer or not? I'm now using the DefaultTableCellRenderer now.
    Thx

    You could create your own renderer or you could try something like:
    table = new JTable(model)
         public TableCellRenderer getCellRenderer(int row, int column)
              DefaultTableCellRenderer tcr =
               (DefaultTableCellRenderer)super.getCellRenderer(row, column);
              if (row == 1 && column == 1)
                   tcr.setBackground(Color.green);
              else
                   tcr.setBackground(Color.red);
              return tcr;
    };

  • Coloring an single field of an ALV using factory method

    how can we color just a single field in ALV using factory method.

    Hello Regi you may want to check this sample code, basically what you need is to use the lvc_s_colo structure and the  set_color method of the class cl_salv_column_table.
    METHOD set_colors.
    *.....Color for COLUMN.....
        DATA: lo_cols_tab TYPE REF TO cl_salv_columns_table,
              lo_col_tab  TYPE REF TO cl_salv_column_table.
        DATA: ls_color TYPE lvc_s_colo.    " Colors strucutre
    *   get Columns object
        lo_cols_tab = co_alv->get_columns( ).
        INCLUDE <color>.
    *   Get ERDAT column & set the yellow Color fot it
        TRY.
            lo_col_tab ?= lo_cols_tab->get_column( 'ERDAT' ).
            ls_color-col = col_total.
            lo_col_tab->set_color( ls_color ).
          CATCH cx_salv_not_found.
        ENDTRY.
    *.......Color for Specific Cell & Rows.................
    *   Applying color on the 3rd Row and Column AUART
    *   Applying color on the Entire 5th Row
        DATA: lt_s_color TYPE lvc_t_scol,
              ls_s_color TYPE lvc_s_scol,
              la_vbak    LIKE LINE OF ct_vbak,
              l_count    TYPE i.
        LOOP AT ct_vbak INTO la_vbak.
          l_count = l_count + 1.
          CASE l_count.
    *       Apply RED color to the AUART Cell of the 3rd Column
            WHEN 3.
              ls_s_color-fname     = 'AUART'.
              ls_s_color-color-col = col_negative.
              ls_s_color-color-int = 0.
              ls_s_color-color-inv = 0.
              APPEND ls_s_color TO lt_s_color.
              CLEAR  ls_s_color.
    *       Apply GREEN color to the entire row # 5
    *         For entire row, we don't pass the Fieldname
            WHEN 5.
              ls_s_color-color-col = col_positive.
              ls_s_color-color-int = 0.
              ls_s_color-color-inv = 0.
              APPEND ls_s_color TO lt_s_color.
              CLEAR  ls_s_color.
          ENDCASE.
    *     Modify that data back to the output table
          la_vbak-t_color = lt_s_color.
          MODIFY ct_vbak FROM la_vbak.
          CLEAR  la_vbak.
          CLEAR  lt_s_color.
        ENDLOOP.
    *   We will set this COLOR table field name of the internal table to
    *   COLUMNS tab reference for the specific colors
        TRY.
            lo_cols_tab->set_color_column( 'T_COLOR' ).
          CATCH cx_salv_data_error.                         "#EC NO_HANDLER
        ENDTRY.
      ENDMETHOD.                    "set_colors

  • Edit Colors of Individual JTable Cells?

    I want to make a JTable that has some blank cells for a TV program I'm writing. These blank cells will be the same color as the cells to the left of them. I wrote a ColorCellRenderer to do just this, as shown:
    class ColorCellRenderer extends DefaultTableCellRenderer
        Color prevColor = Color.white;
        private Color[] colors = {Color.cyan, Color.yellow, Color.pink, Color.orange};
        public void setCellColor(JTable table, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column)
            Object presValue = table.getValueAt(row,column);
            if (presValue.equals(""))
                getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column).setBackground(prevColor);
            else if (column > 0)
                getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column).setBackground(colors[column-1]);
                prevColor = colors[column-1];
    }Then, in my JTable subclass, I loop through the cells, like this:
    ColorCellRenderer ccr;
            for (int i = 0; i < getRowCount(); i++)
                Color prevColor = Color.white;
                for (int j = 1; j < getColumnCount(); j++)
                    ccr = (ColorCellRenderer)getColumnModel().getColumn(j).getCellRenderer();
                    if (j > 1 && items[i][j].equals("")) {
                        ccr.setCellColor(this, items[i][j], false, false, i, j);
                    else {
                        ccr.setCellColor(this, items[i][j], false, false, i, j);
            }And of course I added my ColorCellRenderer to the updateUI() method of this JTable subclass.
    The problem is, the JTable seems to only let me have one color per column. Here's what the result looks like:
    http://img264.imageshack.us/img264/1397/picture3vt6.png
    Anyone know why this is happening?

    Nevermind, I misread a doc. I needed to override the getTableCellRendererComponent method. Here's the method, along with a screenshot of the program in all its glory:
    class ColorCellRenderer extends DefaultTableCellRenderer
        private Color[] colors = {Color.cyan, Color.yellow, Color.pink, Color.orange};
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column)
            if (value.equals(""))
                Color c = colors[column-1];
                switch (column) {
                    case 2:
                        c = colors[0];
                        break;
                    case 3:
                        c = colors[1];
                        if (table.getValueAt(row, 2).equals(""))
                            c = colors[0];
                        break;
                    case 4:
                        c = colors[2];
                        if (table.getValueAt(row, 3).equals("")) {
                            c = colors[1];
                            if (table.getValueAt(row, 2).equals(""))
                                c = colors[0];
                        break;
                super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column).setBackground(c);
            else if (column > 0)
                super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column).setBackground(colors[column-1]);
            else {
                super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column).setBackground(Color.white);
            return this;
    }Screenshot:
    http://img145.imageshack.us/img145/639/picture4mr4.png
    That's it. For some reason the Channels column will not shrink, but I'm sure I'll figure it out.

  • Coloring a Particular Cell

    Hi,
           Please find below the sample program in which tried to color a particular cell. But it is not applying the color. Please help me to resolve this issues.
    Thanks in Advance,
    Sunil Kumar
    *& Report  ZSAPCOLV
    REPORT  ZSAPCOLV.
    TABLES:mara.
    TYPES:BEGIN OF ty_mara,
          matnr TYPE mara-matnr,
          mtart TYPE mara-mtart,
         END OF ty_mara.
    DATA:it_mara TYPE STANDARD TABLE OF ty_mara,
         it_color  type table  of lvc_s_scol,
         wa_mara TYPE ty_mara,
         wa_color    type lvc_s_scol,
         is_layout   type lvc_s_layo.
    DATA: t_newtable TYPE REF TO data,
    t_newline  TYPE REF TO data.
    FIELD-SYMBOLS: <dyntab> TYPE STANDARD TABLE,
                   <wa_dyntab> TYPE ANY,
                   <gfs_wa> TYPE ANY.
    TYPES: BEGIN OF ty_cmara,
         matnr TYPE mara-matnr,
          mtart TYPE mara-mtart,
        tabcolor TYPE lvc_t_scol,
      END OF ty_cmara.   " Cell color
    DATA:it_cmara TYPE STANDARD TABLE OF ty_cmara.
    DATA:
          gr_table     TYPE REF TO cl_salv_table,
          gr_functions TYPE REF TO cl_salv_functions,
          gr_display   TYPE REF TO cl_salv_display_settings.
    DATA:   it_fcat TYPE lvc_t_fcat,
            wa_fcat TYPE lvc_s_fcat.
    DATA:it_fcat1 TYPE lvc_t_fcat, "with cell color
         it_fcat2 TYPE lvc_t_fcat,
    wa_fieldcat LIKE LINE OF it_fcat1,
    wa_cellcolors TYPE lvc_s_scol,
    wa_is_layout TYPE lvc_s_layo.
    FIELD-SYMBOLS:<t_cellcolors> TYPE lvc_t_scol,
    <w_field> TYPE ANY.
    DATA:t_line  TYPE REF TO data .
    *-----design selection screen for plant and material type.
    selection-screen begin of block b1 with frame title text-b01.
    select-options:
                     s_matnr     for mara-matnr.    "material type
    selection-screen end of block b1.
    START-OF-SELECTION.
      PERFORM fetch_data.
      PERFORM display_data.
    *&      Form  fetch_data
    FORM fetch_data .
    DATA:wa_cmara TYPE ty_cmara.
    DATA: ls_tabcolor TYPE lvc_s_scol.
      SELECT
    FROM mara
        INTO CORRESPONDING FIELDS OF TABLE it_mara where matnr in s_matnr.
      CHECK sy-subrc EQ 0.
      PERFORM build_catalog USING '1' 'MATNR' 'Material number' 'Material Number' ' ' '18'.
      PERFORM build_catalog USING '1' 'MTART' 'Material type' 'Material type' ' ' '10'.
      it_fcat1[] = it_fcat[].
       wa_fieldcat-fieldname = 'T_CELLCOLORS'.
       wa_fieldcat-ref_field = 'COLTAB'.
       wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
      APPEND wa_fieldcat TO it_fcat.
      cl_alv_table_create=>create_dynamic_table( EXPORTING it_fieldcatalog = it_fcat
                                                  IMPORTING ep_table = t_newtable ).
      ASSIGN t_newtable->* TO <dyntab>.
      CREATE DATA t_line LIKE LINE OF <dyntab>.
      ASSIGN t_line->* TO <gfs_wa>.
      PERFORM fill_data.
    ENDFORM.                    " fetch_data
    *&      Form  build_catalog
    FORM build_catalog  USING    p_pos TYPE lvc_colpos
                           p_field TYPE lvc_fname
                           p_reptext TYPE reptext
                           p_coltext type coltext
                           p_check TYPE lvc_checkb
                           p_len TYPE lvc_outlen.
      wa_fcat-col_pos    = p_pos.
      wa_fcat-fieldname  = p_field.
      wa_fcat-reptext    = p_reptext.
      wa_fcat-checkbox   = p_check.
      wa_fcat-outputlen  = p_len.
      IF p_check = 'X'.
        wa_fcat-edit = 'X'.
      ENDIF.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
    ENDFORM.                    " catalog
    *&      Form  fill_data
    FORM fill_data .
      FIELD-SYMBOLS: <wa_tmp> TYPE ANY,
                     <v_fld> TYPE ANY,
                     <color> TYPE ANY.
      DATA: v_fld(20).
      DATA : lv_cnt TYPE i,
             lv_cnt1 TYPE i.
      DATA:wa_cmara TYPE ty_cmara.
      LOOP AT it_mara INTO wa_mara.
        lv_cnt1 = lv_cnt1 + 1.
        LOOP AT it_fcat INTO wa_fcat.
          UNASSIGN <wa_tmp>.
          ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <gfs_wa> TO <wa_tmp>.
          CONCATENATE 'WA_MARA-' wa_fcat-fieldname INTO v_fld.
          ASSIGN (v_fld) TO <v_fld>.
          CHECK sy-subrc EQ 0.
          <wa_tmp> = <v_fld>.
          lv_cnt = lv_cnt + 1.
          IF lv_cnt = 1.
            APPEND <gfs_wa> TO <dyntab>.
          ELSE.
            MODIFY <dyntab> INDEX lv_cnt1 FROM <gfs_wa>.
          ENDIF.
        ENDLOOP.
        lv_cnt = 0.
        CLEAR wa_mara.
      ENDLOOP.
    ENDFORM.                    " fill_data
    *&      Form  display_data
    FORM display_data .
      IF <dyntab> IS NOT INITIAL.
        LOOP AT <dyntab> INTO <gfs_wa>.
          ASSIGN COMPONENT 'MATNR' OF STRUCTURE <gfs_wa> TO <w_field>.
          ASSIGN COMPONENT 'T_CELLCOLORS' OF STRUCTURE <gfs_wa> TO <t_cellcolors> .
          CLEAR wa_cellcolors.
         wa_cellcolors-fname = 'MATNR'.
          IF <w_field> = '000000000100000012'.
            wa_cellcolors-color-col = '6'.
            wa_cellcolors-color-int = '1'.
            wa_cellcolors-color-inv = '1'.
           ELSE.
           wa_cellcolors-color-col = '5'.
         ENDIF.
          APPEND wa_cellcolors TO <t_cellcolors>.
          MODIFY <dyntab> FROM <gfs_wa>.
        ENDLOOP.
        cl_salv_table=>factory( IMPORTING r_salv_table = gr_table CHANGING t_table = <dyntab> ).
        gr_functions = gr_table->get_functions( ).
        gr_functions->set_all( abap_true ).
        gr_display = gr_table->get_display_settings( ).
        gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
        gr_display->set_list_header( 'MARA DATA' ).
        gr_table->display( ).
      ENDIF.
    ENDFORM.                    " display_data

    Hi Sunil,
    Coloring a cell is pretty simple.
    1.
    FORMAT COLOR 3 INTENSIFIED ON.
    WRITE:/15 FS_TABLE-FIELD1.
    FORMAT COLOR OFF.
    Color 3 which is Yellow, begins from 0 to last letter of FIELD1.
    To color up the entire row, you can mention
    FORMAT COLOR 3 INTENSIFIED ON.
    WRITE:/15(255) FS_TABLE-FIELD1.
    FORMAT COLOR OFF.
    2. Coloring a cell, carries a bit different method
    LOOP..
    WRITE:/ FS_TABLE-FIELD1 COLOR 3,
                 FS_TABLE-FIELD2-COLOR4.
    ENDLOOP.
    Hope this really helps you,
    Courtesy: Zahackson
    Edited by: Zahackson on Feb 6, 2009 10:25 AM

  • ALV color priority:  The layout color or the cell color?

    I'm trying to assign an ALV at the cell level but it is not showing up.  I have specificed the column color at the layout level.  Does the layout level have color priority?

    Hi
    see the doc and do accordingly
    1. add one more field to ur final internal table say COLOR(4)
    2. in layout wa_layout-style_fname = 'COLOR'. " if its grid
    wa_layout-style_fieldname = 'COLOR'. "if its list
    3. read table itab index 3.
    itab-color = 'C410'.
    modify itab index 3
    4. see program SHOWCOLO for all color codes
    1. Add a field of data type CHAR(3) to the internal output table.
    2. Enter the color code in the appropriate field of the row to be colored in the internal
    output table:
    Code: 'Cxy'
    C = Color (all codes begin with 'C')
    x = color number ('1' - '9')
    y = highlight ('0' = off, '1' = on)
    3. Assign the internal output table color code field name to the IS_LAYOUT importing
    structure IS_LAYOUT-INFO_FIELDNAME field and pass this structure in the ALV call
    interface.
    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, let’s modify declaration of our list data table “gt_list”.
    you should fill the color code to this field. Its format will be the same as explained before at section C.6.3. But how will ALV Grid know that you have loaded the color data for the row to this field. So, you make it know this by passing the name of the field containing color codes to the field “INFO_FNAME” of the layout structure.
    e.g.
    ps_layout-info_fname = <field_name_containing_color_codes>. “e.g. ‘ROWCOLOR’
    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.
    You can color an entire row as described in the next section. However, this method is less time consuming.
    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 can be addressed with two parameters we will need something more. What is meant by “more” is a table type structure to be included into the structure of the list data table. It seems strange, because including it will make our list data structure deep. But anyhow ALV Grid control handles this.
    The structure that should be included must be of type “LVC_T_SCOL”. If you want to color the entire row, this inner table should contain only one row with field “fname” is set to space, some color value at field “col”, “0” or “1” at fields “int” (intensified) and “inv” (inverse).
    If you want to color individual cells, then for each cell column, append a line to this inner table which also contains the column name at field “fname”. It is obvious that you can color an entire column by filling this inner table with a row for that column for each row in the list data table.
    Regards
    Anji

  • How to change the Background color of a cell in JTable

    hi!
    Actually i want to change the background color of few cells in JTable
    is there any method to make this change in JTable ?
    and also is it possible to have 5 rows with single column and 5 rows with 3 columns in a single JTable

    i want to change the background color of few cells in JTableDepending on your requirements for the coloring of cells it may be easier to override the prepareRenderer() method of JTable:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474

  • Problem in factory method, how to pass arguments ?

    Hello it's me again :)
    here's the code :
    package print;
    import java.util.*;
    import static print.Print.*;
    interface Fact<T> {
    T create(String n);;
    T create ();
    class PetColl {
          public String toString() {
          return getClass().getSimpleName();
          static List<Fact<? extends Pet>> petSpecies=
          new ArrayList<Fact<? extends Pet>>();
          static {
          // Collections.addAll() gives an "unchecked generic
          // array creation ... for varargs parameter" warning.
               petSpecies.add(new Cymric.Factory());
               petSpecies.add(new EgyptianMau.Factory());
               petSpecies.add(new Hamster.Factory());
               petSpecies.add(new Manx.Factory());
               petSpecies.add(new Mouse.Factory());
               petSpecies.add(new Pug.Factory());
               petSpecies.add(new Mutt.Factory());
               petSpecies.add(new Rat.Factory());
          private static Random rand = new Random(47);
          public static Pet createRandom() {
          int n = rand.nextInt(petSpecies.size());
          return petSpecies.get(n).create();
          public Pet[] createArray(int size) {
               Pet[] result = new Pet[size];
               for(int i = 0; i < size; i++)
               result[i] = createRandom();
               return result;
          public ArrayList<Pet> arrayList(int size) {
               ArrayList<Pet> result = new ArrayList<Pet>();
               Collections.addAll(result, createArray(size));
               return result;
    class Individual implements Comparable<Individual> {
         private static long counter = 0;
         private final long id = counter++;
         private String name;
         public Individual(String name) { this.name = name; }
         // ?name? is optional:
         public Individual() {}
         public String toString() {
         return getClass().getSimpleName() +
         (name == null ? "" : " " + name);
         public long id() { return id; }
         public boolean equals(Object o) {
         return o instanceof Individual &&
         id == ((Individual)o).id;
         public int hashCode() {
         int result = 17;
         if(name != null)
         result = 37 * result + name.hashCode();
         result = 37 * result + (int)id;
         return result;
         public int compareTo(Individual arg) {
         // Compare by class name first:
         String first = getClass().getSimpleName();
         String argFirst = arg.getClass().getSimpleName();
         int firstCompare = first.compareTo(argFirst);
         if(firstCompare != 0)
         return firstCompare;
         //second compare by name
         if(name != null && arg.name != null) {
         int secondCompare = name.compareTo(arg.name);
         if(secondCompare != 0)
         return secondCompare;
         }//third compare by id
         return (arg.id < id ? -1 : (arg.id == id ? 0 : 1));
    class Pets {
          public static final PetColl creator =
          //new LiteralPetCreator();
               new PetColl();
          public static Pet randomPet() {
          return creator.createRandom();
          public static Pet[] createArray(int size) {
          return creator.createArray(size);
          public static ArrayList<Pet> arrayList(int size) {
          return creator.arrayList(size);
    class Person extends Individual {
    String name;
    public static class Factory implements Fact<Person>{
    public Person create(String name){
         Person.name=name;
         return new Person(); }
    public Person create(){return new Person();}
    class Pet  extends Individual {
    class Dog extends Pet {
    class Mutt extends Dog {
          public static class Factory implements Fact<Mutt> {
               public  Mutt create(String name){return new Mutt(name);}
               public  Mutt create () {return new Mutt();}
    class Pug extends Dog {
          public static class Factory implements Fact<Pug> {
               public  Pug create(String name){return new Pug(name);}
               public  Pug create () {return new Pug();}
    class Cat extends Pet {
    class EgyptianMau extends Cat {
          public static class Factory implements Fact<EgyptianMau> {
               public  EgyptianMau create(String name){return new EgyptianMau(name);}
               public  EgyptianMau create () {return new EgyptianMau();}
          class Manx extends Cat {
               public static class Factory implements Fact<Manx> {
                    public  Manx create(String name){return new Manx(name);}
                    public  Manx create () {return new Manx();}
         class Cymric extends Manx {
              public static class Factory implements Fact<Cymric> {
                    public  Cymric create(String name){return new Cymric(name);}
                    public  Cymric  create () {return new Cymric();}
    class Rodent extends Pet {
    class Rat extends Rodent {
          public static class Factory implements Fact<Rat> {
               public  Rat create(String name){return new Rat(name);}
               public  Rat create () {return new Rat();}
    class Mouse extends Rodent {
          public static class Factory implements Fact<Mouse> {
               public  Mouse create(String name){return new Mouse(name);}
               public  Mouse create () {return new Mouse();}
    class Hamster extends Rodent {
          public static class Factory implements Fact<Hamster> {
               public  Hamster create(String name){return new Hamster(name);}
               public  Hamster create () {return new Hamster();}
    public class Test {
          public static void main(String[] args) {
              for(Pet p:Pets.creator.arrayList(25)){
          PetCount.petC.count(p.getClass().getSimpleName());
              print(p.getClass().getSimpleName());}
      class PetCount {
          static class PetCounter extends HashMap<String,Integer> {
          public  void count(String type) {
          Integer quantity = get(type);
          if(quantity == null)
          put(type, 1);
          else
          put(type, quantity + 1);
         public static PetCounter petC= new PetCounter();
      }and here's my problem:
    I'm trying to fill up list using factory method but in a fact that I want to have two constructors, I have a problem to set field name of objects of those classes. Is there any possibility to use in that way some factory method to create that list ?
    In Person class I've tried to set it in factory method before creating an object, but as you know that option is only alvailable for static fields which i don't want to be static.

    I for one have no idea what you're asking, and what you seem to be saying doesn't make sense.
    I'm trying to fill up list using factory method but in a fact that I want to have two constructors,Two constructors for what? The factory class? The classes that the factory instantiates?
    I have a problem
    to set field name of objects of those classes. Is there any possibility to use in that way some factory method to
    create that list ?What?
    In Person class I've tried to set it in factory method before creating an object, but as you know that option is only alvailable for static fields which i don't want to be static.That doesn't make any sense. A Factory can easily set fields in the objects it creates on the fly (not static).

  • Button to change bg-color in JTable cell

    Hello!
    I would like to change the background color of a cell with a klick on a button.
    There will be 3 colors, and the selected cell are the only one thats going to change.
    How do I do that?
    Heres my code:
    import javax.swing.*;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Rectangle;
    import javax.swing.JButton;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    import javax.swing.table.TableColumnModel;
    import javax.swing.table.TableModel;
    public class Kinna extends JFrame {
         private static final long serialVersionUID = 1L;
         private JPanel jContentPane = null;
         private JTabbedPane jTabbedPane = null;
         private JScrollPane jScrollPane = null;
         private JTable jTable = null;
         private JButton jButtonRed = null;
         private JButton jButtonGreen = null;
         private JButton jButtonBlue = null;
         private JButton jButtonNewWeek = null;
         private JButton jButtonDelWeek = null;
          * This method initializes jTabbedPane     
          * @return javax.swing.JTabbedPane     
         private JTabbedPane getJTabbedPane() {
              if (jTabbedPane == null) {
                   jTabbedPane = new JTabbedPane();
                   jTabbedPane.setBounds(new Rectangle(105, 45, 545, 488));
                   jTabbedPane.addTab(null, null, getJScrollPane(), null);
              return jTabbedPane;
          * This method initializes jScrollPane     
          * @return javax.swing.JScrollPane     
         private JScrollPane getJScrollPane() {
              if (jScrollPane == null) {
                   jScrollPane = new JScrollPane();
                   jScrollPane.setViewportView(getJTable());
              return jScrollPane;
          * This method initializes jTable     
          * @return javax.swing.JTable     
         private JTable getJTable() {
              if (jTable == null) {
                   Object[] head = {"Namn", "M�ndag", "Tisdag", "Onsdag", "Torsdag", "Fredag"};
                   Object[][] data = {{"Niklas", "9-15", "9-15", "9-15", "9-15","9-15"},
                                            {"Niklas", "9-15", "9-15", "9-15", "9-15","9-15"}};
                   jTable = new JTable(data, head);
                      // This table shades every other column yellow
              return jTable;
          * This method initializes jButtonRed     
          * @return javax.swing.JButton     
         private JButton getJButtonRed() {
              if (jButtonRed == null) {
                   jButtonRed = new JButton("R�d");
                   jButtonRed.setBounds(new Rectangle(15, 30, 76, 31));
                   jButtonRed.setText("R�d");
                   jButtonRed.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
              return jButtonRed;
          * This method initializes jButtonGreen     
          * @return javax.swing.JButton     
         private JButton getJButtonGreen() {
              if (jButtonGreen == null) {
                   jButtonGreen = new JButton("R�d");
                   jButtonGreen.setBounds(new Rectangle(15, 75, 76, 31));
                   jButtonGreen.setText("Gr�n");
              return jButtonGreen;
          * This method initializes jButtonBlue     
          * @return javax.swing.JButton     
         private JButton getJButtonBlue() {
              if (jButtonBlue == null) {
                   jButtonBlue = new JButton("R�d");
                   jButtonBlue.setBounds(new Rectangle(15, 120, 76, 31));
                   jButtonBlue.setText("Bl�");
              return jButtonBlue;
          * This method initializes jButtonNewWeek     
          * @return javax.swing.JButton     
         private JButton getJButtonNewWeek() {
              if (jButtonNewWeek == null) {
                   jButtonNewWeek = new JButton();
                   jButtonNewWeek.setBounds(new Rectangle(270, 0, 91, 31));
                   jButtonNewWeek.setText("Ny Vecka");
                   jButtonNewWeek.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             System.out.println("actionPerformed()");
                             int i = getJTabbedPane().getSelectedIndex() + 1;
                             String tab = "Index: " + i;
                             getJTabbedPane().addTab(tab, new JLabel("Hello"));
                             getJTabbedPane().setSelectedIndex(getJTabbedPane().getTabCount()-1);
              return jButtonNewWeek;
          * This method initializes jButtonDelWeek     
          * @return javax.swing.JButton     
         private JButton getJButtonDelWeek() {
              if (jButtonDelWeek == null) {
                   jButtonDelWeek = new JButton();
                   jButtonDelWeek.setBounds(new Rectangle(375, 0, 121, 31));
                   jButtonDelWeek.setText("Ta bort vecka");
                   jButtonDelWeek.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             System.out.println("actionPerformed()");
                             getJTabbedPane().removeTabAt(getJTabbedPane().getSelectedIndex());
              return jButtonDelWeek;
          * @param args
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        Kinna thisClass = new Kinna();
                        thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        thisClass.setVisible(true);
          * This is the default constructor
         public Kinna() {
              super();
              initialize();
          * This method initializes this
          * @return void
         private void initialize() {
              this.setSize(670, 580);
              this.setContentPane(getJContentPane());
              this.setTitle("JFrame");
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.add(getJTabbedPane(), null);
                   jContentPane.add(getJButtonRed(), null);
                   jContentPane.add(getJButtonGreen(), null);
                   jContentPane.add(getJButtonBlue(), null);
                   jContentPane.add(getJButtonNewWeek(), null);
                   jContentPane.add(getJButtonDelWeek(), null);
              return jContentPane;
    }  //  @jve:decl-index=0:visual-constraint="29,25"

    If you have a different color for every cell in the table, then maybe it would be easier to store a custom Object in the TableModel that has two pieces of information:
    a) the text to be displayed
    b) the background color of the text.
    Then you can write a custom renderer that uses both pieces of information to renderer the cell correctly.
    Here is an untested example of what the custom renderer might look like:
    class ColorRenderer extends DefaultTableCellRenderer
         public Component getTableCellRendererComponent(
                   JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
              super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
              CustomObject custom = (CustomObject)value;
              setText( custom.getText() );
              if (!isSelected)
                   setBackground( custom.getBackground() );
              return this;
    }

  • Coloring an ALV Cell with DYNAMIC INTERNAL TABLES

    Hello Gurus,
    I need your help regarding coloring of a cell in my ALV Grid report with DYNAMIC tables.
    I have used the call method in calling my ALV. (CALL METHOD gr_alvgrid->set_table_for_first_display).
    Now my problem is, I can not bring out the cellcolor succesfully, I always ended up to dump (GETWA_NOT_ASSIGNED = You attempted to access an unassigned field symbol     
    (data segment 32807).                                  
    What I have done:
    I've created 2 internal tables:
    *1st table
    *After appended all of my columns to  gt_fieldcat
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = gt_fieldcat
        IMPORTING
          ep_table        = gp_both.
      ASSIGN gp_both->* TO <i_xtab1>.
    *2nd table
    Appended these column for CellColor
      CLEAR wa_gtfldcat.
      wa_gtfldcat-fieldname = 'CELLCOLOR'.
      wa_gtfldcat-ref_table = 'CALENDAR_TYPE'.
      wa_gtfldcat-ref_field = 'COLTAB'.
      APPEND wa_gtfldcat TO gt_fieldcat.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = gt_fieldcat
        IMPORTING
          ep_table        = gp_alvgrid.
      ASSIGN gp_alvgrid->* TO <i_xtab2>.
    *Work Areas for tab1 and tab2
    CREATE DATA dref1 LIKE LINE OF <i_xtab1>.
      ASSIGN dref1->* TO <wa_xtab1>.
      CREATE DATA dref2 LIKE LINE OF <i_xtab2>.
      ASSIGN dref2->* TO <wa_xtab2>.
    *Move contents of table1 to table2 and modify cellcolor column
    LOOP AT <i_xtab1> ASSIGNING <wa_xtab1>.
    *-----Cell color assignment
        DESCRIBE TABLE gt_fieldcat.
        DO sy-tfill TIMES.
          READ TABLE gt_fieldcat INTO wa_gtfldcat INDEX sy-index.
          ASSIGN COMPONENT wa_gtfldcat-fieldname
            OF STRUCTURE <wa_xtab1> TO <fs4>.
          IF sy-subrc NE 0. EXIT .ENDIF.
          ASSIGN COMPONENT wa_gtfldcat-fieldname
            OF STRUCTURE <wa_xtab2> TO <fs3>.
          IF sy-subrc NE 0. EXIT .ENDIF.
            <fs3> = <fs4>.
        ENDDO.
        ASSIGN COMPONENT 'CELLCOLOR' OF STRUCTURE <wa_xtab2> TO <fs3>.
        IF sy-subrc = 0.
          PERFORM modify_cell_color USING 'ZZMATNR' <fs3>.
        ENDIF.
        APPEND <wa_xtab1> TO <i_xtab2>.
    ENDLOOP.
    *Call ALV
    gs_layout-ctab_fname = 'COLORCELL'
        CALL METHOD gr_alvgrid->set_table_for_first_display
          EXPORTING
            is_layout                     = gs_layout
          CHANGING
            it_outtab                     = <i_xtab2d>[]
            it_fieldcatalog               = gt_fieldcat
            it_sort                       = lt_sort
          EXCEPTIONS
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            OTHERS                        = 4.
        IF sy-subrc <> 0.
    *--->Exception handling
        ENDIF.
    FORM modify_cell_color  USING p_fieldname   TYPE lvc_fname
                                  pt_cellcolor  TYPE table.
      DATA l_cellcolor TYPE lvc_s_scol.
      CLEAR l_cellcolor.
      l_cellcolor-fname = p_fieldname.
      l_cellcolor-color-col = 6.       " Red.
      l_cellcolor-color-int = 0.
      l_cellcolor-color-inv = 0.
      INSERT l_cellcolor INTO TABLE pt_cellcolor.
    ENDFORM.                    " MODIFY_CELL_COLOR

    Hi,
    The internal tabl which you are using to display the output should have one column in the end.
    The cell in this column will contain an internal table of type 'lvc_s_scol'.
    The contents of this internal table will be the field names of all other columns of your main internal table in the field FNAME and the required color in the field COLOR.
    Please note that the field COLOR will have a hex value for different colors.
    In the stucture is_layout  whihc you pass to the method 'set_table_for_first_display'
    the name of this last column should be given to the field 'ctab_fname'.
    This will help you to give the colors to each cell.
    for example
    I have my data table as follows:-
    ITAB1
    MATNR  MAKTX        COLOR_TAB
    1           ABC            FNAME  COLOR  NOKEYCOL
                                    MATNR 8000
                                    MAKTX 8000
    2          XYZ             MATNR 10000
                                  MAKTX  10000
    So my internal table ITAB1 had 3 columns MATNR MAKTX and COLOR_TAB.
    And COLOR_TAB will contain an internal table with 3 columns FNAME COLOR and NOKEYCOL.
    The value to importing parameter IS_LAYOUT-CTAB_FNAME will be COLOR_TAB.
    This will help you to assign various colors to the cell of the internal table ITAB.
    When you have to change any color, then you will have to just change the entries in cell COLOR_TAB for the particular row and cell.
    Regards,
    Ankur Parab

  • ALV GRID DISPLAY USING FACTORY METHODS

    Hi all
    I am using factory methods for my alv grid display.
    I have a list of functionalities, for which i am not able to find a correct method..
    1) Header of alv(with all the values of the selection-screen)
    2)How to give text to a subtotal(ed) column, i.e. if i subtotal a qty field against a sorted field, i want to display ==> Nett Wt. = 123.00 (for first header entry) and so on for each header entry.
    3)how to remove the zeroes from a quantity field?
    4) Displaying the cells as blanks where data is 0( for quantity fields if i have a cell with zero value, it should be blank.)
    5) double click on a cell to open a transaction with the cell's value.
    Any help on this would be appreciated.
    Points will be rewarded for sure...
    Thanks & Regards
    Ravish Garg

    Hello Ravish
    Regarding the display of zero values as empty cells have a look at my <i>modified </i>sample report <b>ZUS_SDN_CL_SALV_TABLE_INTERACT</b>.
    *& Report  ZUS_SDN_CL_SALV_TABLE_INTERACT
    REPORT  zus_sdn_cl_salv_table_interact.
    TYPE-POOLS: abap.
    DATA:
      gt_knb1        TYPE STANDARD TABLE OF knb1.
    DATA:
      go_table       TYPE REF TO cl_salv_table,
      go_events      TYPE REF TO cl_salv_events_table.
    *       CLASS lcl_eventhandler DEFINITION
    CLASS lcl_eventhandler DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS:
          handle_double_click FOR EVENT
              if_salv_events_actions_table~double_click
              OF cl_salv_events_table
              IMPORTING
                row
                column.
    ENDCLASS.                    "lcl_eventhandler DEFINITION
    *       CLASS lcl_eventhandler IMPLEMENTATION
    CLASS lcl_eventhandler IMPLEMENTATION.
      METHOD handle_double_click.
    *   define local data
        DATA:
          lo_table   TYPE REF TO cl_salv_table,
          lt_orders  TYPE STANDARD TABLE OF bapiorders,
          ls_knb1    TYPE knb1.
        READ TABLE gt_knb1 INTO ls_knb1 INDEX row.
        IF ( syst-subrc = 0 ).
          CALL FUNCTION 'BAPI_SALESORDER_GETLIST'
            EXPORTING
              customer_number             = ls_knb1-kunnr
              sales_organization          = '1000'
    *         MATERIAL                    =
    *         DOCUMENT_DATE               =
    *         DOCUMENT_DATE_TO            =
    *         PURCHASE_ORDER              =
    *         TRANSACTION_GROUP           = 0
    *         PURCHASE_ORDER_NUMBER       =
    *       IMPORTING
    *         RETURN                      =
            TABLES
              sales_orders                = lt_orders.
    *     Create ALV grid instance
          TRY.
              CALL METHOD cl_salv_table=>factory
    *        EXPORTING
    *          LIST_DISPLAY   = IF_SALV_C_BOOL_SAP=>FALSE
    *          R_CONTAINER    =
    *          CONTAINER_NAME =
                IMPORTING
                  r_salv_table   = lo_table
                CHANGING
                  t_table        = lt_orders.
            CATCH cx_salv_msg .
          ENDTRY.
          lo_table->display( ).
    **      SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.
    **      SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
    **      CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
        ENDIF.
      ENDMETHOD.                    "handle_double_click
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    START-OF-SELECTION.
      SELECT        * FROM  knb1 INTO TABLE gt_knb1
             WHERE  bukrs  = '1000'.
    * Create ALV grid instance
      TRY.
          CALL METHOD cl_salv_table=>factory
    *    EXPORTING
    *      LIST_DISPLAY   = IF_SALV_C_BOOL_SAP=>FALSE
    *      R_CONTAINER    =
    *      CONTAINER_NAME =
            IMPORTING
              r_salv_table   = go_table
            CHANGING
              t_table        = gt_knb1.
        CATCH cx_salv_msg .
      ENDTRY.
    * Create event instance
      go_events = go_table->get_event( ).
    * Set event handler
      SET HANDLER:
        lcl_eventhandler=>handle_double_click FOR go_events.
      PERFORM modify_columns.
      go_table->display( ).
    END-OF-SELECTION.
    *&      Form  MODIFY_COLUMNS
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM modify_columns .
    * define local data
      DATA:
        lt_dfies        TYPE ddfields,
        ls_dfies        TYPE dfies,
        lo_typedescr    TYPE REF TO cl_abap_typedescr,
        lo_strucdescr   TYPE REF TO cl_abap_structdescr,
        lo_tabledescr   TYPE REF TO cl_abap_tabledescr,
        lo_columns      TYPE REF TO cl_salv_columns_table,
        lo_column       TYPE REF TO cl_salv_column.
      lo_columns = go_table->get_columns( ).
      lo_typedescr = cl_abap_typedescr=>describe_by_data( gt_knb1 ).
      lo_tabledescr ?= lo_typedescr.
      lo_strucdescr ?= lo_tabledescr->get_table_line_type( ).
      lt_dfies = lo_strucdescr->get_ddic_field_list( ).
      LOOP AT lt_dfies INTO ls_dfies.
        lo_column = lo_columns->get_column( ls_dfies-fieldname ).
        IF ( ls_dfies-keyflag = abap_true ).
          CONTINUE.
        ELSEIF ( ls_dfies-fieldname = 'WEBTR' ).  " Bill of ex. limit
          lo_column->set_zero( if_salv_c_bool_sap=>true ).   " display zero
          lo_column->set_zero( if_salv_c_bool_sap=>false ).  " hide zero
        ELSE.
          lo_column->set_technical( if_salv_c_bool_sap=>true ).  " hide col
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " MODIFY_COLUMNS
    Regards
      Uwe

  • Change color in a cell in JTable

    Hi, i need to Change color in a cell when this have the focus in a JTable.
    Thanks

    Override the prepareRenderer(...) method. Something like this:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474

  • Setting cell editor for individual cell in JTable

    Hi there,
    I want to provide individual cell editor for my JTable. Basically, my JTable shows property names and values. I want to show different cell editors for different properties.
    I followed the advice in this post:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=423318
    but I have a question:
    I looked at the code of DefaultCellEditor. It just has a single editor component (the one provided in the constructor), so all the methods use the same component and certain aspects are customized for the type of component. Again, there can be only one type of component at a time.The problem that I am facing is that I will have different components for different row/column of the same table. So how do I implement some of the methods (for example, getCellEditorValue()), when I have multiple editor components?
    Also, how do I commit changes made by the user?
    I am extremely confused.
    Someone please help!
    Thanks.

    Actually, that's what I am currently doing.
    Here is my cell editor class:
    public class ObjectPropertyEditor extends DefaultCellEditor
           public ObjectPropertyEditor()
              super(new JTextField());
              Vector list = new Vector();
              list.add("Yes");
              list.add("No");
             myCombo = new JComboBox(list);
          public Component getTableCellEditorComponent(JTable table, Object value,
              boolean isSelected, int row, int column)
             String colName = (String)table.getValueAt(row,0);
             if(colName.equalsIgnoreCase("Leaf-Node?")) //if it is the "Leaf" property, return the combo box as the editor
                 return myCombo;
            else  //for all other properties, use JTextField of the super class
                return super.getTableCellEditorComponent(table,value,isSelected,row,column);
        private JComboBox myCombo;
    }The problem I have is that when I select a new item from the combo box, the new selection is not reflected in the tableModel. I don't know how I can achive that. I think I need the functionalities that DefaultCellEditor gives to its delegate when its constructor arguments is a combo box. But how can I get two different sets of functionalities (JTextField and JComboBox) ?
    Please help!
    Thanks.

  • Two colors in a cell ALV

    Hi All,
    I want to produce a report in ALV , where I have to print two diff colors in a cell..
    Eg:       In a cell  128(38)  
    128(    ) in black and 38 in red.
    Thanks in advance.
    Balamurugan.R

    hi,
    see the below example which may be useful.
    types:  begin of ty_vbak,
            Vbeln type vbeln_va,
            erdat type erdat,
            ernam type ernam,
    cellcolors type lvc_t_scol,  " table type for cell coloring
    cellstyles TYPE lvc_t_styl,  " table type for Style Table for Cells
            end of ty_vbak.
    data:  t_vbak type table of ty_vbak,
           w_vbak type ty_vbak.
    data: gt_fieldcat type lvc_t_fcat,
          gs_fieldcat like line of gt_fieldcat,
          gw_layout type lvc_s_layo.
    Reference to Custom container
    DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
           G_CONTAINER TYPE SCRFNAME VALUE  'CC_ALV',
        G_GRID TYPE REF TO CL_GUI_ALV_GRID,
    *&      Module  STATUS_0001  OUTPUT
          text
    MODULE STATUS_0001 OUTPUT.
    SET PF-STATUS 'xxxxxxxx'.
    SET TITLEBAR 'xxx'.
    CREATE OBJECT G_CUSTOM_CONTAINER
       EXPORTING
        PARENT                      =
         CONTAINER_NAME              = G_CONTAINER
        STYLE                       =
        LIFETIME                    = LIFETIME_DEFAULT
        REPID                       =
        DYNNR                       =
        NO_AUTODEF_PROGID_DYNNR     =
      EXCEPTIONS
        CNTL_ERROR                  = 1
        CNTL_SYSTEM_ERROR           = 2
        CREATE_ERROR                = 3
        LIFETIME_ERROR              = 4
        LIFETIME_DYNPRO_DYNPRO_LINK = 5
        OTHERS                      = 6
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
      CREATE OBJECT G_GRID
        EXPORTING
         I_SHELLSTYLE      = 0
         I_LIFETIME        =
          I_PARENT          =  G_CUSTOM_CONTAINER
         I_APPL_EVENTS     = SPACE
         I_PARENTDBG       =
         I_APPLOGPARENT    =
         I_GRAPHICSPARENT  =
         I_NAME            =
         I_FCAT_COMPLETE   = SPACE
       EXCEPTIONS
         ERROR_CNTL_CREATE = 1
         ERROR_CNTL_INIT   = 2
         ERROR_CNTL_LINK   = 3
         ERROR_DP_CREATE   = 4
         OTHERS            = 5
      IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    perform populate_data.
    perform fieldcat.
    perform populate_layout.
    perform display_output.
    ENDMODULE.                 " STATUS_0001  OUTPUT
    *&      Form  populate_data
          populating the data
    -->  p1        text
    <--  p2        text
    FORM populate_data .
      data: color(1) type c.
    DATA lw_cellcolor TYPE lvc_s_scol . "line type for cell coloring
    select  vbeln
            erdat
            ernam from vbak into CORRESPONDING FIELDS OF TABLE t_vbak up to 10 rows.
    *coloring the particular cell.
    READ TABLE t_vbak INTO w_vbak  INDEX 5 .
    lw_cellcolor-fname = 'ERDAT' .
    lw_cellcolor-color-col = '4' .
    lw_cellcolor-color-int = '1' .
    APPEND lw_cellcolor TO w_vbak-cellcolors .
    modify t_vbak index 5 from w_vbak.
    READ TABLE t_vbak INTO w_vbak  INDEX 7.
    lw_cellcolor-fname = 'ERNAM' .
    lw_cellcolor-color-col = '7' .
    lw_cellcolor-color-int = '1' .
    APPEND lw_cellcolor TO w_vbak-cellcolors .
    modify t_vbak index 7 from w_vbak.
    ENDFORM.                    " populate_data
    *&      Form  fieldcat
          populatin the fieldcat
    -->  p1        text
    <--  p2        text
    FORM fieldcat .
      clear gs_fieldcat.
      gs_fieldcat-fieldname = 'VBELN'.
      gs_fieldcat-tabname = 'T_VBAk'.
      gs_fieldcat-outputlen = '20'.
      gs_fieldcat-SCRTEXT_M = 'DOCUMENT NUMBER'.
      append gs_fieldcat to GT_fieldcat.
      clear gs_fieldcat.
      gs_fieldcat-fieldname = 'ERDAT'.
      gs_fieldcat-tabname = 'T_VBAK'.
      gs_fieldcat-outputlen = '20'.
      gs_fieldcat-SCRTEXT_M = 'CREATED ON'.
      append gs_fieldcat to GT_fieldcat.
      clear gs_fieldcat.
      gs_fieldcat-fieldname = 'ERNAM'.
      gs_fieldcat-tabname = 'T_VBAK'.
      gs_fieldcat-outputlen = '20'.
      gs_fieldcat-SCRTEXT_M = 'CREATED BY'.
      append gs_fieldcat to GT_fieldcat.
    ENDFORM.                    " fieldcat
    *&      Form  display_output
          text
    -->  p1        text
    <--  p2        text
    FORM display_output .
      CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
         I_BUFFER_ACTIVE               =
         I_BYPASSING_BUFFER            =
         I_CONSISTENCY_CHECK           =
         I_STRUCTURE_NAME              =
         IS_VARIANT                    =
         I_SAVE                        =
         I_DEFAULT                     = 'X'
        IS_LAYOUT                      = gw_layout
         IS_PRINT                      =
         IT_SPECIAL_GROUPS             =
       IT_TOOLBAR_EXCLUDING           = *      IT_HYPERLINK                  =
         IT_ALV_GRAPHICS               =
         IT_EXCEPT_QINFO               =
         IR_SALV_ADAPTER               =
        CHANGING
          IT_OUTTAB                      = t_vbak
          IT_FIELDCATALOG                = GT_fieldcat
         IT_SORT                       =
         IT_FILTER                     =
       EXCEPTIONS
         INVALID_PARAMETER_COMBINATION = 1
         PROGRAM_ERROR                 = 2
         TOO_MANY_LINES                = 3
         OTHERS                        = 4
      IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    *&      Form  populate_layout
          populating the layout
         <--P_GW_LAYOUT   internal table for the layput
    FORM populate_layout."  CHANGING P_GW_LAYOUT type lvc_s_layo.
    gw_layout-zebra = 'X'.
    gw_layout-ctab_fname = 'CELLCOLORS'. "cell coloring
    *gw_layout-info_fname = 'ROW_COLOR'.    "row coloring
    gw_layout-stylefname = 'CELLSTYLES'.   "styles
    ENDFORM.                    " populate_layout
    thanks and regards

Maybe you are looking for

  • T400 - Fn Key wakes computer from sleep.

    So, is it normal that by pressing Fn Key + any other key (on the keyboard) - computer wakes up from sleep?? Or is something wrong with the OS? Solved! Go to Solution.

  • Exporting jump lines to pdf

    I've been exploring InDesign after upgrading from PageMaker (used since 1992). The jump lines feature is really cool, but when I tested exporting to pdf, the jumplines aren't live. In PM I would just use hyperlinks. Is there a way to make jump lines

  • Displaying currentState without the _ character

    I have a state called Data_Drilldown and if I use {currentState} in a text label it will return the state exactly as it is but I want to eliminate the underscore character. How do I display the current state of an application so it appears w/o the un

  • ECC Data into CRM

    I would like some recommendations with regards to the following requirement: The requirement is to use quite a bit or Real Estate data in the CRM system. The ECC system is separate from the CRM system. One could use an RFC to constantly get the data

  • Where can I download Change Management Pack?

    Hi, I didn't find Chang Management Pack in downloaded oracle 817NT and linux. Who can tell me where I can find the CMP of OEM? Thanks! Please email me: [email protected] Betty