Dynamic Variable Function Codes
What is a "Function Code" for LSAM Dynamic Variables?
The "Value calc pgm" field of an LSAM Dynamic Variable master record is also used by the LSAM to support special values that govern how the value for a Dynamic Variable will be prepared when it will replace a Dynamic Variable {TOKEN}. The Value Calc Pgm field label shows its alternative purpose by this label: "/Fn Code." This means "Function Code," and it refers to the unique functions of Dynamic Variable value replacement whenever a special value beginning with an asterisk * is entered into this field.
For most Function Codes the Value Calc program library field is ignored. But it is used by the Function Code "*SYSVAL" to specify the name of the IBM i system value name whose current setting should be retrieved.
The special function codes that can be entered into the Value Calc Pgm field include:
Function Codes that use a second definition display
- *DTAARA: The dynamic variable {TOKEN} will be replaced by the contents of a DB2 data area that is defined in page 2 of dynamic variable maintenance. The original value stored in the Value field of the dynamic variable master record is returned whenever the specified data area cannot be found at run time. Preset the dynamic variable Value field so that fetch errors can be detected at run time.
- *DB2 : The dynamic variable {TOKEN} will be replaced by the contents of a DB2 table column value that is defined in page 2 of dynamic variable maintenance, using SQL search criteria. The original value stored in the Value field of the dynamic variable master record is returned whenever the specified SQL query fails to fetch the specified DB2 value. Preset the dynamic variable Value field so that fetch errors can be detected at run time.
- *DATE: The stored Value string will be formatted as a date value, using page 2 of Dynamic Variable maintenance. The value will also support date math (adding or subtracting years, months or days).
Function Codes that do not use a second definition display
- PGM (+ LIB) name: This original use of the Value Calculator Program/Library fields is discussed in a separate section.
- *TIME: The stored Value string will be managed as a time value (with or without time string edit characters), supporting optional time math (adding or substracting hours, minutes or seconds).
- *SYSVAL: The dynamic variable name must match a valid IBM i system value, and the current system value will be used to replace the dynamic variable {TOKEN} at run time. The name of the system value to be retrieved must be entered into the Function Code Field 2, to the right of the Function Code value. (This is the field that is alternately used for the Library name of a user-defined Value Calculator Program.) The value returned by this special function is a program API value, not always formatted in the same way as displayed by the IBM i command DSPSYSVAL. Experimentation is required to adapt the API return value to an appropriate use. Use the LSAM command DSPDYNVAR to test how any system value will be presented when the {TOKEN} is replaced.
In previous patch levels of the IBM i LSAM software, it was required that the Dynamic Variable name itself must match a valid system value name. However, that rule prevented the ability to apply varying formats to the same system value. Any existing Dynamic Variables that conformed to the original rule will still be supported, until the next time that Dynamic Variable Maintenance is used to change or copy these older variables, at which time the data entry edits will enforce the new rule. Dynamic Variable names may still match IBM i system value names, but now the value retrieval routines will ignore the name of the Dynamic Variable whenever the Function Code Field 2 is not blank for a *SYSVAL Function Code.
The system values returned to the Dynamic Variable token replacement module, using an IBM i API, often differ in format from the values that appear on an inter-active workstation when using the DSPSYSVAL command. Use the LSAM DSPDYNVAR command (or option 6 in the list of Dynamic Variables) to test a *SYSVAL Dynamic Variable before using it in production. Dynamic Variable reformatting, and/or nesting of the *SYSVAL {TOKEN} can be used to trim and/or reformat the system values for use in LSAM automation functions.
- *HEX: This Function Code replaces a temporary LSAM utility command called SETHEXDV, for the purpose of storing and retrieving low-level hexadecimal characters. These are characters that are mostly those used for formatting text such as an email text message that needs to separate the content into paragraphs. The *HEX Function Code controls how the Agent Dynamic Variable token replacement module manages the stored value characters. It also controls how the DSPDYNVAR value test command behaves, and how the Work with Dynamic Variables option 2=Change or option 5=Display will show the stored value.
*DATE Function Code with Reformatting
Dynamic Variables that store date values can be transformed into many different edited or unedited formats using the *DATE option supportedby the Dynamic Variable master record field called [Value Calculator Program Name].
*DATE reformatting can only be performed if a Dynamic Variable is defined in advance using green screen maintenance.
User Instructions
Type *DATE into the Value Calculator Program Name field. After Enter is pressed, a second maintenance screen appears, offering a pre-defined selection of FROM and TO date formats. Type a 1 next to the format that describes the date value that was originally captured and stored into the Value of the Dynamic Variable. Optionally, type a 2 next to the format that the LSAM should return when it replaces the {TOKEN} of the Dynamic Variable.
There is also a (0) zero option column. Type a zero next to either or both of the 1=FROM and/or 2=TO selections, if either field does not include punctuation characters. For example, if a captured date represents May 4, 2017, the typical USA format of this date would be either 05/04/17 or 05/04/2017. But if the date was captured as 050417 or 05042017, then it is necessary to type the 0 next to the 1=FROM format, so that the LSAM knows there are no slash characters.
Similarly, if the replacement value provided for the token should NOT include punctuation characters, then type a 0 in the FMT0 column next to the 2=TO format.
A very common use for this feature is to translate a common date format, such as 05/04/2017 into an *ISO-0 format: 201790504. This is the format that is required if date values are going to be compared as GT, LT, GE or LE. When using EQ or NE, it is possible to use punctuated date character strings, but those cannot be used for Greater- or Less-Than Boolean comparisons.
Date Format Usage Notes and Hints
- If a captured date was in punctuated ISO format (for example, 2017-05-04), then it is not necessary (nor possible) to use *DATE reformatting. Instead, just specify the "compress numeric" option when storing the date value, either in the SETDYNVAR command or when configuring a Response Rule.
- The *DATE reformatting cannot be specified for a numeric Dynamic Variable unless the 1=FROM format is also marked for FMT-0. This is prevented by the Dynamic Variable value update program, because a numeric Dynamic Variable will not allow a punctuated date character string to be stored as its Value. To use both the punctuated date and the all-numeric date, create two different Dynamic Variable master records. Store or capture the punctuated format of the date into a character-format Dynamic Variable. Then, store the punctuated date value into the *DATE numeric-format Dynamic Variable using one of two methods:
- Use the SETDYNVAR command where the Value parameter will contain a Dynamic Variable {TOKEN} that names the character Dynamic Variable and be sure to specify CMPNUM(Y) in the SETDYNVAR command parameters.
- If the original, punctuated date is captured data, use a Capture Data Response Rule to store the captured value into the numeric Dynamic Variable by specifying a value of "Y" in the Response Rule "CompNum" field.
- It is possible to specify only the 1=FROM value to indicate what is the format of the current date in the variable's VALUE field, and not use the 2=TO reformatting option. Using this configuration is a way to isolate the Dynamic Variable so that date math can (optionally) still be used on the VALUE as it was originally stored, and no other changes will be made at run time. For example, if the date of November 13, 2017, was originally stored in the *USA format of 11/13/17, date math can be performed on this value to change it to the same date in the previous month: 10/13/17, and then the changed value will be used to replace the variable {TOKEN} at run time, still in the mm/dd/yy format.
- Date formatting characters can be removed from a date value without being forced to change the order and size of the date elements. Instead of relying on the FMT0 option of the Dynamic Variable date conversion, use the "compress numeric" function of the SETDYNVAR command parameter, called CMPNUM. It is also possible to specify "compress numeric" in Captured Data Response Rules, which governs how a captured data element will be stored into a Dynamic Variable.
- Remember that the date math function depends on an accurate specification of the 1=FROM (current) date format for the VALUE stored in the Dynamic Variable table. If a date value was stored without formatting characters, then the 1=FROM date format must also be followed by a '0' typed under the 'FMT' column on page 2 of the Dynamic Variable Maintenance screen.
- Since Dynamic Variable date formatting rules can only be specified using the LSAM green screen maintenance program, it is necessary to define *DATE Dynamic Variables using manual maintenance (or an LSAM data Export/Import action) before the variable can be used in automation rules.
- The automatic creation of missing Dynamic Variable master records by the SETDYNVAR command does not support specification of formatting details for *DATE or any other special function codes. It only supports general formatting of numeric Dynamic Variables.
- The automatic creation of missing Dynamic Variable master records by the Captured Data Response Rules supports no specification of any formatting -- it only adds a character-type Dynamic Variable and its Value. Therefore, if formatting of any kind is required, the Dynamic Variable used by a Captured Data Response Rule in the "Store CAPT to->" field must be defined in advance.
- It is common practice to store a single numeric or date value into more than one Dynamic Variable to support multiple formats for the same captured date value. One format might be used to include the date in an email notification message, while an unformatted date in *ISO0 format is often the best format to use for comparing date values (in Captured Data Response Rules, or in Step qualification rules within either Operator Replay Scripts or Multi-Step Job Scripts). Refer to the Use Case for Nested Dynamic Variable Tokens for additional perspective on the application of multiple date Dynamic Variables.
*TIME Function Code
A function code of *TIME does not change how the recorded time Value for a Dynamic Variable will be offered as the Dynamic Variable {TOKEN} is replaced. However, using this Function Code makes it possible to perform Time Math, increasing or decreasing the time value by using the special Value operation codes described below.
When a Dynamic Variable is designated as a *TIME variable, the LSAM programs recognize and preserve the value separators provided by the user in the Value field of the Dynamic Variable master record. The only supported *TIME separators are:
- (.) = a period
- (,) = a comma
- (:) = a colon
- unformatted = 6 digits only
The LSAM always assumes that the time value is comprised of six digits: HHMMSS (unformatted), or for example: HH.MM.SS. Thus, a *TIME value must be a formatted time value that uses separator characters and occupies exactly 8 bytes of the VALUE field, or else it must be an unformatted time value that occupies only 6 bytes of the VALUE field and all 6 bytes must be numeric digits (a leading zero is required for hour values less than 10).
*DATE and *TIME math
Dynamic Variables support a simple plus (+) or minus (-) value for adjustments that can be used whenever the numeric field size is set. But simple math is usually not useful for managing calendar date values. For *DATE or *TIME type Dynamic Variables there are additional Value operation codes that can be used to perform DATE and TIME math operations, to advance or retard either a date or a time value. The Dynamic Variable must have a Function Code of either *DATE or *TIME for this type of math value setting to work.
For both *DATE and *TIME variables, the largest number that can be used to change any segment of the value is 4 digits. Values from 1 to 9999 can be valid, but the actual value used should take into consideration the dramatic effect on the date or time that will happen if an extremely large number is used.
For *DATE variables, the Date math operators are these:
+Y9999 or -Y9999 +M9999 -M9999 +D9999 -D9999
...where Y=years, M=months and D=days.
For *TIME variables, the Time math operators are these:
+H9999 or -H9999 +M9999 -M9999 +S9999 -S9999
...where H=hours, M=minutes and S=seconds.
If a Date or Time value needs to be adjusted by a combination of its segments, such as 4 hours and 20 minutes, the adjustment can be made by either pre-calculating the total number of minutes, or by executing the SETDYNVAR command twice - once for each value to be changed.
SETDYNVAR ... VALUE('+M20')
Notice that the VALUE string must be enclosed in single quotes.
It is possible to use a Dynamic Variable {TOKEN} for any or all parts of a Data or Time math setting, for example:
SETDYNVAR ... VALUE('+M{NBROFMONTHS}'
*SYSVAL Function Code
A function code of *SYSVAL indicates that the Dynamic Variable name is the actual name of an IBM i System Value that should be retrieved and presented in place of the {TOKEN}.
Examples of System Value names include QDATE (the current system date), which is often used to feed another Dynamic Variable with a Function Code of *DATE, so that the IBM i partition's system date can be reformatted.
Refer to the topic about nested Dynamic Variable tokens, below, for an example of using a System Value {TOKEN} as the Value of another Dynamic Variable.
In previous patch levels of the IBM i LSAM software, it was required that the Dynamic Variable name itself must match a valid system value name. However, that rule prevented the ability to apply varying formats to the same system value. Any existing Dynamic Variables that conformed to the original rule will still be supported, until the next time that Dynamic Variable Maintenance is used to change or copy these older variables, at which time the data entry edits will enforce the new rule. Dynamic Variable names may still match IBM i system value names, but now the value retrieval routines will ignore the name of the Dynamic Variable whenever the Function Code Field 2 is not blank for a *SYSVAL Function Code.
The system values returned to the Dynamic Variable token replacement module, using an IBM i API, often differ in format from the values that appear on an interactive workstation when using the DSPSYSVAL command. Use the LSAM DSPDYNVAR command (or option 6 in the list of Dynamic Variables) to test a *SYSVAL Dynamic Variable before using it in production. Dynamic Variable reformatting, and/or nesting of the *SYSVAL {TOKEN} can be used to trim and/or reformat the system values for use in LSAM automation functions.
*HEX Function Code
This Function Code replaces a temporary LSAM utility command called SETHEXDV, for the purpose of storing and retrieving low-level hexadecimal characters. The documentation section below that describes the SETHEXDV command also explains how Dynamic Variables that were created with this command can be converted to conform to the upgraded *HEX Function Code format.
The *HEX Function Code controls how the Agent Dynamic Variable token replacement module manages the stored value characters. It also controls how the DSPDYNVAR value test command behaves, and how the Work with Dynamic Variables option 2=Change or option 5=Display will show the stored value.
*HEX Dynamic Variables are used to insert non-display control characters into OpCon automation tools such as the External Event command for sending email. The Agent utility command CPYTOMSGIN may include a {TOKEN} that is replaced by the true hexadecimal value stored in the referenced Dynamic Variable with Function Code *HEX.
For example, a Carriage Return character could be used to improve the appearance of email messages by adding blank lines between paragraphs of the email message text.
*HEX Dynamic Variables are restricted to accept only new values specified in the format X'hh', where 'h' is a valid character used to represent a nibble (half byte) of a character in the computer data format of the hexadecimal numbering system.
Characters representing hex values are limited to '0 - 9' and/or 'A - F'. For example, the Carriage Return control character is represented in this EBCDIC data format: X'0D'.
*DTAARA Function Code
Before the official designation of multiple Function Codes for Dynamic Variables, there was a prototype method for fetching data from a DB2 data area that was based on users modifying a model program provided by SMA. With the new Function Code method it is much easier to define DB2 value fetch rules by using the second page of Dynamic Variable Maintenance to define the name, location and character string trimming rules that will fetch and format the Value returned for a *DTAARA {TOKEN}.
Managing Large Data Areas
Prior to LSAM PTF # 211190, Dynamic Variables could only retrieve data from data areas that were no larger than 1024 bytes. Now, the second display in Maintain Dynamic Variables, which appears as the Function Code of *DTAARA is registered, enables the Trim Start and Length fields to be used to specify any start location within a data area even when the data area is larger than 1024 bytes, up to a starting value of 9999. (Thus, any data within a data area beyond 11,023 bytes cannot be retrieved by a Dynamic Variable. For this case, specify a User Program and the program Library location on page one of the Dynamic Variable definition, in the Function Code fields.)
Regarless of how large a data area may be, the Trim Length will always be limited to 1024 characters because this is the maximum size of a data string that can be stored as the Value for any Dynamic Variable. To retrieve all the contents of a very large data area it would become necessary to define multiple separate Dynamic Variables until segments of up to 1024 bytes from each variable will total the entire length of the large data area. Later, those variables could be concatenated if necessary to refer to the entire large data area content, but in this case, great care must be taken to specify the Charater Trim Start and Length values on the first page of the Dynamic Variable master record, so that any space characters appearing within the the 1024 byte segment variables at the begining or the end of the 1024 character string would be preserved.
Trimming Data Area Values
When *DTAARA is specified for the Dynamic Variable Function Code, the second display format will be format R7, with fields that can be used to name the data area and its library location. The only other values that can be defined for data areas are the trim control numbers. A starting location and a length value can be typed. If both fields are left at zero, the value returned for the Dynamic Variable token will be the first 1024 characters of the data area (or all of the data area contents when the data area is smaller than 1024 bytes).
If either of the Data Area Trim control fields is set to a non-zero value, the other field could be left set to zero with the following results:
- Start = 1, Length = 0: Up to 1024 bytes, depending on how large is the whole data area, and/or what amount of data remains to be retrieved beginning with the Start position.
- Start = 0, Length = >0: The trim will start with byte 1, then include only as many characters as the Length specifies.
To protect and retain blank characters in leading or trailing positions of the trimmed (or all) data retrieved from a data area, also set the Character Trim values in the main variable maintenance page. See F1=Help from the first maintenance page for more information about Character Trim values.
It is important to understand that the Data Area Trim controls will be performed first, before the retrieved data area content is returned to the main Agent Dynamic Variable value calculation routines. That value will then be subject to additional trimming, if specified in the primary Dynamic Variable Character Trim Start and Length fields.
Special Rules for the Local Data Area
The IBM i operating system automatically defines a "Local Data Area" (referred to as LDA, or in command parameters as *LDA) which is like a one-record file with a record length of 1024 bytes, stored in the DB2 database. Local data areas are only shared between jobs whenever one job submits another job (using the SBMJOB command, or a spawn() function).
Traditionally, many legacy software applications relied on the local data area to preset parameter values according to application requirements just before submitting a job.
The OpCon Agent of IBM i enables sharing of local data areas between jobs by supporting retrieval of the local data area contents and storing them into Agent Dynamic Variables that can be retrieved by any job. This same technique may also be useful when automating support for restarting a job.
Retrieving data from a local data area is similar to working with any other data area, but with the following exceptions:
- The Data area name on page 2 of Dynamic Variable auxiliary fields must be set to the special name of "*LDA".
- The Library location field is ignored whenever the name is *LDA.
- Whenever the whole LDA is intended to be stored into a Dynamic Variable, and later used in its entirety as when applying it to another job, it is important to remember the hint above about preserving any leading and trailing characters of the total 1024-byte value by specifying the Character Trim values on the first page of Dynamic Variable maintenance as START(1), LENGTH(1024).
*DB2 Function Code
Before the official designation of multiple Function Codes for Dynamic Variables, there was a prototype DB2 method for fetching data from a DB2 database table that was based on users modify a model program provided by SMA. With the new Function Code method it is much easier to define DB2 value fetch rules by using the second page of Dynamic Variable Maintenance to define the SQL query components that will fetch the Value returned for a *DB2 {TOKEN}.
The old DB2 program-based method is still supported for any existing configurations, and the user instructions for the old method have been retained below, following the new method instructions.
Following are instructions for configuring the *DB2 SQL query definitions, including options for each field in page 2 of Dynamic Variable Maintenance and some important rules and hints that make this feature more flexible. There are also some important constraints.
*DB2 User Instructions and Hints
Logging of SQL Statements and Errors
When experimenting with the *DB2 function code, view the contents of the LSAM general purpose log file LSALOGF30 to find images of SQL statements and any error messages that explain why an SQL statement did not work. The LSAM sub-menu 6, option 5, log viewer 4 can be used to view this log. Log entries marked "DQ:" will show the SQL statement that was constructed, and entries marked "DE:" show any error messages that will usually explain what was wrong with the SQL statement.