Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I enable color selector option on an abap report?

Former Member
0 Kudos
808

I have a requirement to color alv report lines based on a dynamic color selector option. I referred DEMO_COLORSEL, but this does not give me an option to choose just 7 colors (the basic ALV colors, and not intensified or inversed) and just calls a standard routine to display the colors in a dropdown fashion.

My need is to get a dropdown of colors and when I click on the color, I should be able to grab the return code so I may use it to do further processing like color the alv lines with the selected color.

Any ideas, anybody? Thanks and appreciate your replies.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
231

Hi Aradhana,

I have created a program using ALV with ABAP objects which contains a column with colors as drop down list.

I have set the default color as Green.

I have created a custom container for ALV.

If the color has been selected and row has been double clicked, the color of the cell changes

accordingly to the selected color using the event data_changed.

I have also attached 2 outputs - 1. before selecting colors and

                                               2. after selecting colors

Coding:

*--------------------------------------------------------------------*

*   Types

*--------------------------------------------------------------------*

TYPESBEGIN OF ys_vbap,

           vbeln       TYPE vbeln_va,

           posnr       TYPE posnr_va,

           matnr       TYPE matnr,

           kwmeng      TYPE kwmeng,

           netpr       TYPE netpr,

           color       TYPE char30,

           line_color  TYPE char4,

         END OF ys_vbap,

         yt_vbap   TYPE STANDARD TABLE OF ys_vbap.

*--------------------------------------------------------------------*

*   Data

*--------------------------------------------------------------------*

DATA: gs_vbap       TYPE ys_vbap,

       gt_vbap       TYPE yt_vbap,

       gt_fcat       TYPE lvc_t_fcat,

       gs_fcat       TYPE lvc_s_fcat,

       gv_opts       TYPE vbak-vbeln,

       gs_layo       TYPE lvc_s_layo,

       gs_drop       TYPE lvc_s_drop,

       gt_drop       TYPE lvc_t_drop,

       go_cont       TYPE REF TO cl_gui_custom_container,

       go_grid       TYPE REF TO cl_gui_alv_grid,

       gt_style      TYPE lvc_t_modi,

       gt_cells      TYPE lvc_t_pos,

       gt_bad_cells  TYPE lvc_t_modi,

       gt_msg        TYPE lvc_t_msg1,

       gt_conversion TYPE lvc_t_roid.

*--------------------------------------------------------------------*

*   Field Symbols

*--------------------------------------------------------------------*

FIELD-SYMBOLS: <fs_fcat>  TYPE lvc_s_fcat,

                <fs_vbap>  TYPE ys_vbap,

                <fs_mod>   TYPE lvc_s_modi.

*--------------------------------------------------------------------*

*   Selection-Screen

*--------------------------------------------------------------------*

SELECT-OPTIONS: so_vbeln FOR gv_opts.

*--------------------------------------------------------------------*

*   Class

*--------------------------------------------------------------------*

CLASS cl_alv DEFINITION FINAL.

   PUBLIC SECTION.

     METHODS: get_modified_data  FOR EVENT data_changed

                                 OF        cl_gui_alv_grid

                                 IMPORTING er_data_changed

                                           e_ucomm.

ENDCLASS.                    "cl_alv DEFINITION

*----------------------------------------------------------------------*

*       CLASS cl_alv IMPLEMENTATION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS cl_alv IMPLEMENTATION.

   METHOD get_modified_data.

     SORT: er_data_changed->mt_mod_cells.

     LOOP AT er_data_changed->mt_good_cells ASSIGNING <fs_mod>.

       gs_vbap-color = <fs_mod>-value.

       CASE gs_vbap-color.

         WHEN 'GUI DEPENDENT'.

           gs_vbap-line_color = 'C010'.

         WHEN 'GRAY-BLUE'.

           gs_vbap-line_color = 'C110'.

         WHEN 'LIGHT GRAY'.

           gs_vbap-line_color = 'C210'.

         WHEN 'YELLOW'.

           gs_vbap-line_color = 'C310'.

         WHEN 'BLUE-GREEN'.

           gs_vbap-line_color = 'C410'.

         WHEN 'GREEN'.

           gs_vbap-line_color = 'C510'.

         WHEN 'RED'.

           gs_vbap-line_color = 'C610'.

         WHEN 'VIOLET'.

           gs_vbap-line_color = 'C710'. "C710 - Color, Number, Intensified, Inverse

       ENDCASE.

       MODIFY gt_vbap FROM gs_vbap INDEX <fs_mod>-row_id

                                   TRANSPORTING color line_color.

     ENDLOOP.

     CALL METHOD go_grid->refresh_table_display

       EXCEPTIONS

         finished       = 1

         OTHERS         = 2.

     IF sy-subrc <> 0.

       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

     ENDIF.

   ENDMETHOD.                    "get_modified_Data

