[OpenVMS documentation]
[Site home] [Send comments] [Help with this site] [How to order documentation] [OpenVMS site] [Compaq site]
Updated: 11 December 1998

OpenVMS User's Manual


Previous Contents Index

14.6.3 Character String Operations

You can specify the following character string operations:

In the following example, the plus sign (+) is used to concatenate two character strings:


$ COLOR = "light brown"
$ WEIGHT = "30 lbs."
$ DOG2 = "No tag, " + COLOR + ", " + WEIGHT
$ SHOW SYMBOL DOG2
  DOG2 = "No tag, light brown, 30 lbs."

In the following example, the minus sign ( - ) is used to remove a character string:


$ SHOW SYMBOL DOG2
  DOG2 = "No tag, light brown, 30 lbs."
$ DOG2 = DOG2 - ", 30 lbs."
$ SHOW SYMBOL DOG2
  DOG2 = "No tag, light brown"

14.6.4 Comparing Character Strings

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 14-1 lists different types of string comparisons.

Table 14-1 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".

14.6.5 Replacing Substrings

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'

14.7 Using Numeric Values and Expressions

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.

14.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

14.7.2 Internal Storage of Numbers

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

These integer operands can be connected by arithmetic, logical, and comparison operators, as described in the following sections.

14.7.3 Performing Arithmetic Operations

You can specify the following arithmetic operations:

Examples

14.7.4 Comparing Numbers

Table 14-2 lists different types of numeric comparisons:

Table 14-2 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 .

14.7.5 Performing Numeric Overlays

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

14.8 Using Logical Values and Expressions

The following sections describe how to use logical values and expressions.

14.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

14.8.2 Logical Expressions

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:

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

[Site home] [Send comments] [Help with this site] [How to order documentation] [OpenVMS site] [Compaq site]
[OpenVMS documentation]

Copyright © Compaq Computer Corporation 1998. All rights reserved.

Legal
6489PRO_034.HTML