cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Hide ALV toolbar icons after refresh table display

bharath_padmanabhan
Participant
0 Kudos
401

Experts, 

I am displaying ALV using method set_table_for_first_display. I am excluding toolbar icons using it_toolbar_excluding  parameter in this method. Button EDIT has been added in application toolbar to allow users to select one or more rows and edit the data. Event handle_change_finished has been used to  call method refresh table display to reflect the edited data in ALV. When this method is called, I see that standard ALV toolbar with append, insert and delete row icons is shown. I want to exclude these icons but don't see a way to influence this in refresh table display method call. I found an old SCN thread where they had suggested to call method set_table_for_first_display again instead of refresh table display. I highlight the cells in the rows selected for editing. This highlighting works fine only when I use refresh table display and doesn't work when I use set table display method. So I believe I have to go with refresh table display method to meet my requirement. 
Can you please let me know if its possible to hide the standard ALV icons after refresh table display method call? Is there any other better approach to handle this. I don't want users to have access to icons which are not relevant to them. 

*******Code to display ALV
    me->exclude_alv_toolbar( ).

    CALL METHOD go_grid->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_enter.

    CALL METHOD go_grid->set_table_for_first_display
      EXPORTING
        is_layout            = value lvc_s_layo( sel_mode = 'A' stylefname = 'CELLTAB' ctab_fname = 'CELLCOLOR' no_rowmark = abap_false )
        it_toolbar_excluding = gt_exclude
      CHANGING
        it_fieldcatalog      = gt_fieldcat
        it_outtab            = gt_final.

    SET HANDLER me->handle_top_of_page FOR go_grid.
    SET HANDLER me->handle_change_finished FOR go_grid.

    CALL METHOD cl_gui_cfw=>flush.

*******Code to handle sy-ucomm for EDIT button in PAI
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      LEAVE PROGRAM.
    WHEN 'EDIT'.
      lo_cashdesk->edit_records( ).
    WHEN 'SAVE'.
      lo_cashdesk->save_edit_data( ).
    WHEN 'UNDO'.
      lo_cashdesk->undo_edit_data( ).
  ENDCASE.
ENDMODULE.

