Using Views with Model classes

Views enable us to have an alternative Query and Buffer on data held in a Model class as shown in the document “Using Model classes to simplify data access from custom code”. The behavior is similar to .NET DataTable and DataView.

Views can be used to query and manipulate data contained in a DatasetModel class without the requirement to populate the Model from the backend each time.


Creating a new instance of a View

To create an instance of a View we just need to call the CreateView method of the TableModel class of a DatasetModel. It returns a new instance of the same TableModel but with ModelType ViewModel property of type Consultingwerk.OERA.TableModelTypeEnum.

DEFINE VARIABLE oCustomerView AS Test.ModelClasses.CustomerTableModel NO-UNDO.

oCustomerView = oCustomerDatasetModel:Customer:CreateView ().


Applying a filter to the View

Due to the fact that a View is a TableModel, the filtering is done in the same way as filtering on the original TableModel/DatasetModel. The only difference is that calling the Fill method will only open a Query on the data already contained in the Model and not cause data to be retrieved from the backend.

Each TableModel instance has a property called “Filter” that references a specialized filter class for the table. These filter classes provide an individual property per field that allows you to define queries in a describing manner. 

The provided filter classes are located in the Consultingwerk.OERA.ModelFilter package: 

IModelFilterTarget

Abstracts the access from the ModelFilter classes to the  TableModel for invoking the Filter 

TableModelFilter

Abstract base class for generated TableModelFilter classes 

CharacterFilter

Provides Filter methods for CHARACTER Buffer Fields 

DateFilter

Provides Filter methods for DATE Buffer Fields 

DateTimeFilter

Provides Filter methods for DATETIME Buffer Fields 

DateTimeTzFilter 

Provides Filter methods for DATETIME-TZ Buffer Fields 

DecimalFilter

Provides Filter methods for DECIMAL Buffer Fields 

Int64Filter

Provides Filter methods for INT64 Buffer Fields 

IntegerFilter

Provides Filter methods for INTEGER Buffer Fields 

LogicalFilter 

Provides Filter methods for LOGICAL Buffer Fields 


As an example I want to have a list of all german customers whose name begins with “L”.

DEFINE VARIABLE oCustomerDatasetModel AS Test.ModelClasses.CustomerDatasetModel NO-UNDO.

oCustomerDatasetModel = NEW Test.ModelClasses.CustomerDatasetModel ().

oCustomerDatasetModel:Customer:Filter:Country:EQ ("Germany").
oCustomerDatasetModel:Customer:Filter:Name:Begins ("L").

oCustomerDatasetModel:Customer:Fill(). 

Afterwards we want to have a View providing a list of all customers where the balance is less or equal 0.

DEFINE VARIABLE oCustomerView AS Test.ModelClasses.CustomerTableModel NO-UNDO.

oCustomerView = oCustomerDatasetModel:Customer:CreateView ().

oCustomerView:Filter:Balance:LE (0).
oCustomerView:FILL ().