‎2008 Oct 24 3:29 PM
Hi,
I know how to create a button in an ALV list based on cl_salv_table.
The buttons created however are single buttons. I'm trying to create a button which can be expanded like the standardbuttons Export or Variants and include my own menu in this.
can this be done?
regards,
bert
‎2008 Oct 27 8:49 PM
Hi Bert,
Caution: I don't think the same screen container can be used for the menu button (cl_gui_alv_grid) and the ALV-OM output (cl_salv_table). Two separate containers could be used on screen 100, one for the menu button and one for the ALV-OM output, but I don't think that is an ideal solution. I'll keep trying, but for now have a look at my original reply. Maybe you or someone else out there can figure out another way.
This can indeed be done. To demonstrate, I created a skeleton program with just one custom button (with two menu items attached to it). As far as I can tell, this will only work for the ALV-OM grid option and not for the ALV-OM full screen option. Maybe the fullscreen option could be a challenge for someone else reading this reply.
I looked in programs BCALV_GRID_08 and SALV_TEST_FUNCTIONS and sort of morphed together the two concepts. Here are the steps to recreate my example:
Step 1: Create a new program (NOTE: In order to make the code as simple as possible for this forum reply, I removed the lines of code that actually output the SPLFI data. I figured seeing some test data would not be important for understanding the menu button in an ALV-OM.)
REPORT zjrg_alvom_demo_menu_button.
*----------------------------------------------------------------------*
* CLASS lcl_gui_alv_grid DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_gui_alv_grid DEFINITION INHERITING FROM cl_gui_alv_grid.
PUBLIC SECTION.
METHODS: set_toolbar_buttons_grid IMPORTING toolbar_table TYPE ttb_button.
ENDCLASS. "lcl_gui_alv_grid DEFINITION
* Global Data
DATA: ispfli TYPE TABLE OF spfli,
gr_table TYPE REF TO cl_salv_table,
gr_events TYPE REF TO cl_salv_events_table,
gr_alv_grid TYPE REF TO lcl_gui_alv_grid,
gr_container TYPE REF TO cl_gui_custom_container,
ok_code TYPE syucomm.
*----------------------------------------------------------------------*
* CLASS lcl_gui_alv_grid IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_gui_alv_grid IMPLEMENTATION.
METHOD set_toolbar_buttons_grid.
CALL METHOD me->set_toolbar_buttons
EXPORTING
toolbar_table = toolbar_table.
ENDMETHOD. "set_toolbar_buttons_grid
ENDCLASS. "lcl_gui_alv_grid IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS:
handle_menu_button
FOR EVENT menu_button OF cl_gui_alv_grid
IMPORTING e_object e_ucomm,
handle_menu_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_handle_events DEFINITION
DATA: event_handler TYPE REF TO lcl_handle_events.
START-OF-SELECTION.
SELECT * FROM spfli INTO TABLE ispfli.
IF ispfli[] IS INITIAL.
MESSAGE 'Nothing selected' TYPE 'I'.
EXIT.
ENDIF.
IF cl_salv_table=>is_offline( ) EQ if_salv_c_bool_sap=>false.
CREATE OBJECT gr_container
EXPORTING
container_name = 'CONTAINER'.
ENDIF.
TRY.
cl_salv_table=>factory(
EXPORTING
r_container = gr_container
container_name = 'CONTAINER'
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = ispfli ).
CATCH cx_salv_msg.
ENDTRY.
CREATE OBJECT gr_alv_grid EXPORTING i_parent = gr_container.
gr_events = gr_table->get_event( ).
CREATE OBJECT event_handler.
SET HANDLER: event_handler->handle_menu_button FOR gr_alv_grid,
event_handler->handle_menu_command FOR gr_alv_grid.
* Display the ALV-OM Grid
CALL SCREEN 100.
*----------------------------------------------------------------------*
* CLASS lcl_handle_events IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
METHOD handle_menu_button.
e_object->add_function( EXPORTING fcode = 'CANC'
text = 'Cancel').
e_object->add_function( EXPORTING fcode = 'EXIT'
text = 'Exit').
ENDMETHOD. "handle_menu_button
METHOD handle_menu_command.
CASE e_ucomm.
WHEN 'EXIT'.
MESSAGE 'Exit menu button option.' TYPE 'I'.
LEAVE TO SCREEN 0.
WHEN 'CANC'.
MESSAGE 'Cacnel menu button option.' TYPE 'I'.
ENDCASE.
ENDMETHOD. "handle_menu_command
ENDCLASS. "lcl_handle_events IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
DATA: it_toolbar TYPE ttb_button.
FIELD-SYMBOLS: <fs_toolbar> TYPE stb_button.
APPEND INITIAL LINE TO it_toolbar ASSIGNING <fs_toolbar>.
<fs_toolbar>-function = 'MENUB'.
<fs_toolbar>-butn_type = '1'.
<fs_toolbar>-text = 'Menu test'.
gr_alv_grid->set_toolbar_buttons_grid( it_toolbar ).
gr_table->display( ).
ENDMODULE. " STATUS_0100 OUTPUTStep 2: Create screen 100 for this program with a single custom control called CONTAINER and the following flow logic:
process before output.
module status_0100.
*
process after input.
*
Activate everything and run the program. You should see a single custom button for an empty ALV-OM Grid. This button has two menu items Cancel, and Exit. Hopefully, this example will give you an idea of how to use this concept in your own development. You can now use the normal ALV-OM methods to design the rest of your ALV grid output.
Best Regards,
Jamie
Edited by: James Gaddis on Oct 27, 2008 5:11 PM - Did not need code for event handle_toolbar, so I removed it from the program sample.
Edited by: James Gaddis on Oct 28, 2008 2:28 PM - Upon further review.... read first paragraph.
‎2008 Oct 27 8:49 PM
Hi Bert,
Caution: I don't think the same screen container can be used for the menu button (cl_gui_alv_grid) and the ALV-OM output (cl_salv_table). Two separate containers could be used on screen 100, one for the menu button and one for the ALV-OM output, but I don't think that is an ideal solution. I'll keep trying, but for now have a look at my original reply. Maybe you or someone else out there can figure out another way.
This can indeed be done. To demonstrate, I created a skeleton program with just one custom button (with two menu items attached to it). As far as I can tell, this will only work for the ALV-OM grid option and not for the ALV-OM full screen option. Maybe the fullscreen option could be a challenge for someone else reading this reply.
I looked in programs BCALV_GRID_08 and SALV_TEST_FUNCTIONS and sort of morphed together the two concepts. Here are the steps to recreate my example:
Step 1: Create a new program (NOTE: In order to make the code as simple as possible for this forum reply, I removed the lines of code that actually output the SPLFI data. I figured seeing some test data would not be important for understanding the menu button in an ALV-OM.)
REPORT zjrg_alvom_demo_menu_button.
*----------------------------------------------------------------------*
* CLASS lcl_gui_alv_grid DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_gui_alv_grid DEFINITION INHERITING FROM cl_gui_alv_grid.
PUBLIC SECTION.
METHODS: set_toolbar_buttons_grid IMPORTING toolbar_table TYPE ttb_button.
ENDCLASS. "lcl_gui_alv_grid DEFINITION
* Global Data
DATA: ispfli TYPE TABLE OF spfli,
gr_table TYPE REF TO cl_salv_table,
gr_events TYPE REF TO cl_salv_events_table,
gr_alv_grid TYPE REF TO lcl_gui_alv_grid,
gr_container TYPE REF TO cl_gui_custom_container,
ok_code TYPE syucomm.
*----------------------------------------------------------------------*
* CLASS lcl_gui_alv_grid IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_gui_alv_grid IMPLEMENTATION.
METHOD set_toolbar_buttons_grid.
CALL METHOD me->set_toolbar_buttons
EXPORTING
toolbar_table = toolbar_table.
ENDMETHOD. "set_toolbar_buttons_grid
ENDCLASS. "lcl_gui_alv_grid IMPLEMENTATION
*----------------------------------------------------------------------*
* CLASS lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS:
handle_menu_button
FOR EVENT menu_button OF cl_gui_alv_grid
IMPORTING e_object e_ucomm,
handle_menu_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_handle_events DEFINITION
DATA: event_handler TYPE REF TO lcl_handle_events.
START-OF-SELECTION.
SELECT * FROM spfli INTO TABLE ispfli.
IF ispfli[] IS INITIAL.
MESSAGE 'Nothing selected' TYPE 'I'.
EXIT.
ENDIF.
IF cl_salv_table=>is_offline( ) EQ if_salv_c_bool_sap=>false.
CREATE OBJECT gr_container
EXPORTING
container_name = 'CONTAINER'.
ENDIF.
TRY.
cl_salv_table=>factory(
EXPORTING
r_container = gr_container
container_name = 'CONTAINER'
IMPORTING
r_salv_table = gr_table
CHANGING
t_table = ispfli ).
CATCH cx_salv_msg.
ENDTRY.
CREATE OBJECT gr_alv_grid EXPORTING i_parent = gr_container.
gr_events = gr_table->get_event( ).
CREATE OBJECT event_handler.
SET HANDLER: event_handler->handle_menu_button FOR gr_alv_grid,
event_handler->handle_menu_command FOR gr_alv_grid.
* Display the ALV-OM Grid
CALL SCREEN 100.
*----------------------------------------------------------------------*
* CLASS lcl_handle_events IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
METHOD handle_menu_button.
e_object->add_function( EXPORTING fcode = 'CANC'
text = 'Cancel').
e_object->add_function( EXPORTING fcode = 'EXIT'
text = 'Exit').
ENDMETHOD. "handle_menu_button
METHOD handle_menu_command.
CASE e_ucomm.
WHEN 'EXIT'.
MESSAGE 'Exit menu button option.' TYPE 'I'.
LEAVE TO SCREEN 0.
WHEN 'CANC'.
MESSAGE 'Cacnel menu button option.' TYPE 'I'.
ENDCASE.
ENDMETHOD. "handle_menu_command
ENDCLASS. "lcl_handle_events IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
DATA: it_toolbar TYPE ttb_button.
FIELD-SYMBOLS: <fs_toolbar> TYPE stb_button.
APPEND INITIAL LINE TO it_toolbar ASSIGNING <fs_toolbar>.
<fs_toolbar>-function = 'MENUB'.
<fs_toolbar>-butn_type = '1'.
<fs_toolbar>-text = 'Menu test'.
gr_alv_grid->set_toolbar_buttons_grid( it_toolbar ).
gr_table->display( ).
ENDMODULE. " STATUS_0100 OUTPUTStep 2: Create screen 100 for this program with a single custom control called CONTAINER and the following flow logic:
process before output.
module status_0100.
*
process after input.
*
Activate everything and run the program. You should see a single custom button for an empty ALV-OM Grid. This button has two menu items Cancel, and Exit. Hopefully, this example will give you an idea of how to use this concept in your own development. You can now use the normal ALV-OM methods to design the rest of your ALV grid output.
Best Regards,
Jamie
Edited by: James Gaddis on Oct 27, 2008 5:11 PM - Did not need code for event handle_toolbar, so I removed it from the program sample.
Edited by: James Gaddis on Oct 28, 2008 2:28 PM - Upon further review.... read first paragraph.