'How to set the default value and read the selected value of a Dropdown Listbox
So I've added a field with the Dropdown type as Listbox via Screen Painter (SE51).
I've binded the data to the dropdown using the PBO and the VRM_SET_VALUES function.
I have 2 problems with this;
- How do you set a selected value to the binded data?
- How do you get the value selected by the user.
Data is bound to the dropdown using the following code;
LOOP AT it_zzdelay_text INTO wa_zzdelay_text.
wa_listbox-key = wa_zzdelay_text-zz_delay_reason.
wa_listbox-text = wa_zzdelay_text-zz_delay_reason_text.
APPEND wa_listbox TO it_listbox.
ENDLOOP.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'ZZ_DELAY_REASON'
values = it_listbox.
The zz_delay_reason is the unique key and the zz_delay_reason_text is the accompanying text.
Solution 1:[1]
Update:
According to your code, the field on the screen should be: ZZ_DELAY_REASON And you also need a global variant with the name.
Then you can Set/Get key value in PBO/PAI: Set value: ZZ_DELAY_REASON = 'KEY'.
Get Selected Value(key): lv_key = ZZ_DELAY_REASON
======================================================
When select list is set by VRM_SET_VALUES, you may notice it is a "Key-Value" pair. The field "KEY" is filled into the screen field value when the user selects drop box.
I could provide detailed information if you attach your code in this question.
Solution 2:[2]
Firstly, several prerequisites are to be met to make a functional drop-down:
- You item table should have type
vrm_values - Values that are showed in the list should be in field
textof the item line. Key should be in fieldkey. - PARAMETER should have type
LISTBOX.
After all that is done, answers for your questions would be:
- Relation of KEY-VALUE is done via
vrm_valuestype. Each line of this type is an drop-down item, wheretextis a visible text, andkeyis key. - Parameter automatically gets the key value after user selects the item in the listbox.
Here is the sample code:
REPORT drop-down.
TYPE-POOLS: vrm.
PARAMETERS p_werks LIKE t001w-werks VISIBLE LENGTH 20 AS LISTBOX OBLIGATORY.
DATA: t_werks TYPE vrm_values,
w_line LIKE LINE OF t_werks.
INITIALIZATION.
SELECT werks name1
FROM t001w INTO (w_line-key, w_line-text).
APPEND w_line TO t_werks.
ENDSELECT.
AT SELECTION-SCREEN OUTPUT.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_WERKS'
values = t_werks.
END-OF-SELECTION.
WRITE: / 'Selected factory:', p_werks.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 |

