Document revision date: 15 July 2002 | |
Previous | Contents | Index |
When you compare two character strings, the strings are compared character by character. Strings of different lengths are not equal (for example, "dogs" is greater than "dog").
The comparison criteria are the ASCII values of the characters. Under these criteria, the digits 0 to 9 are less than the uppercase letters A to Z, and the uppercase letters A to Z are less than the lowercase letters a to z. A character string comparison ends when either of the following conditions is true:
Table 12-1 lists different types of string comparisons.
Comparison | Operator | Description |
---|---|---|
Equal to | .EQS. | Compares one character string to another for equality. |
Greater than or equal to | .GES. | Compares one character string to another for greater or equal value in the first specified string. |
Greater than | .GTS. | Compares one character string to another for a greater value in the first specified string. |
Less than or equal to | .LES. | Compares one character string to another for a lesser or equal value in the first specified string. |
Less than | .LTS. | Compares one character string to another for a lesser value in the first specified string. |
Not equal | .NES. | Compares one character string to another for inequality. |
In all of the following examples, assume that the symbol LAST_NAME has the value "WHITFIELD".
$ TEST_NAME = LAST_NAME .EQS. "Hill" $ SHOW SYMBOL TEST_NAME TEST_NAME = 0 ... |
$ TEST_NAME = LAST_NAME .GES. "HILL" $ SHOW SYMBOL TEST_NAME TEST_NAME = 1 ... |
$ TEST_NAME = LAST_NAME .GTS. "HILL" $ SHOW SYMBOL TEST_NAME TEST_NAME = 1 ... |
$ TEST_NAME = LAST_NAME .LES. "HILL" $ SHOW SYMBOL TEST_NAME TEST_NAME = 0 ... |
$ TEST_NAME = LAST_NAME .LTS. "HILL" $ SHOW SYMBOL TEST_NAME TEST_NAME = 0 ... |
$ TEST_NAME = LAST_NAME .NES. "HILL" $ SHOW SYMBOL TEST_NAME TEST_NAME = 1 ... |
You can replace part of a character string with another character string by specifying the position and size of the replacement string. The format for local symbols is:
symbol-name[offset,size] := replacement-string |
The format for global symbols is:
symbol-name[offset,size] :== replacement-string |
The elements are as follows:
offset | An integer that indicates the position of the replacement string relative to the first character in the original string. An offset of 0 means the first character in the symbol, an offset of 1 means the second character, and so on. |
size | An integer that indicates the length of the replacement string. |
To replace substrings, observe the following rules:
Lining up records in columns makes a list easier to read and sort. You can use this format to specify how you want data to be stored.
In the following example, the first assignment statement gives the symbol A the value PACKRAT. The second statement specifies that MUSK replace the first four characters in the value of A. The result is that the value of A becomes MUSKRAT.
$ A := PACKRAT $ A[0,4] := MUSK $ SHOW SYMBOL A A = "MUSKRAT" |
In the following example, the symbol B does not have a previous value, so it is given a value of four leading spaces followed by RAT:
$ B[4,3] := RAT |
In the following example, a value of 80 blank spaces is assigned to the symbol LINE:
$ LINE[0,80]:= " " |
In the following example, the first statement fills in the first 15 columns of DATA with whatever value NAME has. The second statement fills in column 18 with whatever value GRADE has. Columns 16 and 17 contain blanks:
$ DATA[0,15] := 'NAME' $ DATA[17,1] := 'GRADE' |
A number can have the following values:
The number you assign to a symbol must be in the range --2147483648 to
2147483647 (decimal). An error is not reported if a number outside this
range is specified or calculated but an incorrect value results.
12.7.1 Specifying Numbers
At DCL command level and within command procedures, specify a number as follows:
In the following example, the number 13 is assigned to the symbol DOG_COUNT:
$ DOG_COUNT = 13 $ SHOW SYMBOL DOG_COUNT DOG_COUNT = 13 Hex = 0000000D Octal = 00000000015 |
In the following example, the negative number ( -15237 ) is represented with a minus sign ( - ):
$ BALANCE = -15237 $ SHOW SYMBOL BALANCE BALANCE = -15237 Hex = FFFFC47B Octal = 37777742173 |
In the following example, the hexadecimal number D is represented with the prefix %X:
$ DOG_COUNT = %XD $ SHOW SYMBOL DOG_COUNT DOG_COUNT = 13 Hex = 0000000D Octal = 00000000015 $ BALANCE = -%X3B85 $ SHOW SYMBOL BALANCE BALANCE = -15237 Hex = FFFFC47B Octal = 37777742173 |
Numbers are stored internally as signed 4-byte integers, called longwords; positive numbers have values of 0 to 2147483647 and negative numbers have values of 4294967296 minus the absolute value of the number. The number -15237 , for example, is stored as 4294952059. Negative numbers are converted back to minus-sign format for ASCII or decimal displays; however, they are not converted back for hexadecimal and octal displays. For example, the number -15237 appears in displays as hexadecimal FFFFC47B (decimal 4294952059) rather than hexadecimal --00003B85.
Numbers are stored in text files as a series of digits using ASCII conventions (for example, the digit 1 has a storage value of 49).
In a numeric expression, the values involved must be literal numbers (such as 3) or symbols with numeric values. In addition, you can use a character string that represents a number (for example, "23" or " -51 "). If you perform an operation or comparison between a number and a character string, DCL converts the character string to a number.
Numeric expressions combine the following values (called integer operands):
$ COUNT = 1 |
$ B = F$INTEGER("-9" + 23) |
$ A = B - 6 |
These integer operands can be connected by arithmetic, logical, and
comparison operators, as described in the following sections.
12.7.3 Performing Arithmetic Operations
You can specify the following arithmetic operations:
$ BALANCE = 142 * 14 $ SHOW SYMBOL BALANCE BALANCE = 1988 Hex = 000007C4 Octal = 00000003704 |
$ BALANCE = BALANCE / 14 $ SHOW SYMBOL BALANCE BALANCE = 142 Hex = 0000008E Octal = 00000000216 |
$ BALANCE = BALANCE + 37 $ SHOW SYMBOL BALANCE BALANCE = 179 Hex = 000000B3 Octal = 00000000263 |
$ BALANCE = BALANCE - 15416 $ SHOW SYMBOL BALANCE BALANCE = -15237 Hex = FFFFC47B Octal = 00000142173 |
$ BALANCE = -(- a142) $ SHOW SYMBOL BALANCE BALANCE = 142 Hex = 0000008E Octal = 00000000216 |
Table 12-2 lists different types of numeric comparisons.
Comparison | Operator | Description |
---|---|---|
Equal to | .EQ. | Compares one number to another for equality. |
Greater than or equal to | .GE. | Compares one number to another for a greater or equal value in the first number. |
Greater than | .GT. | Compares one number to another for a greater value in the first number. |
Less than or equal to | .LE. | Compares one number to another for a lesser or equal value in the first number. |
Less than | .LT. | Compares one number to another for a lesser value in the first number. |
Not equal to | .NE. | Compares one number to another for inequality. |
In the following examples, assume that the symbol BALANCE has the value -15237 .
$ TEST_BALANCE = BALANCE .EQ. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 1 ... |
$ TEST_BALANCE = BALANCE .GE. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 1 ... |
$ TEST_BALANCE = BALANCE .GT. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 0 ... |
$ TEST_BALANCE = BALANCE .LE. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 1 ... |
$ TEST_BALANCE = BALANCE .LT. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 0 ... |
$ TEST_BALANCE = BALANCE .NE. -15237 $ SHOW SYMBOL TEST_BALANCE TEST_BALANCE = 0 ... |
You can perform binary (bit-level) overlays of the current symbol value by using a special format of the assignment statement. For local symbols, the format is:
symbol-name[bit-position,size] = replacement-expression |
For global symbols, the format is:
symbol-name[bit-position,size] == replacement-expression |
The elements are as follows:
bit-position | An integer that indicates the location relative to bit 0 at which the overlay is to occur. |
size | An integer that indicates the number of bits to be overlaid. |
To use numeric overlays, observe the following rules:
The following example defines the symbol BELL as the value 7. The low-order byte of BELL has the binary value 00000111. By changing the 0 at offset 5 to 1 (beginning with 0, count bits from right to left), you create the binary value 00100111 (decimal value 39):
$ BELL = 7 $ BELL[5,1] = 1 $ SHOW SYMBOL BELL BELL = 39 Hex = 00000027 Octal = 00000000047 |
The following sections describe how to use logical values and
expressions.
12.8.1 Logical Operations
Some operations interpret numbers and character strings as logical data with values as follows:
In the following examples, DOG_COUNT is assigned the value 13. IF STATUS means if the logical value of STATUS is true.
$ STATUS = 1 $ IF STATUS THEN DOG_COUNT = 13 |
$ STATUS = "TRUE" $ IF STATUS THEN DOG_COUNT = 13 |
A logical operation affects all the bits in the number being acted upon. The values for logical expressions are integers, and the result of the expression is an integer as well. If you specify a character string value in a logical expression, the string is converted to an integer before the expression is evaluated.
Typically, you use logical expressions to evaluate the low-order bit of a logical value; that is, to determine whether the value is true or false. You can specify the following logical operations:
Bit Level | Entity Level |
---|---|
1 .AND. 1 = 1 | true .AND. true = true |
1 .AND. 0 = 0 | true .AND. false = false |
0 .AND. 1 = 0 | false .AND. true = false |
0 .AND. 0 = 0 | false .AND. false = false |
Bit Level | Entity Level |
---|---|
1 .OR. 1 = 1 | true .OR. true = true |
1 .OR. 0 = 1 | true .OR. false = true |
0 .OR. 1 = 1 | false .OR. true = true |
0 .OR. 0 = 0 | false .OR. false = false |
The following example reverses a true value to false. The expression is evaluated as --2; the value is even and is therefore false:
$ SHOW SYMBOL STATUS STATUS = 1 Hex = 00000001 Octal = 00000000001 $ STATUS = .NOT. STATUS $ SHOW SYMBOL STATUS STATUS = -2 Hex = FFFFFFFE Octal = 37777777776 |
The following example combines a true value and a false value to produce a false value:
$ STAT1 = "TRUE" $ STAT2 = "FALSE" $ STATUS = STAT1 .AND. STAT2 $ SHOW SYMBOL STATUS STATUS = 0 Hex = 00000000 Octal = 00000000000 |
The following example combines a true value and a false value to produce a true value:
$ STAT1 = "TRUE" $ STAT2 = "FALSE" $ STATUS = STAT1 .OR. STAT2 $ SHOW SYMBOL STATUS STATUS = 1 Hex = 00000001 Octal = 00000000001 |
Previous | Next | Contents | Index |
privacy and legal statement | ||
6489PRO_031.HTML |