12.4.1 RDML Functions

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')

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

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.

If option *ALP_SYSTEM_VARIABLE is used within the function, return the evaluated value in field SYSVAR$AV, otherwise return the value in field SYSVAR$NV if option *NUM_SYSTEM_VARIABLE has been used.

If either *ALP_SYSTEM_VARIABLE or *NUM_SYSTEM_VARIABLE have been entered as a function option, the following design constraints (rather than technical constraints) exist to ensure the correct use of the system variable facility: