Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

@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 Program type programs; it isn’t supported in Screen.
  • It can’t repeat a name already declared in global (E00298).
  • It doesn’t support struct templates (E00234, like any scope other than global).
  • In the generated RPG it is declared at module level, just like global; the visibility restriction is enforced by the compiler only.
  • An @Parameters parameter can be declared in global or in local. In local only the main body sees it, not the Procedure/Function blocks.

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, varchar and number are supported; any other type produces E00310.
  • 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) or E00311 is reported.
  • It can be read in any expression but never modified: assigning to it, using it as a For counter, passing it as an out/inout argument of a Call, or using it as the target of an Input produces E00312. Passing it to a Procedure/Function that modifies that parameter produces E00179.
  • An @Parameters parameter cannot be a constant (E00313).
  • In a printable Block of a Program it can be displayed, for example with @Label(1,1,&Title). In a Screen it 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 to n, so it behaves like a char(n) variable; a varchar is not padded.
  • A number is written with exactly the decimals of its scale (const Price number(9,2) = -5.5 generates dcl-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)

TypeLimit in @FieldsLimit in @Variables
char1–32,7661–16,773,104
varcharnot valid in @Fields1–16,773,100
number (precision)1–301–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.