Application Development and Automation 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: 
Read only

ALV Toolbarcustom button problem

Former Member
0 Likes
2,136

I have two custom button with th standard ALV toolbar. Every thing is working fine. EDIT button is to open one column (NPI_QTY) is edit mode. when i click on EDIT button it opens up teh NPI_QTY field and I have put code at the SAVE to update the database with the latest NPI_QTY.

My problem is that after hitting the SAVE button if I tried to click on EDIT button it bouble up the Buttons,

Means after that I have two EDIT Button and two PHASE UPDATE Button with the ALV. How Can I avoide this.

CLASS lcl_event_receiver DEFINITION.

handle_toolbar

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object e_interactive,

handle_user_command

FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING e_ucomm,

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

*In event handler method for event TOOLBAR: Append own functions

*by using event parameter E_OBJECT.

DATA: ls_toolbar TYPE stb_button,

lv_object TYPE char15.

READ TABLE e_object->mt_toolbar INTO lv_object

WITH KEY function = 'EDIT'.

IF NOT sy-subrc EQ 0.

MOVE 'EDIT' TO ls_toolbar-function.

MOVE 'ICON_TOGGLE_DISPLAY_CHANGE' TO ls_toolbar-icon.

MOVE text-112 TO ls_toolbar-quickinfo.

MOVE text-111 TO ls_toolbar-text.

MOVE ' ' TO ls_toolbar-disabled.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDIF.

READ TABLE e_object->mt_toolbar INTO lv_object

WITH KEY function = 'UPDATE'.

IF NOT sy-subrc EQ 0.

  • Append a separator to normal toolbar

CLEAR ls_toolbar.

MOVE 3 TO ls_toolbar-butn_type.

APPEND ls_toolbar TO e_object->mt_toolbar.

CLEAR ls_toolbar.

MOVE 'UPDATE' TO ls_toolbar-function.

  • MOVE ' ' TO ls_toolbar-icon.

MOVE text-108 TO ls_toolbar-quickinfo.

MOVE text-108 TO ls_toolbar-text.

MOVE ' ' TO ls_toolbar-disabled.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDIF.

ENDMETHOD.

METHOD handle_user_command.

DATA: lt_rows TYPE lvc_t_row,

wa_rows TYPE lvc_s_row.

*Phase update

WHEN 'UPDATE'.

PERFORM UPDATE_PHASE.

WHEN 'EDIT'.

PERFORM switch_edit_mode.

ENDCASE.

22 REPLIES 22
Read only

Former Member
0 Likes
2,025

Hi,

The problem is you are not refreshing the internal table of the tool list.

Else you can add code saying that if that internal tbale is initial populate them else skip that part.

So, use Refresh and Clear if necessary free the objects where ever required for better performance.

Regards,

Suman

Read only

0 Likes
2,025

Can you please tell me where I need to resresh the ALV toolbar?

Read only

Former Member
0 Likes
2,025
METHOD handle_user_command.
DATA: lt_rows TYPE lvc_t_row,
wa_rows TYPE lvc_s_row.
*Phase update
WHEN 'UPDATE'.
PERFORM UPDATE_PHASE.
 <b> CALL METHOD G_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.</b>WHEN 'EDIT'.
PERFORM switch_edit_mode.
 <b> CALL METHOD G_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.</b>ENDCASE.
Read only

0 Likes
2,025

I did it but still getting bouble. and It is executing the EDIT User command twice.

Read only

0 Likes
2,025

can you give/show your code..

regards

vijay

Read only

0 Likes
2,025

CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

METHODS:

handle_double_click

FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING e_row e_column,

handle_close

FOR EVENT close OF cl_gui_dialogbox_container

IMPORTING sender,

hotspot_click

FOR EVENT hotspot_click OF cl_gui_alv_grid

IMPORTING e_row_id e_column_id,

  • button_click FOR EVENT button_click OF cl_gui_alv_grid

  • IMPORTING es_col_id es_row_no.

handle_toolbar

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object e_interactive,

handle_user_command

FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING e_ucomm,

handle_data_changed

