Explore Categories

 

 PDF

Variable Related Actions

Copy Variable

The action COPY VARIABLE is used to copy the content from one variable (Source) to another variable (Destination). This action is supported for all types of variables (Simple/Compound/List Variables).

Syntax

COPY VARIABLE : <Destination Variable> : <Source Variable>

Where,

<Destination Variable> is the name of the Simple/Compound/List Variable.

<Source Variable> is the name of the Simple/Compound/List Variable, from which the content has to be copied.

Example: Copying from Simple Variable to Simple Variable

[Function : SimpleVar Copy Function]

VARIABLE : SimpleVar1 : String : “Employee1”

VARIABLE : SimpleVar2 : String

10 : COPY VARIABLE : SimpleVar2 : SimpleVar1

20 : LOG                      : “Source” + ##SimpleVar1

30 : LOG                      : “Destination” + ##SimpleVar2

In this example, the variables SimpleVar1 and SimpleVar2 are declared at the Function level. After execution of the action COPY VARIABLE , the content of the variable is copied from SimpleVar1 to SimpleVar2 .

Example: Copying from Compound Variable to Compound Variable

Let us suppose that the following compound variables are defined:

[Variable : Employee1]

Variable : EmpName : String : “Praveen”

Variable : Designation : String : “Manager”

[Variable : Employee2]

Variable : EmpName : String

Variable : Designation : String

In the function below, contents are copied from Compound Variable Employee1 to Employee2:

[Function : Compound Var Copy Function]

VARIABLE : Employee1

VARIABLE : Employee2

10 : COPY VARIABLE : Employee2 : Employee1

20 : LOG           : “Source” + ## Employee1.EmpName

30 : LOG           : “Source” + ## Employee1.Designation

40 : LOG           : “Destination” + ## Employee2.EmpName

50 : LOG           : “Destination” + ## Employee2.Designation

Note: The content will be copied from a member variable of a Compound Variable (Source) to another member variable of a compound variable (Destination), based on the member variable names, since more than one member variable may have the same data type.

Example: Copying from List Variable to List Variable

Let us suppose that the following compound variables are defined:-

[Variable : Employee1]

Variable : EmpName : String

Variable : Designation : String

[Variable : Employee2]

Variable : EmpName : String

Variable : Designation : String

In the following function, the compound variables Employee1 and Employee2 are declared as List Variable. We are copying all the elements from the compound list variable Employee1 to the compound list variable Employee2 .

[Function : ListVar Copy Function]

LIST VARIABLE  : Employee1, Employee2

10 : LIST FILL : Employee1 : Employees : $Name : $Name

20 : LIST FILL : Employee1 : Employees : $Name : $Designation + :Designation

30 : COPY VARIABLE : Employee2 : Employee1

40 : LOG    : “Source Variable – Employee”

50 : FOR IN   : KEY VAR : Employee1

60 : LOG      : $$LISTVALUE:Employee1:##KEYVAR:EmpName

70 : LOG      : $$LISTVALUE:Employee1:##KEYVAR:Designation

80 : END FOR

90 : LOG      : “Destination Variable – Employee”

100 : FOR IN  : KEY VAR : Employee2

110 : LOG     : $$LISTVALUE:Employee2 : ##KEYVAR:EmpName

120 : LOG     : $$LISTVALUE:Employee2 : ##KEYVAR:Designation

130 : END FOR

Decrement

This action is used to decrement the value of variables by any numerical value. DECREMENT is used inside the loop to decrement the value of the control variables.

Syntax

DECREMENT : <Variable Name> [,<Variable Name>, …] [:<Number Expression>]

Where,

< Variable Name > is the name of the variable whose value needs to be decremented by the number specified.

< Number Expression > is the numerical value by which the variable needs to be decremented. If no number is given, the variable will be decremented by 1.

Example

[Function : PrintNumbers]

Variable : Counter : Number

1 : SET : Counter : 10

2 : WHILE : ##Counter >

3 : LOG : ##Counter

4 : DECREMENT : Counter

5 : ENDWHI L E

6 : RETURN

In the function ‘PrintNumbers’, the loop is running from 10 to 1.

Exchange

This action is used to swap the values of two variables, provided both belong to the same data type. This cannot be done for Simple List or Compound List as a whole. However, values of elements of Simple List and Compound List member variables having same data type can be exchanged.

