Sei sulla pagina 1di 11

Getting Started New sletters

Store

Welcome, Guest

Login

Register

Products Industries Lines of Business

Services & Support Training & Education University Alliances

About SCN Partnership Events & Webinars

Downloads Developer Center Innovation

My Home > Code Gallery > ABAP-Changing Cell characteristics in ALV (OOPS)

Browse

Search Tools

ABAP-Changing Cell characteristics in ALV (OOPS)


2 Added by Jayanthi Jayaraman, last edited by Manish Kumar on Jun 18, 2013 (view change) show comment Author: J.Jayanthi Subm itted: 06-Jul-2007 Related Links: ABAP-7 Steps to create OOPS ALV(for beginners) Coloring a Row and Column in ALV (OOPS) Description: This document describes how to 1. color a cell 2. make the particular cell as non-editable 3. display the cell as button in ALV using OOPS method.

Procedure Coloring a cell


Step 1: Include a field called cellcolor in output table as below . Create a w ork area for the cellcolor.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

TYPES : BEGIN OF ty. INCLUDE STRUCTURE mara. * For cell coloring TYPES : cellcolor TYPE lvc_t_scol, END OF ty. Data : w_cellcolor TYPE lvc_s_scol, "For cell color

Step 2: In layout, mention the field name for ctab_fname

* Setting layout w_layout-ctab_fname = 'CELLCOLOR'."For cell coloring

Step 3: Mention the field name for coloring and then set the color, intensified and inverse options.

* Coloring a cell clear w_cellcolor. w_cellcolor-fname = 'ERSDA'. w_cellcolor-color-col = '5'. w_cellcolor-color-int = '1'. w_cellcolor-color-inv = '1'. APPEND w_cellcolor TO wa-cellcolor. MODIFY itab FROM wa INDEX 7 TRANSPORTING cellcolor.

Here you can set the col to different numbers(1 to 9) and then give intensified/ inverse values either 0 or 1 to know the variations. Step 4: Pass the required parameters for set_table_for_first_display as below .

* 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.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.

Displaying the cell as button


Step 1: Include a field called cellstyles in output table as below . Create a w ork area for the styles.
TYPES : BEGIN OF ty. INCLUDE STRUCTURE mara. * For cell editing and displaying cell as push button TYPES : cellstyles TYPE lvc_t_styl, END OF ty. Data w_style TYPE lvc_s_styl.

. Step 2: Set the layout stylefname as CELLSTYLES. * Setting layout


w_layout-stylefname = 'CELLSTYLES' ."cell-push button and edit

t Step 3: Assign mc_style_button to style to display the field as button. You can find those details in cl_gui_alv_grid class's attribute.

* Displaying cell as Push button CLEAR w_style. w_style-fieldname = 'ERNAM' . w_style-style = cl_gui_alv_grid=>mc_style_button . APPEND w_style TO wa-cellstyles. MODIFY itab FROM wa INDEX 1 TRANSPORTING cellstyles.

. Step 4: Pass the layout for set_table_for_first_display.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

* 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.

Making the cell as Editable and non-editable


Follow Step 1 and Step 2 for displaying cell as button. Step 3: Make the entire column as editable and then disable the edit option for a cell for that column. Here in this example, for ERNAM w e are making the third row as non-editable. * Making an entire column as Editable.
FIELD-SYMBOLS: <fs_fcat> TYPE lvc_s_fcat. LOOP AT i_fieldcat ASSIGNING <fs_fcat>. CASE <fs_fcat>-fieldname. WHEN 'ERNAM'. * Making a column as Editable <fs_fcat>-edit = 'X'. ENDCASE. ENDLOOP. * Making a particular cell as non-editable and other editable CLEAR w_style. w_style-fieldname = 'ERNAM'. w_style-style = cl_gui_alv_grid=>mc_style_disabled. REFRESH wa-cellstyles. APPEND w_style TO wa-cellstyles.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

MODIFY itab FROM wa INDEX 3 TRANSPORTING cellstyles.

. Follow Step4 for displaying cell as button.

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

* Data Declaration TYPES : BEGIN OF ty. INCLUDE STRUCTURE mara. * For cell editing and displaying cell as push button TYPES : cellstyles TYPE lvc_t_styl, * For cell coloring cellcolor TYPE lvc_t_scol, 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 w_cellcolor TYPE lvc_s_scol, "For cell color w_style TYPE lvc_s_styl, "cell editing and "displaying cell as push button o_docking TYPE REF TO cl_gui_docking_container,"Docking Container o_grid TYPE REF TO cl_gui_alv_grid. "Grid FIELD-SYMBOLS: <fs_fcat> TYPE lvc_s_fcat. SELECT * FROM mara INTO CORRESPONDING FIELDS OF TABLE itab UP TO 10 ROWS. CALL SCREEN 9000.

