Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

[ Image Removed |../../index.htm#lansa/ugub_30053.htm]
You are here:

...

The introduction to this section described a very simple example of 3 "virtual" fields that were directly derived from a "real" field by simple mapping.
However, because the virtual field derivation logic is specified to LANSA by RPG program code it is possible to use much more complex derivation logic.
These examples demonstrate some of the capabilities of the virtual field facility and common examples of its use. Hopefully it can also be seen that the capabilities are only really limited by the imagination of the user:
Substringing and concatenation
The example in the preceding section that involved breaking a field down into 3 virtual fields is an example of substringing. Virtual fields can be used in all forms of substringing. This includes substringing 1 real field into multiple virtual fields and substringing multiple real fields into one virtual field (also called concatenation).
Access to files with no external description
Many older S/38 applications, and S/36 migrated IBM i applications, use files that have no "external" field descriptions. These are also referred to as "internally described" files. These files appear as if they only contain one very large field which is in fact the entire file record, rather than a series of fields.
In such cases, all the fields in the file can be defined as virtual fields and then mapped from the record. This is in fact another example of substringing one real field into multiple virtual fields.
This case would also involve the mapping of virtual fields to the real field before output to the file. Refer to examples 1 and 2 in Examples of Virtual Fields & Derivation Code for more details.
Simplification and standardisation of common data manipulations
In some applications the manipulation of data from a file in a particular way is very common and is repeated many times in differing applications.
For instance, consider an inventory file. The rule to determine whether a product requires re-ordering may be something like ("quantity on hand" + "quantity awaiting return" - "quantity on order") < "re-order level". This rule may be used in many different applications, particularly in the inquiry and reporting areas.
The logic in this rule can be simplified and standardized by using a virtual field. If a virtual field called REORDER was set up in the file definition, then derivation code could be written to evaluate the rule and set REORDER to "YES" or "NO". This approach has several advantages:

...

If the customer name field was called CUSNAM then it would be a simple task to define a virtual field in the file called PRTNAM that matched these requirements.
[ Image Removed |../../index.htm#lansa/ugub_30053.htm]