[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
Reference Manual


Previous Contents Index

<>

1.2.1.4 Function-Names

A function-name is the name of a function as shown in Table 7-1, Intrinsic Functions. Note that function-names are not reserved words and may appear in a different context in a program as a user-defined word or a system-name.

1.2.2 Literals

A literal is a character-string whose value is specified by: (1) the ordered set of characters it contains, or (2) a reserved word that is a figurative constant.

HP COBOL provides two types of literals: numeric and nonnumeric. Numeric literals include floating-point literals and nonnumeric literals include hexadecimal and national literals. Floating-point, hexadecimal, and national literals are Hewlett-Packard extensions. The following two sections describe literals in detail.

1.2.2.1 Numeric Literals

A numeric literal is a character string of 1 to 33 characters on Alpha and I64 or 1 to 20 characters on VAX, selected from the digits 0 to 9, the plus sign (+), the minus sign (-), and the decimal point (.).

The value of a numeric literal is the algebraic quantity represented by the characters in the literal.

Syntax Rules

  1. A numeric literal must contain at least 1 digit and not more than 31 digits on Alpha and I64 or 18 digits on VAX.
  2. A numeric literal must not contain more than one sign character, which must be the leftmost character. If the literal is unsigned, its value is positive.
  3. A numeric literal must not contain more than one decimal point. The decimal point is treated as an assumed decimal point. It can be used anywhere in the literal except as the rightmost character.
    If a numeric literal contains no decimal point, it is an integer.
  4. The compiler treats a numeric literal enclosed in quotation marks as a nonnumeric literal.

Table 1-4 provides examples of numeric literals.

Table 1-4 Numeric Literals
Literal Value
12 12
0.12000 0.12
-123456789012345678 -123456789012345678
000000003 3
-34.455445555 -34.455445555
0 0
+0.000000000001 +0.000000000001
+0000000000001 +1

Floating-Point Literals

A floating-point literal, a Hewlett-Packard extension to numeric literals, is a character-string whose value is specified by 4 to 37 characters on Alpha and I64 or 4 to 24 characters on VAX, selected from the digits 0 to 9, the plus sign (+), the minus sign (-), the decimal point (.), and the letter E (uppercase or lowercase).

You can use floating-point literals to achieve a wider range of numeric literal values.

Syntax Rules

  1. A floating-point literal must be between 4 and 37 (Alpha, I64) or 24 (VAX) characters in length.
  2. A floating-point literal must contain the following characters:
    • At least 1 digit to the left of the E
    • A decimal point to the left of the E
    • An E (uppercase or lowercase)
    • At least 1 digit to the right of the E
  3. The maximum number of characters to the left of the E is 33 (Alpha, I64) or 20 (VAX), of which no more than 31 (18 on VAX) can be digits.
  4. The maximum number of characters to the right of the E is 4 (Alpha, I64) or 3 (VAX), of which no more than 3 (2 on VAX) can be digits.
  5. A floating-point literal must not contain more than two sign characters as follows:
    • The first character of the literal
    • The first character following the E
  6. If the first character of the literal is not a sign character, the literal is positive.
  7. If the first character following the E is not a sign character, the value of the numeric component following the E is positive.
  8. A floating-point literal must contain only one decimal point that can appear only to the left of the E.
  9. A comma must be used in place of the decimal point, if the DECIMAL POINT IS COMMA clause is specified.

The value of a floating-point literal is the algebraic quantity represented by the characters in the literal that precede the E multiplied by ten raised to the power of the algebraic quantity represented by the characters in the literal following
the E.

Table 1-5 provides a few examples of floating-point literals.

Table 1-5 Floating-Point Literals
Literal Value
1.6e5 160000.0
3.2E-3 0.0032
-1.e4 -10000.0
0.002e+6 2000.0
-.8E-2 -0.008

1.2.2.2 Nonnumeric Literals

A nonnumeric literal is a character-string of 0 to 256 characters. It is delimited on both ends by quotation marks (") or apostrophes ('). A nonnumeric literal delimited by apostrophes is treated in the same manner as a nonnumeric literal delimited by quotation marks.

The value of a nonnumeric literal is the value of the characters in the character-string. It does not include the quotation marks (or apostrophes) that delimit the character-string. All other punctuation characters in the nonnumeric literal are part of its value.

The compiler truncates nonnumeric literals to a maximum of 256 characters.

Syntax Rules

  1. A space, left parenthesis, or pseudo-text delimiter (==) must immediately precede the opening quotation mark (or apostrophe).
  2. The closing quotation mark (or apostrophe) must be immediately followed by one of the following:
    • Space
    • Comma
    • Semicolon
    • Period
    • Right parenthesis
    • Pseudo-text delimiter
  3. If a nonnumeric literal is delimited by quotation marks ("), two consecutive quotation mark characters in the literal represent one quotation mark character.
  4. If a nonnumeric literal is delimited by apostrophes ('), two consecutive apostrophes in the literal represent one apostrophe (').

Table 1-6 provides examples of nonnumeric literals. In these examples, s represents a space character.

Table 1-6 Nonnumeric Literals
Literal Value
"ABC" ABC
"01" 01
"s01" s01
"D""E""F" D"E"F
"a.b" a.b
'GHI' GHI
'02' 02
's02' s02
'c.d' c.d
"""" "
'""' ""
'''' '
"''" ''
'J""K' J""K
"J""""K" J""K
'J''''K' J''K
"J''K" J''K
'L''M''N' L'M'N
"L'M'N" L'M'N
'O"P"Q' O"P"Q
"O""P""Q" O"P"Q
'R""S""T' R""S""T
"R""""S""""T" R""S""T
'U''''V''''W' U''V''W
"U''V''W" U''V''W

Hexadecimal Literals

A hexadecimal literal (a Hewlett-Packard extension to nonnumeric literals) is a character string of 2 to 256 hexadecimal digits. On the left it is delimited by the separator X (or x) immediately followed by a quotation mark (") or apostrophe ('); on the right it is delimited by a matching quotation mark or apostrophe. For example:


Previous Next Contents Index