Copyright 2021 - BV TallVision IT

Selection screens also support listbox or dropdown list selection for parameters. If the number of parameter options is limited (<100) and the user is asked to select a single value (parameter value), the listbox can come in handy. It's all linked to DDIC values, unless you supply your own values. Here's how.

The most commonly used way to implement the listbox is as follows: 

PARAMETERS pa_mine TYPE spfli-carrid 
  AS LISTBOX VISIBLE LENGTH 20. 

If you don't instruct it what the visible length should be, you'll get the syntax error - The "AS LISTBOX" addition can only be used with "VISIBLE LENGTH" - which explains the situation nicely (note however: the dutch translation explains a totally different situation). The field will be displayed with values and kets from the SPFLI table. It's possible to set a default value (option DEFAULT 'LH') and it is also possible to set a USER-COMMAND code, which can be processed further in AT SELECTION-SCREEN.block - when the user selects a value, abap logic can be executed immediately - so the selected value can e.g. be used with other values/selections on the selection screen.

If you need to create your own list of possible values, have a look at this example:

TYPE-POOLS: vrm.

PARAMETERS: pa_mine(1)
  AS LISTBOX VISIBLE LENGTH 20.

AT SELECTION-SCREEN OUTPUT.

  DATA: lt_list TYPE vrm_values,
        lw_list LIKE LINE OF lt_list.

  lw_list-key = 'A'.
  lw_list-text = 'First letter'.
  APPEND lw_list TO lt_list.
  lw_list-key = 'B'.
  lw_list-text = 'Second letter'.
  APPEND lw_list TO lt_list.
  lw_list-key = 'C'.
  lw_list-text = 'Third letter'.
  APPEND lw_list TO lt_list.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = 'PA_MINE'
      values = lt_list.

This will show up as 

Elaborating on the above example, the values from a select option could be listed as possible values for a list box parameter, as follows:

TYPE-POOLS: vrm.
TABLES: dd02l.

SELECT-OPTIONS: so_table FOR dd02l-tabname NO INTERVALS.

PARAMETERS: pa_mine(20)
  AS LISTBOX VISIBLE LENGTH 30.

AT SELECTION-SCREEN.

  DATA: lt_list TYPE vrm_values,
        lw_list LIKE LINE OF lt_list,
        lt_dd02t TYPE STANDARD TABLE OF dd02t,
        lw_dd02t TYPE dd02t.

  CLEAR lt_list[].
  SELECT * FROM dd02t INTO TABLE lt_dd02t
    UP TO 10 ROWS
    WHERE tabname IN so_table AND
          ddlanguage = sy-langu.
    IF sy-subrc = 0.
      LOOP AT lt_dd02t INTO lw_dd02t.
        lw_list-key = lw_dd02t-tabname.
        lw_list-text = lw_dd02t-ddtext.
        APPEND lw_list TO lt_list.
      ENDLOOP.
    ENDIF.

    CALL FUNCTION 'VRM_SET_VALUES'
      EXPORTING
        id     = 'PA_MINE'
        values = lt_list.

Which would show as