Drop Down box in Selection Screen in SAP ABAP

How to add drop-down box in selection screen using SAP ABAP Programming ? Using listbox in SAP ABAP

+ -

Some times we may need to print drop down on selection-screen, and need to catch the selected value for execution logic, the below example will explain how to use drop-down in selection-screen in SAP ABAP.

To display drop down list we have to use type-group VRM as type-pools.

Drop Down list on Selection Screen in SAP ABAP

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.

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 43 People out of 61 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →