The s10dropdownlist() method is implicitly called by the S10 framework when the
dropdown list for an attribute is requested in HTML for a class attribute
"attr" via "attr@dropdownlist". Example:
HTML
<label
class='label
output'
name='land1'></label><br
/>
<select
class='inputselect'
size="1"
name='land1'
style='width:
240px;'
data-s10dropdownlist='land1@dropdownlist'>
</select>
The S10 framework automatically builds the dropdown list from the information
in the SAP Data dictionary. You can specify in HTML whether the internal codes
should also be displayed, or only the texts. Example:
HTML
<label
class='label
output'
name='bsark'></label><br
/> <select
class='inputselect'
size="1"
name='bsark'
style='width:
240px;'
data-s10dropdownlist='bsark@dropdownlist'
data-s10options='hidekeys'> </select>
s10dropdownlist() always returns the values in alphabetical order of the keys.
If you turn off the display of the keys in HTML, the dropdown list will be
displayed sorted by the text:
The dropdown list is returned as a string in which the key and the text are
separated by a TAB character and the entries by a line feed. Here is the display
of the country list in the ABAP Debugger:
If the default dropdown list contains too many values, you can include a value
list as a filter. Since the call to s10dropdownlist() for the value list in
HTML is implicitly made by the S10 framework, this requires overriding the
s10dropdownlist() method in your class.
We show the procedure using the
country list and assume that you only want to offer a selection of countries in
the dropdown list for selection.
HTML
<label
class='label
output'
name='land1'></label><br
/>
<select
class='inputselect'
size="1"
name='land1'
style='width:
240px;'
data-s10dropdownlist='countries01@dropdownlist'
data-s10options='hidekeys'>
</select>
ABAP methods: s10dropdownlist redefinition.
* redefinition of s10dropdownlist() for certain attributes method s10dropdownlist.
case to_lower( attrname ). when 'countries01'. ddlstring = super->s10dropdownlist( exporting attrname = 'land1' valuelist = 'AT,AU,BE,CA,CH,DE,FR,IT' ).
* call up super method for all other attributes when others. ddlstring = super->s10dropdownlist( exporting attrname = attrname valuelist = valuelist ). endcase.
endmethod.
Dynamically generated lists are also possible. For example, when selecting
customers, it would make sense to offer only those countries in which there
actually are customers. We can either implement this again with the same inheritance
mechanism or build the list ourselves without s10dropdownlist(). We show both
methods here.
Method 1 (Redefinition of s10dropdownlist)
HTML
<label
class='label
output'
name='land1'></label><br
/>
<select
class='inputselect'
size="1"
name='land1'
style='width:
240px;'
data-s10dropdownlist='countries02@dropdownlist'
data-s10options='hidekeys'>
</select>
ABAP methods: s10dropdownlist redefinition.
* redefinition of s10dropdownlist() for certain attributes method s10dropdownlist.
case to_lower( attrname ). when 'countries01'. ddlstring = super->s10dropdownlist( exporting attrname = 'land1' valuelist = 'AT,AU,BE,CA,CH,DE,FR,IT' ).
when 'countries02'.
* build up country code list from existing customers data: valuelist02 type string, tabland1
type table of kna1-land1.
select distinct land1 from kna1 into table tabland1. concatenate lines of tabland1 into valuelist02 separated by ','.
ddlstring = super->s10dropdownlist(
exporting attrname = 'land1' valuelist = valuelist02 ).
* call up super method for all other attributes when others. ddlstring = super->s10dropdownlist( exporting attrname = attrname valuelist = valuelist ). endcase.
endmethod.
Method 2 (without s10dropdownlist)
HTML
<label
class='label
output'
name='land1'></label><br
/>
<select
class='inputselect'
size="1"
name='land1'
style='width:
240px;'
data-s10dropdownlist='ddlcountries02'
data-s10options='hidekeys'>
</select>
ABAP
data: ddlcountries02 type string.
methods: build_ddlcountries02
exporting ddlcountries02 type string.
method build_ddlcountries02. clear ddlcountries02.
data: land1 type kna1-land1, landx type t005t-landx.
select distinct kna1~land1 t005t~landx into (land1,landx) from kna1 join t005t on kna1~land1 = t005t~land1 and t005t~spras = sy-langu order by kna1~land1.
ddlcountries02 = ddlcountries02
&& land1 && cl_abap_char_utilities=>horizontal_tab && landx && cl_abap_char_utilities=>cr_lf. endselect. endmethod.
|