SAP ABAP 使用 Dropdown List Box 的方法

Drop down List box in SAP ABAP explained .

LIST BOX                     
Drop down list box can be created in a dialog screen(SE51) as well as selection screen.
  The sap list box allows to select a value from the list but we cannot enter our own value in the list box .The value list that will be displayed consists of two
fields TEXT field of TYPE 80(C) and internal KEY field of TYPE 40(C).
 
 In screen painter to create a input/output field into list box we use
 'L" as a value for dropdown attribute for the i/o field.
 In screen painter to determine the type of method that will be used to fill the value
list we use the attribute value list.
If it is blank  the value list will be filled by the first column of the input help assigned to the screen field.This input help can be defined in the ABAP Dictionary, on screen using SELECT,VALUES screen statements or in event POV (PROCESS ON VALUE-REQUEST ) and the input help that will be passed to the field should consists of 2 columns ,the key column is filled automatically by the system.SAP recommends value list field should be blank.
or
The value  can be 'A' meaning that the value list will be filled in the event PBO(PROCESS BEFORE OUTPUT) or before the screen is displayed.In this method we use function module VRM_SET_VALUES to fill the values and pass it to the i/o field.
 If a function code is attached to the list box the selection of a value triggers a PAI
otherwise PAI will not trigger.

LIST BOX in SELECTION SCREEN

  List Box is created in selection screen using PARAMETERS staement
with AS LISTBOX addition other attributes like VISIBLE LENGTH (width of listbox)
can be specified with the declaration.
PARAMETERS name(n) AS LISTBOX VISIBLE LENGTH n.
 Here n is an integer and name is the name of parameter.
 To populate the value list we use the FM VRM_SET_VALUES  and the
selection screen event AT SELECTION-SCREEN OUTPUT is used to write the code to fill it.
VRM_SET_VALUES    
 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
we should declare TYPE-POOLS VRM before using this FM.
 
 Some important types declared in the VRM type group are
VRM_ID
   It refers to the name of the input/output field associated with list box
VRM_VALUES
  It refers to the internal table consisting of two fields TEXT(80C) and KEY(40)C
that will be used to create the list values.
 
CALL FUNCTION 'VRM_SET_VALUES'
  EXPORTING
      ID                =  name of screen element ,it is of TYPE VRM_ID
      VALUES      =  internal table containing values,of TYPE VRM_VALUES

 
 
LIST BOX with value list from input help
 In this example the screen element attribute value list is set to blank as such the value list will be filled with the 1st column of the input help,We use PROCESS ON VALUE-REQUEST event to pass the value list  to the listbox.In the MODULE call used to fill the value list we can use FM like F4IF_INT_TABLE_VALUE_REQUEST to create input help as explained in the input help.The value of first column will be shown in the field when selected.
 
PROCESS ON VALUE-REQUEST
FIELD list MODULE fill_list_100
 
FIELD list MODULE fill_list_100 INPUT
SELECT f1 f2 FROM table INTO int
 
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
       EXPORTING
            retfield        = 'input/output screen field'
            value_org       = 'S'
       TABLES
            value_tab       = itab "it contains 2 fields that will be shown in the list box
       EXCEPTIONS
            parameter_error = 1
            no_values_found = 2
            OTHERS          = 3.
  IF sy-subrc <> 0.
    ...
ENDIF.
ENDMODULE.

 
VALUE LIST CREATED IN PBO
 
In this method we set the value list attribute to 'A'.The value list will be filled in the PBO by using FM VRM_SET_VALUES .
 
TYPE-POOLS : VRM
DATA : field_id TYPE VRM_ID ,
            values  TYPE VRM_VALUES,
             value   LIKE LINE OF values.
 
PROCESS BEFORE OUTPUT
MODULE list_fill_100
 
MODULE list_fill_100 OUTPUT
SELECT f1 f2 f3  FROM tab WHERE condition.
value-KEY = f1.
value-TEXT = f2
APPEND value TO VALUES
 
CALL FUNCTION 'VRM_SET_VALUES'
       EXPORTING
            id     = 'i/o screen field'
            values = values.
 
ENDMODULE.


LIST BOX with Selection Screen
 For this the FM VRM_SET_VALUES is used to fill the value table and is passed to the parameter created with TYPE LISTBOX in the selection screen event
AT SELECTION-SCREEN.
 
PROGRAM zlist
TYPE-POOLS : VRM.
DATA: param TYPE vrm_id,
       values     TYPE vrm_values,
       value LIKE LINE OF values.

PARAMETERS: p_name(10) AS LISTBOX VISIBLE LENGTH 10.
AT SELECTION-SCREEN OUTPUT.
  param = 'P_NAME'.
  value-key = '1'.
  value-text = 'JOHN'.
  APPEND value TO values.
  value-key = '2'.
  value-text = 'PETER'.
  APPEND value TO values.
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING id     = param
              values = values.

你可能感兴趣的:(SAP ABAP 使用 Dropdown List Box 的方法)