ENDCLASS.                    "cl_alv IMPLEMENTATION

DATA: go_cl TYPE REF TO cl_alv.

START-OF-SELECTION.

   CALL SCREEN 9000.

*&---------------------------------------------------------------------*

*&      Module  CREATE_OBJS  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE create_objs OUTPUT.

   IF go_cont IS NOT BOUND.

     CREATE OBJECT go_cont

       EXPORTING

          container_name              = 'CUSTOM'

       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.

     IF go_grid IS NOT BOUND.

       CREATE OBJECT go_grid

         EXPORTING

             i_parent         = go_cont

         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.

       CREATE OBJECT go_cl.

       IF go_cl IS BOUND.

         SET HANDLER go_cl->get_modified_data FOR go_grid.

       ENDIF.

     ENDIF.

   ENDIF.

ENDMODULE.                 " CREATE_OBJS  OUTPUT

*&---------------------------------------------------------------------*

*&      Module  DATA_FETCH  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE data_fetch OUTPUT.

   SELECT vbeln posnr matnr kwmeng netpr

   FROM vbap

   INTO TABLE gt_vbap

   WHERE vbeln IN so_vbeln.

   IF sy-subrc <> 0.

     REFRESH: gt_vbap.

   ENDIF.

ENDMODULE.                 " DATA_FETCH  OUTPUT

*&---------------------------------------------------------------------*

*&      Module  FIELD_CAT  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE field_cat OUTPUT.

   PERFORM field_catalog USING: 1 'VBELN'  'Sales Doc. No.',

                                2 'POSNR'  'Item',

                                3 'MATNR'  'Material',

                                4 'KWMENG' 'Quantity',

                                5 'NETPR'  'Net Price',

                                6 'COLOR'  'Color'.

   PERFORM set_dropdown.

ENDMODULE.                 " FIELD_CAT  OUTPUT

*&---------------------------------------------------------------------*

*&      Module  SET_LAYOUT  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE set_layout OUTPUT.

   gs_layo-info_fname = 'LINE_COLOR'.

   "Default color

   LOOP AT gt_vbap ASSIGNING <fs_vbap>.

         <fs_vbap>-color = 'Green'.

         <fs_vbap>-line_color = 'C510'.

   ENDLOOP.

ENDMODULE.                 " SET_LAYOUT  OUTPUT

*&---------------------------------------------------------------------*

*&      Module  DISPLAY_ALV  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE display_alv OUTPUT.

   IF go_grid IS BOUND.

     CALL METHOD go_grid->set_table_for_first_display

       EXPORTING

          is_layout                     = gs_layo

       CHANGING

          it_outtab                     = gt_vbap

          it_fieldcatalog               = gt_fcat

       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.                 " DISPLAY_ALV  OUTPUT

*&---------------------------------------------------------------------*

*&      Form  FIELD_CATALOG

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->P_1      text

*      -->P_0067   text

*----------------------------------------------------------------------*

FORM field_catalog  USING    value(pa_col_pos)  TYPE lvc_colpos

                              value(pa_fname)    TYPE lvc_fname

                              value(pa_colname)  TYPE scrtext_m.

   gs_fcat-col_pos = pa_col_pos.

   gs_fcat-fieldname = pa_fname.

   gs_fcat-scrtext_m = pa_colname.

   CASE gs_fcat-fieldname.

     WHEN 'COLOR'.

       gs_fcat-edit = 'X'.

       gs_fcat-drdn_hndl = 1.

   ENDCASE.

   APPEND gs_fcat TO gt_fcat.

   CLEAR: gs_fcat.

ENDFORM.                    " FIELD_CATALOG

*&---------------------------------------------------------------------*

*&      Form  SET_DROPDOWN

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM set_dropdown .

   PERFORM set_color USING: 'GUI Dependent',

                            'Gray-Blue',

                            'Light Gray',

                            'Yellow',

                            'Blue-Green',

                            'Green',

                            'Red',

                            'Violet'.

   IF go_grid IS BOUND.

     CALL METHOD go_grid->set_drop_down_table

       EXPORTING

         it_drop_down = gt_drop.

   ENDIF.

ENDFORM.                    " SET_DROPDOWN

*&---------------------------------------------------------------------*

