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 to create editable and non editable checkboxes in alv grid display

Former Member
0 Kudos

Hi,

I have two check boxes at my alv output both are editable. But my requirement is when i edit 1st check box second check box should be non editable or make it invisible the second check box. At the time i need to edit one check box. Is it possible in alv grid display.

1 ACCEPTED SOLUTION

AnoopMayamkote
Participant
0 Kudos

I wrote a test program using table SCARR to demonstrate how this can be done.

The checkbox field in the ALV is also a hotspot, so when the user clicks on it, it trigger the form USER_COMMAND, which changes the contents of the selected row and then refreshes the ALV.

In order to refresh, I used the method REFRESH_TABLE_DISPLAY from class CL_GUI_ALV_GRID. I know you are not using ALV OO, but we can get the reference to the ALV grid using FM   'GET_GLOBALS_FROM_SLVC_FULLSCR'.

Here is the code:

REPORT  z_checkbox.

TYPE-POOLS: slis.

TYPES: BEGIN OF ty_scarr,

          checkbox   TYPE c,

          carrid         TYPE scarr-carrid,

          carrname    TYPE scarr-carrname,

          color(4)       TYPE c,  "Field for the color of the row

        END OF ty_scarr.

DATAgt_scarr    TYPE STANDARD TABLE OF ty_scarr,

        gs_scarr    TYPE ty_scarr,

        gt_fcat     TYPE slis_t_fieldcat_alv,

        gs_fcat     TYPE slis_fieldcat_alv,

        gs_layout   TYPE slis_layout_alv,

        gv_repid    TYPE syrepid,

        gv_color(1) TYPE c VALUE '1'.

START-OF-SELECTION.

   gv_repid = sy-repid.

   SELECT carrid carrname

     FROM scarr

     INTO CORRESPONDING FIELDS OF TABLE gt_scarr.

   "The loop changes the color of the rows in the ALV

   LOOP AT gt_scarr INTO gs_scarr.

     "There are only 7 color we can use

     IF gv_color = 8.

       gv_color = 1.

     ENDIF.

      "The field must have the content like 'C110', 'C120',....

     CONCATENATE 'C'

                 gv_color

                 '10'

            INTO gs_scarr-color.

     MODIFY gt_scarr FROM gs_scarr.

     gv_color = gv_color + 1.

   ENDLOOP.

   "Building field catalog

   CLEAR gs_fcat.

   gs_fcat-fieldname  = 'CHECKBOX'.

   gs_fcat-seltext_m  = 'Select'.

   gs_fcat-checkbox  = 'X'.

   gs_fcat-hotspot     = 'X'.

   APPEND gs_fcat TO gt_fcat.

   CLEAR gs_fcat.

   gs_fcat-fieldname     = 'CARRID'.

   gs_fcat-ref_tabname   = 'SCARR'.

   gs_fcat-ref_fieldname = 'CARRID'.

   APPEND gs_fcat TO gt_fcat.

   CLEAR gs_fcat.

   gs_fcat-fieldname     = 'CARRNAME'.

   gs_fcat-ref_tabname   = 'SCARR'.

   gs_fcat-ref_fieldname = 'CARRNAME'.

   APPEND gs_fcat TO gt_fcat.

   

   "Layout information for the ALV

   gs_layout-colwidth_optimize = 'X'.

   gs_layout-info_fieldname    = 'COLOR'.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

     EXPORTING

       i_callback_program           = gv_repid

       i_callback_user_command = 'USER_COMMAND'

       is_layout                          = gs_layout

       it_fieldcat                         = gt_fcat

     TABLES

       t_outtab                           = gt_scarr.

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

*&      Form  user_command

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

*   Form for user actions on the ALV

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

FORM user_command USING r_ucomm LIKE sy-ucomm

                         rs_selfield TYPE slis_selfield.

    "Reference to the ALV grid object

   DATA: lr_grid TYPE REF TO cl_gui_alv_grid.

   READ TABLE gt_scarr INTO gs_scarr INDEX rs_selfield-tabindex.

   "Modifying the selected row - we modify the checkbox and the color.

   gs_scarr-checkbox = 'X'.

   gs_scarr-color    = 'C810'.

   MODIFY gt_scarr FROM gs_scarr INDEX rs_selfield-tabindex.

   "Getting the reference to teh ALV grid

   CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

     IMPORTING

       e_grid = lr_grid.

   "Calling method to refresh the data in the ALV

   CALL METHOD lr_grid->refresh_table_display.

ENDFORM.                    "user_command

I hope it helps, please let me know!

Regards

Anoop

6 REPLIES 6

Former Member
0 Kudos

Here's something that may help:

Neal

0 Kudos

Hi Neal,

Thanks for your reply. I can edit the check box. But my requirement is i have two check boxes at my alv output screen. In this two check boxes  at a time i need to edit one check box another one will make invisible or non editable.
If i edit 1st check box means second should be non editable or else i edit 2nd check box means 1st box should be non editable or invisible.

Thanks/Regards

Venkat

0 Kudos

Hi venkat,

for ALV it is easy to make a whole column editable or not. If the two check boxes are in the same row, then they are different columns. So make one column editable and the other one not.

If the behavior must change depending on the content of the output row, you need an invisible style field column. This will control each cell as desired.

