Products Downloads


French version


 


VADELIA

SADELIA

WADELIA

EADELIA


(I/B) (C/S)

(B) (S)

(I/B) (C/S)

(B) (C/S)


Section for use

DECLARATION



Syntax

Syntax 1

CONST  

Id type = Value

or

CONST  

REF(VarId) Id  = Value



Type

ALPHA | NUM_BIN2 | NUM_BIN_4 | NUM_BIN_8 | NUM_E | NUM_P | BOOL | DATE | TIME | TIMESTAMP



Value NumLitConstant | AlphaLitConstant | NonTypeConstantId | NonTranslatableDicConstantId | *TRUE | *FALSE | *LOVAL | *HIVAL
Syntax 2

CONST  

Id  = Value



Value

NumLitConstant | AlphaLitConstant | NonTypeConstantID | NonTranslatableDicConstantId

| *TRUE | *FALSE


                 

Description

The CONST qualifier is used to declare a typed named constant (syntax 1), or untyped named constant (syntax 2) called Id with the Value value. Unlike a dictionary constant, named constants declared with the CONST qualifier are private (only concern the program in which they are declared).
This keyword enables the programmer to tell the 3GL generator that the element with this qualifier must not be modified. The element will therefore be constant throughout program execution, including when it is passed as an argument from a procedure, program or class/dll call order. This means that the Value of a constant must be defined when it is declared.

The CONST qualifier does not accept the declaration of array-type elements.

Like for a variable, the constant declaration can be associated with a logical server, making it visible for the relevant logical server only.


A typed named constant (syntax 1) follows the same declaration rules as the Type associated with it.
Its Value must correspond to a literal which is compatible with its type and any associated attributes (length, precision), a previously declared untyped named constant, or a compatible non- translatable dictionary constant.
For the BOOL type, only the reserved words *TRUE/*FALSE are accepted, and for DATETIME_T, TIMESTAMP type, Value must correspond to a character string in *ISO format TIMESTAMP (see documentation relating to the predefined functions &ALPHA_DATE, &ALPHA_TIME and &ALPHA_TIMESTAMP for the alphanumeric representation definition in *ISO format). Reserved words *LOVAL/*HIVAL are also accepted as Value, and, along with *TRUE and *FALSE, are the only authorized reserved words.

The REF keyword can be used to declare a typed named constant with the same definition as the VarId data environment variable.

Finally, and in addition to assignment expressions and conditional expressions, a typed named constant can be used in instructions and functions for which a literal argument is accepted, with the exception of declarative instructions. It can also be used as an input host variable in SQL instructions. In the latter case, the Id constant identifier must be preceded by the ":" character.


An untyped named constant (syntax 2) corresponds to a simplified version of syntax 1, where the type is implicit and automatically deduced from the Value. The possible types for a ALPHA Value are in character string form, NUM_E for a Value in numeric literal form and BOOL when Value is *TRUE or *FALSE. A previously declared untyped named constant and a compatible non-translatable dictionary constant are also accepted as a Value.
Finally, and in addition to assignment expressions and conditional expressions, an untyped named constant can be used in instructions and functions for which a literal argument is accepted, including for declarative instructions (for example, dimensions in an array variable declaration)It can also be used as an input host variable in SQL instructions. In the latter case, the Id constant identifier must be preceded by the ":" character. 



Example

CONST ConstWithoutType = 'An implicit alpha constant'

CONST ALPHA(50) ConstAlpha = 'An alpha constant'

CONST ConstBool = *TRUE


CONST ConstNumWithoutType= -3

CONST NUM_BIN_8 ConstNum = ConstNumWithoutType


CONST Dim1Tab = 1000

DATE VarArrayDate(Dim1Tab)


TIMESTAMP VarTsp

CONST REF(VarTsp) ConstFromRef = '2023-09-01-10.10.10.000000'


CONST ConstValueFromDictionary = _NotTranslatableDicoConstEntry




↑ Top of page



  • Aucune étiquette