0% found this document useful (0 votes)
39 views10 pages

Example: ALV Row Coloring: "Normal Work Area "Field Symbol Work Area

The document describes how to color rows and cells in an ALV grid based on different criteria. It shows how to create an ALV grid, generate the field catalog, and perform row and cell coloring based on date and amount fields. Forms are used to retrieve and display sales order data, generate the field catalog, and perform the row and cell coloring.

Uploaded by

Gaurav Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views10 pages

Example: ALV Row Coloring: "Normal Work Area "Field Symbol Work Area

The document describes how to color rows and cells in an ALV grid based on different criteria. It shows how to create an ALV grid, generate the field catalog, and perform row and cell coloring based on date and amount fields. Forms are used to retrieve and display sales order data, generate the field catalog, and perform the row and cell coloring.

Uploaded by

Gaurav Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 10

Example: ALV Row coloring

REPORT Z730ALV6.

data v_vbeln type vbak-vbeln.
select-OPTIONS so_vbeln for v_vbeln DEFAULT '4980' to '5020'.

data : o_cust_cont type ref to cl_gui_custom_container,
       o_grid type ref to cl_gui_alv_grid.

types : begin of ty_temp_sales.
           include type zcvbak.
types : netwr type vbak-netwr,
        end of ty_temp_sales.

data : t_temp_sales type table of ty_temp_sales,
      wa_temp_sales type ty_temp_sales.

types : begin of ty_final_sales.
           include type zcvbak.
types : netwr type vbak-netwr,
        rowcolor(4) type c,
        end of ty_final_sales.

data : t_final_sales type table of ty_final_sales,
      wa_final_sales type ty_final_sales.

field-symbols <wa_final> like line of t_final_sales.

data wa_layo type lvc_s_layo.

data : t_fcat type lvc_t_fcat,
      wa_fcat type lvc_s_fcat. "normal work area

FIELD-SYMBOLS <abc> like line of t_fcat. "field  symbol work area

START-OF-SELECTION.
  call screen 100.

MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'ABC'.

*  link custom container  with custom control
CREATE OBJECT O_CUST_CONT
  EXPORTING
    CONTAINER_NAME              = 'CUSTCTRL'.

*  link alv grid  with custom container
CREATE OBJECT O_GRID
  EXPORTING
    I_PARENT          = o_cust_cont.

*  get sales  orders
  perform getsalesorders.
  if t_final_sales is not INITIAL.
*  generate  fieldcatalog
    perform fldcat.
*  row coloring
    perform rowcoloring.
*  layout
    perform layout.
*  display  sales orders
     perform displaysalesorders.
  endif.
ENDMODULE.                 " STATUS_0100   OUTPUT

FORM GETSALESORDERS .
  select vbeln erdat erzet ernam netwr
         from vbak
        into table t_temp_sales
            where vbeln in so_vbeln.
  if sy-subrc eq 0.
*      append  lines  of  t_temp_sales to  t_final_sales.
    loop at t_temp_sales into wa_temp_sales.
      clear wa_final_sales.
      wa_final_sales-vbeln = wa_temp_sales-vbeln.
      wa_final_sales-erdat = wa_temp_sales-erdat.
      wa_final_sales-erzet = wa_temp_sales-erzet.
      wa_final_sales-ernam = wa_temp_sales-ernam.
      wa_final_sales-netwr = wa_temp_sales-netwr.
      append wa_final_sales to t_final_sales.
    endloop.
  endif.
ENDFORM.                    "  GETSALESORDERS

FORM DISPLAYSALESORDERS .
 CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
   EXPORTING
     IS_LAYOUT                     = wa_layo
   CHANGING
     IT_OUTTAB                     = t_final_sales
     IT_FIELDCATALOG               = t_fcat.

ENDFORM.                    "  DISPLAYSALESORDERS

MODULE USER_COMMAND_0100 INPUT.
  case sy-ucomm.
      when 'FC1'.
          leave PROGRAM.
  endcase.
ENDMODULE.                 " USER_COMMAND_0100   INPUT