********Method called when user clicks EDIT button 
 METHOD edit_records.
    DATA lv_valid TYPE c.
    DATA lt_row_no     TYPE lvc_t_roid.
    DATA lt_stylerow TYPE lvc_t_styl.
    DATA ls_stylerow TYPE lvc_s_styl.
    DATA lt_cellcolor TYPE lvc_t_scol.
    DATA ls_cellcolor TYPE lvc_s_scol.
    DATA ls_stable TYPE lvc_s_stbl.

    CLEAR lt_row_no.
    CALL METHOD go_grid->get_selected_rows
      IMPORTING
        et_row_no = lt_row_no.

    IF NOT lt_row_no IS INITIAL.
      LOOP AT gt_final ASSIGNING FIELD-SYMBOL(<lfs_final>).
        READ TABLE lt_row_no ASSIGNING FIELD-SYMBOL(<lfs_row_no>) WITH KEY row_id = sy-tabix.
        IF sy-subrc = 0.
          ls_stylerow-fieldname = 'TOTAL'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'REC_NO'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'NAME'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'ELECRTICITY'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_cellcolor-fname = 'ELECRTICITY'.
          ls_cellcolor-color-col = 6.
          INSERT ls_cellcolor INTO TABLE lt_cellcolor.
          ls_stylerow-fieldname = 'FRESH_WATER'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_cellcolor-fname = 'FRESH_WATER'.
          ls_cellcolor-color-col = 6.
          INSERT ls_cellcolor INTO TABLE lt_cellcolor.
          ls_stylerow-fieldname = 'SALT_WATER'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_cellcolor-fname = 'SALT_WATER'.
          ls_cellcolor-color-col = 6.
          INSERT ls_cellcolor INTO TABLE lt_cellcolor.
          ls_stylerow-fieldname = 'INST_FEE'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_cellcolor-fname = 'INST_FEE'.
          ls_cellcolor-color-col = 6.
          INSERT ls_cellcolor INTO TABLE lt_cellcolor.
          ls_stylerow-fieldname = 'LABOUR_FEE'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_cellcolor-fname = 'LABOUR_FEE'.
          ls_cellcolor-color-col = 6.
          INSERT ls_cellcolor INTO TABLE lt_cellcolor.
          ls_stylerow-fieldname = 'FINE'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_cellcolor-fname = 'FINE'.
          ls_cellcolor-color-col = 6.
          INSERT ls_cellcolor INTO TABLE lt_cellcolor.
          ls_stylerow-fieldname = 'BALDIAH'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_cellcolor-fname = 'BALDIAH'.
          ls_cellcolor-color-col = 6.
          INSERT ls_cellcolor INTO TABLE lt_cellcolor.
          ls_stylerow-fieldname = 'SEC_DEPO'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_cellcolor-fname = 'SEC_DEPO'.
          ls_cellcolor-color-col = 6.
          INSERT ls_cellcolor INTO TABLE lt_cellcolor.
          ls_stylerow-fieldname = 'PAYON_ACC'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_cellcolor-fname = 'PAYON_ACC'.
          ls_cellcolor-color-col = 6.
          INSERT ls_cellcolor INTO TABLE lt_cellcolor.
          ls_stylerow-fieldname = 'CON_CHARGE'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_cellcolor-fname = 'CON_CHARGE'.
          ls_cellcolor-color-col = 6.
          INSERT ls_cellcolor INTO TABLE lt_cellcolor.
          ls_stylerow-fieldname = 'R'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
        ELSE.
          ls_stylerow-fieldname = 'TOTAL'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'REC_NO'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'NAME'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'ELECRTICITY'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'FRESH_WATER'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'SALT_WATER'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'INST_FEE'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'LABOUR_FEE'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'FINE'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'BALDIAH'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'SEC_DEPO'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'PAYON_ACC'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'CON_CHARGE'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
          ls_stylerow-fieldname = 'R'.
          ls_stylerow-style = cl_gui_alv_grid=>mc_style_disabled.
          INSERT ls_stylerow INTO TABLE lt_stylerow.
        ENDIF.
        CLEAR: <lfs_final>-celltab, <lfs_final>-cellcolor.
        TRY.
            INSERT LINES OF lt_stylerow INTO TABLE <lfs_final>-celltab.
          CATCH cx_sy_itab_duplicate_key.
        ENDTRY.
        TRY.
            INSERT LINES OF lt_cellcolor INTO TABLE <lfs_final>-cellcolor.
          CATCH cx_sy_itab_duplicate_key.
        ENDTRY.
        CLEAR: lt_stylerow, ls_stylerow, lt_cellcolor, ls_cellcolor.
      ENDLOOP.
    ENDIF.

    go_grid->check_changed_data( ).
    IF go_grid->is_ready_for_input( ) EQ 0.
      CALL METHOD go_grid->set_ready_for_input
        EXPORTING
          i_ready_for_input = 1.
    ENDIF.
    ls_stable-row = abap_true.
    ls_stable-col = abap_true.
    CALL METHOD go_grid->refresh_table_display
      EXPORTING
        is_stable = ls_stable
      EXCEPTIONS
        finished  = 1
        OTHERS    = 2.

  ENDMETHOD.

