Initialization of Variables

Transaction variables of type boolean, number and string can be initialized the first time the transaction where they are declared is called. If you omit an init value, the variable is initialized with the null value of its data type (false for boolean, zero (0) for number, and the empty string "" for strings).

注: You cannot use the keyword init with local variables of type BOOLEAN, NUMBER and FLOAT declared in functions. However, strings may be initialized in functions using the init keyword.

Example

dcltrans 
  transaction TMain; 
  var 
    nNumber : number  init 10; 
    fFloat : float  init 123.456; 
    bBoolean : boolean  init true; 
    sString : string  init "Hello world!"; 
  begin 
    write("number = "); write(nNumber); writeln; 
    write("float = "); write(fFloat); writeln; 

    if bBoolean then 
      write("boolean = true"); writeln 
    else 
      write("boolean = false"); writeln 
    end; 
  
    write("string = "); write(sString); writeln; 
  end TMain;

Output

number = 10 
float = 123.456 
boolean = true 
string = Hello world!