<?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: Creating an ALV report using factory method in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113739#M983539</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;PRE&gt;&lt;CODE&gt;REPORT ZWA_ALV_COLORS .
 
tables : BKPF.
 
types : begin of ty_BKPF,
  belnr like BKPF-belnr,
  bukrs like BKPF-bukrs,
  counter(4) type n,
  color_line(4) type c, " Line color
  color_cell type lvc_t_scol, " Cell color
end of ty_BKPF.
 
* Structures
data : wa_BKPF type ty_BKPF,
wa_fieldcat type lvc_s_fcat,
is_layout type lvc_s_layo,
wa_color type lvc_s_scol.
 
* Internal table
data : it_BKPF type standard table of ty_BKPF,
       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 DEFAULT 'X',
             p_line as checkbox DEFAULT 'X',
             p_cell as checkbox DEFAULT 'X'.
 
 
at selection-screen output.
 
  perform get_data.
  perform fill_catalog.
 
  if w_docking_container is initial.
    perform create_objects.
  endif.
 
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Form create_objects
*&amp;amp;--------------------------------------------------------------*
form create_objects.
 
  create object w_docking_container
  exporting
  ratio = 40
  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.
 
* 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.
 
  call method w_alv_grid-&amp;gt;set_table_for_first_display
  exporting
  is_layout = is_layout
  changing
  it_outtab = it_BKPF
  it_fieldcatalog = it_fieldcat
  exceptions
  invalid_parameter_combination = 1
  program_error = 2
  too_many_lines = 3
  others = 4.
 
endform.
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Form get_data
*&amp;amp;--------------------------------------------------------------*
form get_data.
 "Check this code for colour
  select * from BKPF up to 50 rows.
    clear : wa_BKPF-color_line, wa_BKPF-color_cell.
 
    move-corresponding BKPF to wa_BKPF.
    add 1 to wa_BKPF-counter.
 
    if wa_BKPF-COUNTER = '2' AND p_line = 'X'.
* Color line
      move 'C610' to wa_BKPF-color_line.
    elseif wa_BKPF-counter = '0004'
    and p_cell = 'X'.
* Color cell
      move 'BELNR' to wa_color-fname.
      move '1' 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_BKPF-color_cell[] = it_color[].
    endif.
 
    append wa_BKPF to it_BKPF.
  endselect.
 
endform.
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Form fill_catalog
*&amp;amp;--------------------------------------------------------------*
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'.
 "In field catalog filling coulour
  clear wa_fieldcat.
  move w_position to wa_fieldcat-col_pos.
  move 'BELNR' to wa_fieldcat-fieldname.
  move 'BKPF' to wa_fieldcat-ref_table.
  move 'BELNR' 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 'BUKRS' to wa_fieldcat-fieldname.
  move 'BKPF' to wa_fieldcat-ref_table.
  move 'BUKRS' to wa_fieldcat-ref_field.
* Color column
  if p_column = 'X'.
    move 'C510' 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.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Vikranth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Jun 2008 19:56:47 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-06-25T19:56:47Z</dc:date>
    <item>
      <title>Creating an ALV report using factory method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113734#M983534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi &lt;/P&gt;&lt;P&gt;i am creating an alv report using factory method, i want to color every line (row ) in the report which contains "E" in the coloumn 'TYPE' in &lt;STRONG&gt;RED&lt;/STRONG&gt;  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how do i do that ? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i am trying to do it for the last 2 days without any help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanx Ami.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2008 13:36:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113734#M983534</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-25T13:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an ALV report using factory method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113735#M983535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;apply the given tips in bold....yesterday I have given this...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2008 13:41:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113735#M983535</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-25T13:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an ALV report using factory method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113736#M983536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm not sure what the factory method is, but if you're using a function module you need to set a fieldcat that points the column to the col_pos eg:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  w_fieldcat-col_pos = 1.&lt;/P&gt;&lt;P&gt;  w_fieldcat-fieldname = 'COL'.&lt;/P&gt;&lt;P&gt;  append w_fieldcat to t_fieldcat.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I won't give you any more pointers incase this has nothing to do with the alv function module.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ash Thomas&lt;/P&gt;&lt;P&gt;Sap Consultants&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.sap.com/www.ashpeople.com" target="test_blank"&gt;www.ashpeople.com&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2008 14:04:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113736#M983536</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-25T14:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an ALV report using factory method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113737#M983537</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;Declare the final internal table which you want to display with clrtab TYPE slis_t_specialcol_alv.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Manipulate the final internal table and when the column TYPE is filled with 'E' then modify the above structure with &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REFRESH gk_final_new-clrtab.&lt;/P&gt;&lt;P&gt;       gk_color-color-col = 6.&lt;/P&gt;&lt;P&gt;       gk_color-color-int = 1.&lt;/P&gt;&lt;P&gt;       gk_color-color-inv = 0.&lt;/P&gt;&lt;P&gt;       gk_color-nokeycol = gc_x. "Also paint key columns&lt;/P&gt;&lt;P&gt;       APPEND gk_color TO gk_final_new-clrtab.&lt;/P&gt;&lt;P&gt;       CLEAR gk_color.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;&lt;STRONG&gt;&amp;lt;REMOVED BY MODERATOR&amp;gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanx&lt;/P&gt;&lt;P&gt;Sumanth&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Alvaro Tejada Galindo on Jun 25, 2008 3:48 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2008 14:10:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113737#M983537</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-25T14:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an ALV report using factory method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113738#M983538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;try this code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT  ZAMIT_TEST2.

