You are on page 1of 13

Selection Screen in SAP

Selection Screen is the first interface for the users to interact with the
reports/transactions designed by developers. This is often the first component
which the developers design in the whole application. Truely, this is the first
impression which you can give your business or end users.

In this article, we have jotted down some of the common requirements in actual
projects and how we can achieve them. You can treat it as a reference
document.
1. Multiple Elements in a Selection Screen Line

Sometimes we have specific requirements while designing a selection screen.


We may have to place more than one Parameter (or Select Option or Radio
Button). This can be easily done by using the selection screen BEGIN OF LINE /
END OF LINE statements.
The following code extract will help you in designing such a selection screen.

1
2 DATA: l_field TYPE char10,
3 l_pos TYPE char4.
4
5 SELECTION-SCREEN BEGIN OF BLOCK out WITH FRAME TITLE text-s01.
6 * Line 1
7 SELECTION-SCREEN BEGIN OF LINE.
8 SELECTION-SCREEN COMMENT 5(15) nam1 FOR FIELD p_field1.
9 PARAMETERS: p_field1 LIKE l_field.
10 SELECTION-SCREEN COMMENT 45(15) nam2 FOR FIELD p_pos11.
11 PARAMETERS: p_pos11 LIKE l_pos.
12 SELECTION-SCREEN COMMENT 75(15) nam3 FOR FIELD p_pos12.
13 PARAMETERS: p_pos12 LIKE l_pos.
14 SELECTION-SCREEN END OF LINE.
15 SELECTION-SCREEN END OF BLOCK out.
16
17 AT SELECTION-SCREEN OUTPUT.
18 nam1 = 'Parameter'.
19 nam2 = 'Start Position'.
20 nam3 = 'End Position'.

Let’s check how the output looks.

Please note: Instead of Parameters, you can easily have other elements like
Radio Buttons or Select Options. The important thing here is that you need to
keep the correct spacing and position or else you can get a selection screen
generation error during activating the code, even if your code is syntactically
correct.
2. Restricting Range entry for Select-Option

Sometime it is required to restrict range input for a select option. SAP provides
an extension which is generally used for this is NO INTERVALS. But, is it
adequate?

1
2 SELECT-OPTIONS: mat FOR mara-matnr NO INTERVALS.

Apparently it seem that requirement is met but if someone presses Select


Ranges tab, user can enter the range.

1
2 **********************************************************************
3 * TYPE-POOLS:
4 **********************************************************************
5 TYPE-POOLS: sscr.
6 *----------------------------------------------------------------------*
7 *TABLES*
8 *----------------------------------------------------------------------*
9 TABLES: mara.
10 *----------------------------------------------------------------------*
11 *SELECTIONSCREEN*
12 *----------------------------------------------------------------------*
13 SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME.
14 SELECT-OPTIONS: mat FOR mara-matnr NO INTERVALS.
15 SELECT-OPTIONS: mtype FOR mara-mtart NO INTERVALS.
16 SELECTION-SCREEN: END OF BLOCK b2.

With just NO INTERVALS command. After pressing Select Ranges tab you can
enter range value.
How to really restrict the range? We need to use
FM ‘SELECT_OPTIONS_RESTRICT’ as shown below.

1
2 INITIALIZATION.
3
4 CONSTANTS: lc_opt_list TYPE rsrest_opl VALUE 'OPT_LIST',
5 lc_s TYPE rsscr_kind VALUE 'S',
6 lc_mat TYPE blockname VALUE 'MAT',
7 lc_inc TYPE c VALUE 'I'.
8
9 DATA: lw_opt_list TYPE sscr_opt_list,
10 lw_restrict TYPE sscr_restrict,
11 lw_ass TYPE sscr_ass.
12
13 lw_opt_list-name = lc_opt_list.
14 lw_opt_list-options-bt = space.
15 lw_opt_list-options-eq = 'X'.
16 APPEND lw_opt_list TO lw_restrict-opt_list_tab.
17
18 lw_ass-kind = lc_s.
19 lw_ass-name = lc_mat.
20 lw_ass-sg_main = lc_inc.
21 lw_ass-op_main = lc_opt_list.
22 APPEND lw_ass TO lw_restrict-ass_tab.
23
24 CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
25 EXPORTING
26 restriction = lw_restrict
27 EXCEPTIONS
28 too_late =1
29 repeated =2
30 selopt_without_options = 3
31 selopt_without_signs = 4
32 invalid_sign =5
33 empty_option_list =6
34 invalid_kind =7
35 repeated_kind_a =8
36 OTHERS = 9.
37
38

