Dropdown in Selection screen code example

Example: Dropdown in Selection screen

REPORT  ZSAPN_DROP_DOWN_SS.

TYPE-POOLS: VRM. " Use type group VRM for list

DATA: IT_LIST     TYPE VRM_VALUES.
DATA: WA_LIST    TYPE VRM_VALUE.
DATA: IT_VALUES   TYPE TABLE OF DYNPREAD,
      WA_VALUES  TYPE DYNPREAD.

DATA: LV_SELECTED_VALUE(10) TYPE C.
*--------------------------------------------------------------*
*Selection-Screen
*--------------------------------------------------------------*
PARAMETERS: COLORS TYPE C AS LISTBOX VISIBLE LENGTH 20. "Parameter
*--------------------------------------------------------------*
*Initialization
*--------------------------------------------------------------*
INITIALIZATION. "initialize values to drop down list
  WA_LIST-KEY = '1'.
  WA_LIST-TEXT = 'Green'.
  APPEND WA_LIST TO IT_LIST.
  WA_LIST-KEY = '2'.
  WA_LIST-TEXT = 'Blue'.
  APPEND WA_LIST TO IT_LIST.
  WA_LIST-KEY = '3'.
  WA_LIST-TEXT = 'Orange'.
  APPEND WA_LIST TO IT_LIST.
  WA_LIST-KEY = '4'.
  WA_LIST-TEXT = 'Gray'.
  APPEND WA_LIST TO IT_LIST.
  WA_LIST-KEY = '5'.
  WA_LIST-TEXT = 'White'.
  APPEND WA_LIST TO IT_LIST.
  WA_LIST-KEY = '6'.
  WA_LIST-TEXT = 'Yellow'.
  APPEND WA_LIST TO IT_LIST.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      ID              = 'COLORS'
      VALUES          = IT_LIST
    EXCEPTIONS
      ID_ILLEGAL_NAME = 1
      OTHERS          = 2.


*--------------------------------------------------------------*
*At Selection Screen
*--------------------------------------------------------------*
AT SELECTION-SCREEN ON COLORS.
  CLEAR: WA_VALUES, IT_VALUES.
  REFRESH IT_VALUES.
  WA_VALUES-FIELDNAME = 'COLORS'.
  APPEND WA_VALUES TO IT_VALUES.
  CALL FUNCTION 'DYNP_VALUES_READ'
    EXPORTING
      DYNAME             = SY-CPROG
      DYNUMB             = SY-DYNNR
      TRANSLATE_TO_UPPER = 'X'
    TABLES
      DYNPFIELDS         = IT_VALUES.

  READ TABLE IT_VALUES INDEX 1 INTO WA_VALUES.
  IF SY-SUBRC = 0 AND WA_VALUES-FIELDVALUE IS NOT INITIAL.
    READ TABLE IT_LIST INTO WA_LIST
                      WITH KEY KEY = WA_VALUES-FIELDVALUE.
    IF SY-SUBRC = 0.
      LV_SELECTED_VALUE = WA_LIST-TEXT.
    ENDIF.
  ENDIF.
*--------------------------------------------------------------*
*Start of Selection
*--------------------------------------------------------------*
START-OF-SELECTION.
  WRITE:/ LV_SELECTED_VALUE.

Tags:

Sql Example