FOR EVENT data_changed OF cl_gui_alv_grid

IMPORTING er_data_changed.

PRIVATE SECTION.

DATA: dialogbox_status TYPE c. "'X': does exist, SPACE: does not ex.

  • This flag is set if any error occured

DATA: v_error_in_data TYPE c.

  • Methods to modularize event handler method HANDLE_DATA_CHANGED:

METHODS: check_npi_qty

IMPORTING

ps_npi_qty TYPE lvc_s_modi

pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

ENDCLASS.

----


  • CLASS LCL_EVENT_RECEIVER IMPLEMENTATION

----


  • Implementation *

----


CLASS lcl_event_receiver IMPLEMENTATION.

*Using row parameter to select a line of the

*corresponding internal table.

METHOD handle_double_click.

CHECK e_column = 'GV_FLAG' OR

e_column = 'GV_FLAG_PO'.

IF gt_item1[] IS INITIAL.

PERFORM f_display_rfq_po_data USING e_row e_column.

ENDIF.

IF NOT gt_item1[] IS INITIAL.

*To Create dialogbox to show detail list

IF dialogbox_status IS INITIAL.

dialogbox_status = 'X'.

PERFORM f_detail_list.

ELSE.

CALL METHOD dialogbox_container->set_visible

EXPORTING visible = 'X'.

CALL METHOD gcl_grid2->refresh_table_display.

SET HANDLER w_event_rec->handle_double_click FOR gcl_grid2.

SET HANDLER w_event_rec->hotspot_click FOR gcl_grid2.

ENDIF.

ENDIF.

ENDMETHOD.

*Hotspot click

METHOD hotspot_click.

PERFORM f_hotspot_click USING e_row_id

e_column_id .

ENDMETHOD.

METHOD handle_data_changed.

DATA: ls_good TYPE lvc_s_modi.

v_error_in_data = space.

LOOP AT er_data_changed->mt_good_cells INTO ls_good.

CALL METHOD check_npi_qty

EXPORTING

ps_npi_qty = ls_good

pr_data_changed = er_data_changed.

ENDLOOP.

*Display application log if an error has occured.

IF v_error_in_data EQ 'X'.

CALL METHOD er_data_changed->display_protocol.

ELSE.

LOOP AT er_data_changed->mt_good_cells INTO ls_good.

wa_chg-row_id = ls_good-row_id.

APPEND wa_chg TO gt_chg.

ENDLOOP.

ENDIF.

ENDMETHOD.

  • set dialogbox invisible

METHOD handle_close.

CLEAR gt_item1.

CALL METHOD sender->set_visible

EXPORTING visible = space.

ENDMETHOD.

METHOD handle_toolbar.

*In event handler method for event TOOLBAR: Append own functions

*by using event parameter E_OBJECT.

DATA: ls_toolbar TYPE stb_button,

lv_object TYPE char15.

MOVE 'EDIT' TO ls_toolbar-function.

MOVE 'ICON_TOGGLE_DISPLAY_CHANGE' TO ls_toolbar-icon.

MOVE text-112 TO ls_toolbar-quickinfo.

MOVE text-111 TO ls_toolbar-text.

MOVE ' ' TO ls_toolbar-disabled.

APPEND ls_toolbar TO e_object->mt_toolbar.

  • Append a separator to normal toolbar

CLEAR ls_toolbar.

MOVE 3 TO ls_toolbar-butn_type.

APPEND ls_toolbar TO e_object->mt_toolbar.

CLEAR ls_toolbar.

MOVE 'UPDATE' TO ls_toolbar-function.

  • MOVE ' ' TO ls_toolbar-icon.

MOVE text-108 TO ls_toolbar-quickinfo.

MOVE text-108 TO ls_toolbar-text.

MOVE ' ' TO ls_toolbar-disabled.

APPEND ls_toolbar TO e_object->mt_toolbar.

ENDMETHOD.

METHOD handle_user_command.

DATA: lt_rows TYPE lvc_t_row,

wa_rows TYPE lvc_s_row.

*Phase update

CASE e_ucomm.

WHEN 'UPDATE'.