Syntax

EXCHANGE : <First Variable Specification> : <Second Variable Specification>

Where,

<First Variable Specification> is the simple variable specification.

<Second Variable Specification> is the simple variable specification.

Exchanging value of a simple variable with another simple variable.

EXCHANGE : EmpVarOld : EmpVarNew

Both the Variables are of ‘String’ data type. The value of the variable Emp VarOld is exchanged with that of the variable Emp VarNew on execution of the action.

Exchanging value of an element of  Simple List Variable with that of another Simple List Variable.

EXCHANGE : SlvEmpOld[1] : SlvEmpNew[1]

The value of the first element  of SLV EmpOld is exchanged with that of the first element of SlvEmpNew. Both the Simple List Variables are of ‘String’ data type

Exchanging value of a simple variable with a member variable of a compound list variable.

EXCHANGE : EMP Salary : CLVEmp[1].Salary

The value of a variable EMP Salary is exchanged with that of the member variable “Salary’ of the Compound List Variable CLV Emp. Both the simple variables are of String data type. 

Increment

INCREMENT is a special action provided in ‘Function’ scope to increment values of the variable. This is supported only on simple variables of type Number.

Syntax

INCREMENT : <Simple Variable Specification> [:<NumIncrement Expression>]

Where,

<Simple Variable Specification> is the simple variable specification.

<NumIncrementExpression> is an expression which evaluates to a number. Based on this, the Variable value is incremented. It is optional. If not specified, the variable value is incremented by 1.

Example:

INCREMENT : Counter

;; Incrementing the variable value by 1

INCR : Counter : 2

;; Incrementing the variable value by 2

List Add

The action LIST ADD is used to add the values in a List variable. It adds a single value at a time to the list variable, identified by a key. If the value is added to the list with a duplicate key, then the existing value is overwritten. LIST SET is an alias for the action LIST ADD.

Syntax

LIST ADD : <List Var Name> : <Key Formula> : <Value Formula>

Where,

<List Var Name> is the name of the list variable.

<Key Formula> can be any expression formula which evaluates to a unique string value.

<Value Formula> can be any expression formula which returns a value. The data type of the value must be the same as that of the List variable.

Example

LIST ADD : TestFuncVar : “Mobile” : 9340193401

LIST ADD : TestFuncVar : “Office” : 08066282559

LIST ADD : TestFuncVar : “Fax” : 08041508775

LIST ADD : TestFuncVar : “Residence” : 08026662666

The four values inserted in the list variable ‘Test Func Var’ are identified by the key values ‘Mobile’, ‘Office’, ‘Fax’ and ‘Residence’ respectively.

List Add Ex

This action is used on a list variable to a d d an element to the list variable without KEY.

Syntax

LIST ADD EX : <List Variable Specification> [:<Value Formula> [:<Member Specification>]]

Where,

<List Variable Specification> is the Simple List/Compound List Variable specification.

<Key Formula> can be any expression which evaluates to a unique string value.

<Value Formula> can be any expression which returns a value. It sets the initial value of the element variable, and is optional.

<Member Specification> is required only if the value needs to be added to a specific member of a Compound List Variable. If member specification is not provided, the first member variable is considered for the value.

Note: Action LIST APPENDEX is an alias for the action LIST ADDEX.

Adding elements to Simple List Variable using LIST ADD EX

  • Adding an element to Simple List Variable SLV Emp

LIST ADD EX : SLV Emp

  • Adding an element to Simple List Variable SLV Emp, with Value

LIST ADD EX : SLV Emp : “Kumar”

Adding elements to Compound List Variable using LIST ADD EX

  • Adding an element to Compound List Variable CLV Emp

LIST ADD EX : CLV Emp

  • Adding an element to Compound List Variable CLV Emp, with value

LIST ADD EX : CLV Emp : “Kumar”

Here, since member specification is not provided, first member variable is considered for value.

  • Adding an element to Compound List Variable CLV Emp, with value and member specification

LIST ADDEX : CLV Emp : 25 : Age

Here, member specification is provided, hence member variable ‘Age’ is considered for the value.

  • Adding an element to the Compound List Member variable of a Compound List Variable with value and member specification

LIST ADDEX : CLVEmp[1].Relatives : “Prem” : Name

