Skip to end of metadata
Go to start of metadata

Author: J.Jayanthi
Submitted: 05-07-2007

Related Links:

          ABAP-7 Steps to create OOPS ALV(for beginners)

          https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907

          https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b6cae890-0201-0010-ef8b-f970a9c41d47

Description:

This document describes how to color the row and column in ALV using OOPS method. Before starting to read this code, the user should be aware of the basic OOPS ALV[Refer first link given].

Procedure

Coloring a Row

Step 1:  Include a field called rowcolor in output internal table.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
TYPES : BEGIN OF ty.
        INCLUDE STRUCTURE mara.
TYPES : rowcolor(4) TYPE c,
        END OF ty.
DATA : itab TYPE STANDARD TABLE OF ty,"Output Internal table
       wa TYPE ty.

Step 2: Setting the layout accordingly

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA w_layout  TYPE lvc_s_layo."Layout structure
* Setting layout
w_layout-info_fname = 'ROWCOLOR'."For row coloring

Step 3: Coloring the specific row

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
* Colouring a row
CLEAR wa.
READ TABLE itab INTO wa INDEX 3.
IF sy-subrc EQ 0.
  wa-rowcolor = 'C311'.
  MODIFY itab FROM wa TRANSPORTING rowcolor WHERE matnr = wa-matnr.
ENDIF.

Step4: Pass the layout also in the method set_table_for_first_display

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
* Displaying the output
CALL METHOD o_grid->set_table_for_first_display
  EXPORTING
    is_variant                    = w_variant
    i_save                        = 'A'
    is_layout                     = w_layout
  CHANGING
    it_outtab                     = itab
    it_fieldcatalog               = i_fieldcat
  EXCEPTIONS
    invalid_parameter_combination = 1
    program_error                 = 2
    too_many_lines                = 3
    OTHERS                        = 4.


Complete Code for Coloring a Row

Screen 9000,GUI Status ZSTATUS and GUI Title ZTITLE should be created and in Flow logic of the screen, PBO and PAI should be uncommented.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
TYPES : BEGIN OF ty.
  INCLUDE STRUCTURE mara.
TYPES : rowcolor(4) TYPE c,
        END OF ty.
DATA : itab TYPE STANDARD TABLE OF ty,"Output Internal table
       i_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,"Field catalog
       wa TYPE ty,
       w_variant TYPE disvariant,
       w_layout  TYPE lvc_s_layo,"Layout structure
       o_docking TYPE REF TO cl_gui_docking_container,"Docking Container
       o_grid TYPE REF TO cl_gui_alv_grid."Grid

SELECT * FROM mara INTO CORRESPONDING FIELDS OF TABLE itab UP TO 10 ROWS.
CALL SCREEN 9000.

*&---------------------------------------------------------------------
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------
MODULE status_9000 OUTPUT.
  IF o_docking IS INITIAL.
    SET PF-STATUS 'ZSTATUS'. "GUI Status
    SET TITLEBAR 'ZTITLE'.   "TitleCreating Docking Container
    CREATE OBJECT o_docking
      EXPORTING
        ratio = '95'.
    IF sy-subrc EQ 0.
*Creating Grid
      CREATE OBJECT o_grid
        EXPORTING
          i_parent = o_docking.
    ENDIF.
*Filling the fieldcatalog table
    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
        i_structure_name       = 'MARA'
      CHANGING
        ct_fieldcat            = i_fieldcat
      EXCEPTIONS
        inconsistent_interface = 1
        program_error          = 2
        OTHERS                 = 3.
    w_variant-report = sy-repid.
*Setting layout
    w_layout-info_fname = 'ROWCOLOR'."For row coloring
*Colouring a row
    CLEAR wa.
    READ TABLE itab INTO wa INDEX 3.
    IF sy-subrc EQ 0.
      wa-rowcolor = 'C311'.
      MODIFY itab FROM wa TRANSPORTING rowcolor WHERE matnr = wa-matnr.
    ENDIF.
*Displaying the output
    CALL METHOD o_grid->set_table_for_first_display
      EXPORTING
        is_variant                    = w_variant
        i_save                        = 'A'
        is_layout                     = w_layout
      CHANGING
        it_outtab                     = itab
        it_fieldcatalog               = i_fieldcat
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.

  ENDIF.
ENDMODULE.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------
*       PAI
*----------------------------------------------------------------------
MODULE user_command_9000 INPUT.
  DATA lv_ucomm TYPE sy-ucomm.
  lv_ucomm = sy-ucomm.
  CASE lv_ucomm.
    WHEN 'CANCEl' OR 'EXIT'.
      PERFORM free_objects.
      LEAVE PROGRAM.
    WHEN 'BACK'.
      PERFORM free_objects.
      SET SCREEN '0'.
      LEAVE SCREEN.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------
*&      Form  free_objects
*&---------------------------------------------------------------------
*       Free Objects
*----------------------------------------------------------------------
FORM free_objects .
  CALL METHOD o_grid->free
    EXCEPTIONS
      cntl_error        = 1
      cntl_system_error = 2
      OTHERS            = 3.

  CALL METHOD o_docking->free
    EXCEPTIONS
      cntl_error        = 1
      cntl_system_error = 2
      OTHERS            = 3.

ENDFORM.                    " free_objects

Output

Colorconstants

Use this Type-Pool to have "speaking constants" for your colorcodes.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
TYPE-POOL zcol .

CONSTANTS:
  zcol_greyblue(04)              TYPE c VALUE 'C100',
  zcol_lightgrey(04)             TYPE c VALUE 'C200',
  zcol_yellow(04)                TYPE c VALUE 'C300',
  zcol_bluegreen(04)             TYPE c VALUE 'C400',
  zcol_green(04)                 TYPE c VALUE 'C500',
  zcol_red(04)                   TYPE c VALUE 'C600',
  zcol_violett(04)               TYPE c VALUE 'C700',

  zcol_greyblue_int(04)          TYPE c VALUE 'C110',
  zcol_lightgrey_int(04)         TYPE c VALUE 'C210',
  zcol_yellow_int(04)            TYPE c VALUE 'C310',
  zcol_bluegreen_int(04)         TYPE c VALUE 'C410',
  zcol_green_int(04)             TYPE c VALUE 'C510',
  zcol_red_int(04)               TYPE c VALUE 'C610',
  zcol_violett_int(04)           TYPE c VALUE 'C710',

  zcol_greyblue_inv(04)          TYPE c VALUE 'C101',
  zcol_lightgrey_inv(04)         TYPE c VALUE 'C201',
  zcol_yellow_inv(04)            TYPE c VALUE 'C301',
  zcol_bluegreen_inv(04)         TYPE c VALUE 'C401',
  zcol_green_inv(04)             TYPE c VALUE 'C501',
  zcol_red_inv(04)               TYPE c VALUE 'C601',
  zcol_violett_inv(04)           TYPE c VALUE 'C701',

  zcol_greyblue_int_inv(04)      TYPE c VALUE 'C111',
  zcol_lightgrey_int_inv(04)     TYPE c VALUE 'C211',
  zcol_yellow_int_inv(04)        TYPE c VALUE 'C311',
  zcol_bluegreen_int_inv(04)     TYPE c VALUE 'C411',
  zcol_green_int_inv(04)         TYPE c VALUE 'C511',
  zcol_red_int_inv(04)           TYPE c VALUE 'C611',
  zcol_violett_int_inv(04)       TYPE c VALUE 'C711'.

Create this Type-Pool with transaction SE11.

1 Comment

  1. Former Member

    Muy Bueno, y muy útil.