HomeDeveloper ReferenceTally Definition LanguageDatatypes, Operators & Expressions

 

Explore Categories

 

 PDF

Data Types, Operators & Expressions

Introduction

The primary focus of this topic is to understand the various data types and operators available in TDL and how valid expressions are constructed. Any information stored on computer system is commonly referred as data. Based on the value the data is classified into different types called as data types.

For example, if the value is 123, then the data type is Number. Data type specifies the type of value and the validity constraint of each data type.

Data Types

The data is the lowest element of information. It exists in different forms as number, date etc. A data type is a set of data with values having predefined characteristics.

Data types supported by computer languages vary from one language to another. The language usually specifies the range of values for a given data type, how the values are processed by the computer, and how they are stored.

The data types in TDL are used to specify the type of data stored in the field or a variable. As discussed, TDL is a business language and it requires the support for various business data types like amount, quantity, rate apart from the other basic types. Refer to the below image to identify all the TDL data types.

TDL Data Types

 

Based on the requirements of the business the data types in TDL are classified in two categories: Simple and Compound.

Simple Data Types

The data types which can hold the data for a specific type only are referred to as Simple Data Types. These cannot be further divided into sub types. Mentioned are the simple data types available in TDL.

String

The string data type accepts alpha numeric characters as well as special symbols. There is no restriction on the number of characters which can be accepted for this data type. If the restrictions are required, they can be applied at the field level as per the scenario.

Example:

The name of the company ABC Company Ltd. can be stored in the string data type.

Number

A number data type is used to store a numeric data only. The valid range  acceptable in TDL  is from  92233720368547.7580   to +92233720368547.7580.

Example:

The phone number ‘98450 98450’ can be entered in a number type field.

Date

This data type is used to store dates. The valid range acceptable in TDL is from 1-1-1901 to 31-12-2098.

Example:

The date of purchase or payment can be displayed only in a field of type Date.

Logical

This data type is used to specify a logical value. It accepts Yes/ No, True/ False, On /Off and 0/1.

Example:

The logical data type is mostly used in the configuration settings. The value of Explode flag is No by default. It must be set to Yes in order to display exploded data.

 Compound Data Type

In a business scenario the data may be a combination of multiple components. TDL provides a comprehensive set of compound data types which consists of further subtypes.

Compound data types in TDL are: Amount, Quantity, Rate, Rate of Exchange, Due Date.

Amount

This data type is a combination of subtype of Base/Direct Base, Forex, Rate and DrCr.

Base/Direct Base – This subtype is used to specify the amount in the base currency applicable for the particular company.

Forex – This subtype is used to specify the value of the amount in a foreign currency, as specified by the user.

Rate – This subtype will be used to specify the Forex rate.

DrCr – This subtype is used to specify a Dr & Cr based on whether it is a Debit/Credit amount.

The valid range acceptable in TDL is from -92233720368547.7580 to 92233720368547.7580 and the four decimal places are applicable for base amount and forex based on the number of decimal specified in the currency master. Whereas for Forex, the decimal places can go to the maximum of four decimal places which are independent of the number of decimals mentioned in the respective currency master.

Example:

The opening balance of a ledger from group Sundry Debtor is $1000. The base currency of the company is Rupees and the Rate of Exchange is specified as $1/ Rs. 42.50. Now this information is stored in the respective sub-types as follows:

Base  : Rs. 42,500 ($1000 * 42.50)

Forex : $1000

Rate  : Rs. 42.50/$

DrCr  : Dr

Quantity

This data type comprises of the subtype base units/primary units, alternate units/ secondary units and unit symbol.

Base Units/Primary Units – The quantity along with the base unit is specified using this data type.

Alternate  Unit/ Secondary  Units  –The  quantity  in  alternate  units  is specified using the sub type as Alternate units

Unit symbol – The unit symbol for the quantity is specified using this subtype. The valid range acceptable in TDL for the quantity data is from –92233720368547.7580 to +92233720368547.7580 and number of decimal places depends on the number of decimal specified in the Unit master.

Example:

For a Stock item Rice the quantity is 10 Bags and 2 kgs. The unit of measurement is 1 bag of 10 kgs. The alternate unit is specified as Grm and 1000gms = 1 kg.

Base Unit: 10 bags 2 kgs

Alternate Unit: 102000 gms

Unit Symbol: bag of 10 kgs

Rate – A rate data type is a combination of sub-types price, quantity & units symbol.

Price – The price of the item is specified using this sub-type.

Quantity – This specifies the quantity for which the price is specified.

Units/Unit  Symbol  –  This  specifies  the  unit  for  which  the  price  is specified. The valid range acceptable in TDL for the rate is from 2233720368547.7580 to 92233720368547.7580. The number of decimal places for price depends on the number of decimal specified in the currency master and for quantity it depends on the number of decimal specified in the unit master.

Example:

The rate for a Stock Item is entered as Rs. 100/5 nos

Price      : 100

Quantity   : 5 nos

Unit symbol: 5 nos

Rate of Exchange

