Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Store
Welcome, Guest
Login
Register
My Home > Code Gallery > ABAP-Changing Cell characteristics in ALV (OOPS)
Browse
Search Tools
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 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.
pdfcrowd.com
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.
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.
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.
pdfcrowd.com
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.
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
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 *&---------------------------------------------------------------------*
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'.
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.
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))
pdfcrowd.com
Labels
tutorial oops cell edfg
Contact Us Privacy
Legal Disclosure
Copyright
Follow SCN
pdfcrowd.com