11-08-2006 8:20 PM
Hi, Experts
I can exclude some toolbar by passing the internal table lt_exclude when first calling the method as below:
call method g_grid->set_table_for_first_display
EXPORTING
it_toolbar_excluding = lt_exclude
CHANGING
it_fieldcatalog = pt_fieldcat
it_outtab = pt_outtab.
Now, my problem is after that, if I change lt_exclude table so as to change excluding toolbar in runtime, how can I do?
Thanks a lot.
Tom
11-08-2006 8:23 PM
Sorry, I might not say that clearly. My problem is after ALV is first displayed, in runtime, I want to change excluding toolbar, how can I do that?
Thanks.
11-08-2006 8:31 PM
11-09-2006 9:32 PM
Hello Rich
Here my reply to Toms request in another forum category:
Hello Tom
Of course you can change the toolbar dynamically. You have to call method grid->set_toolbar_interactive and an event handler method for event TOOLBAR.
The following sample (modified version of BCALV_GRID_DEMO) shows how to do (my coding is in bold):
[code]PROGRAM test.
DATA: ok_code LIKE sy-ucomm,
gt_sflight TYPE TABLE OF sflight,
g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
grid1 TYPE REF TO cl_gui_alv_grid,
g_custom_container TYPE REF TO cl_gui_custom_container.
----
CLASS lcl_eventhandler DEFINITION
----
*
----
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
md_cnt TYPE i.
CLASS-METHODS:
handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING
e_object
e_interactive
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
----
CLASS lcl_eventhandler IMPLEMENTATION
----
*
----
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_toolbar.
DATA:
ls_button TYPE stb_button.
ADD 1 TO md_cnt. " a simple counter
LOOP AT e_object->mt_toolbar INTO ls_button FROM 1 TO md_cnt.
ls_button-disabled = 'X'.
MODIFY e_object->mt_toolbar FROM ls_button.
ENDLOOP.
ENDMETHOD. "handle_toolbar
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
----
MAIN *
----
SELECT * FROM sflight INTO TABLE gt_sflight.
CALL SCREEN 100.
----
MODULE PBO OUTPUT *
----
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING container_name = g_container.
CREATE OBJECT grid1
EXPORTING i_parent = g_custom_container.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = gt_sflight.
*$Comment: Set event handler for event TOOLBAR
SET HANDLER:
lcl_eventhandler=>handle_toolbar FOR grid1.
ENDIF.
*$Comment: Toolbar can be modified on-the-fly
grid1->set_toolbar_interactive( ). " raises event TOOLBAR
ENDMODULE. "PBO OUTPUT
----
MODULE PAI INPUT *
----
MODULE pai INPUT.
to react on oi_custom_events:
CALL METHOD cl_gui_cfw=>dispatch.
CASE ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
WHEN OTHERS.
do nothing
ENDCASE.
CLEAR ok_code.
ENDMODULE. "PAI INPUT
----
FORM EXIT_PROGRAM *
----
FORM exit_program.
CALL METHOD G_CUSTOM_CONTAINER->FREE.
CALL METHOD CL_GUI_CFW=>FLUSH.
LEAVE PROGRAM.
ENDFORM. "EXIT_PROGRAM[/code]
When you run the program simply push several times the ENTER button. You will see how the buttons of the toolbar are inactivated one by one.
Regards
Uwe
11-09-2006 9:37 PM
11-09-2006 9:48 PM
Hello Rich
The two methods <b>SET_TOOLBAR_INTERACTIVE</b> and <b>CHECK_DATA_CHANGED</b> of the ALV grid control are somewhat special in the sense that they allow us to <b>explicitly</b> raise ALV grid events (TOOLBAR and DATA_CHANGED).
Regards
Uwe
11-13-2006 1:55 PM
Hi..
check this code.. to add the tools in the custom container output.. using events..
REPORT ZALV_OBJECT.
type-pools: icon.
--
class: lcl_event_receiver definition deferred.
data: dis_obj type ref to zalv_obj,
alv_dis type ref to cl_gui_alv_grid,
G_container type ref to cl_gui_custom_container,
GT_CONTAINER TYPE SCRFNAME VALUE 'ALVLIST',
event_receiver type ref to lcl_event_receiver.
DATA: OK_CODE TYPE SY-UCOMM,
g_repid like sy-repid,
x_save type c,
gs_layout type disvariant, "Layout (External Use)
gl_layout type lvc_s_layo. "ALV control: Layout structure
data: WA_TAB LIKE ZOB_TAB,
itab type ZOB_ITAB,
fcat type LVC_T_FCAT.
----
local class definition to handle events
----
class lcl_event_receiver definition.
public section.
methods: handle_toolbar for event toolbar
of cl_gui_alv_grid importing e_object,
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.
endclass.
----
local class implementation to handle events
----
class lcl_event_receiver implementation.
method handle_toolbar.
to add a buton in the standard toolbar of the custom control
data: ls_toolbar type stb_button, "Toolbar Button
ls_toolbar1 type stb_button.
*to add insert button.
clear ls_toolbar.
move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move ICON_EXECUTE_OBJECT to ls_toolbar-icon.
move 'INSERT' to ls_toolbar-function.
move 'move list to ztable' to ls_toolbar-quickinfo.
move 'Insert_values' to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
*to add edit button.
clear ls_toolbar1.
move 3 to ls_toolbar1-butn_type.
append ls_toolbar1 to e_object->mt_toolbar.
clear ls_toolbar1.
move ICON_TOGGLE_DISPLAY_CHANGE to ls_toolbar1-icon.
move 'EDIT' to ls_toolbar1-function.
move 'change contents in list' to ls_toolbar1-quickinfo.
move 'Edit' to ls_toolbar1-text.
move ' ' to ls_toolbar1-disabled.
append ls_toolbar1 to e_object->mt_toolbar.
clear ls_toolbar1.
endmethod.
*to trigge the action when the button is pressed
method handle_user_command.
*data gl1_layout type lvc_s_layo.
case e_ucomm.
*function insert
when 'INSERT'.
LOOP AT ITAB INTO WA_TAB.
INSERT INTO ZALV_TAB values wa_tab. " from wa_tab table itab.
ENDLOOP.
*function edit
when 'EDIT'.
perform editable.
endcase.
endmethod.
endclass.
*selection-screen
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETER: P_VBELN LIKE VBAP-VBELN.
selection-screen: END OF BLOCK B1.
start-of-selection.
create object dis_obj.
CALL METHOD DIS_OBJ->GET_METHOD
EXPORTING
SALE_DOC_NUM = p_vbeln
IMPORTING
ZITAB = itab.
end-of-selection.
clear gs_layout.
call screen 201.
&----
*& Module STATUS_0201 OUTPUT
&----
text
----
MODULE STATUS_0201 OUTPUT.
SET PF-STATUS 'ZSRN201'.
SET TITLEBAR 'xxx'.
if g_container is initial.
--
CREATE OBJECT G_CONTAINER
EXPORTING
CONTAINER_NAME = GT_CONTAINER
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5
others = 6.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
--
CREATE OBJECT ALV_DIS
EXPORTING
I_PARENT = G_CONTAINER
EXCEPTIONS
ERROR_CNTL_CREATE = 1
ERROR_CNTL_INIT = 2
ERROR_CNTL_LINK = 3
ERROR_DP_CREATE = 4
others = 5.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
--
PERFORM FIELDCAT CHANGING FCAT.
perform save_layout.
gl_layout-grid_title = 'sales document details'(100).
*gl_layout-edit = 'X'.
endif.
--
CALL METHOD ALV_DIS->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_VARIANT = gs_layout
I_SAVE = x_save
IS_LAYOUT = gl_layout
CHANGING
IT_OUTTAB = itab[]
IT_FIELDCATALOG = fcat
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.
*create object for event reference var
create object event_receiver.
*set the event to grid reference variable
set handler event_receiver->handle_toolbar for alv_dis.
set handler event_receiver->handle_user_command for alv_dis.
CALL METHOD ALV_DIS->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE =
I_SOFT_REFRESH =
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.
ENDMODULE. " STATUS_0201 OUTPUT
&----
*& Module USER_COMMAND_0201 INPUT
&----
text
----
MODULE USER_COMMAND_0201 INPUT.
*CALL METHOD CL_GUI_CFW=>DISPATCH.
CASE OK_CODE.
when 'EXIT'.
LEAVE PROGRAM.
when 'EXEC'.
LOOP AT ITAB INTO WA_TAB.
INSERT INTO ZALV_TAB values wa_tab. " from wa_tab table itab.
ENDLOOP.
when 'EDIT'.
perform editable.
ENDCASE.
CLEAR OK_CODE.
ENDMODULE. " USER_COMMAND_0201 INPUT
&----
*& Form save_layout
&----
text
----
--> p1 text
<-- p2 text
----
FORM save_layout .
x_save = 'A'.
g_repid = sy-repid.
gs_layout-report = g_repid.
ENDFORM. " save_layout
regards
kothai venkatasamy