This data type is used to specify the conversion rate between currencies. Acceptable range for Rate of Exchange is from – 92233720368547.  7580  to 92233720368547.  7580 and the decimal places can go to the maximum of four which are independent of the number of the decimals mentioned in the respective currency master.

Example:

If the conversion rate for $1 is Rs. 45

Rate of Exchange: Rs 45/$

Due Date – This data type is used to store a date range. It stores two date values From Date and To Date. Only the To Date value is entered and the value of from date is determined by the system.

Example:

While entering a voucher in the credit period either number of days is entered or to date is entered and from date is internally considered to be billed date.

Note: Even though the data types Rate of Exchange and Due Date are compound data types, they don’t have any sub-types .i.e. for these data types sub-types can’t be specified explicitly.

The Field Attribute Type

The type for the field definition is specified using the Type attribute.

Syntax

[Field: <Field Name>]

Type : <Data Type> : <Sub-type>

Where,

<Data  Type> is primary data type name,

<Sub–type> is name of sub-type belonging to the specified primary data type

Example:

[Field: Qty Secondary Field]

Type : Quantity: Secondary Units

The Field Attribute Format

The type for the field definition is specified using the Type attribute.

Syntax

[Field: <Field Name>]

Type      : <Data type>
Format : <List of Formats>

Where,

<Data Type> is primary data type name,
<List of Formats> is comma separated list of formats applicable for the <primary data type>

Example:

The code to specify format for number ‘85.49’ to be displayed as (44.5%) is as follows:

[Field: NumField]

Type  : Number
Format : Decimal: 1, Percentage, Bracketed

In Tally, quantity of a Stock item can be expressed using a Simple or Compound Unit of Measure.

Simple Unit – Unit of measure used to express the quantity of an Item. for example, kgs, nos, pcs, etc.

Compound Unit – The unit of measure which is a combination of Simple units related to each other by a conversion factor, is termed as a Compound Unit. Examples of compound units are kg of 1000 gms, dozen of 12 nos, etc.

In case of compound unit, the highest unit is referred to as the Base/Primary unit and the sub units thereafter, are referred to as the Tail units. The quantity is always expressed in terms of the Primary unit. A compound unit can be nested further to contain another compound unit as a Tail unit, up to any number of levels. For example., Bag of 10 kgs of 1000 gms.

If the unit of measure used for a Stock item “Grains” is Bag of 10kgs of 1000 gms and the closing balance is 12-5-250 bags, it means that the quantity of items is 12 bags 5 kgs 250 gms. Whenever the tail unit quantity crosses the conversion factor, it adds up to the bigger unit. If the gms part exceeds 1000 in this example and the value is 12-5-1250 bags, then it will be converted to 12-6-250 bags.

In TDL, the data type to support representation & storage of data of the above type is Quantity. It comprises of subtypes Number, Base/Primary units, Alternate/Secondary units and unit symbol.

We know that when a method of type ‘Quantity’ is retrieved in a report, it is always expressed in terms of primary units. In case the Unit of Measure is a nested compound unit, the user may require the quantity in terms of any of the units in the entire Compound unit chain. The ‘Format’ attribute of Field has been enhanced to specify the Tail unit, in which the quantity value needs to be extracted.

Syntax

[Field: <Field Name>]

Type     : Quantity

Set As  : $<Method Name>

Format: “Tail Units:” + <String Expression>

Where,

<String Expression> must evaluate to any Tail Unit Name used in the Item.

Example:

As per the previous example, the unit of measure used for the Stock item “Grains” is Bag of 10kgs of 1000 gms and the closing balance is 12-5-250 bags. In a field, we may require to retrieve the value in kgs or gms instead on bags. For this, the following specification can be used:

[Field: Qty Format Enhancement]

Use   : Qty Primary Field

Set As: $ClosingBalance

Format: “Tail Units:” + “kgs”

If Format is “Tail Units:kgs”, value returned is 125 kgs 250 gms=12X10 kgs+5kgs & 250 gms

If the Format is “Tail Units:gms”, the value returned would be 125250 gms = 12X10X1000 gms+ 5X1000 gms +250 gms.

Note: Appropriate conversions take place as per the conversion factors set in the nested Compound unit chain.

Data Type Formats

In TDL various formats are used are available to represent the data. Some formats are applicable only to a specific data type. The field attribute format is used to specify the format based on the data type specified in the type attribute of the field.

The formats applicable for data types Number, Amount, Quantity, Rate and Rate Of Exchange are as follows:

Number Data Type and its Formats

The following table shows formats applicable for data type Number with example:

Format

Value of Field

Value Returned

Comma

1000 (Default)

1,000

No Comma

1,000

1,000

Positive/Signed

1000 (positive number by default)

(+) 1000

Decimal: no of decimals

1000.19

1000.2 (Round off)

No Zero

0.00

(Blank field)

Percentage

1.00

1 %

Bracketed

1.00

(1.00)

Amount Data Type and its Formats

The following table shows formats applicable for data type Amount along with example:

Format

Value of Field

Value Returned

Comma

