A virtual field can be used in a request as though it is a real data source field. The calculation that determines the value of a virtual field is performed on each retrieved record that passes any screening conditions on real fields. The result of the expression is treated as though it were a real field stored in the data source.
You can define a virtual field in the following ways:
For more information, see the Describing Data With WebFOCUS Language manual.
Tip: If your environment supports the KEEPDEFINES parameter, you can set KEEPDEFINES to ON to protect virtual fields from being cleared by a subsequent JOIN command.
To define a virtual field (Define object) in a procedure:
The Define dialog box opens. For details see Define Tool.
For information on expressions, see the Creating Reports With WebFOCUS Language manual.
You can also use a function in an expression by clicking the Functions button on the Define dialog box. For details on functions, see the Using Functions manual.
Note: If you want to make a virtual field available for use with all procedures during your session, issue the DEFINE command from the Command Console. The virtual field is retained for the duration of the session.
In the Define tool window:
The Format dialog box opens.
The default length is 20. It appears in the Length input area.
The Format dialog box closes.
For more information on field formats, see Assigning Field Formats in the Creating Reports With Report Painter manual.
The Format dialog box opens.
The default length appears in the Length input area. The Decimal input area shows the number of decimal places for Floating Point, Decimal, and Packed.
The Format dialog box closes.
For more information on field formats, see Assigning Field Formats in the Creating Reports With Report Painter manual.
In the Define tool window:
The Format dialog box opens.
The Date and Time Formats dialog box opens.
The Date section options are enabled.
Note: The Date and Time Formats dialog box enforces valid Date-only and DateTime format combinations, based on the input entered and the field selected. Some options may not be available for your selections.
When a date format is selected, the Format String and Sample Date are displayed for the format selected.
The Date and Time Formats dialog box closes. The selected format appears in the Date/Time Format section of the Format dialog box.
Note: Administrators and developers should note that date options set in a virtual field will override date options set in the Master File or with a SET command.
The following image shows the Define tool.
The Define tool has the following fields or options:
Displays the name of the temporary field.
To create a field, type the name that you want to use in the Field text box.
To edit a field, select the field. When you select a field, the corresponding information appears in the Format box, and the expression box. You can edit the information, eliminate the field, or run it.
When selected, it indicates that the current temporary field definitions should be added to the list of temporary fields previously defined for the same data source.
If this button is not selected, the current set of temporary fields replaces those previously defined for the same data source.
In Application View, this action marks all definitions created during the current use of the Define tool to be added to other virtual fields defined for the same data source during earlier use of the tool.
Note: You can define and execute several virtual fields during a single use of the Define tool. However, unless you select Add, running the current list will erase other virtual fields created outside of the Master File for the same data source. Virtual fields created in the Master File remain in effect.
When selected, it clears any current temporary field definitions you previously added to the list of temporary fields.
Opens the Format dialog box, where you assign a format to the temporary field.
Displays the field type, field length, and display options. The field type can be alphanumeric, numeric, or date/time.
Opens the Options window, which enables you to establish a segment location for a temporary field in the associated Master File, and/or assign attributes to set how missing values in the virtual field are handled.
Displays the expression used to evaluate the field.
Type the expression or use the Fields list, calculator, and functions list to help you create the expression.
Provide numbers and operators that you can use to create numeric, alphanumeric, Boolean, and conditional expressions.
Click the desired number or operator to add it to the expression box.
Displays the Define phrase in code, and specifies any errors.
Clears the entry fields of the tools, including the Field text box and the corresponding expression. It also returns the format to the default value D12.2, and places the cursor in the Field text box so you can begin to create a new field.
Deletes the temporary field identified in the Field text box. The field is no longer available.
Opens the Function Arguments dialog box, which lists all available built-in functions. (A function is a program that returns a value.)
Double-click the desired function to add it to the expression box. Then, in the expression box, highlight each argument and substitute the value or field name you wish to use. For details, see the Using Functions manual.
Lists the names of the temporary fields already associated in the Master File.
Lists the fields defined in the Master File.
Using information in the sample data source EMPLOYEE, the following example shows how to create a virtual field, INCREASE, to calculate the annual salary increase each employee will receive. This example assumes that you have already created a procedure with which you want to use this virtual field.
The Format dialog box opens.
* .05
The expression for the Define field now appears as CURR_SAL * .05.
You can then select the new field, INCREASE, in the Fields window of the reporting tools.
Select Define from the component connector toolbar in the Procedure Viewer.
or
The Define tool opens.
For more information about Missing Field Values, see MISSING Attribute in a DEFINE or COMPUTE Command in the Handling Records With Missing Field Values chapter of the Creating Reports With WebFOCUS Language manual.
Select Define from the component connector toolbar in the Procedure Viewer.
or
The Define tool opens.
For more information about Missing Field Values, see Establishing a Segment Location for a Virtual Field in the Handling Records With Missing Field Values chapter of the Creating Reports With WebFOCUS Language manual.
How to: |
You may wish to have more than one set of virtual fields for the same data source, and to use some or all of the virtual fields in the request. The Add option enables you to specify additional virtual fields without clearing existing ones. If you omit the Add option, previously defined virtual fields in that data source are cleared.
If you want to clear a virtual field for a particular data source, use the Clear option.
For information on expressions, see the Creating Reports With WebFOCUS Language manual.
How to: |
You can display all virtual fields with the ? DEFINE command. You can also access this information in the Define tool.
How to: |
The following can clear a virtual field created in a procedure:
Unlike fields created in a procedure, virtual fields in the Master File are not cleared in the above ways.
Virtual fields can be compiled into machine code in order to increase the speed of calculations.
When you enable compilation of expressions, expressions in IF criteria are also compiled. In some cases, an expression in an IF test may contain too many elements to be compiled (the limit is 8192). In this case, a FOC1975 message is generated to indicate that the expression could not be compiled. However, the report completes successfully, and the expression is evaluated correctly without compilation.
How to: |
Dynamic formatting enables you to apply different formats to specific data in a column by using a temporary field that contains dynamic data settings. You can create a dynamic format by writing an expression using the Define tool inside or outside of Report Painter.
Before you can format a report column using the dynamic format, you must create the report, then apply the temporary field to a column in the report. For example, you can create a temporary field that contains different decimal currency formats for countries like Japan (which uses no decimal places) and England (which uses 2 decimal places). These currency formats are considered dynamic formats. You can then apply the temporary field containing the dynamic formatting to a Sales column. In a report, the Sales column reflects the different currency formats for each country.
In the Define tool:
You can apply dynamic formatting to a report column.
For more information about Report Painter, see the Creating Reports With Report Painter manual.
The following example demonstrates how the dynamic field format can be used to set different currency formats for specific countries in a report.
The Open dialog box opens.
The Define tool opens.
Notice that the SALES column displays the format variations you defined for each country in the DECODE function.
WebFOCUS |