Restrict Possible Selection Options and Signs of SELECT-OPTIONS

Function module SELECT_OPTIONS_RESTRICT can be used to restrict the number of selection options available for a select-option on selection screen.

The RESTRICTION parameter has 2 components.

Component Description
OPT_LIST_TAB This is a table of option lists
ASS_TAB This is a table in which you assign selection screen objects to option lists and permitted signs

OPT_LIST_TAB has following fields.

Field Description
NAME Freely-definable name for a list of valid options
OPTIONS Character fields of length 1 (for example, EQ, BT, …) for each of the 10 possible options

ASS_TAB has following fields.

Field

Possible Values
KIND

‘A’: The restrictions apply to all SELECT-OPTIONS. A(ll)
‘B’: Block on the selection screen. The restrictions apply to all SELECT-OPTIONS within the selection screen block specified in the field NAME B(lock)
‘S’: The restrictions apply to the single SELECT-OPTIONS specified in NAME S(elect-Option)

NAME

Where KIND = ‘B’ or ‘S’: Name of the object.B(lock), S(elect-Option)
Where KIND = ‘A’: Empty

SG_MAIN

‘*’: Do not restrict the sign on the main selection screen.
‘I’: Only sign ‘I’ allowed on the main selection screen.

OP_MAIN Name of the option list (from RESTRICTION-OPT_LIST_TAB) for the main selection screen.

Below is an example where we enable only Equals option and both Include and Exclude option of a particular select-option i.e S_MATNR.

*----------------------------------------------------------------------*
* TYPE-POOLS:
*----------------------------------------------------------------------*
TYPE-POOLS: sscr.
*----------------------------------------------------------------------*
* TABLES
*----------------------------------------------------------------------*
TABLES: mara.
*----------------------------------------------------------------------*
* Data Declaration
*----------------------------------------------------------------------*
DATA: gs_opt_list TYPE sscr_opt_list,
      gs_restrict TYPE sscr_restrict,
      gs_ass      TYPE sscr_ass.
*----------------------------------------------------------------------*
* SELECTION-SCREEN
*----------------------------------------------------------------------*
SELECT-OPTIONS: s_matnr FOR mara-matnr NO INTERVALS.
SELECT-OPTIONS: s_mtart FOR mara-mtart NO INTERVALS.
*---------------------------------------------------------------------*
* Initialization Event
*---------------------------------------------------------------------*
INITIALIZATION.
*Create an option list where only EQUALS is enabled
  gs_opt_list-name       = 'EXAMPLE1'.  " Any name
  gs_opt_list-options-eq = 'X'.         " Equals is enabled
  APPEND gs_opt_list TO gs_restrict-opt_list_tab.

*Apply the option list that has only Equals enabled to Select-option S_MATNR
  gs_ass-kind    = 'S'.       " Applicable to specific Select-option
  gs_ass-name    = 'S_MATNR'.
  gs_ass-sg_main = '*'.       " Both Include and Exclude options
  gs_ass-op_main = 'EXAMPLE1'.
  APPEND gs_ass TO gs_restrict-ass_tab.

  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
    EXPORTING
      restriction            = gs_restrict
    EXCEPTIONS
      too_late               = 1
      repeated               = 2
      selopt_without_options = 3
      selopt_without_signs   = 4
      invalid_sign           = 5
      empty_option_list      = 6
      invalid_kind           = 7
      repeated_kind_a        = 8
      OTHERS                 = 9.

Result

In the output, first click on S_MATNR select-option button and then click on the available options button as shown below. For S_MATNR select-option only EQUALS option and both INCLUDE and EXCLUDE options are enabled.

restrict-abap-select-options-1

Below is an example where we enable Equals and Not Equals options and only Include option of all select-options on the selection screen

*----------------------------------------------------------------------*
* TYPE-POOLS:
*----------------------------------------------------------------------*
TYPE-POOLS: sscr.
*----------------------------------------------------------------------*
* TABLES
*----------------------------------------------------------------------*
TABLES: mara.
*----------------------------------------------------------------------*
* Data Declaration
*----------------------------------------------------------------------*
DATA: gs_opt_list TYPE sscr_opt_list,
      gs_restrict TYPE sscr_restrict,
      gs_ass      TYPE sscr_ass.
*----------------------------------------------------------------------*
* SELECTION-SCREEN
*----------------------------------------------------------------------*
SELECT-OPTIONS: s_matnr FOR mara-matnr NO INTERVALS.
SELECT-OPTIONS: s_mtart FOR mara-mtart NO INTERVALS.
*---------------------------------------------------------------------*
* Initialization Event
*---------------------------------------------------------------------*
INITIALIZATION.
*Create an option list where EQUALS and NOT EQUALS are enabled
  gs_opt_list-name       = 'EXAMPLE1'.  " Any name
  gs_opt_list-options-eq = 'X'.         " Equals is enabled
  gs_opt_list-options-ne = 'X'.         " Not Equals is enabled
  APPEND gs_opt_list TO gs_restrict-opt_list_tab.

*Apply the option list that has only Equals enabled to Select-option S_MATNR
  gs_ass-kind    = 'A'.       " Applicable to ALL Select-options
  gs_ass-sg_main = 'I'.       " Only Include
  gs_ass-op_main = 'EXAMPLE1'.
  APPEND gs_ass TO gs_restrict-ass_tab.

  CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
    EXPORTING
      restriction            = gs_restrict
    EXCEPTIONS
      too_late               = 1
      repeated               = 2
      selopt_without_options = 3
      selopt_without_signs   = 4
      invalid_sign           = 5
      empty_option_list      = 6
      invalid_kind           = 7
      repeated_kind_a        = 8
      OTHERS                 = 9.

Result

In the output, first click on S_MTART select-option button and then click on the available options button as shown below. For all select-options both EQUALS and NOT EQUALS options and only INCLUDE option is enabled.

restrict-abap-select-options-2


1 Comment

Comments are closed.