Page History
...
Consider the following function to evaluate the system variable *SYDN as an example of the simplest form of a system evaluation function:
FUNCTION OPTIONS(*DIRECT *ALP_SYSTEM_VARIABLE *NOMESSAGES)
CHANGE FIELD(#SYSVAR$AV) TO('SYD0386')
This function can be very easily expanded to return the values for 2 system variables named *SYDN and *MELB because they are both of type alphanumeric:
FUNCTION OPTIONS(*DIRECT *ALP_SYSTEM_VARIABLE *NOMESSAGES)
IF COND(#SYSVAR$NM *EQ '''*SYDN''')
CHANGE FIELD(#SYSVAR$AV) TO('SYD0386')
ELSE
CHANGE FIELD(#SYSVAR$AV) TO('MEB2307')
ENDIF
In addition this function could return values for system variables that have different lengths like *SYDN, *MELB, *COMPANY ...
FUNCTION OPTIONS(*DIRECT *ALP_SYSTEM_VARIABLE *NOMESSAGES)
CASE OF_FIELD(#SYSVAR$NM)
WHEN VALUE_IS('= ''*SYDN''')
CHANGE FIELD(#SYSVAR$AV) TO('SYD0386')
WHEN VALUE_IS('= ''*MELB''')
CHANGE FIELD(#SYSVAR$AV) TO('MEB2307')
WHEN VALUE_IS('= ''*COMPANY''')
CHANGE FIELD(#SYSVAR$AV) TO('C05')
ENDCASE
In these examples the returned values are generated from moves of numeric or alphanumeric literals that are "hard-coded" into the system variable evaluation function. In reality this is not usually the case. The returned values are most often derived from data areas or database files. The extension of the logic demonstrated above to access data areas or database files is fairly easy to imagine.
Technical Notes
System variable evaluation functions can handle system variables of different lengths and decimal precision but not of different types. The option *ALP_SYSTEM_VARIABLE is used to indicate that this is a function to evaluate an alphanumeric value. The option *NUM_SYSTEM_VARIABLE is used to indicate that this is a function to evaluate a numeric value.
It is necessary to define the following fields in the data dictionary, in order to access the system variable name and the system variable value within the evaluation function:
...
SYSVAR$NM A(20) | System Variable Name |
SYSVAR$AV A(256) | System Variable Alphanumeric Return Value |
SYSVAR$NV P(30,9) | System Variable Numeric Return Value |
Note that this implementation effectively prohibits evaluating numeric fields with more than 21 significant digits of precision.
...