Display an ALV in a Selection Screen

This program demonstrates how to display an ALV grid in the selection screen itself upon hitting "ENTER" button.

The Selection Screen:



The ALV (Upon hitting enter):



The ALV gets refreshed when new selection screen values are entered:



The code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
*&---------------------------------------------------------------------*
*& Report ZSB_ALV_SAME_SCREEN
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zsb_alv_same_screen.

DATA:
wa_sflight TYPE sflight,
i_sflight TYPE STANDARD TABLE OF sflight INITIAL SIZE 0,
oref_dock TYPE REF TO cl_gui_docking_container,
oref_alv TYPE REF TO cl_gui_alv_grid,
i_exclude TYPE TABLE OF syucomm.


SELECT-OPTIONS:
s_carrid FOR wa_sflight-carrid,
s_connid FOR wa_sflight-connid,
s_fldate FOR wa_sflight-fldate.

AT SELECTION-SCREEN OUTPUT.

APPEND 'ONLI' TO i_exclude.
APPEND 'SJOB' TO i_exclude.
APPEND 'PRIN' TO i_exclude.

CALL FUNCTION 'RS_SET_SELSCREEN_STATUS'
EXPORTING
p_status = sy-pfkey
p_program = sy-repid
TABLES
p_exclude = i_exclude.


AT SELECTION-SCREEN.
CHECK sy-ucomm = space.
SELECT * FROM sflight INTO TABLE i_sflight
WHERE carrid IN s_carrid
AND connid IN s_connid
AND fldate IN s_fldate.

IF sy-subrc = 0.

IF oref_dock IS NOT BOUND.

CREATE OBJECT oref_dock
EXPORTING
repid = sy-repid
dynnr = '1000'
side =
cl_gui_docking_container=>dock_at_bottom
ratio = 70
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.
ENDIF.
IF oref_alv IS NOT BOUND.

CHECK oref_dock IS BOUND.
CREATE OBJECT oref_alv
EXPORTING
i_parent = oref_dock
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.

CHECK oref_alv IS BOUND.

CALL METHOD oref_alv->set_table_for_first_display
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = i_sflight
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.
ELSE.

CALL METHOD oref_alv->refresh_table_display
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.

ENDIF.
ENDIF.