1000 (Default)

1,000

No Comma

1,000

1,000

Positive/Signed

1000 (+ve number by default)

(+) 1000

Decimal: no of decimals

1000.19

1000.2 (Round off)

DrCr/CrDr

1000.00

1000 Cr

Symbol/Currency

1000

Rs.1000

Show Base Currency

1000

Rs.1000

Forex

1200

$1200 if the amount is in foreign

All Symbols

1260

If the amount is converted to base currency from other currency then value

No Zero

0.00

(Blank field)

No Symbol

1000.00

1000.00

Bracketed: For Negative

-100

(100)

Quantity Data Type and its Formats

The following table shows formats applicable for data type Quantity with example:

Format

Value of Field

Value Returned

Comma

1000 (Default setting of Number Type)

1,000

No Comma

1,000

1,000

SDF

1000

1000 for Cr Side

-1000 for Dr Side

Positive/Signed

1000 (Denotes a positive number by default in Tally)

+(1000)

Decimal:   No.  of Decimals

1000.19

1000.2 (Rounded off)

DrCr/CrDr

1000

1000.00 Dr

1000.00 Cr

Units

750

750 kgs, 750 nos depending on the units in which the entries have been passed

TailUnits

10 Crtn 5 Box 3 Pcs

1253 Pcs. Here it shows the least unit(Pcs). All the cartons and boxes get converted into Pcs

TailUnits:Box

10 Crtn 5 Box 3 Pcs

125 Box. All the cartons and pieces get converted to Boxes

Shortform

10 Crtn 5 box 3 Pcs

10-5-3

No Compact

10Crtn 5 box 3 Pcs

10- 5-3

No Zero

0.00

(Blank Field)

Note: The field format No compact has to be used along with Shortform. Assuming the units of measure are set as 1 Carton = 12 Box and 1Box =10 Nos

Rate and Rate of Exchange Data Type and its Formats

The following table shows formats applicable for data type Rate and Rate of Exchange with example:

Format

Value of Field

Value Returned

Comma

1000 (Default setting of Number Type)

1,000

No Comma

1,000

1,000

Positive/Signed

1000 (Denotes a positive number by default in Tally)

+(1000)

Decimal:                   No                   of Decimals

1000.19

1000.2 (Rounded off)

DrCr

1000

1000.00 Dr/Nos

1000.00 Cr/Nos

Units

750

750 kgs, 750 Nos

TailUnits

10 Crtn 5 Box 3 Pcs

1253 pcs. Here it shows the least unit(Pcs). All the cartons and boxes get converted into Pcs

TailUnits:Box

10 Crtn 5 Box 3 Pcs

125 Box. All the cartons and pieces get converted to Boxes

Shortform

10 crtn 5 box 3 Pcs

10-5-3

No Compact

10Crtn 5 box 3 Pcs

10-5-3

No Zero

0.00

(Blank Field)

Calendar Data Type and its Formats

The formats applicable for data types date and Due Date are as follows:

Format

Value Set in the Field

Value Displayed after applying Format

Short Date

22-Dec-1999

16-Mar-2000

22-12-99

16-03-2000

Long Date

22-Dec-1999

Wednesday, 22 Dec, 1999

Universal Date

22-12-1999

22-Dec-1999

Month Beginning

01-12-1999

04-12-1999

Dec – 99

04-Dec-99

Month Ending

31-12-1999

14-12-1999

Dec – 99

14-Dec-99

All the data types pertaining to date and time are now collectively referred to as Calendar data types, which are as follows:

  • Date
  • Time
  • DateTime
  • Duration
  • Due Date

Various business functionalities like capturing Date and Time of entering a voucher, calculating the weekly average clock-in time of employees, etc., will be possible in Tally.ERP9.

Apart from the new data types, a few supporting Functions, Formats, Input Keywords and Qualifiers have also given  for each. Formats can be specified to indicate the format in which the value has to be displayed.

The concept of Input Keywords and Qualifiers has given to assist the Tally user in data entry operations, as well as to minimize the effort of the programmer in setting the values of any particular calendar data type within a Field.

For example, in a Field of data type ‘Date’, specifying the Input keyword ‘Week’ as the value, will lead to setting of the current week’s beginning date as the value.

Also, Qualifiers like ‘This’, ‘Next’, etc., if specified along with the Input Keywords, will lead to storing and displaying of values determined by the ‘Input Keyword-Qualifier’ combination.

For example, specifying ‘Next Week’ will return the beginning date of the following week as the value.
All of these have been discussed in detail in the following sections.

Date

Specifying the data type as Date indicates that the data container can only hold Date values. The data container can be a UDF, a Variable or a Field. The date values can range from January 1, 1901 to December 31, 9999.

The default separator character within a Date is ‘Hyphen’, e.g., 22-12- 2011.

Example:

[System: UDF]

DateOfPurchase : Date : 1107

/* A new System UDF DateofPurchase of Type Date is declared. */

[Field: Date of Purchase]

Type : Date

Storage : DateOfPurchase