TYPE-POOLS: icon, col.
* type for internal table
TYPES: BEGIN OF t_marc.
        INCLUDE STRUCTURE marc.
* internal table for cell color information
TYPES : it_colors TYPE lvc_t_scol,
END OF t_marc.

DATA: it_marc TYPE TABLE OF t_marc.
DATA: wa_marc LIKE LINE OF it_marc.
DATA: wa_colors LIKE LINE OF wa_marc-it_colors.

DATA: gr_alv TYPE REF TO cl_salv_table.
DATA: lr_columns TYPE REF TO cl_salv_columns_table.

SELECT-OPTIONS: so_mat FOR wa_marc-matnr MEMORY ID car.

START-OF-SELECTION.
* retrieve data into internal table
  SELECT * FROM marc
    INTO CORRESPONDING FIELDS OF TABLE it_marc
  WHERE matnr IN so_mat.

  LOOP AT it_marc INTO wa_marc.

    IF wa_marc-werks = '1060'.
      CLEAR wa_colors.
      wa_colors-fname = ''.
      wa_colors-color-col = col_positive.
      wa_colors-color-int = 1.
      APPEND wa_colors TO wa_marc-it_colors.
    ENDIF.
    MODIFY it_marc FROM wa_marc TRANSPORTING it_colors.
  ENDLOOP.

  CALL METHOD cl_salv_table=&amp;gt;factory
  EXPORTING
  list_display = if_salv_c_bool_sap=&amp;gt;false
  IMPORTING
  r_salv_table = gr_alv
  CHANGING
  t_table = it_marc.

  lr_columns = gr_alv-&amp;gt;get_columns( ).

  lr_columns-&amp;gt;set_color_column( value = 'IT_COLORS' ).

* display ALV
gr_alv-&amp;gt;display( ).

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this will work....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN __default_attr="red" __jive_macro_name="color"&gt;&lt;STRONG&gt;&amp;lt;REMOVED BY MODERATOR&amp;gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Amitava De on Jun 25, 2008 9:04 PM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Alvaro Tejada Galindo on Jun 25, 2008 3:48 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2008 15:33:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113738#M983538</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-25T15:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Creating an ALV report using factory method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113739#M983539</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;PRE&gt;&lt;CODE&gt;REPORT ZWA_ALV_COLORS .
 
tables : BKPF.
 
types : begin of ty_BKPF,
  belnr like BKPF-belnr,
  bukrs like BKPF-bukrs,
  counter(4) type n,
  color_line(4) type c, " Line color
  color_cell type lvc_t_scol, " Cell color
end of ty_BKPF.
 
* Structures
data : wa_BKPF type ty_BKPF,
wa_fieldcat type lvc_s_fcat,
is_layout type lvc_s_layo,
wa_color type lvc_s_scol.
 
* Internal table
data : it_BKPF type standard table of ty_BKPF,
       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 DEFAULT 'X',
             p_line as checkbox DEFAULT 'X',
             p_cell as checkbox DEFAULT 'X'.
 
 
at selection-screen output.
 
  perform get_data.
  perform fill_catalog.
 
  if w_docking_container is initial.
    perform create_objects.
  endif.
 
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Form create_objects
*&amp;amp;--------------------------------------------------------------*
form create_objects.
 
  create object w_docking_container
  exporting
  ratio = 40
  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.
 
* 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.
 
  call method w_alv_grid-&amp;gt;set_table_for_first_display
  exporting
  is_layout = is_layout
  changing
  it_outtab = it_BKPF
  it_fieldcatalog = it_fieldcat
  exceptions
  invalid_parameter_combination = 1
  program_error = 2
  too_many_lines = 3
  others = 4.
 
endform.
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Form get_data
*&amp;amp;--------------------------------------------------------------*
form get_data.
 "Check this code for colour
  select * from BKPF up to 50 rows.
    clear : wa_BKPF-color_line, wa_BKPF-color_cell.
 
    move-corresponding BKPF to wa_BKPF.
    add 1 to wa_BKPF-counter.
 
    if wa_BKPF-COUNTER = '2' AND p_line = 'X'.
* Color line
      move 'C610' to wa_BKPF-color_line.
    elseif wa_BKPF-counter = '0004'
    and p_cell = 'X'.
* Color cell
      move 'BELNR' to wa_color-fname.
      move '1' 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_BKPF-color_cell[] = it_color[].
    endif.
 
    append wa_BKPF to it_BKPF.
  endselect.
 
endform.
*&amp;amp;--------------------------------------------------------------*
*&amp;amp; Form fill_catalog
*&amp;amp;--------------------------------------------------------------*
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'.
 "In field catalog filling coulour
  clear wa_fieldcat.
  move w_position to wa_fieldcat-col_pos.
  move 'BELNR' to wa_fieldcat-fieldname.
  move 'BKPF' to wa_fieldcat-ref_table.
  move 'BELNR' 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 'BUKRS' to wa_fieldcat-fieldname.
  move 'BKPF' to wa_fieldcat-ref_table.
  move 'BUKRS' to wa_fieldcat-ref_field.
* Color column
  if p_column = 'X'.
    move 'C510' 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.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Vikranth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Jun 2008 19:56:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/creating-an-alv-report-using-factory-method/m-p/4113739#M983539</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-25T19:56:47Z</dc:date>
    </item>
  </channel>
</rss>

