Previous
Topic:
The NDL++ Data-Load Scripting Language |
Next
Topic: The #INCLUDE Directive |
Declaring Variables in NDL++ Scripts
NDL++ supports the declaration of variables for use in any NDL++ statement. Variables are declared in a VAR section of the script, which appears before the RECORD section and after the TYPE section (if present), and can be used in any of the expressions that appear subsequently in the script. To call a variable in an NDL++ expression, precede the variable name with the percent sign (%).The following considerations apply to the declaration and calling of variables in NDL++ scripts:
- Variable names cannot be longer than 256 characters. They must begin with either an alphabetic character or the underscore character ( _ ), and cannot contain spaces.
- By default, variables are case-insensitive. To enable case sensitivity, include the -q flag in the ndlm invocation.
- Variables cannot be called from the TYPE section or from within a PIC clause.
- Variables cannot be used in combination with the (position:length) style of field mapping.
- Variable expressions cannot be larger than 10 KB (10,240 ASCII characters).
Variable Declaration SyntaxVAR
{
variable-name( <variable-definition> )
...
}
Exampleinput: first-name, last-name, limit, owing
IMPORT @sample.dat
{TYPE
{
FLOAT field3,field4
}
VAR
{
V1(field1+field2)
V2(field3-field4)
}
RECORD
{
field1 *,
field2 *,
field3 *,
field4 *\r\n
}
finance.debtors
{
names (%V2<0)?(%V1):("Null")
}}
Results:
Variable V1 concatenates the first-name and last-name fields; variable V2 subtracts owing from limit. This script uses a conditional expression to insert the full names of debtors who have surpassed their credit limit into the names column of the finance.debtors table.
Previous
Topic:
The NDL++ Data-Load Scripting Language |
Next
Topic: The #INCLUDE Directive |