CALL METHOD gcl_grid->get_selected_rows

IMPORTING et_index_rows = lt_rows.

CALL METHOD cl_gui_cfw=>flush.

CLEAR gt_draw.

LOOP AT lt_rows INTO wa_rows.

READ TABLE gt_header INTO wa_header INDEX wa_rows-index.

MOVE wa_header-dokar TO wa_draw-dokar.

MOVE wa_header-doknr TO wa_draw-doknr.

MOVE wa_header-dokvr TO wa_draw-dokvr.

MOVE wa_header-doktl TO wa_draw-doktl.

APPEND wa_draw TO gt_draw.

CLEAR wa_draw.

ENDLOOP.

CALL FUNCTION 'Z_PLM_UPDATE_PHASE'

TABLES

  • plm_doc =

tdraw = gt_draw

i_ret = gt_bapiret2

.

CALL METHOD gcl_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.

WHEN 'EDIT'.

PERFORM switch_edit_mode.

CALL METHOD gcl_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.

ENDCASE.

ENDMETHOD. "handle_user_command

METHOD check_npi_qty.

DATA : lv_npi_qty TYPE atwrt.

CALL METHOD pr_data_changed->get_cell_value

EXPORTING i_row_id = ps_npi_qty-row_id

i_fieldname = ps_npi_qty-fieldname

IMPORTING e_value = lv_npi_qty.

IF lv_npi_qty LT 0.

CALL METHOD pr_data_changed->add_protocol_entry

EXPORTING

i_msgid = 'ZPNR'

i_msgno = '026'

i_msgty = 'E'

i_msgv1 = lv_npi_qty

i_msgv2 = space

i_msgv3 = space

i_msgv4 = space

i_fieldname = ps_npi_qty-fieldname

i_row_id = ps_npi_qty-row_id.

v_error_in_data = 'X'.

EXIT. "Quanity is negative

ENDIF.

ENDMETHOD.

ENDCLASS.

<b>After ALV Display</b>

CALL METHOD gcl_grid->set_table_for_first_display

EXPORTING

i_structure_name = 'TY_HEADER'

is_variant = wa_disvariant

i_save = 'A'

is_layout = wa_layout

it_toolbar_excluding = gt_exclude

CHANGING

it_outtab = gt_header

it_fieldcatalog = gt_fieldcatalog

  • IT_SORT =

  • IT_FILTER =

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4

.

ENDIF.

CLEAR : gt_fieldcatalog,

gt_fieldcatalog[].

  • CALL METHOD gcl_grid->list_processing_events

  • EXPORTING i_event_name = 'PRINT_TOP_OF_PAGE'.

  • Optionally register ENTER to raise event DATA_CHANGED.

  • (Per default the user may check data by using the check icon).

CALL METHOD gcl_grid->register_edit_event

EXPORTING

i_event_id = cl_gui_alv_grid=>mc_evt_enter.

CREATE OBJECT w_event_rec.

  • SET HANDLER w_event_rec->handle_top_of_page FOR gcl_grid.

SET HANDLER w_event_rec->handle_data_changed FOR gcl_grid.

SET HANDLER w_event_rec->handle_double_click FOR gcl_grid.

SET HANDLER w_event_rec->hotspot_click FOR gcl_grid.

SET HANDLER w_event_rec->handle_user_command FOR gcl_grid.

SET HANDLER w_event_rec->handle_toolbar FOR gcl_grid.

CALL METHOD gcl_grid->set_toolbar_interactive.

CALL METHOD cl_gui_control=>set_focus EXPORTING control = gcl_grid.

Read only

0 Likes
2,025

Hi Can you give PBO and PAI ?

how exactly you are doing in the ALV output .

can you repeat the steps..

vijay

Read only

0 Likes
2,025

PROCESS BEFORE OUTPUT.

MODULE STATUS_9000.

*

PROCESS AFTER INPUT.

MODULE USER_COMMAND_9000.

MODULE status_9000 OUTPUT.

SET PF-STATUS 'ZRPL_NPI'.

SET TITLEBAR 'ZRPL_NPI'.