/* A Field DateofPurchase of Type Date is defined for updating values in the UDF DateOfPurchase */

The prefix century behavior has been introduced (when a 2 digit year value is entered by the user) in the Date field.

The century value prefixed by the system will depend upon

  • The 2-digit year value passed by the user
  • The system year

Thus, the different cases that are possible as follows

Format Keywords

Apart from specifying the Type as Date, one of the various available Formats can also be specified, using the attribute ‘Format’. The various Formatting Keywords for the data type ‘Date’ are listed in the following table. If no Format is specified, the default format ‘Universal Date’ is assumed.

Example

[Field: Date of Purchase]

Type : Date

Storage : DateOfPurchase

Format : “Short Date”

/* The Format specified within the Field DateofPurchase is Short Date, and hence, the date is returned in dd-mm-yyyy format. */

Input Keyword

There are certain Input keywords, which can be specified instead of the date itself. This increases the ease of data entry. The Input Keywords available for the data type Date are as follows:

Example

[Field: Date of Purchase]

Type    : Date

Storage : DateOfPurchase

Format  : “Short Date”

Set As  : TODAY

/* The input keyword Today sets today’s date as the value within the Field Date of Purchase. */

Date Qualifiers

There are also some date qualifiers, which can be used in combination with input keywords, to return the required date value. Qualifiers cannot be used independently, but they can be provided as additional specification for the input keyword.

The various date qualifiers are as follows:

Example

[Field: Date of Purchase]

Type : Date
Storage : DateOfPurchase
Format : “Short Date”
Set As :Last Financial Year

/* In Last Financial Year, ‘Last’ and ‘Financial’ are qualifiers, while ‘Year’ is an Input Keyword. It sets the field value as the 1st day of the last/previous financial year. */

Note: Week is assumed to begin on Sunday. For example, on 20th August, 2013, the value of the Field set as ‘Prev Week’ is returned as 11th August, 2013, which is the Sunday of the week prior to the current week.

Time

A new Data Type Time represents an absolute time of the day. Specifying the Data Type as ‘Time’ indicates that the data container can hold only the Time values. The data container can be a UDF, a Variable or a Field. A value of this data type describes the time, with milliseconds precision, i.e., using the subparts HOURS, MINUTES, SECONDS, and MILLI SECONDS. Thus, the format is hh:mm:ss:MMM

By default, Colon is the separator between the sub-parts of the time value, which can also be altered by the user. For example, 16:35:12:348


Example:


[System: UDF]

TimeOfPurchase : Time : 1108


/* A new System UDF TimeofPurchase of Type Time is declared. */


[Field: Time of Purchase]

Type    : Time
Storage : TimeOfPurchase

/* A Field Time of Purchase of Type Time is defined for updating values in the UDF TimeOfPurchase */

Format Keywords

Just as in the case of Date data type, various Formatting Keywords have also been introduced for the Time data type, to render the Time in various formats. The formats are listed in the following table.

Input Keywords

The input Keywords available for the data type Time are as shown in the following table:

DateTime

A new Data Type DateTime has also been introduced. Specifying the Data Type as DateTime indicates that the data container can hold only the values of type DateTime. The data container can be a UDF, a Variable or a Field. A value of data type DateTime represents a date, along with the absolute time of the day. The date and the time are described using the sub-parts DAY, MONTH, YEAR, HOUR, MINUTE, SECOND, and MILLISECONDS. Thus, the format is dd-mm- yy hh:mm:ss:MMM

By default, the separator for the Date part is Hyphen (-) and for the Time part is Colon (:). However, the same can be altered by the user. The date-time combination values can range from January 1,1901 00:00:00:000 to December 31, 2098 23:59:59:999

Example:

[System: UDF]

DateTimeOfPurchase : DateTime : 1109

/* A new System UDF DateTimeofPurchase of Type DateTime is declared. */ [Field: Date and Time of Purchase]

Type    : DateTime

Storage : DateTimeOfPurchase

/* A Field DateandTimeofPurchase of Type DateTime is defined for updating values in the UDF DateTimeOfPurchase */

Input Format
Date Only

This Format is specified to accept both Date and Time values in the Field, but display only Date. In other words, if this Format is specified within a field of type DateTime, then the field can accept both Date and Time values, but will display only Date.

For example, consider a Field of Type DateTime, where the Format is specified as ‘Date Only’. If the Input keyword ‘Today’ is entered in this Field, then instead of displaying the current date and time, the field will display only the current date.

Example:

[Field: Date of Purchase]

Type : DateTime

Storage : DateTimeOfPurchase Format : “Long Date, Date Only”

/* Both Date and Time values will be accepted as input in the Field DateofPurchase, but only the Date value will be displayed. */

Time Only

This Format is specified to accept both Date and Time values in the Field, but display only Time. In other words, if this Format is specified within a field of type DateTime, then the field can accept both Date and Time values, but will display only Time.

For example, consider a Field of type DateTime, where the Format is specified as ‘Time Only’. If the Input keyword ‘Now’ is entered in this Field, then instead of displaying the current date and time, the field will display only the current time.

