I want to develop the following logic:
The box "DISPLAY ALV
" corresponds to the function module REUSE_ALV_GRID_DISPLAY
.
With LEAVE TO SCREEN 0
I can't pass directly to DISPLAY ALV
. Is it possible?
Thank you.
No, you cannot return to FM, as you intend to do, 'cause FM is a special callable unit and LEAVE TO SCREEN
statement works only for screens. However, you can return to screen 100 which shows that ALV.
Consider following coding, for which you should have screens 100 and 300 with custom containers 100_CONT
and 300_CONT
on them.
Screen 100 PBO
MODULE pbo_100 OUTPUT.
SET PF-STATUS 'YOUR_PF_STATUS'.
IF custom_container1 IS INITIAL.
SELECT *
FROM mara AS m
INTO TABLE gt_mara
WHERE EXISTS ( SELECT * FROM vbrp WHERE matnr = m~matnr ).
CREATE OBJECT custom_container1
EXPORTING
container_name = cont_on_main.
CREATE OBJECT grid1
EXPORTING
i_parent = custom_container1.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'mara'
is_layout = gs_layout
CHANGING
it_outtab = gt_mara.
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_double_click FOR grid1.
ENDIF.
ENDMODULE. " PBO_100 OUTPUT
Screen 300 PBO
MODULE pbo_0300 OUTPUT.
IF custom_container2 IS INITIAL.
CREATE OBJECT custom_container2
EXPORTING
container_name = cont_on_dialog.
CREATE OBJECT grid2
EXPORTING
i_parent = custom_container2.
gs_layout-grid_title = 'Orders'.
CALL METHOD grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'VBRP'
is_layout = gs_layout
CHANGING
it_outtab = gt_vbrp.
ELSE.
CALL METHOD grid2->refresh_table_display.
ENDIF.
ENDMODULE. " PBO_0300 OUTPUT
Screen 300 PAI
MODULE pai_0300 INPUT.
CASE ok_code.
WHEN 'RETURN'.
DATA: ans.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'SO sample'
text_question = 'Select next action'
text_button_1 = 'Yes'
icon_button_1 = 'ICON_CHECKED'
text_button_2 = 'No'
icon_button_2 = 'ICON_CANCEL'
display_cancel_button = ' '
IMPORTING
answer = ans.
CASE ans.
WHEN 1.
LEAVE TO SCREEN 0.
WHEN 2.
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.
ENDCASE.
CLEAR ok_code.
ENDMODULE.
Main program
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA: ok_code LIKE sy-ucomm,
gt_mara TYPE TABLE OF mara,
gt_vbrp TYPE TABLE OF vbrp,
grid1 TYPE REF TO cl_gui_alv_grid,
grid2 TYPE REF TO cl_gui_alv_grid,
cont_on_main TYPE scrfname VALUE '100_CONT',
cont_on_dialog TYPE scrfname VALUE '300_CONT',
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.
START-OF-SELECTION.
CALL SCREEN 100.
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS: handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column.
ENDCLASS.
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_double_click.
READ TABLE gt_mara INDEX e_row-index ASSIGNING FIELD-SYMBOL(<fs_mara>).
SELECT *
INTO TABLE gt_vbrp
FROM vbrp
WHERE matnr = <fs_mara>-matnr.
CALL SCREEN 300 STARTING AT 10 5.
ENDMETHOD.
ENDCLASS.
Here at program start we fetch material list with sales orders in the system, and then on double click on screen 100 these orders are showed in screen 300.
By special button with function code RETURN
(you should place it on screen 300) we call popup window for interaction with user. By pressing Yes it returns to the initial screen 100, by pressing No the program is interrupted completely.
Here you should pay attention to statement LEAVE TO SCREEN 0
which terminates current dynpro sequence (i.e. 300) and thus returns to 100.