*******Method handle change finished
METHOD handle_change_finished.
    DATA ls_stable TYPE lvc_s_stbl.
    IF et_good_cells IS NOT INITIAL.
      APPEND LINES OF et_good_cells TO gt_good_cells.
      LOOP AT et_good_cells INTO DATA(ls_good_cells) GROUP BY ls_good_cells-row_id.
        READ TABLE gt_final ASSIGNING FIELD-SYMBOL(<lfs_final>) INDEX ls_good_cells-row_id.
        IF sy-subrc EQ 0.
          LOOP AT et_good_cells INTO DATA(ls_good_cells_value) WHERE row_id = ls_good_cells-row_id.
            CASE ls_good_cells_value-fieldname.
              WHEN 'ELECRTICITY'.
                <lfs_final>-elecrticity = <lfs_final>-elecrticity / 10.
              WHEN 'FRESH_WATER'.
                <lfs_final>-fresh_water = <lfs_final>-fresh_water / 10.
              WHEN 'OTHER'.
                <lfs_final>-other = <lfs_final>-other / 10.
              WHEN 'INST_FEE'.
                <lfs_final>-inst_fee = <lfs_final>-inst_fee / 10.
              WHEN 'LABOUR_FEE'.
                <lfs_final>-labour_fee = <lfs_final>-labour_fee / 10.
              WHEN 'FINE'.
                <lfs_final>-fine = <lfs_final>-fine / 10.
              WHEN 'BALDIAH'.
                <lfs_final>-baldiah = <lfs_final>-baldiah / 10.
              WHEN 'SEC_DEPO'.
                <lfs_final>-sec_depo = <lfs_final>-sec_depo / 10.
              WHEN 'SALT_WATER'.
                <lfs_final>-salt_water = <lfs_final>-salt_water / 10.
              WHEN 'PAYON_ACC'.
                <lfs_final>-payon_acc = <lfs_final>-payon_acc / 10.
              WHEN 'CON_CHARGE'.
                <lfs_final>-con_charge = <lfs_final>-con_charge / 10.
              WHEN OTHERS.
            ENDCASE.
          ENDLOOP.
          <lfs_final>-total = <lfs_final>-elecrticity + <lfs_final>-fresh_water + <lfs_final>-salt_water + <lfs_final>-inst_fee +
                              <lfs_final>-labour_fee + <lfs_final>-other + <lfs_final>-payon_acc + <lfs_final>-fine + <lfs_final>-con_charge.
        ENDIF.
      ENDLOOP.
      ls_stable-row = abap_true.
      ls_stable-col = abap_true.
      CALL METHOD go_grid->refresh_table_display
        EXPORTING
          is_stable = ls_stable
        EXCEPTIONS
          finished  = 1
          OTHERS    = 2.
    ENDIF.
  ENDMETHOD.

 I have attached images of initial ALV display where I have successfully hidden icons on ALV toolbar. 2nd attachment shows ALV with standard ALV tool bar icons which is shown after user selects a row and clicks EDIT icon. 

IMG # 1: Initial ALV display where I have hidden the icons using it_toolbar_excluding parameter

IMG # 2: ALV toolbar with standard icons displayed after refresh table display method call

Initial ALV display.jpgALV after refresh table display.jpg

Thanks

Bharath

Accepted Solutions (1)

Accepted Solutions (1)

Sandra_Rossi
Active Contributor
0 Kudos

I guess it's because you call set_ready_for_input( 1 ) after pressing the button which makes the buttons appear.

Move the call before set_table_for_first_display and set the styles of all cells to mc_style_disabled.

You may also not call the method at all, pass EDIT = 'X' instead:

is_layout            = value lvc_s_layo( edit = 'X' ...

NB: your code is difficult to read concerning the change of styles, I suggest this writing (EDIT 2 hours later: color logic adjusted with "row_is_to_be_edited"):

DATA(names_of_editable_fields) = VALUE string_table( ( `ELECRTICITY` )
                                                     ( `FRESH_WATER` )
                                                     ( `SALT_WATER` )
                                                     ( `INST_FEE` )
                                                     ( `LABOUR_FEE` )
                                                     ( `FINE` )
                                                     ( `BALDIAH` )
                                                     ( `SEC_DEPO` )
                                                     ( `PAYON_ACC` )
                                                     ( `CON_CHARGE` ) ).
LOOP AT gt_final ASSIGNING FIELD-SYMBOL(<lfs_final>).
  DATA(row_is_to_be_edited) = COND abap_bool( WHEN line_exists( lt_row_no[ row_id = index_of_alv_row ] )
                                              THEN abap_true 
                                              ELSE abap_false ).
  LOOP AT names_of_editable_fields ASSIGNING FIELD-SYMBOL(<fieldname>).
    <lfs_final>-celltab   = VALUE #( ( fieldname = <fieldname>
                                       style     = COND #( WHEN row_is_to_be_edited = abap_true
                                                           THEN cl_gui_alv_grid=>mc_style_enabled
                                                           ELSE cl_gui_alv_grid=>mc_style_disabled ) ) ).
    <lfs_final>-cellcolor = COND #( WHEN row_is_to_be_edited = abap_true
                                    THEN VALUE #( ( fname     = <fieldname>
                                                    color-col = 6 ) ) ).
   ENDLOOP.