PERFORM f_firstalv_display.

ENDMODULE. " STATUS_9000 OUTPUT

CASE sy-ucomm.

WHEN 'BACK' OR 'CANCEL'.

IF NOT gt_chg IS INITIAL.

PERFORM confirm_changes.

ENDIF.

IF NOT gcl_custom_container IS INITIAL.

CALL METHOD gcl_custom_container->free.

ENDIF.

IF NOT dialogbox_container IS INITIAL.

CALL METHOD dialogbox_container->free.

CALL METHOD cl_gui_cfw=>flush.

ENDIF.

LEAVE TO SCREEN 0.

WHEN 'EXIT'.

IF NOT gcl_custom_container IS INITIAL.

CALL METHOD gcl_custom_container->free.

ENDIF.

IF NOT dialogbox_container IS INITIAL.

CALL METHOD dialogbox_container->free.

CALL METHOD cl_gui_cfw=>flush.

ENDIF.

LEAVE PROGRAM.

WHEN 'SAVE'.

PERFORM update_npi_qty.

CALL METHOD gcl_grid->set_ready_for_input

EXPORTING i_ready_for_input = 0.

ENDCASE.

ENDMODULE.

Read only

0 Likes
2,025
in PAI

you might be checking sy-ucomm.

case sy-ucomm.

when 'SAVE'.
<b>do some thing..
CALL METHOD gcl_grid2->refresh_table_display.</b> try here

when'BACK'.

when others.

endcase.
Read only

0 Likes
2,025

In this method add the code that is in BOLD. Does this help the problem?



  method handle_toolbar.
*In event handler method for event TOOLBAR: Append own functions
*by using event parameter E_OBJECT.

<b>    clear e_object->mt_toolbar.  refresh e_object->mt_toolbar.</b>

    data: ls_toolbar type stb_button,
    lv_object type char15.
    move 'EDIT' to ls_toolbar-function.
    move 'ICON_TOGGLE_DISPLAY_CHANGE' to ls_toolbar-icon.
    move text-112 to ls_toolbar-quickinfo.
    move text-111 to ls_toolbar-text.
    move ' ' to ls_toolbar-disabled.
    append ls_toolbar to e_object->mt_toolbar.

* Append a separator to normal toolbar

    clear ls_toolbar.
    move 3 to ls_toolbar-butn_type.
    append ls_toolbar to e_object->mt_toolbar.
    clear ls_toolbar.
    move 'UPDATE' to ls_toolbar-function.
* MOVE ' ' TO ls_toolbar-icon.
    move text-108 to ls_toolbar-quickinfo.
    move text-108 to ls_toolbar-text.
    move ' ' to ls_toolbar-disabled.
    append ls_toolbar to e_object->mt_toolbar.

  endmethod.


Regards,

Rich Heilman

Read only

0 Likes
2,025

In the SAVE I was executing PERFORM update_npi_qty.

and in the PERFORM update_npi_qty i was doing exactly same mentioned by you. But still I am getting double

EDIT and PHASE Button.

Read only

0 Likes
2,025

If I refresh it and after that i am getting only My Toolbars(Only EDIT and PHASE BUTTON).

After proessing the SAVE button program executing the EDIT Functionality Twice.

Read only

0 Likes
2,025

if you don't mind can you paste the whole code and after that you can remove...

i faced similar problem....

regards

vijay

Read only

0 Likes
2,025

Code Deleted

Message was edited by: Amandeep Singh

Read only

0 Likes
2,025

In the report I was just trying to put code

READ TABLE e_object->mt_toolbar INTO lv_object

WITH KEY function = 'EDIT'.

IF NOT sy-subrc EQ 0.

in method

METHOD handle_toolbar.

Append EDIT and UPDATE if those buttons are not in the toolbars.

Read only

0 Likes
2,025

yeah you can remove the code now..

i will find and let you know..

vijay

Read only

0 Likes
2,025
why can't you try in this way?

  METHOD HANDLE_TOOLBAR.
    DATA: LS_TOOLBAR  TYPE STB_BUTTON.