Example:

[Field: Time of Purchase]

Type    : DateTime

Storage : DateTimeOfPurchase
Format  : “12 hour, Time Only”

/* Both Date and Time values will be accepted as input in the Field
TimeofPurchase, but only the Time value will be displayed. */

Input Keywords

Input Keywords available for the date type DateTime are as shown in the following table:

Note: For the keywords ‘Tomorrow’, ‘Yesterday’, ‘Month’, ‘Week’ and ‘Year’, the time already available in the Field, i.e., the ‘Time’ Part of the DateTime value, is set as the time. If the ‘Time’ value is not available, then it will be set to 0:00.

Date Qualifiers

All the qualifiers for the data type Date are applicable for the data type DateTime as well.

Sub Types for the Data Type ‘DateTime’

Two subtypes have also been introduced for the data type DateTime:

Date

This Subtype is specified to accept both Date and Time values in the Field, but display only Date. In other words, if this SubType is specified within a field of type DateTime, then the field can accept both Date and Time values, but will display only Date.

For example, consider a Field of type DateTime, where the sub-type is specified as ‘Date’. If the Input keyword ‘Today’ is entered in this Field, then instead of displaying the current date and time, the field will display only the current date.

Example:

[Field: Date and Time of Purchase Date]

Type : DateTime : Date

Storage : DateTimeOfPurchase

Time

This SubType is specified to accept both Date and Time values in the Field, but display only Time. In other words, if this SubType is specified within a field of type DateTime, then the field can accept both Date and Time values, but will display only Time.

For example, consider a Field of type DateTime, where the sub-type is specified as ‘Time’. If the Input keyword ‘Now’ is entered in this Field, then instead of displaying the current date and time, the field will display only the current time.

Example:

[Field: Date and Time of Purchase Time]

Type : DateTime : Time

Storage : DateTimeOfPurchase

Here, both Date and Time will be accepted but only the ‘Time’ part of the DateTime value is displayed in the field. Manipulation can be done on date as well as time.

Note: Two fields with subtypes as Date and Time can have the same storage and the changes from one field will be reflected in the other field.

Duration

Values of this data type will represent the interval between two Date and/or Time values (two DateTime values), measured in years, months, weeks, days, hours, minutes, and seconds.

Example:

[System: UDF]

TenureOfService : Duration : 1110 [Field: Tenure Of Service]

Type            : Duration

Storage         : TenureOfService

/* A Field TenureOfService of Type Duration is defined for updating values in the UDF TenureOfService */

Formats

The format options available for the Duration data type are:


Example:

[Field: Tenure Of Service]

Type    : Duration
Storage : TenureOfService
Format  : “Months, Days”

Points to Remember
  1. Any combination of the formats can be provided. However, Week is an independent format and cannot be clubbed with any other. Let’s see the following examples:
    • In the above example, if the value entered by the user in the Field is 100, then the lowest (in terms of duration) of the formats specified will be considered as the input format, e. 100 will be considered as 100 days and then, the same will be displayed as output in terms  of months and days, i.e., 3 months and 10 days.
    • If the Format is specified as ‘Weeks, Days’, then the value returned will be in Days, as ‘Weeks’ is an independent entity and cannot be clubbed with any other
  1. If the value entered is less than the lowest value (in terms of duration) among the format specified, then the value returned will be For example,
    • If 6 days is entered and the format is weeks, then the value returned will be 0 weeks.
    • If 8 days is entered and the format is weeks, then 1 week will be displayed.
Due Date

The values of Data Type Due Date are used to represent the Due Date in cases like Purchase Order, Bill Credit Period, etc., in TallyPrime. These values actually comprise of two date values, e., the From Date and the last date by which honoring of the commitment is due (i.e., the due date). A flexible range of values can be specified. The value can be a Date (the ‘due date’) or the Duration, in terms of Days, Weeks, Months and Years, from the starting date (‘From’ date). The acceptable duration values used to specify the due date range from 0 to 89 years. 

Input Formats

Four input formats can be specified for values of data type Due Date. If no input format is specified, then the default format Days is considered.

Note: As the default format is ‘Days’, on entering only the number 30, 30 days will be considered. The value is displayed in the same format in which it has been entered.

Compatibility of data type ‘DateTime’ with data types ‘Date’ and ‘Time’

  1. Setting a data container (Field, UDF or Method) of type Date OR Time with a value of data type DateTime is possible. For example, if the value of a field of type Date or Time is set by referring to another field of type DateTime, the particular date value OR time value is taken, respectively, and the same is displayed in the Field.

Example:

[Field: Date of Purchase]

Type    : Date

Storage : DateOfPurchase Format : “Long Date”

Set as  : #DateandTimeOfPurchase

In this example, Date and TimeOfPurchase is a Field containing a value of type DateTime.

When this field is being referred to in the Field Date of Purchase of type Date, the ‘Date’ part of the value is extracted and set as the value of the field.

  1. Date and Time functions can be used on a value of type DateTime. The vice versa is also true, e., DateTime functions can also be used on a value of type Date or Time.

Example:

$$DayOfWeek:$DateTimeOfPurchase

/* Date function is used on method value of type DateTime */

$$DayOfDate:#DateandTimeOfPurchase

/*  Date  function  is  used  on  field  value  of  type  DateTime */

$$Time:#DateandTimeOfPurchase

/* Time function is used on field value of type DateTime */

$$DateTime:#DateOfPurchase

/* DateTime function is used on field value of type Date */

Constraints and Assumptions for Calendar data types TIME

  1. Data Type Time currently does not support time
  2. Data Type Date is independent of the Data Type Time. This means that if the time is changed from PM to AM, or vice versa, the Date does not
  3. Time is cyclic in nature, e., if 12 hours are subtracted from 1 am, it results in 1 pm.
DATETIME
  1. In a field of type DateTime, for entering the time value, date must be entered first.
  2. When a value of type Date is converted to type DateTime, then default value of time is taken as 0:00.

  3. When a value of type Time is converted to type DateTime, then the default value of Date is assumed as the current date.
DURATION
  1. In Duration data type, if no unit is specified, then it is by default taken as days. For example, in a Field of type ‘Duration’, if the value entered is 10, then it is considered as 10 days.
  2. Negative Duration is not
COM Support to Calendar Data Types

COM support has been extended for two other data types, viz., Time and DateTime.

Data Conversion (Type Casting)

Data conversion refers to changing one data type to the other. Converting the data of a given type into another type is known as type-casting. Type casting is required when an expression data is a combination of different data types. Each programming language has its own rules on how types can be converted. Data conversion can be Implicit or Explicit.

Implicit Data Conversion

Implicit data conversion is done automatically by the language compiler. In a mixed-type expression, data of one or more subtypes can be converted to a super type as needed at runtime so that the program will run correctly. Implicit conversion can occur from all data types to string data type.

Consider following Examples:

Example:

[Field: Field1]

Type    : String
Set As  : 12345

The number is implicitly converted to String and will be displayed.

Example:

[Field: Clg Bal]

Type   : Number
Set As : “1000”

In the above case the string 1000 will be automatically converted to number.

The following table shows the implicit conversion for simple data types based on the value specified in the field using Set As attribute and the data type of the field specified using Type attribute.

Set As Type

Number

Amount

Rate of Exchange

Quantity

Rate

Date

Due- Date

String

Logical

String

Yes

Yes

Yes

Yes

Yes

Yes

Yes

Yes

Yes

Number

Yes

Yes

Yes

Yes

Yes

No

Yes

Yes

No

Date

No

No

No

No

No

Yes

Yes

Yes

No

Logical

Yes

No

No

No

No

No

No

Yes

Yes

  1. Implicit conversion happens from Amount, Rate Of Exchange, Quantity and Rate to Number data type when a method returning value in respective data type is used in Set As Otherwise an empty field is displayed.

Example:

[Field: NoToAmt]

Type   : Number

Set As : $ClosingBalance

  1. When the string specified in a Date field is in date format acceptable by  TallyPrime  like  “06/06/2011”,  “6-Jun-2011”  etc.  then  implicit conversion is done.

Example:

[Field: StrToDate]

Type   : Date

Set As : “6-Jun-2011”

  1. In the Logical field, ONLY the number 0/1 are acceptable for No/Yes respectively. If any other number is specified as value for a Logical field then an empty field is displayed.

Example:

[Field: NoToLogical]

Type   : Logical

Set As : 0

  1. When the string specified in a Logical field is any one of these True, False, On, Off, Yes, No then implicit conversion is done.

Example

[Field: StrToLogical]

Type   : Logical

Set As : “True”

Explicit Data Conversion

Explicit data conversion is required when the data types can not be converted implicitly. For example, converting string type to Amount needs explicit conversion. TDL provides different functions to support data conversion e.g., $$AsAmount, $$AsQty, $$AsRate, $$Inwords, $$Number, $$String etc. The function $$Date is used to convert string data to date.

Syntax

<Conversion Function> : <Value>

Example:

[Field: Clg Bal]

Type   : Amount
Set As : $$AsAmount:“Rs.1000”

1,000.00 is displayed in the field as a result of above code assuming that rupees is a valid currency in the current company. By default for the data types Amount and Rate the conversion is done based on the Base currency and currencies set for the selected company; whereas for Quantity data type conversion depends on the unit of measure of the selected stock item.

Example:

[Field: Clg Bal]

Type   : Amount

Set As : $$AsAmount:“1000”

1,000.00 is displayed in the field as a result of above code and by default the currency is considered as base currency of the current company.

Operators in TDL

Operators are special symbols or keywords that perform specific operations on one, two or three operands and then return a result.

The types of operators in TDL are as follows:

  • Unary Operators
  • Arithmetic Operators
  • Logical Operators
  • Comparison Operators
  • String Operators

Unary Operators

The two unary operators supported by TDL are: – and %. % is used to specify the dimension in percentage of page or screen. It is also used as pattern matching character.

Syntax

