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 shocould consists of 2 columns, the key column is filled automatically by the system. SAP recommends Value List field shocould 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
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 shoshould 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.