* append a separator to normal toolbar
    CLEAR LS_TOOLBAR.
    MOVE 3 TO LS_TOOLBAR-BUTN_TYPE.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
* append SAVE icon
    CLEAR LS_TOOLBAR.
    MOVE 'SAVE' TO LS_TOOLBAR-FUNCTION.
    MOVE ICON_SYSTEM_SAVE TO LS_TOOLBAR-ICON.
    MOVE 'Save' TO LS_TOOLBAR-QUICKINFO.
    MOVE '  Save  '  TO LS_TOOLBAR-TEXT.
    MOVE ' '  TO LS_TOOLBAR-DISABLED.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
    CLEAR LS_TOOLBAR.
* append a separator to normal toolbar
    CLEAR LS_TOOLBAR.
    MOVE 3 TO LS_TOOLBAR-BUTN_TYPE.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
* append BACK icon
    CLEAR LS_TOOLBAR.
    MOVE 'BACK' TO LS_TOOLBAR-FUNCTION.
    MOVE ICON_SYSTEM_BACK TO LS_TOOLBAR-ICON.
    MOVE 'Back' TO LS_TOOLBAR-QUICKINFO.
    MOVE ' Back '  TO LS_TOOLBAR-TEXT.
    MOVE ' '  TO LS_TOOLBAR-DISABLED.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
    CLEAR LS_TOOLBAR.
  ENDMETHOD.                    "handle_toolbar
Read only

0 Likes
2,025

i did in this way it is not repeating?

try to change the icons and place the code...

and check..

please remove the code , as it is very big.

vijay

Read only

0 Likes
2,025

Our Business user need the standard SAVE button to save the changed ALV data. I tried that , It is working.

Read only

0 Likes
2,025

you need not to check , you can directly do that..

try to implement the same way as i did, and check ...

regards

vijay

still you are facing the problem,..

please let me know..

Message was edited by: Vijay Babu Dudla

Read only

0 Likes
2,025

no aman,

what i am telling is instead of making buttons in other way try this way..

[code]  METHOD HANDLE_TOOLBAR.
    DATA: LS_TOOLBAR  TYPE STB_BUTTON.
* append a separator to normal toolbar
    CLEAR LS_TOOLBAR.
    MOVE 3 TO LS_TOOLBAR-BUTN_TYPE.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
* append SAVE icon
    CLEAR LS_TOOLBAR.
    MOVE 'EDIT' TO LS_TOOLBAR-FUNCTION.
    MOVE ICON_TOGGLE_DISPLAY_CHANGE TO LS_TOOLBAR-ICON.
    MOVE 'edit' TO LS_TOOLBAR-QUICKINFO.
    MOVE ' edit  '  TO LS_TOOLBAR-TEXT.
    MOVE ' '  TO LS_TOOLBAR-DISABLED.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
    CLEAR LS_TOOLBAR.
* append a separator to normal toolbar
    CLEAR LS_TOOLBAR.
    MOVE 3 TO LS_TOOLBAR-BUTN_TYPE.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
* append BACK icon
    CLEAR LS_TOOLBAR.
    MOVE 'UPDATE' TO LS_TOOLBAR-FUNCTION.
    MOVE ICON_SYSTEM_UPDATE TO LS_TOOLBAR-ICON.
    MOVE 'update' TO LS_TOOLBAR-QUICKINFO.
    MOVE ' update '  TO LS_TOOLBAR-TEXT.
    MOVE ' '  TO LS_TOOLBAR-DISABLED.
    APPEND LS_TOOLBAR TO E_OBJECT->MT_TOOLBAR.
    CLEAR LS_TOOLBAR.
  ENDMETHOD.                    "handle_toolbar

try to change your handle tool bar method..

and while handling save

in PAI

CALL METHOD CL_GUI_CFW=>FLUSH.

CALL METHOD CL_GUI_CFW=>DISPATCH.

case sy-ucomm.

when 'SAVE'.

do some thing....

call method g_gird->refresh...

endcase.

regards

vijay[/code]

Read only

Former Member
0 Likes
2,025

call the method refresh after the sy-ucomm check..

it will work well../.

regards

vijay