Using Expressions in CI Commands [ Command Interpreter Access and Variables Programmer's Guide ] MPE/iX 5.0 Documentation
Command Interpreter Access and Variables Programmer's Guide
Using Expressions in CI Commands
The CI provides an expression evaluator that supports a large selection
of arithmetic operations; number conversions; file information; and
string, bit, and variable operations. (Appendix B provides a table of
commonly used functions. Refer to the MPE/iX Commands Reference Manual
(32650-90003) for a complete list of expression evaluator functions.)
Performing Arithmetic Operations
Standard addition, subtraction, multiplication, and division functions,
as well as exponentiation, absolute value, and modulo arithmetic
functions, are valid arithmetic operations in the CI. The standard
expression symbols are used in the CI as in other programming languages.
The following examples show the common arithmetic symbols used by the CI.
Description Example Result
Addition 1 + 3 4
Subtraction 3 - 1 2
Multiplication 2 * 4 8
Division 16 / 8 2
Absolute Value ABS(-3) 3
Exponentiation 2^3 8
Multiple Functions 2 * 3 + 6 12
The expression evaluator performs integer algebra. Functions are
executed from left to right, in the following order of operations.
1. Exponentiation and absolute value.
2. Multiplication and division.
3. Addition and subtraction.
The following example sets the variable EXP with the result of an
expression. Note the order in which the operations are performed.
:SETVAR A 1
:SETVAR B 2
:SETVAR C 3
:SETVAR D 4
:SETVAR EXP A+B*C/D
:SHOWVAR EXP
EXP = 2
The multiplication and division functions are performed first from left
to right. The integer result is added to A. Note that division is an
integer function; results are truncated, not rounded.
Parentheses can be inserted to clarify or to alter the logical order of
operations. The following example provides the expression from the
previous example with parentheses included for clarification.
:SETVAR EXP A+((B*C)/D)
Evaluating Strings
String functions provide a means of analyzing strings. These functions
include adding and subtracting characters in a string, determining the
length of a string, determining the position of a particular character in
a string, adjusting the case of characters, repeating a a character in a
string, and removing leading or trailing characters from a string.
Strings are evaluated character by character from left to right. Adding
two strings concatenates the contents of the second string to the end of
the first.
:SETVAR ANS "abcd" + "efg"
:SHOWVAR ANS
ANS = abcdefg
Subtracting characters from a string deletes the first occurrence of the
specified characters from the original string.
:SETVAR ANS "abcabc" - "ab"
:SHOWVAR ANS
ANS = cabc
The case of string data can be altered with the downshift (DWNS) or
upshift (UPS) functions. These functions are used in case-sensitive
comparisons.
:SETVAR ANS UPS("abcdEFG")
:SHOWVAR ANS
ANS = ABCDEFG
:SETVAR ANS DWNS("abcdEFG")
:SHOWVAR ANS
ANS = abcdefg
The length of a string can be determined with the LEN function.
:SETVAR ANS LEN("abcdefg")
:SHOWVAR ANS
ANS = 7
The RPT function repeats a string a specified number of times. This is
often used to pad another string with blanks or zeros.
:SETVAR ANS RPT("A",3)
:SHOWVAR ANS
ANS = AAA
The LTRIM and RTRIM functions trim leading or trailing characters from
the left or right of a string. Blanks are trimmed from the string unless
a trim character is specified in the command.
:SETVAR ANS RTRIM("ABC ") + LTRIM(".....DEF",".")
:SHOWVAR ANS
ANS = ABCDEF
ASCII characters can be defined by their ordinal representation. Note
that if the parameter of the ordinal function consists of more than one
character, the ordinal representation of only the first character is
returned. The other characters are ignored.
:SETVAR ANS ORD("AbcD")
:SHOWVAR ANS
ANS = 65
Ordinal numbers can likewise be defined by their ASCII character
representation. This is often used for escape sequences and control
sequences that have no printable counterpart.
:SETVAR ANS CHR(65)
:SHOWVAR ANS
ANS = A
Performing Bit Operations
Integer data can be evaluated and adjusted by using the bit operations
provided with the CI. These include bit shift left (LSL), bit shift right
(LSR), and circular shifts (CSL and CSR). Also, logical OR, AND, NOT, and
XOR operations are available.
Because AM capability is identified by a 1 in the second bit of the
predefined variable HPUSERCAP, either of the following expressions can be
used to see if a user has AM capability.
IF ((HPUSERCAP LSR 30) BAND 1) = 1 THEN ...
or
IF ODD(HPUSERCAP LSR 30) THEN ...
Note that the preceding examples show the use of the bit operations. A
simpler way of determining if a user has AM capability would be the
following method.
IF POS("AM",HPUSERCAPF) > 0 THEN
:
Converting Numbers
Numeric values can be converted from decimal representation to octal or
hexadecimal string equivalents. Numeric output is identified by three
prefixes: # represents decimal, $ represents hexadecimal, and %
represents octal. If no prefix is specified, decimal is assumed.
In the following example, the decimal number 329 is converted to its
hexadecimal and octal string representations.
SETVAR ANS HEX(329)
SHOWVAR ANS
ANS = $149
SETVAR ANS OCTAL(329)
SHOWVAR ANS
ANS = %511
NOTE The results of converting numbers using the HEX and OCTAL functions
are character strings. The result cannot be used in numeric
calculations.
Evaluating File Characteristics
The FINFO function retrieves file specifications for the identified file.
This is useful in creating files, verifying that a file exists, or
identifying file specifications.
The type of file information requested is identified by a numeric entry
or an alias for the numeric entry, similar to the parameters of the FINFO
function. Note that aliases are strings and must be enclosed in
parentheses. String, boolean, or numeric data is returned depending on
the option specified.
FINFO recognizes HFS (hierarchical file system) names and supports the
FLABELINFO intrinsic items relating to POSIX. Examples include:
* number of hard links
* time of last file access
* file owner (full user.account name and numeric ID)
* file type (directory, symbolic link, pipe, FIFO, device link,
etc.)
* record type (fixed, root, spool, byte stream, directory, etc.)
* file size in bytes
* KSAM XL version
* device type (disk, tape, port, streams, sockets, etc.)
* whether the file has been released.
Refer to New Features of MPE/iX: Using The Hierarchical File System
(32650-90351).
The following table provides some of the most commonly used FINFO
options, by number and alias, and a description of the results. FINFO
passes the name of the file using either MPE syntax (the default) or HFS
syntax. You can enter CALC FINFO('.1',0) and receive TRUE as output, and
filename in HFS can end in any character.
If MPE syntax, the file name can include password, group, and account
specifications. The file name can backreference a file equation and
optionally be preceded by an asterisk.
If HFS syntax, the file name must start with either a dot (.) or a slash
(/). For files located in HFS directories, traverse directory entries
(TD) access is required to all directories specified in the formal
design. If there is no TD access, FINFO fails.
If the file can be named using both MPE syntax and HFS syntax (for
example, FILEA.MYGROUP.MYACCT and /MYACCT/MYGROUP/FILEA), the file can be
either permanent or temporary. If a temporary and a permanent file have
the same name, FINFO returns information about the temporary file only.
Refer to the MPE/iX Commands Reference Manual (32650-90003) for a
complete description of the FINFO options.
Table 4-1. FINFO Specifications
-------------------------------------------------------------------------------------------------
| | | | |
| Number | Alias | Data | Item Description |
| | | Type | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 0 | EXIST | Boolean | Existence of file |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 1 | FILENAME ONLY | String | File name |
| | FNAME | | |
| | FULL FILENAME | | |
| | FULLFNAME | | |
| | FULLY QUALIFIED FILENAME | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 2 | GROUP | String | Group name |
| | GROUPNAME | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 3 | ACCOUNT | String | Account name |
| | ACCT | | |
| | ACCOUNTNAME | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 4 | CREATOR | String | File creator name |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 5 | SECURITY MATRIX | String | Security matrix for access |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -5 | SECURITY MATRIX | Integer | Security matrix for access |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 6 | CREATED | String | File creation date |
| | CREATION DATE | | |
| | FMTCREATED | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -6 | CREATION DATE INTEGER | Integer | File creation date |
| | INTCREATED | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 7 | ACCESSED | String | Last access date |
| | FMTACCESSED | | |
| | LAST ACCESS DATE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -7 | LAST ACCESS DATE INTEGER | Integer | Last access date |
| | INTACCESSED | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 8 | MODIFIED | String | Last modification date |
| | LAST MOD DATE | | |
| | FMTMODDATE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -8 | LAST MOD DATE INTEGER | Integer | Last modification date |
| | INTMODDATE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 9 | FILE CODE | String | File code of disk file |
| | MNEMONIC | | |
| | FMTFCODE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -9 | FCODE | Integer | File code of disk file |
| | INTFCODE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 10 | USER LABELS WRITTEN | Integer | Number of user labels written |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 11 | USER LABELS AVAIL | Integer | Number of user labels available |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 12 | FILE LIMIT | Integer | Total number of logical records |
| | LIMIT | | possible in the file |
| | | | |
-------------------------------------------------------------------------------------------------
Table 4-1. FINFO Specifications (cont.)
-------------------------------------------------------------------------------------------------
| | | | |
| Number | Alias | Data | Item Description |
| | | Type | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 13 | FOPTIONS | String | File options |
| | FMTFOPT | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -13 | FORMATTED FOPTIONS | Integer | File options |
| | INTFOPT | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 14 | RECORD SIZE | Integer | Record size |
| | RECSIZE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 15 | BLOCK SIZE | Integer | Block size |
| | BLKSIZE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 16 | MAX EXTENTS | Integer | Maximum number of extents |
| | MAXEXT | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 17 | LAST EXTENT SIZE | Integer | Last extent size |
| | LASTEXTSIZE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 18 | EXTENT SIZE | Integer | Extent size |
| | EXTSIZE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 19 | END OF FILE | Integer | Number of logical records in file |
| | EOF | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 20 | ALLOC TIME | String | File allocation time |
| | FMTALLOCTIME | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -20 | ALLOC TIME INTEGER | Integer | File allocation time |
| | INTALLOCTIME | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 21 | ALLOC DATE | String | File allocation date |
| | FMTALLOCDATE | | |
| | ALLOCATED | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -21 | ALLOC DATE INTEGER | Integer | File allocation date |
| | INTALLOCDATE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 22 | NUM OPEN CLOSE RECS | Integer | Number of open/close records |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 23 | DEVICE NAME | String | Device name (8 bytes |
| | DEV NAME | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 24 | FMTMODTIME | String | Last modification time |
| | LAST MOD TIME | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -24 | INTMODTIME | Integer | Last modification time |
| | LAST MOD TIME | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 25 | FIRST USER LABEL | String | First user label (user label 0) |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 27 | UNIQUE FILE ID | REC | Unique file identifier (UFID) |
| | UFID | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 28 | BYPE FILE SIZE | Integer | Total number of bytes allowed in file |
| | BYTEFILESIZE | | |
| | | | |
-------------------------------------------------------------------------------------------------
Table 4-1. FINFO Specifications (cont.)
-------------------------------------------------------------------------------------------------
| | | | |
| Number | Alias | Data | Item Description |
| | | Type | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 29 | BYTE DATA OFFSET | Integer | Start of file offset |
| | DATASTART | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 30 | BYTE RECORD SIZE | Integer | Record size (indicates bytes) |
| | BYTERECSIZE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 31 | BYTE BLOCK SIZE | Integer | Block size (indicates bytes) |
| | BYTEBLKSIZE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 32 | BYTE EXTENT SIZE | Integer | Extent size (indicates bytes) |
| | BYTEEXTSIZE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 33 | LOCKWORD | String | File lockword |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 34 | VOLUME RESTRICTION | String | Volume restriction |
| | VOLRESTR | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 35 | VOLUME SET NAME | String | Volume set names |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 36 | LOGSET ID | String | Transaction management log set id |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 37 | LDEV | Integer | Logical device number |
| | LOGICAL DEVICE NUMBER | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 38 | POSIX FULL FILE NAME | REC | Terminated HFS-syntax system absolute |
| | POSIXFULLFNAME | | pathname |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 39 | NUM HARD LINKS | Integer | The current number of hard links to |
| | NUMHARDLINKS | | the file |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 40 | ACCESS TIME | String | Time of last file access (clock |
| | FMTACCESSTIME | | format) |
| | LAST ACCESS TIME | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -40 | LAST ACCESS TIME INTEGER | Integer | Time of last file access (clock |
| | INTACCESSTIME | | format) |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 41 | STATUS CHANGE TIME | String | Time of last file status change (clock |
| | FMTSTATUSCHANGETIME | | format) |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -41 | INTSTATUSCHANGETIME | Integer | Change Time Integer |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 42 | STATUS CHANGE DATE | String | Date of the last file status change |
| | FMTSTATUSCHANGEDATE | | (calendar format) |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -42 | CHANGE DATE INTEGER | Integer | Date of the last file status change |
| | INTSTATUSCHANGEDATE | | (calendar format) |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 43 | FILE OWNER NAME | String | File owner |
| | OWNER | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 44 | FILE OWNER ID | Integer | File owner identifier |
| | UID | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 45 | FILE GROUP NAME | String | File group |
| | FILEGROUP | | |
| | | | |
-------------------------------------------------------------------------------------------------
Table 4-1. FINFO Specifications (cont.)
-------------------------------------------------------------------------------------------------
| | | | |
| Number | Alias | Data | Item Description |
| | | Type | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 46 | FILE GROUP ID | Integer | File group identifier |
| | GID | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 47 | FILE TYPE | String | File type |
| | FILETYPE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -47 | FILE TYPE INTEGER | Integer | File type |
| | INTFILETYPE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 48 | RECORD TYPE | Integer | Record type |
| | RECTYPE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 49 | BYTE FILE SIZE | Integer | Current file size (in bytes) |
| | BYTEFILESIZE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 50 | KSAM VERSION | Integer | KSAM XL file version |
| | KSAMVERS | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 51 | KSAM LABEL | some | KSAM XL parameters |
| | KSAMPARAM | type by | |
| | | refer- | |
| | | ence | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 52 | DEVICE TYPE | String | MPE/iX device type |
| | DEVTYPE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| -52 | DEVICE TYPE INTEGER | Integer | MPE/iX device type |
| | INTDEVTYPE | | |
| | | | |
-------------------------------------------------------------------------------------------------
| | | | |
| 53 | RELEASED | Boolean | Secured/Released |
| | | | |
-------------------------------------------------------------------------------------------------
The FINFO function is often used in file maintenance routines to create,
delete, or determine certain characteristics of a file. The following
examples demonstrate the responses to several FINFO requests about the
file X.PUB.SYS.
:CALC FINFO('X',0)
TRUE
:CALC FINFO('X','EXISTS')
TRUE
:CALC FINFO('X',13)
ASCII, FIXED, NOCCTL, STD
:CALC FINFO('X','FMTFOPT')
ASCII, FIXED, NOCCTL, STD
:CALC FINFO('X',1)
X.PUB.SYS
:CALC FINFO('X','FULLFNAME')
X.PUB.SYS
:CALC FINFO('X',38)
/SYS/PUB/X
The last example asks for the absolute pathname of the file "X" (HFS
syntax). Compare this with the example immediately preceding it, which
asks for the file name in MPE syntax.
Comparing Results
The comparison operators, equal (=), less than (<), greater than (>), not
equal to (<>), less than or equal to (<=), and equal to or greater than
(>=), are provided in the CI expression evaluator. These expressions
produce a boolean result that can be used to set the criteria for a
conditional branch or a looping structure.
MPE/iX 5.0 Documentation