In addition to NO INTERVALS, after restricting with the function module, you


cannot enter range value now. This would be a robust solution.

There are other option available in this function module. Explore and enjoy
[adToAppearHere]

3. Select-Options in a module pool screen

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 SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
3 select-options s_matnr for mara-matnr.
4 SELECTION-SCREEN END OF SCREEN.

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

1
2 CALL SUBCREEN sub_area INCLUDING

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 struc_tab_and_field-fieldname = con_cust. ” ‘KUNNR’
3 struc_tab_and_field-tablename = con_kna1. ” ‘KNA1’.
4
5 CALL FUNCTION ‘COMPLEX_SELECTIONS_DIALOG’
6 EXPORTING
7 * TITLE = ‘ ‘
8 text = g_titl1 ” ‘Customers’
9 tab_and_field = struc_tab_and_field
10 TABLES
11 RANGE = rng_kunnr
12 EXCEPTIONS
13 NO_RANGE_TAB = 1
14 CANCELLED = 2
15 INTERNAL_ERROR = 3
16 INVALID_FIELDNAME = 4
17 OTHERS = 5.
18 IF NOT rng_kunnr[] IS INITIAL.
19 * Read the very first entry of the range table and pass it to
20 * dynpro screen field
21 READ TABLE rng_kunnr INDEX 1.
22 IF sy-subrc = 0.
23 g_cust = rng_kunnr-low.
24 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.

Also Read: ‘SY-ABCDE in SAP’

4. Displaying the Selection Screen value in report automatically

Value entered in the selection screen can be displayed automatically by the


function
modules ‘RS_REFRESH_FROM_SELECTOPTIONS’ and ‘RS_LIST_SELECTIO
N_TABLE’ is nice tabular fashion. Very helpful when the selection screen is
huge having a lot of parameters and select options.

1
2 *TABLES*
3 *----------------------------------------------------------------------*
4 TABLES: mara.
5 *----------------------------------------------------------------------*
6 *SELECTIONSCREEN*
7 *----------------------------------------------------------------------*
8 SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME.
9 SELECT-OPTIONS: mat FOR mara-matnr NO INTERVALS.
10 SELECT-OPTIONS: mtype FOR mara-mtart NO INTERVALS.
11 SELECTION-SCREEN: END OF BLOCK b2.
12
13 END-OF-SELECTION.
14 WRITE:/ 'Thank you for visiting SAPYard'.
15
16 TOP-OF-PAGE.
17 DATA: i_sel TYPE STANDARD TABLE OF rsparams INITIAL SIZE 0.
18 IF sy-pagno EQ 1.
19 * Call function for getting selection screen details
20 CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
21 EXPORTING
22 curr_report = sy-cprog
23 TABLES
24 selection_table = i_sel
25 EXCEPTIONS
26 not_found =1
27 no_report =2
28 OTHERS = 3.
29 IF sy-subrc <> 0.
30 WRITE:/ 'Fails to get the selection screen details'(201).
31 ENDIF.
32
33 * Displaying selection screen details
34 CALL FUNCTION 'RS_LIST_SELECTION_TABLE'
35 EXPORTING
36 report = sy-cprog
37 seltext = 'X'
38 screennr =''
39 TABLES
40 sel_tab = i_sel
41 EXCEPTIONS
42 sel_tab_empty = 1
43 OTHERS = 2.
44 IF sy-subrc <> 0.
45 WRITE:/ 'Fails to display the selection screen details'(202).
46 ENDIF.
47 ENDIF.

Check the image below. All the values of selection screen input are printed in
the report.
5. Dynamic Selection Screen

Selection screen is the first thing which user can see when he/she executes a
program or transaction. For basic need, we can create a selection screen only
by using ABAP commands and we do not have to go for a module pool
programming.

