02-25-2009 7:38 PM
Hi there,
In a report type program I'm making, I have to show the data trough an ALV Control. I've decided to do it by the object oriented type.
So this is what I have. In the TOP INCLUDE, and in the main program:
CLASS lcl_receptor_eventos DEFINITION DEFERRED.
DATA: go_grid TYPE REF TO cl_gui_alv_grid,
go_cont TYPE REF TO cl_gui_custom_container,
go_context_menu TYPE REF TO cl_ctmenu,
go_event_receiver TYPE REF TO lcl_receptor_eventos.
CALL SCREEN 1400.
In another include for the local classes to be declared, I have declared the class who will receive the events. I have done this in order to set handlers later, in order to add a button to the ALV's toolbar:
CLASS lcl_receptor_eventos DEFINITION.
PUBLIC SECTION.
METHODS:
handle_menu_button
FOR EVENT menu_button OF cl_gui_alv_grid
IMPORTING e_ucomm e_object,
handle_toolbar_set
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 sender.
ENDCLASS. "lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
* CLASS lvl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_receptor_eventos IMPLEMENTATION.
METHOD handle_user_command.
CASE e_ucomm.
WHEN 'SUBT'.
gv_okcode = 'SUBT'.
ENDCASE.
ENDMETHOD.
* Here I will add the button
METHOD handle_toolbar_set.
DATA: gs_toolbar TYPE stb_button.
CLEAR gs_toolbar.
MOVE 'SUBT' TO gs_toolbar-function.
MOVE ICON_SUM TO gs_toolbar-icon.
MOVE 1 TO gs_toolbar-BUTN_TYPE.
MOVE 'Totales parciales' TO gs_toolbar-quickinfo.
MOVE ' ' TO gs_toolbar-disabled.
INSERT gs_toolbar INTO e_object->mt_toolbar INDEX 10.
CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = go_grid.
ENDMETHOD.
METHOD handle_menu_button.
IF e_ucomm = 'MBUT'.
CALL METHOD e_object->add_function
EXPORTING
fcode = 'SUBT'
text = text-105.
ENDIF.
ENDMETHOD.
ENDCLASS.
In the 1400 screen's PBO there is two modules. One of them instantiates the objects and sets the handlers for the events:
MODULE instanciar_objetos OUTPUT.
IF go_cont IS INITIAL.
CREATE OBJECT go_cont
EXPORTING
container_name = 'ALV_CONTAINER'.
CREATE OBJECT go_grid
EXPORTING
i_appl_events = 'X'
i_parent = go_cont.
CREATE OBJECT go_event_receiver.
SET HANDLER go_event_receiver->handle_toolbar_set FOR go_grid.
SET HANDLER go_event_receiver->handle_user_command FOR go_grid.
SET HANDLER go_event_receiver->handle_menu_button FOR go_grid.
PERFORM introducir_datos_en_grilla TABLES gt_salida.
PERFORM crear_tabla_dinamica.
ENDIF.
ENDMODULE.
The another one is to set the status and the main window toolbar, so it's not relevant right now. In the PAI there is a module who register the events, in order to the handlers to be called at the beginning of the PAI and the ok_code to be set.
module REGISTRAR_EVENTOS input.
DATA return_code TYPE i.
CALL METHOD cl_gui_cfw=>dispatch
IMPORTING
return_code = return_code.
endmodule.
So, here the question comes... I need, when the button I have added is pressed, to show a submenu beside it (exactly like the one that is shown when the standard sigma button in the ALV toolbar, I mean the sum button, is pressed). How can I do that??
02-26-2009 1:50 PM
Hi Jose,
Refer SAP standard prog BCALV_GRID_07 for yourreference.
Regards,
Pratik Vora
02-25-2009 8:00 PM
Hi Jose,
I think you have this already done here
METHOD handle_menu_button.
IF e_ucomm = 'MBUT'.
CALL METHOD e_object->add_function
EXPORTING
fcode = 'SUBT'
text = text-105.
ENDIF.
ENDMETHOD.
This method will be triggered each time you press the button with fcode MBUT, so the submenu will be added and shown. But what I am missing in your code is this in your instanciar_objetos module.
"reach toolbar event by using this method
CALL METHOD go_grid->set_toolbar_interactive.
Now all the events regarding toolbar (including new buttons and submenus for them) will be active.
Regards
Marcin
02-25-2009 8:41 PM
Hello Jose
Just a few remarks regarding OO-like programming:
I would recommend to make the entire initialization of the controls BEFORE you call your screen (for an example have a look at report ZUS_SDN_TWO_ALV_GRIDS_2SCR in thread )
I prefer to have screens with as little flow logic as possible (screens are there for displaying and not executing business logic)
For me the CALL SCREEN statement does not belong at all into a TOP include
Context menus can be created in two ways:
Using the static method LOAD_GUI_STATUS of CL_CTMENU (which loads a predefined gui status) => static
Adding a submenu function to an existing toolbar button => dynamic
Regards
Uwe
02-25-2009 9:06 PM
Let's see. I'll answer you both.
Marcin Pciak: I have given a try to your solution. I added the statement inside the instanciar_objetos module, and the things is, just after the method call, the program dumps.
I've seeing the error description screen and the error seems to be generated by the statement call method m_cl_menu_button_variant->clear, which is executed inside the toolbar_menus_init method. By seeing the statements that follows it, I can deduce the problem is that I have exluded some buttons from the toobar, by mean of the it_toolbar_excluding exporting parameter of the set_table_for_first_dislpay method.
The runtime error code is OBJECTS_OBJREF_NOT_ASSIGNED and the raised, uncaughted exception name is CX_SY_REF_IS_INITIAL.
Uwe Schieferstein:
- The CALL SCREEN statement is not in the TOP Include of my program. I have put it there in my message just for practicity.
- I will follow your recomendation about initialize the controls before the screen call.
- The flow logic in the screens is reduced to maximum, I can't make it smaller.
- Between the two ways you have stated of creating context menus, I obviusly choose the second one. So I don't get what you mean with that.
02-25-2009 9:29 PM
Jose,
Not sure if this will help but try first using set_table_for_first_dislpay, then (after setting the handlers) use
set_toolbar_interactive. Maybe as you said, it is a matter of excluding standard toolbar buttons, but I believe not. In case dump is still comming, try to skip excluding table and see the results.
Regards
Marcin
02-26-2009 4:51 AM
Hello Jose
You are right, I mixed things up.
The LOAD_GUI_STATUS method can be used for context menus on the list (and not for the ALV toolbar functions) to add a fixed context menu to a pre-existing one when the user triggers the event CONTEXT_MENU_REQUEST.
Regards
Uwe
02-26-2009 1:50 PM
Hi Jose,
Refer SAP standard prog BCALV_GRID_07 for yourreference.
Regards,
Pratik Vora