*&      Form  SET_COLOR

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->P_0188   text

*      -->P_0189   text

*----------------------------------------------------------------------*

FORM set_color  USING    value(pa_value) TYPE lvc_value.

   gs_drop-handle   = 1.

   gs_drop-value  = pa_value.

   APPEND gs_drop TO gt_drop.

   CLEAR: gs_drop.

ENDFORM.                    " SET_COLOR

Output:

Before Selecting Colors:



After Selecting Colors:

Hope, this helps.

Thanks & Regards,

T. Prasanna Kumar

6 REPLIES 6

Former Member
0 Kudos
232

Hi Aradhana,

I have created a program using ALV with ABAP objects which contains a column with colors as drop down list.

I have set the default color as Green.

I have created a custom container for ALV.

If the color has been selected and row has been double clicked, the color of the cell changes

accordingly to the selected color using the event data_changed.

I have also attached 2 outputs - 1. before selecting colors and

                                               2. after selecting colors

Coding:

*--------------------------------------------------------------------*

*   Types

*--------------------------------------------------------------------*

TYPESBEGIN OF ys_vbap,

           vbeln       TYPE vbeln_va,

           posnr       TYPE posnr_va,

           matnr       TYPE matnr,

           kwmeng      TYPE kwmeng,

           netpr       TYPE netpr,

           color       TYPE char30,

           line_color  TYPE char4,

         END OF ys_vbap,

         yt_vbap   TYPE STANDARD TABLE OF ys_vbap.

*--------------------------------------------------------------------*

*   Data

*--------------------------------------------------------------------*

DATA: gs_vbap       TYPE ys_vbap,

       gt_vbap       TYPE yt_vbap,

       gt_fcat       TYPE lvc_t_fcat,

       gs_fcat       TYPE lvc_s_fcat,

       gv_opts       TYPE vbak-vbeln,

       gs_layo       TYPE lvc_s_layo,

       gs_drop       TYPE lvc_s_drop,

       gt_drop       TYPE lvc_t_drop,

       go_cont       TYPE REF TO cl_gui_custom_container,

       go_grid       TYPE REF TO cl_gui_alv_grid,

       gt_style      TYPE lvc_t_modi,

       gt_cells      TYPE lvc_t_pos,

       gt_bad_cells  TYPE lvc_t_modi,

       gt_msg        TYPE lvc_t_msg1,

       gt_conversion TYPE lvc_t_roid.

*--------------------------------------------------------------------*

*   Field Symbols

*--------------------------------------------------------------------*

FIELD-SYMBOLS: <fs_fcat>  TYPE lvc_s_fcat,

                <fs_vbap>  TYPE ys_vbap,

                <fs_mod>   TYPE lvc_s_modi.

*--------------------------------------------------------------------*

*   Selection-Screen

*--------------------------------------------------------------------*

SELECT-OPTIONS: so_vbeln FOR gv_opts.

*--------------------------------------------------------------------*

*   Class

*--------------------------------------------------------------------*

CLASS cl_alv DEFINITION FINAL.

   PUBLIC SECTION.

     METHODS: get_modified_data  FOR EVENT data_changed

                                 OF        cl_gui_alv_grid

                                 IMPORTING er_data_changed

                                           e_ucomm.

ENDCLASS.                    "cl_alv DEFINITION

*----------------------------------------------------------------------*

*       CLASS cl_alv IMPLEMENTATION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS cl_alv IMPLEMENTATION.

   METHOD get_modified_data.

     SORT: er_data_changed->mt_mod_cells.

     LOOP AT er_data_changed->mt_good_cells ASSIGNING <fs_mod>.

       gs_vbap-color = <fs_mod>-value.

       CASE gs_vbap-color.

         WHEN 'GUI DEPENDENT'.

           gs_vbap-line_color = 'C010'.

         WHEN 'GRAY-BLUE'.

           gs_vbap-line_color = 'C110'.

         WHEN 'LIGHT GRAY'.

           gs_vbap-line_color = 'C210'.

         WHEN 'YELLOW'.

           gs_vbap-line_color = 'C310'.

         WHEN 'BLUE-GREEN'.

           gs_vbap-line_color = 'C410'.

         WHEN 'GREEN'.

           gs_vbap-line_color = 'C510'.

         WHEN 'RED'.

           gs_vbap-line_color = 'C610'.

         WHEN 'VIOLET'.

           gs_vbap-line_color = 'C710'. "C710 - Color, Number, Intensified, Inverse

       ENDCASE.

       MODIFY gt_vbap FROM gs_vbap INDEX <fs_mod>-row_id

                                   TRANSPORTING color line_color.

     ENDLOOP.

     CALL METHOD go_grid->refresh_table_display

       EXCEPTIONS

         finished       = 1

         OTHERS         = 2.

     IF sy-subrc <> 0.

       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

     ENDIF.

   ENDMETHOD.                    "get_modified_Data