There are some extensions which can be used with select option to meet the
requirement.

Please check F1 for the extensions and their effects.

Sometime it is required to populate a default value in the selection screen.


There is an ABAP command which can be used for this.

Eg. SELECT-OPTIONS: matn FOR mara-matnr DEFAULT ‘AA’.

Sometimes the default value needs to be calculated at run-time. Use


INITIALIZATION Event or AT SELECTION-SCREEN OUTPUT Event.

Dynamic Selection Screen: You can activate a field or can disable input to a
certain field depending on some criteria at your will. The following code may
help you to make a dynamic screen. There are several other option in SCREEN
structure. Explore and you can impress some user by producing a flashy
selection screen. Remember selection screen is the first impression of your

program.

1
2 TABLES: mara.
3 *----------------------------------------------------------------------*
4 *SELECTIONSCREEN*
5 *----------------------------------------------------------------------
6 SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME.
7 PARAMETERS : mat RADIOBUTTON GROUP opt1 DEFAULT 'X' USER-COMMAND aa.
8 PARAMETERS : mtype RADIOBUTTON GROUP opt1.
9 SELECTION-SCREEN: END OF BLOCK b1.
10 SELECTION-SCREEN: BEGIN OF BLOCK b2.
11 SELECT-OPTIONS: matn FOR mara-matnr DEFAULT 'AA'
12 MODIF ID a.
13 SELECT-OPTIONS: mtypen FOR mara-mtart MODIF ID b.
14 SELECTION-SCREEN: END OF BLOCK b2.
15 *----------------------------------------------------------------------*
16 * AT S E L E C T I O N S C R E E N O U T P U T *
17 *----------------------------------------------------------------------
18 AT SELECTION-SCREEN OUTPUT.
19 LOOP AT SCREEN.
20 IF mat = 'X'.
21 IF screen-group1 = 'B'.
22 screen-input = 0.
23 ENDIF.
24 ELSE.
25 IF screen-group1 = 'A'.
26 screen-active = 0.
27 ENDIF.
28 ENDIF.
29 MODIFY SCREEN.
30 ENDLOOP.
6. Search Help from the values in Internal table

Sometimes the requirement is such that search help is required from the values
obtained at run time or from constant values. In such cases, you can use the FM
‘F4IF_INT_TABLE_VALUE_REQUEST‘ to meet your purpose. The basic logic
is that it uses data from the internal table to show in the F4 search help.

Example: Here an internal table is populated with some constants. This program
is just for concept.

