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 toolbar button trouble

Former Member
0 Likes
697

Hy gurus i'm still fighting with my alv oo.

i'm managing my toolbar like this...

1)

CALL METHOD grid1->set_table_for_first_display
 ...
    CREATE OBJECT g_event_receiver.
    SET HANDLER g_event_receiver->handle_data_changed FOR grid1.
    SET HANDLER g_event_receiver->handle_toolbar FOR ALL INSTANCES.
    SET HANDLER g_event_receiver->handle_user_command FOR grid1.

    CALL METHOD grid1->register_edit_event
              EXPORTING
                 i_event_id = cl_gui_alv_grid=>mc_evt_enter.
*Toolbar
    CALL METHOD grid1->set_toolbar_interactive.

2)

PUBLIC SECTION.
    METHODS:
...
    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.
  METHOD handle_toolbar.
*si creano prima i pulsanti
*aggiunta di un  separator toolbar normale per i nostri pulsanti
...
    CLEAR gs_toolbar.
    MOVE 'REFR' TO gs_toolbar-function.
    MOVE 'Refresh' TO gs_toolbar-quickinfo.
    MOVE 0 TO gs_toolbar-butn_type.
    MOVE ' ' TO gs_toolbar-disabled.
    MOVE icon_detail TO gs_toolbar-icon.
    MOVE 'ELABORA' TO gs_toolbar-text.
    APPEND gs_toolbar TO e_object->mt_toolbar.
  ENDMETHOD.                                          "HANDLE_TOOLBAR

and finally

METHOD handle_user_command.
    PERFORM handle_user_command USING e_ucomm.
  ENDMETHOD.
...
FORM handle_user_command USING p_ucomm TYPE any.
  CASE p_ucomm.

    WHEN 'REFR'.
      CALL METHOD grid1->check_changed_data.
      PERFORM call_transaction.
  ENDCASE.
ENDFORM.
...
form call transaction
  DATA: l_valid TYPE c.
  CALL METHOD grid1->get_selected_rows
  IMPORTING
  et_index_rows = lt_rows[].
  DESCRIBE TABLE lt_rows LINES n.
  IF n = 0.
    MESSAGE w208 WITH text-001.
    CALL SCREEN 100.
  ELSEIF n > 1.
    MESSAGE w208 WITH text-001.
  ELSEIF n = 1.
    READ TABLE lt_rows INTO ls_rows INDEX 1.
    IF sy-subrc = 0.
      READ TABLE gt_outtab INTO ls_outtab INDEX ls_rows-index.
      IF sy-subrc EQ 0.
        CALL transaction 'CN21'.
        PERFORM refresh_table.
      ENDIF.
    ENDIF.
  ENDIF.

now here my trouble...

in the form call_transaction , i'm trying to obligate the user to use only one row with a warning message...

when i'm using in the user command the Save button, the warning is working perfectely but if i use the toolbar button,

the message is type E.

i don't understand why? is it due to type of button?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
631

Hi,

check out this wiki, it tells how to add button on toolbar using OOPS.

https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=60654876

Thanks,

Krishna

Hy gurus i'm still fighting with my alv oo.

i'm managing my toolbar like this...

1)

CALL METHOD grid1->set_table_for_first_display
 ...
    CREATE OBJECT g_event_receiver.
    SET HANDLER g_event_receiver->handle_data_changed FOR grid1.
    SET HANDLER g_event_receiver->handle_toolbar FOR ALL INSTANCES.
    SET HANDLER g_event_receiver->handle_user_command FOR grid1.

    CALL METHOD grid1->register_edit_event
              EXPORTING
                 i_event_id = cl_gui_alv_grid=>mc_evt_enter.
*Toolbar
    CALL METHOD grid1->set_toolbar_interactive.

2)

PUBLIC SECTION.
    METHODS:
...
    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.
  METHOD handle_toolbar.
