CONSTANT

Overview

The Constant's Scope

Specifying the Data Type

Usage

Usage Restrictions

Overview

The CONSTANT instruction defines a constant that has a name and a predefined, unchangeable value (unlike a variable value that can be changed). The constants can be used throughout the 4GL code within their scope of reference after they were declared.

Constants can be useful in declaring special symbols and symbol combinations such as "\n".

Identifier

The name of the constant. It should be unique and differ from the names of the variables available in the same scope of reference.

Data Type

A Simple or a Structured data type (see the full list in the Specifying the Data Type section of this page ↓).

Value

The unchangeable value of the constant. Cannot be NULL.

Example:

CONSTANT const CHAR(3) = "5" -- the data type is CHAR(3)

The Constant's Scope

If no scope has been specified, the constants are private (have a Module scope). Constants can have a global, a module, or a local scope of reference depending on the position where they are declared.

The constants defined at the beginning of a module have the Module scope of reference by default. They are visible to and can be used only in the current module. You can declare a private constant explicitly by specifying the PRIVATE keyword before the CONSTANT statement.

A public constant can be referenced by other modules of the same program. To make a constant public, use the PUBLIC keyword before the CONSTANT keyword in the constant declaration. After that, the public constant can also be referenced using the IMPORT statement.

 

Return to top

Specifying the Data Type

The data types you can declare as a CONSTANT type are the following:

INTEGER SMALLINT BIGINT
BOOLEAN MONEY  
DECIMAL FLOAT SMALLFLOAT
CHAR VARCHAR  
DATE DATETIME INTERVAL
RECORD ARRAY DYNAMIC ARRAY

Example:

TYPE MyArrayType ARRAY[3] OF INT
TYPE MyDynamicArrayType DYNAMIC ARRAY OF INT
CONSTANT global_r3 MyArrayType        = [ 11343, "1223", "3"]
CONSTANT global_r4 MyDynamicArrayType = [   194,  "164",  14454.4,"4" ]

CONSTANT r1 RECORD v1 INT, v2 STRING END RECORD = (v1: 5, v2: "11A")
Note: Although in some cases (for integers, strings, and character data types), the data type definition for a constant can be omitted, we recommend to always specify the data type to ensure that no errors will occur.

If the data type has not been specified, the literal value assigned to the constant can define its data type implicitly.

Example:

CONSTANT const1 = 5 -- the data type is defined automatically as INT
CONSTANT const2 = "yes" -- the data type is STRING

 

Return to top

Usage

 

Return to top

Usage Restrictions

There are several restrictions as to in which statements and situations constants cannot be used:

 

Return to top

 

 

 

Contact Us

Privacy Policy

Copyright © 2026 Querix, (UK) Ltd.