ENDCLASS.                    "cl_alv IMPLEMENTATION

DATA: go_cl TYPE REF TO cl_alv.

START-OF-SELECTION.

   CALL SCREEN 9000.

*&---------------------------------------------------------------------*

*&      Module  CREATE_OBJS  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE create_objs OUTPUT.

   IF go_cont IS NOT BOUND.

     CREATE OBJECT go_cont

       EXPORTING

          container_name              = 'CUSTOM'

       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.

     IF go_grid IS NOT BOUND.

       CREATE OBJECT go_grid

         EXPORTING

             i_parent         = go_cont

         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.

       CREATE OBJECT go_cl.

       IF go_cl IS BOUND.

         SET HANDLER go_cl->get_modified_data FOR go_grid.

       ENDIF.

     ENDIF.

   ENDIF.

ENDMODULE.                 " CREATE_OBJS  OUTPUT

*&---------------------------------------------------------------------*

*&      Module  DATA_FETCH  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE data_fetch OUTPUT.

   SELECT vbeln posnr matnr kwmeng netpr

   FROM vbap

   INTO TABLE gt_vbap

   WHERE vbeln IN so_vbeln.

   IF sy-subrc <> 0.

     REFRESH: gt_vbap.

   ENDIF.

ENDMODULE.                 " DATA_FETCH  OUTPUT

*&---------------------------------------------------------------------*

*&      Module  FIELD_CAT  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE field_cat OUTPUT.

   PERFORM field_catalog USING: 1 'VBELN'  'Sales Doc. No.',

                                2 'POSNR'  'Item',

                                3 'MATNR'  'Material',

                                4 'KWMENG' 'Quantity',

                                5 'NETPR'  'Net Price',

                                6 'COLOR'  'Color'.

   PERFORM set_dropdown.

ENDMODULE.                 " FIELD_CAT  OUTPUT

*&---------------------------------------------------------------------*

*&      Module  SET_LAYOUT  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE set_layout OUTPUT.

   gs_layo-info_fname = 'LINE_COLOR'.

   "Default color

   LOOP AT gt_vbap ASSIGNING <fs_vbap>.

         <fs_vbap>-color = 'Green'.

         <fs_vbap>-line_color = 'C510'.

   ENDLOOP.

ENDMODULE.                 " SET_LAYOUT  OUTPUT

*&---------------------------------------------------------------------*

*&      Module  DISPLAY_ALV  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE display_alv OUTPUT.

   IF go_grid IS BOUND.

     CALL METHOD go_grid->set_table_for_first_display

       EXPORTING

          is_layout                     = gs_layo

       CHANGING

          it_outtab                     = gt_vbap

          it_fieldcatalog               = gt_fcat

       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.                 " DISPLAY_ALV  OUTPUT

*&---------------------------------------------------------------------*

*&      Form  FIELD_CATALOG

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->P_1      text

*      -->P_0067   text

*----------------------------------------------------------------------*

FORM field_catalog  USING    value(pa_col_pos)  TYPE lvc_colpos

                              value(pa_fname)    TYPE lvc_fname

                              value(pa_colname)  TYPE scrtext_m.

   gs_fcat-col_pos = pa_col_pos.

   gs_fcat-fieldname = pa_fname.

   gs_fcat-scrtext_m = pa_colname.

   CASE gs_fcat-fieldname.

     WHEN 'COLOR'.

       gs_fcat-edit = 'X'.

       gs_fcat-drdn_hndl = 1.

   ENDCASE.

   APPEND gs_fcat TO gt_fcat.

   CLEAR: gs_fcat.

ENDFORM.                    " FIELD_CATALOG

*&---------------------------------------------------------------------*

*&      Form  SET_DROPDOWN

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM set_dropdown .

   PERFORM set_color USING: 'GUI Dependent',

                            'Gray-Blue',

                            'Light Gray',

                            'Yellow',

                            'Blue-Green',

                            'Green',

                            'Red',

                            'Violet'.

   IF go_grid IS BOUND.

     CALL METHOD go_grid->set_drop_down_table

       EXPORTING

         it_drop_down = gt_drop.

   ENDIF.

ENDFORM.                    " SET_DROPDOWN