1
2 * Type for internal table for populating the file-type
3 TYPES: BEGIN OF x_filtyp,
4 filetype TYPE char3, " File type
5 description TYPE char50, " description
6 END OF x_filtyp.
7 ***********************************************************************
8 * DATA *
9 ***********************************************************************
10 DATA:
11
12 * File type
13 i_filtyp TYPE STANDARD TABLE OF x_filtyp INITIAL SIZE 0,
14 wa_filtyp TYPE x_filtyp.
15
16 PARAMETERS: p_file(3) TYPE c.
17 ***********************************************************************
18 * INITIALIZATION *
19 ***********************************************************************
20 INITIALIZATION.
21 *Populating file type in an internal table
22 PERFORM sub_filtyp.
23 ***********************************************************************
24 * AT SELECTION-SCREEN *
25 ***********************************************************************
26 AT SELECTION-SCREEN.
27 * On value request for p_filtyp
28 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file .
29 PERFORM sub_get_help_filtyp USING p_file.
30 *&---------------------------------------------------------------------*
31 *& Form sub_filtyp
32 *&---------------------------------------------------------------------*
33 FORM sub_filtyp.
34 * local variables
35 DATA: l_wa_filtyp TYPE x_filtyp. "work area
36
37 * Appending row
38 l_wa_filtyp-filetype = 'A'.
39 l_wa_filtyp-description = 'Alphabet A'.
40 APPEND l_wa_filtyp TO i_filtyp.
41
42 * Appendng row
43 l_wa_filtyp-filetype = 'B'.
44 l_wa_filtyp-description = 'Alphabet B'.
45 APPEND l_wa_filtyp TO i_filtyp.
46
47 ENDFORM. "sub_filtyp
48 *&---------------------------------------------------------------------*
49 *& Form sub_get_help_filtyp
50 *&---------------------------------------------------------------------*
51 FORM sub_get_help_filtyp USING l_filtyp .
52 * local vairables
53
54 DATA: l_dynfld TYPE dynfnam, "Screen Field Name
55 l_retfld TYPE fieldname, "Return Field Name
56 l_i_fields TYPE STANDARD TABLE OF dfies, "for call function
57 l_i_return TYPE TABLE OF ddshretval, "for call function
58 l_wa_field TYPE dfies, "work area
59 l_wa_return TYPE ddshretval, "work
60 l_wa_value TYPE seahlpres,
61 l_i_value TYPE STANDARD TABLE OF seahlpres,
62 l_i_mapping TYPE STANDARD TABLE OF dselc,
63 l_wa_mapping TYPE dselc.
64
65 l_wa_mapping-fldname = 'DESCRIPTION'.
66 APPEND l_wa_mapping TO l_i_mapping.
67
68 l_wa_field-fieldname = 'FILETYPE'.
69 l_wa_field-tabname = 'I_FILTYP'.
70 l_wa_field-intlen = 6.
71 l_wa_field-leng = 6.
72 l_wa_field-outputlen = 6.
73 l_wa_field-position = 1 .
74 l_wa_field-scrtext_s = l_wa_field-fieldname.
75 l_wa_field-scrtext_m = l_wa_field-fieldname.
76 l_wa_field-scrtext_l = l_wa_field-fieldname.
77 l_wa_field-reptext = l_wa_field-fieldname.
78
79 APPEND l_wa_field TO l_i_fields.
80 CLEAR l_wa_field .
81
82 l_wa_field-fieldname = 'DESCRIPTION'.
83 l_wa_field-tabname = 'I_FILTYP'.
84 * l_wa_field-OFFSET = 3.
85 l_wa_field-intlen = 50.
86 l_wa_field-leng = 50.
87 l_wa_field-outputlen = 50.
88 l_wa_field-position = 2 .
89 l_wa_field-scrtext_s = l_wa_field-fieldname.
90 l_wa_field-scrtext_m = l_wa_field-fieldname.
91 l_wa_field-scrtext_l = l_wa_field-fieldname.
92 l_wa_field-reptext = l_wa_field-fieldname.
93
94 APPEND l_wa_field TO l_i_fields.
95
96 LOOP AT i_filtyp INTO wa_filtyp.
97 l_wa_value-string = wa_filtyp-filetype.
98 APPEND l_wa_value TO l_i_value.
99
100 l_wa_value-string = wa_filtyp-description.
101 APPEND l_wa_value TO l_i_value.
102 ENDLOOP.
103
104 l_retfld = 'FILETYPE'.
105 l_dynfld = l_filtyp.
106
107 * call fucntion for search help
108 CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
109 EXPORTING
110 retfield = l_retfld
111 dynpprog = sy-repid
112 dynpnr = sy-dynnr
113 dynprofield = l_dynfld
114 window_title = 'Filetype'
115 * value_org = 'S'
116 callback_program = sy-repid
117 TABLES
118 value_tab = l_i_value
119 field_tab = l_i_fields
120 return_tab = l_i_return
121 * dynpfld_mapping = l_i_mapping
122 EXCEPTIONS
123 parameter_error = 1
124 no_values_found = 2
125 OTHERS = 3.
126 IF sy-subrc EQ 0.
127 READ TABLE l_i_return INTO l_wa_return
128 WITH KEY fieldname = 'FILETYPE'.
129 IF sy-subrc EQ 0.
130 l_filtyp = l_wa_return-fieldval.
131 ENDIF.
132 ENDIF.
133 ENDFORM. " sub_get_help_filtyp

Check the Search Help is from our custom internal table. Isn’t it useful in real
projects?

If you want to get such practical issues and resolutions straight to your inbox,
please SUBSCRIBE. We respect your privacy and take protecting it seriously.

You might also like