Variable
A Variable definition is used to create a variable that can hold data. It can be a simple variable (storing a single value) or a compound variable (storing multiple values). These variables can be defined and used in different places, such as within a report, a function, or across the entire system.
Syntax
[Variable : <Variable Name>]
Example
[Variable : TSPL Variable]
Type : String
This example defines a variable named TSPL Variable, with its type set to String.
➥ Click here to download Variable_Sample
Attributes
The Default attribute is used to assign an initial value to a variable based on its defined type. This value is automatically set when the variable is first initialized, ensuring that it has a valid and predictable state before being used in any logic or operation. By defining a default value, developers can avoid uninitialized variables and ensure consistent behavior across executions.
Syntax
[Variable : <Variable Name>]
Default : <Logical Value>
Example
[Variable : TSPL Variable]
Type : Logical
Default : Yes
The Default initial value for the Variable TSPL Variable of the type set to Logical is set to YES. This variable will begin with an initial value YES in the Reports, unless overridden by a System Formula.
A List Variable is used to store multiple values as a collection, where each entry can be either a simple variable or a compound variable. These variables can be defined directly within the variable definition or referenced from an existing variable structure. By using a list variable, developers can manage and process groups of related data together, making it suitable for scenarios that involve repeating or structured records.
Syntax
[Variable : <Variable Name>]
List variable : <Value>
Example
[Variable : TSPL Variable]
List variable : TSPL_List_Entry
[Variable: TSPL_List_Entry]
Variable : ItemName : String
Variable : Qty : Number
In this example, TSPL Variable declares TSPL_List_Entry as a List Variable, meaning it can hold multiple sets of values. The second definition, Variable: TSPL_List_Entry, describes what each item in this list will contain. It defines two components:
- ItemName of type String, which will store string values.
- Qty of type Number, which will store numerical values.
Together, this creates a structured list where each entry includes both a string and numeric value, making it useful for managing groups of related data.
The Local attribute allows you to assign a value that is applicable only within the scope of the current definition. The value set using this attribute is temporary and remains confined to that definition, ensuring that it does not modify or override the variable or attribute in any other context.
The Local attribute in TDL is not directly used within the Variable definition block itself. Instead, it is used as an attribute modifier to locally override or set the value of an attribute for a specific instance of a definition (such as Field, Line, Report, etc.) within a particular scope without affecting the global definition.
Syntax
[Variable: Variable Name]
Local: Variable: <Variable Name1>: <Attribute> : <Value>
Example
[Variable: RepeatCollection]
Type : String
Volatile : No
Local: Variable: TSPL_Simple_Var : Default: No
In this example, the variable Repeat collection is defined with type String. The piece of code will set the default value of TSPL_Simple_Var to No only within the current scope.
This attribute determines whether a variable retains its value beyond the current session. When set to Yes, the variable stores its most recent value and restores it across sessions, as long as the variable is not defined as a local variable. This attribute is useful for preserving state or preferences that need to persist between executions.
Note: Persistent is an alias for the attribute Persist.
Syntax
[Variable : <Variable Name>]
Persistent : <Logical Value>
Example
[Variable : TSPL Variable]
Type : String
Persistent : Yes
In this example, the variable TSPL Variable is defined as a String type and marked as Persistent : Yes.
This means the value assigned to this variable will remain stored even after TallyPrime is closed and reopened.
The Repeat attribute is primarily used to enable Auto Column behavior in reports. It takes a variable that contains a collection of objects and dynamically generates columns based on that collection. Each time the Repeat attribute is evaluated, a new column is created for the corresponding object in the collection. This allows reports to automatically expand or shrink their columns at runtime, depending on the data available, without requiring predefined static column definitions.
Syntax
[Variable : <Variable Name>]
Repeat : <Variable Value>
Example
[Variable: TSPL Variable]
Type : String
Default : Yes
Repeat: ##RepeatCollection
[Variable: RepeatCollection]
Type : String
Volatile : No
##RepeatCollection variable receives the Collection Name from the Child report, which accepts inputs from the user regarding the columns required. Variable TSPL Variable gets repeated over the subsequent period in the Collection each time the column repeats.
The Set Always attribute is used to ensure that the value displayed is refreshed every time any of the values it depends on change. Instead of being calculated only once, it is recalculated continuously, keeping the displayed value up to date. This is especially useful for dynamic fields where the output must instantly reflect changes in related inputs.
Syntax
[Variable : Variable Name]
Set Always : <Logical Value>
Example
[Variable: TSPL Variable]
Type : Logical
Set Always : Yes
In this example, the variable TSPL Variable is defined with the type Logical, meaning it can hold a Yes/No value. By setting Set Always : Yes, the value of this variable is automatically recalculated and refreshed whenever any dependent values or conditions change. This ensures that the logical state of the variable is always up to date and accurately reflects the current conditions during execution.
The System Name attribute determines whether a variable can store system names (sysnames) used internally by Tally. When enabled, the variable can hold internal identifiers such as names of masters, reports, or other system-defined objects. This is useful when working with internal references rather than user-facing values, enabling precise identification and reuse of system-level entities within TDL logic.
Syntax
[Variable : <Variable Name>]
System Name : <Logical Value>
Example
[Variable : TSPL Variable]
Type : String
System Name : Yes
In this example, the variable TSPL Variable is defined as a String, which means it will store text-based values. Since System Name is set to Yes, the variable will hold all the system names in Tally.
The Type attribute specifies the kind of value a variable can store, such as String, Number, Date, or Logical (True/False). If this attribute is not explicitly defined, the variable automatically defaults to the String type. Defining the type ensures proper handling, validation, and interpretation of the variable’s value during execution.
Syntax
[Variable : <Variable Name>]
Type : <Data Type>
Example
[Variable : TSPL Variable]
Type : Logical
A logical variable, TSPL Variable, is defined and used to control the behaviour of certain reports, based on its logical value, as configured by the user.
The Variable attribute is used to define whether a variable is Simple or Compound within a Variable definition. A simple variable holds a single value, whereas a compound variable groups multiple related variables together under one definition. This enables structured data handling and helps organize related values in a logical and manageable way.
Syntax
[Variable : <Variable Name>]
Variable : Variable Name
Example
[Variable : TSPL Variable]
Variable : vErrorCodeNumber
In this example, the Variable definition named TSPL Variable declares a sub-variable called vErrorCodeNumber using the Variable attribute. This means that TSPL Variable is treated as a compound variable, capable of holding multiple related values.
The Volatile attribute determines whether a variable can retain multiple values over time. When set to Yes, the variable behaves like a stack, preserving its original value along with any subsequent values assigned to it. This allows previous values to remain available instead of being overwritten. By default, variables are volatile unless this attribute is explicitly set otherwise.
Syntax
[Variable : <Variable Name>]
Volatile : <Logical Value>
Example
[Variable : TSPL Variable]
Type : String
Volatile : Yes
In this example, the variable TSPL Variable is defined with the type String. By setting Volatile: Yes, the variable is configured to retain multiple string values over time, maintaining them as a stack rather than overwriting the previous value. This allows the variable to preserve its original value along with any new values assigned during execution.
