Overview
When selecting data for a list, it is often useful to specify not only a single value, for example a customer number, but a whole list of values.

In ABAP, it is possible to create an attribute of the type "r type range of ....", which is used for flexible inclusion of the value set. Such "range" objects are supported in ABAP both in if-queries ("if x in r") and in database accesses ("select ... where x in r"). Besides a list of values, the range data type can also store intervals as well as additional conditions, for example masking or excluding values.

The S10 framework supports the range data type directly in the user interface, so that the implementation in HTML is consistent and simple.

Example
In the selection of sales orders, we give the user the option to enter one or more item numbers. We then select only those orders in which one of the specified articles has been ordered.

For the user it looks like this: He can enter a single article number in an input field "Material"; the corresponding orders are then selected:

 

The input field is marked as a range input by the table symbol shown on the right. Clicking on the table symbol displays the "Range pop-up" in which any number of values, intervals and further conditions can be entered:

With "Apply" the selection is accepted and the new list is displayed:

The input field can no longer be changed directly and is displayed with the value "*". As soon as all values in the range pop-up are deleted except for a single value, an entry can again be made directly in the field without going via the range pop-up.

 

Implementation
In the ABAP class, define an attribute of the type "range of...". In HTML, specify the CSS class "range":

HTML
 
<input class="input range" name="matnr_range“
    
style="width:150px" onchange="S10Enter();" />

ABAP
  data:
     
matnr_range type range of vbap-matnr.


You can use the entered values in an ABAP select statement, for example:

select
     …       
    
from vbak join vbap
           
on vbak~vbeln vbap~vbeln

          
where vbap~matnr in @matnr_range
          
and  ... 

 

Upload and Download
Instead of entering the values manually, the user can upload them from a local text file by clicking on the arrow symbol:

The text file must contain one line per value. If intervals are involved or special selection conditions are active, the format is as follows:

1st column: "I "or "E" for inclusive or exclusive.
2nd column: one of the operators defined by SAP "EQ", "NE", "BT", "CP", "LE", "GT", ...
3rd column: the value
4th column: single value, if it is an interval, otherwise empty.

The tab character is used as the separator between the columns.

Example:

After uploading, it will look like this:

In the opposite direction, the "Download" creates a text file in the described format.

 

Value help
You activate the value help in HTML via the CSS class "valuehelp":

HTML
 
<input class="input range valuehelp" name="matnr_range“
    
style="width:150px" onchange="S10Enter();" />

The value help symbol is then displayed in the input fields of the range pop-up. A click on the value help symbol calls the ABAP method "on_valuehelp_...", in the example "on_valuehelp_matnr_range". The method can then start a value help dialogue and then returns the selected value, which is inserted in the Range popup in the output field:

method on_valuehelp_matnr_range.

    
datamymatnr type vbap-matnr.

*   call value help
   
mymatnr material=>valuehelp( ).

set selected material number
   s10valuehelpreturn
mymatnr ).

  
endmethod.

 


Use in build methods
So that a list is rebuilt if something has changed in the values of the range attribute, you can include the range attribute as an import parameter of a build method.

There is a small syntactical problem in ABAP, because the notation with "type range of ..." is not possible here:

methods:
      
build_allorders
        
importing
          
orders_maxrowcount type string
          orders_years          
type string
          
orders_minvalue       type string
          
matnr_range           type range of vbpa-matnr  "Synaxfehler!
        
exporting
          
allorders             type table.

Remedy: Pass the attribute with "type table". This works because the range type is implemented internally as a standard table:

methods:
      
build_allorders
        
importing
          
orders_maxrowcount type string
          orders_years          
type string
          
orders_minvalue       type string
          
matnr_range           type table
        
exporting
          
allorders             type table.

 

 

Alternative: You create your own type in your class and use it in all places:

types:
      
matrange type range of vbap-matnr.

...

 data:
     
matnr_range type matrange.

...

methods:
      
build_allorders
        
importing
          
orders_maxrowcount type string
          orders_years          
type string
          
orders_minvalue       type string
          
matnr_range           type matrange
        
exporting
          
allorders             type table.

Format conversions
The conversion between external and internal format is automatic. For example, if the user enters the interval "1 to 50", "00000000000001" to "00000000000050" is stored in the Range object, as well as in the reverse direction.

This means for the implementation in ABAP:

  • Always work with the appropriate "type range of ...", e.g. do not allow material numbers to be entered in an attribute with "type range of kna1-kunnr". This would work for e.g. "M-01", but not for "123", because the customer number has 10 digits and the material number 18 digits, both with leading zeros.

  • You can also fill a range object in the ABAP program; these values then appear in the range pop-up. However, always use the appropriate (internal) formats when filling; the S10 Framework converts them into external format for display in the range popup.

Components: S10 Framework