<operand 1>  %Screen/Page

Example:

[Part: Title]

Width : 20 %Screen

This will allocate 20% of the screen space as width to the given Title part. ‘%’ as pattern matching character means any character any number of times.

Syntax

%<String Value>

Example:

[Field: Test Fld]

Set As : If @@CMPMailName LIKE “%Ltd.” Then “Limited Company” + Else “Public Company”

: It negates the value of its operand. The data type of the result is same as its operand.

Syntax

– <Operand>

Example:

[Field: Test Fld]

Use    : Number Field

Set As : -100

Arithmetic Operators

The  arithmetic operators  supported  by TDL are + (Addition), – (Subtraction), / (Division) and* (Multiplication).

+  Addition

_  Subtraction

 Division

*    Multiplication

+ : The addition operator is used to add the two operands on either side of the operator.

Syntax

<operand 1> + <operand 2>

Example:

12345 + 6789

This will give the result as 19134.

: The subtraction operator is used to subtract the second operand from the first operand.

Syntax

<operand 1> – <operand 2>

Example:

12345 – 6789

This will give the result as 5556.

* : The Multiplication operator is used to multiply the two operands on either side of the operator.

Syntax

<operand 1> * <operand 2>

Example:

12345 * 6789

This will give the result as 83810205.

/ : The Division operator is used to divide the first operand by the second operand.

Syntax

<operand 1> / <operand 2>

Example:

12345/6789

This will give the result as 1.89.

 Logical Operators

The logical operators used are:

OR Returns True if either of the operand is True

AND Returns True when both the operands are True

NOT Returns True if the operand value is False and False when operand value is True

TRUE/ON/YES Can be used to check if the value of the operand is True.

FALSE/OFF/NO Can be used to check if the value of the operand is False.

OR : Evaluates <operand1> and returns true if the operand evaluates to true. If <operand1> evaluates to false, <operand2> is evaluated. If

<operand2> evaluates to false, the final result is false; otherwise, it is true.

The result is true if either or both operands evaluate to true; the result is false only if both operands evaluate to false. The OR operator can be used with any number of operands; if any operand evaluates to true, the result is true.

The final value can be evaluated based on the following Table:

<Operand 1>

<Operand 2>

OR

False

False

False

True

False

True

False

True

True

True

True

True

Example:

[System: Formula]

Explodable : $$KeyExplode OR @@FlagExplode

The value of Explodable is TRUE is any of the two argument returns the value as TRUE otherwise the value is FALSE.

AND : Performs an operation on the values of one or both of the operands. Evaluates <operand1> and returns false if the operand evaluates to false. If <operand1> evaluates to true, <operand2> is evaluated. If <operand2> evaluates to true, the final result is true; otherwise, it is false. And operator can be used with any number of operands; the result is true only if all the operands are true else it is false.

<Operand 1>

<Operand 2>

OR

False

False

False

True

False

False

False

True

False

True

True

True

Syntax

<Operand 1> AND <Operand 2>

Example:

[System: Formula]

IsBatchWiseOn : $IsBatchWiseOn AND $$IsBatchWiseOn

The value of the formula IsBatchwiseOn is set to true only if the values of method $IsBatchWiseOn and function $$IsBatchWiseOn both are true otherwise false is set.

! / Not : the Not operator reverses the value of the operand. If operand is a value is true, the value of !<operand> is false. In short NOT TRUE returns false and NOT FALSE returns true.

The final value can be evaluated based on the following Table:

<Operand>

NOT

False

True

True

False

Syntax

NOT <operand> / !<operand>

Example:

[System: Formula]

SimpleCompany : NOT $IsAggregate

The value of the formula SimpleCompany is true if the value of Method $IsAggregate is false.

True/On/Yes:  Any of the keyword True/ On /Yes can be used in the conditional operands as it is or for comparing values.

Syntax

TRUE/On/Yes

Example:

[Field: MyField]

 

Type   :Amount 

Set As : If True Then $$AsAmount:“Rs.1000” Else $$AsAmount:”500”

The 1,000.00 is displayed in the field as a result of above code.

False/ Off/ No: Any of the keyword False/ Off / No can be used in the conditional operands as it is or for comparing values.

Syntax

FALSE/Off/No

Example:

[Field: MyField]

Type : Amount

Set As : If False Then $$AsAmount:”Rs.1000” Else $$AsAmount:”500”

The 500.00 is displayed in the field as a result of above code.

Comparison Operators

A comparison operator compares its operands and returns a logical value based on whether the comparison is true. The comparison operator returns value as true or false. TDL supports following comparison operators:

=  /Equal/  Equals

Checks if the values of both the operands are equal.

< / Less Than / Lesser

Checks if the value of the <operand 1> is less than the value of <operand 2>

> / Greater Than/ More

Checks if the value of the <operand 1> is greater than the value of <operand 2>

In

Checks if the value is in the List of comma separated values

Null

Checks whether the operand is Empty

Between…And

Checks if the operand value is in the range

= /Equal/ Equals

The value TRUE is returned if both the operands are equal.