In this example, we are adding an element to the Compound List Variable “Relatives” and the member variable ‘Name’ is considered for the value. ‘Relatives’ is a Compound List Member variable of the Compound List Variable CLVEMP.

List Delete

The action LIST DELETE is used to delete values from the List variable. It allows deleting a single value at a time or all the values in one go.

Syntax

LIST DELETE : <List Var Name> [:<Key Formula>]

Where,

<List Var Name> is the name of the list variable.

<Key Formula> can be any expression formula which evaluates to a unique string value. In the absence of key formula, all the values in the list will be deleted. In other words, if key formula is omitted, the list is reset.

Example: 1

LIST DELETE : TestFuncVar : “Office”

The value identified by the key ‘Office’ is deleted from the list variable ‘Test Func Var’.

Example: 2

LIST DELETE : TestFuncVar

All the values in the list variable TestFuncVar are removed. The list variable is empty after the execution of the action.

List Delete Ex

This action is used to delete an element from the list based on index. Index formula is optional. If not specified all the elements in the list are deleted. A negative index denotes reverse position. 

Syntax

LIST DELETE EX : <List Variable Specification> [:<Index Formula>]

Where,

<List Variable Specification> is the Simple List or Compound List Variable specification.

<Index Formula> can be any expression which evaluates to an index number. It is optional. 

Note: Action LIST REMOVE EX is an alias for the action LIST DELETE EX.

Deleting elements from Simple List Variable using LIST DELETE EX

  • Deleting a single element from a simple List Variable

LIST DELETE EX : SLVEmp : 2

The element identified by index number ‘ 2 ’ will be deleted from Simple List Variable  SLC Emp.

  • Deleting all elements from a simple List Variable

LIST DELETE EX : SLVEmp

Since index formula is not specified, all elements from Simple List Variable SLV Emp are deleted.

Deleting elements from a Compound List Variable using LIST DELETE EX

  • Deleting an element from a Compound List Variable

LIST DELETE EX : CLVEmp : 10

The element identified by index ‘1 ’ will be deleted from the Compound List Variable CLV Emp.

  • Deleting all elements from a Compound List Variable

LIST DELETE EX : CLVEMP

Since index formula isn’t specified, all elements of compound list variable CLV EMP are deleted.

List Expand

The Action LIST EXPAND is used to create the specified number  of blank elements and insert them into the list. All these elements are created without a key. If key specification is required for each element then either LIST FILL or a loop can be used to add elements individually. 

Syntax

LIST EXPAND : <List Variable Specification> : <Count Formula>

Where,

<List Variable Specification> is the Simple List or Compound List variable specification.

<Count Formula> can be any expression which evaluates to a number.

Example:

Expanding Simple List Variable using LIST EXPAND

LIST EXPAND : SLVEMP : 10

Here, count formula is 10. Hence , 10 blank elements are added to Simple List Variable ‘ SLVEMP’.

Expanding Compound List Variable using LIST EXPAND.

LIST EXPAND : CLVEMP : 5

Here, count formula is 5. Thus, 5 blank elements are added to the Compound List Variable ‘CLV EMP’. 

LIST EXPAND : CLVEMP[1].Relatives : 10

Here, count formula is 1. Hence, 10 blank elements are added to Compound List Variable ‘Relatives’. ‘Relatives’ is a Compound List Member variable of the Compound List Variable ‘CLVEMP’.

List Fill

It is used to add multiple values from a collection to the List Variable.

Syntax

LIST FILL : <List Var Name> : <Collection Name : <Key Formula> : <Value Formula>

Where,

<List Var Name> is the name of the list variable.

<Collection Name> is the name of the collection from which values are fetched to fill the list variable.

<Key Formula> can be any expression formula which evaluates to a string value.

<Value Formula> can be any expression formula which returns a value. The data type of the value must be the same as that of the List variable.

The action LIST FILL returns the number of items added to the list variable.

Example

LIST FILL : TestFuncVar : Group : $Name : $Name

List Key Sort

This action allows sorting the list based on a key value. If the data type specified while sorting the list is different than the original, then this action will temporarily convert the original data type to the specified data type while comparing the elements for sorting the list and the list will be sorted based on the new data type specified. The original list and the key data type remains as it is, on which a new sorting can be applied, based on some other data type, at any other point of time. LIST SORT is an alias of the action LIST KEY SORT.

Syntax

LIST KEY SORT : <List Var Name> [:<Asc/Desc flag> : <Key Data Type>]

Where,

<List Var Name> is the name of the list variable.

<Asc/Desc> can be YES/NO. YES is used to sort the list in ascending order and NO for descending. If the flag is not specified, then the default order is ascending.

<Key Data Type> can be String, Number, etc. It is optional.

Example: 1

LIST KEY SORT : Test Func Var : YES : String

The values in the list variable are sorted in ascending order of the key.

Example: 2

In case a different data type is used for sorting, the key may become duplicate if the conversion fails as per the data type specified for sorting. If the key becomes duplicate, then the insertion order of the items in the list variable is used for comparison.

LIST KEY SORT : Test Func Var : YES : Number

In this example, the action LIST KEY SORT will convert the key to ZERO (0) for all the list items while comparing, as all the keys are of type String. In this case, the insertion order will be considered for sorting. As a result, the values in the list will be sorted in the following order: 9340193401, 08066282559, 08041508775, and 08026662666.

In case the key contains numeric values like “11”, “30”, “35” and “20”, which can be converted to Number, the list is sorted based on the key values, else it converts them to ZERO and sorts the list as per the order of insertion.

 List Value Sort

Action LIST VALUES SORT sorts the list items based on value. As there can be duplicate values in the list, the combination of key and value is considered as key for sorting duplicate values.

Syntax

LIST VALUE SORT : <List Var Name> [:<Asc/Desc flag> : <Key Data Type>]

Where,

<List Var Name> is the name of the list variable.

<Asc/Desc> can be YES/NO. YES is used sort the list in ascending order and NO for descending. It is optional. If the flag is not specified, then the default order is ascending.

<Key Data Type> can be String, Number, etc. It is optional.

Example

LIST VALUE SORT : Test Func Var : YES : String

The values in the list variable are sorted in ascending order of values.

List Reset Sort

The action LIST RESET SORT retains the sorting back to the order of insertion.

Syntax

LIST RESET SORT : <List Var Name>

Where,

<List Var Name> is the name of the list variable.

Example

LIST RESET SORT : TestFuncVar

Here, the action resets the sort order of the list variable ‘Test Func Var’ to the order of insertion.

Load Variable

The action LOAD VARIABLE is used to reload the report scope variables from the specified file.

Syntax

LOAD VARIABLE : <FileName> [:<Variable List>]

Where,

<FileName> is the name of file in which the ‘report’ scope variables are persisted. The extension .PVF will be taken by default, if the file extension is not specified.

<Variable List> is the comma-separated list of variables that need to be loaded from the file. It is optional. In case it is not specified, all the variables saved in the file will be loaded.

Example

In the previous example, we have persisted values of the Report Scope Variables EmpNameVar and EmpIDVar in the file SmpVar.pvf . Now, let us see how to re-load these ‘report’ scope variables from the file.

[Button : LoadVar]

Key    : Alt + L

Action : LOAD VARIABLE : SmpVar.pvf : EmpNameVar, EmpIDVar

The action LOAD VARIABLE will load the report scope variables EmpNameVar and EmpIDVar from the file SmpVar.pvf .

Member Variable Specification or Dotted Notation Specification is not allowed for specifying Variable list for both the actions SAVE VARIABLE and LOAD VARIABLE . It has to be a variable name identifier at the current report scope.

Modify System

The action MODIFY SYSTEM launches the given report in ‘auto’ mode. Even if the report is called under some other report context, this action makes the new report to get the system context and thereby modify the system scope variables.

Syntax

MODIFY SYSTEM : <Report Name>

Where,

<Report Name> is the name of the report which is to be launched in ‘Auto Mode’.

Example:

[Button: Change System Period]

Key    : Alt+F2

Action : Modify System : Change Menu Period

Title  : $$LocaleString:“Period”

The Action ‘Modify System’ has launched the report ‘Change Menu Period’ in ‘Auto’ Mode. The report is having two fields SVFromDate and SVToDate.

[Field : SVFromDate]

Use      : Short Date Field

Modifies : SVFromDate

Variable : SVFromDate

[Field : SVToDate]

Use      : Short Date Field

Format   : Short Date, End : #SVFromDate

Modifies : SVToDate

Variable : SVToDate

The value changes would affect the variables at system scope, as the report is launched using the Action ‘Modify System’.

Modify Variable

It launches the given report in auto mode. Since the launch e d report is in ‘auto’ mode, it cannot have its own instance of Variables and any modification would affect the parent context.

Syntax

MODIFY Variable : <Report Name>

Where,

<Report Name> is the name of the report which is to be launched in ‘AutoMode’.

Example:

[Button : F2 Change Period]

Key    : F2

Action : Modify Variables : Change Period

Title  : $$LocaleString:”Period”

The Action ‘Modify Variable’ launches the report ‘Change Period’ in ‘Auto’ Mode. The report is having two fields SVFromDate and SVToDate

[Field : SVFromDate]

Use      : Short Date Field

Modifies : SVFromDate

Variable : SVFromDate

[Field : SVToDate]

Use      : Short Date Field

Format   : Short Date, End : #SVFromDate

Modifies : SVToDate

Variable : SVToDate

The variable value changes would affect the parent report context only (i.e., it will affect values of the variables SVFromDate and SVTodate, which are associated to the report, from which the report Change Period is launched in Auto Mode).

Save Variable

The action SAVE VARIABLE is used to persist the Report Scope Variables in a user specified file.

Syntax

SAVE VARIABLE : <FileName> [:<Variable List>]

Where,

<FileName> is the name of the file in which the report scope variables are persisted. The extension .PVF will be taken by default, if the file extension is not specified.

<Variable List> is the list of comma-separated variables that need to be persisted in the file. Specifying the variable list is optional.

If the Variable List is not specified, all the variables at the ‘Report’ scope, which have ‘Persist’ attribute set to YES, will be persisted in the specified file. We need not declare the variable at System level unless it is required to persist the same in the default configuration file tallycfg.tsf.

Example

Let us assume that the variables EmpNameVar and EmpIDVar are declared at the Report Scope, and the same need to be persisted in a user specified file. We can achieve this using the newly introduced actions SAVE VARIABLE and LOAD VARIABLE . The buttons SAVEVAR and LOADVAR are added at the Form Level for the same.

[Button: SaveVar]

Key    : Alt + S

Action : Save Variable : SmpVar.pvf : EmpNameVar, EmpIDVar

The action SAVE VARIABLE will persist the values of the variables EmpNameVar and EmpIDVar in the file SmpVar .pvf

Set

Values of variables can be set/updated via the SET action. This action is available as a global action, and can be used within a function also. List variables and compound variables cannot have values; they can have only element/member variables inside them, respectively. If SET action is used on compound variables, the value will be set to the FIRST member variable. If the first member variable is again compound, the program would search for the first non-compound leaf member and set the value.

For list variables, the value is treated as the count, and the list is expanded by the number of elements provided in the expression.

Syntax

SET : <Variable Specification> : <Value Expression>

Where,

<Variable Specification> is the variable path specification.

<Value Expression> can be any expression which evaluates to a value for the variable of the specified data type.

Example:

;; Setting value to a simple Variable

SET : Var : “ABC”

;; Setting value to a simple List Variable element

SET : SLVEMP[1] : “XYZ”

;; Setting value to Compound List Variable element’s member

SET : CLVEMP[1].Name: “Kumar”

 MultiSet

The action MULTI SET is used to set the values  of compound member variables in one call. All member specifications are relative to the compound variable specification given.

Syntax

MULTI SET : <CompoundVariable Specification> + : <Member Specification :Value> [, <Member Specification : Value>, …]

Where,

<Compound Variable Specification> is the Compound Variable specification.

<Member Specification : Value> is the list of name-value pairs for setting member values.

Example: 1

MULTISET : CLVEMP[1] : Name : “Vimal”,Age : 26, Salary :($$AsAmount:10000)

All member variables of 1st element of Compound List Variable CLV EMP are set with MULTISET .

Example: 2

MULTISET : CLVEMP[1].Relatives[1] : Name : “Hari”, Age : 20, +

Relation:“Brother”

Here, all member variables for the first element of the Compound List Variable Relatives are set.

Relatives is a Compound List Member variable of the Compound List Variable CLV EMP.

TallyHelpwhatsAppbanner
Is this information useful?
YesNo
Helpful?
/* */