*&---------------------------------------------------------------------* *& Module STATUS_9000 OUTPUT *&---------------------------------------------------------------------* * PBO *----------------------------------------------------------------------* MODULE status_9000 OUTPUT.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

IF o_docking IS INITIAL. SET PF-STATUS 'ZSTATUS'. "GUI Status SET TITLEBAR 'ZTITLE'. "Title * Creating Docking Container and grid PERFORM create_object. * Filling the fieldcatalog table PERFORM create_fieldcat. * Setting layout PERFORM set_layout. * Colouring a cell PERFORM color_cell. * Displaying cell as Push button PERFORM cell_button. * Making a cell as non-editable in a column PERFORM cell_edit. * Displaying the output PERFORM display_output. 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

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

*&---------------------------------------------------------------------* * 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 *&---------------------------------------------------------------------* *& Form create_object *&---------------------------------------------------------------------* * Creating Docking Container and grid *----------------------------------------------------------------------* FORM create_object . * Creating 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. ENDFORM. " create_object *&---------------------------------------------------------------------*

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

*& Form create_fieldcat *&---------------------------------------------------------------------* * Filling the fieldcatalog table *----------------------------------------------------------------------* FORM create_fieldcat . * 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. ENDFORM. " create_fieldcat *&---------------------------------------------------------------------* *& Form set_layout *&---------------------------------------------------------------------* * Setting layout *----------------------------------------------------------------------* FORM set_layout . w_variant-report = sy-repid. * Setting layout w_layout-stylefname = 'CELLSTYLES' ."cell-push button and edit w_layout-ctab_fname = 'CELLCOLOR'."For cell coloring ENDFORM. " set_layout *&---------------------------------------------------------------------* *& Form color_cell *&---------------------------------------------------------------------* * Colouring a cell *----------------------------------------------------------------------* FORM color_cell . * Colouring a cell CLEAR w_cellcolor. w_cellcolor-fname = 'ERSDA'. w_cellcolor-color-col = '5'.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

w_cellcolor-color-int = '1'. w_cellcolor-color-inv = '1'. APPEND w_cellcolor TO wa-cellcolor. MODIFY itab FROM wa INDEX 7 TRANSPORTING cellcolor. ENDFORM. " color_cell *&---------------------------------------------------------------------* *& Form cell_button *&---------------------------------------------------------------------* * Displaying cell as Push button *----------------------------------------------------------------------* FORM cell_button . * Displaying cell as Push button CLEAR w_style. w_style-fieldname = 'ERNAM' . w_style-style = cl_gui_alv_grid=>mc_style_button . APPEND w_style TO wa-cellstyles. MODIFY itab FROM wa INDEX 1 TRANSPORTING cellstyles. ENDFORM. " cell_button *&---------------------------------------------------------------------* *& Form cell_edit *&---------------------------------------------------------------------* * Making a cell as non-editable in a column *----------------------------------------------------------------------* FORM cell_edit . LOOP AT i_fieldcat ASSIGNING <fs_fcat>. CASE <fs_fcat>-fieldname. WHEN 'ERNAM'. * Making a column as Editable <fs_fcat>-edit = 'X'. ENDCASE. ENDLOOP. * Making a particular cell as non-editable and other editable. Similarly we can make a * particular cell as non-editable based on some condition. CLEAR w_style. w_style-fieldname = 'ERNAM'. w_style-style = cl_gui_alv_grid=>mc_style_disabled. REFRESH wa-cellstyles. APPEND w_style TO wa-cellstyles. MODIFY itab FROM wa INDEX 3 TRANSPORTING cellstyles.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

ENDFORM. " cell_edit *&---------------------------------------------------------------------* *& Form display_output *&---------------------------------------------------------------------* * Displaying the output *----------------------------------------------------------------------* FORM display_output . * 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. ENDFORM. " display_output

Output
Field : Created on (7th row is colored) Field : Created by (1st row is show n as button) Field : Created by (3rd row is non-editable w hile others are editable(except button))

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Labels
tutorial oops cell edfg

Contact Us Privacy

SAP Help Portal Terms of Use

Legal Disclosure

Copyright

Follow SCN

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Potrebbero piacerti anche