Friday, April 20, 2012

List Box in Selection Screen

A List Box is created in the selection screen using PARAMETERS statement with the AS LISTBOX addition. Other attributes like VISIBLE LENGTH (width of listbox) can be specified with the declaration.
The function module VRM_SET_VALUES is used to fill the value list associated with a List Box .This FM uses types which are declared in type group VRM. So the type pool should be declared VRM before using this FM.


Sample Program:


TYPE-POOLS : vrm.
TABLES:vbak,vbap.
DATA: wa_vbak TYPE vbak,
      it_vbak TYPE table of vbak,
      wa_vbap TYPE vbap,
      it_vbap TYPE table of vbap.
DATA: li_list TYPE vrm_values ,     "Listbox values
      l_value LIKE LINE OF li_list.
PARAMETERS: p_test(20) AS LISTBOX VISIBLE LENGTH 60 MODIF ID DAT.
INITIALIZATION.AT SELECTION-SCREEN OUTPUT.
  PERFORM get_data.   "Get data for the listbox options
  LOOP AT it_vbak into wa_vbak.
    l_value-key = wa_vbak-vbeln .
    l_value-text = wa_vbak-vbeln .
    APPEND l_value TO li_list.
    clear wa_vbak.
  ENDLOOP.
  CALL FUNCTION 'VRM_SET_VALUES'  "Populate the listbox parameter
    EXPORTING
      id              = 'P_TEST'
      values          = li_list
    EXCEPTIONS
      id_illegal_name = 1
      OTHERS          = 2.
START-OF-SELECTION.
  SELECT vbeln
  matnr
  meins
  FROM vbap
  INTO CORRESPONDING FIELDS OF TABLE it_vbap
  WHERE vbeln = p_test.
  LOOP AT it_vbap into wa_vbap.
    WRITE :/ wa_vbap-vbeln, wa_vbap-matnr,wa_vbap-meins.
    clear wa_vbap.
  ENDLOOP.*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_data .
  SELECT vbeln FROM vbak
  INTO CORRESPONDING FIELDS OF TABLE it_vbak.
ENDFORM. " get_Data

1 comment: