3 3 6 Code Fragment

LANSA Technical

3.3.6 Code Fragment

The code fragment virtual field allows you to specify RDMLX code to populate a virtual field when reading from a file, and to populate a real field when writing to a file.

A code fragment does not support the full range of RDML/X commands. In Version 11, you are limited to constructs such as If, Case, Dountil, Dowhile, Change, Assign.

At execution time, the code fragment will have read-only access to all fields in the file. You may use trigger functions for complex coding of virtual fields or to update fields in a file.

Code Fragments are specified by selecting Code Fragments in the Virtual field type dropdown list in the Details tab. In the Details tab, when you select the Derive Value when record is read option, the associated tab for Virtual Field Derivation is displayed. Enter the code fragment to be used to derive the virtual field. The code fragment is typically derived from one or more real fields on the file but may also use system variables, multilingual variables and work fields.

When you select the Populate real field when writing to the file option, the associated tab for Real Field Derivation is displayed. Enter the code fragment to be used to derive the real field values. The code fragment is typically derived from the current virtual field.

In the following example, only the first option is selected, so only the Virtual Field Derivation tab is shown:

When both options are selected both tabs appear:

When only the second option is selected, only the Real Field Derivation tab is shown:

Code fragment vs concatenation

Code fragments give you more control and variability than concatenation. The following example of Concatenation uses the same information to derive the real and the virtual field (simply by applying reverse of definition) and gives you a similar but not quite the same result.

The code fragment:

#fullname := #surname + ' , ' + #givename

 

would result in Turner , Scott

Concatenation of Surname and Full name would give TurnerScott

Also see

Code Fragment Virtual Field Derivation

Code Fragment Real Field Derivation

3.3.4 Concatenation

Ý 3.3 Virtual Fields in File