6 4 3 Virtual Fields

LANSA for i

6.4.3 Virtual Fields

Virtual fields allow you to significantly reduce your application code by centralizing the manipulation of data that is repeated in many applications.

A virtual field does not physically exist in the file. If you were to display the contents of the file, you would not see the virtual fields. To a program, whether a client or IBM i program, the field appears to be part of the file, however, the value is derived when the record is input or output from the file. With virtual fields, you could:

  • use fields CENTURY, YEAR, MONTH, DAY to create a single virtual field called DATE.
  • store a date in YYMMDD format but retrieve and display it as MMDDYY or DDMMYY.
  • derive AGE from the BIRTH DATE.

In each case, code is removed from the application. Maintenance is only required in one place. A calculation is always the same, regardless of where it is used.

A virtual field must be defined in the Repository and may have field and file level validations associated with it. Validation rules for the fields used in defining the virtual field are still enforced.

Virtual fields can be used like any other Repository field, except that:

  • they cannot be used outside of LANSA. Virtual fields are made possible using LANSA's I/O module.
  • they cannot be used as keys in a file.

For more information, refer to Virtual Fields the LANSA for i User Guide.