FORM FLDCAT .
  clear wa_fcat.
  wa_fcat-fieldname = 'VBELN'.
  wa_fcat-col_pos = 1.
  wa_fcat-coltext = 'Sales Document'.
  wa_fcat-outputlen = 15.
  wa_fcat-tooltip = 'Sales Document Number'.
  append wa_fcat to t_fcat.
  clear wa_fcat.
  wa_fcat-fieldname = 'ERDAT'.
  wa_fcat-col_pos = 2.
  wa_fcat-coltext = 'Creation Date'.
  wa_fcat-outputlen = 15.
  append wa_fcat to t_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'ERZET'.
  wa_fcat-col_pos = 3.
  wa_fcat-coltext = 'Creation Time'.
  wa_fcat-outputlen = 15.
  append wa_fcat to t_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'ERNAM'.
  wa_fcat-col_pos = 4.
  wa_fcat-coltext = 'Name of Person'.
  wa_fcat-outputlen = 30.
  append wa_fcat to t_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'NETWR'.
  wa_fcat-col_pos = 5.
  wa_fcat-coltext = 'Net Value'.
  wa_fcat-outputlen = 15.
  append wa_fcat to t_fcat.
ENDFORM.                    "  FLDCAT

FORM ROWCOLORING .
  loop at t_final_sales ASSIGNING <wa_final>.
    if <wa_final>-erdat = '19970121'.
        <wa_final>-rowcolor = 'C510'.
    elseif <wa_final>-erdat = '19970122'.
        <wa_final>-rowcolor = 'C310'.
    elseif <wa_final>-erdat = '19970123'.
        <wa_final>-rowcolor = 'C710'.
    else.
        <wa_final>-rowcolor = 'C210'.
    endif.
  endloop.
ENDFORM.                    "  ROWCOLORING

FORM LAYOUT .
  clear wa_layo.
  wa_layo-info_fname = 'ROWCOLOR'. "row coloring
ENDFORM.                    "  LAYOUT

Example: ALV Cell coloring


REPORT Z730ALV7.

data v_vbeln type vbak-vbeln.
select-OPTIONS so_vbeln for v_vbeln DEFAULT '4980' to '5020'.

data : o_cust_cont type ref to cl_gui_custom_container,
       o_grid type ref to cl_gui_alv_grid.

types : begin of ty_temp_sales.
           include type zcvbak.
types : netwr type vbak-netwr,
        end of ty_temp_sales.

data : t_temp_sales type table of ty_temp_sales,
      wa_temp_sales type ty_temp_sales.

types : begin of ty_final_sales.
           include type zcvbak.
types : netwr type vbak-netwr,
        cellcolor type lvc_t_scol,
        end of ty_final_sales.

data : t_final_sales type table of ty_final_sales,
      wa_final_sales type ty_final_sales.
field-symbols <wa_final> like line of t_final_sales.

data wa_cellcolor type LVC_S_SCOL.

data wa_layo type lvc_s_layo.

data : t_fcat type lvc_t_fcat,
      wa_fcat type lvc_s_fcat. "normal work area

FIELD-SYMBOLS <abc> like line of t_fcat. "field  symbol work area

START-OF-SELECTION.
  call screen 100.

MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'ABC'.

*  link custom container  with custom control
CREATE OBJECT O_CUST_CONT
  EXPORTING
    CONTAINER_NAME              = 'CUSTCTRL'.

*  link alv grid  with custom container
CREATE OBJECT O_GRID
  EXPORTING
    I_PARENT          = o_cust_cont.

*  get sales  orders
  perform getsalesorders.
  if t_final_sales is not INITIAL.
*  generate  fieldcatalog
    perform fldcat.
*  cell  coloring
    perform cellcoloring.
*  layout
    perform layout.
*  display  sales orders
     perform displaysalesorders.
  endif.
ENDMODULE.                 " STATUS_0100   OUTPUT

FORM GETSALESORDERS .
  select vbeln erdat erzet ernam netwr
         from vbak
        into table t_temp_sales
            where vbeln in so_vbeln.
  if sy-subrc eq 0.
