| Subject/Additions | Notes | Code Snippet |
|
Type specification options Additions `TYPE` and `LIKE` |
- You can specify data types for parameters similar to `DATA` statements. - This includes the `TYPE` and `LIKE` additions. Types requiring a length specification use the `TYPE ... LENGTH ...` additions. - Regarding the type `c`, there are syntax variants to specify the length and the type itself (such as leaving out the explicit type or length specification; length specification in parentheses). - Note that without the `LOWER CASE` addition, inserted character-like values are transformed to uppercase. - For type `p`, you can specify the `DECIMALS` addition. | ``` abap PROGRAM. "TYPE addition "The example uses a built-in ABAP type "Note the LOWER CASE addition further down. PARAMETERS p_str TYPE string. "LIKE addition "Referring to an existing data object DATA some_number TYPE i. PARAMETERS p_num LIKE some_number. "TYPE ... LENGTH for types that require a length specification "such as c, n, p, and x PARAMETERS p_clen10 TYPE c LENGTH 10. PARAMETERS p_nlen5 TYPE n LENGTH 5. "Length specification variants "The length can be specified in parentheses, however, specifying LENGTH "explicitly is recommended for better readability. PARAMETERS p_lenpar(3) TYPE c. "No length specified means LENGTH 1 by default PARAMETERS p_wo_len TYPE c. "No explicit type specification means TYPE c by default PARAMETERS p_wo_c_a(20). PARAMETERS p_wo_c_b LENGTH 20. "No explicit type and length specification means TYPE c LENGTH 1 by default PARAMETERS p_woclen. START-OF-SELECTION. WRITE / `Inserted values (note that inserted characters are capitalized):`. SKIP. WRITE / |p_str: "{ p_str }"|. WRITE / |p_num: "{ p_num }"|. WRITE / |p_clen10: "{ p_clen10 }"|. WRITE / |p_nlen5: "{ p_nlen5 }"|. WRITE / |p_lenpar: "{ p_lenpar }"|. WRITE / |p_wo_len: "{ p_wo_len }"|. WRITE / |p_wo_c_a: "{ p_wo_c_a }"|. WRITE / |p_wo_c_b: "{ p_wo_c_b }"|. WRITE / |p_woclen: "{ p_woclen }"|. ``` |
| Parameters using ABAP Dicitionary input helps | - When referring to data types from the ABAP Dictionary, all screen-relvant properties of that type are adopted. - If the referred type includes input help functionality, a callable field help is automatically created. - The input helps inlcude search helps, check tables, fixed values and calendar/clock helps. Find more information [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_dynpros_value_help_auto.htm). - Note that there is no automatic value check. For that, use the `VALUE CHECK` addition. - The code snippet includes input helps from a DDIC structure of an ABAP Keyword Documentation example. | ``` abap PROGRAM. "carrier1 is based on DDIC data element demof4de, which has the search help "demo_f4_de assigned PARAMETERS p_carr1 TYPE demof4help-carrier1. "carrier2 is assigned to check table scarr, which is assigned to the "search help h_scarr PARAMETERS p_carr2 TYPE demof4help-carrier2. "DDIC data element that has the search help s_carrier_id assigned PARAMETERS p_carr3 TYPE s_carr_id. "connid is assigned to the search help demo_f4_field PARAMETERS p_connid TYPE demof4help-connid. "Component of demo database table that specifies a foreign key PARAMETERS p_plane TYPE sflight-planetype. "Fixed values as input help PARAMETERS p_num TYPE demo_numbers. "ABAP Dictionary types such as DATS and TIMS have "a predefined input help (calendar and clock). PARAMETERS p_dats TYPE dats. PARAMETERS p_tims TYPE tims. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |p_carr1: "{ p_carr1 }"|. WRITE / |p_carr2: "{ p_carr2 }"|. WRITE / |p_carr3: "{ p_carr3 }"|. WRITE / |p_connid: "{ p_connid }"|. WRITE / |p_plane: "{ p_plane }"|. WRITE / |p_num: "{ p_num }"|. WRITE / |p_dats: "{ p_dats }"|. WRITE / |p_tims: "{ p_tims }"|. ``` |
|
Dynamically specifying the type Addition `LIKE (...)` |
- The dynamic specification works with `LIKE` followed by a data object name in parentheses. - As name, a character-like data object that contains the name of a structure component in the ABAP Dictionary in uppercase letters. - The parameter is then of type `c` length 132, however, the properties such as length and input help are taken from the type specified in parentheses. | ``` abap PROGRAM. "In the example, the currently loaded text pool does not contain a selection text "for the parameters. Here, the output field displays the field label from the "ABAP Dictionary. DATA some_dobj TYPE c LENGTH 30. PARAMETERS p_dyn1 LIKE (some_dobj). DATA comp TYPE c LENGTH 20. PARAMETERS p_dyn2 LIKE (comp). "Parameter on the screen with type c length 132 "Here, no selection text is created for the example, and no field "label field can be referred to. The output field displays the text "'Dynamic Parameter'. DATA another_dobj like some_dobj. PARAMETERS p_dyn3 LIKE (another_dobj). "Text field literal, however, its content is not evaluated. "Also here, the parameter on the screen is of type "c length 132. PARAMETERS p_dyn4 LIKE ('SPFLI-CARRID'). INITIALIZATION. some_dobj = 'SPFLI-CARRID'. comp = 'SFLIGHT-PLANETYPE'. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |p_dyn1: "{ p_dyn1 }"|. WRITE / |p_dyn2: "{ p_dyn2 }"|. WRITE / |p_dyn3: "{ p_dyn3 }"|. WRITE / |p_dyn4: "{ p_dyn4 }"|. ``` |
|
Specifying value options Additions `DEFAULT`, `LOWER CASE`, `MATCHCODE OBJECT`, `MEMORY ID`, `VALUE CHECK` |
- `DEFAULT`: Defines a start value (can also be a data object instead of a literal) - `LOWER CASE`: Prevents the effect of capitalizing the entry made when the content is transported to the data object - `MATCHCODE OBJECT`: Links an input field with a DDIC search help - `MEMORY ID`: Links an input field with an SPA/GPA parameter in the user memory, i.e. data objects in the user memory accessible by ABAP programs. When calling the selection screen, the input field receives the SPA/GPA parameter value if the `PARAMETERS`'s data object is initial after processing of the `AT SELECTION-SCREEN OUTPUT` event block. The SPA/GPA parameters are set using [`SET PARAMETER`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapset_parameter.htm) and read using [`GET PARAMETER`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapget_parameter.htm) statements. See the names of the parameters in the `TPARA` database table. - `VALUE CHECK`: Checks input against fixed values defined for the domain of a data type. It can only be used for DDIC data types. Checks are also available for data types being components of foreign key tables. It is recommended to specify the `VALUE CHECK` addition with the `OBLIGATORY` addition as the check is also applied in case of empty input fields. | ``` abap PROGRAM. *&---------------------------------------------------------------------* *& DEFAULT addition *&---------------------------------------------------------------------* PARAMETERS p_deflti TYPE i DEFAULT 12345. PARAMETERS p_deflts TYPE string DEFAULT `This is some demo text`. *&---------------------------------------------------------------------* *& LOWER CASE addition *&---------------------------------------------------------------------* PARAMETERS p_upper TYPE string DEFAULT `Hello World`. PARAMETERS p_lower TYPE string DEFAULT `Hello World` LOWER CASE. *&---------------------------------------------------------------------* *& MATCHCODE OBJECT addition *&---------------------------------------------------------------------* "The following example uses a search help of an ABAP Keyword Documentation example. PARAMETERS p_carr1 TYPE s_carr_id MATCHCODE OBJECT demo_f4_de. "Another predelivered demo search help. PARAMETERS p_carr2 TYPE c LENGTH 3 MATCHCODE OBJECT s_carrier_id. "Non-existent search help (triggers a message in the status line) PARAMETERS p_nope TYPE s_carr_id MATCHCODE OBJECT demo_f4_de###. *&---------------------------------------------------------------------* *& MEMORY ID addition *&---------------------------------------------------------------------* "The example use the memory id 'rid' that stores the name of the program "processed last. The demo explicitly sets the value to a dummy program "name in the AT SELECTION-SCREEN OUTPUT event block using a SET PARAMETER ID "statement. PARAMETERS p_prog TYPE sy-repid MEMORY ID rid. *&---------------------------------------------------------------------* *& VALUE CHECK addition *&---------------------------------------------------------------------* "The example selection parameters are specified with reference to a "demo database table field for which the check table scarr is specified. "So, you can only enter values that are also contained in scarr. "When running the example program, you can ... "- make entries that are not contained in the list and execute the program " to demonstrate that the value check is applied. "- leave the input for pvalchk1 empty to demonstrate that the value check is " also applied on empty fields. Therefore, also specifying the OBLIGATORY " addition is recommended. PARAMETERS pvalchk1 TYPE spfli-carrid VALUE CHECK. PARAMETERS pvalchk2 TYPE spfli-carrid VALUE CHECK OBLIGATORY. AT SELECTION-SCREEN OUTPUT. SET PARAMETER ID 'RID' FIELD 'SOME_TEST_REPORT'. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |p_deflti: "{ p_deflti }"|. WRITE / |p_deflts: "{ p_deflts }"|. WRITE / |p_upper: "{ p_upper }"|. WRITE / |p_lower: "{ p_lower }"|. WRITE / |p_carr1: "{ p_carr1 }"|. WRITE / |p_nope: "{ p_nope }"|. WRITE / |p_prog: "{ p_prog }"|. WRITE / |pvalchk1: "{ pvalchk1 }"|. WRITE / |pvalchk2: "{ pvalchk2 }"|. ``` |
|
Specifying screen options Additions `OBLIGATORY`, `NO-DISPLAY`, `VISIBLE LENGTH`, `AS CHECKBOX`, `RADIOBUTTON GROUP`, `AS LISTBOX VISIBLE LENGTH` |
- `OBLIGATORY`: Declares the input field as a required field. If there is no entry, the program cannot proceed when choosing *Execute*. A message will be displayed.
- `NO-DISPLAY`: Hides the input field on the selection screen. A value can be supplied when calling the program with `SUBMIT` and the `WITH` addition. Note that with the `NO-DISPLAY` addition, the parameter can have any data types except for reference/enumerated types, unlike in the other additions which require flat types (except type `string`).
- `VISIBLE LENGTH`: Defines the visible length of the field. If you specify the parameter with type `c` and length 10, and you specify the visible length as 3, the input field size is reduced accordingly, but you can still insert 10 characters.
- `AS CHECKBOX`: Displays an input field as checkbox. Type `c` and length 1 is expected, but the explicit length specification is not allowed. The checkbox is selected if the value has the value `X` or `x`.
- `RADIOBUTTON GROUP`: Defines a radio button group for parameters. Note:
- The group name can have a maximum of four characters.
- Regarding the data type, the same applies as for `AS CHECKBOX`.
- Only one parameter can be defined with the `DEFAULT` addition.
- If `DEFAULT` is not specified, the first parameter of the group is set to the value `X`.
- `AS LISTBOX VISIBLE LENGTH`: Creates a dropdown list box. You can use the function module `VRM_SET_VALUES` by passing a suitable list at the
`AT SELECTION-SCREEN OUTPUT` or `AT SELECTION-SCREEN ON VALUE-REQUEST` events. You may want to specify the `OBLIGATORY` addition here, too, as the check is also applied to empty fields.
> **💡 Note** > The `USER-COMMAND` addition can be specified together with `AS CHECKBOX`, `RADIOBUTTON GROUP` and `AS LISTBOX VISIBLE LENGTH` to assign a function code to the selection parameter. |
``` abap PROGRAM. *&---------------------------------------------------------------------* *& OBLIGATORY addition *&---------------------------------------------------------------------* PARAMETERS p_oblgty TYPE c LENGTH 10 OBLIGATORY. *&---------------------------------------------------------------------* *& NO-DISPLAY addition *&---------------------------------------------------------------------* PARAMETERS p_hidden TYPE c LENGTH 10 NO-DISPLAY. "With NO-DISPLAY, also complex types (except reference types) can be "specified. PARAMETERS p_tabtyp TYPE string_table NO-DISPLAY. *&---------------------------------------------------------------------* *& VISIBLE LENGTH addition *&---------------------------------------------------------------------* PARAMETERS p_vislen TYPE c LENGTH 10 VISIBLE LENGTH 3. *&---------------------------------------------------------------------* *& AS CHECKBOX addition *&---------------------------------------------------------------------* "Implicit type c PARAMETERS p_chkbx1 AS CHECKBOX. "Explicit type specification (but no explicit length) PARAMETERS p_chkbx2 TYPE c AS CHECKBOX. *&---------------------------------------------------------------------* *& RADIOBUTTON GROUP addition *&---------------------------------------------------------------------* "The following example uses a chained statement. PARAMETERS: p_rb1a RADIOBUTTON GROUP rbg1, p_rb1b TYPE c RADIOBUTTON GROUP rbg1, "Explicit type specification p_rb1c RADIOBUTTON GROUP rbg1 DEFAULT 'X'. "Select this radiobutton by default "Separate specifications, no DEFAULT specification "Here, the first radio button is selected by default. PARAMETERS p_rb2a RADIOBUTTON GROUP rbg2. PARAMETERS p_rb2b RADIOBUTTON GROUP rbg2. PARAMETERS p_rb2c RADIOBUTTON GROUP rbg2. PARAMETERS p_rb2d RADIOBUTTON GROUP rbg2. *&---------------------------------------------------------------------* *& AS LISTBOX VISIBLE LENGTH *&---------------------------------------------------------------------* "See the implementation in the AT SELECTION-SCREEN OUTPUT event block PARAMETERS plistbox TYPE i AS LISTBOX VISIBLE LENGTH 10 OBLIGATORY. AT SELECTION-SCREEN OUTPUT. "The following implementation is relevant for the AS LISTBOX VISIBLE LENGTH "addition. Note: "- The function module VRM_SET_VALUES is used. "- Column TEXT: What is displayed in the list box. "- Colum KEY: When a line is selected, the KEY value is added to the parameter "- In the example, the numbers 1 - 10 are added as values. CALL FUNCTION 'VRM_SET_VALUES' EXPORTING id = CONV vrm_id( 'PLISTBOX' ) values = VALUE vrm_values( FOR i = 1 UNTIL i > 10 ( key = i text = |Value { i }| ) ). "Filling the string table for the NO-DISPLAY example statement. p_tabtyp = VALUE #( ( `Some` ) ( `demo` ) ( `strings` ) ). START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |p_oblgty: "{ p_oblgty }"|. WRITE / |p_hidden: "{ p_hidden }"|. LOOP AT p_tabtyp into data(wa). WRITE / |p_tabtyp (line { sy-tabix }): "{ wa }"|. endloop. IF p_chkbx1 IS INITIAL. WRITE / `Checkbox p_chkbx1 was not selected.`. ELSE. WRITE / `Checkbox p_chkbx1 was selected.`. ENDIF. IF p_chkbx2 IS INITIAL. WRITE / `Checkbox p_chkbx2 was not selected.`. ELSE. WRITE / `Checkbox p_chkbx2 was selected.`. ENDIF. WRITE / |Radio button rbg1 selection: "{ COND #( WHEN p_rb1a IS NOT INITIAL THEN 'p_rb1a' WHEN p_rb1b IS NOT INITIAL THEN 'p_rb1b' ELSE 'p_rb1c' ) }"| . WRITE / |Radio button rbg2 selection: "{ COND #( WHEN p_rb2a IS NOT INITIAL THEN 'p_rb2a' WHEN p_rb2b IS NOT INITIAL THEN 'p_rb2b' WHEN p_rb2c IS NOT INITIAL THEN 'p_rb2c' ELSE 'p_rb2d' ) }"| . WRITE / |p_list: "{ plistbox }"|. ``` |
|
Assigning function codes to selection parameters Addition `USER-COMMAND` |
- You can assign function codes to selection parameters using the `USER-COMMAND` addition. - The addition is supported by `PARAMETERS` statements specifying the `AS CHECKBOX`, `RADIOBUTTON GROUP` and `AS LISTBOX VISIBLE LENGTH` additions. - As a prerequisite, you must specify a [`TABLES`](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abaptables.htm) statement to declare an [interface work area](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abeninterface_work_area_glosry.htm) of the `sscrfields` DDIC structure. - On user selection (e.g. a checkbox or radio button is selected), the `AT SELECTION-SCREEN` event is raised, and the function code is passed to the `ucomm` component of `sscrfields`. For evaluation purposes, evaluate `sscrfields-ucomm` instead of `sy-ucomm` as it is not guaranteed that the latter is always passed the correct value during selection screen processing. | ``` abap PROGRAM. "Declaring interface work area TABLES sscrfields. *&---------------------------------------------------------------------* *& AS CHECKBOX USER-COMMAND *&---------------------------------------------------------------------* PARAMETERS p_chkbox AS CHECKBOX USER-COMMAND box_cmd. *&---------------------------------------------------------------------* *& RADIOBUTTON GROUP group USER-COMMAND *&---------------------------------------------------------------------* PARAMETERS: p_rb1 RADIOBUTTON GROUP rbg USER-COMMAND rb_cmd, p_rb2 RADIOBUTTON GROUP rbg, p_rb3 RADIOBUTTON GROUP rbg. *&---------------------------------------------------------------------* *& AS LISTBOX VISIBLE LENGTH ... USER-COMMAND *&---------------------------------------------------------------------* PARAMETERS plistbox TYPE i AS LISTBOX VISIBLE LENGTH 10 USER-COMMAND list_cmd. AT SELECTION-SCREEN OUTPUT. CALL FUNCTION 'VRM_SET_VALUES' EXPORTING id = CONV vrm_id( 'PLISTBOX' ) values = VALUE vrm_values( FOR i = 1 UNTIL i > 10 ( key = i text = |Value { i }| ) ). AT SELECTION-SCREEN. CASE sscrfields-ucomm. WHEN 'BOX_CMD'. MESSAGE |Hallo { sy-uname }. You selected a checkbox.| TYPE 'I'. WHEN 'RB_CMD'. MESSAGE |Hallo { sy-uname }. You selected a radio button.| TYPE 'I'. WHEN 'LIST_CMD'. MESSAGE |Hallo { sy-uname }. You selected an item from the list box.| TYPE 'I'. ENDCASE. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. IF p_chkbox IS INITIAL. WRITE / `Checkbox p_chkbox was not selected.`. ELSE. WRITE / `Checkbox p_chkbox was selected.`. ENDIF. WRITE / |Radio button rbg selection: "{ COND #( WHEN p_rb1 IS NOT INITIAL THEN 'p_rb1' WHEN p_rb2 IS NOT INITIAL THEN 'p_rb2' ELSE 'p_rb3' ) }"| . WRITE / |p_list: "{ plistbox }"|. ``` |
|
Assigning a screen element of a selection screen to a modification group Addition `MODIF ID` |
- The `PARAMETERS` statement can be specified with the `MODIF ID` addition to assign a screen element of a selection screen to a modification group, which represents a group of multiple screen elements of a dynpro having a three-character ID. This ID is used to modify the display properties of all those elements specifying the ID before they are actually displayed. For that purpose, you can use the `MODIFY SCREEN` statement. The ID is assigned to the `screen-group1` component that can be evaluated. - Find more information [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenmodification_group_glosry.htm). | ``` abap PROGRAM. TABLES sscrfields. PARAMETERS showhide AS CHECKBOX USER-COMMAND box_cmd1. PARAMETERS p_input1 TYPE c LENGTH 20. PARAMETERS p_input2 TYPE c LENGTH 20 MODIF ID id1. PARAMETERS p_input3 TYPE c LENGTH 20. PARAMETERS p_input4 TYPE c LENGTH 20 MODIF ID id1. PARAMETERS colored AS CHECKBOX USER-COMMAND box_cmd2. PARAMETERS p_input5 TYPE c LENGTH 20 DEFAULT 'abcdefg'. PARAMETERS p_input6 TYPE c LENGTH 20 MODIF ID id2 DEFAULT 'hijklm'. PARAMETERS p_input7 TYPE c LENGTH 20 MODIF ID id2 DEFAULT 'nopqrs'. PARAMETERS p_input8 TYPE c LENGTH 20 DEFAULT 'tuvwxyz'. AT SELECTION-SCREEN. CASE sscrfields-ucomm. WHEN 'BOX_CMD1'. MESSAGE |Hallo { sy-uname }. You selected the SHOWHIDE checkbox. Screen elements are about to be shown or hidden.| TYPE 'I'. WHEN 'BOX_CMD2'. MESSAGE |Hallo { sy-uname }. You selected the COLORED checkbox. The colors of output fields are about to be intensified or reverted.| TYPE 'I'. ENDCASE. AT SELECTION-SCREEN OUTPUT. LOOP AT SCREEN INTO DATA(screen_wa). IF showhide = 'X' AND screen_wa-group1 = 'ID1'. screen_wa-active = '0'. ENDIF. IF colored = 'X' AND screen_wa-group1 = 'ID2'. screen_wa-intensified = '1'. ENDIF. MODIFY SCREEN FROM screen_wa. ENDLOOP. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |p_input1: "{ p_input1 }"|. WRITE / |p_input2: "{ p_input2 }"|. WRITE / |p_input3: "{ p_input3 }"|. WRITE / |p_input4: "{ p_input4 }"|. WRITE / |p_input5: "{ p_input5 }"|. WRITE / |p_input6: "{ p_input6 }"|. WRITE / |p_input7: "{ p_input7 }"|. WRITE / |p_input8: "{ p_input8 }"|. ``` |
| Replacing the technical name displayed on the screen | - The parameter name is a technical name. You probably do not want to display technical names on the user interface. You can define proper names ([text elements](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abentext_element_glosry.htm)) in the ABAP Editor, e.g. for translation purposes. - For the example code snippet, proceed as follows: - In ADT, make a right-click inside your demo report you copied the code to. Choose *Open Others -> Text Elements*. - At the bottom of the opened window, select the *Selection Texts* tab. - Insert `PARAM=Enter some text` and activate. Leave the *number* parameter unchanged. - You can also use `SELECTION-SCREEN` statements such as the `... COMMENT ...` statement, as outlined below, and assign a text value to the screen comment. - When you execute the program, you will see the technical names replaced by *Enter some text* and *Enter a number*. | ``` abap PROGRAM. PARAMETERS param type string. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT (33) txt. PARAMETERS number type i. SELECTION-SCREEN END OF LINE. INITIALIZATION. txt = 'Enter a number'. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |param: "{ param }"|. WRITE / |number: "{ number }"|. ``` |
| Subject/Addition | Notes | Code Snippet |
|
Determining the `low` and `high` columns in the selection table Addition `FOR` |
- Determines the `low` and `high` columns in the selection table. - Besides a statically defined data object from the program or public attributes of global classes, you can also dynamically specify a DDIC data type within parentheses. - Note: - Without the addition `NO_DISPLAY`, the data types must be elementary and flat (except type `f` and enumerated types). - When you specify a reference to a DDIC type, its screen-related properties are used. - In case of the dynamic specification, the columns in the selection table are created using type `c` length 45. A constant or variable containing the name of component of a flat structure from the DDIC can be specified. Literals are not evaluated. | The code snippet, copyable to a demo program and executable using F8, implements the following: - A demo internal table is created. It is filled in the `INITIALIZATION` event block. - Two `SELECT-OPTIONS` statements are included. The first references a statically data object after `FOR`, the second a dynamically specified DDIC type. The latter demonstrates that screen-relevant properties are inherited. - When running the program, you can make entries. `SELECT` statements retrieve data from the internal table based on the specifications in the ranges table. To visualize the selection result, `WRITE` statements display table entries in a classic list. ``` abap PROGRAM. DATA: BEGIN OF demo_structure, carrid TYPE c LENGTH 3, num TYPE i, END OF demo_structure. DATA itab LIKE TABLE OF demo_structure WITH EMPTY KEY. *&---------------------------------------------------------------------* *& Referencing a statically defined data object *&---------------------------------------------------------------------* "In the example, a structure component is specified. SELECT-OPTIONS sel1 FOR demo_structure-num. *&---------------------------------------------------------------------* *& Referencing a dynamically specified DDIC type *&---------------------------------------------------------------------* "Here, the name of a component of a flat structure from the DDIC "is passed. The example type involves search help functionality. "Screen-relevant properties are inherited. DATA dyn_spec TYPE c LENGTH 12. SELECT-OPTIONS sel2 FOR (dyn_spec). INITIALIZATION. itab = VALUE #( ( carrid = 'AA' num = 1 ) ( carrid = 'AC' num = 2 ) ( carrid = 'AF' num = 3 ) ( carrid = 'AZ' num = 4 ) ( carrid = 'BA' num = 5 ) ( carrid = 'FJ' num = 6 ) ( carrid = 'JL' num = 7 ) ( carrid = 'LH' num = 8 ) ( carrid = 'NW' num = 9 ) ( carrid = 'QF' num = 10 ) ( carrid = 'SQ' num = 11 ) ( carrid = 'UA' num = 12 ) ). dyn_spec = 'SCARR-CARRID'. START-OF-SELECTION. WRITE / `Selected values (sel1):`. SKIP. SELECT * FROM @itab AS tab WHERE num IN @sel1 INTO @demo_structure. WRITE / |{ demo_structure-carrid } { demo_structure-num }|. ENDSELECT. SKIP. SKIP. WRITE / `Selected values (sel2):`. SKIP. SELECT * FROM @itab AS tab WHERE carrid IN @sel2 INTO @demo_structure. WRITE / |{ demo_structure-carrid } { demo_structure-num }|. ENDSELECT. ``` |
|
Specifying screen options Additions `OBLIGATORY`, `NO-DISPLAY`, `VISIBLE LENGTH`, `NO-EXTENSION`, `NO INTERVALS`, `MODIF ID` |
- `OBLIGATORY`: Declares the first input field as a required field. If there is no entry, the program cannot proceed when choosing Execute. A message will be displayed. - `NO-DISPLAY`: Hides screen elements. Values (any flat types) can be supplied using `SUBMIT` statements. Note that there is no restriction to 45 characters. - `VISIBLE LENGTH`: Defines the visible length of the input field. - `NO-EXTENSION`: Cancels the option for multiple selection on the screen. - `NO INTERVALS`: Removes the second input field on the screen. - `MODIF ID`: See a description in the previous section about `PARAMETERS`. - Note that combinations of the additions are possible. | The code snippet, copyable to a demo program and executable using F8, implements the following: - A demo internal table is created. It is filled in the `INITIALIZATION` event block. - Multiple `SELECT-OPTIONS` statements are included that specify additions. - When running the program, you can make entries. `SELECT` statements retrieve data from the internal table based on the specifications in the ranges table. To visualize the selection result, `WRITE` statements display table entries in a classic list. ``` abap PROGRAM. DATA: BEGIN OF demo_structure, carrid TYPE c LENGTH 3, num TYPE i, END OF demo_structure. DATA itab LIKE TABLE OF demo_structure WITH EMPTY KEY. *&---------------------------------------------------------------------* *& OBLIGATORY *&---------------------------------------------------------------------* SELECT-OPTIONS sel_oblg FOR demo_structure-num OBLIGATORY. *&---------------------------------------------------------------------* *& NO-DISPLAY *&---------------------------------------------------------------------* SELECT-OPTIONS sel_nodi FOR demo_structure-num NO-DISPLAY. *&---------------------------------------------------------------------* *& VISIBLE LENGTH *&---------------------------------------------------------------------* SELECT-OPTIONS sel_visl FOR demo_structure-carrid VISIBLE LENGTH 2. *&---------------------------------------------------------------------* *& NO-EXTENSION *&---------------------------------------------------------------------* SELECT-OPTIONS sel_noet FOR demo_structure-num NO-EXTENSION. *&---------------------------------------------------------------------* *& NO INTERVALS *&---------------------------------------------------------------------* SELECT-OPTIONS sel_noin FOR demo_structure-num NO INTERVALS. INITIALIZATION. itab = VALUE #( ( carrid = 'AA' num = 1 ) ( carrid = 'AC' num = 2 ) ( carrid = 'AF' num = 3 ) ( carrid = 'AZ' num = 4 ) ( carrid = 'BA' num = 5 ) ( carrid = 'FJ' num = 6 ) ( carrid = 'JL' num = 7 ) ( carrid = 'LH' num = 8 ) ( carrid = 'NW' num = 9 ) ( carrid = 'QF' num = 10 ) ( carrid = 'SQ' num = 11 ) ( carrid = 'UA' num = 12 ) ). START-OF-SELECTION. WRITE / `Selected values (OBLIGATORY addition):`. SKIP. SELECT * FROM @itab AS tab WHERE num IN @sel_oblg INTO @demo_structure. WRITE / |{ demo_structure-carrid } { demo_structure-num }|. ENDSELECT. SKIP. SKIP. WRITE / `Selected values (NO-DISPLAY addition):`. SKIP. SELECT * FROM @itab AS tab WHERE num IN @sel_nodi INTO @demo_structure. WRITE / |{ demo_structure-carrid } { demo_structure-num }|. ENDSELECT. SKIP. SKIP. WRITE / `Selected values (VISIBLE LENGTH addition):`. SKIP. SELECT * FROM @itab AS tab WHERE carrid IN @sel_visl INTO @demo_structure. WRITE / |{ demo_structure-carrid } { demo_structure-num }|. ENDSELECT. SKIP. SKIP. WRITE / `Selected values (NO-EXTENSION addition):`. SKIP. SELECT * FROM @itab AS tab WHERE num IN @sel_noet INTO @demo_structure. WRITE / |{ demo_structure-carrid } { demo_structure-num }|. ENDSELECT. SKIP. SKIP. WRITE / `Selected values (NO INTERVALS addition):`. SKIP. SELECT * FROM @itab AS tab WHERE num IN @sel_noin INTO @demo_structure. WRITE / |{ demo_structure-carrid } { demo_structure-num }|. ENDSELECT. ``` |
|
Specifying value options Additions `DEFAULT a [TO b] [OPTION c] [SIGN d]`, `LOWER CASE`, `MATCHCODE OBJECT`, `MEMORY ID` |
- `DEFAULT a [TO b] [OPTION c] [SIGN d]`: Defines start values for the first line of the selection table. - `a` specifies the `low` column - `b` specifies the `high` column - `c` specifies the `option` column (specify the comparison expressions `eq`, `ne`, `ge`, `gt`, `le`, `lt`, `cp`, `np`, `bt`, `nb` directly after `OPTION`; restrictions apply if you do not specify `TO`; not specifying `OPTION` means `eq` or `bt` by default; to use patterns with `cp` and `np`, specify wildcard characters `*` or `+`) - `d` specifies the `sign` column (specify either `i` or `e` to include or exclude; not specifying `SIGN` means `i` is used by default) - `LOWER CASE`: Avoid autoamtic transformation to uppercase letters. - `MATCHCODE OBJECT`: Links an input field with a DDIC search help - `MEMORY ID`: See a description in the previous section about `PARAMETERS`. |
The code snippet, copyable to a demo program and executable using F8, implements the following:
- A demo internal table is created. It is filled in the `INITIALIZATION` event block.
- Multiple `SELECT-OPTIONS` statements are included that specify additions.
- When running the program, you can make entries. `SELECT` statements retrieve data from the internal table based on the specifications in the ranges table. To visualize the selection result, `WRITE` statements display table entries in a classic list. Additionally, the content of the ranges tables is displayed.
``` abap
PROGRAM.
DATA: BEGIN OF demo_structure,
carrid TYPE c LENGTH 3,
num TYPE i,
END OF demo_structure.
DATA itab LIKE TABLE OF demo_structure WITH EMPTY KEY.
*&---------------------------------------------------------------------*
*& DEFAULT a [TO b] [OPTION c] [SIGN d]
*&---------------------------------------------------------------------*
SELECT-OPTIONS sel_dfl1 FOR demo_structure-num DEFAULT 4.
SELECT-OPTIONS sel_dfl2 FOR demo_structure-num DEFAULT 2 TO 8.
SELECT-OPTIONS sel_dfl3 FOR demo_structure-num DEFAULT 5 TO 10 OPTION BT SIGN I.
SELECT-OPTIONS sel_dfl4 FOR demo_structure-num DEFAULT 5 TO 10 OPTION BT SIGN E.
SELECT-OPTIONS sel_dfl5 FOR demo_structure-carrid DEFAULT 'A*' OPTION CP SIGN I.
*&---------------------------------------------------------------------*
*& LOWER CASE
*&---------------------------------------------------------------------*
"The example is specified with DEFAULT ... TO ... and includes values
"with uppercase and lowercase. If you leave the demo values, all table
"entries are read (starting from AA which is the first) as there is no
"lh value. It should be specified as LH in uppercase.
SELECT-OPTIONS sel_lc FOR demo_structure-carrid DEFAULT 'AA' TO 'lh' LOWER CASE.
*&---------------------------------------------------------------------*
*& MATCHCODE OBJECT
*&---------------------------------------------------------------------*
"The specified type includes a search help
SELECT-OPTIONS sel_mtch FOR demo_structure-carrid MATCHCODE OBJECT s_carrier_id.
INITIALIZATION.
itab = VALUE #( ( carrid = 'AA' num = 1 )
( carrid = 'AC' num = 2 )
( carrid = 'AF' num = 3 )
( carrid = 'AZ' num = 4 )
( carrid = 'BA' num = 5 )
( carrid = 'FJ' num = 6 )
( carrid = 'JL' num = 7 )
( carrid = 'LH' num = 8 )
( carrid = 'NW' num = 9 )
( carrid = 'QF' num = 10 )
( carrid = 'SQ' num = 11 )
( carrid = 'UA' num = 12 ) ).
START-OF-SELECTION.
WRITE / `Selected values (only DEFAULT):`.
LOOP AT sel_dfl1 ASSIGNING FIELD-SYMBOL( |
| Subject/Statement | Notes | Code Snippet |
|
Creating a selection screen as regular dynpro `SELECTION-SCREEN BEGIN OF SCREEN ...` |
- Creates a selection screen as regular dynpro by specifying a dynpro number. - The dynpro number must be unique in the program. Do not use 1000. - Additions (which can be combined): - `... TITLE ...`: Defines a title (e.g. a random name or the name of a text symbol) for the title bar - `... AS WINDOW`: Displays the selection screen in a modal dialog box |
``` abap
PROGRAM.
SELECTION-SCREEN BEGIN OF SCREEN 9000.
PARAMETERS param TYPE string.
PARAMETERS number TYPE i.
SELECTION-SCREEN END OF SCREEN 9000.
START-OF-SELECTION.
CALL SELECTION-SCREEN 9000.
WRITE / `Inserted values:`.
SKIP.
WRITE / |param: "{ param }"|.
WRITE / |number: "{ number }"|.
```
`TITLE` addition For the example, proceed as follows: - Copy and paste the code snippet to a demo executable program. - Create a text symbol by making a right-click in the source code, and choose *Open Others -> Text Elements*. - Select the *Text Symbols* tab. - Add the following code and activate. ```abap @MaxLength:64 001=Selection screen demo with the TITLE addition ``` ```abap PROGRAM. SELECTION-SCREEN BEGIN OF SCREEN 9001 TITLE TEXT-001. PARAMETERS param TYPE string. PARAMETERS number TYPE i. SELECTION-SCREEN END OF SCREEN 9001. START-OF-SELECTION. CALL SELECTION-SCREEN 9001. WRITE / `Text of text symbol:`. WRITE / TEXT-001. SKIP. SKIP. WRITE / `Inserted values:`. SKIP. WRITE / |param: "{ param }"|. WRITE / |number: "{ number }"|. ``` `AS WINDOW` addition - The example code includes multiple `SELECTION-SCREEN` statements that specify the `AS WINDOW` addition. They also specify the `TITLE` addition. In these cases, a random name is used. The name is assigned a value in the `INITIALIZATION` event block. - You can select a radio button. Depending on the selection a selection screen is called. - The example demonstrates selection screens displayed as modal dialog box. They are called with `CALL SELECTION-SCREEN ... STARTING AT ...` statements (except one example, `p_winno` selection, that does not open a modal dialog box). ```abap PROGRAM. PARAMETERS: p_winat1 RADIOBUTTON GROUP rbg, p_winat2 RADIOBUTTON GROUP rbg, p_noat RADIOBUTTON GROUP rbg. SELECTION-SCREEN BEGIN OF SCREEN 9001 TITLE seltitl1 AS WINDOW. PARAMETERS param1 TYPE string. SELECTION-SCREEN END OF SCREEN 9001. SELECTION-SCREEN BEGIN OF SCREEN 9002 TITLE seltitl2 AS WINDOW. PARAMETERS param2 TYPE string. SELECTION-SCREEN END OF SCREEN 9002. INITIALIZATION. seltitl1 = 'Selection screen demo with the AS WINDOW addition (1)'. seltitl2 = 'Another selection screen with the AS WINDOW addition (2)'. START-OF-SELECTION. CASE 'X'. WHEN p_winat1. CALL SELECTION-SCREEN 9001 STARTING AT 10 10. WRITE / `Inserted value:`. SKIP. WRITE / |param1: "{ param1 }"|. WHEN p_winat2. CALL SELECTION-SCREEN 9002 STARTING AT 1 5. WRITE / `Inserted value:`. SKIP. WRITE / |param2: "{ param2 }"|. WHEN p_noat. CALL SELECTION-SCREEN 9001. WRITE / `Inserted value:`. SKIP. WRITE / |param1: "{ param1 }"|. ENDCASE. ``` |
|
Creating a selection screen as subscreen dynpro `SELECTION-SCREEN BEGIN OF SCREEN ... AS SUBSCREEN` |
- Can be included in other dynpros or selection screens, or in subscreen areas or tab pages. - They cannot be called explicitly using `CALL SELECTION-SCREEN` statements. - Additions: - `NO INTERVALS`: `NO INTERVALS` is implicitly used in `SELECT-OPTIONS` statements - `NESTING LEVEL` Adjusts the subscreen width (a number between 0 and 4 is ecpected) when the subscreen is part of one or more frames in tabstrip controls | The code snippet, copyable to a demo program and executable using F8, implements the following: - Multiple selection screens are created as subscreen dynpros, each including a `PARAMETERS` statement. - They are included in a tabstrip control on the standard selection screen of an executable program. The `TABBED BLOCK` syntax is covered further down. In the example, the first tabbed block specifies default screens. The second does not. There, the switch on tab click is realized by evaluating `sscrfields-ucomm`. ``` abap PROGRAM. TABLES sscrfields. SELECTION-SCREEN BEGIN OF SCREEN 9001 AS SUBSCREEN. PARAMETERS param1 TYPE c LENGTH 20. SELECTION-SCREEN END OF SCREEN 9001. SELECTION-SCREEN BEGIN OF SCREEN 9002 AS SUBSCREEN. PARAMETERS param2 TYPE c LENGTH 20. SELECTION-SCREEN END OF SCREEN 9002. SELECTION-SCREEN BEGIN OF SCREEN 9003 AS SUBSCREEN. PARAMETERS param3 TYPE c LENGTH 20. SELECTION-SCREEN END OF SCREEN 9003. SELECTION-SCREEN BEGIN OF SCREEN 9004 AS SUBSCREEN. PARAMETERS param4 TYPE c LENGTH 20. SELECTION-SCREEN END OF SCREEN 9004. SELECTION-SCREEN: BEGIN OF TABBED BLOCK tabbl1 FOR 2 LINES, TAB (20) tab1 USER-COMMAND push1 DEFAULT SCREEN 9001, TAB (20) tab2 USER-COMMAND push2 DEFAULT SCREEN 9002, END OF BLOCK tabbl1. SELECTION-SCREEN: BEGIN OF TABBED BLOCK tabbl2 FOR 2 LINES, TAB (20) tab3 USER-COMMAND push3, TAB (20) tab4 USER-COMMAND push4, END OF BLOCK tabbl2. INITIALIZATION. tab1 = 'Subscreen 1'. tab2 = 'Subscreen 2'. tab3 = 'Subscreen 3'. tab4 = 'Subscreen 4'. tabbl2-prog = sy-repid. tabbl2-dynnr = 9003. tabbl2-activetab = 'TAB3'. AT SELECTION-SCREEN. CASE sscrfields-ucomm. WHEN 'PUSH1'. tab1 = 'New subscreen title'. WHEN 'PUSH2'. tab2 = 'Some tab'. WHEN 'PUSH3'. tabbl2-dynnr = 9003. WHEN 'PUSH4'. tabbl2-dynnr = 9004. ENDCASE. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |param1: "{ param1 }"|. WRITE / |param2: "{ param2 }"|. WRITE / |param3: "{ param3 }"|. WRITE / |param4: "{ param4 }"|. ``` |
| Subject/Statement | Notes | Code Snippet |
|
Adding blank lines `SELECTION-SCREEN SKIP` |
- Creates a specified number of lines - If a number is not specified, one blank line is created by default. | ``` abap PARAMETERS param1 TYPE c LENGTH 20. SELECTION-SCREEN SKIP. PARAMETERS param2 TYPE c LENGTH 20. SELECTION-SCREEN SKIP 3. PARAMETERS param3 TYPE c LENGTH 20. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |param1: "{ param1 }"|. WRITE / |param2: "{ param2 }"|. WRITE / |param3: "{ param3 }"|. ``` |
|
Creating horizontal lines `SELECTION-SCREEN ULINE` |
- Formatting options are available: - Position from where to start the line and length specification - Either the position (1-83) is specified directly as number or with the additions `POS_LOW` (position of first input field) and `POS_HIGH` (position of second inut field). - `/` creates the line a new line; cannot be specified if multiple elements are specified in a line - If no formatting options are specified, a line is created that goes accross the whole screen below the lines that are already filled. - The addition `MODIF ID` is supported. - Find more details [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapselection-screen_uline.htm). | ``` abap PROGRAM. PARAMETERS param1 TYPE c LENGTH 20. SELECTION-SCREEN ULINE. PARAMETERS param2 TYPE c LENGTH 20. "/ means the line is created in a new line "/ is followed by the position and the length in parentheses SELECTION-SCREEN ULINE /5(10). PARAMETERS param3 TYPE c LENGTH 20. "SELECTION-SCREEN ULINE 5(10). PARAMETERS param4 TYPE c LENGTH 20. SELECTION-SCREEN ULINE /pos_low(15). PARAMETERS param5 TYPE c LENGTH 20. SELECTION-SCREEN ULINE /pos_high(15). "/ can be ommitted if the elements are in the same line SELECTION-SCREEN BEGIN OF LINE. PARAMETERS param6 TYPE c LENGTH 1. SELECTION-SCREEN ULINE 4(5). PARAMETERS param7 TYPE c LENGTH 1. SELECTION-SCREEN ULINE pos_low(20). PARAMETERS param8 TYPE c LENGTH 1. SELECTION-SCREEN ULINE pos_high(40). SELECTION-SCREEN END OF LINE. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |param1: "{ param1 }"|. WRITE / |param2: "{ param2 }"|. WRITE / |param3: "{ param3 }"|. WRITE / |param4: "{ param4 }"|. WRITE / |param5: "{ param5 }"|. WRITE / |param6: "{ param6 }"|. WRITE / |param7: "{ param7 }"|. WRITE / |param8: "{ param8 }"|. ``` |
|
Creating an output field/comment on the selection screen `SELECTION-SCREEN COMMENT` |
- Creates text content in a field - The statement expects a random name (maximum 8 characters; a global variable with type `c` and length 83 is implicitly created) or a text symbol - Additions - Position-related additions as outlined for `SELECTION-SCREEN ULINE` - `FOR FIELD`: Links output field to elements specified with `PARAMETERS` or `SELECT-OPTIONS` - `VISIBLE LENGTH`: Defines the visible length of the output field - `MODIF ID`: See above. | ``` abap PROGRAM. *&---------------------------------------------------------------------* *& Position-related additions *&---------------------------------------------------------------------* SELECTION-SCREEN COMMENT /1(20) txt1. SELECTION-SCREEN ULINE /1(50). PARAMETERS: rb1 RADIOBUTTON GROUP rbgr, rb2 RADIOBUTTON GROUP rbgr, rb3 RADIOBUTTON GROUP rbgr. SELECTION-SCREEN ULINE /1(50). SELECTION-SCREEN COMMENT /pos_high(40) txt2. "Providing a text for a parameter SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN COMMENT (15) txt3. PARAMETERS param1 TYPE c LENGTH 10. SELECTION-SCREEN END OF LINE. "Using a text symbol SELECTION-SCREEN COMMENT /1(20) TEXT-001. *&---------------------------------------------------------------------* *& VISIBLE LENGTH *&---------------------------------------------------------------------* SELECTION-SCREEN COMMENT /1(20) txt4 VISIBLE LENGTH 4. *&---------------------------------------------------------------------* *& MODIF ID *&---------------------------------------------------------------------* SELECTION-SCREEN COMMENT /1(50) txt5 MODIF ID mid. SELECTION-SCREEN COMMENT /1(50) txt6. SELECTION-SCREEN COMMENT /1(50) txt7 MODIF ID mid. AT SELECTION-SCREEN OUTPUT. txt1 = 'Make a selection:'. txt2 = 'Text with pos_high'. txt3 = 'Make an entry'. txt4 = 'Some long text'. txt5 = 'First intensified text'. txt6 = 'Not intensified text'. txt7 = 'Second intensified tex'. LOOP AT SCREEN INTO DATA(screen_wa). IF screen_wa-group1 = 'MID'. screen_wa-intensified = '1'. MODIFY SCREEN FROM screen_wa. ENDIF. ENDLOOP. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |Radio button selection: "{ COND #( WHEN rb1 IS NOT INITIAL THEN 'rb1' WHEN rb2 IS NOT INITIAL THEN 'rb2' ELSE 'rb3' ) }"|. WRITE / |param1: "{ param1 }"|. IF TEXT-001 IS INITIAL. WRITE / |Text symbol TEXT-001 does not exist.|. ENDIF. ``` |
|
Specifying multiple elements in one line and their position in the line `SELECTION-SCREEN BEGIN OF LINE. ... SELECTION-SCREEN END OF LINE.` and `SELECTION-SCREEN POSITION` |
- Places all `PARAMETERS`, `SELECT-OPTIONS` and `SELECTION-SCREEN` statements in one line without spaces - The statement `SELECTION-SCREEN POSITION` can only be specified in the statement block. The position can be specified as number (1-83) or using the additions `POS_LOW` and `POS_HIGH`. The statement relates to positioning the following statement. - Note that if there are positioning conflicts, the selection screen cannot be created. - In the statement block, certain restrictions apply. See [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapselection-screen_line.htm). |
``` abap
PROGRAM.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (10) txt1.
SELECTION-SCREEN POSITION 15.
PARAMETERS param1 TYPE c LENGTH 3.
SELECTION-SCREEN COMMENT (10) txt2.
SELECTION-SCREEN POSITION 45.
PARAMETERS param2 TYPE c LENGTH 3.
SELECTION-SCREEN COMMENT (10) txt3.
SELECTION-SCREEN POSITION 70.
SELECTION-SCREEN COMMENT (10) txt4.
SELECTION-SCREEN END OF LINE.
DATA dyn_spec TYPE c LENGTH 12.
"Chained statement
"The example emphasizes potential positioning
"conflicts that can prevent the selection screen
"from being created. For demo purposes, you can
"comment in param3 and run the program, resulting
"in a runtime error. Then you can comment in the
"NO-EXTENSION and NO INTERVALS additions to the
"SELECT-OPTIONS statement, and run the program
"again. Since the extra screen elements are not
"displayed, the selection screen can be created.
SELECTION-SCREEN: BEGIN OF LINE,
POSITION 5,
COMMENT (10) txt5.
SELECT-OPTIONS sel FOR (dyn_spec)
"NO-EXTENSION
"NO INTERVALS
.
"PARAMETERS param3 TYPE c LENGTH 3.
SELECTION-SCREEN: POSITION 70,
COMMENT (10) txt6,
END OF LINE.
INITIALIZATION.
txt1 = 'Some text'.
txt2 = 'Hello'.
txt3 = sy-uname.
txt4 = sy-datum.
txt5 = 'Select'.
txt6 = 'More text'.
dyn_spec = 'SCARR-CARRID'.
START-OF-SELECTION.
WRITE / `Inserted values:`.
SKIP.
WRITE / |param1: "{ param1 }"|.
WRITE / |param2: "{ param2 }"|.
SKIP.
WRITE / `Selection table content:`.
LOOP AT sel ASSIGNING FIELD-SYMBOL( |
|
Creating pushbuttons `SELECTION-SCREEN PUSHBUTTON` |
- Typically, pushbuttons are used to modify the selection screen, not to control the program (e.g. to exit the program). - Additions: - Position-related additions as outlined above - `USER-COMMAND`: Used to assign a function code. The pushbutton is enabled by implementing a `TABLES sscrfields.` statement. In doing so, an interface work area is created. When a pushbutton is clicked, the `AT SELECTION-SCREEN` event is raised, and the function code can be evaluated using `sscrfields-ucomm` (do not use `sy-ucomm`). - `VISIBLE LENGTH`: Defines the visible length of the pushbutton - `MODIF ID`: See above - You can use the function module `ICON_CREATE` to assign an icon, a tooltip, and a text to a pushbutton. | ``` abap PROGRAM. TABLES sscrfields. SELECTION-SCREEN PUSHBUTTON /1(15) btn_a USER-COMMAND cmd1. SELECTION-SCREEN SKIP. SELECTION-SCREEN PUSHBUTTON /1(15) btn_b USER-COMMAND cmd2. SELECTION-SCREEN SKIP. SELECTION-SCREEN PUSHBUTTON /1(30) btn_c USER-COMMAND cmd3 VISIBLE LENGTH 7. INITIALIZATION. btn_a = 'Button A'. btn_c = 'Button C with long text'. CALL FUNCTION 'ICON_CREATE' EXPORTING name = icon_information text = 'Button B' info = 'Some info' IMPORTING result = btn_b EXCEPTIONS OTHERS = 0. AT SELECTION-SCREEN. CASE sscrfields-ucomm. WHEN 'CMD1'. MESSAGE |Hello { sy-uname }. You clicked button A.| TYPE 'I'. WHEN 'CMD2'. MESSAGE |Hello { sy-uname }. You clicked button B.| TYPE 'I'. WHEN 'CMD3'. MESSAGE |Hello { sy-uname }. You clicked button C.| TYPE 'I'. ENDCASE. START-OF-SELECTION. WRITE / `No content to display in this example.`. ``` |
|
Defining a block `SELECTION-SCREEN BEGIN OF BLOCK ... SELECTION-SCREEN END OF BLOCK ...` |
- You can also create blocks within blocks. - The blocks raise the `AT SELECTION-SCREEN ON BLOCK`. There, the entries of a block can be processed together. - Additions: - `WITH FRAME [TITLE ...]`: Draws a frame round a block. You can optionally specify a title either by specifying a random name or a text symbol. - `NO INTERVALS`: When specified, `NO INTERVALS` is used implicitly for `SELECT-OPTIONS` (in all nested blocks). | The code snippet, copyable to a demo program and executable using F8, implements the following: - Multiple blocks are created using `SELECTION-SCREEN ... BLOCK ...` statements, including different additions or none. One block contains nested blocks. - The raising of `AT SELECTION-SCREEN ON BLOCK` events for the blocks defined is demonstrated using messages displayed when the program is run. ``` abap PROGRAM. *&---------------------------------------------------------------------* *& No addition *&---------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK block1. PARAMETERS param1 TYPE c LENGTH 10 DEFAULT 'abc' LOWER CASE. PARAMETERS param2 TYPE c LENGTH 10 DEFAULT 'def' LOWER CASE. SELECTION-SCREEN END OF BLOCK block1. *&---------------------------------------------------------------------* *& WITH FRAME *&---------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME. PARAMETERS param3 TYPE c LENGTH 10 DEFAULT 'hij' LOWER CASE. PARAMETERS param4 TYPE c LENGTH 10 DEFAULT 'klm' LOWER CASE. SELECTION-SCREEN END OF BLOCK block2. *&---------------------------------------------------------------------* *& WITH FRAME WITH TITLE *&---------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK block3 WITH FRAME TITLE titl. PARAMETERS: rb1 RADIOBUTTON GROUP gr, rb2 RADIOBUTTON GROUP gr, rb3 RADIOBUTTON GROUP gr. SELECTION-SCREEN END OF BLOCK block3. *&---------------------------------------------------------------------* *& Nested blocks *&---------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK block4a WITH FRAME TITLE titl4a. PARAMETERS param5 TYPE c LENGTH 10 DEFAULT 'nop' LOWER CASE. SELECTION-SCREEN SKIP. SELECTION-SCREEN BEGIN OF BLOCK block4b WITH FRAME TITLE titl4b. PARAMETERS param6 TYPE c LENGTH 10 DEFAULT 'qrs' LOWER CASE. SELECTION-SCREEN SKIP. SELECTION-SCREEN BEGIN OF BLOCK block4c WITH FRAME TITLE titl4c. PARAMETERS param7 TYPE c LENGTH 10 DEFAULT 'tuv' LOWER CASE. SELECTION-SCREEN SKIP. SELECTION-SCREEN END OF BLOCK block4c. SELECTION-SCREEN END OF BLOCK block4b. SELECTION-SCREEN END OF BLOCK block4a. "Demo flags for the AT SELECTION-SCREEN ON BLOCK implementations DATA block1_flag TYPE abap_boolean. DATA block2_flag TYPE abap_boolean. DATA block3_flag TYPE abap_boolean. DATA block4a_flag TYPE abap_boolean. DATA block4b_flag TYPE abap_boolean. DATA block4c_flag TYPE abap_boolean. INITIALIZATION. titl = 'Radiobutton Selection'. titl4a = 'Title 1'. titl4b = 'Title 2'. titl4c = 'Title 3'. AT SELECTION-SCREEN ON BLOCK block1. block1_flag = abap_true. MESSAGE |Event AT SELECTION-SCREEN ON BLOCK block1 raised. Others already raised? | && |block2: "{ COND #( WHEN block2_flag = abap_true THEN abap_true ) }" | && |block3: "{ COND #( WHEN block3_flag = abap_true THEN abap_true ) }" | && |block4a: "{ COND #( WHEN block4a_flag = abap_true THEN abap_true ) }" | && |block4b: "{ COND #( WHEN block4b_flag = abap_true THEN abap_true ) }" | && |block4c: "{ COND #( WHEN block4c_flag = abap_true THEN abap_true ) }" | TYPE 'I'. AT SELECTION-SCREEN ON BLOCK block2. block2_flag = abap_true. MESSAGE |Event AT SELECTION-SCREEN ON BLOCK block2 raised. Others already raised? | && |block1: "{ COND #( WHEN block1_flag = abap_true THEN abap_true ) }" | && |block3: "{ COND #( WHEN block3_flag = abap_true THEN abap_true ) }" | && |block4a: "{ COND #( WHEN block4a_flag = abap_true THEN abap_true ) }" | && |block4b: "{ COND #( WHEN block4b_flag = abap_true THEN abap_true ) }" | && |block4c: "{ COND #( WHEN block4c_flag = abap_true THEN abap_true ) }" | TYPE 'I'. AT SELECTION-SCREEN ON BLOCK block3. block3_flag = abap_true. MESSAGE |Event AT SELECTION-SCREEN ON BLOCK block3 raised. Others already raised? | && |block1: "{ COND #( WHEN block1_flag = abap_true THEN abap_true ) }" | && |block2: "{ COND #( WHEN block2_flag = abap_true THEN abap_true ) }" | && |block4a: "{ COND #( WHEN block4a_flag = abap_true THEN abap_true ) }" | && |block4b: "{ COND #( WHEN block4b_flag = abap_true THEN abap_true ) }" | && |block4c: "{ COND #( WHEN block4c_flag = abap_true THEN abap_true ) }" | TYPE 'I'. AT SELECTION-SCREEN ON BLOCK block4a. block4a_flag = abap_true. MESSAGE |Event AT SELECTION-SCREEN ON BLOCK block4a raised. Others already raised? | && |block1: "{ COND #( WHEN block1_flag = abap_true THEN abap_true ) }" | && |block2: "{ COND #( WHEN block2_flag = abap_true THEN abap_true ) }" | && |block3: "{ COND #( WHEN block3_flag = abap_true THEN abap_true ) }" | && |block4b: "{ COND #( WHEN block4b_flag = abap_true THEN abap_true ) }" | && |block4c: "{ COND #( WHEN block4c_flag = abap_true THEN abap_true ) }" | TYPE 'I'. AT SELECTION-SCREEN ON BLOCK block4b. block4b_flag = abap_true. MESSAGE |Event AT SELECTION-SCREEN ON BLOCK block4b raised. Others already raised? | && |block1: "{ COND #( WHEN block1_flag = abap_true THEN abap_true ) }" | && |block2: "{ COND #( WHEN block2_flag = abap_true THEN abap_true ) }" | && |block3: "{ COND #( WHEN block3_flag = abap_true THEN abap_true ) }" | && |block4a: "{ COND #( WHEN block4a_flag = abap_true THEN abap_true ) }" | && |block4c: "{ COND #( WHEN block4c_flag = abap_true THEN abap_true ) }" | TYPE 'I'. AT SELECTION-SCREEN ON BLOCK block4c. block4c_flag = abap_true. MESSAGE |Event AT SELECTION-SCREEN ON BLOCK block4c raised. Others already raised? | && |block1: "{ COND #( WHEN block1_flag = abap_true THEN abap_true ) }" | && |block2: "{ COND #( WHEN block2_flag = abap_true THEN abap_true ) }" | && |block3: "{ COND #( WHEN block3_flag = abap_true THEN abap_true ) }" | && |block4a: "{ COND #( WHEN block4a_flag = abap_true THEN abap_true ) }" | && |block4b: "{ COND #( WHEN block4b_flag = abap_true THEN abap_true ) }" | TYPE 'I'. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |param1: "{ param1 }"|. WRITE / |param2: "{ param2 }"|. WRITE / |param3: "{ param3 }"|. WRITE / |param4: "{ param4 }"|. WRITE / |param5: "{ param5 }"|. WRITE / |param6: "{ param6 }"|. WRITE / |param7: "{ param7 }"|. ``` |
|
Defining tabstrips `SELECTION-SCREEN BEGIN OF TABBED BLOCK ... SELECTION-SCREEN END OF BLOCK ...` and `SELECTION-SCREEN TAB` |
- Within the statement block, you can only specify `SELECTION-SCREEN ... TAB ...` statements (they define tab titles). - Additions to `... TABBED BLOCK ...` statements: - `FOR ... LINES`: Defines the number of lines in the tabstrip area - `NO INTERVALS`: To narrow the size for subscreen dynpros. - Additions to `... TAB ...` statements: - `(...)`: Length specification - `USER-COMMAND`: To assign a function code. See above. - `DEFAULT [PROGRAM ...] SCREEN`: - The tab titles must be assigned a subscreen dynpro. - For the tabstrip areas, structures are implicitly created having the specified name. They have 3 components: `prog`, `dynnr` and `activetab`. Not specifying `DEFAULT ...` means the values must be passed before the selection screen is sent. Find [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapselection-screen_tabbed.htm) more information. - `MODIF ID`: See above | See the example for `SELECTION-SCREEN BEGIN OF SCREEN ... AS SUBSCREEN` that uses `... TABBED BLOCK ...` and `... TAB ...` statements. |
|
Adding pushbuttons in the application toolbar `SELECTION-SCREEN FUNCTION KEY` |
- The statement activates pushbuttons in the application toolbar for specific function codes (`FC0n`). - There are five inactive pushbuttons to which the function codes `FC01`, `FC02` up to `FC05` are assigned. - To enable the pushbutton, include the `TABLES sscrfields.` statement in the code for the interface work area. - When the button is clicked, the `AT SELECTION-SCREEN` event is raised and the function code is passed to `sscrfields-ucomm`, which can be evaluated and reacted upon accordingly. | The code snippet, copyable to a demo program and executable using F8, implements the following: - Five pushbuttons are added to the application toolbar. - To provide text for the buttons, values are assigned to the `sscrfields-functxt_0n` component. - In the `AT SELECTION-SCREEN` event block, `sscrfields-ucomm` is evaluated. Depending on the function code, parameter values are assigned or messages are raised for demonstration purposes. ``` abap PROGRAM. TABLES sscrfields. PARAMETERS param1 TYPE c LENGTH 20. PARAMETERS param2 TYPE c LENGTH 20. PARAMETERS param3 TYPE c LENGTH 20. SELECTION-SCREEN: FUNCTION KEY 1, "Stands for FC01 FUNCTION KEY 2, "FC02 FUNCTION KEY 3, "FC03 FUNCTION KEY 4, "FC04 FUNCTION KEY 5. "FC05 INITIALIZATION. sscrfields-functxt_01 = 'Insert name'. sscrfields-functxt_02 = 'Insert time'. sscrfields-functxt_03 = 'Insert date'. sscrfields-functxt_04 = 'Say hi'. sscrfields-functxt_05 = 'Error message'. AT SELECTION-SCREEN. CASE sscrfields-ucomm. WHEN 'FC01'. param1 = sy-uname. WHEN 'FC02'. param2 = sy-uzeit. WHEN 'FC03'. param3 = sy-datum. WHEN 'FC04'. MESSAGE |Hello { sy-uname }. You clicked the fourth button.| TYPE 'I'. WHEN 'FC05'. MESSAGE |Error message raised by clicking the fifth button.| TYPE 'E'. ENDCASE. START-OF-SELECTION. WRITE / `Inserted values:`. SKIP. WRITE / |param1: "{ param1 }"|. WRITE / |param2: "{ param2 }"|. WRITE / |param3: "{ param3 }"|. ``` |
| Subject/Addition | Notes | Code Snippet |
| Calling a program, ending the current program | - The program name is specified directly. - If the program does not exist, a runtime error occurs. - Without the `AND RETURN` addition, the current [SAP LUW](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_luw_glosry.htm) is terminated. |
The following code snippets, copyable to demo programs and executable using F8 (execute program `zdemo_abap_report`), implements the following:
- Using radio buttons in the calling program, you can determine which `SUBMIT` statement to execute.
- One statement specifies the `AND RETURN` addition, the others do not.
- Regarding the third radiobutton:
- The example is implemented to demonstrate the program interruption triggered by the `AND RETURN` addition. In the calling program, the SAP LUW key is retrieved using a system class before and after the `SUBMIT` statement. Both values are the same, demonstrating that the SAP LUW has been kept and is still the same. However, the called program has its own SAP LUW. The code of the called program also includes the retrieval of the SAP LUW key. This value differs from the SAP LUW key of the calling program, thus, showing that two different SAP LUWs have been started.
- As there is no "returning parameter-like" functionality when returning to the calling program, the called program uses an `EXPORT ... TO MEMORY ID` statement to store the SAP LUW key value in the ABAP memory. For display and demonstration, the calling program retrieves this stored content with an `IMPORT ... TO MEMORY ID` statement. It then writes the content to a list using a `WRITE` statement. Find more information and criteria for the use [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendata_cluster.htm).
`zdemo_abap_report`
``` abap
PROGRAM.
PARAMETERS: noreturn RADIOBUTTON GROUP rbg,
w_return RADIOBUTTON GROUP rbg,
w_retkey RADIOBUTTON GROUP rbg.
START-OF-SELECTION.
CASE 'X'.
WHEN noreturn.
SUBMIT zdemo_abap_report_submit.
"Text will not be written to the list since the calling program is ended.
WRITE / |This text was written to the list in program { sy-repid }.|.
WHEN w_return.
SUBMIT zdemo_abap_report_submit AND RETURN.
"Text will be written to the list since the calling program is only interrupted.
WRITE / |This text was written to the list in program { sy-repid }.|.
WHEN w_retkey.
"SAP LUW key information
DATA(sap_luw_key_calling_prog1) = cl_system_transaction_state=>get_sap_luw_key( ).
SUBMIT zdemo_abap_report_submit AND RETURN.
DATA(sap_luw_key_calling_prog2) = cl_system_transaction_state=>get_sap_luw_key( ).
DATA luw_key_called_prog TYPE sychar32.
IMPORT key = luw_key_called_prog FROM MEMORY ID 'ID4LUWKEY'.
WRITE / |This text was written to the list in program { sy-repid }.|.
SKIP.
ASSERT sap_luw_key_calling_prog1 <> luw_key_called_prog.
WRITE: / |SAP LUW key in calling program (1): { sap_luw_key_calling_prog1 }|.
WRITE: / |SAP LUW key in calling program (2): { sap_luw_key_calling_prog2 }|.
WRITE: / |SAP LUW key in called program: { luw_key_called_prog }|.
ENDCASE.
```
`zdemo_abap_report_submit` ``` abap PROGRAM. START-OF-SELECTION. DATA(sap_luw_key_called_prog) = cl_system_transaction_state=>get_sap_luw_key( ). EXPORT key = sap_luw_key_called_prog TO MEMORY ID 'ID4LUWKEY'. MESSAGE |Hello from program { sy-repid }, { sy-uname }. The SAP LUW key value is "{ sap_luw_key_called_prog }".| && | If you selected the first radiobutton (no "AND RETURN"), you must run the program again to check out more radiobuttons.| TYPE 'I'. ``` |
|
Calling a program, interrupting the current program and return Addition `AND RETURN` |
- The calling program is interrupted. - With the `AND RETURN` addition, the called program starts in a new [internal session](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abeninternal_session_glosry.htm) and has its own [SAP LUW](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_luw_glosry.htm). The current internal session and [SAP LUW](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abensap_luw_glosry.htm) is kept. When the called program is ended, the execution of the calling program continues. - Find [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapsubmit.htm) more information regarding the impact of the involved SAP LUWs. | See above. |
| Dynamically calling a program | - A parenthesized flat character-like data object (literal, constannt or variable) is specified. - The name must be specified in uppercase. - Note the security risks and consequences a program submitted from outside can cause. You can use the class `CL_ABAP_DYN_PRG` to tackle security risks. - As there is no "returning parameter-like" functionality when returning to the calling program, the called program uses an `EXPORT ... TO MEMORY ID` statement to store parameter values in a string table within the ABAP memory. For display and demonstration, the calling program retrieves this stored content with an `IMPORT ... TO MEMORY ID` statement. It then writes the content to a list using `WRITE` statements. Find more information and criteria for the use [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendata_cluster.htm). |
The following code snippets, copyable to demo programs and executable using F8 (execute program `zdemo_abap_report`), implements the following:
- Using radio buttons in the calling program, you can determine which dynamic `SUBMIT` statement to execute.
- Some statements specify the `AND RETURN` addition, some do not.
- Regarding the fourth radiobutton, see the description in the first example.
`zdemo_abap_report`
``` abap
PROGRAM.
PARAMETERS: noreturn RADIOBUTTON GROUP rbg,
no_retdo RADIOBUTTON GROUP rbg,
w_return RADIOBUTTON GROUP rbg,
w_retkey RADIOBUTTON GROUP rbg.
START-OF-SELECTION.
CASE 'X'.
WHEN noreturn.
"Program name specified as literal
SUBMIT ('ZDEMO_ABAP_REPORT_SUBMIT').
"Text will not be written to the list since the calling program is ended.
WRITE / |This text was written to the list in program { sy-repid }.|.
WHEN no_retdo.
"Specifying the program with a variable
DATA prog_name TYPE syrepid VALUE 'ZDEMO_ABAP_REPORT_SUBMIT'.
SUBMIT (prog_name).
"Text will not be written to the list since the calling program is ended.
WRITE / |This text was written to the list in program { sy-repid }.|.
WHEN w_return.
SUBMIT ('ZDEMO_ABAP_REPORT_SUBMIT') AND RETURN.
"Text will be written to the list since the calling program is only interrupted.
WRITE / |This text was written to the list in program { sy-repid }.|.
WHEN w_retkey.
"SAP LUW key information
DATA(sap_luw_key_calling_prog1) = cl_system_transaction_state=>get_sap_luw_key( ).
SUBMIT ('ZDEMO_ABAP_REPORT_SUBMIT') AND RETURN.
DATA(sap_luw_key_calling_prog2) = cl_system_transaction_state=>get_sap_luw_key( ).
DATA luw_key_called_prog TYPE sychar32.
IMPORT key = luw_key_called_prog FROM MEMORY ID 'ID4LUWKEY'.
WRITE / |This text was written to the list in program { sy-repid }.|.
SKIP.
ASSERT sap_luw_key_calling_prog1 <> luw_key_called_prog.
WRITE: / |SAP LUW key in calling program (1): { sap_luw_key_calling_prog1 }|.
WRITE: / |SAP LUW key in calling program (2): { sap_luw_key_calling_prog2 }|.
WRITE: / |SAP LUW key in called program: { luw_key_called_prog }|.
ENDCASE.
```
`zdemo_abap_report_submit` ``` abap PROGRAM. START-OF-SELECTION. DATA(sap_luw_key_called_prog) = cl_system_transaction_state=>get_sap_luw_key( ). EXPORT key = sap_luw_key_called_prog TO MEMORY ID 'ID4LUWKEY'. MESSAGE |Hello from program { sy-repid }, { sy-uname }. The SAP LUW key value is "{ sap_luw_key_called_prog }".| && | If you selected one of the first two radiobuttons (no "AND RETURN"), you must run the program again to check out more radiobuttons.| TYPE 'I'. ``` |
|
Specifying a particular selection screen to be called and display it or not Additions `USING SELECTION-SCREEN` and `VIA SELECTION-SCREEN` |
- `USING SELECTION-SCREEN`: Specifies the selection screen. If the addition is not specified, the standard selection screen 1000 is called. The specified seclection screen must exist, otherwise a runtime error occurs. - `VIA SELECTION-SCREEN`: Determines whether the selection is displayed or not. - The following sections outline options to pass parameter and selection criteria values. |
The following code snippets, copyable to demo programs and executable using F8 (execute program `zdemo_abap_report`), implements the following:
- Using radio buttons in the calling program, you can determine which `SUBMIT` statement to execute.
- All statements use the `AND RETURN` addition.
- Some statements anticipate the `WITH` addition with which you can pass values for parameters and selection criteria.
- As there is no "returning parameter-like" functionality when returning to the calling program, the called program uses an `EXPORT ... TO MEMORY ID` statement to store parameter values in a string table within the ABAP memory. For display and demonstration, the calling program retrieves this stored content with an `IMPORT ... TO MEMORY ID` statement. It then writes the content to a list using `WRITE` statements. Find more information and criteria for the use [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendata_cluster.htm).
`zdemo_abap_report`
``` abap
PROGRAM.
PARAMETERS: use_sel RADIOBUTTON GROUP rbg,
use_selp RADIOBUTTON GROUP rbg,
use_sels RADIOBUTTON GROUP rbg,
sel_via RADIOBUTTON GROUP rbg,
onlyvia RADIOBUTTON GROUP rbg.
DATA param1 TYPE c LENGTH 10.
DATA param2 TYPE c LENGTH 10.
START-OF-SELECTION.
CASE 'X'.
WHEN use_sel.
"In this example, the called selection screen is not displayed. As no parameter values
"are passed (see next example), none of the parameters in the called program are assigned
"values.
SUBMIT zdemo_abap_report_submit USING SELECTION-SCREEN 9000 AND RETURN.
WHEN use_selp.
"The following statement does not specify VIA SELECTION-SCREEN either, but anticipates
"the WITH addition to pass parameter values.
SUBMIT zdemo_abap_report_submit WITH param2 = 'hello'
USING SELECTION-SCREEN 9000 AND RETURN.
WHEN use_sels.
"This example statement explicitly calls the standard selection screen.
SUBMIT zdemo_abap_report_submit WITH param1 = 'hi'
USING SELECTION-SCREEN 1000 AND RETURN.
WHEN sel_via.
"The specified selection screen is called.
SUBMIT zdemo_abap_report_submit USING SELECTION-SCREEN 9000
VIA SELECTION-SCREEN
AND RETURN.
WHEN onlyvia.
"The standard selection screen 1000 is called.
SUBMIT zdemo_abap_report_submit VIA SELECTION-SCREEN
AND RETURN.
ENDCASE.
DATA input_values TYPE string_table.
IMPORT input = input_values FROM MEMORY ID 'DEMO_ID'.
WRITE / |This text was written to the list in program { sy-repid }.|.
LOOP AT input_values INTO DATA(wa).
WRITE / wa.
ENDLOOP.
```
`zdemo_abap_report_submit` ``` abap PROGRAM. PARAMETERS param1 TYPE c LENGTH 10 LOWER CASE. SELECTION-SCREEN BEGIN OF SCREEN 9000. PARAMETERS param2 TYPE c LENGTH 10 LOWER CASE. SELECTION-SCREEN END OF SCREEN 9000. START-OF-SELECTION. DATA input_values TYPE string_table. APPEND |param1: "{ param1 }"| TO input_values. APPEND |param2: "{ param2 }"| TO input_values. EXPORT input = input_values TO MEMORY ID 'DEMO_ID'. MESSAGE |Hello from program { sy-repid }, { sy-uname }. The parameter values are param1 = "{ param1 }" and param2 = "{ param2 }".| TYPE 'I'. ``` |
|
Passing values to a called selection screen Additions `WITH SELECTION-TABLE`, `WITH ...` |
- `WITH SELECTION-TABLE`: Passes values specified in an internal of a special line type (`RSPARAMS`, `RSPARAMSL_255`, without secondary table keys). The line type has specific component, among them: `selname` (parameter name in uppercase), `kind` (`P` for parameters, `S` for selection criteria), `sign`/`option`/`low`/`high` (ranges table components; note that for parameters, the value must be specified for `low`) - `WITH ...` : Supplying individual values - More additions are available. Find more information [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapsubmit_selscreen_parameters.htm): - `WITH FREE SELECTIONS`: For dynamic selections of selection screens of [logical databases](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenlogical_data_base_glosry.htm) - `USING SELECTION-SET`: Passes values of a [selection screen variant](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenvariant_glosry.htm) - `USING SELECTION-SETS OF PROGRAM`: Passes values of a selection screen variant of a particular program |
The following code snippets, copyable to demo programs and executable using F8 (execute program `zdemo_abap_report`), implements the following:
- Using radio buttons in the calling program, you can determine which `SUBMIT` statement to execute.
- The `SUBMIT` statements do not specify the `VIA SELECTION-SCREEN` addition on purpose. Parameter values and selection criteria are predefined in the calling program and then used by the `SUBMIT` statements.
- As there is no "returning parameter-like" functionality when returning to the calling program, the called program uses an `EXPORT ... TO MEMORY ID` statement to store parameter values in a string table within the ABAP memory. For display and demonstration, the calling program retrieves this stored content with an `IMPORT ... TO MEMORY ID` statement. It then writes the content to a list using `WRITE` statements. Find more information and criteria for the use [here](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abendata_cluster.htm).
`zdemo_abap_report`
``` abap
PROGRAM.
PARAMETERS: wseltab1 RADIOBUTTON GROUP rbg,
wseltab2 RADIOBUTTON GROUP rbg,
wseltab3 RADIOBUTTON GROUP rbg,
simple_w RADIOBUTTON GROUP rbg,
with_sel RADIOBUTTON GROUP rbg,
singlrt RADIOBUTTON GROUP rbg,
intv_rt RADIOBUTTON GROUP rbg,
rangest RADIOBUTTON GROUP rbg.
START-OF-SELECTION.
CASE 'X'.
WHEN wseltab1.
DATA seltab1 TYPE TABLE OF rsparams WITH EMPTY KEY.
seltab1 = VALUE #( ( selname = 'PARAM2' kind = 'P' low = 'Test' ) ).
SUBMIT zdemo_abap_report_submit USING SELECTION-SCREEN 9000 WITH SELECTION-TABLE seltab1 AND RETURN.
WHEN wseltab2.
DATA seltab2 TYPE TABLE OF rsparams WITH EMPTY KEY.
seltab2 = VALUE #( ( selname = 'SEL1' kind = 'S' low = 'A' high = 'M' option = 'BT' sign = 'I' ) ).
SUBMIT zdemo_abap_report_submit USING SELECTION-SCREEN 9001 WITH SELECTION-TABLE seltab2 AND RETURN.
WHEN wseltab3.
DATA seltab3 TYPE TABLE OF rsparams WITH EMPTY KEY.
seltab3 = VALUE #( ( selname = 'PARAM3' kind = 'P' low = 'Hello' )
( selname = 'SEL2' kind = 'S' low = 1 high = 10 option = 'BT' sign = 'I' ) ).
SUBMIT zdemo_abap_report_submit USING SELECTION-SCREEN 9002 WITH SELECTION-TABLE seltab3 AND RETURN.
WHEN simple_w.
"Calls the standard selection screen
SUBMIT zdemo_abap_report_submit WITH param1 = 'ABAP' AND RETURN.
WHEN with_sel.
SUBMIT zdemo_abap_report_submit USING SELECTION-SCREEN 9000 WITH param2 = 'lorem' AND RETURN.
WHEN singlrt.
"Single value passed for ranges table
"Note:
"- Specifying SIGN is optional. The default value for sign is 'I'.
"- Specify the comparions operations EQ|NE|CP|NP|GT|GE|LT|LE and =|INCL instead of EQ
SUBMIT zdemo_abap_report_submit USING SELECTION-SCREEN 9001 WITH sel1 = 'A' SIGN 'I' AND RETURN.
WHEN intv_rt.
"Passed interval for ranges table
SUBMIT zdemo_abap_report_submit USING SELECTION-SCREEN 9001 WITH sel1 BETWEEN 'A' AND 'M' SIGN 'I' AND RETURN.
WHEN rangest.
"Passing a ranges table
TYPES c10 TYPE c LENGTH 10.
DATA rangetab TYPE RANGE OF c10.
rangetab = VALUE #( sign = 'I'
option = 'BT' ( low = 'A' high = 'C' )
( low = 'F' high = 'M' )
( low = 'S' high = 'U' )
option = 'GE' ( low = 'X' ) ).
SUBMIT zdemo_abap_report_submit USING SELECTION-SCREEN 9001 WITH sel1 IN rangetab AND RETURN.
ENDCASE.
DATA input_tab TYPE string_table.
IMPORT values = input_tab FROM MEMORY ID 'ID4INPUT'.
LOOP AT input_tab INTO DATA(wa).
SET BLANK LINES ON.
WRITE / wa.
ENDLOOP.
```
`zdemo_abap_report_submit` ``` abap PROGRAM. PARAMETERS param1 TYPE c LENGTH 10 LOWER CASE. SELECTION-SCREEN BEGIN OF SCREEN 9000. PARAMETERS param2 TYPE c LENGTH 10 LOWER CASE. SELECTION-SCREEN END OF SCREEN 9000. DATA txt TYPE c LENGTH 10. SELECTION-SCREEN BEGIN OF SCREEN 9001. SELECT-OPTIONS: sel1 FOR txt. SELECTION-SCREEN END OF SCREEN 9001. DATA num TYPE i. SELECTION-SCREEN BEGIN OF SCREEN 9002. PARAMETERS param3 TYPE c LENGTH 10 LOWER CASE. SELECT-OPTIONS: sel2 FOR num. SELECTION-SCREEN END OF SCREEN 9002. START-OF-SELECTION. DATA input_values TYPE string_table. APPEND |param1: "{ param1 }"| TO input_values. APPEND INITIAL LINE TO input_values. APPEND |param2: "{ param2 }"| TO input_values. APPEND INITIAL LINE TO input_values. APPEND |param3: "{ param3 }"| TO input_values. APPEND INITIAL LINE TO input_values. IF sel1 IS INITIAL. APPEND `No sel1 selection criteria.` TO input_values. ELSE. APPEND `sel1 selection criteria:` TO input_values. LOOP AT sel1 ASSIGNING FIELD-SYMBOL( |
|
Handling the list of the called program Addition `EXPORTING LIST TO MEMORY` |
- After a program has been called, the output statements of that program write to the [basic list](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenbasic_list_glosry.htm). - If this addition is used, the output list is stored in the [ABAP memory](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenabap_memory_glosry.htm) in an internal table of type `abaplist`. If it is not used, the list of the called program is displayed. That's why the examples above do not use `WRITE` statements in the called program. - The addition must be used with `AND RETURN`. - You can access the stored list in the calling program using these function modules: - `LIST_FROM_MEMORY`: Retrieves the list from the ABAP memory in an internal table of type `abaplist` - `WRITE_LIST`: Writes the content of the table (of type `abaplist`) to the current list - `DISPLAY_LIST`: Displays the content the content of the table (of type `abaplist`) in a separate [list dynpro](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abenlist_dynpro_glosry.htm) - `LIST_TO_ASCI`: Converts the content the content of the table (of type `abaplist`) to ASCII representation - Find more information in the [ABAP Keyword Documentation](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapsubmit_list_options.htm). More additions are available to handle lists: - `TO SAP-SPOOL`: Sends the output list to the SAP spool system as spool list - `LINE-SIZE`: Defines the line width of the basic list - `LINE-COUNT`: Defines the page length the basic list |
The following code snippets, copyable to demo programs and executable using F8 (execute program `zdemo_abap_report`), implements the following:
- Using radio buttons in the calling program, you can determine which `SUBMIT` statement to execute and how the list is handled afterwards.
- The examples cover the calling of the function modules mentioned above.
`zdemo_abap_report`
```abap
PROGRAM.
PARAMETERS: expwrite RADIOBUTTON GROUP rbg,
expdispl RADIOBUTTON GROUP rbg,
expascii RADIOBUTTON GROUP rbg.
DATA list_tab TYPE TABLE OF abaplist.
START-OF-SELECTION.
CASE 'X'.
WHEN expwrite.
SUBMIT zdemo_abap_report_submit WITH param = 'WRITE_LIST'
EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = list_tab
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
CALL FUNCTION 'WRITE_LIST'
TABLES
listobject = list_tab.
ELSE.
WRITE / `List not found.`.
ENDIF.
WRITE / |This text was written in the calling program { sy-repid }.|.
WHEN expdispl.
SUBMIT zdemo_abap_report_submit WITH param = 'DISPLAY_LIST'
EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = list_tab
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
CALL FUNCTION 'DISPLAY_LIST'
TABLES
listobject = list_tab
EXCEPTIONS
empty_list = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE / `Cannot display list.`.
ENDIF.
ELSE.
WRITE / `List not found.`.
ENDIF.
WRITE / |This text was written in the calling program { sy-repid }.|.
WHEN expascii.
SUBMIT zdemo_abap_report_submit WITH param = 'LIST_TO_ASCI'
EXPORTING LIST TO MEMORY AND RETURN.
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = list_tab
EXCEPTIONS
not_found = 1
OTHERS = 2.
TYPES c255 TYPE c LENGTH 255.
DATA list_ascii TYPE TABLE OF c255 WITH EMPTY KEY.
IF sy-subrc = 0.
CALL FUNCTION 'LIST_TO_ASCI'
TABLES
listasci = list_ascii
listobject = list_tab
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE / `Cannot convert list.`.
ELSE.
WRITE / `List converted to ASCII representation:`.
LOOP AT list_ascii INTO DATA(wa_ascii).
WRITE / wa_ascii.
ENDLOOP.
ENDIF.
ELSE.
WRITE / `List not found.`.
ENDIF.
SKIP.
WRITE / |This text was written in the calling program { sy-repid }.|.
ENDCASE.
```
`zdemo_abap_report_submit` ```abap PROGRAM. PARAMETERS param TYPE c LENGTH 20. START-OF-SELECTION. IF param IS INITIAL. WRITE / `No value passed for parameter "param".`. ELSE. WRITE / |param: "{ param }"|. ENDIF. SKIP. WRITE / |Some text written in the called program { sy-repid }|. DO 10 TIMES. WRITE / |Text no. { sy-index } added to list.|. ENDDO. ``` |
|
Running a program in the background Addition `VIA JOB ... NUMBER ...` |
- Must be used with `AND RETURN` - Background jobs can be created programmatically using function modules. The example uses some of them, e.g. for creating, completing, and analyzing background jobs. - See the documentation for the [details](https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapsubmit_via_job.htm). |
The following code snippets, copyable to demo programs and executable using F8 (execute program `zdemo_abap_report`), implements the following:
- A program is scheduled as background task, and then completed and released.
- The program execution is interrupted for one second. Then, function modules are used to analyze the background job.
- Using the `cl_demo_output` class for demo output purposes, text and the content of data objects are displayed.
- The transaction `SMX` is called to view the job overview. In the *Spool* column, you can click the icon to display the list output. On the next screen, the list of spool request is displayed. Choose the icon in the *Type* column. The `sy-batch` should be not initial denoting the run in the background.
`zdemo_abap_report`
```abap
PROGRAM.
PARAMETERS callbgr TYPE c AS CHECKBOX DEFAULT 'X'.
DATA: number TYPE tbtcjob-jobcount,
name TYPE tbtcjob-jobname VALUE 'DEMO_JOB',
print_parameters TYPE pri_params.
START-OF-SELECTION.
IF callbgr IS INITIAL.
MESSAGE `You chose not to run the called program in the background.` TYPE 'I'.
SUBMIT zdemo_abap_report_submit WITH param = 'not in background' AND RETURN.
ELSE.
MESSAGE `You chose to run the called program in the background.` TYPE 'I'.
"Creating background job
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = name
IMPORTING
jobcount = number
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc = 0.
"Scheduling a program as a background task using the number created previously
"and the name specified
SUBMIT zdemo_abap_report_submit WITH param = 'in background'
TO SAP-SPOOL
SPOOL PARAMETERS print_parameters
WITHOUT SPOOL DYNPRO
VIA JOB name NUMBER number
AND RETURN.
IF sy-subrc = 0.
"Completing the background job
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = number
jobname = name
strtimmed = 'X'
EXCEPTIONS
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
OTHERS = 8.
IF sy-subrc = 0.
cl_demo_output=>write( |The job { name } was submitted with number { number }| ).
"Interrupting the program shortly
WAIT UP TO 1 SECONDS.
"Analyzing the background job
DATA: BEGIN OF jobstate,
aborted TYPE c LENGTH 1,
finished TYPE c LENGTH 1,
preliminary TYPE c LENGTH 1,
ready TYPE c LENGTH 1,
running TYPE c LENGTH 1,
scheduled TYPE c LENGTH 1,
suspended TYPE c LENGTH 1,
other TYPE c LENGTH 1,
END OF jobstate.
CALL FUNCTION 'SHOW_JOBSTATE'
EXPORTING
jobcount = number
jobname = name
IMPORTING
aborted = jobstate-aborted
finished = jobstate-finished
preliminary = jobstate-preliminary
ready = jobstate-ready
running = jobstate-running
scheduled = jobstate-scheduled
suspended = jobstate-suspended
other = jobstate-other
EXCEPTIONS
jobcount_missing = 1
jobname_missing = 2
job_notex = 3
OTHERS = 4.
IF sy-subrc = 0.
cl_demo_output=>write( jobstate ).
ELSE.
cl_demo_output=>write( `Exception in SHOW_JOBSTATE` ).
ENDIF.
DATA joblog TYPE TABLE OF tbtc5.
CALL FUNCTION 'BP_JOBLOG_READ'
EXPORTING
jobcount = number
jobname = name
TABLES
joblogtbl = joblog
EXCEPTIONS
cant_read_joblog = 1
jobcount_missing = 2
joblog_does_not_exist = 3
joblog_is_empty = 4
joblog_name_missing = 5
jobname_missing = 6
job_does_not_exist = 7
OTHERS = 8.
IF sy-subrc = 0.
cl_demo_output=>write( joblog ).
ELSE.
cl_demo_output=>write( `Exception in BP_JOBLOG_READ` ).
ENDIF.
ELSE.
cl_demo_output=>write( `Exception in JOB_CLOSE` ).
ENDIF.
ELSE.
DATA(msg) = cl_abap_submit_handling=>get_error_message( ).
cl_demo_output=>write( msg ).
ENDIF.
ENDIF.
cl_demo_output=>display( ).
MESSAGE `You are redirected to transaction SMX.` TYPE 'I'.
CALL TRANSACTION 'SMX'.
ENDIF.
```
`zdemo_abap_report_submit` ```abap PROGRAM. PARAMETERS param TYPE c LENGTH 20 LOWER CASE. START-OF-SELECTION. IF param IS INITIAL. WRITE / `No value passed for parameter "param".`. ELSE. WRITE / |param: "{ param }"|. ENDIF. SKIP. WRITE / |Some text written in the called program { sy-repid }|. DO 10 TIMES. WRITE / |Text no. { sy-index } added to list.|. ENDDO. SKIP. WRITE / |Value of sy-batch: "{ sy-batch }"|. ``` |