*&---------------------------------------------------------------------*

*&      Form  SET_COLOR

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->P_0188   text

*      -->P_0189   text

*----------------------------------------------------------------------*

FORM set_color  USING    value(pa_value) TYPE lvc_value.

   gs_drop-handle   = 1.

   gs_drop-value  = pa_value.

   APPEND gs_drop TO gt_drop.

   CLEAR: gs_drop.

ENDFORM.                    " SET_COLOR

Output:

Before Selecting Colors:



After Selecting Colors:

Hope, this helps.

Thanks & Regards,

T. Prasanna Kumar

0 Kudos
231

Thanks for your elaborate reply, that was very helpful. Sorry for replying to you so late, I had been busy with some other high priority items, so the color coding got pushed to later. Your answer does point to the direction I must go to achieve color coding in the report, but the initial stage of this has to be 'Choose color'.

So when I execute the report, I should see a button that says Choose color and when I click on it, it should show me the colors available(some few colors - they dont have a specific requirement), and based upon what I choose I should be able to capture the color code and turn the row into that color accordingly. This 'Choose color' is what I havent been able to figure out. I have a std. reference program DEMO_COLORSEL, but I dont understand how this will fit into the scheme of the requirement.Any ideas ? Thanks.

0 Kudos
231

Hi Aradhana,

Sorry for the late reply.

I need to know that whether "Choose color" button should be available for each row in ALV.

If it is so, do I need to display the colors in a separate window as a dialog box or do I need to display another column for color in ALV when this button is clicked in ALV.

Thanks & Regards,

T. Prasanna Kumar

0 Kudos
231

Prasanna, the Choose color button should be on the ALV report output screen. The reqmnt is to select few lines and then click on this button which will show a dialog box. Choose any color from the dailog box and that should update the selected lines. Please let me know if you need more clarity. Thanks, Aradhana

0 Kudos
231

Hi Aradhana,

Use the below specified events from class CL_GUI_ALV_GRID to solve your problem by declaring a class in your program and methods are to be defined and implemented according to the requirement.

S.No.     Functionality                                                            Event

1.          To add button to the toolbar                                         toolbar

2.          After user selects rows and clicks the button                user_command

Steps:


1. Initially, you have to add a button in the toolbar. 

2. When the user selects the rows in ALV and clicks the button, the rows that has been selected must be retrieved using the method get_selected_rows of class CL_GUI_ALV_GRID.

3. Then, call a screen which is a modal dialog box containing the colors.

Steps 4 and 5 logic should be written in PAI of modal dialog box.

4. When the color is selected, based upon the color chosen, change the field LINE_COLOR for the selected rows.

LOOP AT gt_sel_row_id INTO gs_sel_row_id.      "Selected Rows

          "Internal table of ALV

         READ TABLE gt_vbap ASSIGNING <fs_vbap> INDEX gs_sel_row_id-row_id.

         IF sy-subrc = 0.

           CASE gs_colors-color_name.

             WHEN 'GUI DEPENDENT'.

               <fs_vbap>-line_color = 'C010'.

             WHEN 'GRAY-BLUE'.

               <fs_vbap>-line_color = 'C110'.

             WHEN 'LIGHT GRAY'.

               <fs_vbap>-line_color = 'C210'.

             WHEN 'YELLOW'.

               <fs_vbap>-line_color = 'C310'.

             WHEN 'BLUE-GREEN'.

               <fs_vbap>-line_color = 'C410'.

             WHEN 'GREEN'.

               <fs_vbap>-line_color = 'C510'.

             WHEN 'RED'.

               <fs_vbap>-line_color = 'C610'.

             WHEN 'VIOLET'.

               <fs_vbap>-line_color = 'C710'.

           ENDCASE.

         ENDIF.


ENDLOOP.

5. Refresh the ALV using method refresh_table_display of class CL_GUI_ALV_GRID.

IF go_grid IS BOUND.

     CALL METHOD go_grid->refresh_table_display

       EXCEPTIONS

         finished = 1

         OTHERS   = 2.

     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.

Thanks & Regards,

T. Prasanna Kumar


former_member220538
Active Participant
0 Kudos
231

Hi,

Please refer this link.

http://wiki.scn.sap.com/wiki/display/Snippets/Change+color+of+individual+ALV+rows

Use a buttton in ALV to call a screen which shows the colors,use the code to dispaly as a dialog box.

CALL SCREEN <no> STARTING AT <x> <y>.

According to the user selection, modify the field LINE_COLOR for the selected records in the internal table.

Regards,

Jeffin