The code fragment virtual column allows you to specify RDMLX code to populate a virtual column when reading from a table, and to populate a real column when writing to a table.
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 columns in the table. You may use trigger functions for complex coding of virtual columns or to update columns in a table.
Code Fragments are specified by selecting Code Fragments in the Virtual column 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 Column Derivation is displayed. Enter the code fragment to be used to derive the virtual column. The code fragment is typically derived from one or more real columns on the table but may also use system variables, multilingual variables and work fields.
When you select the Populate real column when writing to the table option, the associated tab for Real Column Derivation is displayed. Enter the code fragment to be used to derive the real column values. The code fragment is typically derived from the current virtual column.
In the following example, only the first option is selected, so only the Virtual Column Derivation tab is shown:
When both options are selected both tabs appear:
When only the second option is selected, only the Real Column 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 column (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