A variable is temporary storage location used to hold a value. Variables have an associated identifier that lets you reference and work with the value stored in your computer's memory.
How variables work in ACLScript
Creating a variable and assigning a value
ACLScript uses the ASSIGN command to create a variable and assign it a value at the same time:
ASSIGN v_age_in_years = 3
For simplicity you can omit the ASSIGN keyword, however ASSIGN is implicitly used and the same command runs:
v_age_in_years = 3
ACLScript does not support null values. All variables must have an associated value of one of the supported data types. The script interpreter evaluates the data type using the data format and qualifier you use to assign the value. For more information, see Data types.
Once a variable is created, you can reference it anywhere you reference field names or variables. You can also reassign it a new value using the ASSIGN command.
EXTRACT RECORD TO 'result.fil' IF age > v_age_in_years v_age_in_years = 5
You can also use string interpolation, or variable substitution, to include a variable in a string literal by wrapping the variable name in % characters. When ACL encounters the substituted variable, it replaces the placeholder with its corresponding value:
ASSIGN v_table = erp_data OPEN %v_table%
Types of variables
ACL uses the following types of variables:
- system-generated variables automatically created after executing a command
- permanent variables remain in your computer's memory until you delete them and persist after closing the ACL project
To define a permanent variable, prefix the identifier with an '_': _v_company_name = 'Acme'.
- session variables remain in your computer's memory until you delete them or until the ACL project is closed
Variable identifiers are case-insensitive and follow certain conventions related to the type of variable:
- system-generated variable identifiers use all caps: OUTPUTFOLDER
- permanent variable identifiers must have a '_' prefix: _v_permanent
- session variable identifiers use the format v_varname by convention but you are not restricted to this naming convention
Viewing variable values
During script development or while debugging, it can be useful to track variable values as the script executes. To capture variable values in the script log file, use the DISPLAY command:
When the script encounters this command, it writes the command to the log file. To view the variable value at that stage of script execution, click the entry in the log.
You can also use variables to help debug by inserting breakpoints in your script and inspecting the variable values on the Variables tab of the Navigator.