4 4 2 Distinction between real and virtual fields

Visual LANSA

4.4.2 Distinction between real and virtual fields

The distinction between the real and virtual fields can be best illustrated by example.

Consider an accounting file called ACCMST that contains an 8 digit field called CHTACC (chart of accounts) that looks like this:

       +---+---+---+---+---+---+---+---+

       | 0 | 8 | 6 | 3 | 4 | 3 | 1 | 2 |

       +---+---+---+---+---+---+---+---+

This example is for chart of accounts number 08634312. In actual fact the chart of accounts has 3 components. These are:

1.  A 2 digit company number (08),

2.  A 2 digit division number (63), and

3.  A 4 digit cost center (4312).

Since the company number, division number and cost center can be "derived" directly from the chart of accounts number it would be possible to define in file ACCMST three "virtual" fields called COMPNO, DIVNUM and COSTCT.

If this was done the definition of file ACCMST would contain:

Field

Alphanumeric Length

A "real" field called CHTACC

8

A "virtual" field called COMPNO

2

A "virtual" field called DIVNUM

2

A "virtual" field called COSTCT

4

 

Of course there is a missing link. That is the definition of how virtual fields COMPNO, DIVNUM and COSTCT are "derived" from the real field CHTACC.

There are two methods available that allow you to specify how a virtual field is derived:

  • The first method is the Extended definition of virtual fields function, which allows you to perform the most commonly used actions to derive virtual fields from real fields and vice versa.
  • The second method is achieved by entering program code. This method is by far the most flexible method of specification for more complex actions but has platform implications for code.

In this example, the virtual fields COMPNO, DIVNUM and COSTCT could have been derived by using the "Extended definition of a virtual field" function by Substringing the real field into CHTACC OR by entering a few lines of RPG/400 code that mapped field CHTACC into fields COMPNO, DIVNUM and COSTCT.

Once this has been done COMPNO, DIVNUM and COSTCT would appear to be in file ACCMST. However, if the file was examined it would be found that the fields do not actually exist. Hence the name "virtual" fields.

Note that fields COMPNO, DIVNUM and COSTCT are only used when reading (i.e. inputting) from the ACCMST file. When writing to or updating the ACCMST file they have no particular meaning.

This need not be so, in fact virtual fields COMPNO, DIVNUM and COSTCT could be used to "re-assemble" field CHTACC when outputting to the file. This feature of virtual fields is extremely useful in some situations.

Also See

4.4.4 Examples of Virtual Field Applications

4.4.1 Virtual Field Concepts

Ý 4.4 Virtual Field Development