@Variables
Declares variables inside a named scope: global (visible throughout the file) or the name of a Procedure/Function declared in @Source (visible only inside that procedure/function, in addition to global ones).
@Variables {
global {
Username char(10)
MyDate date
Balance number(9,2)
}
MyProcedure {
counter number(3)
}
Greet {
name char(10)
}
}
One Name type(...) line per variable — same format as @Fields, but with more available types (see Data types): char, varchar, number, date, field(Field), list(type), matrix(rows, cols, type), struct(TemplateName).
local scope
local is a reserved scope, alongside global and the names of Procedure/Function. Its variables are only visible in the main body of @Source (outside any Procedure/Function) and in @Layout. Using them inside a Procedure/Function produces E00146.
@Variables {
global {
Username char(10)
}
local {
counter number(3)
message char(40)
}
}
- It only makes sense in
Programtype programs; it isn’t supported inScreen. - It can’t repeat a name already declared in
global(E00298). - It doesn’t support
structtemplates (E00234, like any scope other thanglobal). - In the generated RPG it is declared at module level, just like
global; the visibility restriction is enforced by the compiler only. - An
@Parametersparameter can be declared inglobalor inlocal. Inlocalonly the main body sees it, not theProcedure/Functionblocks.
Struct: inline template definition
Inside the global scope (only there) you can also define a struct template with struct Name [ ... ], before or after instantiating it with struct(Name) — see Data types: Struct for the full syntax and its limits (including nested structs and list(struct(...)) as a member).
Modifier
Only Description("text") is available in @Variables (unlike @Fields, it doesn’t support Default/AllowNull):
@Variables {
global {
RequestNo field(ADHOJA50) Description("Request number")
}
}
Constants
Inside any scope (global, local or that of a Procedure/Function), in Program and in Screen, you can declare a constant with const Name type = value:
@Variables {
global {
const MaxItems number(3,0) = 100
const Price number(9,2) = -5.5
const Title char(30) = "Pass report"
const Greeting varchar(30) = "Hello" Description("Initial greeting")
}
}
- Only
char,varcharandnumberare supported; any other type producesE00310. - The value must be a literal of the same type: quoted text, or a number (integer or decimal) with an optional
-sign. It must fit the type (text no longer than the length; a number with no more decimals than the scale and no more integer digits than the precision allows) orE00311is reported. - It can be read in any expression but never modified: assigning to it, using it as a
Forcounter, passing it as anout/inoutargument of aCall, or using it as the target of anInputproducesE00312. Passing it to aProcedure/Functionthat modifies that parameter producesE00179. - An
@Parametersparameter cannot be a constant (E00313). - In a printable
Blockof aProgramit can be displayed, for example with@Label(1,1,&Title). In aScreenit cannot be displayed in a screen field (Label/Input/Column):E00314; copy it to a variable.
In the generated RPG it is declared as a named constant (dcl-c NAME value;):
- A
char(n)text is padded with blanks up ton, so it behaves like achar(n)variable; avarcharis not padded. - A number is written with exactly the decimals of its scale (
const Price number(9,2) = -5.5generatesdcl-c Price -5.50;). - An RPG numeric constant has no precision of its own (the context where it is used sets it), but WARP treats it as the declared type for type checks.
Length/precision limits (standalone variable, different from a table field)
| Type | Limit in @Fields | Limit in @Variables |
|---|---|---|
char | 1–32,766 | 1–16,773,104 |
varchar | not valid in @Fields | 1–16,773,100 |
number (precision) | 1–30 | 1–63 |
These larger limits in @Variables reflect that a variable declared there isn’t tied to a DDS physical file the way an @Fields field is.