Syntax

<operand 1> =/Equals/Equal <operand2>

Example:

Break On   : $$Line = 1

My Formula : $BasicTypeOfDuty:Ledger:$LedgerName Equals +
$$LocaleString:“Sales Tax”

 

< / Less Than / Lesser Than / Lesser

 The value TRUE is returned if the <operand1> is less than the <operand2>.

Syntax

<operand 1> </Less Than/Lesser <operand2>

Example:

$$Line < $$NumItems:AllLedgerEntries

>/ Greater Than/ More

The value TRUE is returned if the <operand1> is greater than the <operand2>.

Syntax

<operand 1> >/Greater Than/More <operand2>

Example:

$$Line > $$NumItems:AllLedgerEntries

In

The value TRUE is returned if the <operand1> is in the List of comma separated values, otherwise FALSE is returned.

Syntax

<operand 1> In (<list of values>)

Example:

Set As: If #Myfield IN (100,200,300) then 200 else 500

Null:

The value TRUE is returned if the <operand1> is empty, otherwise false is returned.

Syntax

<operand 1> Null

Example:

Set As: If #Myfield Null Then 200 Else 500

Between …. And:

The Between … And operator returns True, if the value of <operand> is between <Lower limit> and <Upper Limit> (inclusive); otherwise, it returns False. The Not logical operator can be included to evaluate the opposite condition.

Syntax

<operand> Between <Lower limit> And <Upper Limit>

Example:

If #Myfield Between 50 And 150 Then 200 Else 500

String Operators

A string operator allows comparing two strings. The following are the string operators:

Contains/ Containing

Checks if the operand contains given string

Starting With/ Starting

Checks if the operand starts with the given string Beginning With/ Starting

Ending With/ Ending

Checks if the operand ends with given string

Like

Checks if the operand matches with the given string pattern

Contains/ Containing

The string operator Contains alias Containing returns Yes if the <operand1> string has a string <operand2> else No is returned.

Syntax

<operand1> Contains/Containing <operand2>

Example:

Set As: “Hello TDL” Contains “TDL”

Starting With/ Beginning With/ Starting

 The string operator Starting with alias Beginning With returns Yes if the <operand2> starts with <operand1> string else No is returned.

Syntax

<operand1> Starting With/Starting/Begins <operand 2>

Example

Set As: If “TDL World” Starting with “TDL” Then “TDL” Else “World”

Set As: If “TDL World” Beginning “TDL” Then “TDL” Else “World”

Ending With/ Ending

The string operator Ending With alias Ending returns Yes if the <operand2> ends with <operand1> string else No is returned.

Syntax

<operand1> Ending With/Ending <operand 2>

Example:

Set As: If “World TDL” Ending with “TDL” Then “TDL” Else “World”

Like

Like operator uses % as a pattern matching character. % means zero or more characters.

Syntax


<operand1> Like <%operand 2>

Example

Set As: If $Name Like “%Party” Then “Debtors” Else “Creditor”

Note: The operator = is a comparison operator, not assignment operator. There is no assignment operator in TDL.

Operator Precedence

The expression value is evaluated based on the following operator precedence:

  1. Arithmetic Operator
    • Division or Multiplication
    • Addition or Subtraction
  1. Logical Operators
    • NOT
    • AND
    • OR
  1. Comparison Operators

The precedence is in the order of their appearance in the expression.

      4.  String Operators

  • The precedence is in the order of their appearance in the expression.
  • The default operator precedence can be overridden by enclosing the expression in Brackets/parenthesis.
  •  The expression in parenthesis is evaluated first.

 Data Types Supported by Arithmetic Operators

The arithmetic operators + (Addition), – (Subtraction), / (Division) and * (Multiplication) are applicable to all Data Types.

The following table specifies the data types of two operands and whether arithmetic operations can be performed or not:

Operand 1

Operand 2

Number

Amount

Rate of Exchange

Quantity

Rate

Date

Due- Date

Number

Yes

Yes

Yes

Yes

Yes

Yes

Yes

Amount

Yes

Yes

Yes

Yes

Yes

No

No

RateEx

Yes

Yes

Yes

No

No

No

No

Qty

Yes

Yes

No

Yes

Yes

No

No

Rate

Yes

Yes

No

Yes

Yes

No

No

Date

Yes

No

No

No

No

No

Yes

Due Date

Yes

No

No

No

No

Yes

Yes

  1. For data type Date, ONLY addition and subtraction is supported.
  2. For the data type String, ONLY addition is supported

Expressions in TDL

A TDL expression is a combination of an operand and operator, where an operand can be either a field/variable value, method/function/formula evaluation result, constant/keyword/identifier. In the expression a constant can be of type String, Logical or Number. The compound data types i.e., Date, Quantity, Amount and Rate are not supported as Constants. The keywords used in the expression can be any of the pre-defined values and the identifier always accepts a name of the definition which can be in turn derived from an expression. The detailed explanation on expressions is available in the topic Symbols and Prefixes.

Post a Comment

Is this information useful?
YesNo
Helpful?