See this sample (upps sorry don't know how to insert code lines here) Can't help. Forget about SCN!

Regards

Clemens

0 Kudos

Clemens Li wrote:

Hi venkat,

for ALV it is easy to make a whole column editable or not. If the two check boxes are in the same row, then they are different columns. So make one column editable and the other one not.

If the behavior must change depending on the content of the output row, you need an invisible style field column. This will control each cell as desired.

See this sample (upps sorry don't know how to insert code lines here) Can't help. Forget about SCN!

Regards

Clemens

{code}

FORM adjust_editables USING pt_list LIKE gt_list[] .

DATA ls_listrow LIKE LINE OF pt_list .

DATA ls_stylerow TYPE lvc_s_styl .

DATA lt_styletab TYPE lvc_t_styl .

LOOP AT pt_list INTO ls_listrow .

IF ls_listrow-carrid = 'XY' .

ls_stylerow-fieldname = 'SEATSMAX' .

ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled .

APPEND ls_stylerow TO lt_styletab .

ENDIF .

IF ls_listrow-connid = '02' .

ls_stylerow-fieldname = 'PLANETYPE' .

ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled .

APPEND ls_stylerow TO lt_styletab .

ENDIF .

INSERT LINES OF lt_styletab INTO ls_listrow-cellstyles .

MODIFY pt_list FROM ls_listrow .

ENDLOOP .

ENDFORM .

{code}

Sijin_Chandran
Active Contributor
0 Kudos

Apart from this helpful replies.

Also check demo program BCALV_EDIT_05 it will also be helpful.

AnoopMayamkote
Participant
0 Kudos

I wrote a test program using table SCARR to demonstrate how this can be done.

The checkbox field in the ALV is also a hotspot, so when the user clicks on it, it trigger the form USER_COMMAND, which changes the contents of the selected row and then refreshes the ALV.

In order to refresh, I used the method REFRESH_TABLE_DISPLAY from class CL_GUI_ALV_GRID. I know you are not using ALV OO, but we can get the reference to the ALV grid using FM   'GET_GLOBALS_FROM_SLVC_FULLSCR'.

Here is the code:

REPORT  z_checkbox.

TYPE-POOLS: slis.

TYPES: BEGIN OF ty_scarr,

          checkbox   TYPE c,

          carrid         TYPE scarr-carrid,

          carrname    TYPE scarr-carrname,

          color(4)       TYPE c,  "Field for the color of the row

        END OF ty_scarr.

DATAgt_scarr    TYPE STANDARD TABLE OF ty_scarr,

        gs_scarr    TYPE ty_scarr,

        gt_fcat     TYPE slis_t_fieldcat_alv,

        gs_fcat     TYPE slis_fieldcat_alv,

        gs_layout   TYPE slis_layout_alv,

        gv_repid    TYPE syrepid,

        gv_color(1) TYPE c VALUE '1'.

START-OF-SELECTION.

   gv_repid = sy-repid.

   SELECT carrid carrname

     FROM scarr

     INTO CORRESPONDING FIELDS OF TABLE gt_scarr.

   "The loop changes the color of the rows in the ALV

   LOOP AT gt_scarr INTO gs_scarr.

     "There are only 7 color we can use

     IF gv_color = 8.

       gv_color = 1.

     ENDIF.

      "The field must have the content like 'C110', 'C120',....

     CONCATENATE 'C'

                 gv_color

                 '10'

            INTO gs_scarr-color.

     MODIFY gt_scarr FROM gs_scarr.

     gv_color = gv_color + 1.

   ENDLOOP.

   "Building field catalog

   CLEAR gs_fcat.

   gs_fcat-fieldname  = 'CHECKBOX'.

   gs_fcat-seltext_m  = 'Select'.

   gs_fcat-checkbox  = 'X'.

   gs_fcat-hotspot     = 'X'.

   APPEND gs_fcat TO gt_fcat.

   CLEAR gs_fcat.

   gs_fcat-fieldname     = 'CARRID'.

   gs_fcat-ref_tabname   = 'SCARR'.

   gs_fcat-ref_fieldname = 'CARRID'.

   APPEND gs_fcat TO gt_fcat.

   CLEAR gs_fcat.

   gs_fcat-fieldname     = 'CARRNAME'.

   gs_fcat-ref_tabname   = 'SCARR'.

   gs_fcat-ref_fieldname = 'CARRNAME'.

   APPEND gs_fcat TO gt_fcat.

   

   "Layout information for the ALV

   gs_layout-colwidth_optimize = 'X'.

   gs_layout-info_fieldname    = 'COLOR'.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

     EXPORTING

       i_callback_program           = gv_repid

       i_callback_user_command = 'USER_COMMAND'

       is_layout                          = gs_layout

       it_fieldcat                         = gt_fcat

     TABLES

       t_outtab                           = gt_scarr.

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

*&      Form  user_command

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

*   Form for user actions on the ALV

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

FORM user_command USING r_ucomm LIKE sy-ucomm

                         rs_selfield TYPE slis_selfield.

    "Reference to the ALV grid object

   DATA: lr_grid TYPE REF TO cl_gui_alv_grid.

   READ TABLE gt_scarr INTO gs_scarr INDEX rs_selfield-tabindex.

   "Modifying the selected row - we modify the checkbox and the color.

   gs_scarr-checkbox = 'X'.

   gs_scarr-color    = 'C810'.

   MODIFY gt_scarr FROM gs_scarr INDEX rs_selfield-tabindex.

   "Getting the reference to teh ALV grid

   CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

     IMPORTING

       e_grid = lr_grid.

   "Calling method to refresh the data in the ALV

   CALL METHOD lr_grid->refresh_table_display.

ENDFORM.                    "user_command

I hope it helps, please let me know!

Regards

Anoop