*si creano prima i pulsanti
*aggiunta di un  separator toolbar normale per i nostri pulsanti
...
    CLEAR gs_toolbar.
    MOVE 'REFR' TO gs_toolbar-function.
    MOVE 'Refresh' TO gs_toolbar-quickinfo.
    MOVE 0 TO gs_toolbar-butn_type.
    MOVE ' ' TO gs_toolbar-disabled.
    MOVE icon_detail TO gs_toolbar-icon.
    MOVE 'ELABORA' TO gs_toolbar-text.
    APPEND gs_toolbar TO e_object->mt_toolbar.
  ENDMETHOD.                                          "HANDLE_TOOLBAR

and finally

METHOD handle_user_command.
    PERFORM handle_user_command USING e_ucomm.
  ENDMETHOD.
...
FORM handle_user_command USING p_ucomm TYPE any.
  CASE p_ucomm.

    WHEN 'REFR'.
      CALL METHOD grid1->check_changed_data.
      PERFORM call_transaction.
  ENDCASE.
ENDFORM.
...
form call transaction
  DATA: l_valid TYPE c.
  CALL METHOD grid1->get_selected_rows
  IMPORTING
  et_index_rows = lt_rows[].
  DESCRIBE TABLE lt_rows LINES n.
  IF n = 0.
    MESSAGE w208 WITH text-001.
    CALL SCREEN 100.
  ELSEIF n > 1.
    MESSAGE w208 WITH text-001.
  ELSEIF n = 1.
    READ TABLE lt_rows INTO ls_rows INDEX 1.
    IF sy-subrc = 0.
      READ TABLE gt_outtab INTO ls_outtab INDEX ls_rows-index.
      IF sy-subrc EQ 0.
        CALL transaction 'CN21'.
        PERFORM refresh_table.
      ENDIF.
    ENDIF.
  ENDIF.

now here my trouble...

in the form call_transaction , i'm trying to obligate the user to use only one row with a warning message...

when i'm using in the user command the Save button, the warning is working perfectely but if i use the toolbar button,

the message is type E.

i don't understand why? is it due to type of button?

4 REPLIES 4
Read only

sivasatyaprasad_yerra
Product and Topic Expert
Product and Topic Expert
0 Likes
631

Form Call_Transaction will only be called for the other button which is not part of ALV toolbar.

Form Call_Transaction will not be invoked when you click on ALV toolbar button. Please check the g_event_receiver->handle_user_command method implementation. Here I think you would have set message type as 'E'.

Regards,

Siva.

Read only

0 Likes
631

sorry, but i don't follow you,

in my method i never set the type of message.

METHOD handle_user_command. 
PERFORM handle_user_command USING e_ucomm. 
ENDMETHOD
FORM handle_user_command USING p_ucomm TYPE any. 
CASE p_ucomm.
 WHEN 'REFR'.
 CALL METHOD grid1->check_changed_data.
 PERFORM call_transaction.
 ENDCASE.
 ENDFORM.

and the call zransaction:

CALL METHOD grid1->get_selected_rows
 IMPORTING et_index_rows = lt_rows[].
 DESCRIBE TABLE lt_rows LINES n.
 IF n = 0. MESSAGE w208 WITH text-001.
 CALL SCREEN 100. ELSEIF n > 1.
 MESSAGE w208 WITH text-001. ELSEIF n = 1. 
READ TABLE lt_rows INTO ls_rows INDEX 1.
 IF sy-subrc = 0. 
READ TABLE gt_outtab INTO ls_outtab INDEX ls_rows-index. 
IF sy-subrc EQ 0.
 CALL transaction 'CN21'. 
PERFORM refresh_table.

Read only

uwe_schieferstein
Active Contributor
0 Likes
631

Hello

Basically the (GUI) design of your ALV list is wrong. If your ALV list allows for multiple selected rows then toolbar buttons will apply to all these selected rows. Thus, you have (at least) two options:

1) Allow single selection of rows only (need to change SEL_MODE in LVC_S_LAYO)
2) Replace the toolbar function by DOUBLE_CLICK event or context menu function (which is executed on a single row

Regards

Uwe

Read only

Former Member
0 Likes
632

Hi,

check out this wiki, it tells how to add button on toolbar using OOPS.

https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=60654876

Thanks,

Krishna