Add

Tuesday, August 4, 2009

Variable scope and initialization

Global and Local Variables
All variables have a defined "scope", that is, a defined set of places where itcan be accessed. A variable is said to have "global" scope if it can be accessedanywhere in an object. A variable is said to have "local" scope if it can only beaccessed in a single trigger in an object. No variables can be accessed outsideof the object in which they are defined.
System Defined Variables
Certain variables are automatically defined and maintained by the system. Anexample of this is the variable called Rec in table objects. Each object has itsown set of system-defined variables. The programmer can use these variableswhenever they need to without doing anything special to either create them orto initialize their values.
Variable Initialization
Before any C/AL code is executed, all programmer-defined variables areinitialized with certain values.
· For all variables with a numeric type, this value is 0.
· For string variables, the value is the empty string ('').
· For Boolean variables, the initial value is FALSE.
· For Date and Time type variables, this initial value is 0D (the undefineddate) and 0T (the undefined time) respectively.

No comments: