[Digital logo]
[HR]

OpenVMS User's Manual


Previous | Contents

If you perform an operation or comparison between a character string and a number, DCL converts the character string to a number.

String operands can be added (string concatenation), subtracted (string reduction), compared, or replaced with other character strings as described in the following subsections.

14.7.6 Examples

14.7.7 Character String Operations

You can specify the following character string operations:

14.7.8 Examples

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

14.7.10 Types of String Comparisons

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.

14.7.11 Examples

In all of these examples, assume that the symbol LAST_NAME has the value "WHITFIELD".

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

14.7.13 Rules for Replacing Substrings

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.

14.7.14 Examples

14.8 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.8.1 Specifying Numbers

At DCL command level and within command procedures, specify a number as follows:

14.8.2 Examples

14.8.3 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).

14.8.4 Numeric Expressions

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.

14.8.5 Integer Operands

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.8.6 Performing Arithmetic Operations

You can specify the following arithmetic operations:

14.8.7 Examples

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

14.8.9 Examples

In the following examples, assume that the symbol BALANCE has the value -15237 .

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

14.8.11 Rules for Using Numeric Overlays

To use numeric overlays, observe the following rules:

14.8.12 Example

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.9 Using Logical Values and Expressions

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

14.9.1 Logical Operations

Some operations interpret numbers and character strings as logical data with values as follows:

14.9.2 Example

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

14.9.4 Uses of Logical Expressions

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:

14.9.5 Examples

14.9.6 Logical Operation Results

The following tables demonstrate the results of logical operations on a bit-by-bit basis and a number-by-number basis. In logical operations, a character string beginning with an uppercase or lowercase T or Y is treated as the number 1; a character string beginning with any other character is treated as the number 0. In logical operations, odd numbers are true and even numbers and zero are false.
Given That: The Results Are:
Bit A Bit B .NOT. A A .AND. B A .OR. B
1 1 0 1 1
1 0 0 0 1
0 1 1 0 1
0 0 1 0 0
Given That: The Results Are:
Number A Number B .NOT. A A .AND. B A .OR. B
odd odd even odd odd
odd even even even odd
even odd odd even odd
even even odd even even

14.9.7 Using Values Returned by Lexical Functions

Typically used in command procedures, lexical functions retrieve information from the system, including information about system processes, batch and print queues, and user processes. You can also use lexical functions to manipulate character strings and translate logical names. When you assign a lexical function to a symbol, the symbol is equated to the information returned by the lexical function (for example, a number or character string). At DCL level, you can then display that information with the DCL command SHOW SYMBOL. In a command procedure, the information stored in the symbol can be used later in the procedure. See the Chapter 17 for additional information on lexical functions.

14.9.8 Lexical Function Format

To use a lexical function, specify the name of the lexical function (which always begins with F$) and its argument list. Use the following format:

F$function-name(args[,...]) 

The argument list follows the function name with any number of intervening spaces and tabs.

14.9.9 Rules for Using Lexical Functions

When you use a lexical function, observe the following rules:

14.9.10 Evaluation of Lexical Functions

Use lexical functions the same way you would use character strings, integers, and symbols. When you use a lexical function in an expression, DCL automatically evaluates the function and replaces the function with its return value.

14.9.11 Example

In the following example, the F$LENGTH function returns the length of the value specified as BUMBLEBEE as its argument. DCL automatically determines the return value (9) and uses this value to evaluate the expression. Therefore, the result of the expression (9 + 1) is 10 and this value is assigned to the symbol SUM:

$ SUM = F$LENGTH("BUMBLEBEE") + 1
$ SHOW SYMBOL SUM
  SUM = 10   Hex = 0000000A  Octal = 00000000012

14.9.12 Lexical Function Usage

Note that each lexical function returns information as either an integer or a character string. In addition, you must specify the arguments for a lexical function as either integer or character string expressions.


Previous | Next | Contents | [Home] | [Comments] | [Ordering info] | [Help]

[HR]

  6489P024.HTM
  OSSG Documentation
  22-NOV-1996 13:17:12.02

Copyright © Digital Equipment Corporation 1996. All Rights Reserved.

Legal