ENDLOOP.

Also, the "FS" part of field symbol names <LFS...> is useless, it's obvious that <...> is a field symbol.

NB: catching duplicate lines of INSERT is useless because your code doesn't pass duplicate lines so the exception will never happen.

bharath_padmanabhan
Participant

Hi Sandra,

Thank you so much for your reply.

1) I have removed the img attachments and embedded them to the thread body.

2) Insert statement - catching duplicates is useless. Agreed. Thanks for the call out. I have changed the code now.

3) "FS" part of field symbol names <LFS...> is useless - Agreed. I picked it up somewhere long back in one of my clients as part of their ABAP naming convention docu. Been doing it for many yrs now. But your point makes total sense. Will change my approach.

4) My reqmt is to make all the rows display only. User will choose one or more rows to edit. Only those rows should be allowed for editing and the rest should be in display mode. I believe if I use value lvc_s_layo( edit = 'X' ... ) then the entire ALV rows will show up as editable.

5) Your code is difficult to read concerning the change of styles: I love your suggestion. Will implement the same. The code I have written comes from BCALV_EDIT_05.

Thanks Bharath

bharath_padmanabhan
Participant
0 Kudos

Hi

bharath_padmanabhan
Participant
0 Kudos

Hi Sandra,

Reason I don't want to open up the entire ALV output for editing is because users might fat finger the edit and change the incorrect report.

So I am restricting it with a display mode initially and then only highlight the selected row using red color.

Thanks

Bharath

Sandra_Rossi
Active Contributor
0 Kudos
You're right, if you define as editable, the default cell styles are "enabled", hence you also need to set the initial cell styles to "disabled".
bharath_padmanabhan
Participant

Hi Sandra,

Thanks a bunch for your reply. Your solution worked perfectly. As you rightly said, below code was the reason behind standard ALV toolbar icons showing up post refresh table display method call.

IF go_grid->is_ready_for_input( ) EQ 0.

CALL METHOD go_grid->set_ready_for_input

EXPORTING

i_ready_for_input = 1.

ENDIF.

I simply followed your suggestion and it worked like a magic. To sum up, given below are the steps performed:

Step 1) Set ALV layout parameter EDIT as 'X'. This will open up the entire ALV for editing. Since my reqmt is to keep the whole ALV as display only to begin with, I did step 2.

Step 2) For each cell in ALV row, set the celltab as disabled. This made the entire ALV as display only during initial ALV output. 

Step 3) User selects 1 or more rows and clicks edit button. At this point, we open up only the selected rows for editing by setting the celltab as enabled. Since the layout is already set as EDIT mode in step 1, I didn't have to call is_ready_for_input method again in PAI. 

Step 4) The initial ALV toolbar with the excluded ALV toolbar icons is perfectly retained on the screen post PAI and refresh table display method call. 

Thanks

Bharath

Sandra_Rossi
Active Contributor
0 Kudos
Thanks for the feedback. By the way, I also recommend not using "CALL METHOD methodname" which is obsolete, just don't mention "CALL METHOD" at all, i.e. use "methodname( )." The only form where "CALL METHOD" can still be used is where it's mandatory, i.e. the dynamic variant, for instance "CALL METHOD ('ZCL_CLASS')=>('METHODNAME')."

Answers (1)

Answers (1)

lcpaiva
Explorer
0 Kudos

Hi Bharath,

You can try the thread below:

Solved: set specific rows in ALV grid ready for input - SAP Community

See also the sample report BCALV_EDIT_02

bharath_padmanabhan
Participant
0 Kudos
Hi Icpaiva
bharath_padmanabhan
Participant

Hi Icpaiva

Thanks for your reply. I am able to set the desired rows in edit mode. My question was related to influencing ALV toolbar after refresh table display method call.

Thanks