Constant types

Constants are classified into four types: integer, string, hexadecimal string, and bit. You do not declare types for constants; the value of a constant determines its type. The types can take the following values:
  • Integer constants are positive decimal integers from 0 to 2147483647.
    message_count = 0       /* 0 is an integer constant assigned to the    */
                            /* integer variable "message_count."           */
    if error_count = 5 then ...
                            /* Here the integer constant 5 is used to test */
                            /* the current value of the integer variable   */
                            /* "error_count."                              */
  • String constants are any set of characters. A string constant must be enclosed in a pair of single or double quotation marks (the string delimiter character). If a string constant contains the string delimiter character (a single or double quotation mark), that character must be entered twice so that it will be recognized. You will probably want to use single quotes as your delimiter character for strings containing double quotes and double quotes as a delimiter for strings containing single quotes. You do not have to use the same delimiter character throughout your program; you can use whichever is most appropriate for each string you are enclosing.
    The following examples show how string constants and the delimiting characters are used.
    message = 'Hello'     /* The string constant 'Hello' is assigned to   */
                          /* the string variable "message."               */
    message = 'Isn''t this fun!!!'
                          /* Notice the doubling of the single quotation  */
                          /* mark in the contraction when it is used as   */
                          /* the string delimiter.                        */
    message = "Isn't this fun!!!"
                          /* Notice the single quotation mark is not      */
                          /* doubled in the contraction when double       */
                          /* quotation marks are used as string           */
                          /* delimiters.                                  */
    Note: The string constants '' and "" have a length of zero and are called the null string.

    You can continue a string constant without a blank between the continued characters by ending a line with a quotation mark, entering the concatenation operator (││) and a comma, and continuing on a subsequent line with the rest of the string enclosed in quotation marks. If you do not use the concatenation operator, the continuation of the string follows an intervening blank (X'40').

    The following examples show how strings are concatenated.

    In the first example, the value of the variable "introduction" is "HelloGoodbye" without an intervening blank because the concatenation operator joins the two strings without a blank.
    introduction = 'Hello'││'Goodbye'
                          /* Here a string constant is used as part of a */
                          /* string expression.                          */
    In the next example, there is one space between "men" and "to" because a space is included before the string delimiter character. The concatenation operator joins the strings without an intervening blank.
    /*************************************************************************/
    /* Below, a long, continued string constant is assigned to "message."    */
    /*************************************************************************/
    message = 'Now is the time for all good men '││,
              'to come to the aid of their country.'
    /*************************************************************************/
    /* The previous STL statement assigns the variable "message" the value:  */
    /* Now is the time for all good men to come to the aid of their country. */
    /*************************************************************************/
    Note that ending spaces are included as part of the string.
    You could have included the blank and omitted the concatenation operator by coding the statement as follows:
    message = 'Now is the time for all good men',
              'to come to the aid of their country.'
    This statement would assign the same value to the variable “message”.

    There are no limits on the length of string constants, although string constants greater than 32767 characters may be truncated before use. If a string constant is too long, you will get a message indicating a possible truncation in your STL trace messages. See Obtaining STL trace records for more information about STL trace messages.

    Note: Double-byte character set data must be enclosed in SO and SI characters and must be coded on the same record.
  • Hexadecimal string constants are specified by enclosing pairs of hexadecimal digits in string delimiters followed by the character x or X. Each pair of hexadecimal digits represents a single character in the string.
    The following examples show how hexadecimal strings can be used in STL statements. Both statements have the same effect. The first statement assigns a hexadecimal string constant to a string variable. The second statement assigns the same value using a normal character string constant.
    message = 'C8859393965A'x      /* This statement uses a hexadecimal string. */
    message = 'Hello!'             /* This statement uses a normal string.      */
    You must use hexadecimal string constants when the data cannot be expressed using printable characters, as shown in the following example.
    if substr(data,1,3) = '0030FF'x then ... /* Test for a special 3-byte code. */
  • Bit constants can take the value ON or OFF. These constants can be assigned to bit variables or used to test the current setting of a bit variable. The following examples show how bit constants can be used.
    error_occurred = off              /* Bit variable "error_occurred"    */
                                      /* is initialized to OFF.           */
    if message_received = on then ... /* The bit constant ON is used to   */
                                      /* test the current setting of      */
                                      /* bit variable "message_received." */