OK, hier nun der Report. Ist eine Kopie von BCALV_GRID_05 unter 4.6c.
Das einzige was ich geändert habe, ist ein Selektionsparamter (zum Testen sollte dieser genügen).
Außerdem habe ich in der FORM exit_program "LEAVE PROGRAM' mit 'LEAVE TO SCREEN 0' ersetzt.
PROGRAM ZBCALV_GRID_05.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
* Purpose:
* ~~~~~~~~
* Demonstrate the creation of an own toolbar button.
*-----------------------------------------------------------------
* To check program behavior
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* The report shows a list of flights of one airline.
* Select one or more lines and press the 'Detail'-Button to popup
* a dialog window with related bookings.
*-------------------------------------------------------------------
* Essential steps (Search for '§')
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 1.Apply steps for event handling for events TOOLBAR and
* USER_COMMAND (see example for print events)
* 2.In event handler method for event TOOLBAR: Append own functions
* by using event parameter E_OBJECT.
* 3.In event handler method for event USER_COMMAND: Query your
* function codes defined in step 2 and react accordingly.
* 4.Call method 'set_toolbar_interactive' to raise event TOOLBAR.
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
INCLUDE <icon>.
*********
* Predefine a local class for event handling to allow the
* declaration of a reference variable before the class is defined.
CLASS lcl_event_receiver DEFINITION DEFERRED.
*
*********
DATA: ok_code LIKE sy-ucomm,
gt_sflight TYPE TABLE OF sflight,
gt_sbook TYPE TABLE OF sbook,
g_repid LIKE sy-repid,
g_max type i value 100,
gs_layout TYPE lvc_s_layo,
cont_on_main TYPE scrfname VALUE 'BCALVC_TOOLBAR_D100_C1',
cont_on_dialog TYPE scrfname VALUE 'BCALVC_TOOLBAR_D101_C1',
grid1 TYPE REF TO cl_gui_alv_grid,
grid2 TYPE REF TO cl_gui_alv_grid,
custom_container1 TYPE REF TO cl_gui_custom_container,
custom_container2 TYPE REF TO cl_gui_custom_container,
event_receiver TYPE REF TO lcl_event_receiver.
*Selektionsbild
parameters: p_box as checkbox.
* Set initial dynpro
SET SCREEN 100.
****************************************************************
* LOCAL CLASSES: Definition
****************************************************************
*===============================================================
* class lcl_event_receiver: local class to
* define and handle own functions.
*
* Definition:
* ~~~~~~~~~~~
CLASS lcl_event_receiver DEFINITION.
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.
PRIVATE SECTION.
ENDCLASS.
*
* lcl_event_receiver (Definition)
*===============================================================
****************************************************************
* LOCAL CLASSES: Implementation
****************************************************************
*===============================================================
* class lcl_event_receiver (Implementation)
*
*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
* § 2.In event handler method for event TOOLBAR: Append own functions
* by using event parameter E_OBJECT.
DATA: ls_toolbar TYPE stb_button.
*....................................................................
* E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET.
* This class has got one attribute, namly MT_TOOLBAR, which
* is a table of type TTB_BUTTON. One line of this table is
* defined by the Structure STB_BUTTON (see data deklaration above).
*
* A remark to the flag E_INTERACTIVE:
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* 'e_interactive' is set, if this event is raised due to
* the call of 'set_toolbar_interactive' by the user.
* You can distinguish this way if the event was raised
* by yourself or by ALV
* (e.g. in method 'refresh_table_display').
* An application of this feature is still unknown...
* 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 an icon to show booking table
CLEAR ls_toolbar.
MOVE 'BOOKINGS' TO ls_toolbar-function.
MOVE icon_employee TO ls_toolbar-icon.
MOVE 'Show Bookings'(111) TO ls_toolbar-quickinfo.
MOVE 'Detail'(112) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
*-------------------------------------------------------------------
METHOD handle_user_command.
* § 3.In event handler method for event USER_COMMAND: Query your
* function codes defined in step 2 and react accordingly.
DATA: lt_rows TYPE lvc_t_row.
CASE e_ucomm.
WHEN 'BOOKINGS'.
CALL METHOD grid1->get_selected_rows
IMPORTING et_index_rows = lt_rows.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc ne 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
else.
perform show_booking_table tables lt_rows.
ENDIF.
ENDCASE.
ENDMETHOD. "handle_user_command
*-----------------------------------------------------------------
ENDCLASS.
*
* lcl_event_receiver (Implementation)
*===================================================================
*---------------------------------------------------------------------*
* FORM EXIT_PROGRAM *
*---------------------------------------------------------------------*
FORM exit_program.
* The instance grid2 is freed not until the program exits from the
* main screen.
* (It is created only once during the first selection of SBOOK,
* no matter how many times the second window is called).
*
CALL METHOD custom_container1->free.
IF not custom_container2 is initial.
CALL METHOD custom_container2->free.
ENDIF.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc ne 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
ENDIF.
* LEAVE PROGRAM.
LEAVE TO SCREEN 0.
ENDFORM.
*&---------------------------------------------------------------------*
*& Module PBO_100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pbo_100 OUTPUT.
SET PF-STATUS 'MAIN100'.
g_repid = sy-repid.
IF custom_container1 is initial.
* select data from table SFLIGHT
PERFORM select_table_sflight CHANGING gt_sflight.
* create a custom container control for our ALV Control
CREATE OBJECT custom_container1
EXPORTING
container_name = cont_on_main
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc ne 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'The control could not be created'(510).
ENDIF.
* create an instance of alv control
CREATE OBJECT grid1
EXPORTING i_parent = custom_container1.
*
* Set a titlebar for the grid control
*
gs_layout-grid_title = 'Flights'(100).
* allow to select multiple lines
gs_layout-sel_mode = 'A'.
CALL METHOD grid1->set_table_for_first_display
EXPORTING i_structure_name = 'SFLIGHT'
is_layout = gs_layout
CHANGING it_outtab = gt_sflight.
********
* ->Create Object to receive events and link them to handler methods.
* When the ALV Control raises the event for the specified instance
* the corresponding method is automatically called.
*
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_user_command FOR grid1.
SET HANDLER event_receiver->handle_toolbar FOR grid1.
*
********
* § 4.Call method 'set_toolbar_interactive' to raise event TOOLBAR.
CALL METHOD grid1->set_toolbar_interactive.
ENDIF. "IF grid1 IS INITIAL
CALL METHOD cl_gui_control=>set_focus EXPORTING control = grid1.
ENDMODULE. " PBO_100 OUTPUT
*&---------------------------------------------------------------------*
*& Module PAI_100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pai_100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
ENDCASE.
CLEAR ok_code.
ENDMODULE. " PAI_100 INPUT
*&---------------------------------------------------------------------*
*& Module PBO_0101 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pbo_0101 OUTPUT.
IF custom_container2 is initial.
* (the data from sbook is already selected)
* create a custom container control for our ALV Control
CREATE OBJECT custom_container2
EXPORTING
container_name = cont_on_dialog
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc ne 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'The control could not be created'(510).
ENDIF.
* create an instance of alv control
CREATE OBJECT grid2
EXPORTING i_parent = custom_container2.
*
* change title
*
gs_layout-grid_title = 'Bookings'(101).
gs_layout-sel_mode = ' '.
CALL METHOD grid2->set_table_for_first_display
EXPORTING i_structure_name = 'SBOOK'
is_layout = gs_layout
CHANGING it_outtab = gt_sbook.
ELSE.
CALL METHOD grid2->refresh_table_display.
ENDIF. "IF custom_container2 IS INITIAL.
CALL METHOD cl_gui_control=>set_focus EXPORTING control = grid2.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc ne 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
ENDIF.
ENDMODULE. " PBO_0101 OUTPUT
*&---------------------------------------------------------------------*
*& Form SELECT_TABLE_SFLIGHT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_SFLIGHT text
*----------------------------------------------------------------------*
FORM select_table_sflight CHANGING p_gt_sflight LIKE gt_sflight[].
SELECT * FROM sflight INTO TABLE p_gt_sflight up to g_max rows.
ENDFORM. " SELECT_TABLE_SFLIGHT
*&---------------------------------------------------------------------*
*& Form SELECT_TABLE_SBOOK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LS_SFLIGHT text
* <--P_GT_SBOOK text
*----------------------------------------------------------------------*
FORM select_table_sbook USING p_ls_sflight LIKE LINE OF gt_sflight
CHANGING p_gt_sbook LIKE gt_sbook[].
DATA: lt_sbook LIKE gt_sbook[].
* Select data from sbook according to a line of sflight
* and append that data to table p_gt_sbook
*
SELECT * FROM sbook INTO TABLE lt_sbook
WHERE carrid = p_ls_sflight-carrid
AND connid = p_ls_sflight-connid
AND fldate = p_ls_sflight-fldate.
APPEND LINES OF lt_sbook TO p_gt_sbook.
ENDFORM. " SELECT_TABLE_SBOOK
*&---------------------------------------------------------------------*
*& Module PAI_0101 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pai_0101 INPUT.
CASE ok_code.
WHEN 'RETURN'.
LEAVE TO SCREEN 0.
ENDCASE.
CLEAR ok_code.
ENDMODULE. " PAI_0101 INPUT
*&---------------------------------------------------------------------*
*& Form show_booking_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ET_INDEX_ROWS text
*----------------------------------------------------------------------*
FORM show_booking_table TABLES p_et_index_rows
STRUCTURE lvc_s_row.
DATA: ls_selected_line LIKE lvc_s_row,
lf_row_index TYPE lvc_index,
ls_sflight LIKE LINE OF gt_sflight.
CLEAR gt_sbook[].
LOOP AT p_et_index_rows INTO ls_selected_line.
lf_row_index = ls_selected_line-index.
* read selected row from internal table gt_sflight
READ TABLE gt_sflight INDEX lf_row_index INTO ls_sflight.
* select corresponding lines of table sbook
* and append new lines to global table
PERFORM select_table_sbook USING ls_sflight
CHANGING gt_sbook.
ENDLOOP.
* call dialog screen and display new alv control
CALL SCREEN 101 STARTING AT 10 5.
ENDFORM. " show_booking_table