4 4 1 Virtual Field Concepts

Visual LANSA

4.4.1 Virtual Field Concepts

A virtual field is a special feature provided as part of the LANSA Repository.  Used properly, virtual fields can be very helpful in simplifying the processing of logic within applications and in improving the user interface of your applications.

A virtual field is a field which appears as part of a file but does not actually exist in the physical database file. Its value is dynamically derived based on the fields in the file.  (Virtual fields can also be derived from other virtual fields.) Virtual fields provide flexibility, since you can combine or extract data from fields in a file and extend the information already contained in the file.

You may use virtual fields for implementing "conceptual structures" within the database.  For example, you can take the fields CENTURY, YEAR, MONTH, DAY to create a single field called date.  You could also store a date in YYMMDD format but retrieve and display it as MMDDYY or DDMMYY.

To a program, the field appears to exist as part of the file; however, the value is not actually stored but derived by the I/O Module when the record is input or output from the file.  If you were to display the contents of the file, you would not see the virtual fields. Hence, virtual fields cannot be used as keys in a file. Some examples of using virtual fields:

  • Display an Order Date in MMDDYY format but store the data as YYMMDD.
  • Display the Discount Amount which is calculated as 75% of the Original Amount.
  • Display the Telephone Number which is the Area Code and Local Phone Number.
  • Display the First Name which is the first 10 characters of the Customer Name.

You can use virtual fields to simplify, standardize and centralize field related string handling, conversions and calculations.

A virtual field must be defined in the repository and may have field and file level validations associated with it.  Also, validation rules for the fields used in defining the virtual field are still enforced.  A virtual field can be used like any other field in the repository.

Virtual fields are not part of the real file and cannot be directly used outside of LANSA.  Virtual fields are made possible using LANSA's object access module. Client applications using LANSA Open and any applications which use the LANSA Object Access Module can access the LANSA virtual fields.

Virtual fields are derived and are not real fields in the file. Virtual fields cannot be used as a key field for a physical file or a logical view. If you require fields for these purposes, you will need to make them into real fields as opposed to virtual fields.

LANSA provides several methods of defining virtual fields:

  • LANSA extended definitions such as Date Conversion, Substring, Concatenation, Mathematical Calculation, Code Fragment (refer to  Virtual Fields in File in the Technical Reference Guide)

RPG or C coded definitions may be necessary for complex actions such as type and length conversions, date to age conversions, or dynamic data conversion.

Also, review the 4.7.1 Predetermined Join Field Concepts for details about another form of virtual field that may use field values from other files.

Also See

4.4.2 Distinction between real and virtual fields

4.4.4 Examples of Virtual Field Applications

Ý 4.4 Virtual Field Development