*      append  lines  of  t_temp_sales to  t_final_sales.
    loop at t_temp_sales into wa_temp_sales.
      clear wa_final_sales.
      wa_final_sales-vbeln = wa_temp_sales-vbeln.
      wa_final_sales-erdat = wa_temp_sales-erdat.
      wa_final_sales-erzet = wa_temp_sales-erzet.
      wa_final_sales-ernam = wa_temp_sales-ernam.
      wa_final_sales-netwr = wa_temp_sales-netwr.
      append wa_final_sales to t_final_sales.
    endloop.
  endif.
ENDFORM.                    "  GETSALESORDERS

FORM DISPLAYSALESORDERS .
 CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY
   EXPORTING
     IS_LAYOUT                     = wa_layo
   CHANGING
     IT_OUTTAB                     = t_final_sales
     IT_FIELDCATALOG               = t_fcat.

ENDFORM.                    "  DISPLAYSALESORDERS

MODULE USER_COMMAND_0100 INPUT.
  case sy-ucomm.
      when 'FC1'.
          leave PROGRAM.
  endcase.
ENDMODULE.                 " USER_COMMAND_0100   INPUT

FORM FLDCAT .
  clear wa_fcat.
  wa_fcat-fieldname = 'VBELN'.
  wa_fcat-col_pos = 1.
  wa_fcat-coltext = 'Sales Document'.
  wa_fcat-outputlen = 15.
  wa_fcat-tooltip = 'Sales Document Number'.
  append wa_fcat to t_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'ERDAT'.
  wa_fcat-col_pos = 2.
  wa_fcat-coltext = 'Creation Date'.
  wa_fcat-outputlen = 15.
  append wa_fcat to t_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'ERZET'.
  wa_fcat-col_pos = 3.
  wa_fcat-coltext = 'Creation Time'.
  wa_fcat-outputlen = 15.
  append wa_fcat to t_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'ERNAM'.
  wa_fcat-col_pos = 4.
  wa_fcat-coltext = 'Name of Person'.
  wa_fcat-outputlen = 30.
  append wa_fcat to t_fcat.

  clear wa_fcat.
  wa_fcat-fieldname = 'NETWR'.
  wa_fcat-col_pos = 5.
  wa_fcat-coltext = 'Net Value'.
  wa_fcat-outputlen = 15.
  append wa_fcat to t_fcat.
ENDFORM.                    "  FLDCAT

FORM LAYOUT .
  clear wa_layo.
  wa_layo-ctab_fname = 'CELLCOLOR'. "cell  coloring
ENDFORM.                    "  LAYOUT

FORM CELLCOLORING .
  loop at t_final_sales assigning <wa_final>.
       if <wa_final>-netwr < 10000.
         clear wa_cellcolor.
         wa_cellcolor-fname = 'VBELN'.
         wa_cellcolor-color-col = 3.
         wa_cellcolor-color-int = 1.
         wa_cellcolor-color-inv = 0.
         append wa_cellcolor to <wa_final>-cellcolor.
       elseif <wa_final>-netwr >= 10000 and
              <wa_final>-netwr < 20000.
         clear wa_cellcolor.
         wa_cellcolor-fname = 'VBELN'.
         wa_cellcolor-color-col = 7.
         wa_cellcolor-color-int = 1.
         wa_cellcolor-color-inv = 0.
         append wa_cellcolor to <wa_final>-cellcolor.
       elseif <wa_final>-netwr > 20000 and
              <wa_final>-netwr <= 40000.
         clear wa_cellcolor.
         wa_cellcolor-fname = 'VBELN'.
         wa_cellcolor-color-col = 2.
         wa_cellcolor-color-int = 1.
         wa_cellcolor-color-inv = 0.
         append wa_cellcolor to <wa_final>-cellcolor.
       elseif <wa_final>-netwr > 40000.
         clear wa_cellcolor.
         wa_cellcolor-fname = 'VBELN'.
         wa_cellcolor-color-col = 6.
         wa_cellcolor-color-int = 1.
         wa_cellcolor-color-inv = 0.
         append wa_cellcolor to <wa_final>-cellcolor.
      endif.
  endloop.
ENDFORM.                    "  CELLCOLORING

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy