# var

> 1. Declaring a variable of built-in type

> 2. Declaring a variable of referenced type

> 3. Multiple declaration of variables of the same type

> 4. Declaring a variable array

#### 1. Declaring a variable of built-in type

### var ( bitstring | boolean | charstring | universal charstring | integer | octetstring | objid | hexstring | verdicttype | float | address | default | anytype ) var_identifier [:= single_variable_expression ] ;

- The var keyword introduces the variable definition.

- bitstring denotes an a type whose distinguished values are the ordered sequences of zero, one, or more bits.

- boolean is a simple basic type consisting of two distinguished values (namely true or false).

- charstring denotes a type whose distinguished values are the ordered sequences of characters of ISO/IEC 646 as described in ITU-T Recommendation T.50.

- universal charstring denotes a type whose distinguished values are the ordered sequences of UCS-4 coded representation of ISO/IEC 10646 characters.

- integer denotes a a type with distinguished values which are the positive and negative whole numbers, including zero.

- octetstring stands for a a type whose distinguished values are the ordered sequences of zero or a positive even number of hexadecimal digits (every pair of digits corresponding to an ordered sequence of eight bits).

- objid defines a type whose distinguished values are the set of all object identifiers conforming to clause 6.2 of ITU-T Recommendation X.660.

- hexstring defines a type whose distinguished values are the ordered sequences of zero, one, or more hexadecimal digits, each corresponding to an ordered sequence of four bits.

- verdicttype defines a type for use with test verdicts consisting of 5 distinguished values.

- float defines a type to describe floating-point numbers.

- address denotes a user defined type to allow addressing specific entities inside the system under test.

- default is a reference to an activated default resulting from an activate operation.

TITAN specific restriction compared to the standard: anytype is not implemented yet. anytype defines as a shorthand for the union of all defined types, imported ASN.1 and other imported external types.

- var_identifier is the name used to refer to the variable. Must begin with a letter, may contain letters, numbers and underscore characters.
  According to the Naming convention, the following prefixes are recommended:

  - v_ for variables declared in the test component type definition,
  - vc_ for variables defined within a component type and used to store component instance references (returned by a create operation),
  - vd_ for variables defined within a component type used to store references to activated defaults (returned by an activate statement),;
  - vl_ for variables declared in testcases, functions, altsteps, block of statements or in the control part,
  - vlc_ for variables defined in testcases or functions and used to store component instance references (returned by a create operation),

  - vld_ for variables defined in testcases or functions used to store references to activated defaults (returned by an activate statement),

- The optional single_variable_expression is used to define an initial value. It may contain variables and literal values as operands. The result of the expression must correspond to the type of the variable.

Example

#### 2. Declaring a variable of referenced type

### var [ module_id [.obj_id ].] type_reference [.field_reference ] var_identifier [:= single_variable_expression | value_list | value_assginment_list ];

- The var keyword introduces the variable definition.

- module_id is needed when the referenced type is defined in another TTCN-3 module and denotes the name of that module.

TITAN specific restriction compared to the standard: objid is not implemented yet; it is discarded when encountered. obj_id is an optional object identifier which may follow the TTCN-3 module identifier.

- type_reference refers to an already defined (structured or simple) type.

TITAN specific restriction compared to the standard: field reference can only be used with structured variables defined in the module definition part. field_reference optionally stands for a field of a structured type.

- var_identifier is the name used to refer to the variable. Must begin with a letter, may contain letters, numbers and underscore characters.

- The optional single_variable_expression may contain variables and literal values as operands. The result of the expression must correspond to the type of the variable. Used with simple types to define an initial value.

- The optional value_list is a comma-separated list of the variable values between curly brackets. Used with structured types to define an initial value

TITAN specific restriction compared to the standard: value assignment can only be used with structured variables defined in the module definition part. The optional value_assignment_list is a comma-separated list of the field name - variable value pairs between curly brackets. Used with structured types to define an initial value.

Example

#### 3. Multiple declaration of variables of the same type

### var type identifier1 [ := variable_expression1], identifier2 [:= variable_expression2 ]â¦ ;

- The var keyword introduces the variable definition.

- type is one of the built-in types mentioned in paragraph 1 or referenced types mentioned in paragraph 2 .

- identifiern is the name used to refer to the nth variable.

- The optional variable_expressionn determines the initial value of the nth variable.

Example

#### 4. Declaring a variable array

### var type var_identifier [ array_index ] [:= value_list];

- The var keyword introduces the variable definition.

- type is one of the built-in types mentioned in paragraph 1 or referenced types mentioned in paragraph 2 .

- var_identifier is the name used to refer to the variable. Must begin with a letter, may contain letters, numbers and underscore characters.

- array index is a non-negative integer value corresponding to the number of elements in the array.
  Alternatively, the lower and upper index values are given joined by two dots.

- The optional value_list is a comma-separated list of the initial variable values between curly brackets.

Example

Example 1a:

var integer v_myVariable := 127;

A variable called v_MyVariable is defined. The variable will have the initial value one hundred twenty seven.

Example 1b:

var bitstring v_myGarland := '00101101'B;
var bitstring v_myBiggerGarland := v_myGarland & '11000010'B;

Two variables are defined. The one called v_myBiggerGarland initially will have the binary value 11101111.

Example 2a:

type record E_Rec {integer field1, boolean field2}; //defined in Elsewhere

var Elsewhere.E_Rec v_CurrVar := {17, true};

A record called E_Rec have been defined in the TTCN-3 module Elsewhere. In the current module we define a variable named v_CurrVar and assign values to all of its fields. In TITAN, the value notation as shown above may only be used in the module definition part.

Example 2b:

type record G_Rec {float first_field, hexstring last_field};
var G_Rec.last_field v_FuzerVar;

First we define a record called G_Rec. Then we define a variable named v_FuzerVar derived from the second field of the referred type and assign no initial value to it.

Example 2c:

type record G_Rec {float first_field, hexstring last_field};
var G_Rec v_UeppigVar := {
first_field := 5.77,
last_field := '55'H;
}

First we define a record called G_Rec. Then we define a variable named v_UeppigVar and assign initial values to both of its fields using assignment notation.

Example 3:

var boolean v_MyVar2 := true, v_MyVar3;

Two variables (v_MyVar2 and v_MyVar3) are declared within one operation. The latter variable has no initial value assigned.

Example 4a:

var boolean v_MinVar[3] := { true, false, false };

The array defined v_MinVar consists of three elements indexed from 0 to 2.

Example 4b:

var boolean v_DinVar[7..9] := { true, false, false };

The array defined v_DinVar consists also of three elements as in the example 4a, but here the indices run from 7 to 9.

BNF definition of var