Showing posts with label Selection Screen. Show all posts
Showing posts with label Selection Screen. Show all posts

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.

Create a SELECT-OPTIONS in a module pool screen

Create a SELECT-OPTIONS in module pool screen using two methods as shown.

Method 1

a) Create a subscreen area in your screen layout where you want to create the select options.
b) In the top include of your module pool program declare a selection screen as a subscreen e.g.

1
2
3
4
5
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.

select-options s_matnr for mara-matnr.

SELECTION-SCREEN END OF SCREEN.

c) In the PBO and PAI of the main screen where the select options needs to be created do a call subscreen of the above screen (100).

CALL SUBCREEN sub_area INCLUDING <program> <screen>

This CALL SUBSCREEN statement is necessary for transport of values between screen and program.

Note: All validations of the selection screen fields e.g. the s_matnr field created above should be done in selection screen events like AT SELECTION-SCREEN etc and not in PAI. These selection screen validations etc should be done in the top include only.

Method 2

a) Create 2 separate fields in your screen layout - one for the low value and one for the high value. Insert an icon beside the high value which will call the multiple selections popup screen on user command. Use function module COMPLEX_SELECTIONS_DIALOG to achieve this.

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
struc_tab_and_field-fieldname = con_cust.  " 'KUNNR'
struc_tab_and_field-tablename = con_kna1. " 'KNA1'.

CALL FUNCTION 'COMPLEX_SELECTIONS_DIALOG'
EXPORTING
* TITLE = ' '
text = g_titl1 " 'Customers'
tab_and_field = struc_tab_and_field
TABLES
RANGE = rng_kunnr
EXCEPTIONS
NO_RANGE_TAB = 1
CANCELLED = 2
INTERNAL_ERROR = 3
INVALID_FIELDNAME = 4
OTHERS = 5.

IF NOT rng_kunnr[] IS INITIAL.

* Read the very first entry of the range table and pass it to
* dynpro screen field

READ TABLE rng_kunnr INDEX 1.
IF sy-subrc = 0.
g_cust = rng_kunnr-low.
ENDIF.
ENDIF.


You can use the return table rng_kunnr to populate your own internal range table with the values entered by the user. Basically here you are just simulating the work of a select-options parameter by module pool screen elements.

Get the entered value from a field on POV of another field using FM DYNP_VALUES_READ

Demo code on how to populate search help values dynamically depending upon values of another parameter on F4 button press. We have to use FM "DYNP_VALUES_READ".






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
*&---------------------------------------------------------------------*
*& Program : Z_TEST_PROGRAM
*& Created on : 23.07.2008 22:55:41
*&---------------------------------------------------------------------*
*& Test program for blog http://abap-explorer.blogspot.com/
*&---------------------------------------------------------------------*
REPORT z_test_program.

*Data Declaration
TYPES :
BEGIN OF x_spfli,
carrid TYPE s_carr_id,
connid TYPE s_conn_id,
END OF x_spfli.

DATA :
i_spfli TYPE STANDARD TABLE OF x_spfli INITIAL SIZE 0.
*Parameters
PARAMETERS:
p_carrid TYPE x_spfli-carrid OBLIGATORY,
p_connid TYPE x_spfli-connid.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_connid.

PERFORM sub_get_f4.

START-OF-SELECTION.

WRITE: / ' this is for testing'.
*&---------------------------------------------------------------------*
*& Form sub_get_f4
*&---------------------------------------------------------------------*
* Subroutine to populate F$ help
*----------------------------------------------------------------------*
FORM sub_get_f4 .
DATA:
l_i_dynpfields TYPE STANDARD TABLE OF dynpread INITIAL SIZE 0,
l_wa_dynpfields TYPE dynpread,
l_carrid TYPE s_carr_id.
*Populate the Parameter Name whoso value is required

l_wa_dynpfields-fieldname = 'P_CARRID'.
APPEND l_wa_dynpfields TO l_i_dynpfields.

*Call the FM to read that value
CALL FUNCTION 'DYNP_VALUES_READ'
EXPORTING
dyname = sy-repid
dynumb = sy-dynnr
* TRANSLATE_TO_UPPER = ' '
* REQUEST = ' '
* PERFORM_CONVERSION_EXITS = ' '
* PERFORM_INPUT_CONVERSION = ' '
* DETERMINE_LOOP_INDEX = ' '
TABLES
dynpfields = l_i_dynpfields
EXCEPTIONS
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
invalid_parameter = 7
undefind_error = 8
double_conversion = 9
stepl_not_found = 10
OTHERS = 11
.
IF sy-subrc = 0.
*Get the value
READ TABLE l_i_dynpfields INTO l_wa_dynpfields
WITH KEY fieldname = 'P_CARRID'.
IF sy-subrc = 0.
l_carrid = l_wa_dynpfields-fieldvalue.

SELECT
carrid " Airline Code
connid " Flight Connection Number
FROM spfli " Flight schedule
INTO TABLE i_spfli WHERE carrid = l_carrid.

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CONNID'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'P_CONNID'
value_org = 'S'
TABLES
value_tab = i_spfli.
ENDIF.
ENDIF.
ENDFORM. " sub_get_f4