Domain: PROCEDURE
Command description
The DECLARE-CONSTANT command is used to declare one or more variables and to assign them a constant value, thus protecting these values from being overwritten. Variables with a constant value are treated in much the same way as ordinary variables. You cannot, however, modify their value using SET-VARIABLE or remove the value using FREE-VARIABLE.
Format
DECLARE-CONSTANT |
VARIABLE-NAME = list-poss(2000): <structured-name 1..20>(...) <structured-name 1..20>(...) VALUE = <text 0..1800 with-low expr> ,TYPE = *ANY / *STRING / *INTEGER / *BOOLEAN ,SCOPE = *CURRENT(...) / *PROCEDURE(...) / *TASK(...) *CURRENT(...) IMPORT-ALLOWED = *NO / *YES *PROCEDURE(...) IMPORT-ALLOWED = *NO / *YES *TASK(...) STATE = *ANY / *NEW / *OLD ,CONTAINER = *STD / <composed-name 1..64> / *VARIABLE(...) *VARIABLE(...) VARIABLE-NAME = <structured-name 1..20> ,SCOPE = *VISIBLE / *TASK |
Operands
VARIABLE-NAME = list-poss (2000): <structured-name 1..20>(...)
Name of the constant variable to be declared. The variable must be a simple variable; it must not be a complex variable or a variable element.
VALUE = <text 0..1800 with-low expr>
Assigns a variable a constant value; the value must be compatible with the data type of the variable and may be specified as an expression.
TYPE =
Assigns the data type to the variable.
TYPE = *ANY
The data type STRING, INTEGER or BOOLEAN may be assigned to the variable. The data type cannot be changed once a constant variable has been declared.
TYPE = *STRING
Assigns the data type STRING to the variable.
Value range: any character string.
TYPE = *INTEGER
Assigns the data type INTEGER to the variable.
Value range: integer between -231 and 231-1.
TYPE = *BOOLEAN
Assigns the data type BOOLEAN to the variable.
Value range: TRUE, FALSE, YES, NO, ON, OFF.
SCOPE =
Defines the variable scope.
SCOPE = *CURRENT(...)
The variable is a procedure-local variable.
In call procedures, this corresponds to the entry PROCEDURE.
In include procedures, CURRENT means that the variable is declared in the current include procedure. It is then visible in this include procedure and in all include procedures on lower nesting levels (= scope: include).
IMPORT-ALLOWED =
Specifies whether the variable can be imported with IMPORT-VARIABLE in a called procedure.
IMPORT-ALLOWED = *NO
The variable cannot be imported with IMPORT-VARIABLE in a called procedure.
IMPORT-ALLOWED = *YES
The variable can be imported with IMPORT-VARIABLE in a called procedure.
SCOPE = *PROCEDURE
The variable is a procedure-local variable with the scope procedure.
The variable is declared in the current procedure.
In include procedures, the current procedure is always the higher-ranking call procedure from which the include procedure was called.
The variable is visible in this procedure and in all include procedures on lower nesting levels.
IMPORT-ALLOWED =
Specifies whether the variable can be imported with IMPORT-VARIABLE in a called procedure.
IMPORT-ALLOWED = *NO
The variable cannot be imported with IMPORT-VARIABLE in a called procedure.
IMPORT-ALLOWED = *YES
The variable can be imported with IMPORT-VARIABLE in a called procedure.
SCOPE = *TASK(...)
The variable is a task-global variable.
If it is declared in an include procedure, it is also visible in the higher-ranking call procedure from which the include procedure was called and in all include procedures on lower nesting levels.
STATE = *ANY
If a variable with the specified name already exists in the task, this variable is used; otherwise a new variable is declared.
STATE = *NEW
The task should not contain any variables with the specified name.
STATE = *OLD
The task must contain a variable with the specified name. The current variable declaration must then match the declaration of the existing variable.
CONTAINER = *STD
The variables cannot be assigned variable containers. The value of the variable is stored in class 5 memory.
CONTAINER = <composed-name 1..64>
Links the currently declared variable with the variable container specified here.
This variable container must already be open. “STD” must not be specified here, because “STD” is not interpreted as a permanently existing variable container.
CONTAINER = *VARIABLE(...)
Links the currently declared variable to another variable already defined in this procedure via a link mechanism. This variable is then known as the variable container.
Structure elements cannot be specified as variable containers.
VARIABLE-NAME = <structured-name 1..20>
Name of a variable already defined in the procedure. The variable attributes used as variable containers and the currently declared variable must be compatible with each other. This variable must also be declared with a constant value (the same constant value as is used in the VARIABLE-NAME operand) and with a constant data type.
SCOPE =
Scope of the container variable.
SCOPE = *VISIBLE
The variable is visible.
SCOPE = *TASK
Task variable.
Command return codes
(SC2) | SC1 | Maincode | Meaning/Guaranteed messages |
0 | CMD0001 | No error | |
1 | 0 | CMD0001 | Warning; element already declared |
1 | CMD0202 | Syntax error | |
3 | CMD2203 | Incorrect syntax file | |
32 | CMD0221 | System error (internal error) | |
64 | CMD0216 | Do not have required privilege | |
64 | SDP0091 | Semantic error Guaranteed messages: SDP1018, SDP1030 | |
130 | SDP0099 | No further address space available |
Example
/DECLARE-CONSTANT KBYTE(TYPE=*INTEGER,VALUE=1024) /DECLARE-CONSTANT MBYTE(TYPE=*INTEGER,VALUE=KBYTE*KBYTE) /DECLARE-CONSTANT PAMPAGE(TYPE=*INTEGER,VALUE=2*KBYTE) /DECLARE-VARIABLE FILE(TYPE=*STRUCTURE) /DECLARE-VARIABLE FILES(TYPE=*STRUCTURE),MULTIPLE-ELEMENTS=*LIST /EXECUTE-CMD (SHOW-FILE-ATTRIBUTES *ALL),STRUCTURE-OUTPUT=FILES,- / TEXT-OUTPUT=*NO / /FOR FILE=*LIST(FILES) / IF (FILE.F-SIZE * PAMPAGE >= 5 * MBYTE) / WRITE-TEXT 'VERY HUGE FILE &(FILE.SHORT-F-NAME)' / ELSE-IF (FILE.F-SIZE * PAMPAGE >= 100 * KBYTE) / WRITE-TEXT 'HUGE FILE &(FILE.SHORT-F-NAME)' / END-IF /END-FOR
This procedure declares three variables: ’KBYTE’, ’MBYTE’ and ’PAMPAGE’. They are declared with a constant value to ensure that they are correct throughout the entire procedure. Their values cannot be changed.
These variables are needed to test the size of the files of the current user ID.