SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Coloring a Row and Column in ALV (OOPS)



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Wed Sep 05, 2007 4:57 pm    Post subject: Coloring a Row and Column in ALV (OOPS) Reply with quote

Original: https: //wiki.sdn.sap.com/wiki/display/Snippets/Coloring+a+Row+and+Column+in+ALV+%28OOPS%29

Author: J.Jayanthi

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.
Code:

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
Data w_layout TYPE lvc_s_layo."Layout structure
Code:
* Setting layout
  w_layout-info_fname = 'ROWCOLOR'."For row coloring


Step 3: Coloring the specific row
Code:
* 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

Code:
* 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.
    IF sy-subrc <> 0.
       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.


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.

Code:

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
&---------------------------------------------------------------------
*       text
----------------------------------------------------------------------
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 coloringColouring 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.
    IF sy-subrc <> 0.
       MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.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.
IF sy-subrc <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD o_docking->free
  EXCEPTIONS
    CNTL_ERROR        = 1
    CNTL_SYSTEM_ERROR = 2
    others            = 3.
IF sy-subrc <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endform.                    " free_objects


Procedure
Coloring a Column

Code:
* Declaring field symbols
FIELD-SYMBOLS : <fs_fieldcat> TYPE lvc_s_fcat.
* Modifying the fieldcatalog for coloring a column
 LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>.
      CASE <fs_fieldcat>-fieldname.
        WHEN 'MATNR'.
* Make the field as non-key so that color should take effect
           <fs_fieldcat>-key = ' '.
* Coloring a column
          <fs_fieldcat>-emphasize = 'C311'.
      ENDCASE.
 ENDLOOP.

Complete Code for Coloring a Column
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.

Code:
DATA : itab TYPE STANDARD TABLE OF mara, "Output Internal table
*Field catalog
     i_fieldcat TYPE STANDARD TABLE OF lvc_s_fcat,
        wa type MARA,
        w_variant TYPE disvariant,
        w_layout  TYPE lvc_s_layo,"Layout structure
*Docking Container
        o_docking TYPE REF TO cl_gui_docking_container,
*GridDeclaring field symbols
        o_grid TYPE REF TO cl_gui_alv_grid.

FIELD-SYMBOLS : <fs_fieldcat> TYPE lvc_s_fcat.
SELECT * FROM mara
  INTO CORRESPONDING FIELDS OF TABLE itab
  UP TO 10 ROWS.
CALL SCREEN 9000.

*&---------------------------------------------------------------------
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------
*       text
*----------------------------------------------------------------------
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.
    "Modifying the fieldcatalog for coloring a column
    LOOP AT i_fieldcat ASSIGNING <fs_fieldcat>.
      CASE <fs_fieldcat>-fieldname.
        WHEN 'MATNR'.
          <fs_fieldcat>-key = ' '.
*Make the field as non-key so that color should take effect
*Coloring a column
          <fs_fieldcat>-emphasize = 'C311'.
      ENDCASE.
    ENDLOOP. "Displaying the output
    CALL METHOD o_grid->set_table_for_first_display
      EXPORTING
         is_variant                    = w_variant
         i_save                        = 'A'
      CHANGING
         it_outtab                     = itab
         it_fieldcatalog               = i_fieldcat
          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.
  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.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  CALL METHOD o_docking->free
    EXCEPTIONS
      cntl_error        = 1
      cntl_system_error = 2
      OTHERS            = 3.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
ENDFORM.



zstatus.PNG
 Description:
zstatus
 Filesize:  3.35 KB
 Viewed:  4828 Time(s)

zstatus.PNG


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.