Académique Documents
Professionnel Documents
Culture Documents
This document is for informational purposes only. TALLY MAKES NO WARRANTIES, EXPRESS OR
IMPLIED, IN THIS DOCUMENT.
Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights
under copyright, no part of this document may be reproduced, stored in, or introduced into a retrieval
system, or transmitted in any form, by any means (electronic, mechanical, photocopying, recording, or
otherwise), or for any purpose, without the express written permission of Tally Solutions Pvt. Ltd.
Tally may have patents, patent applications, trademarks, copyrights, or other intellectual property rights
covering subject matter in this document. Except as expressly provided in any written licence agreement
from Tally, the furnishing of this document does not give you any licence to these patents, trademarks,
copyrights, or other intellectual property.
Tally, Tally 9, Tally9, Tally.ERP, Tally.ERP 9, Shoper, Shoper 9, Shoper POS, Shoper HO, Shoper 9 POS,
Shoper 9 HO, TallyDeveloper, Tally Developer, Tally.Developer 9, Tally.NET, Tally Development
Environment, Tally Extender, Tally Integrator, Tally Integrated Network, Tally Service Partner,
TallyAcademy & Power of Simplicity are either registered trademarks or trademarks of Tally Solutions Pvt.
Ltd. in India and/or other countries. All other trademarks are properties of their respective owners.
The heart and crux of Tally Technology is the DSL-Tally Definition Language (TDL) which
has been there from the advent of Tally version 5.4 during the late 90’s i.e., around 1995-96.
The language used in development of Tally, predominantly made its presence felt with
business programmers who opted for developing customizations and extensions on Tally.
Over the years, major advancements in Tally Technology resulted in transformation of Tally as
a complete Application Development Platform. The developments in TDL resulted in capabil-
ities for Rapid Development, Rendering, Data Management and Integration. The Tally Defini-
tion Language (TDL) along with the development suite Tally.Developer 9 (TD 9) provides the
strong technology backbone for developing solutions on Tally platform.
This book provides a comprehensive coverage of Tally Technology starting from the basic
understanding of Tally Architechture to in-depth concepts, usage and implementation
scenarios using TDL. With each chapter you will find explanations for topics along with
syntax and examples substantiating the content. The exercises provided give a good hands-on
experience for the concepts learnt.
The preliminary chapters from 1 through 5 mainly focus on the various components of the
language along with User Interface Design elements. The chapters 6 through 11 provide the
core capability coverage on the basis of which Tally is termed as an “Application Develop-
ment Platform”. The chapters “6. Objects, Collections and Internal Object Structure”,
“8. Object Manipulation and Storage” and “11. User Defined Fields, Validation and Controls”
emphasizes solely on data storage, manipulation and retrieval methodologies using the user
interface. The chapters “7. Actions, Event Framework and Key Definition“ and “9. TDL Pro-
cedural Capabilities“ cover concepts which make TDL a true action and event driven language
with procedural capabilities augmenting its power. The chapter “10. Variable Framework“
helps in understanding the usage of various types of variables available in TDL. The chapter
“12. Advanced Reporting and Printing” will take you through the various reporting and
printing techniques. The various techniques aid in development of simple tabular reports to
complex columnar reports which provide a strong foundation in the area of MIS reporting.
Towards the end you will find various use cases which will give you an insight on various
implementation scenarios emphasizing on the application of concepts covered. By the time
you complete the book you are ready to undertake the project work “Inventory Management-
Garment Store” and dive into the over expansive world of Tally Technology.
Contents
Chapter 1: Tally Technology – An Overall Perspective
1.1 Introduction...................................................................................................................... 1
1.2 Need for Tally Extensions .......................................................................................................... 2
1.3 The Domain Specific Language – TDL ................................................................................... 4
1.3.1 Definition Language .......................................................................................................... 4
1.3.2 Action Driven Language with Procedural Capabilities .................................................... 4
1.3.3 Completely Object Oriented .............................................................................................. 4
1.4 Tally – As a Development Platform ......................................................................................... 5
1.4.1 Rapid Development ............................................................................................................ 5
1.4.2 Flexibility ........................................................................................................................... 5
1.5 Components of a TDL program .............................................................................................. 6
1.5.1 Underlying Tally Technology ............................................................................................ 7
1.6 Tally Architecture – Overview ................................................................................................. 8
1.6.1 The Application/Tally Layer .............................................................................................. 9
1.6.2 The TDL Language and Interpreter Layer ........................................................................ 9
1.6.3 Platform Layer ................................................................................................................... 9
1.7 Tally Technology – Capabilities ............................................................................................. 11
1.7.1 Solution-ability & Customizability .................................................................................. 11
1.7.2 Multiple Output Capability .............................................................................................. 11
1.7.3 Data Management Capability .......................................................................................... 11
1.7.4 Integrate-ability ............................................................................................................... 11
1.8 Tally Development Environment ............................................................................................ 12
1.8.1 Getting Started with TD 9 ................................................................................................ 13
1.8.2 Usage of Different Explorer Windows ............................................................................. 14
1.8.3 Usage of different Browsers and Property Window ........................................................ 15
1.8.4 Coding Convention .......................................................................................................... 16
1.8.5 Navigating and understanding the Tally Source Code(Default TDL project) ................. 16
1.8.6 Folder Structure and File naming convention ................................................................. 17
1.8.7 Navigating and Searching project Default TDL .............................................................. 17
1.9 TDL Program Life Cycle ......................................................................................................... 17
i
Contents
ii
Contents
5.3.1
Sizing/ Size Attributes .................................................................................................... 118
5.3.2
Spacing/ Position Attributes .......................................................................................... 125
5.3.3
Alignment Attributes ...................................................................................................... 130
5.3.4
Some Specific Attributes ................................................................................................ 145
5.4 Definitions and Attributes for Formatting ........................................................................... 149
5.4.1 Border ............................................................................................................................ 149
5.4.2 Color, Background, PrintFG and PrintBG Attribute .................................................... 156
5.4.3 Format Attribute ............................................................................................................ 157
5.5 Report Layouts in Tally.ERP 9 ............................................................................................. 159
5.5.1 Tabular Report – Eg: Ledger Vouchers ......................................................................... 159
5.5.2 Columnar Report, Eg: Sales Register .......................................................................... 160
5.5.3 Designing a Hierarchical Report, Eg: Trial Balance ................................................... 161
iii
Contents
iv
Contents
v
Contents
vi
Contents
Use Cases
1. Use Case I – Import from Excel/Text .................................................................................. 633
2. Use Case II – Multiple Saved Configurations for Report ................................................. 642
3. Use Case III – Multiple Email Configurations ................................................................... 650
4. Use Case IV – Duplicating Vouchers .................................................................................. 656
5. Use Case V – Inter Company Data transfer ........................................................................ 660
6. Use Case VI – Multi Company Outstanding Report ......................................................... 665
7. Use Case VII – Voucher and Invoice Customization ........................................................ 669
vii
Chapter 1: Tally Technology – An
Overall Perspective
1.1 Introduction
We begin our discussion with the fundamental assumption that you are quite familiar with
Tally.ERP 9 as a complete business solution. Tally.ERP 9 is known for its sheer simplicity in
terms of user experience. The way business processes are handled, workflows are managed and
the complex reports are generated gives a clear indication on the usage flexibility and benefits
derived from the product by the business user. Before moving into the technology aspects of
Tally.ERP 9 let us have a cursory look into the major functional areas catered to by the applica-
tion.
Order to Payment (Purchase Process)
Simple (Cash Purchase) to Advanced Purchase Processes (including Ordering,
Receipting, Rejections, Discounts, etc)
Order to Receipt (Sales Processes)
Simple (Cash Sales) to Advanced Sales Processes (including Orders Received, Deliv-
ery, Invoicing, Rejections, Receipting)
POS Invoicing at retail
Material to Material (Manufacturing Processes)
Simple to Multi-Step material transformations
Discrete and Process Industry cycles
Handling Work in progress and valuations.
Payroll
Simple to Complex Payrolls - including working with different units of measures
(e.g. job rates). Statutory compliances, their specification and their usage
MIS
A complete set of reports for Financial, Inventory, MIS & Analysis
Budgeting & Controls with advanced classification and filtering techniques
Group Companies and multiple consolidation views
Cross-Period Reporting, Forex handling, Bank Reconciliation
1
Tally Technology, An Overall Perspective
One click Export option to port data into other applications (e.g. Spreadsheets) for
additional manipulation
Tax Audit using TallyNet
TallyNet and its overall enabling environment for Remote Access Services
Tax Audit Tools in Tally for the CA community to deliver affordable services to
addressing Security and Privacy concerns
Statutory Compliance
Compliance Requirements and related configurations in Tally
Implementation of Direct Taxes (TDS/TCS, FBT), Indirect Taxes (Excise, Service
Tax, VAT, CST)
1.2 Need for Tally Extensions
In addition to the default product capabilities, the user often requires additional modules in
order to suit the over expanding requirements of the business space. Sometime the requirement
may vary from a simple change like "having an additional field in the vouchers and dis-
playing the corresponding value in the invoice" to a complex requirement like "altering
the entire workflow from master entry upto the generation of MIS reports".
All these solution requirements can be catered to and deployed within minimal developmental
cycles using the RAD(Rapid Application Development) environment provided by Tally.
Have you ever wondered how a simple report is rendered on the Tally screen? Let us consider
the following simple steps to experience the development environment of Tally.
1. Open Notepad
2. Type the following on the screen and save it with a file name HelloTDL.txt
[Report: RepHello]
Form : FrmHello
[Form: FrmHello]
Parts : PrtHello
[Part: PrtHello]
Lines : LneHello
2
Tally Technology, An Overall Perspective
[Line: LneHello]
Fields : FldHello
[Field: FldHello]
Set as : "Hello World"
3. Start Tally > Goto F12 > TDL Configuration
4. Click the button Local TDLs available on the right button bar
5. Specify the path of the file "Hello TDL.txt" within the List of TDLs to preload on
start up
6. Goto the menu Gateway of Tally menu and click on the menu item HelloTDL and
the following output screen appears:
As a first time programmer on Tally platform, you might have experienced the following from
the above program execution.
1. The program is written in a language which is very different from a general purpose
procedural programming language
2. The program runs within the Tally Application
3. The language primarily contains certain syntaxes enclosed within square brackets
3
Tally Technology, An Overall Perspective
4. On user interaction with a particular menu item the main report is invoked as a sepa-
rate window
Each of the above observations can be elaborated to understand the crux of the Technology
behind Tally.
1.3 The Domain Specific Language – TDL
The entire application and the user interface via which the user interacts is completely built
using the Tally Definition Language. This is the Domain Specific Language of Tally which is
developed to provide the user with flexibility & power to extend the default capabilities of
Tally and integrate with external applications. TDL as a language provides capabilities for
Rapid Development, Rendering, Data Management and Integration.
1.3.1 Definition Language
TDL is a definition language. This provides the users with "named definitions" which allows
them to specify a set of properties/attributes for those definitions. Every definition should have
a name and it should be unique across the same definition type. Definitions are enclosed
within square brackets.
All the interface elements, data elements, style elements and procedural elements are created
using definitions. The order in which the specific attributes/properties come into effect is
purely based on user interaction. This is unlike a procedural language where the complete
sequence of execution is in the hands of the programmer.
1.3.2 Action Driven Language with Procedural Capabilities
TDL is a completely Action Driven language. Actions are triggered based on events which can
either be user or system driven. The specific segment of the code gets executed on the basis of
the Action performed. E.g. The programmer can write a code to create a Report, and the
action to trigger the report is specified with a menu item. The actual report comes into
existence only when the user selects the particular menu item.
The procedural elements are incorporated into the language where an Action can be created by
the programmer. This allows the specification of series of tasks/operations controlled by the
programmer. The fundamental aspects of conditional evaluation and looping are incorporated
which can be used for flow control, computation and object data manipulation.
1.3.3 Completely Object Oriented
TDL is a completely Object Oriented Language. Whether it an Interface, Data, Integration ,
Procedural or a styling element everything is an Object. There are mainly two types of Objects
in TDL Interface Objects and Data Objects. Interface Objects mainly determines the behavior
of the product in terms of user experience. Data objects suffice the information storage
requirements of the application. The data objects can either be used for temporary data display
and computation or can be persisted into the Tally Database.
Let us take an example of Interface Object. When a Report is created a unique report object is
instantiated. This report object in turn contains the various other objects used to build a report.
4
Tally Technology, An Overall Perspective
It emphasizes strongly on reusability. An object defined once can be reused and modified to
have additional properties of its own along with existing properties/attributes.
1.4 Tally – As a Development Platform
Tally is not only the application but is also a complete development environment which
enables the programmer to build extensions using Tally Definition Language in a RAD envi-
ronment.
1.4.1 Rapid Development
TDL is a rich language i.e it is possible to design a complex report or modify an existing report
by referring to a list of various components of the language. The components can be listed of
various types as
Definitions, Attributes & Modifiers – Every definition has a permissible set of
attribute for defining specific behavior and usage
Datatypes & Operators – A finite set of Datatypes and operators govern the type of
data and construction of valid expressions
Predefined Actions & Functions – A comprehensive set of predefined Actions and
Functions available within the platform can be invoked/ called in order to perform
the desired task.
Moreover, the entire source code of Tally is provided along with the development suite. The
existing definitions can be used as templates and tweaked further to provide an extremely
rapid deployment environment.
We will introduce you to the development suite in the later sections of the
chapter.
1.4.2 Flexibility
TDL provides an amazing level of flexibility in the hands of the programmer. Most of the time
customer specific requirements may seem like majority of functional changes which are
required to be done but they may only be minor variation of the existing functionality which
may be done within no time. User can extend the default functionalities of the product by
writing only a few lines of code.
5
Tally Technology, An Overall Perspective
The first TDL program "Hello TDL.txt" has been modified slightly in order to highlight the
various components of a TDL program. The code has been written using the development
suite Tally.Developer 9 where the various colors used for Syntax Coloring signify a specific
component of the TDL program. Refer to the legend box in the above figure to identify the
various components.
TDL comprises of many components such as definitions, actions, attributes, modifiers,
keywords, operators, functions and data types.
Definition – Definitions in TDL are the fundamental building blocks which control the
Interface Design and Data gathering requirements primarily. The procedural elements in the
language are also introduced in the language using definitions. In the above program all the
elements enclosed within square brackets are definitions. There are a predefined set of Defini-
tion Types available in TDL. The programmer can create multiple instances of each by
assigning a unique name to each.
Example:
Report, Form, Part etc. are definition types and the definitions names are prefixed with the
word “Hello”.
6
Tally Technology, An Overall Perspective
Attributes – The properties of definition are referred as 'Attributes'. Each definition has a set
of specific attributes. The attributes works on the concept of Name/Value value pair. Each
attributes has a Name and an assigned value.
Example:
Set As is an attribute of a field definition and "My formula" is the value assigned to it.
Actions – Actions are executors of the specified task with a definite result. This provides an
indication to the TDL interpreter (platform element), as to when a specific task has to be per-
formed. The definition Report and Menu are mostly originators of an action. These actions can
either be predefined or can be defined by the user by making use of the procedural elements.
Example:
The menu item Hello TDL invokes the Action Display
Operators – Like any other the programming languages TDL also supports all the standard
operators to construct an expression in addition to some TDL specific Operators. TDL
provides the following categories operators i.e. Unary, Arithmetic, String, Comparison/
Logical.
Functions -– The procedural flow is achieved in TDL with the help of functions. TDL has a
wide range of built-in functions for generic operations required by the end user. For specific
business requirements and data manipulations an user defined function can be written by
making use of the procedural elements.
Example:
$$LocaleString is a predefined function which takes the parameter as "My Test Field"
Data Types – The Data Types in TDL specifies the type of data which can be stored in the
field or to specify the type of the variable. In TDL there are two types of datatypes available
Simple and Compound.
Example:
String, Number etc are simple datatypes whereas Amount,Quantity etc are compound
datatypes
1.5.1 Underlying Tally Technology
The new Tally.ERP 9 has been designed in a way which provides extensive customisation &
solutioning capability which enables the developer community to exploit and deliver
solutions to complex business problems and requirements with the Power of Simplicity.
TDL – Tally Definition Language takes care of all aspects of solution development ie form/
screen design, entries, generating reports, data export, printing and mailing. TDL provides tre-
mendous capability in the hands of the programmer to extend, customize and build solutions
on Tally.ERP 9.
Moreover the language itself is designed keeping the Business/Application programmers in
mind. Programmers with sound domain experience can concentrate on the implementation of
business requirements rather than being bogged on by technical nuance of the platform. The
7
Tally Technology, An Overall Perspective
8
Tally Technology, An Overall Perspective
The entire Tally architecture can be conceptualized as being divided into three layers
The Application / Tally.ERP 9 Layer
The TDL Language and Interpreter Layer
The Platform Layer / Engine
1.6.1 The Application/Tally Layer
Application layer forms the topmost layer of the product architecture. All the user interactions
take place at this layer. It is through this interface that the user exploits complete functionali-
ties offered to them. The product exploits the capabilities of the Operating System using the
intermediate layers between the application and the OS.
1.6.2 The TDL Language and Interpreter Layer
The heart of Tally, this layer forms the key link between the application and the platform layer
consisting of
Tally Definition Language
TDL Interpreter
Tally Definition Language is developed to provide the user with flexibility and power to
extend the default capabilities of Tally and integrate with external applications. TDL provides
a development platform for the user. The entire User Interface of Tally is built using TDL.TDL
as a language provides capabilities for Rapid Development, Rendering, Data Management and
Integration.
TDL works in an interpreted environment. In TDL, definitions are deployed by use and not by
mere existence. An action performed by user will trigger a particular segment of code to get
executed. The interpreter examines each line and throws an error when encountered.
1.6.3 Platform Layer
The capabilities which TDL offers are due to the strong platform capabilities of Tally. This is
the lowermost layer of Tally which interacts with the OS and ultimately the file system. The
various components of the platform layer are
DB Engine
ODBC Engine/Driver
Language Parser
Output/Rendering Engine
Function Library
User Interface/ Business Logic
Memory Management
All the retrieval and manipulation requests to the database by the application program are
handled by the Database Engine. Tally database is a true OODBMS (Object Oriented
9
Tally Technology, An Overall Perspective
Database Management System). It is possible to store data as objects and retrieve data as
objects. In other traditional OODBMS, data pertaining to an object is internally converted into
disparate files and stored, but in Tally database data for an object is stored as it is as a block.
This allows faster retrieval of data. Object Oriented Recursive Management System follows
the concept of Flexi-Length Record, Flexi-Field, Self-Indexed weighted file structure for a
extremely compact and fast database. Fault tolerance is built in the system i.e., it uses the
CRC(Cyclic Redundancy Check) mechanism to achieve this. Transaction support is provided
by using roll forward capability i.e. it is extremely robust in case of power failure. It provides
concurrent access in a multi-user environment.
Tally File System consists of Data files (Master, Transaction, Link Masters), Msgfiles (Trans-
action Management) and State Files (concurrency control and exclusivity control).
It follows the concept of Embedded and Weighted Indexes. In other traditional databases,
separate index file is maintained. In Tally, indexes are built into the data files. This facilitates
faster retrieval of data.
ODBC Engine/Driver handles the ODBC calls from external applications to Tally Database
or from Tally to external Data Bases using SQL (Structured query language). Tally can act as a
client accessing data from external databases and as Server it allows the data access from Tally
to external Applications.
TDL works in an interpreted environment. The Language Parser consisting of Syntax and
Formula parser enables the parsing of syntax and semantics of the statements and expression
parsing. Whenever an statement containing a formula is encountered by the interpreter the
formula identifies the type of the formula i.e. Method, Function, Expression Formula, etc.
which is determined by the type of symbol prefix i.e. $, $$, @, etc.
Managing multiple outputs types from Tally and rendering it based on the output environment
is the capability of the Output Engine. TDL has the capability to output to Screen, Printer,
File (XML, SDF), Mail, and HTTP using this engine. If we talk specifically about Display,
Tally has a unique capability to accommodate the entire contents into the screen. It also
shrinks the data to fit within the specified width of the field. The mechanism using which data
is made to fit the screen is taken care by the Screen Management algorithm. Scrolling, Page
Break, etc. is provided as functionalities.
Some capabilities which are required by the application based on business type it caters to are
built in into the system as business logic. The Business Logic/UI engine takes care of valida-
tion techniques and checking of business rules. If the capabilities and validations were to be
provided in the TDL layer, it would consume a large amount of time for processing. Bundling
this at the platform layer enables an increase in application speed and ensures integrity of data.
For e.g., Some validation mechanisms like matching the Debit Credit totals can never be
bypassed even if data is pushed from an external application to Tally.
Function Library provides a wide range of functions for performing various activities. These
functions execute by accepting a predefined set of parameters returning a value to the calling
expression from the TDL layer.
10
Tally Technology, An Overall Perspective
All the memory requirements of the application when it is running are taken care of by
Memory Management component. This takes care of interactions with the Operating System
on the memory requirements of the application. This will take care of allocating a chunk of
memory from the OS and managing it. From time to time, the common activities such as
garbage collection, compacting and releasing the unused memory aids in optimal use of
computer memory.
All of these platform components are developed in a language which can interact with the
Operating System directly. These internally make use of various algorithms, OS calls (System
calls) and Data Structures for the interactions. The platform developers interact at this layer
and provide new functions and TDL language capabilities to be used by the programmers.
1.7 Tally Technology – Capabilities
1.7.1 Solution-ability & Customizability
TDL is a powerful tool in the hands of the programmer which enables Customizability &
Solutioning capability in the product. TDL is platform independent, i.e., the TDL programs
remain the same irrespective of which Operating System/ Network Environment one uses
TDL automatically takes care of all developmental features of a solution, be it entries, reports,
printing, data export in various formats with a single unified program. There is no requirement
of resources with varied technical expertise to build these diverse functionalities unlike other
technologies which may require a Database programmer, an Application programmer, a
systems programmer, etc.
1.7.2 Multiple Output Capability
Same language can be used to output to multiple output devices and formats. Whenever an
output is generated this can be displayed on the screen, printed ,transferred to a file in particu-
lar format, mailed or transferred to a webpage using Http protocol.
1.7.3 Data Management Capability
As we have discussed earlier data is stored and retrieved as objects. There are a few internal
objects predefined by the platform. Using TDL it is possible to create and manipulate these
information with ease. If an additional field is required by the user to store information as a
part of the predefined object that capability is also provided ie by using TDL the user can
create a new field and store value into the same which can be persisted in tally database.
1.7.4 Integrate-ability
Tally has been designed in a way which provides extensive integration capability which
enables the developer community to exploit and deliver cross platform solutions thereby
allowing seamless interoperability among multiple applications with the Power of Simplicity.
Tally.ERP 9 is endowed with limitless possibilities due to its capability to interface with other
applications, devices and the internet. Tally.ERP 9 allows export and import of data in various
formats like CSV, Excel and so on.
11
Tally Technology, An Overall Perspective
It can act as a backend(server) for various web-applications built on platforms like ASP, PHP
etc or other applications accessing data using ODBC. Using TDL data can be accessed from
any external ODBC Database. TDLs procedural capabilities perform various tasks including
batch jobs, scheduled events and so on. It can also be made a part of a larger system process.
Tally provides different API's (Application Programming Interfaces) to integrate data.
XML
ODBC
DLL
These allow seamless integration between application/database in two modes:
Online Mode
Tally to Tally using Synchronization
Tally to External Application and vice versa using the Interfaces Available
Tally to Web Service using HTTP Interface
Offline Mode
Tally to External Applications using Export
Data from External Application in XML using Import
We have Tally Definition Language (TDL) which is a domain specific development language
of Tally and is integrated with Tally. ERP 9 platform. It enables the programmer to develop
solutions IN and Around Tally. We have comprehensively covered the capabilities of Tally
12
Tally Technology, An Overall Perspective
Technology and TDL in the preceding sections of the chapter. It is a powerful instrument in
the hands of the TDL programmer to extract maximum benefits from Tally!!!
Tally.Developer 9 is a comprehensive development suit designed specifically for program-
ming in TDL (Tally Definition Language). Tally.Developer 9 comes with its unique features
in terms of :
Easy programming by Syntax Colouring, Tagging and Navigation of code, Auto
Completion, Project Management and so on
Ease of debugging with error listing and diagnosis
Build , Compilation / Validation / Execution of Code from within the product
Authorization techniques for TCP(Tally Compliant product) ensuring IP protection,
control license usage and minimize revenue leakage.
Easy Distribution mechanism using licensing and subscription renewals
Easy customer serial management
Access to the Complete Tally source code as a reference
Ability to load multiple versions of the source code
Instant references to TDL Language API's such as Schema, Definition and
Attributes, Functions, Actions and so on
Ability to extend multilingual support to the product, customization, modules in
localized languages with the powerful dictionary manager tool
Rich set of TDL language documentation and programming samples
Access to the support centre / KB
Tools that help to develop and test external application's integration with tally (Tally
connector)
13
Tally Technology, An Overall Perspective
Please refer to the "Getting Started with Tally.Developer 9" for the detailed
explanation of Installation and Licensing process. The document can be down-
loaded from the Tally website.
The developer window is divided in four sub windows namely Browser Window, Editor
Window, Property Window and Output Window.
1.8.2 Usage of Different Explorer Windows
Browser window consists of four tabs: Project, Definition, Schema and Function. By default
the Project tab (Project Window) is active which displays all the loaded projects in a tree view.
14
Tally Technology, An Overall Perspective
Editor Window is the place which displays the actual file content. Output window also
contains four tabs, Output, Build, Search and Command. Property windows display additional
information for the item selected in the Browser window.
Please refer to the Tally.Developer 9 Help file for the detailed explanation of
each window and their functionality.
Project browser displays the loaded projects and the folder and files in each in tree view.
When a Project is selected the property window displays the project statistics like Project
location, number of files in the project, project GUID etc.
Definition browser displays all the definition types in TDL and the list of all the attributes
supported by each definition as a tree view. The property window displays a brief description
of the selected definition type and addition information like number of attributes, category etc.
If the attribute is selected than the property windows displays details like attribute type,
number of parameters, and even for the sub attribute.
Schema browser displays the metadata for all the objects of Tally database as a tree view. The
object structure displays list of all the methods and collections available in each object of Tally
schema. The Property window displays details corresponding to the object , collection or the
method name selected. If a method name is selected then the displayed details are the data type
accepted by that method and whether it is a repeated or not.
Function browser displays list of all the built-in functions in TDL. The functions are listed
under the specific category. The Property window displays details like Total number of param-
eters, mandatory parameters, category, execution mode and return type along with the details
of each parameter like parameter type, data type and mandatory flag.
Action browser displays list of all the actions in TDL. The actions can be viewed alphabeti-
cally, category wise or definition wise. The Property window displays details like Total
15
Tally Technology, An Overall Perspective
number of parameters, mandatory parameters, category, execution mode and return type along
with the details of each parameter like parameter type, data type and mandatory flag.
Please refer to the "Getting Started with Tally.Developer9" for the detailed
explanation of Installation and Licensing process. The document can be down-
loaded from the Tally website.
Static Variables
Variables
List Variables
Local Formulae
16
Tally Technology, An Overall Perspective
17
Tally Technology, An Overall Perspective
We have an option while creating Project to add an Existing Source File or a New File which
will be created subsequently.
18
Tally Technology, An Overall Perspective
The authorization details like the Author Name, Serial Numbers, Product GUID its can be
specified in project Properties Build Options tab.
Step II:Compilation & Error diagnosis – Checking the program for possible syntax and
other errors by compiling the program
This can be either a single step where we can compile the project directly (which will list the
syntax errors and other errors in the program) or a two step process where we can check for
syntax errors first and then compile the program.
Checking Syntax Errors
The application Tally.Developer 9 comes with a built-in compiler which helps in finding out
the syntactical errors before attaching the TDL to Tally.ERP 9. The user can select option List
Syntax Errors or simply select compile.
19
Tally Technology, An Overall Perspective
Compiling Project
Compiling project provides the user a flexibility to compile all the files in a project in one go.
The user can click on the error message displayed in the output window to navigate to the
location in file which has an error.
Step III:Build TCP(Tally Compliant Product) – Securing the code by creating a TCP
The step to create a TCP file is referred as building in the Tally.Developer 9. The user can
select the Build option from Build Menu.The (.tcp) file corresponding to the .tpj file is created
using the various authorization settings configured while creating the .tpj.
Step IV:Deploying the TCP – Associating and executing the tdl program (tdl/txt/tcp) with
Tally.ERP 9. The TCP/TXT can be associated and executed within Tally.ERP9 in two ways.
Specifying TDL file in Tally.ini
Specifying TDL file in Tally.ERP 9 configuration screen
Specifying TDL files in Tally.ini
The path must be specified in the Tally.ini file using the parameter called 'TDL'. In the initiali-
zation file two parameter values must be specified. The value of parameter User TDL must be
set to Yes and the value of parameter TDL is the TDL file path. If the parameter 'User TDL' is
set to No, Tally.ERP 9 will not read any TDL parameters specified in Tally.ini file.
To associate the MyFirstTDL.tcp file with tally.ERP9, specify the following in the Tally.ini
file:
User TDL = Yes
TDL= C:\MyFirstTDL.tcp
Now save the file and launch the Tally.ERP 9 application.
Specifying TDL file in Tally.ERP 9 configuration screen
Alternatively, the TDL file name can be specified in the configuration screen displayed by
selecting menu item 'TDL Configuration' from the F12: Configure menu. In this screen, click
on the button Local TDLs which displays the TDL Configuration screen. Specify the value
Yes in field 'Load TDLs on Start up' and the <Path\filename> with extension in 'List of TDLs
to preload on Tally Startup' field respectively.
Enter the path of HelloTDL.tcp as shown:
20
Tally Technology, An Overall Perspective
Now in the main menu Gateway of Tally a new menu item My First TDL will appear. Select
the menu to see the result as shown:
21
Chapter 2 : Definitions, Attributes
and Modifiers
Introduction
An overall insight on the Tally Technology, the Development language and the Tool has given
us a strong foundation over which we can proceed and explore the various domains of Tally
Definition Language.
As we know, TDL is a definition language. This provides the users with named definitions
which allows them to specify a set of properties/attributes for those definitions. Every defini-
tion should have a name and that it should be unique. Definitions are enclosed within square
brackets.
All the interface elements, data elements, style elements and procedural elements are created
using definitions. The order in which the specific attributes/properties come into effect is
purely based on user interaction. This is unlike a procedural language where the complete
sequence of execution is in the hands of the programmer.
The properties of definitions are referred as attributes. Attributes decide behaviour of the defi-
nitions. We have a set of modifiers which allow the programmer to alter either the definitions or
the corresponding Attributes.
This chapter will help us to cover the concept of definitions, its categorization and then
progress on to discussion for attributes, its types and modifiers.
2.1 Definitions
A definition is identified by its type and unique name. TDL is definition language based on
object oriented programming concepts which strongly emphasizes on reusability. Once a defi-
nition is created it can be reused any no of times. Not only can it be reused but new features can
be added along with existing ones.
A definition is created as per below:
Syntax
[<Definition Type> : <Definition Name>]
All definitions start with an open square bracket and ends with a closed bracket.
23
Definitions, Attributes & Modifiers
Where,
<Definition type> is name of predefined definition types available in the language e.g. Col-
lection, Menu, Form, Part, Line, Report etc.
<Definition Name> is any user defined name which the user provides to instantiate the defini-
tion i.e. whenever a definition is created a new object of a particular definition type comes into
existence.
Example:
[Part: PartOne]
In the example the type of definition is part and the name of definition is PartOne. The combi-
nation of definition type and definition name must be unique. There are 20 definition types in
TDL.
Proper naming conventions allow us to ensure uniqueness and better code readability/clarity
across projects.
Naming Conventions for Definitions
Definition name must be unique for a particular Definition type
Definition names are case and space insensitive
Special characters are not allowed
Definition names should not start with numerals
The reserved words cannot be used as a Definition Name
The Definition names that have been used by default TDL cannot be given as a Def-
inition name by User defined TDL. If required, the default definitions can be reused
/modified
It is strongly recommended that Definition names be meaningful and indicate the
functionality of the element being defined. For example, prefix MBS to indicate My
Balance Sheet for all Definition used in a TDL program to create Balance Sheet
report
2.1.1 Definition Categorization
There are twenty definitions in TDL which can be categorized based on their functionality and
usage. Some definitions are used to design the Interfaces and control the Presentation Layers.
Few suffice the fundamental requirements of data gathering and processing requirements. The
procedural capabilities included in the language are also provided using definitions.
The broad categorization is given as below
Interface Definitions
Data Definitions
Formatting Definitions
Integration Definitions
Action Definitions
24
Definitions, Attributes & Modifiers
System Definitions
Procedural Definitions
Interface Definitions
These definitions control the construction of the Interfaces. Mostly oriented at the presentation
layers of the application. The various visible elements on the Tally screen are Menu, Report,
Button and Tables fall under the category of Interface Definitions. The fundamental interface
definition is the “Report”. In order to create a Report, the other sub elements will be required
which have a predefined containership and cannot exist on their own.
25
Definitions, Attributes & Modifiers
The definitions Menu and Button falls under the category of Action and
Interface definition both as they control the appearance and perform an Action
as well
Example:
In the example a menu definition is created with the name My Menu. It contains two items
Item A and Item B. Item A invokes the report Rep A which is constructed using the various
interface definitions as per hierarchy shown in the picture.
[Menu: My Menu]
Add: Item : Item A: Display:Rep A
Add: Item : Item B: Display:Rep B
26
Definitions, Attributes & Modifiers
[Report : Rep A]
[Form :Form A]
[Part:Part A]
[Line:Line A]
[Field:Field A]
Data Definitions
The Definitions which suffice the data gathering, processing, storage and manipulation
requirements are termed as Data Definitions.
Definitions in this category include
Object – As we know TDL is an Object Oriented Language. Whenever we create a
new Interface Definition an object is instantiated. Under the Data Definition Cate-
gory we are referring to Objects which contain Data and methods to manipulate its
own data. The Data Objects can further be categorized into Internal (predefined) and
TDL Objects(user defined).TDL follows a hierarchical data structure ie an Object
can further contain a single or multiple sub objects. The various interface elements
either pull/push data from/into the data objects. A Ledger / Group is an example of
an internal Object.
Collection – The fundamental Data gathering and processing element of TDL is the
Collection definition. The bulk of aggregation, chaining and Integration capabilities
are delivered using Collections. A collection is a group Object/Collections. The
source of Objects in the collection can be either an Internal/TDL Object.
The definition Collection falls under the category of Data and Integration defi-
nition as it provides Data Processing and Integration Capabilities as well.
27
Definitions, Attributes & Modifiers
Example:1
In the example a collection definition My Coll is created which has two objects O1 and O2.
The Object O1 is created using the definition Object with name O1.
[Collection :My Coll]
Objects :O1, O2
[Object:O1]
Name :”ABC”
Example:2
The collection definition “LedColl” is created using the internal ledger objects.
[Collection :LedColl]
Type:Ledger
Formatting Definitions
We have earlier covered the construction elements of the Interfaces. These definitions control
the appearance of the content or elements on the screen.
Definitions in this category include
Style – Style determines the appearance of the text to be displayed by using a partic-
ular font scheme. Font name, Font style and font size can be changed/defined using
style definition. In default TDL the pre-defined Style definitions are Normal Bold,
Normal Italic, and Normal Bold Italic. We can create our own style definitions and
apply them as required
Border – This definition is used to create borders of a specific type. Thin Box, Thin
Line, Common Border are all examples of pre defined borders which can be applied
to Part, Line and Field definitions
Color – Color definition is used to define a color. A name can be given to an RGB
value of color. Once a name is assigned to an RGB color value it can be referred in
the color attribute of the field.
Example:
In the example a Color definition New Blue and a Style definition New Style is created and
applied to the contents of the Field My Field.
28
Definitions, Attributes & Modifiers
Integration Definitions
The definitions which facilitate the integration of Data from external applications to Tally
form a part of Integration Definitions. Import of Data using standard API’s ODBC,XML and
DLL is provided using the Collection Definition. Though XML is the de facto standard for
information interchange in recent times, still there may be a few applications which support
SDF/Fixed Width format for storing the data.We have the definitions ImportFile and Import
Object which enable integration with this format.
Definitions in this category include:
Collection – The collection definition which is primarily a Data Definition falls
under this category this provides the capability to import data from a variety of dis-
crete External Data Sources. The data objects gathered through the API’s ODBC,
XML and DLL can be further persisted into the Tally DataBase.
Import File – Import file allows describing the structure of each record in the ASCII
file that is being imported. The field names and the width is specified as the
attributes of this definition.
Import Object – Import Object specifies the Internal Object into which the data
being imported is stored. It also defines the mapping of the Object being imported to
the corresponding Internal Object.
Example:1
In the example a collection is created using the data gathered from an XML located at an
HTTP URL.
[Collection :HTTPColl]
Remote URL : “http:\\localhost\MyFile.xml”: ASCII
Example:2
In the example an Import File definition I45Mast is created to define the structure of the
external file being imported and the data is imported into the corresponding Ledger object as
defined using the Import Object definition I45Ledger.
29
Definitions, Attributes & Modifiers
30
Definitions, Attributes & Modifiers
System Definitions
System definitions are viewed as being created by the administrator profile. Any items defined
under system definitions are available globally across the application. It is not possible to
instantiate a new Object of type System unlike other definitions given above. System defini-
tions can be defined multiple times in TDL. The items defined are appended to the existing
list.
Definitions in this category include:
System: Form Keys – The key names that are defined under Form Keys will be
available by default to all the form definitions.
System: Formulae/Formulas – The formulas which are included in the list if Sys-
tem Formulae/Formulas can be shared by all the TDLs. These are referred as Global
Formulae.
System: Menu Keys – The key names included in the list of Menu Keys will be
available to all the Menu definitions by default.
System : TDL Names – In this definition, the frequently used business keywords
can be stored as system names. System names are keywords which have an identifier
associated to it. Only once the value will be saved.
System : UDF – The additional storage required as per the business requirements
are created using the definition System : UDF
System : Variable – If the variables are to be declared at the System scope the same
is done using this definition. The variable thus declared will be available across all
reports in Tally.
System : Events – This definition is used to define certain events and associate the
corresponding actions based on the occurrence of the same.
Example:1
In the example below a variable My Variable is defined at the system scope.
[System: Variable]
My Variable : “Value“
Example:2
In the example below an action Display is triggered on the occurrence of the System Event
Load Company.
[System :Events]
CmpLoadEvent3: Load Company :TRUE:Action:Display:"Balance Sheet"
Procedural Definition
Definition in this category include:
Function – It has been possible to include the procedural capabilities in the language
using the definition Function. Prior to Tally.ERP 9, the tasks to be triggered from the
31
Definitions, Attributes & Modifiers
key/button/menu item used to be only those Actions which were provided by the lan-
guage/platform. Using the function definition the programmer can now define his
own set of tasks to be performed and the same can be triggered from a key/button/
menu item. Also, it can be used to perform computations and can be called from
within an expression. This can be used in an evaluation or for execution.
Example:
A function definition SI Calc used to calculate the Simple Interest and return the result to the
calling program.
[Function: SI Calc]
Parameter: P : Amount
Parameter: R : Number
Parameter: T : Number
Returns : Amount
Variable : Interest: Amount
2.2 Attributes
Each definition has properties referred to as Attributes. There is a predefined set of attributes
provided by the platform for each definition type. The attribute specifies the behavior of a def-
inition. Attributes differ from definition to definition. A definition can have multiple attributes
associated with it. Each attribute has a 'Name' (predefined) and an assigned value (provided
by the programmer). The values to be set for an attribute can either be a constant or the result
of an expression evaluation. The expression may be a combination of methods, variables,
formula etc which may be evaluated based on a condition.
Syntax
[<Definition Type> : <Definition Name>]
<Attribute Name> : <Attribute Value>
Where,
<Attribute Name> is name of the attribute specific for the definition type
<Attribute Value> can be a constant or a formula
Example:1
[Part: PartOne]
Line : PartOne
32
Definitions, Attributes & Modifiers
Example:2
[Form: Form One]
Part: Part One
An attribute can have more than one value separated by “:”. When an attribute accepts more
than one value, each sub-value is referred as sub-attribute. The number of sub-attribute allows
to classify the attribute as either Single, Dual, Triple.
Syntax
<Attribute Name> : <Sub-Attribute> : <Sub-Attribute>
Where,
<Attribute Name> which is a keyword is called as the primary attributes.
<Sub-attribute> doesn’t have a keyword associated with it. Primary attributes are recognized
based on the keyword.
<Sub-attributes> are recognized based on the pre-defined internal order. If the order is
changed the specified action will not take place. <Sub-Attribute> can be optional.
Example:
Explode : <part name> : <condition>
Here Explode is a primary attribute and <part name> and <condition> are sub-attributes.In
the order of <part name> and <condition> is changed, the code will not execute the explode
action.
In this example sub-attribute <part name> is mandatory while the sub-attribute <condition>
is optional. Sub-attribute finally evaluates to a value which is of a particular data type.
[Part: PartOne]
Line : LineOne
33
Definitions, Attributes & Modifiers
Line : LineTwo
;; Observe the multiple occurance of the attribute Line with values LineOne and LineTwo respectively
This type is in contrast with the attributes which accept ONLY one value where these values
can fall into the category of Single/Dual/Triple. Whenever multiple values are provided to
such attributes the recent value overwrites the previous value.
In the example below we have provided two values to the “Set As” attribute
[Field : FieldOne]
Set As :”Value One”
Set As :”New Value”
;; Here FieldOne displays the “New Value” as Set As accepts only one value the the “New Value” overwrites the
previous value “Value One”
34
Definitions, Attributes & Modifiers
35
Definitions, Attributes & Modifiers
Other examples of Single Attributes are: Set as, Set Always, Scroll and Title etc.
The Part attribute is of Type Single List as it takes one subattribute as value and this value can
be repeated multiple times
Other examples of Single List Attributes are Part, Field, and Line etc.
The Repeat Attribute is of Dual type as it takes two subattributes as value and the value can be
specified only once in a part.
36
Definitions, Attributes & Modifiers
37
Definitions, Attributes & Modifiers
Example:
[#Menu: Gateway Of Tally]
Key Item : Sales Analysis : S : Display : Sales Analysis
Key Item : Purchase Analysis: P : Display : Purchase Analysis
/* The attribute “Item” takes first subattribute as “Sales Analysis” second subattribute as the hotkey “S” and the
third subattribute as Action “Display” and the subsequent subattributes as parameters as required for the action
“Display”. The attribute can be specified twice with different set of subattributes.*/
The attribute Key Item is of Type Menu Item List where the no of subattributes for the value
vary based on the parameters for the Action and this value can be repeated multiple times.
The attribute On is of Type Event List where the number of subattributes for the value vary
based on the parameters for the Action and this value can be repeated multiple times. The list
of actions thus specified will be executed sequentially when the even occurs.
38
Definitions, Attributes & Modifiers
ON is a list type attribute, so list of actions can be executed sequentially when the specific
event occurs.
2.2.4 Predefined Attribute values in TDL
There are certain Attributes which take predefined values .The TDL programmer can make
use of them. The values accepted must be from the predefined set.
Example:
Scroll : Vertical
Scroll attribute accepts value Vertical, Horizontal and Both only. Some attribute accepts an
identifier as a value. The identifier is an existing definition name which is either available in
user defined TDL or in the default TDL.
Example:
Style : Normal
Style : Normal Bold
Style attribute takes name of style definition as a value. The style definition name can be user
defined.
Aliases for Definitions and Attributes
In TDL, we can refer to Defintions/Attributes with the same name. The synonymous names
are known as alias.
Definition Alias
Key and Button definition are Aliases.
Attribute Alias
Lines is an alias for Line. Similarly Part/Parts/ Top Parts, Field/Fields/Top Field etc. are alias
of the same attribute. Either can be used to get the same result
In a Part Definition a line can be assigned using the attribute “Line” as well as “Lines”. So, the
two Definitions (1 and 2) of a Part below are identical.
Definition – Default
In Default TDL, definition Default is defined for the definition types Menu, Report, Form,
Field and Collection. Some of the attributes predefined for the “Default” definition for each
definition type. Whenever a definition of this type is created, it inherits all the properties of
definition Default. We don’t have to explicitly mention these attributes.
Syntax
[<Definition Type> : Default]
Where,
<Definition type> is either of Menu, Report, Form, Field and Collection.
Example:
[Menu: Default]
Top Buttons:Select Company,Close Company,Blank Button,Change Date
39
Definitions, Attributes & Modifiers
[Form: Default]
Space Top : 0.5
Space Bottom : 0.5
Key : Form Delete, Form Cancel
XMLTag : "ENVELOPE"
Toolbar Buttons: FormOutputLanguage, FormInputLanguage
Toolbar Buttons: OnlineHelpButton, HelpButton, TallyNetButton
Bottom Toolbar Buttons : BottomToolBarBtn1
/*In the form definition Default, the spacing of .05 is specified. The Enclosing XML tag sent along with all the XML
formats from Tally is specified at Form Level. The toolbar buttons are also specified.*/
40
Definitions, Attributes & Modifiers
[Field: Default]
Space Left : 0.5
Space Right : 0.45
Show Table : On First Key
Lines : 1
Border3D : Yes
/* In order to display data in the field the Lines attribute is mandatory. The attribute is already specified in the field
definition Default, so when any field definition is created , it inherits this attribute value. The application developer
need not specify it again. */
Syntax
KBLanguage : <Language ID>
Where,
<Language Id> is language id in which the master is created. If the language id is specified
as 0 then all masters will be gathered other wise only maters created in provided language id
will be gathered.
[Collection: Default]
KB Language : If ##SVFilterMasterTableOnLanguage then +
##SVCurrentUILanguageId else 0
/*In collection definition Default only attribute specified is KB language. The attribute KBLanguage is used to
gather masters created in particular language id. */
2.2.5 Modifiers
Modifiers are used to perform a specific action on definition or an attribute. These are mainly
targeted to do bring in some changes to the existing Definition or Attribute.
Modifiers can be classified as
Definition Modifiers – #, !, @ and *
Attribute modifiers
Static/Load time modifiers – Use, Add, Delete, Replace/Change
Definition Modifiers
The modifiers that operate upon Definitions and are used to modify/alter some existing defini-
tions are referred to as definition modifiers.
Syntax
[<Modifier><Definition Type> : <Definition Name>]
41
Definitions, Attributes & Modifiers
Where,
<Modifier> is any one of the definition modifiers #, ! and *
<Definition type> is name of predefined definition types
<Definition Name> is any user defined name for the definition
Modifier ( # )
This is used to modify an existing definition. # can also be used to modify the [System :
Formula/Formulae] definition.
Example:
[#Menu: Gateway of Tally]
Here # is used to modify the existing menu “Gateway of Tally “
Modifier ( * )
This is used to re-initialize the definition i.e. all existing properties are not considered.
Whatever we provide as new attributes are only applicable. It is similar to modifying an
existing definition and deleting all its attributes and adding new ones.
[*Field: Sample ReInitialize]
Info :"Re Initialized - All the attribute values are deleted+
and newly defined
Border: Thick Box
Even the attributes that are inherited from default definition are removed. When
a field used for displaying data is re-initialized, the attribute Lines is manda-
tory.
Modifier (!)
This is used to define optional definition for an existing Definition. We can have multiple
options for the same definition based on a condition. The optional definitions can be defined
using the modifier “!” .We cannot refer to the optional definition directly from any other defi-
nition.
Example:
[Report : RepName]
Option: Rep1:##SVCurrentCompany=”Tally India”
Option: Rep2:##SVCurrentCompany=”Tally Solutions”
<report attributes>
42
Definitions, Attributes & Modifiers
[! Report:Rep1]
<report attributes>
[!Report:Rep2]
<Report Attributes>
;;When the current company is “Tally India” the report Rep1 will be displayed. The report Rep 2 is displayed if the
selected company is “Tally Solutions”. In any other case the report RepName will be displayed.
Attribute Modifiers
An attribute modifier is used to modify an existing defined attributes. There are two types of
attribute modifiers.
Static/Load time modifiers
The modifiers Use, Add, Delete, and Replace are referred as static modifiers. These modifiers
do not require any conditions to be evaluated at the run time. The value is evaluated at the load
time only and remains static throughout the execution.
Modifier (Add)
The ADD modifier is used in a definition to add an attribute to a Definition.
Example:
[Form: Cost Centre Summary]
Add : Button :ChangeItem
;;A new button “ChangeItem” is added to the form Cost Centre Summary.
Modifier (Delete)
The Delete modifier is used in a definition to delete an attribute from the Definition
Example:
[Form: Cost Centre Summary]
Delete : Button : ChangeItem
;;The button ChangeItem is deleted from the form Cost Centre Summary. The functionality of the button
ChangeItem is no longer available in the form Cost Centre Summary.
Modifier ( Replace)
The replace modifier is used in a definition to alter an attribute of the Definition
Example:
[Form: Cost Centre Summary]
Replace: Part : Part1: Part2
;;The part Part1 of form Cost Centre Summary is replaced by the Part2. Now only Part2 properties are applicable.
43
Definitions, Attributes & Modifiers
Modifier (Use)
The USE keyword is used in a definition to reuse an existing definition. After using the defini-
tion one can add or delete the attributes as required in the resultant definition.
Example:
[Field: DSPExplodePrompt]
Use : Medium Prompt
;;All the properties of the existing field definition Medium Prompt are applicable to the field DSPExplodePrompt.
Modifier (Local)
The Local attribute is used in the context of the definition to set local value within the scope of
that definition only.
Example:
Local : Field: Name Field : Set As : #StockItemName
;;The value of the formula #StockItemName is now the new value for the attribute Set As of the field Name Field
applicable only for this instance.
Modifier (Option )
Option is an attribute which can be used by various definitions, to provide optional definitions
based on the condition.. The ‘Option’ attribute can be used in the Menu, Form, Part, Line, Key,
Field, Import File and Import Object definitions.
Syntax
Option : <Optional definition>: <Logical Condition >
<Optional Definition> is the name of optional definition created using the definition
modifier !.
<Logical Condition> if the ‘Logical’ value is set to ‘True’, then the ‘Optional definition’
becomes a part of the original definition and the attributes of the original definition are
modified based on this definition.
Example:
[Field: FldMain]
Option: FldFirst :cond1
Option: FldSecond :cond2
/* The field Fldfirst is applicable when the cond1 is true. The field Fldsecond is applicable when the cond2 is true.
Optional definitions are created with the symbol prefix "!" as follows*/
[!Field: FldFirst]
[!Field: FldSecond]
44
Definitions, Attributes & Modifiers
The attribute option compulsorily evaluates the conditions for all the options provided in the
definition code. All the definitions satisfying the evaluation conditions are applied to the
resultant definition. This means that it is not always easy to write the code where just want one
of the options to be applied, the programmer have to make sure that other options are not
applied using a negative condition. The new attribute Switch has been provided to support
these types of scenarios where evaluation is to be carried out only up to the point where the
first evaluation condition is satisfied
Modifier (Switch-Case)
Switch is attribute is similar to the Option attribute but reduces code complexity and improves
the performance. Once a condition is satisfied from one group, switch will not check further
conditions from the same group. It will evaluate the conditions from the other groups speci-
fied, if any.
The Switch are grouped using a label. Therefore, multiple switch groups can be created and
zero or one of the switch cases would be applied from each such group.
45
Definitions, Attributes & Modifiers
Apart from this, the switch can be grouped using a label, as shown below:
Syntax
Switch : Label : <Definition Name> : <Condition>
Switch : Label : <Definition Name> : <Condition>
Where,
< Label > is any string combination used to group,
< Definition Name > of same definition type in which the switch modifier is used,
< Condition > when true the optional definition will be used.
Example:
[Field: Sample Switch]
Set as : "Default Value"
46
Definitions, Attributes & Modifiers
Let’s say that the value of the two variables Sample Switch1 and Sample Switch3 are true. In
this case the field Sample switch will display text Value from Sample Switch 1 in Released
Blue color.
47
Definitions, Attributes & Modifiers
Add/Delete/Replace are referred to as Delayed attributes because even if they are specified
within the definition in the beginning their evaluation will be delayed till the end within static
modifier and normal attributes.
4. Option
The option conditions are evaluated on runtime based on the user selection.
5. Switch
The switch conditions are then evaluated on runtime based on the user selection.
6. Local
The local modifier is evaluated in the end, on runtime based on the user selection.
Example of Evaluation
Let us understand the execution of a TDL Program.
Exercise 2.1
Objective
The objective of this program is to render the text 'Hello World' at the Top and Hello Universe
at the bottom of the screen in 'Blue' Color.
Capabilities Used
Attribute Modifier Use gets evaluated first in the sequence.
Subsequently, other attributes get evaluated; hence the Width within 'Short Name
Field' is overridden with the Width Attribute specified in this Field.
Since, Field Attribute 'Set As' is a single type attribute; the recent value will be set.
Hence, the value 'Hello World' overrides the value 'World'.
Code
[Report: Exer Seq of Eval]
Form : Exer Seq of Eval
Title : "Sequence of Evaluation"
48
Definitions, Attributes & Modifiers
49
Definitions, Attributes & Modifiers
Output
The report displays two lines on the screen. The line Exer Seq of Eval HW is displayed at the
Top and the line Exer Seq of Eval HU at the bottom of the screen.
In the field Exer Seq of Eval HW, as the attribute modifier Use is evaluated first, the font
used is Arial, the Width is 15 and case is Title case. The Set As attribute is of type single so the
last value for the Attribute Set As overrides the previous Set As. The result Hello World is
displayed.
In the Line Exer Seq of Eval HU, the field Exer Seq of Eval HW is reused. The value
displayed in the field is locally set/ altered to Hello Universe. The width of the form is auto set
according to the width set in the Fields.
Exercise 2.2
Objective
The objective of this program is to render the text 'Hello World’ either in Full Height of the
Form or required content height within the Form on selecting the Button 'Alt + H'. In other
words, this program helps us control the Height of the Form on click of a Button.
Capabilities Used
The objective of this code is to understand :
The Switch Case conditions and Optional Definition
50
Definitions, Attributes & Modifiers
51
Definitions, Attributes & Modifiers
Output
The above are the Output when the Logical Variable value Exer SC Full Height is No. On
clicking the button Full Height, the Variable value is set to Not of current Variable value.
52
Definitions, Attributes & Modifiers
Hence, the resultant Variable value is Yes and the below Output appears displaying Form with
Full Height and the Toggle Button Title changed to Reqd Height.
In the Form Exer Switch Case, there are two Switch conditions based on Logical Variable
value Exer SC Full Height. Based on the satisfied condition, relevant optional Form gets
evaluated. Also, the Button Title and Field contents get altered based on the Variable value.
53
Chapter 3: Datatypes, Operators and
Expressions
3.1 Introduction
In the previous chapter we have discussed about the three basic components of TDL, Defini-
tions, Attributes and Modifiers. The primary focus of this chapter would be 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
that is refers to, the data is classified in to different types called as data type. 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
3.2 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 we know that TDL is a business language it requires the support for various business data
types like amount, quantity, rate apart from the other basic types.
55
Datatypes, Operators & Expressions
Based on the requirements of the business the data types in TDL are classified in two catego-
ries: Simple and Compound.
3.2.1 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 restric-
tions are required that 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.
56
Datatypes, Operators & Expressions
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.
3.2.2 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.
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 cur-
rency, 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 the decimals
mentioned in the respective currency master.
57
Datatypes, Operators & Expressions
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 infor-
mation 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 10Bags 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 -92233720368547.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.
58
Datatypes, Operators & Expressions
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 4 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.
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.
59
Datatypes, Operators & Expressions
Example:
[Field: Qty Secondary Field]
Type : Quantity: Secondary Units
Data Type Formats
In TDL various formats are used are available to represent the data. Some Formats are applica-
ble 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.
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
60
Datatypes, Operators & Expressions
The formats applicable for applicable data types Number, Amount, Quantity, Rate and Rate Of
Exchange are as follows:
61
Datatypes, Operators & Expressions
62
Datatypes, Operators & Expressions
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
63
Datatypes, Operators & Expressions
The unit is displayed based on the Unit of Measure of selected Stock Item.
64
Datatypes, Operators & Expressions
65
Datatypes, Operators & Expressions
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.
i. Implicit conversion happens from Amount, Rate Of Exchange, Quantity
and Rate to Number data type when a method returning value in respec-
tive data type is used in Set As attribute. Otherwise an empty field is dis-
played.
Eg: [Field: NoToAmt]
Type : Number
Set As : $ClosingBalance
ii. 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.
Eg. [Field: NoToLogical]
Type : Logical
Set As : 0
iii. When the string specified in a Logical field is any one of these True, False,
On, Off, Yes, No then implicit conversion is done.
Eg.[Field: StrToLogical]
Type : Logical
Set As : “True”
66
Datatypes, Operators & Expressions
67
Datatypes, Operators & Expressions
Code
[Report: Exer Data Types]
Form : Exer Data Types
Title : "Data Types"
68
Datatypes, Operators & Expressions
69
Datatypes, Operators & Expressions
Output
Program Explanation
The report displays three lines on the screen. The title Understanding Data Types are
displayed by using the pre-defined field Form Subtitle.
The lines Exer Data Types Title and Exer Data Types are displayed after the Form Title line.
The line Exer Data Types Title displays names of various data types and line Exer Data
Types displays the respective values for each data type.
In the field Exer DT String, Exer DT Date, Exer DT Number and Exer DT Amount the
attribute Type is used to set the data type in the respective field as String, Date, Number and
Amount.
The attribute Align, Border and Width are used to create the table like format.
3.3 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
70
Datatypes, Operators & Expressions
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
71
Datatypes, Operators & Expressions
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.
3.3.3 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/ Can be used to check if the value of the operand is true.
ON/YES
FALSE/ Can be used to check if the value of the operand is false.
OFF/NO
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.
72
Datatypes, Operators & Expressions
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
Syntax
<operand 1> OR <operand 2>
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. Eval-
uates <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.
The final value can be evaluated based on the following Table
<Operand 1> <Operand 2> AND
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
73
Datatypes, Operators & Expressions
The value of the formula IsBatchwiseOn is set to true only if the values of method $IsBatch-
WiseOn 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
Syntax
[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.
74
Datatypes, Operators & Expressions
75
Datatypes, Operators & Expressions
In / One: The value TRUE is returned if the <operand1> is in the List of comma sep-
arated 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 <oper-
and> 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
3.3.5 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 / Checks if the operand starts with the given
Beginning With/ Starting string
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 <operand 2>
76
Datatypes, Operators & Expressions
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”
77
Datatypes, Operators & Expressions
Addition or Subtraction
2. Logical Operators
NOT
AND
OR
3. 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.
3.3.7 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 Number Amount Rate of Quantity Rate Date Due-
Exchange Date
Operand 2
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
Exercise 3.2
Objective
The objective of this program is to accept two numbers/strings and compare them.
78
Datatypes, Operators & Expressions
Capabilities Used
The If Then Else Conditions are used for comparing the Strings/Numbers and display the
result accordingly.
The expression for comparison uses
Logical Operator OR
Numerical Operators >, <
String Operators EQUALS, CONTAINS
Function 'String' to convert the parameter to String Type
Code
[Report: Exer Operators]
Form : Exer Operators
Title : "Operators"
79
Datatypes, Operators & Expressions
Set As: 12
Border: Thin Box
80
Datatypes, Operators & Expressions
/* String Operator 'CONTAINS' is used to compare two strings and return if one contains the other. Similarly, 'EQUALS'
is used to compare two strings and returns if both the strings are equal. */
Set As:If @NonEmptyChk then ""else if #ExerOpInput1+
EQUALS #ExerOpInput2 then @EqualStr else +
if #ExerOpInput1 CONTAINS #ExerOpInput2then +
@S2PartOfS1 else if #ExerOpInput2 CONTAINS +
#ExerOpInput1 then @S1PartofS2 else @ElseMsg
;; Local Formulae within Field 'Exer Op Result Str'
EqualStr : "Both strings are equal"
S2PartOfS1: #ExerOpInput2 + " is part of " + #ExerOpInput1
S1PartOfS2: #ExerOpInput1 + " is part of " + #ExerOpInput2
ElseMsg : "There is no relation between both the strings"
End-Of-File
81
Datatypes, Operators & Expressions
Output
Program Explanation
The report is displayed in edit mode five lines on the screen. The title Working with
Operators is displayed by using the pre-defined field Form Subtitle.
The line Exer Operators is used to accept two numbers and the line Exer Operator Result
Num is used to display the result after comparing the two numbers. The numbers for compari-
son are entered in the fields Exer Op Input and Exer Op Input2 and the logical operator OR
is used to check if any of these two is empty. The comparison operator > and < are used in the
If statement to check which number is greater than the other and display the result accordingly.
Similarly in the field in the line Exer Operator Result Num uses the attributes Set As to
display the result after evaluating the specified string expression. The string operator 'CON-
TAINS' is used to compare two strings and return if one contains the other and 'EQUALS' is
used to compare two strings and returns if both the strings are equal.
The attribute Set Always is used to display the result immediately.
3.4 Expressions in TDL
Expression is combination of operands and operators. A valid TDL expression is a combina-
tion 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 key words used in the expression can
be any of the pre-defined values and Identifier always accepts a name of the definition which
can be in turn derived from an expression.
We will be taking up the various types of expressions and expression evaluation at the end of
the subsequent chapter “Access Specifiers & Special Symbols”.
82
Chapter 4 : Access Specifiers and
Special Symbols
Introduction
In the previous lesson, we have discussed the various Data types, Operators and Expressions
used in TDL. In TDL, few symbols are used for specific purposes and some symbols are used
as Access Specifiers i.e., mainly used to access value of a method, variable, field, formula etc.
Some symbols are used for a general purpose such as modifiers. Let us refer to the table below
to understand the categorization of the various symbols and their usage at a glance.
Access Specifiers
Symbols Usage
@ Used to access Local formula
@@ Used to get the value of a System formula
# When prefixed to Field name gives the value of the field
## Used to get the value of a global variable
$ Used to access the value of an Object Method
$$ Used to call the Function
Special Symbols
Symbols Usage
Definition
Modifiers
* Used to Reinitialize a Definition
! Used to create an Optional Definition
# Used as a definition modifier
Code Diffren-
tiator
; ;; ;;; /* */ Used for adding comments in TDL
83
Definitions, Attributes & Modifiers
84
Definitions, Attributes & Modifiers
is specific to a definition and not required by any other definition. The value of a Local
Formula evaluation can be accessed using the Symbol Prefix @.
Example:
[Field: CompanyNameandAddress]
Set as : “Tally India Pvt Ltd, No 23 & 24, AMR Tech Park II,+
Hongasandra, Bangalore”
The above can be written, using the Local Formula as:
[Field: CompanyNameandAddress]
Set as : @Company + @Address + @City
Company : “Tally India Pvt Ltd,”
Address : “No 23 & 24, AMR Tech Park II, Hongasandra, ”
City : “Bangalore”
In the above example Company, Address and City are the formula names and specific values
are assigned to it. The "Set as" attribute is used to set the value of the field by evaluating the
concatenation of local formulae Company, Address and City by using the symbol @.
Example:
[System: Formula]
BackgroundColor:”Green”
AmountWidth :20
[Field: RepTitleAmt]
Color: @@BackgroundColor
[Field: RepDetailAmt]
Width: @@AmountWidth
85
Definitions, Attributes & Modifiers
Color: @@BackgroundColor
[Field: RepTotalAmt]
Width: @@AmountWidth
In the example mentioned above, all the fields assume the same width and the same back-
ground color. If the width of the fields need to be altered, a change is made only at the
[System: Formula] section. This change will be applied to all the Fields using the Global
Formula AmountWidth and BackgroundColor.
86
Definitions, Attributes & Modifiers
TDL are categorized based on the type and the number of values they can hold. The various
types of variables are:
Simple Variable
Simple Repeat Variable
Compound Variable
List Variable
Now we can look into these variable types in detail.
Simple Variable
Simple variables are used to store single value of the specified data type
Compound Variable
Compound Variables allow the user to store multiple values of same or different data types.
This is achieved by making the variable itself compound, by allowing variable declaration
inside itself. These sub variables are called member variable of the main variable.
List Variable
List variables can store multiple values of the specified variable type by using a string based
‘Key’ specification. List Variable is a container ie; data structure which holds elements. List
variables are by default sorted on the insertion order. List variables further divided into
Simple List variable and Compound List Variable.
Simple List Variable
Simple List Variables can hold multiple values of single data type.
Compound List Variable
Compound List Variables can hold multiple values of different data types.
Both Simple and compound list variables can be declared as a list.
87
Definitions, Attributes & Modifiers
where,
<Variable Name> is the meaningful name for the variable
Attribute is the name of the attribute
Attribute Value is the value to be assigned to the specified attribute
Example:Simple Variable
[Variable : SimpleVar]
Type : Date
In the above example the variable SimpleVar holds the data type of Date is defined
[Variable: EmpDetails]
Variable : PhoneNo : Number
Variable : BloodGroup: String
[Variable : Address]
Variable : HouseNo : String
Variable : StreetName: String
Variable : Place: String
In the above example the attributes Variable and List Variable defines the compound variable.
Here Name and EmpId are Simple variables and Emp Details and Address are Compound
88
Definitions, Attributes & Modifiers
variables which are defined as members. A separate definition is required for the compound
variable Emp Details and Address.
[System: Variable]
SystemVar : No
Or
[System: Variable]
Variable:SystemVar
Report
Variables can be declared at report definition and it will be having the report scope. These
variables exist till the life of the report. The variables declared at report scope are accessible
from the report itself and all TDL elements which are executed form within this report such as
another report, function etc.
Example:
[Variable: ReportVar]
Type : Logical
[Report: Report Scope]
Variable: Report Var
Function
As we discussed earlier Function is an important component in TDL language. User Defined
functions are used to create procedures by TDL programmer, if it is required to execute a
certain set of statements repeatedly to achieve a certain functionality. Since Function is a TDL
component, it also allows the variables to be declared at its scope. Function variables has
lifetime till the end of the execution of the function.
89
Definitions, Attributes & Modifiers
Example:
[Function: FunctionVar]
Variable : FuncVar1
List Variable: FuncVar2
Example:
;;Variable Definition
[Variable: ReportVar]
Type : Logical
;;Variable declaration
[Report: Report Scope]
Variable: Report Var
;; Accessing the variable
[Field: Report Scope]
Option : Report Scope Red BG: Not ##ReportVar
Option : Report Scope Green BG: ##ReportVar
Here we are accessing the value of a variable at the Report Scope by using the operator ##.
Similarly ## operator is used on a compound variable it returns the first member variable
value. If it is used on a list variable it returns the number of items in the list.
This operator is allow dotted notation syntax to access the member of compound variables and
also it support index operator to access the value of elements in list variable directly. This will
be covered in detail along with complete Variable Framework in subsequent chapters.
90
Definitions, Attributes & Modifiers
Internal Methods
The methods which are defined by the platform are called as Internal Methods. For example
the methods Name, Address, Parent are the internal Methods of Object Ledger.
The previous code snippet displays the value of the method Name of the associated object. As
we already know that the objects in TDL follows a hierarchical data structure. It is possible to
extract information from any level by using the dotted syntax. “$” also supports dotted
notation syntax for the same. This will be dealt with in detail in the Chapter “Objects,Collec-
tions & Internal Object Structure”.
User Defined Functions which does not return a value are called using the
keyword “Call”.
91
Definitions, Attributes & Modifiers
Example:
[Field: Current Date]
Set as : $$MachineDate
[Field: Credit Amt]
Set as : if $$IsDr:$ClosingBalance then 0 else $ClosingBalance
[Field: StringPart Field]
Set as : $$StringPart($Email:Company:##SVCurrentCompany):0:5
Exercise 4.1
Objective
The objective of this program is to understand the usage of different access specifiers in TDL.
The access specifiers available in TDL are @, @@,#,##,$ and $$.
Capabilities Used
Variable attribute is used to define or declare the value of a Variable
Accessing values of Local formula as well as System formula
TDL functions like $$String, $$IsBillwiseOn
Usage of Tooltip attribute
Code
[Report: Exer Symbols]
Form : Exer Symbols
Title : "Usage of Symbols"
;; Variable is declared of Type 'String' and an initial Value 'Variable Value' is set to it within this Report.
Variable: Exer Symbols Var1 : String: "TallySolutions Pvt Ltd."
Variable: Exer Symbols Var2 : Number: 9000
Object : Company: ##SVCurrentCompany
92
Definitions, Attributes & Modifiers
93
Definitions, Attributes & Modifiers
94
Definitions, Attributes & Modifiers
95
Definitions, Attributes & Modifiers
96
Definitions, Attributes & Modifiers
97
Definitions, Attributes & Modifiers
Output
Program Explanation
The output shows the usage of all the access specifiers. In the report, the part Exer Symbols
defines some lines which show the titles for the columns.
The Line Exer Symbols Title1 is used to show the main titles for the report. Further each
column divides into two to display titles for the value of field and its description for both fields
by using the line Exer Symbols Title2. The attributes Style, Border, Align, Width, Subtitle
etc are used to format the report or report values.
98
Definitions, Attributes & Modifiers
The Lines Exer Symbols@, Exer Symbols@@, Exer Symbols#, Exer Symbols##, Exer
Symbols$, Exer Symbols$$ includes four different fields called ExerSymbols Orig Info,
ExerSymbols Orig, ExerSymbols Reused Info, ExerSymbols Reused which are used to
display the values using various special symbols. These fields are locally modified in each line
by using the attribute modifier Local. Exer Add1, Exer Add2, Exer City, Exer State are the
system formulae which can be used anywhere in the program.
The attribute modifier Use is used at Line Exer Symbols$$ to reuse the properties of the
existing definition Exer Symbols@. The attribute Tool tip is enabled for the entire value
field.
Example:
$$String: $$MachineDate
In the above example, this function accepts machine date as parameter and it will be convert-
ing to the string data type.
$$Number
This function converts the given parameter into a valid number data type. It takes an expres-
sion and returns a numeric value. The value contains only four digits after decimal.
Syntax
$$Number:<expression>
Where, expression is any valid TDL expression
Example:
[System: Formula]
ActualRate : $Amount / $$Number:$ActualQty
In the above example the Number value is extracted from Actual Qty to divide Amount.
$$Date
The function $$Date is used to convert a date specified in string format into the "Date" data
type. This is mainly required when a string contains a date on which manipulations are to be
99
Definitions, Attributes & Modifiers
performed treating it as a date format eg: filtering the data based on the date comparison. TDL
allows Addition or subtraction of a number to a date type field and in turn, it will return a date
type field.
Syntax
$$Date : <String Expression>
Where, expression is any valid TDL expression
Example:
Set as : $$Date:$JoiningDate
In the above example the method joining date will return a date to $$Date as parameter.
$$Date function converts this date to date format.
$$AsAmount
This function is used to convert data types of the value from one form to amount type. This
function states the calculated value as an Amount.
Syntax
$$AsAmount:<expression>
Where, expression is any valid TDL expression
Example:
[Field: AmtFld]
Use : Amount Field
Set as : $$AsAmount:$BasicRateOfInvoiceTax
In the above example, "BasicRateOfInvoiceTax" is of type Number and to display the same in
Amount Field, it is being converted to Amount Type using the function $$AsAmount.
$$AsQty
This function treats the quantity received as Inward Quantity.
Syntax
$$AsQty:<expression>
Where, expression is any valid TDL expression
Example:
[Field: AsQty]
Use : Qty Primary Field
Set as : $$AsQty:$Amount
In the above example, Amount is of type Amount and to display the same in Quantity Field, it
is being converted to Quantity Type using the function $$AsQty.
100
Definitions, Attributes & Modifiers
$$Total
This function is used to total all the values in a specific column for a particular field. The
column of the Field being totaled could be a Quantity or Amount or a Number. The Fields
being totaled need to be specified in the Part Definition with attribute ‘Total’ apart from the
actual definition of the field. The Expression/Field values should be Amount/Number/
Quantity type.
Syntax
$$Total:<Field Name>
Example:
[Field: FieldTotal]
Use : Number Field
Set as : $$Total: SCRAmount
In the above example the field definition ‘FieldTotal’ and totals the "SCRAmount” field
values and display the final total in the “FieldTotal” field.
$$SubTotal
The Sub Total function is exactly like the Total function except that it is a running total for that
column and appears on individual Lines and not on the total lines, hence the individual lines
will need to use a defined Subtotal field. The Expression Field should be Amount/Number
Type. i.e., input should be numerical field. Return type will be Amount.
Syntax
$$SubTotal:<Field Name>
Example:
[Field: BillSubOp]
Use : BillOp
Set as : $$SubTotal:BillOp
In above Example the $$SubTotal will give the total of field BillOp
$$PrevFldTotal
The function $$PrevFldTotal is used to extract the total value of the previous fields. This is
useful in Multi column reports. It does not accept any parameter and returns a value of type
same as the type of previous fields. This function doesn’t take any parameters
101
Definitions, Attributes & Modifiers
Syntax
$$PrevFldTotal
Example:
[Field: DSP Perc]
TotPercVal : ($$AsSignedQty:$$PrevFld / $$Number: +
$$AsSignedQty: $$PrevFldTotal) * 100
4.4.3 Logical Functions
$$DoExplosionsFit
In case of printing, if a line is exploded then this function can be used to check whether the
exploded part fits in the given page. It returns logical expression Yes if it is true.
Syntax
$$DoExplosionsFit
Example:
[Line:EXPINVInvDetails]
Explode : EXPINVBatchDetails
NextPage : NOT $$DoExplosionsFit OR (($$LineNumber = +
$$LastLineNumber) AND $$IsLastOfSet)
This function can be used to print the line in the next page, with attribute Next Page in line.
$$IsDr
This function is used to check if the amount is a Debit amount.
Syntax
$$IsDr : <amount expression>
Example:
[Field: DrAmt]
Use : Logical Field
Set as : $$IsDr:$OpeningBalance
In the above example function returns "Yes" if "OpeningBalance " is a Debit amount else it
returns "No".
$$IsEven
This function checks whether the numeric value passed as a parameter is Even number or not.
If the given input is an even value the function will return "Yes" otherwise it will return "No".
102
Definitions, Attributes & Modifiers
Syntax
$$IsEven:<number>
Example:
[System: Formula]
NumVal : $$Number:25
ChkEvenNumber : $$IsEven:@@NumVal
In the above example, the system formula ‘ChkEvenNumber’ will return ‘No’.
$$IsGroupCash
This function is used to check if the group belongs to Cash-in-Hand or not.
Syntax
$$IsGroupCash: <string expression>
Where, String expression is any TDL expression, which returns string data type value
Example:
[System: Formula]
IsCashLedger : $$IsGroupCash:$Parent:Ledger:$Name
$$IsLedger
To check if the current object is of type "Ledger".
Syntax
$$IsLedger
Example:
Display : Ledger Monthly Summary : $$IsLedger
$$IsPayment
This function is used to check if the Voucher Type is Payment or not.
Syntax
$$IsPayment : <string expression>
Example:
Set as : if $$IsPayment:$VoucherTypeName then +
$$AsCrAmt:$Amount else $$AsDrAmt:$Amount
In the above example the Credit Amount is displayed if the voucher type name is Payment
otherwise it displays Debit Amount.
103
Definitions, Attributes & Modifiers
$$DayofWeek
This function returns the day of the specified date e.g., Monday. This function returns the
weekday of the date specified. The Parameter can be any expression (i.e.,Formula / Storage/
variable etc) in date format.
Syntax
$$DayOfWeek:<date expression>
Example:
Set as : $$DayOfWeek:$$CurrentDate
Function 'DayOfWeek' extracts the day of the week from the specified date ie; Current Date
$$MonthStart
This function returns the first day of the specified month.
Syntax
$$MonthStart:<date expression>
Example:
Set : SVFromDate : $$MonthStart:##SVCurrentDate
The above example will set the first day of the specified month to SVFromDate.
104
Definitions, Attributes & Modifiers
$$WeekEnd
This function gives the first Sunday’s Date. If the argument itself (Date) is a Sunday then it
will return the following Sunday.
Syntax
$$WeekEnd:<date expression>
Example:
Set : SVFromDate : $$WeekEnd:##SVCurrentDate
The above example will set the first Sunday’s date for the specified to SVFromDate.
Exercise 4.2
Objective
The objective of this program is to demonstrate the process of extracting value from the TDL
Functions using Symbol '$$'. The various date functions used in the program to extract the
value of current date, Day of the week, month and so on. Functions accept zero or more
parameters, processes and returns some value, this code also introduces some date related
functions.
Capabilities Used
Using the $$ symbol to extract the value from the function
Code
[Report: Exer Date Functions]
Form : Exer Date Functions
Title : "Date Functions"
Auto : Yes
105
Definitions, Attributes & Modifiers
106
Definitions, Attributes & Modifiers
107
Definitions, Attributes & Modifiers
Output
Program Explanation
The above report is displayed by using default TDL functions. The line Exer DF Current
Date extracts the current date by using the function $$MachineDate and this function accepts
zero parameters. Similarly, the function $$DayOfWeek returns the day of week and this
fuction accepts the value of the field #ExerDFCurrentDate.
The formatting of this report is done by using the attributes Align, Width, Border etc. The date
format also fixed by using the attribute modifier Use and the value of the same inherits the
format, which is defined in the default TDL.
108
Definitions, Attributes & Modifiers
[!Line: MFTBDtlsClsgG1000]
Local : Field : MFTBDrAmt : Style : Normal Bold
Local : Field : MFTBCrAmt : Style : Normal Bold
109
Definitions, Attributes & Modifiers
[!Line: MFTBDtlsClsgL1000]
Local : Field : MFTBDrAmt : Style : Normal
Local : Field : MFTBCrAmt : Style : Normal
In the above code snippet, the condition specified in both the options, will be checked and it
will execute the option satisfying the given condition. In this case, there is a possibility that
more than one condition might satisfy and get executed.
Example:Switch
[Line: MFTBDetails]
Fields : MFTBNameRight
Fields : MFTBDrAmt, MFTBCrAmt
Switch : Case 1: MFTBDtlsClsgG1000 : $ClosingBalance > 1000
Switch : Case 1: MFTBDtlsClsgL1000 : $ClosingBalance < 1000
[!Line: MFTBDtlsClsgG1000]
Local: Field : MFTBDrAmt : Style : Normal Bold
Local: Field : MFTBCrAmt : Style : Normal Bold
[!Line: MFTBDtlsClsgL1000]
Local: Field : MFTBDrAmt : Style : Normal
Local: Field : MFTBCrAmt : Style : Normal
In the previous code snippet, the condition specified in the switch statements, will be checked
one after another. The first statement satisfying the given condition will be executed and all
other statements grouped within this label, ‘Case 1’ will not be executed further unlike Option.
The similar behavior of Option can be achieved by specifying different labels, if required.
There are three formats to write a comment in TDL language. They are as follows:
110
Definitions, Attributes & Modifiers
Semicolon ( ; )
This is used for commenting a part from a line.
Example:
; Altering Menu Gateway of Tally
[#Menu: Gateway of Tally]
Add: Key Item: Comment: C: Display : Comment
Double semicolon ( ;; )
This is normally used for Single Line Commenting. Put a double semicolon in every line
before the starting of comments
Example:
;; Altering Menu Gateway of Tally
[#Menu: Gateway of Tally]
Add: Key Item: Comment: C: Display : Comment
Enclose a comment within /* */
This is used for multi line commenting. Start a comment with a single backslash with an
asterick ( /* ) and then at the end of the comment put an asterick with a single backslash ( */ ).
A comment can be split over more than one line
Example:
/* This code explains the usage of Multi-Line Commenting as well as Single Line Commenting.*/
111
Definitions, Attributes & Modifiers
Example:
;; Exposing Methods within the Objects to ODBC
[#Object: Ledger]
_Difference: $ClosingBalance - $OpeningBalance
Creating SQL procedures using ( _ )
By prefixing _ to a Collection Name, it turns into a procedure which can be referenced exter-
nally by passing the parameter as a Variable. Creating Procedures to be referenced externally
Example:
[Collection: _LedBills]
Type : Bills
Child of : #UName
SQLParms : UName
SQLValues : Bill No : $Name
SQLValues : Bill Date : $$String:$BillDate:UniversalDate
You will be in a better position to understand the above when we discuss the
same in subsequent chapter “ODBC Interface”.
112
Definitions, Attributes & Modifiers
In the code snippet the function access the value of the method ‘StartingFrom’ of the object
‘Company’ based on the value of the variable ‘SVCurrentCompany’.
113
Definitions, Attributes & Modifiers
Example:6
[System : Formula]
PrintLangName : $$FilterValue:@@LangNameInUILangauge:Languages:+
First:PrintLangConfigFilter
In the code snippet the function ‚$$FilterValue‛ retrieves the first matching value from the
Language collection for the value of the method
Example:7
[Field: CV Dep Variable]
Use : Name Field
Table : CV List Child Collection
Set As : $$CollectionField:$Name:2:CVListChildCollection
In the code snippet the function ‚$$CollectionField‛ retrieves the method $Name from the
second object of the collection ‚CVListChildCollection‛
So, any expression will always have an Interface Object and the corresponding Data Object on
the basis of which it will be evaluated. Methods, Variables and Fields are Leaf components in
an expression as other components like Formulae or Functions finally evaluate into either one
of these or result into constants. A method value is evaluated based on the data object and
Variable and Field value is evaluated based on Interface object. The data type of the value
returned by an expression depends upon the data type of its operands. While evaluating the
expression the operator precedence is considered. If there is a data type mismatch, then
implicit conversion (type casting) will be handled by the language compiler.
114
Definitions, Attributes & Modifiers
We will now look into the default context fall through of the compiler for evaluation of various
components of an expression.
Evaluating a method using $
Checks if it is an internal method or UDF
System Formula
Changes context to parent object in the hierarchy and the steps are repeated
[System : Formula]
TDSITAssbleValue : $$ReportObject:$$CollectionFieldByKey:+
$AssessableAmount:@@TDSCategoryParty: +
TDSPartyCategoryColl
115
Chapter 5: Dimensions, Formatting
and Report Layouts
5.1 Introduction
We have various definitions in TDL, which control the construction of the Interfaces. The
various visible elements on the Tally screen are Menu, Report, Button and Tables.
Report is the primary Interface element which is used for Display, Edit and Printing of data. In
order to create a Report, the other sub elements will be required which have a predefined con-
tainership and cannot exist on their own. They are Form, Part, Line and Field definitions. The
various specifications on Sizing, Alignment, Positioning and Formatting attributes applied for
these elements.
In this lesson, we will cover the various dimensional aspects of the screen design. The various
attributes, which control the appearance, will also be covered subsequently.
117
Dimensions, Formatting & Report Layouts
118
Dimensions, Formatting & Report Layouts
The following table shows the definitions and its supported attributes to be discussed in this
section.
Definition Attributes
Form Height, Width
Line Height
Field Width
Height and Width - Form Definition
Height and Width when specified in a Form Definition implies that it is the available Height
and Width, which can be utilized by all the Parts, Lines and Fields within the Form. If the
contents of the Part and Line exceed the available Height and/or Width, the contents of the
Form are squeezed to accommodate the same within the available Height and Width.
In the absence of any Height and Width specification, it assumes the Height and Width
required by the contents of the Form comprising of Parts, Lines and Fields.
Example:
[Form: Form Height Width]
Parts : Form Height Width
Height : 50% Page
Width : 50% Page
119
Dimensions, Formatting & Report Layouts
120
Dimensions, Formatting & Report Layouts
121
Dimensions, Formatting & Report Layouts
122
Dimensions, Formatting & Report Layouts
Key : Alt + W
Action : Set : Exer Is FullWidth: NOT ##ExerIsFullWidth
Title : If ##ExerIsFullWidth then "No FullWidth" else "FullWidth"
;; End-of-File
Output
123
Dimensions, Formatting & Report Layouts
Program Explanation
The above program is used to explain the usage and implications of the form attributes Full-
Height and FullWidth. The report shows the usage of FullHeight and FullWidth attribute by
using the buttons FullHeight and FullWidth. These two buttons are available to toggle the
values of variable and depends on the value of these variables the output is shown as above.
The form Exer FullHeight and FullWidth defines four switch conditions, it further defines
the optional forms to set the value of FullHeight, and FullWidth attributes. The Part Exer Full-
Height and FullWidth define the Lines and Bottom Lines for the part and the values are
displayed in the fields called Exer NormalWidth, Exer FullWidth and Exer Right Field.
The width of these fields is varied based on the Logical variable value from the switch condi-
tions. Based on the value of satisfied condition, the relevant optional form is get evaluated.
Similarly, the button title is altered based on the variable value.
FullScreen
The attribute FullScreen is used in Report definition. It helps to control the display of
command window/calculator pane. It is a logical type of attribute.
124
Dimensions, Formatting & Report Layouts
Syntax
FullScreen : <Logical Value>
The attribute Full Screen is set to Yes, command window will be hidden providing extra space
to the report displayed. The default value of this attribute is Yes. In case of the SubReport/
AutoReport, if the value of this attribute is not specified, the default value is No.
Example:
[Report: Attr FullScreen]
Full Screen : Yes
5.3.2 Spacing/ Position Attributes
This category includes all attributes, which help in specifying the space to be provided for the
various elements on the screen.
125
Dimensions, Formatting & Report Layouts
The following table shows the definitions and its supported attributes to be discussed in this
section.
Definition Attribute
Line Space Top, Space Bottom
Field Space Left, Space Right
Space Top, Space Bottom, Space Left and Space Right - Form/ Part Definition
Space Top, Space Bottom, Space Left and Space Right when specified in Form or a Part defi-
nition leave the appropriate spaces before displaying/printing a Form. These spaces are
included in the Height/ Width of the Form definition.
Space Top and Space Bottom - Line Definition
Space Top and Space Bottom when specified in a Line definition leave the appropriate spaces
before/ after the Line. These spaces are inclusive within the Height of the specific Part in
which the current Line definition resides. If the Height of the Part is unable to accommodate
the same, it compresses the line to fit it within the available Height.
Space Left and Space Right - Field Definition
Space Left and Space Right when specified in a Field definition leave the appropriate spaces
before/ after the Field. These spaces are inclusive within the Width of the Part and Field. If the
Width of the Part is unable to accommodate the same, it compresses the Fields within the Parts
and Lines to fit it within the available Width.
Indent
Indent can be specified in either a Line or a Field definition. It is similar to the Tab Key,
which is used to specify a starting point for a Line or a Field.
126
Dimensions, Formatting & Report Layouts
Syntax
Indent: <Measurement Formula>
Example:
[Line: Indent Line]
Fields : Indent Field1, Indent Field2
127
Dimensions, Formatting & Report Layouts
Exercise 5.2
Objective
The objective of this TDL is to understand the applicability of Sizing ad Spacing attributes.
Capabilities Used
The Line attributes Space Bottom, Space Top and Right Fields
The Part attribute Lines
The Field attributes Space Left, Space Right and Indent
Code
[Report: Exer SizingSpacing Attributes]
Form : Exer SizingSpacing Attributes
Title: "Sizing and Spacing Attributes"
128
Dimensions, Formatting & Report Layouts
129
Dimensions, Formatting & Report Layouts
Program Explanation
The report shows the usage and implication of sizing and spacing attributes. The Line 'Exer
SS Line1' is displayed after 25 mms of Space from the Top. After this Line 70 Mms of Space
is left from the Bottom by using the attribute Space Bottom before displaying the next Line or
part.
The Field Exer SSField1 is displayed after leaving 50 mms of space from the left. From the
program it is understood the width of this field is 80mms and this includes both space left
value and actual width of the field ie., 50mms is used for space Left and the balance 30mms is
assigned as actual field width.
The Field Exer SSField2 is displayed after leaving 10mms from the left ie., the field is
indented by 10mms.
The Field Exer SSField3 is displayed after leaving 25mms of space from the right by using
Space Right attribute and the width of this field is includes this 25mms also.
The attribute Background is used to give different background colors for the fields, Exer
SSField1, Exer SSField2 and Exer SSField3. Similarly Border attribute is used to border for
each fields.
5.3.3 Alignment Attributes
This category includes all attributes, which help in specifying the alignment of various
elements on the screen.
Example:
[Form: Top and Bottom Parts]
Top Parts : TBTopPart
Bottom Parts: TBBottomPart
130
Dimensions, Formatting & Report Layouts
[Part: TBTopPart]
;; Only for Part Definition
Left Parts : TB Left Part
Right Parts : TB Right Part
The following table shows the definitions and its supported attributes to be discussed in this
section.
Definition Attribute
Form Top Parts, Bottom Parts
Part Top Parts, Bottom Parts, Left Parts, Right Parts
The Bottom Parts/ Bottom Lines start printing from bottom to the top of the Form. If Height is
specified at the Form Definition, then the Bottom Parts/ Lines start printing from the bottom-
most line within the specified Height.
Exercise 5.3
Consider the following code Snippet. The objective is to understand the Top and Bottom
attributes at Form. Top and Bottom parts render the parts at the Top and Bottom respectively
within the available Form Height
[Form: Exer Top and Bottom Parts Form]
;; Top Parts are rendered at the Top of the Form after excluding the Space to leave at Top
Top Parts : Form SubTitle, Exer TB PF Top
;; Bottom Parts are rendered at the Bottom of the Form based on the available Form Height after excluding the Space to leave at
Bottom
Bottom Parts: Exer TB PF Bottom
Local: Field: Form SubTitle: Info: "Understanding Top and Bottom+
Part Attributes - Form"
/* The following are Form Dimensions i.e., Height, Width of the Form and Space Top and Bottom to be left. Space Top and
Bottom are also included within the Height and Width of the Form.*/
Height : 50% Page
Width : 50% Page
Space Top : 0.25 inch
131
Dimensions, Formatting & Report Layouts
The above output demonstrates the usage of Top parts and Bottom parts under Form defini-
tion. The Top Part Exer TB PF Top is given at the Top of the Form after excluding the Space
to leave at Top. Bottom Parts Exer TB PF Bottom are displayed at the Bottom of the Form
based on the available Form Height after excluding the Space to leave at Bottom.
For the entire TDL code of the given example, please refer Exercises 5.3
Top Parts, Bottom Parts, Left Parts and Right Parts – Part Definition
In cases where the Left Part or Right Part is specified within a Part Definition, it occupies the
left section or right section of the Part respectively keeping Space Left and Space Right of the
Part in account. Space Right impacts the Right Parts by moving it from right in order to leave
appropriate spaces. Similarly, Space Left impacts the Left Parts by moving it from Left in
order to leave appropriate spaces.
If the intent is to have multiple parts printed horizontally, then the Part attribute Vertical should
be set to No. If Vertical Attribute is set to Yes, then all the parts within this part will be printed
vertically. In such circumstances, the Left Parts will position at the Top of the Screen/ Page
and Right Parts will position at the Bottom of the Screen/ Page.
Incases where the Top Part or Bottom Part is specified within a Part definition, it occupies the
top section or bottom section of the Part respectively keeping Space Top and Space Bottom of
the Part in account. Space Bottom impacts the Bottom Parts by moving it from bottom in
order to leave appropriate spaces. Similarly, Space Top impacts the Top Parts by moving it
from Top in order to leave appropriate spaces.
If the intent is to have multiple parts printed vertically, then the Part attribute Vertical should
be set to Yes. If Vertical attribute is set to No, then all the parts within this part will be printed
132
Dimensions, Formatting & Report Layouts
horizontally. In such circumstances, the Top Parts will position at the Left of the Screen/ Page
and Bottom Parts will position at the Right of the Screen/ Page.
Exercise 5.4
[Part: Exer Parts Part]
/* Parts can be rendered either vertically or horizontally. In this case, Parts are rendered horizontally as the Part Attribute 'Ver-
tical' is not enabled/*
Parts : Exer Parts PartL
Right Parts : Exer Parts PartR
Height : 50% Page
Border : Thin Top Bottom
Program Explanation
In the above output, the attribute Top Part displays the top part of a part and the attribute Right
part shows the Right Part of a part. Ie., Exer Parts Part has further two more parts as one
Left part and one Right part called Exer Parts PartL and Exer Parts PartR. The Left part
Exer Parts PartL divided into two parts called the top part Exer Parts PartLT and the
133
Dimensions, Formatting & Report Layouts
bottom part Exer Parts PartLB and the attribute vertical is used set the parts vertically, ie.,
one below another.
For the entire TDL code of the given example, please refer Exercises 5.4
Both Parts and Lines are not allowed within a Part. They are mutually
exclusive entities. Either Parts or Lines can be used.
Exercise 5.5
Consider the following example to demonstrate the attribute Top Lines and Bottom Lines.
134
Dimensions, Formatting & Report Layouts
For the entire TDL code for the above snippet, please refer Exercises 5.5
Top Lines/ Lines – Line Definition
The attribute Top Line/Line is used in a Line definition to define another line inside one.
These attributes are also useful if more than one line needs to be repeated over a collection.
Part attributes, Repeat and Collection are advanced topics and will be
discussed later in the section, Objects, Methods and Collections.
135
Dimensions, Formatting & Report Layouts
Syntax
Lines : <Numerical Value>
Where,
<Numerical Value> is any number
Example:
Lines : 2
Exercise 5.6
Consider the following example to demonstrate the usage of lines attribute under field defini-
tion
[Field: Exer LWF]
Set as : "By default, the Lines is set as 1 in the Default Field,
we can override the same to set another number. If any other
number is set, the contents can be split into the fixed number of
lines specified. But if 0 is set, it can be split to as many lines
as required and available within the current Part. If Lines is
specified as 0, Width is mandatory."
Background: Green
/* By default, the Lines is set as 1 in the Default Field, we can override the same to set another number. If any other number is set,
the contents can be split into the fixed number of lines specified. But if 0 is set, it can be split to as many lines as required and
available within the current Part. If Lines is specified as 0, Width is mandatory.*/
Lines : 0
ToolTip : "Lines is set to 0 (Zero) in this Field"
Width : 50% Page
136
Dimensions, Formatting & Report Layouts
For the entire TDL code of above snippet, please refer Exercises 5.6
Left Field and Right Field
Attribute Left Fields can be specified in both Line and Field definition whereas attribute Right
Fields can only be specified in a Line Definition.
Syntax
Left Fields : <Field1, Field2, ….>
Right Fields : <Field1, Field2, ….>
Example:
Left Fields : Medium Prompt, Chg SVDate, Chg VchDate
Right Fields: Trader TypeofPurchase, Trader QtyUtilisedTotal
Definition Attribute
Line Left Fields, Right Fields
Field Left Fields/Fields
137
Dimensions, Formatting & Report Layouts
Exercise 5.7
Consider the following code snippet to understand the usage of Left and Right Fields.
The Right field values move the fields and start rendering the same from the extreme right.
For the entire TDL code for the above snippet, please refer Exercises 5.7
Align
The attribute Align aligns the contents of a Field as specified. The permissible values to this
attribute are Left, Center, Right, Justified and Prompt.
Syntax
Align : <String Value>
Example:
Align : Right
138
Dimensions, Formatting & Report Layouts
139
Dimensions, Formatting & Report Layouts
displayed clearly and can be scrolled both, across the Fields Horizontally as well as Lines Ver-
tically.
Difference between Scroll: Vertical and Scroll: Flow is as follows:
Scroll : Vertical Scroll : Flow
When there are two vertical sub-parts In similar scenario, if we apply
inside a main part with “Scroll : Vertical” “Scroll : Flow” at the main part, and
applied at the sub-part level and both the “Scroll : Vertical” at the sub part, it
sub parts are repeated over different set of completes the first sub-part
information which may run into multiple (whether single or multiple pages)
pages, it starts printing both the sub parts then starts printing the subsequent
from the first page itself (partially) and it sub-part
continues the remaining part in the next
page.
Again, if we apply “Scroll: Vertical” at However if the sub-part is further
the main part itself, then it prints the sub divided into two or more horizontal
parts one after another. sub-parts, it prints all the sub-parts
vertically ONLY. This happens
because once a Part is defined with
“Scroll: Vertical”, all the sub-parts
and child parts will be treated as
Vertical Parts. Where as if we apply
“Scroll: Flow” at the main part, we
can have a combination of vertical
and horizontal sub parts.
Exercise 5.8
Objective
The objective of this program is to understand the applicability of various alignment attributes.
Capabilities used
Form attributes Space Top, Space Bottom, Space Left, Space Right
Form attribute Height, Width
Part attributes Lines, Bottom Lines, Border and Vertical
Line attributes Fields, Right Fields
140
Dimensions, Formatting & Report Layouts
Code
[Report: Exer Alignment Attributes]
Form : Exer Alignment Attributes
Title : "Alignment Attributes"
[Form: Exer Alignment Attributes]
141
Dimensions, Formatting & Report Layouts
142
Dimensions, Formatting & Report Layouts
143
Dimensions, Formatting & Report Layouts
Output
Program Explanation
The report is displayed by using various alignment attributes. The Form Exer Alignment
Attributes is displayed 100% Screen by using the form attributes Height and width. The four
sides of form are left with 5% screen space by using the space attributes like Space Left, Space
Right, Space Top and Space Bottom.
The part Exer Alignment Attributes contains two parts Exer Alignment Attributes TPart
and Exer Alignment Attributes BPart. The top part is rendered at the top of the main part
and the bottom part is rendered at the bottom. Similarly, these two parts includes three
different lines ie., two top lines and one bottom line. This bottom line Exer AAP BLine1
displayed at the bottom of the part Exer Alignment Attributes TPart.
The Line Exer AAP TLine1 contains two fields called Exer AAP LField and Exer AAP
RField. The Right field Exer AAP RField start displaying from the right of the line Exer
AAP TLine1.
The attribute Background is used to give background color to the two parts Exer Alignment
Attributes TPart and Exer Alignment Attributes BPart.
144
Dimensions, Formatting & Report Layouts
Invisible
The attribute Invisible can be specified in Part, Line or Field definition. Based on the logical
condition, this attribute decides whether the contents of the definition should be displayed or
not. When this attribute is set to Yes, it does not display the contents but the contents are
retained for further processing. In this case, contrary to Inactive, the size of the entire field is
reduced to null but the value is retained.
Syntax
Invisible: Logical Formula
In the above example, this field Attr Invisible does not display the string Invisible Attribute
because the value of the attribute is Yes. If the value of the attribute is No then it displays the
string.
145
Dimensions, Formatting & Report Layouts
Exercise 5.9
Consider the following the code snippet:
[Line: Exer IAI Details]
Fields : Medium Prompt, Simple Field
RightFields : Name Field
Local : Field : Medium Prompt: Set as: "Company Address"
Local : Field : Medium Prompt: Style: Normal Bold
;; Here, the prompt is made Inactive beyond first line, as a result of which the space will be retained without the Field contents
Local : Field : Medium Prompt: Inactive: $$Line > 1
;; Function Line returns the current Line Number in a repeated Environment
Local : Field : Simple Field: Set as: $Address
Local : Field : Simple Field: FullWidth: Yes
/* Value of Field 'Medium Prompt' is set to the Field 'Name Field'. Second Line onwards, the value of the Field 'Medium Prompt'
will be empty due to Field Attribute 'Inactive'. With Field Attribute 'Invisible', the contents of the Field 'Medium Prompt' will be
available as seen in the Part 'Exer IAI Part Invisible'*/
Local : Field : Name Field: Set as: #MediumPrompt
Local : Field : Name Field: Background: Green
Local : Field : Name Field: Style: Normal Italic
Local : Field : Name Field: Width: @@MediumWidth
146
Dimensions, Formatting & Report Layouts
Output
The above report demonstrates the usage of Inactive and Invisible attributes. Inside the line
Exer IAI Details, the field medium prompt set the value as “Company Address” and further
the field is made Inactive, if $$Line>1then from second line onwards space for the field will
be retained without the field content. Here the field medium prompt is displayed in green
background.
Similarly, in the Part Exer IAI Part Invisible, the field Medium Prompt made Invisible, the
contents of the field Medium prompt is available and displayed, but it did not occupy any
width, ie., Here the field medium prompt is displayed in Yellow background. Function $$Line
returns the current line number.
For the entire TDL code for the above snippet, please refer Exercises 5.9.
Fixed
The attribute Fixed can be specified in Part, Line and Field. In part definition when the
attribute Fixed is set to yes, it forces the cursor to skip the Part. In the alteration screen it
allows the TDL programmer to skip a part of a Form which is not meant to be altered. In Line
definition it skips the line such that the cursor will not positioned on it. The attribute Fixed
when used in a field definition does not allow the user to change the value of the field.
Syntax
Fixed : < Logical Value >
Example:
Fixed: Yes
Widespaced
This attribute is used in Field definition which allows increased spacing between the charac-
ters of the string value specified in the field. This attribute is used to create titles for the report
/ columns.
147
Dimensions, Formatting & Report Layouts
Syntax
Widespaced: Logical Value
Example:
Widespaced: Yes
Preprinted
This attribute can be used in Part, Line or a Field definition. When this attribute is set to Yes,
the contents of the current definition will not be printed assuming that they have been pre-
printed. Ideally, Preprinted is used where static texts are assumed to be preprinted like Invoice
printing, where Company Name, Address, static declaration, etc. are preprinted.
Syntax
Preprinted: Logical Value
Example:
Preprinted: Yes
SubTitle
This attribute can be used in Field definition as well as Collection definition. In the Field def-
inition, if the value of SubTitle is set to Yes, the current field will be considered as a subtitle
and the border will not be extended to the current field.
For example, in a Trial Balance Report where Column headings are displayed, first line dis-
playing Closing Balance and the second line displays two fields consisting of Debit and Credit
fields below the Closing Balance. Now the Common Border at the Part definition will extend
the Border between the Debit and Credit to the Closing Balance Line too. This will be
prevented by saying SubTitle : Yes in the Closing Balance Field.
Syntax
SubTitle: Logical Value
Example:
[Field : SubTitle Field]
SubTitle: Yes
In Collection definition, this attribute gives the Subtitles for each column in the table.
Syntax
SubTitle: List of Column Titles
where,
<List of Column Titles> specifies the Title for the columns
148
Dimensions, Formatting & Report Layouts
149
Dimensions, Formatting & Report Layouts
Color / Shade
Color or Shade attribute of Border definition is useful to specify the color required for the
border while in display mode. Border attribute Color requires two values to be specified, viz.,
one which is used in case of a Black and White Monitor and second in case of a color monitor.
Example:
[Border: Top Bottom Colored]
Top : Thin
Bottom : Thin
Color : "Deep Grey, LeafGreen"
[Field: Total Field]
Set As : $Total
Border : Top Bottom Colored
PrintFG
PrintFG attribute of Border definition is useful to specify the color required for the border
during printing.
Example:
Style
Style definition determines the appearance of the text being displayed/printed by using a cor-
responding font scheme, Bold, Italic, Point Size, Font Name, etc. This definition Style can be
used in the Field definition only.
Style attribute in Field definition is used to format the appearance of the text appearing within
the Field both in display and print mode provided the Print Style attribute is not used within
150
Dimensions, Formatting & Report Layouts
the current Field. Print Style attribute in Field is used if the Style specified while displaying is
different from the Style required while printing.
Syntax
[Style: <Style Name>]
Font : <Font Name>
Height : <required Font Height in Point Size>
Bold : <Logical Formula>
Italic : <Logical Formula>
Where,
<Style name> is the name of the style definition
<Font Name> is the name of the Name of the Font
Font
This is the generic name of the Font supported by the Operating System. Font is system
dependent and we do not have any control over them. However, one can select the required
fonts from among the available fonts.
Example:
[Style: Normal]
Font : If $$IsWindows then "Arial" else "Helvetica"
Height : @@NormalSize
151
Dimensions, Formatting & Report Layouts
Height
Height attribute within the Style definition should be specified without any measurement spec-
ification as it is always measured in terms of Points. The value for the attribute Height can
have fractions and can be denoted by a formula which returns a number.
One can also grow or shrink the Height by a multiplication factor or percentage.
Example:
[Style: Normal Large]
Use : Normal
Height : 25%
Bold
The attribute Bold can take only logical value/ formula. In other words, it can take either Yes
or No. This signifies that the Field using this Style should be printed in Bold.
Example:
[Style: Normal Bold Large]
Use : Normal Large
Bold : Yes
Italic
The attribute Italic can take only logical value/ formula. In other words, it can take either Yes
or No. This signifies that the Field using this Style should be printed in Italics.
Example:
[Style: Normal Large Italics]
Use : Normal Large
Italic : Yes
Color
The definition Color is useful to determine the foreground and background color for a Form,
Part, Field or Border both in Display as well as in Print Mode,
Color specification can be done by the following ways:
By specifying the RGB Values (the combination of Red, Green and Blue - each value
should range from 0 to 255)
By specifying the particular shade or color
152
Dimensions, Formatting & Report Layouts
Syntax
[Color: <Color Name>]
Shade/Color : <Hue>, <Saturation>, <Brightness>
RGB : <Red>, <Green>, <Blue>
While defining a color, only one type should be used i.e. either Shade or RGB.
It does not make sense to use both, since the attribute given at the end will
override the attribute prior to that one.
Shade / Color
One of the ways in which color specification can be done is by using the HSB Standard. HSB
stands for Hue, Saturation, and Brightness. One can create different shades and colors by
varying the percentages of HSB.
This ranges from 0 to 100% and indicates the percentage of the color replaced by white. For
example, 50% means that 50% of the color is white, and 50% the original shade, while 100%
means, that 100% of the color is white, and 0% the original shade – effectively that the shade
value is white, and 0% the original shade – effectively that the shade value is meaningless.
Another viewpoint is to think of the quantum of white as the DECREASE in the PURENESS
of the color (or decrease in the saturation of the color).
Example:
The RGB value equivalent of red color can be specified in HSB standard as follows:
[Color: Red]
Shade : 0%, 100%, 100%
HSB standard for black color
[Color: Black]
Shade : 0%, 0%, 0%
HSB standard for white color
[Color: White]
Shade : 0%, 0%, 100%
153
Dimensions, Formatting & Report Layouts
RGB
This is the second way of specifying the color. One can specify the RGB value from a palette
of 256 colors to obtain the required color. i.e., the values Red, Green & Blue each can range
from 0 to 255. This gives the user an option to select from 24 bit Color.
Example:
[Color: Pale Leaf Green]
RGB : 169, 211, 211
SysColor
The attribute Syscolor is used to specify the default system colors.
Syntax
Syscolor : < Default system Color>
Default System Color is to specify the default system color
Exercise 5.10
Objective
The objective of the following program to demonstrate the usage of Definition and Attribute
'Border' and 'Style'.
Capabilities Used
Usage of border and style definition
Background Attribute at Form and Field Definition
Style attributes Font, Height and bold
Color attribute at Field definition
154
Dimensions, Formatting & Report Layouts
Code
[Report: Exer Border and Style]
Form : Exer Border and Style
155
Dimensions, Formatting & Report Layouts
Output
Program Explanation
The report is displayed by using Style and Border definition. The style Exer Style defines one
different style for this TDL and it defines the Font, Height and Bold for the text. Similarly, the
border Exer Border defines a new border by using the attributes Top, Bottom, Left, Right and
color attributes.
The field Exer Border and Style is displayed by using the defined border and style. The
attributes Style and Border helped to apply these style and border to this field Exer Border and
Style.
The attribute Color at field Exer Border and Style is used to give g color to the displayed text
and border.
5.4.2 Color, Background, PrintFG and PrintBG Attribute
Color
Color attribute is used to specify the color for the Field and Border.
Background
Background attribute is used to set the background Color of a Form, Part or a Field in display
mode.
PrintFG
PrintFG attribute is to set the foreground color for the field in print mode. At the border defi-
nition this attribute is used give the color to the border in print mode.
PrintBG
Print BG attribute is used to set Background Color of a Form, Part or a Field in print mode.
Syntax
[Form: <Form Name>]
Background : <Color Name Formula>
Print BG : <Color Name Formula>
156
Dimensions, Formatting & Report Layouts
157
Dimensions, Formatting & Report Layouts
The value for Format attribute varies based on the data type of the Field.
Field of Type Number
Example:
[Field: My Rate of Excise]
Set As : $BasicRateOfInvoiceTax
Format : “No Comma, Percentage”
In the above example, the attribute Format will display the contents of the table in the
specified width i.e. 30 in this case, If the width of the table is not sufficient for the name to be
displayed, then the contents will be compressed to fit the width.
158
Dimensions, Formatting & Report Layouts
When the collection is a union of collections, the format object in this collection behaves as a
placeholder for the columns. It is mandatory to specify Format attribute in individual collec-
tion when a collection is union of collections.
Example:
[Collection: LedTable]
Collection: DebtorsLedTable, CreditorsLedTable
Format : A, 20
Format : B, 25
In the above example, A and B act as dummy identifiers and the second parameter is width.
In a typical Tabular Report, the number of columns is fixed and is interactive i.e. an end user
can change the appearance of the Report. The Day Book, Stock Summary, Trial Balance,
Group Summary, Ledger Vouchers are the some of the default Tabular Reports in Tally.ERP 9.
159
Dimensions, Formatting & Report Layouts
A typical Tabular Report will have a Title Line, Details Line and an optional Total Line. The
Details Line will be repeated over the objects of a Collection.
A Tabular Report can be made Interactive by adding the following features.
Adding Buttons to change the period, to change the contents of the Report, etc..
Adding explosions to the lines
160
Dimensions, Formatting & Report Layouts
Automatic Auto-Column Reports – Automatic auto column reports are used when
the columns are required automatically without the intervention of the user when the
report is opened.
Columnar Reports – The reports which are displayed in columns are called columnar
reports
161
Dimensions, Formatting & Report Layouts
162
Chapter 6: Objects, Collections and
Internal Object Structure
6.1 Introduction
As we know TDL is a completely Object Oriented Language. Whether it is creating an
Interface or storing some information in the Tally Database, the fundamental artifact is an
Object. All the Interface and Data storing elements are Objects.
This chapter will give a detailed conceptual understanding of Objects & Collections and the
Collection Capabilities in terms of fundamental Data gathering and processing element of
TDL.
Let us begin our discussion by understanding the concept of an Object in general. As we
progress we will take you through the Object Structure and Type of Objects available in TDL.
Then, the focus completely moves on to Collections, its construction, sources and capabilities.
163
Objects, Collections & Internal Object Structure
Hence, in order to store and to manipulate these information, we need some procedures. These
procedures are termed as Methods which operate on data. Data and Methods combined
together are referred as an OBJECT. Objects are persisted/stored in the Database. There can be
relationship established between various Objects which can be maintained and defined as per
the Database Structure adopted.
Tally follows a hierarchical Data Structure. We will discuss the hierarchical Data Structure in
detail under the subsequent section “Tally Object Structure”.
164
Objects, Collections & Internal Object Structure
Whether it is an Interface that is to be created or a Data that needs to be persisted into the Tally
DataBase, the object follows a hierarchical structure.
In order to construct a Report, we can have a form which may contain multiple parts, each part
subsequently can contain multiple lines which in turn is made up of fields. Based on the con-
tainership a complete hierarchy of Interface Objects is created.
Similarly, all the data which is persisted into the Tally Database has a predefined hierarchy.
Any manipulations to the existing data needs to strictly adhere to the hierarchy.
Let us understand the Database Object Structure with an example of Ledger object
165
Objects, Collections & Internal Object Structure
In the above figure Ledger is the Base/Primary object. This object has methods Name, Parent ,
Opening Balance and a Collection of Secondary Object Ledger Bill Allocations which can
further contain multiple opening bills. Each Bill Allocation Object further has Methods,
Name, Bill Date, Bill Due Date, and Bill Amount. These Bill Allocation Sub Objects are col-
lectively referred to as Bill Allocations collection.
166
Objects, Collections & Internal Object Structure
Interface Objects
Objects that are used for rendering the User Interface are Interface objects. Report, Form, Part,
Line, Field, Menu, Table and Button are Interface objects. Interface objects like Report and
Menu are independent items and can exist on their own. The objects Form, Part, Line, Table
and Field comes to existence only when they are contained by their parent in the Interface
Object hierarchy chain.
Data Objects
A data object is a region of storage that contains a value or group of values. Each value can be
accessed using its identifier i.e., Method or a more complex expression that refers to the sub
objects.
167
Objects, Collections & Internal Object Structure
Every Interface Object is associated with a Data Object to perform various operations like
adding, retrieving or altering information stored in the Data Objects. These Data Objects can
either be Internal Objects or External Objects.
Internal Objects
Internal Objects are objects provided by the platform These data objects which are stored as a
part of Tally Database can be manipulated by Tally user i.e., Data can be added, deleted or
updated from within Tally. There are several Internal Objects like Company, Group, Ledger,
Stock Group, Stock item, Unit of measure, Voucher Type, Cost Category, Cost Centre, Budget
and so on.
TDL/External Objects
Objects which cannot be stored as a part of Tally Database are classified as External Objects
and are used for some intermediate data manipulations and temporary storages. These objects
are further categorized as
Static Objects
Dynamic Objects
Static Objects are objects hard coded in the TDL code and can be used for some specific
purposes like accepting Inputs from the user during Auto Column Reports, displaying in a
Report etc. These objects can neither be added nor be altered by the Tally user.
Dynamic Objects are temporary Objects created in memory for performing various manipula-
tions. The associated values for these objects can change during the execution of Tally. The
source of these objects can be from a variety of Data Sources like ODBC, XML, DLL and so
on.
6.3 Collections
The fundamental Data gathering and processing element of TDL is the Collection definition.
The bulk of aggregation, chaining and integration capabilities are delivered using Collections.
A collection is a group of Objects/Collections. The source of Objects in the collection can be
either an Internal/TDL Object. Each Object in the Collection follows a hierarchical structure
i.e., it can further contain sub collections within itself.
A collection is created using the Collection definition.
168
Objects, Collections & Internal Object Structure
Syntax
[Collection : <Collection Name>]
Where, <Collection Name> is the identifier assigned to the desired Collection of Objects.
Example:
[Collection : NewTDLCollection]
6.3.1 Simple and Compound Collection
As we have already seen, a collection is a group of multiple Objects/Collections, where each
Object can contain multiple methods and subcollections.
Based on the type of Collections available in TDL, its usage in Default TDL/Source Code and
constituents we can classify them as
Simple Collections
Compound Collections
Simple Collection has multiple Objects which contain a single method and contains zero sub-
collections. Default TDL Collections, Name and Address are examples of Simple collection.
Compound Collection has multiple objects containing multiple methods and sub-collections.
Ledger and Stock Item are examples of compound collection.
169
Objects, Collections & Internal Object Structure
If both Object Type and Parent Types are specified and if current object context
does not belong to the Parent Type, then Attribute Child Of is mandatory which
acts as an identifier to the Parent Type.
Primary Objects
Collection gathered using primary objects directly.
Example:
[Collection : LedgerList]
Type : Ledger
The above code snippet indicates Collection, Ledger list consists of Ledger objects
Sub Objects
Collection gathered using sub collection/secondary collection.
Example:
[Collection : Ledger Vouchers]
Type : Vouchers: Ledger
Child Of : ##LedgerName
Where Variable LedgerName contains the LedgerName selected by the user thereby
gathering all the vouchers of the selected ledger.
170
Objects, Collections & Internal Object Structure
Capabilities Used
Attribute Type utilized at Collection definition to specify Internal Object type
Attribute Repeat used at Part definition for repeating line on a collection
Attribute Scroll along with Repeat attribute to allow the data to flow off the screen.
This would enable vertical scrolling.
Attribute modifier Local has been used for changing field attribute values for a line.
Code
[Report: Exer Coll of Internal Objects]
Form : Exer Coll of Internal Objects
Title: "Collection of Internal Objects"
171
Objects, Collections & Internal Object Structure
172
Objects, Collections & Internal Object Structure
Output
The report displays all the Ledger Objects of the collection line after line. The line Exer CIO
Title displayed at the top is for showing title for each column.
The line Exer CIO Details is repeated on the Collection Exer Coll of IO Ledgers. This col-
lection holds Ledger Objects. The instance of line Exer CIO Details will be generated based
on number of objects being populated in the Collection.
For Line Exer CIO Title we have used Line Exer CIO Details, so that title line inherits
attributes of detailed line. At title line we are localizing every field and providing the value to
be displayed by making use of attribute Set As. However it would become very difficult for
the developer, incase for all fields we require to change attribute values. Hence we have made
use of keyword ‘Default’ alongwith Local attribute modifier.
In the fields Exer CIO LedName, Exer CIO GrpName and Exer CIO OpenBal, Set as
attribute has been used and methods $Name, $Parent and $OpeningBalance of Object Ledger
has been used as value for display.
173
Objects, Collections & Internal Object Structure
174
Objects, Collections & Internal Object Structure
choice. Symbol Prefix $ is used to extract value from the Method CourseName and 30
indicates the Width to be used for displaying the coursename.
Each Object used in the Collection definition must be defined as shown below:
[Object : Course1]
CourseName: “BCom”
Duration : “3 Years”
[Object : Course2]
CourseName: “Bsc”
Duration : “3 Years”
[Object : Course1]
CourseName: “BBM”
Duration : “4 Years”
CourseName and Duration are user specified methods and values to the right of the colon are
the corresponding method values.
When the above list is displayed for user selection and user selects any course, the correspond-
ing value for Duration can be extracted and displayed to the user.
Example of External Objects
Let us learn to populate External or Hard coded Objects
Exercise 6.2:
Objective
The objective of this program is to render the list of Students, their fees and Date of joining
which are defined as external objects.
Capabilities Used
Attribute Objects is utilized at Collection definition to specify the external objects
required.
Object definition has been used to specify the methods and its values for the exter-
nal objects.
Attribute Repeat used at Part definition for repeating line on a collection.
Attribute Scroll along with Repeat attribute to allow the data to flow off the screen.
This would enable vertical scrolling.
175
Objects, Collections & Internal Object Structure
Code
[Report: Exer Coll of External Objects]
Form : Exer Coll of External Objects
Title : "Collection of External Objects"
176
Objects, Collections & Internal Object Structure
Width : 10
Border : Thin Right
177
Objects, Collections & Internal Object Structure
Output
The report displays all the External Objects of the collection line after line. The line Exer
CEO Title displayed at the top is for showing title for each column.
178
Objects, Collections & Internal Object Structure
The line Exer CEO Details is repeated on the Collection Exer Coll of EO Students. As we
require external objects, we have made use of Object attribute at collection definition Exer
Coll of EO Students and provided comma listed object definition names.
For Line Exer CEO Title we have used Line Exer CEO Details, so that title line inherits
attributes of detailed line. At title line we are localizing every field and providing the value to
be displayed by making use of attribute ‘Set as’. However it would become very difficult for
the developer, in case for all fields we require to change attribute values. Hence we have made
use of keyword ‘Default’ alongwith Local attribute modifier
In an Object definition the first left most string before ‘:’ are the method names i.e., Name,,
Fee Paid & Joining Date for External Objects and the values on the right of the separator are
the method values.
6.3.3 Dynamic Objects
Dynamic Objects are created dynamically from external sources like HTTP XML, DLL,
ODBC, XML File etc. from selected Objects in a Report, Variables and using information per-
taining to a disk Directory. Object manipulations like Addition, Deletion, etc. can be
performed with these Objects by the Tally user. These values change during the execution of
the program. The various attributes used for populating a collection using Dynamic Objects
discussed as below
Using an In Memory Object
A collection can be populated using the attribute New Object which is using an object type
specification as defined by the programmer. This is a very useful capability from the point of
view of In Memory Object manipulations required specifically in editing(alter/create) mode.
The new attribute will independently govern the type of object to be added to the collection
on-the-fly. The following is now supported in collection
Syntax
NEW OBJECT: Type-of-Object: Condition
Where, <Type of Object> is the Object Specification as defined by the Object Definition
<Condition> Object will be populated as per the condition specified
Example:
This collection can be used in a Report opened in Edit Mode (Create/Alter).
[Collection: Coll Customer]
New Object : Customer Data
;; New TDL Object Defined
179
Objects, Collections & Internal Object Structure
;; Compound Collection
Collection : PhoneColl : Phone
Collection : AddressColl : Address
[Object: Phone]
Storage : OfficeNo : String
Storage : HomeNo : String
Storage : Mobile : String
[Object: Address]
Storage : AddrLine1 : String
Storage : AddrLine2 : String
The attributes given below are provided specifically for using the source as
HTTP XML. The generic attribute Data Source can also be used for the same
which is discussed subsequently.
Syntax
[Collection: <Collection Name>]
RemoteURL : <HTTP/HTTPS URL Address>
RemoteRequest : <Request-Report-Name>, +
<Pre-Request-Edit-Report> :<Encoding Type>
XMLObjectPath : <Start-node> : <Path-to-start-node>
180
Objects, Collections & Internal Object Structure
XMLObject : <TDL-Object-Name>
Where, Remote URL attribute is used to specify the URL of the HTTP/HTTPS Server deliv-
ering the XML data.
RemoteRequest attribute is used to specify the Report name which is to be sent to the HTTP/
HTTPS Server as an XML Request, if the report requires user inputs, then it has to be accepted
before the request is sent. Pre-request edit report specifies the name of the report which
accepts the user input.
XMLObjectPath attribute must contain the path to walk in the response XML which will be
gathered as Collection Objects and is converted to TDL Objects. By default, root node is
assumed to be the Object Path.
<Start-Node> allows you to specify the name and position of the XML node from which the
data should be extracted. It takes two parameters as follows:
<Node Name> : <Position>
<Path-to-Start-Node> is used to specify the path to reach the <start node> from the root
node.
The path specification is :
<Root-node> : <Child Node> : <Start Pos> : <Child Node>: <Start Pos> …
XMLObject attribute is used to specify the TDL Object specifications with their respective
Data Types .
181
Objects, Collections & Internal Object Structure
SQLObject Attribute is used to specify the corresponding TDL Object specifications with
their respective Data Types.
For the detailed usage and examples refer the document“Tally.ERP 9 – Inte-
gration Capabilities” available in the CD. Here we are focusing only on popu-
lating the collection.
182
Objects, Collections & Internal Object Structure
Example:
HTTP as data source
[Collection : My XML Coll]
Data Source : HTTP XML : “http:\\localhost\MyFile.xml”: ASCII
In the above code snippet the type is HTTP XML as the data source is obtained through
HTTP. The encoding of the file MyFile.XML is ASCII.
Example:2
[Collection: Selected Objects from Parent Report]
183
Objects, Collections & Internal Object Structure
Variable
Collection can be created using the variable elements as a the source. The type specification
in this case is Variable. Identity is the Variable Name
Example:
[Collection: LV List Collection]
Data Source: Variable: SLVEmp
The elements of the Simple List Variable SLVEmp will be available as objects in the collec-
tion LV List Collection.
Directory
The collection can be created using the information pertaining to the contents of the disk
directory/folder. The Type specification in this case is Directory. Identity is the Path of the
Directory
Example:
[Collection: ABC Contents]
Data Source: Directory: "C:\ABC"
6.4 Methods
Information is stored in an object, so that we can re-call the same whenever needed. This
information can be retrieved using methods i.e. storage name prefixed with ‘$’ symbol. Based
on general information required, many methods have been provided by the platform.
However, TDL provides a capability to the developer to create methods. We can classify the
methods as Internal & User Defined/External Methods.
184
Objects, Collections & Internal Object Structure
185
Objects, Collections & Internal Object Structure
Object. E.g. If a particular ledger ‚ABC‛ is being altered in a Report, the Report will
be associated to the ledger Data Object ‚ABC‛
Similarly if all the Data Objects of Ledger are displayed in Report, each line in the
Report will be associated with one specific Ledger Data Object
Each Interface object must exist in the context of a data object. In the absence of any explicit
data object association, Interface object will get associated with an Anonymous object which
is the parent of all data objects. The method value referred to at the Field level will always be
evaluated based on the Data Object associated to it. We will now discuss the various method-
ologies to associate Data Object with the Interface Objects.
Object Association Methodologies
There is an implicit Data Association at the various Interface Object levels based on the data
object context which gets inherited based on the hierarchy generated in Report construction or
subsequent Reports/Functions being called from parent Reports. However, TDL programmer
can explicitly associate Data Objects at various Interface object levels like Report, Part, Line
and Field. Based on the data object associated at interface object, method values will be
retrieved at Field definition
Report Level
A Report usually will be associated with a data object, which it inherits from the previous
Report. In case it is the parent Report and no explicit association exists it will be associated
with anonymous object
Report Attribute-Object
Explicit object association at the Report level is done using the “Object” attribute of the
Report. The attribute ‘Object’ takes the “Object Type” and an additional optional value
‘ObjectIdentifierFormula’. In case no Object Identifier is specified it takes the current Object
context available for association.
Syntax
Object: <ObjectType> [:<ObjectIdentifierFormula>]
Where, <ObjectType> is type of any Primary Object
<ObjectIdentifierFormula> is an optional value and is any formula which evaluates to
name of Primary Object.
Example:1
Associating Report object with the Current Voucher object
[Report : New Sales Format]
Object : Voucher
Example:2
Associating Report object with Ledger “Cash”
[Report : Ledger Details]
Object : Ledger : ##LedCash
186
Objects, Collections & Internal Object Structure
Exercise 6.3:
Objective
The objective of this program is to display Ledger ‘Cash’ alongwith its Group and Opening
Balance
Capabilities Used
Attribute 'Object' at report level alongwith its identifier to associate data object at
report level.
At Field Attribute 'Set As' methods $Name, $Parent and $OpeningBalance of Object
Ledger has been utilized.
Code
[Report: Exer Object Association at Report]
Form : Exer Object Association at Report
Title : "Object Association at Report"
/*Object 'Ledger' is associated at the Report with Identifier as 'Cash'. Hence, the subsequent UI definitions will inherit
this Object context as a result of which Methods Name, Parent and OpeningBalance at the Field renders the details about
the Object Ledger 'Cash'. */
Object : Ledger: "Cash"
187
Objects, Collections & Internal Object Structure
This report is displaying details of Cash Ledger Object. At report level we have specified
attribute Object and the second parameter Object Type as Ledger. Optionally we can also
specify Object Identifier after Object Type. Object Identifier can be any formula which
evaluates to the Object name. In current scenario we have specified ‘Cash’.
For current display three lines Exer OAR Name, Exer OAR Group and Exer OAR
OpenBal have been declared at Part Level. Each line is having two fields, one for displaying
label and another for the value.
Part Level
Part inherits its data object from the parent Report or Part by default. In order to explicitly
associate a different Object and override the default association the attribute ‘Object’ and
ObjectEx are used at the Part Level. Also, it is possible to Repeat a subpart over each object of
the Collections also
188
Objects, Collections & Internal Object Structure
Example:1
Associate the part over the ledger object
[Part : TSPL Ledger Object]
Parts : Object Associated Part
Repeat : Object Associated Part : Ledger
Scroll : Vertical
This can be very useful in reports such as Multi Account Single Page printing where more than
one ledger along with their vouchers are being printed in a single page. Within the Part for the
current Ledger, subsequent Parts and Lines with Voucher information for the current ledger
object can be printed.
Exercise 6.4:
Objective
The objective of this program is to render List of Ledgers alongwith their pending bills.
Capabilities Used
Attribute ‘Repeat’ has been used at part level to repeat sub part over a collection.
Attribute ‘Repeat’ has been used at sub part level to repeat line over a collection.
‘Scroll’ attribute has been used at both the parts to ensure the Text is not shrunk
Code
[Report: Exer Object Association at Part]
Form : Exer Object Association at Part
Title : "Object Association at Part"
189
Objects, Collections & Internal Object Structure
Scroll : Vertical
190
Objects, Collections & Internal Object Structure
Output
In this report Form Exer Object Association at Part has a part Exer Object Association at
Part. This part has a sub part Exer OAP Details which is being repeated on a collection Exer
List of Debtors.
Collection Exer List of Debtors is holding Ledger Objects. We have also made use of
attribute ‘Child of’ which would filter Ledger Objects for the specified Parent. In this case we
have made use of function ‘$$GroupSundryDebtors’ which looks for group name Sundry
Debtors in the Ledger Parent.
‘Child of ’locates ledgers that are directly available under Sundry Debtors. In
case you require ledgers under Sub Group also then you need to make use of
attribute ‘Belongs To’.
191
Objects, Collections & Internal Object Structure
The sub part Exer OAP Details has another part Exer OAP LedBills. The part Exer OAP
LedBills has line Bill Detail which is being repeated on a collection Exer Ledger Bills.
Collection Exer Ledger Bills has object of type Bill. Object Bill is dependent on Object
Ledger and cannot be on its own, hence mentioning of attribute Child of for this collection
and the attribute value as Ledger Name i.e. $Name.
Part Attribute – Object
Syntax
Object :<SupplierCollection>:<Index Formula>[:<SeekCondition>]
Where,
<SupplierCollection> This is the name of the Collection of Secondary Objects. Assuming
Primary Object is mentioned at Report Level
<IndexFormula> This can be First or Last keywords or an index number which denotes the
position index of the object. A negative sign denotes reverse search.
<SeekCondition > This is an optional value and is a filter condition to the supplier collection
Example:1
Report is in the Context of Voucher Object and at part level we are associating with first sub
object Inventory Entry without seek condition
[Part: Sample Part1]
Line : Sample Line
Object : InventoryEntries:First
Scroll : Vertical
Example:2
Report is in the Context of Voucher Object and at part level we are associating with Sub object
Ledger Entry with seek condition
[Part: Sample Part2]
Line : Sample Line
Object : LedgerEntries:(-1):@@IsParty
Scroll : Vertical
[System: Formula]
IsParty : $IsPartyLedger
192
Objects, Collections & Internal Object Structure
which was not possible with the Object attribute of Part Definition. Taking an example of
Party that we select in a voucher, we require its address from the corresponding Ledger master
Object.
Syntax
ObjectEx : <Method Formula Syntax>
ObjectEx : <Primary Object Specification>.+
[<Sub Object Specification>]
Where,
<Method Formula Syntax> is <Primary Object Specification>.[<Sub Object Specifica-
tion>]
<Primary Object Specification> is (<Object Type>,<Object Identifier Formula>). Since
the specification evaluates to an Object, it should end with a period i.e. (.)
<Sub Object Specification> is CollectionName[Index,<Condition>]. Since the specification
evaluates to an Object, it should end with a period i.e. (.)
i. While using the Method Formula Syntax with Object Ex ensure that it
evaluates to an Object.
ii. The Method Formula Syntax for “Accessing Methods” will be covered in
detail in the subsequent section
Example:1
Report is in the Context of Voucher Object and at Part level we are associating with Stock Item
Object without sub object specification
[Part: Sample Part3]
ObjectEx : (Stock Item, ##IName).
[Variable : IName]
Type : String
Default : “Item 1”
Make a close observation, the Part SamplePart 3 would now be in associated with the
stockitem and as this is a Primary Object Specification it ends with a period (.).
Example:2
Report is in the Context of Voucher Object and at part level we are associating with Ledger
Object with Sub Object Specification for Bill Allocation Collection
193
Objects, Collections & Internal Object Structure
Example:
The Part Sample Part 2 is in the association of Voucher Object
[Part : Sample Part 2]
Line : Sample Line 2
Repeat: Sample Line 2:Batch Allocations:Inventory Entries : First
Scroll : Vertical
194
Objects, Collections & Internal Object Structure
The line Sample Line 2 will be repeated on each object of Batch Allocations collection of
the first Object of the Inventory Entries collection
Repeat Attribute – Method Formula Syntax Support
The Method Formula syntax is also supported for the Collection specification in the Repeat
Attribute
Syntax
Repeat : <Line Name>: <Method Formula Syntax>
Where,
<Method Formula Syntax> is <Primary Object Specification>.[<Sub Object Specification>]
<Primary Object Specification> is (<Object Type>,<Object Identifier Formula>). This
evaluates to a Primary Object.
<Sub Object Specification> is CollectionName[Index,<Condition>]. If this specifies the col-
lection over which the line is to be repeated then the Index and Condition need not be specified
as it evaluates to a specific Object.
While using the Method Formula Syntax with Repeat ensure that it evaluates to
a Collection.
Example:3
The Part Sample Part 3 is associated with the Voucher object.
[Part : Sample Part 3]
Line : Sample Line 3
Repeat : Sample Line 3: (Ledger, “ABC”).BillAllocations
Scroll : Vertical
The line Sample Line 3 will be repeated over each object of the Bill Allocations collection for
the Ledger ABC.
Field Level
By default, Field inherits its object context from its parent UI Object. Field also allows Object
overriding using Field Attribute Object.
Syntax
Object: <ObjectType> [: <ObjectIdentifierFormula>]
Where,
<ObjectType> is type of any Primary Object
195
Objects, Collections & Internal Object Structure
196
Objects, Collections & Internal Object Structure
List of objects, collections and its methods have been provided in Tally.Devel-
oper 9 under Schema Browser. Please refer to the same.
197
Objects, Collections & Internal Object Structure
<Object Identifier Formula> would be a formula that uniquely identifies the Referred Object
Example:
Field is in context of Voucher Object and company’s email is required
[Field : Sample Field]
Set as :$Email:Company:##SVCurrentCompany
The above snippet would display email id of the current company
Example:
The current Object context in this case is the Voucher Object.
$LedgerName:LedgerEntries:First
This will retrieve the value of the Method LedgerName from the first sub object LedgerEn-
tries.
198
Objects, Collections & Internal Object Structure
Example:1
Assuming Voucher Object is the current object. Assuming the current Object Context is
Voucher.
[Field : Sample Field 1]
Set As : $LedgerEntries[1].LedgerName
This is used to retrieve the method LedgerName from the first LedgerEntries object of the
current voucher Object.
Example:2
Assuming the current Object Context is Voucher(Sales Invoice).
[Field : Sample Field 2]
Set As : $LedgerEntries[1,@LedgerCondition].Amount
LedgerCondition : $LedgerName = “Sales”
199
Objects, Collections & Internal Object Structure
This is used to retrieve the method Amount from the first LedgerEntries object with ledger
name Sales of the current voucher Object. Observe the usage of condition in the above syntax.
Example:
Assuming the current Object Context is Voucher(Sales Invoice).
[Field : Sample Field 3]
Set As : $LedgerEntries[1,@LedgerCondition].+
BillAllocations[1].Name
LedgerCondition: $LedgerName = “Acme Corp”
This is used to retrieve the method Name from the first Bill Allocations object with ledger
name Acme Corp of the current voucher Object. Observe the usage of condition in the above
syntax.
Example:4
In the example below the method is evaluated irrespective of the current Object ContexT. Here
the Primary Object specification is mandatory
[Field : Sample Field 4]
Set As : $(Ledger,@PartyLedger).BillAllocations[1].+
OpeningBalance
PartyLedger : “Acme Corp”
This is used to retrieve the method OpeningBalance of the first Bill for the Party Ledger Acme
Corp. Observe the Primary Object Specification for the Ledger Master Object in the above
syntax.
Example:5
Assuming that Batch Allocation is the current object context
[Field : Sample Field 1]
Set as : $...Date
In the Voucher Object hierarchy Batch Allocations is at the third level. Each dot denotes one
level. First dot signifies current object, second dot signifies Parent and third dot signifies
Grand Parent. In the example triple dot is used to reach to the Voucher Object level and
retrieve the method “Date” from there.
This can also be specified alternatively as
[Field : Sample Field 1]
Set as : $().Date
Where,
(). signifies Primary Object in the current internal Object hierarchy
200
Objects, Collections & Internal Object Structure
Example:
Assuming that the current object context is at any level within the voucher object hierarchy
[Field : Sample Field 2]
Set as : $().LedgerEntry[1,@ExpLedGrp].Amount
ExpLedGrp: $IsGroupDirectExpenses:($Parent:Ledger:$LedgerName)
This is used to retrieve the method Amount of the first Expense Ledger Entry Object. Observe
the usage of (). in the syntax. From any level this specification takes to the Primary Object
i.e., the Voucher Object in the above case.
Exercise 6.5:
Objective
The objective of this program is to understand the Dotted Method Syntax.
Capabilities Used
At report level data Object association is specified by providing attribute ‘Object’
alongwith it’s Identifier.
At field level attribute ‘Set as’ has been used and various methods are utilized to
fetch values from various data objects
Code
[Report: Exer Dotted Method Syntax]
Form : Exer Dotted Method Syntax
Object : Ledger: "Cash"
Title : "Dotted Method Syntax"
201
Objects, Collections & Internal Object Structure
202
Objects, Collections & Internal Object Structure
At report Exer Dotted Method Syntax an attribute Object has been mentioned to associate
Object Ledger and have specified its identifier as Cash.
The report displays five lines on the screen. The pre-defined part Form SubTitle has been
added to Form for displaying the text Understanding Dotted Method Syntax, by localizing
the field Form SubTitle at the Form Exer Dotted Method Syntax. The part Exer Dotted
Method Syntax has four lines.
Line Exer DMS Title has three fields and has been used for title.
Line Exer DMS CurrObj has three fields and has been used for displaying value from Ledger
Object. Hence at fields available at this line we directly mention method names i.e., $Parent
and $ClosingBalance
Line Exer DMS DiffObjGroup has three fields and is displaying value of Bank Account
Group Object. Hence at fields we need to specify the entire Object path i.e., $(Group, "Bank
Accounts").Parent and $(Group, "Bank Accounts").ClosingBalance.
203
Objects, Collections & Internal Object Structure
Similarly at line Exer DMS DiffObjCompany we need the details of the Company Address
from Company Object; hence we have to specify the entire object using Dotted Method
Syntax. As we need a value from a sub-Object ‘Address’ we need to move a level further i.e.,
$(Company, ##SVCurrentCompany).Address[1].Address.
Example:1
Access Name at Part Definition
[Part: Sample Part]
Line : Sample Line1
Access Name: “Sample Part”
204
Objects, Collections & Internal Object Structure
Example:2
Access Name at Line Definition
[Line: Sample Line]
Field : Sample Fld1, Sample Fld2
Access Name: "Repeated Line" + $$String:$$Line
When Line Sample Line is repeated over a collection, every Line is uniquely identified by the
assigned Access Name.
205
Objects, Collections & Internal Object Structure
In all the subsequent examples we will be using the Voucher Data Object
hierarchy to demonstrate the various scenarios for Context Change.
$$Owner
$$Owner evaluates the given expression in the context of the parent data object in the Data
Object hierarchy chain
Syntax
$$Owner:<Expression>
Example:1
In the example given below, let us assume that the field Bill Allocations Amount field
(Requestor) exists in context of Bill Allocations Data Object. In order to evaluate the method
Amount from Ledger Entries Object Context we need to use the function $$Owner.
[Field: Bill Allocations Amount]
Set As : $$Owner:$Amount
In the above Field, the Amount Method from parent Object LedgerEntry is set by using Owner
Function.
Example:2
Similarly, let us assume that the current data object context for the field Bill Allocations
Remarks is Bill Allocations and we need to evaluate the Method Narration from Voucher
Object.
[Field: Bill Allocations Remarks]
Set As : $$Owner:$$Owner:$Narration
In the above Field, the Narration from Object Voucher which is 2 levels above the hierarchy is
set using Owner Function twice. In other words, we are requesting the Narration Method from
Owner of Owner.
$$BaseOwner
$$BaseOwner evaluates the given expression in the context of the base/ primary data object in
the Data Object hierarchy chain available with the Report Object.
206
Objects, Collections & Internal Object Structure
Since the entire Data Object hierarchy is cached with the Object associated at
the Report, BaseOwner Function changes the Data Object context to the Object
associated at the Report .
Example:
$$BaseOwner:<Expression>
As per the Voucher hierarchy, let us assume that our current data object context for the field
Bill Allocations Remarks is Bill Allocations. We require Narration value available at Voucher
Object.
[Field: Bill Allocations Remarks]
Set As : $$BaseOwner:$Narration
In the above Field, the Method Narration from the base Object Voucher is set by using
function BaseOwner.
$$PrevObj
$$PrevObj evaluates the given expression in the context of previous data object of the collec-
tion which contains the current data object in context.
Syntax
$$PrevObj:<Expression>
Example:
Let’s assume that a line is being repeated over a collection of Outstanding Bills which is sorted
on PartyName. After every party Info, a Total Line is needed to print the subtotal for current
Party.
[Line: Outstanding Bills]
Option : Partywise Totals : $$PrevObj:$PartyName != $PartyName
[!Line: Partywise Totals]
Add : Lines : At Beginning : Party SubTotal Line
$$NextObj
$$NextObj evaluates the given expression in the context of next data object of the collection
which contains the current data object in context.
207
Objects, Collections & Internal Object Structure
Syntax
$$NextObj:<Expression>
Example:
Let's assume that a line is being repeated over a collection of Outstanding Bills which is sorted
on PartyName. After every party Info, a Total Line is needed to print the subtotal for current
Party.
[Line: Outstanding Bills]
Explode : Partywise Totals : $$NextObj:$PartyName != $PartyName
$$FirstObj
$$FirstObj evaluates the given expression in the context of first data object of the collection
which contains the current data object in context.
Syntax
$$FirstObj:<Expression>
Example:
Let’s assume a line is being repeated over the ledger collection wherein a field, we require the
first object's name to be set.
[Field: First Name]
Set As: $$FirstObj:$Name
In the above example, a Field First Name is set to First Object of Name Method in a Collection
$$LastObj
$$LastObj evaluates the given expression in the context of last data object of the collection
which contains the current data object in context.
Syntax
$$LastObj:<Expression>
Example:
Let's assume a line is being repeated over the ledger collection wherein a field, we require the
last object's name to be set.
[Field: Last Name]
Set As: $$LastObj:$Name
In the above example, a Field Last Name is set to Last Object of Name Method in a Collection
208
Objects, Collections & Internal Object Structure
$$TgtObject
Apart from Interface (Requestor) and current Data Object Context, there is one more context
available with reference to User Defined Functions and Aggregate Collections i.e., the Target
Object Context.
There are scenarios where the expression needs to be evaluated in the context of Target object,
in such cases the $$TgtObject can be used. Using the $$TgtObject values can be fetched from
the target object without setting the target object as the current context object
Syntax
$$TgtObject:<Expression>
In case of User Defined Functions, the object being manipulated is the Target Object.
Example:1
Consider writing a Function to import a Voucher from Excel wherein the Source Object is Col-
lection gathered out of Objects in Excel Worksheet and the Target Object being the Voucher
and its sub objects.
While setting value to Inventory Entries sub object, the Target Object is changed to Inventory
Entries and the Source Object continues to be Excel Objects.
In order to set values to methods, Quantity and Rate, Stock Item context is required since Unit
Information is available for Item. Hence, TGTObject Function is prefixed to the Expression
@BillQty and @BillRate in order to evaluate these Methods in the context of Target Object
which is the Inventory Entries Object.
209
Objects, Collections & Internal Object Structure
In case of aggregate Collection the object being populated in the resultant collection is the
Target Object.
Please refer to this example only after you complete the chapter on “TDL Pro-
cedural”
Example:2
Consider an example where while populating a summary collection of Sales Voucher, we need
to track the maximum sales amount for each Item with the date on which the maximum sales
triggered.
In the following example, while populating the Summary Collection, Method MaxItemAmt is
being computed for Maximum Amount. Subsequently, Date is also computed by validating if
current object's Amount is greater than previous computed Amount. Since, Maximum Amount
so far is computed and accumulated in the Target Object being populated, we need to access it
using function TGTObject. Hence,$$TgtObject:$MaxItemAmt evaluates the Method Max-
ItemAmt in the context of computed Target Object MaxItemAmt.
210
Objects, Collections & Internal Object Structure
Please refer to this example only after you complete the topic on Aggregation
Capabilities this chapter only.
$$LoopCollObj
We can gather a Collection (Data Collection) in context of each object of another collection
which is known as Loop Collection. To access methods of Loop Collection objects within
Data Collection, $$LoopCollObj is used.
Syntax
$$LoopCollObj:<Expression>
Example:
To see a consolidated list of vouchers across all the loaded companies
[Collection: Company Collection]
Type : Company
Fetch : Name
211
Objects, Collections & Internal Object Structure
Please refer to this example only after you complete the topic on “Loop Collec-
tion” in subsequent section on Collection Capabilities.
$$ReportObject
$$ReportObject evaluates the given expression in the context of the Data Object associated
with the Report Interface Object.
One of the important Use Case of Report Object is its usage in purview of in memory Collec-
tion gathering. Whenever a collection is gathered it is retained in memory with the Data
Object of the current Interface (Requestor) Object. If the same collection is being used in
expressions again and again then it’s beneficial from the performance point of view to attach it
to the Report Object and evaluate it in context of Report Object n number of times. This elim-
inates the need to re-gather the collection every time in context of other Data Objects.
Syntax
$$ReportObject:<Expression>
Example:1
From a Bill Allocations Data Object context, Voucher Number of Report Object Voucher is
required.
[Field: Bill No]
Set As: $$ReportObject:$VoucherNumber
Example:2
In a Report, Sales of each Item against corresponding Parties required.
[Collection: CFBK Voucher]
Type : Voucher
Filter: IsSalesVT
212
Objects, Collections & Internal Object Structure
$$ReqObject
$$ReqObject evaluates the given expression in context of the Data Object associated with the
Interface (Requestor) Object. There may be scenarios where during the expression evaluation
the Data Object context changes automatically and all the methods referred to are evaluated in
context of the changed Data Object Context. The Data Object associated with the Interface
(Requestor) Object is lost. Specifically in those cases, where we need to evaluate methods in
context of the data object associated with the Interface (Requestor) Object we will use the
function $$ReqObject.
Syntax
$$ReqObject:<Expression>
Example:
A Report is required to display Ledger-wise Sales Totals
[#Collection : Ledger]
Compute :LedgerSalesTotal :$$FilterAmtTotal :LedVouchrs:+
MyParty: $Amount
213
Objects, Collections & Internal Object Structure
[System: Formula]
My Party : $PartyLedgerName = $$ReqObject:$Name
Only Sales: $$IsSales:$VoucherTypeName
In the above example, a new method LedgerSalesTotal is added in the Ledger Object to
compute the Sales Total from all the Vouchers filtered for the current Party Ledger Object. The
Interface Object (Requestor) for this method is the field FldLedSalesTotal. In the Formula
My Party, current Ledger Name must be checked with the Party Ledger Name of the Voucher
Object which is the current Data Object context. The Data Object associated with the
Requestor is the Ledger Object. So, in order to evaluate the method $name from the Interface
(Requestor) Object's Data Object context the function $$Reqobject must be used.
$$ObjectOf
We have the capability to identify a Part and Line Interface Object using a unique Access
Name. A Form/Report can be identified from any level using the Definition Type. The
function ObjectOf is used to evaluate the expression in context of the Data Object associated
with the Interface Object identified by the Access Name.
Syntax
$$ObjectOf:<DefinitionType>:<AccessNameFormula>:+
<Evaluation Formula>
Example:
The Part Cust Object Association is associated with the Ledger Object Customer. It is iden-
tified by the Access Name CustLedger.
214
Objects, Collections & Internal Object Structure
In the above example, Field Ledger Parent from a different Part accesses the method $Parent
from the Ledger object Customer as it is the Object associated with the part Cust Object
Association identified by Access Name CustLedger.
$$Table
$$Table evaluates the expression in the context of the table object which is selected
in the given Field.
Syntax
$$Table:<Field Name>:<expression>
Example: In the code snippet given below, the table is displayed in the field Ledger Name. In
the other fields LedGrp, LedOpBal, $$Table is used to evaluate the methods $Parent, $Open-
ingBalance in context of the Data Object selected in the field “Ledger Name”.
[Field: Ledger Name]
Table : List of Ledgers
Show Table: Always
[Field: LedGrp]
Set as : $$Table: Ledger Name:$ Parent
[Field: LedOpBal]
Set as : $$Table: Ledger Name:$ OpeningBalance
215
Objects, Collections & Internal Object Structure
$$TableObj
$$TableObj is similar to the $$Table. The expression is evaluated in context of the Data Object
selected in the Table in the field specified. The difference is that, in case no object is selected
in the Table or expression evaluation fails $$Table returns a blank string. In such a case
$$TableObj returns a logical value (FALSE) as the result
Syntax
$$TableObj:<Field Name>:<expression>
Example:
A Field needs to be skipped based on the selection of the table in a field.
[!Field: VBOrdDueDRNote]
Skip : $$TableObj:VCHBATCHOrder:$$IsOrder
In the above example, if the Object selected in the Field VchBatchOrder is an Object Order,
then the current field needs to be skipped.
Switching the Interface (Requestor) Object Context does not imply a change in
current Data Object.
$$AsReqObj
$$AsReqObj is used to save the Interface (Requestor) context to the current object for the
evaluation of the expression. All the future references done using ReqObject will point to the
saved Interface Object context. The actual requestor is overridden using the function
AsReqObject
Syntax
$$AsReqObj:<Expression>
Example:
In the example below, a Table of Company Vehicles is displayed in a Field Select Vehicle
which exists in context of the Voucher Object. The table is filtered on the basis of Unused
Vehicles
216
Objects, Collections & Internal Object Structure
[Collection: PrevSalesVchs]
Type : Voucher
Filter: Only Sales
[System: Formula]
Unused Veh :$$AsReqObj:$$FilterCount:PrevSalesVchs:UsedVehicle = 0
Used Vehicle : $$ReqObject:$VehicleNumber = $VCHVehicle
Only Sales : $$IsSales :$VoucherTypeName
217
Objects, Collections & Internal Object Structure
In the FilterCount Function, when the object context changes to the list of sales
vouchers, ReqObject Function evaluates the parameter $VehicleNumber in the con-
text of requestor Collection CMP Vehicles set using AsReqObj Function earlier and
compares the same with the Voucher UDF VchVehicle stored in the respective
vouchers.
$$ReqOwner
$$ReqOwner evaluates the given expression in context of the Interface (Requestor) objects
Owner in the current Interface object hierarchy. For instance, Report is an owner requestor for
Form; Form is an owner requestor for Part and so on. From Line, when ReqOwner Function is
used, the expression gets evaluated in the context of the Part containing the current line.
Syntax
$$ReqOwner:<Expression>
Example:
[#Menu: Gateway of Tally]
Add: Key Item: ReqOwner Sample: W : Alter: ICCF ReqOwner
218
Objects, Collections & Internal Object Structure
[Function: FunctoreturnReqOwner]
Variable: VarReqOwner: String: “Madhava”
Variable: Temp: String: $$ReqOwner:##VarReqOwner
$$AccessObj
We have the capability to identify a Part and Line Interface Object using a unique Access
Name. The function AccessObj changes the Interface Object context to the one identified by
the Access name to evaluate the expression The Interface Object being referred to should be
assigned a unique AccessName via Access Name attribute.
Syntax
$$AccessObj:<DefinitionType>:<AccessNameFormula>:+
<Evaluation Formula>
Example:
[Line: ABC]
Access Name : “AccABC”
[Field: XYZ]
Set As: $$AccessObj:Line:“AccABC”:##VarABC
In the example above the function $$AccessObj changes the Interface Object context from the
field XYZ to the line ABC which is identified by Access Name AccABC. The variable value
is evaluated in context of the line ABC.
$$ExplodeOwner
$$ExplodeOwner changes the Interface (Requestor) Object to the Line owning the current
exploded Part and evaluates the given expression i.e., Field and Variable Values in the context
of Interface Object.
Syntax
$$ExplodeOwner:<Expression>
219
Objects, Collections & Internal Object Structure
Example:
In the following example, Field NameField is being evaluated in the context of Line Smp
InvEntries which owns the current exploded part Smp Expl Part
$$PrevLine
When the line is repeating, we may require evaluating an expression in context of the previous
line. For example, we might require fetching the field values stored in previous line for an
expression in the current line. The function PrevLine is used to change the Requestor to the
Previous Line for expression evaluation.
Syntax
$$PrevLine:<Expression>
The PrevLine function not only changes the Interface (Requestor) Object
context but also changes the Data Object context to the Object associated with
the Requestor
220
Objects, Collections & Internal Object Structure
Example:
In the following example, in case of repeated lines where subtotals are required to be
displayed or printed for same party, we can explode a subtotal line after comparing previous
line’s Ledger and current line's Ledger. If the field values are not the same, then subtotal line is
exploded.
[Line: PrevParticulars]
Explode : PrevParticulars ExpPart : $$PrevLine: #PartyParticulars+
!= #PartyParticulars
$$PrevFld
$$PrevFld is used to extract the value of the filed in the previous field. This is useful in Multi
column reports where this function is used to get the value of the previous field or to find the
difference between two previous fields. The function $$PrevFld without any parameter
retrieves the value of previous field. It can optionally accept a single parameter which
specifies the field number the value of which is to be extracted
Syntax
$$PrevFld:<Expression>
Example:
[Line: Ledger Line]
Field : Ledger Name, Prev Fld Name
221
Objects, Collections & Internal Object Structure
of specific data as well. Also, the searching and indexing capabilities facilitate faster retrieval
enhancing the performance improvements.
Data Presentation
The various processing attributes allow aggregation, chaining, combining and sorting facilities
which are largely focused on advanced presentation of data as per complex business require-
ments.
Integration
The various attributes allow the retrieval of data into collection from external data bases
available oves like HTTP/HTTPS/ODBC/DLL etc.
In this part of the book we will concentrate on the first two points only. Integra-
tion capabilities will be covered in the second part of the book on Integration
Capabilities.
222
Objects, Collections & Internal Object Structure
The two wild characters can be used in Fetch attribute specification ? and *
? is used to fetch all the methods of Object in current context.
* is used to fetch all the methods and sub collections of the Object in context.
Example:1
To fetch all methods of Object
[Collection : Vouchers]
Type : Voucher
Fetch : ?
Example:2
To fetch all methods and sub-collections of Voucher Object
[Collection : Vouchers]
Type : Voucher
Fetch : *
Example:3
To fetch the methods Date, VoucherNumber, Narration and all the methods of collection
Inventory Entries
[Collection : Vouchers]
Type : Voucher
Fetch : Date, VoucherNumber, Narration, InventoryEntries.*
Attribute – Compute
The specification of all internal methods which are required is handled by the Fetch Attribute.
In case, the external methods which are to be computed for each object of the collection, the
same needs to be specified by using the “Compute” attribute.
Syntax
Compute : <Method-Name> : <Method-Formula>
Example:1
The internal method can be accessed by a different name by using Compute
[Collection : Vouchers]
Type : Voucher
Compute : VchDate : $Date
Example:
The parent of the ledger and Stock item is computed at each object level of the Voucher by
referring to the corresponding Stock Item/Ledger Master.
223
Objects, Collections & Internal Object Structure
[Collection : Vouchers]
Type : Voucher
Fetch : LedgerName
Compute : LedParent : $Parent:Ledger:$LedgerName
Compute : ItemParent: $Parent:StockItem:$StockItemName
In this example the LedParent and ItemParent is computed for the first Object
of the subcollections “Ledger Entries” and “Inventory Entries”.
By specifying a list of Data Collection Only where each Data Collection is discrete
in itself. This is referred to as Union Pictorially shown as below
224
Objects, Collections & Internal Object Structure
The attribute Collection is used to specify the various Collections. This attribute combines all
objects belonging to various collections within a single collection.
Syntax
Collection : <List of Data Collections>
Where,
<List of Data Collections> is a comma separated list of collection.
Example:
[Collection : GroupAndLedger]
Collections : AllGroups, AllLedgers
[Collection : AllGroups]
Type : Group
[Collection : AllLedgers]
Type : Ledger
In the above example, the Resultant Collection “GroupAndLedger” consists of all Objects of
Groups as well as Ledgers.
By specifying a list of Data Collections where the same Data Collection is repeated
over each Object of another Collection. This is referred to as Looping
225
Objects, Collections & Internal Object Structure
TDL gives developer a capability to dynamically gather data collections in context of each
object of another collection. ‘Collection’ attribute accepts two additional optional parameters
i.e. Loop Collection Name and Looping criteria.
The collection names in the list of collection are referred as Data Collections. The collection
on which the repetition is done is referred as Loop Collection. The collection in which data is
populated is referred as Resultant Collection.
Each data collection is gathered once for each object in the loop collection. If there are n
objects in the loop collection, the data collections are gathered n-times in the context of each
object in loop collection. In the resultant collection objects are delivered as TDL Objects. This
makes it mandatory to fetch the required methods in the Data Collection
226
Objects, Collections & Internal Object Structure
Syntax
Collection : <List of Data Collection>[:<Loop Collection Name>+
[:<Condition for Loop Collection]]
Where,
<List of Data Collection> is comma separated list of data collections.
<Loop Collection Name> is the name of loop collection and it is optional.
<Condition for Loop Collection> is optional. The condition is evaluated on each object of
the Loop Collection.
Example:
The resultant collection will contain all the Voucher Objects for all the Companies that are
loaded
6.7.3 Filtering
If it is required to retrieve only a specific set of objects from a Collection, then the collection
needs to be filtered. Filtering is applied on the Collection based on a condition. All the objects
which satisfy the given condition are retrieved and are available in the Collection.
227
Objects, Collections & Internal Object Structure
In TDL filter is applied on the collection and all the objects that satisfies the given condition is
retrieved and populated in the collection. Attributes Child Of, Belongs To and Filter are
available to filter. Pictorially represented as below :
Attribute – Child of
Attribute Child Of is a context sensitive attribute. The ChildOf attribute helps to control the
display of the contents of a collection. It retrieves only those objects whose direct parent is the
string specified as the parameter of this attribute.
We have already covered that the “Type” attribute for collection can be specified in two ways
Type : Primary Object Type
Or
Type : Sub Type: Primary Object Type
Syntax
Child Of : <String Formula>
If the collection is constructed using the first syntax the expression in Child Of must evaluate
to Identifier for the parent of the Primary Object Type.
228
Objects, Collections & Internal Object Structure
Example:
If the Type is Object Ledger, then the Child of can evaluate to Sundry Debtors to gather all the
ledgers under the Group Sundry Debtors.
[Collection : My Collection]
Type : Ledger
Child Of : $$GroupSundryDebtors
If the collection is constructed using the second syntax the expression in Child Of must
evaluate to Identifier for the Primary Object Type.
Example:
If the Type Attribute contains SubType as Vouchers and Primary Object Type as Ledger then
Child of attribute must identify the ledger name for which all the vouchers will be gathered. If
the Object Context for the primary Object Type is available, then the Child Of specification is
optional.
[Collection : My Collection]
Type : Voucher : Ledger
Child Of : “ABC led”
Attribute – Belongs To
The attribute Belongs To is used along with the ‘Child Of’ attribute. This attribute determines
whether to retrieve the first level of objects under the value specified in Child Of or include all
the objects upto the lowermost level .BelongsTo takes a logical value.
Syntax
Belongs To : <Logical Value>
Where,
<Logical Value> can either be Yes or No
Example:
To gather all the ledgers under Sundry Debtors including its sub-groups, the following can be
done
[Collection : My Collection]
Type : Ledger
Child Of : $$GroupSundryDebtors
Belongs To: Yes
\
229
Objects, Collections & Internal Object Structure
Filter
The attribute ‘Filter’ is used to specify the condition for filtering the objects. The Filter
attribute takes a system formula which evaluates to a logical value. The condition is specified
in the formula. If more than one filter has to be specified it can be separated by a comma. All
the Objects which fulfill the filter condition are populated in the collection.
Syntax
Filter : <FilterName>
Where,
<Filter Name> is the name of a system formula.
Example:
The collection needs to be gathered with all Sundry Debtor ledgers whose name contain Ltd.
Or Limited
[Collection : LtdDebtors]
Type : Ledgers
ChildOf : $$GroupSundryDebtors
BelongsTo : Yes
Filter : NameFilter
[System: Formula]
NameFilter : $Name contains "Ltd" OR $Name contains "Limited"
First the ChildOf is applied to filter all Sundry Debtor Ledgers and then an additional filter
NameFilter is applied to to get only those ledgers whose name contains “Ltd” or “Limited”.
Filter can filter values biased on any Methods or UDF values within the current
object whereas Child Of can only accept specific object identifiers as specified
by the platform.
6.7.4 Sorting
Sorting is a process of arranging objects in a specific order. Objects of a collection can be
sorted by specifying the sort sequence using the ‘Sort’ attribute. Sorting can be done on
multiple fields both in either ascending or descending order. For descending order, Negative
symbol must be prefixed.
230
Objects, Collections & Internal Object Structure
Syntax
Sort: <Sort Name> : <List of Expressions>
Where,
<List of Expressions> is a comma separated list of expression i.e. Method names, Formula
and Variable. The default sort order is ascending. For sorting in descending order pre-fix the
expression with a negative sign.
Example:
[Collection: My Collection]
Type : Ledger
Sort : Default : $ClosingBalance, -$Name
In the above collection, sorting will happen firstly on Closing Balance method in ascending
order and then by Name in descending order
This is shown in the table as below:
Original Collection before Sorting
Name Closing Balance
Global Traders 10,000
Prism Softlinks 25,000
Universal Computers 10,000
Arvind Kumar 12,500
Fortune Computer Services 5,000
Janata Timbers 7,000
Resultant Collection after Sorting on Closing Balance
Name Closing Balance
Fortune Computer Services 5,000
Janata Timbers 7,000
Global Traders 10,000
Universal Computers 10,000
Arvind Kumar 12,500
Prism Softlinks 25,000
In the above table of sorted objects, please observe that when both the objects Universal
Computers and Global Traders contain the same Closing Balance, the Objects are further
sorted on Name in descending order.
231
Objects, Collections & Internal Object Structure
6.7.5 Searching
Collection capabilities enable indexing of objects based on some unique Key. Whenever a col-
lection is indexed on a particular method, it allows instant access to the corresponding values
without a complete scan. ‘Search Key’ attribute is used to specify the Keys which is indexed
for instant access. This implies that a unique key is created for every object which can be used
to instantly access the corresponding objects and its values.
Syntax
Search Key : <Combination of Method name/s>
Where,
<Combination of Method name/s> are method names separated by ‘+’
The function $$CollectionFieldByKey is used to retrieve values from a collection based on the
key specified.
Syntax
$$CollectionFieldByKey:<Method Name>:<Key Formula>:+
<Collection Name>
Where,
<Method Name> is the name of the method
<Key Formula> is a formula that can be mapped to the methods in the current context as
defined in the search key
<Collection Name> is the collection name in which the Objects are available with their
unique Keys as identifiers
Example:
[Collection: My Ledgers]
Type : Ledger
Fetch : Name, ClosingBalance
Search Key : $Name
232
Objects, Collections & Internal Object Structure
other functions like FilterValue or CollectionField. This capability is also very powerful in
case of matrix reports were two or more dimensions need to be represented as rows and
columns. In such case, search key is made up of combination of methods which helps the
retrieval fast since all the keys are indexed and when the matrix value at certain point is
required, it need not search the collection but can directly pick up the Indexed Object with the
help of given Key.
6.7.6 Grouping & Aggregation
The language capability facilitates the creation of large summary aggregated objects very fast
in a single operation which allows the developer to walk down the object hierarchies and
gather values to summarize them in a single scan. The attributes used for aggregation and
grouping are Walk, By and AggrCompute.
The picture below will give clarity on what is meant by Grouping & Aggregation.
Original Collection before Aggregation
Student Name Subject Marks
Krishna English 100
Radha Maths 95
Gopal English 75
Krishna Maths 97
Krishna Science 75
Radha English 90
233
Objects, Collections & Internal Object Structure
Let us now discuss the various attributes for achieving the above :
Attribute – Source Collection
Source Collection specifies the collections to be used for source data. Multiple Source Collec-
tions can be used which can either be specified as a comma separated list or can be listed in
several lines. The aggregation and grouping is applied thereafter on the Source Collection
Objects. The final collection which is arrived at is referred to as “Summary Collection” in our
discussions.
Syntax
Source Collection : <Collection name>, <Collection Name> …
Where,
<Collection Name> is any predefined collection, the methods and sub objects of which are
available to the current collection for further processing.
Example:
[Collection: Vouchers Collection]
Type : Voucher
Attribute – Walk
Attribute Walk allows us to traverse the hierarchy of sub objects which are available in the
source. This will generate a set of Objects which are required to be grouped and aggregated.
Walk is optional and if not specified, the first level Objects are only available for aggregation.
Walk can be specified to any depth within the source object. This gives enormous flexibility
and power. The Walk list has to be specified in the order in which they occur in the source
object.
Syntax
Walk : <Sub-Object Type/ Sub-Collection>[, <Sub-Object Type/ +
Sub-Collection> …]
Where,
<Sub–Object Type/Sub-Collection> is the name of the Sub Objects/ Sub Collection.
234
Objects, Collections & Internal Object Structure
Example:
[Collection: Vouchers Collection]
Type : Voucher
Attribute - By
After walking to the desired level and generating the final set of Objects to be aggregated, the
next step is to identify the method on which Grouping needs to be performed. This is termed
as the Grouping Criteria. Attribute ‘By’ allows us to specify the grouping criteria.
Syntax
By : <Method-Name>: <Method-Formula>
Example:1
Grouping objects based on Stock Item name
235
Objects, Collections & Internal Object Structure
Example:2
Grouping objects based on Party Ledger name and then on StockItemName
236
Objects, Collections & Internal Object Structure
This is done by specifying the Aggr Compute attribute. The sum of Billed Qty for StockItem a
particular Party is available with the method name “TotBilledQty” within the Summary Col-
lection.
Exercise 6.6
Objective
The objective of the code is to display a report listing all the Parties with the Count, Sales
Amounts and Dates
Capabilities Used
Button has been added at the form level for changing period of the report
Repeat attribute at part level for repeating line over a collection
Scroll attribute for allowing data to flow off the screen
Total attribute at part to add field values vertically
At collection definition attributes ‘Type’, ‘Filter’, ‘Source Collection’, ‘By’, ‘Com-
pute’, ‘Aggr Compute’
237
Objects, Collections & Internal Object Structure
Code
[Report: Exer Grp Aggr and Extr]
Form : Exer Grp Aggr and Extr
Title : "Grouping, Aggregation and Extraction"
238
Objects, Collections & Internal Object Structure
Local : Field: Exer GAE Total Sales Count: Set As: "Frequency +
of Billing" + $$NewLine + "(Count)"
Local : Field: Exer GAE Min Date : Set As: "First Bill Date"
Local : Field: Exer GAE Max Date : Set As: "Recent Bill Date"
Local : Field: Exer GAE Min Sales Amount: Set As: +
"Least Billed Amount"
Local : Field: Exer GAE Max Sales Amount: Set As: "Maximum +
Billed Amount"
Local : Field: Exer GAE Sales Amount: Set As: "Total Sales+
Amount"
Border : Thin Top Bottom
239
Objects, Collections & Internal Object Structure
240
Objects, Collections & Internal Object Structure
241
Objects, Collections & Internal Object Structure
Output
At form Exer Grp Aggr and Extr a button F2ChangePeriod has been added to change the
period of the report. The form has two parts. The part ‘Exer GAE Period’ has been added to
show the period of the report.
The part Exer Grp Aggr and Extr has three lines. The topmost line Exer GAE Title is
utilized for displaying column Titles and is using the line Exer GAE Details, so it will inherit
all the attributes of the line Exer GAE Details. At line Exer GAE Title we have localized all
the fields and set the values by using attribute Set as.
At part Exer Grp Aggr and Extr, second line Exer GAE Details has been repeated over col-
lection Exer GAE Partywise Sales.
Collection Exer GAE Partywise Sales is a summary collection. The Exer GAE Sales
Vouchers is the source collection of this collection, which is holding Object Voucher and
filter for all the all sales voucher by using ‘Filter’ attribute. Filter attribute accepts only a
system formula as a value.
As the Objective stated is very clear that we require Parties Bill Count, Total Sales Amount
and Dates i.e., First Bill Date and Last Bill Date, we would utilize By for grouping the values
Party Name wise i.e., further Aggregation would be done uniquely on each party, hence we
have grouped on PartyLedgerName.
242
Objects, Collections & Internal Object Structure
At collection Exer GAE Partywise Sales we would have multiple Sales Voucher and this
would have multiple Party Name and repeated Party Name. We require Party Name just once,
hence we would group on basis of Party Name i.e. method PartyLedgerName. Attribute By
takes two parameters, first Method Name that would be defined by the developer and second
Method Formula which would evaluate to a value and would be hold in the Method Name. In
our example we require Party Name hence we have utilized.
By : Exer GAE LedgerName : $PartyLedgerName
Where,
Exer GAE LedgerName is the method name in which unique values of method formula
would be gathered and $PartyLedgerName is the method formula.
After grouping we require to aggregate the values i.e. we need Count of Bills, Total Sales Bill
Amount, First Bill Date and Last Bill Date. This is done by specifying attribute Aggr
Compute. To count the number of bills we would make use of AggrType Sum.i.e.,
In order to get the total Bill Amount for each party, we will apply summation of all amounts of
the ledger entry object belonging to the Party from all Vouchers. Observe the usage of the
index 1 with Ledger Entries collection, which is always the first ledger entries object in
respective voucher pertaining to the Party.
Aggr Compute : Exer GAE Sales Amt: Sum: $LedgerEntries[1].Amount
243
Objects, Collections & Internal Object Structure
;;The Resultant Collection which is a union of objects from the above two collections “Ledger Details” and “StockItem Details”
244
Objects, Collections & Internal Object Structure
rizing values from the Source Collection, each object of the collection Voucher Source is
traversed twice for aggregating objects over two different paths i.e., once for Ledger Entries
and then again for Inventory Entries. The Report finally uses the Union Collection Union
LedStk Vouchers to render the same.
In such cases, significant CPU cycles will be utilized in gathering and walking over the same
Source Object along different paths more than once.
[Collection: VoucherSource]
Type : Voucher
/* The collection “UnionLedStkVouchers” is the resultant collection which will contain all the Objects obtained out of walks and
multiple walks over the same Source Collection. The Report finally uses this Collection. The attribute WalkEx is specified which
has values as collection names “Ledger Details” and “StockItem Details”*/
245
Objects, Collections & Internal Object Structure
The Collections used within the WalkEx uses the same Source Collection. Each Object of
Voucher Source is walked across Ledger Entries and Inventory Entries in a single pass.
Thus, there is an exponential improvement in performance as it traverses each object only
once to gather the values for the resultant collection. In the case of Union Collection, for every
Collection using different walk path, the Source Collection Object is being traversed again and
again.
. – Single dot retains the source collection objects in current interface object
.. – Double Dot will retain the source collection objects in current interface object’s parent
246
Objects, Collections & Internal Object Structure
... – Triple Dot will retain the source collection objects in the current interface object’s parent’s
parent and so on
(). –This will retain the source collection objects in the Base Owner of the Interface Object
Syntax
Keep Source : Yes/No/.../().
Example:
Keep the source collection objects in the current Interface Object level
Keep Source : Yes
OR
Keep Source : .
Keep the source collection objects with the base owner interface object
Keep Source : ().
6.7.8 Variables in Collection
TDL supports the concept of aggregate/summary collection for creating summarized reports.
In the aggregate collection during the evaluation following three sets of objects are available:
Source Objects: Objects of the collection specified in the Source Collection
attribute.
Current Objects : Objects of the collection obtained till the Walk specification is
exhausted
Aggregate Objects: Objects obtained after performing the grouping and aggrega-
tion
There are scenarios where some calculation is to be evaluated based on the source object or the
current object value and the filtration is done based on the value evaluated with respect to final
247
Objects, Collections & Internal Object Structure
objects before populating the collection. In these cases to evaluate value based on the
changing object context is tiresome and at times impossible as well.
The concept of collection level variables provides Object-Context Free processing. The values
of these inline variables are evaluated before populating the collection.
The variables defined using attributes Source Var and Compute Var can be referred in the col-
lection attributes By, Aggr Compute and Compute.
The variable defined by Filter Var can be referred in the collection attribute Filter. The value of
these variables can be accessed from anywhere while evaluating the current collection objects.
The variable defined using ParmVar can be referred by any attribute within the collection
Source Var
The attribute Source Var evaluates the value based on the source object.
Syntax
Source Var : <Variable Name> : <Data Type> : <Formula>
Where,
<Variable Name> is name of variable
<Data Type> is the data type of the variable
<Formula> can be an expression formula which evaluates to value of the variable
Example:
The requirement here is to calculate the Date and VoucherType wise ledger total amounts
[Collection : Src Vouchers]
Type : Voucher
Fetch: Date, VoucherNumber, VoucherTypeName, AllLedgerEntries.*
248
Objects, Collections & Internal Object Structure
In the above example a variable SrcVch is created which concatenates Date and Voucher Type
from the Source Objects. Then the objects are grouped first based on the SrcVch and then by
Ledger name. The aggregation is applied on the ledger amount.
Compute Var
The attribute Compute Var evaluates the value of based on the Current Objects i.e., on the
basis of the objects obtained after evaluating the Walk specification.
Syntax
Compute Var : <Variable Name> : <Data Type> : <Formula>
Where,
<Variable Name> is name of variable.
<Data Type> is the data type of the variable.
<Formula> can be an expression formula which evaluates to value of the variable
Example:
The only difference in this example from the previous one is that if the source objects contain
Sale as Voucher type then the second level grouping will be on the basis of combination of
Date, VoucherType and ledger name in combination.
Filter Var
The attribute Filter Var evaluates the value of the variable on Aggregate Objects ie the objects
obtained in collection after the grouping criteria and aggregation is applied.
249
Objects, Collections & Internal Object Structure
Syntax
Filter Var : <Variable Name> : <Data Type> : <Formula>
Where,
<Variable Name> is the name of variable
<Data Type> is the data type of the variable
<Formula> can be an expression which evaluates to value of the variable type
Example:
In the example we require to filter those item for which the aggregated billed qty is greater
than zero.
[Collection: SCF CFBK Voucher]
Type : Voucher
Filter : SCF IsSalesVT
;; Cmp Var is used in the above Filter
Compute Var: Compute Var in Source: Logical: $IsSales:+
$VoucherTypeName
Fetch : VoucherTypeName, VoucherNumber
250
Objects, Collections & Internal Object Structure
[System: Formula]
SCF IsSalesVT: ##ComputeVarinSource
Final Filter : ##FilVar
Parm Var
Collection Artifact evaluates the various attributes either during initialization or at the time of
gathering the collection. It may require various inputs from the Requestor context.
For e.g., the evaluation of ‘Child of’ and ‘Filter’ attribute happens at the time of gathering the
collection. It requires certain values from Requestors context like $Name. In filter attribute if
$Name of each object is to be compared with $Name of the Requestors context then we have
to refer it as $ReqObject:$Name. However, in a Remote Environment where the Requestor
Context is not available within the collection at the Server side. Hence we require attribute
Parm Var. This variable is a context free structure in the collection. The variable is evaluated
only once in the context of the caller/requestor. This happens at collection initialization and
the expression provided to it is evaluated and further stored as a variable which can be referred
within any of the attributes of the collection at any given time. This is made available at the
Server end by passing it with the XML Request.
Syntax
Parm Var : <Variable Name> : <Data Type> : <Formula>
Where,
<Variable Name> is the name of variable
<Data Type> is the data type of the variable
<Formula> can be an expression which evaluates to value of the variable data type
In the code given below the Line Groups and Ledgers is repeating on a Group collection. From
within that line a part is exploded which displays the List of Ledgers belonging to that Group.
The line List of Ledgers within this part Repeats on the collection Smp List of Ledgers
[Part: Groups and Ledgers]
Lines : Groups and Ledgers
Repeat : Groups and Ledgers : List of Groups
Scroll : Vertical
251
Objects, Collections & Internal Object Structure
Where,
<Collection Name> is the name of collections and can be a comma separated list
Example:
List of ledgers to be displayed as a table within the field for selection
[Field : Sample Field]
Table : LedgerCollection
[Collection : LedgerCollection]
Type : Ledger
252
Objects, Collections & Internal Object Structure
Syntax
Title : <String >
SubTitle : <List of comma separated string>
Example:
[Collection: Ledger Collection]
Type : Ledger
Format : $Name, 15
Format : $OpeningBalance, 10
Title : $$LocaleString:"Table Sub-Titles"
Sub Title : $$LocaleString:"Name"
Sub Title : $$LocaleString:"Op.Balance"
The above code example displays a table with two columns. Column titles are also displayed
with the help of attribute Sub Title. Instead of specifying the Sub Title attribute multiple times
a comma separated list can be given as shown like :
Sub Title : $$LocaleString:"Name", $$LocaleString:"Op.Balance"
253
Objects, Collections & Internal Object Structure
We have already seen that it is possible to populate a collection either by using an Internal
Object or an External Object which can also be a Dynamic Object populated from a variety of
Data Sources like HTTP/HTTPS-XML/DLL/ODBC etc. The various types of Collections
which can be displayed as tables are listed as below .
Voucher Collection
ODBC Collection
XML Collection
Summary/Aggregate Collection
DLL Collection
Variable Collection
$$Table
$$Table returns the corresponding method value selected from the table which mentioned in
the field using the field value
Syntax
$$Table:<FieldName>:<Expression>
In the example given below, let us assume that the field Led Name Field has a table. Based on
selection of the Ledger Name, Ledger Opening should be picked automatically in Opening
Bal Field.
[Field: Opening Bal Field]
Set As : $$Table:LedNameField:$OpeningBalance
In the above Field, the Opening Balance Method from Object Ledger is set at the current field
by using Table Function.
Exercise 6.7
Objective
The objective of this program is to open a report in Alter Mode and a Table is displayed. On
selecting an Item, the corresponding Description is set in the subsequent Field using Function
'Table'.
Capabilities Used
Table attribute at Field definition to display pop up list
At Set As of the Field used Function $$Table to set corresponding values in the sub-
sequent field
Attributes Type, Title, Format and Subtitle has been utilized for deciding the Object
Type, Title to be displayed for the pop up list, Values in the columns of the pop up
list, Title for the columns respectively
254
Objects, Collections & Internal Object Structure
Code
[Report: Exer Collection as Table]
Form : Exer Collection as Table
Title : "Collection as Table"
255
Objects, Collections & Internal Object Structure
Output
The report has three fields. Field Medium Prompt has been used to display Label Select an
Item”. Field ‘Name Field’ is where we have displayed the pop up list. Attribute Table has been
used and the name of the collection ‘Exer CaT List of Stock Items’ has been provided as the
attribute value.
The collection is holding Object of Type Stock Item. Attribute Title has been used to provide
title to the Table. Attribute Format would decide the values to be displayed in the column.
Give format as many columns you require in your Table. Format attribute takes one value as
parameter. This can be any formula and we can provide width to the column by providing a
comma after the formula i.e., Format: $ClosingBalance, 20. Attribute Sub title helps us to
provide the Title for the columns. The width for this would be picked from the corresponding
Format attribute.
At field Short Name Field we would like to display description of the Stock Item which has
been selected in the previous field, hence we have made use of $$Table function at Set As.
Function $$Table accepts two parameters. First parameter is the name of the field to which
Table is attached and second parameter is the corresponding method which is to be selected
based on the object selected from the Table.
256
Objects, Collections & Internal Object Structure
Where ,
<Table Object Method> is a method whose value is uniquely displayed in the table.
<Field Object Method> is the storage/method which is associated with the field which is
used to control the display of Table values dynamically. If a particular table object method
value from the Table is selected in the field, then that value is removed from the table based on
the value of <Field Object Method> This parameter is mandatory if extended method is
specified else its optional.
<Extended Method> is a storage/method whose value specifies whether the previous value of
field object method should be used to control unique values display in the table. If the current
value of the value of <Extended Method> is same as that of previous values then <Field
Object Method> value is considered while populating unique value in the table. Otherwise
the <Field Object Method> value is ignored to set the unique values in the table. This
parameter is optional.
The collection and definition is modified as follows so that while populating unique values of
Batch names in the table, Stock Item name is also considered apart from the value of the field
storage/ method BtName. i.e., if the same stock item is selected in the field which has been
selected previously then the field storage/method value BtName is considered for controlling
display of Batches else it is ignored.
Example:
[Part: StkBat]
Repeat : GrpLedLn: StkItemColl
[Line : GrpLedNm]
Field : StkIt, StkBatNm
[Field : StkIt]
Use : Name Field
Storage: ItemName
[Field : StkBatNm]
Use : Name Field
Table : BatList
Storage : BtName
Show Table : Always
Dynamic : Yes
257
Objects, Collections & Internal Object Structure
[Collection: BatList]
Title : “List of Batches”
Type : Batch
Format : $BatchName,20
Child of : #StkIt
Unique : $BatchName,$BtName,$ItemName
Here the method $Itemname used in the unique attribute is the storage defined in the field
‘StkIt’. Consider the following Scenario:
Stock Item Name Batch Name
Batch A
Item 1 Batch B
Batch C
Batch A
Item 2 Batch B
Batch C
Batch A
Item 3 Batch B
Batch C
There are two fields in the line one which displays stock item name and the other displays
batches. The selected batch is stored in the UDF say BtName. The following table displays the
values in each field and the unique values in the tables based on the selection.
Line No Value in Field 1 Values in Selected Value
Table in Field 2
1 Item 1 Batch A Batch A
Batch B
Batch C
Primary Batch
258
Objects, Collections & Internal Object Structure
$$NumItems
$$NumItems returns the count of Objects in the given collection.
Syntax
$$NumItems:<CollectionName>
Where,
<CollectionName> is the name of a Collection
Example:
[Field : Sample Field]
Set as : $$NumItems:Ledgers
[Collection : Ledgers]
Type : Ledger
$$FullList
$$FullList returns a list of comma separated values of the specified expression evaluated for
each object of the collection.
Syntax
$$FullList:<CollectionName>:<Expression>
Where,
<CollectionName> is the name of the Collection
<Expression> refers to any valid expression to be evaluated on each Object of the Collection
259
Objects, Collections & Internal Object Structure
Example:
[Field : Sample Field]
Set as : $$FullList:Address:$Address
$$FullListEx
$$FullList returns a list of values of the specified expression evaluated for each object of the
collection separated by the character as specified.
Syntax
$$FullListEx:<separator character>:<CollectionName>:+
<MethodFormula>
Example:
[Field : MyAddField]
Set as : $$FullListEx:”;”:CompanyAddress:$Address
$$CollectionField
$$CollectionField is used to retrieve the value of a specified expression from the specified
Object of a Collection. In other words, the Function CollectionField extracts the required
expression value from the object at a specified index within the given Collection
Syntax
$$CollectionField:<ValueExpression>:<Index>:<CollectionName>
Where,
<ValueExpression> refers to any valid expression to be evaluated on the specified Object of
the Collection
<Index> denotes the position
<CollectionName> is the name of the Collection
Example:
[Field : Sample Field]
Set as : $$CollectionField:$Amount:1:AllLedgerEntries
The example returns the Amount from the first object of AllLedgerEntries available within the
current Voucher Object.
$$CollectionFieldByKey
The function $$CollectionFieldByKey is used to retrieve values from a collection based on the
key specified.
260
Objects, Collections & Internal Object Structure
Syntax
$$CollectionFieldByKey:<Method Name>:<Key Formula>:<Collection
Name>
Where,
<Method Name> is the name of the method
<Key Formula> is a formula that can be mapped to the methods in the current context as
defined in the search key
<Collection Name> is the collection name in which the Objects are available with their
unique Keys as identifiers
The Search key specifications and detailed examples have already been taken
up in the prior sections
$$CollAmtTotal
$$CollAmtTotal is used to calculate the total of all the values of the expression evaluated for
each Object of the collection. The expression needs to evaluate to a value of Amount
Datatype.
Syntax
$$CollAmtTotal:<CollectionName>:<ValueExpression>
Where,
<CollectionName> is the name of a Collection
<ValueExpression> is any valid TDL expression to be evaluated on each Object in the Col-
lection.
Example:
[Field : Sample Field]
Set As : $$CollAmtTotal:LedgerEntries:$Amount
The above example calculates the total of method Amount for all objects of the Ledger Entries
Object available within the current Voucher Object
$$CollNumTotal
$$CollNumTotal is used to calculate the total of all the values of the expression evaluated for
each Object of the collection. The expression needs to evaluate to a value of Number
Datatype.
261
Objects, Collections & Internal Object Structure
Syntax
$$CollNumTotal:<CollectionName>:<ValueExpression>
Where,
<CollectionName> is the name of a Collection
<ValueExpression> This refers to any valid expression to be evaluated on each Object of the
Collection
Example:
[Field : Sample Field]
Set as : $$CollNumTotal:InventoryEntries:$Height
The above example calculates the total of method height(external method) for all objects of
the InventoryEntries Object available within the current Voucher Object
$$CollQtyTotal
$$CollQtyTotal is used to calculate the total of all the values of the expression evaluated for
each Object of the collection. The expression needs to evaluate to a value of Quantity
Datatype.
Syntax
$$CollQtyTotal:<CollectionName>:<ValueExpression>
Where,
<CollectionName> is the name of a Collection
<ValueExpression> refers to any valid TDL expression to be evaluated on each Object of the
Collection.
Example:
[Field : Sample Field]
Set as : $$CollQtyTotal:InventoryEntries:$BilledQty
The above example calculates the total of method BilledQty for all objects of the InventoryEn-
tries Object available within the current Voucher Object
$$FilterCount
$$FilterCount is used to get the total number of Objects in a Collection after the specified filter
is applied.
Syntax
$$FilterCount:<CollectionName>:<FilterExpression>
262
Objects, Collections & Internal Object Structure
Where,
<CollectionName> is the name of a Collection
<FilterExpression> is a System Formula
Example:
[Field : Sample Field]
Set as : if @PartyLedAvailable then “Supplier” else +
“ -- No Party --”
PartyLedAvailable : $$FilterCount:AllLedgerEntries:+
IsPartyLedgerAccount > 1
[System: Formula]
IsPartyLedgerAccount: $IsPartyLedger
The filter in the example, checks whether Ledger Name is a Party Ledger Name or not. In case
it returns true for more than 1, then the field would display Supplier, else it would display “ --
No Party --”
$$FilterValue
$$FilterValue is used to get the value of a specified expression based on the position specified
within the set of objects returned after filter condition is applied.
Syntax
$$FilterValue:<ValueExpression>:<CollectionName>:<Index>:<Fil-
terExpression>
Where,
<CollectionName> is the name of the Collection.
<FilterExpression> is used to specify the filter condition.
<Index> denotes the position.
<ValueExpression> refers to any valid expression to be evaluated on each Object of the Col-
lection.
Example:
[Field : Sample Field]
Set as : $$FilterValue:$LedgerName:LedgerEntries:First:+
IsPartyLedger
The example retrieves the method $LedgerName from the first LedgerEntries Object which
satisfies the filter condition IsPartyLedger
263
Objects, Collections & Internal Object Structure
$$FilterQtyTotal
$$FilterQtyTotal is used to calculate the total of all the values of the expression evaluated for
each Object of the collection which satisfies the Filter condition. The expression needs to
evaluate to a value of Quantity Datatype.
Syntax
$$FilterQtyTotal:<CollectionName>:<FilterExpression>:+
<ValueExpression>
Where,
<CollectionName> is the name of a Collection
<FilterExpression> is a System Formula. The Filter Expression is evaluated for each Object
and the resultant Objects that clear the filter are selected for further processing.
<ValueExpression> refers to any valid expression to be evaluated on each Object of the Col-
lection.
Example:
[Field : Sample Field]
Set as : $$FilterQtyTotal:InventoryEntries:IName:$BilledQty
[System : Formula]
IName : $StockItemName = “Tally ERP 9”
The above example calculates the total of method BilledQty for all objects of the InventoryEn-
tries where the StockItemName is “Tally.ERP 9”available within the current Voucher Object
$$FilterAmtTotal
$$FilterAmountTotal is used to calculate the total of all the values of the expression evaluated
for each Object of the collection which satisfies the Filter condition. The expression needs to
evaluate to a value of Amount Datatype.
Syntax
$$FilterAmtTotal:<CollectionName>:<FilterExpression>:+
<ValueExpression>
Where,
<CollectionName> is the name of a Collection
<FilterExpression> is a System Formula. Filter Expression is evaluated for each Object and
the resultant Objects that clear the filter are selected for further processing
<ValueExpression> is any valid expression to be evaluated on each Object of the Collection
264
Objects, Collections & Internal Object Structure
Example:
[Field : Sample Field]
Set As : $$FilterAmtTotal:AllLedgerEntries:CashBankEntries:$Amount
[System :Formula]
CashBankEntries :($$IsCashLedger:$LedgerName) AND ($$IsDr:$Amount)
The above example calculates the total of method Amount for all objects of the AllLedgerEn-
tries where Ledger Name is a CashLedger and Amount is a debit amount available within the
current Voucher Object
Accounting Voucher
Vouchers in which only Account masters are used are termed as ‘Accounting Voucher’.
Receipt Voucher and Payment Voucher fall under this category.
As depicted in the above pictorial representation, Voucher Object is the Primary Object. All
Ledger Entries is the sub collection under Voucher Object which contains Sub Object ’Ledger
Entry’. Bill Allocations is a sub collection under Ledger Entry Object which contains ‘Sub
Object Bill Allocations’
265
Objects, Collections & Internal Object Structure
Inventory Voucher
Vouchers in which only inventory masters are used are termed as ‘Inventory Voucher’. Stock
Journal Voucher falls under this category.
As depicted in the above pictorial representation, Voucher Object is the Primary Object.
Inventory Entries In and Inventory Entries Out are the sub collection under Voucher Object
which contains Sub Object ’Inventory Entry’ respectively. Each of the Inventory Entry Object
may have Batch Allocations sub collection which contains ‘Batch Allocations’ sub object.
266
Objects, Collections & Internal Object Structure
As Voucher
Voucher is the traditional way of entering data. Debit and Credit is used to enter data. As
depicted in the above pictorial representation, Voucher Object is the Primary Object. Bill Allo-
cations, Interest Collection, Inventory Allocations and Category Allocations are the sub col-
lection under Voucher Object which contains Sub Object Bill Allocations, Vch Interest
Collection, Inventory Entry and Category Allocations respectively. Inventory Entry sub
Object may have sub collection Batch Allocations which contains Batch Allocations sub
object. Category Allocations sub object may have sub collection Cost Centre Allocations
which contains Cost Center Allocations.
267
Objects, Collections & Internal Object Structure
As Invoice
As Invoice is the most widely used format in Tally where Tally helps in various calculations.
While entering a Sales Invoice, all the duty and Tax calculations are done automatically. Also
Voucher Classes can be used only with As Invoice Format. While entering in Invoice Mode,
the Voucher Object Structure is as shown below:
Detailed hierarchy and schema reference of the various Internal Objects can be
referred to from the Schema Brow
268
Chapter 7: Action, Event Framework
and Key Definition
269
Action, Event Framework and Key Definition
This can be clearly understood with the pictorial representation as given below:
The Actions which gets triggered on the particular event occurrence can be of two types:
Predefined Actions
These actions are provided by the platform and can be triggered by using the specific keyword
provided for it.
User defined Actions
These are the Actions which can be defined by the programmer. The TDL procedural artifact
Function can be used to create such actions where the programmer has a complete control on
the desired functionality required.
270
Action, Event Framework and Key Definition
There is a difference in the manner in which a Predefined Action and a User Defined Action is
invoked.
7.1.2 Invoking Predefined Actions
In TDL, action has an action keyword. Display, Line Down, Form Accept etc. are the action
keywords. Some of the actions accept parameters and some do not.
Syntax
Action: Action Name [: Action Parameters]
In the above syntax:
Action is the keyword
Action Name specifies the name of the action to be performed. It can be any of the
predefined actions. Eg: Display, Print etc.
Action Parameters are set of parameters which are to be passed to the Action as
required
Example:
1. Action : Print Report
This actions prints the current report in context unless explicitly specified
271
Action, Event Framework and Key Definition
Code
[#Menu: Gateway of Tally]
Output
272
Action, Event Framework and Key Definition
Program Explanation
The above output shows the print preview of Balance sheet. It displayed by using the action
Print. When you select the menu item Invoking Predefined action, it will display the print con-
figuration screen to print the Balance sheet report. When you accept the screen, it displays the
print preview of Balance sheet.
273
Action, Event Framework and Key Definition
Code
[Menu : Exer Action Event Framework and Key definition]
Key Item : "Invoking Predefined Actions": P: Print: Balance Sheet
Key Item : "Invoking User defined Actions": U : CALL :+
Exer Invoking User Defined Action
274
Action, Event Framework and Key Definition
Output
275
Action, Event Framework and Key Definition
276
Action, Event Framework and Key Definition
277
Action, Event Framework and Key Definition
Program Explanation
For the above outputs are for Function Exer Invoking User Defined Action is invoked from
the menu item Exer Action Event Framework and Key definition itself. This is to print the
default reports like Trial Balance, Profit & Loss A/c, and Balance Sheet. Inside the function
MSGBOX is used to display the message This will print the Final Accounts to the user,
before invoking the above Print reports. The action Print is used for the same.
The SET attribute is used to set the value Yes for the variables DSPShowClosing, Explode-
Flag, ExplodeAllLevels. Based on this variable values the final accounts were printed.
7.2 Action Association
As we have already seen that, an Action can be triggered on the occurrence of either an User
Driven/System Driven Event. An User driven Event can be identified by defining a Key,
Button or a Menu Item. For identifying System Driven Event we have a predefined set of
Events available in TDL. These can either be specified at System level or at a particular defini-
tion level for which it is provided.
For handling User Driven Events the Action can be associated at
Key/Button Definition using the Action attribute
Menu Definition along with a Menu Item
Field Definition using the Action keyword
For handling System Driven Events the Action can be associated at
System: Event definition using the Event keyword provided
Specific definition level using the On attribute and Event Keyword
7.2.1 Action Association at Button/Key Definition
An Action can be triggered from a Button/Key definition by specifying the particular Action
using the attribute Action. The parameters to be supplied to the Action as required.
Syntax
[Button: Button Name]
Action: Action Keyword [: <Action Parameters>]
Where:
The Action Keyword can be any Global or Object Specific Action
The Action Parameter is as required by the Action Keyword. If the Action Keyword is
Menu, then the Action Parameter necessarily has to be a Menu Name, else if action name is
Create, Alter, Display then the action parameter should be a Report Name.
Example:1
Actions with Parameters
[Button: Outstandings]
Key : F5
278
Action, Event Framework and Key Definition
Example
[Menu: Commonly Used Reports]
Add: Key Item: Trial Balance: T: Display : Trial Balance
Add: Key Item: At Beginning: Outstandings: O: Menu : Outstandings
279
Action, Event Framework and Key Definition
In the above example, a Menu Commonly Used Reports is defined with two Items, viz.,
An Item Trial Balance is added displaying default report Trial Balance. Here, the
Action is Display and the Action parameter has to be a Report Name.
An Item Outstandings is added at the beginning to activate another Menu Outstand-
ings. The Action here is a Menu, so the Action Value required is a Menu Name.
Here ‘At Beginning’ is the value of position and ‘Outstandings’ is the display item
an ‘O’ is the unique key.
7.2.3 Action Association at Field Definition
Action Association at Field definition is done using the Action Keyword with the parameters
and the optional condition
Syntax
[Field: Field Name]
Action Keyword: Action Parameters [:< Condition >]
Where,
Action Keyword can be both, Global or Object Specific Actions
Action Parameters can be the Value on which these Actions could be performed
<Condition> is optional. This restricts the action to perform only if the Condition returns true
Example:
[Field: My Trial Balance]
Display : Group : $$IsGroup
Display : Ledger: $$IsLedger
In the example above, the Field Trial Balance has two statements, viz,
Displaying a Group if the current object in context is a Group
Displaying a Ledger if the current object in context is a Ledger
Typically, actions initiated through the selection of a Menu item or through an assignment to a
Key or a Button.
280
Action, Event Framework and Key Definition
Capabilities used
Action usage at Field level
Button & Key usage
Filter usage at collection level
Repeat attribute at part level to repeat the line over collection
Code
[Report: Exer Action Association at Field]
Form : Exer Action Association at Field
Title : "Object Association at Field"
281
Action, Event Framework and Key Definition
282
Action, Event Framework and Key Definition
[System: Formula]
Exer AAF NonEmptyLedgers: $$NumItems:LedgerEntries > 0
Exer AAF NonEmptyAmt : NOT $$IsEmpty:$ExerAAFLedgerAmt
;; End-of-File
Output
283
Action, Event Framework and Key Definition
284
Action, Event Framework and Key Definition
Program Explanation
This is to demonstrate the action association at field level. Action display is called from the
field Exer AAF PartyName. Inside the part Exer Action Association at Field the line Exer
AAF Details is getting repeated over the collection Exer AAF VchSummColl and this col-
lection holds the details about Ledgers.
Exer AAF LedgerName, Exer AAF LedgerAmt are the two methods which holds Ledger-
name and Ledger Amount respectively. The Fields Exer AAF PartyName, Exer AAF
PartyAmt were used to display the party name and Amount. The action Display is triggered
from the Field Exer AAF PartyName when an Enter is pressed on the current Field and the
default report 'LedgerVouchers' is being displayed. This report displays the vouchers of par-
ticular ledger stored in the variable called LedgerName.
7.2.4 Action Association at System Event Definition
System events are events for which no object context is available when they occur. Eg., Tally
application launch. An Action can be associated on occurrence of such an event by specifying
it within the System :Event definition.
285
Action, Event Framework and Key Definition
Syntax
[System: Events]
Label : EventKeyword : ConditionExpr : ActionKeyword :+
Action Parameters
Where,
<Label> is name assigned to the event handler. This has to be unique for each event handler.
<EventKeyword> can be any one of System Start, System End, Load Company, Close
Company.
<ConditionExpr> should return a logical value and the action will be performed only if the
condition returns TRUE
<ActionKeyword> is the Action which is to be triggered
<Action Parameters> parameters of the actions specified
Example:
[System: Events]
AppStart1: System Start : TRUE : CALL : MyAppStart
The function ‘MyAppstart’ is called as soon as Tally application is launched.
7.2.5 Action Association for Object Specific Events
The events that are performed only if the specific object context is available are referred as
Object Specific events. The Action can be specified on the occurrence of such an event by
using the ON attribute at the specific interface object definition level.
Syntax
ON : EventKeyword : ConditionExpr : ActionKeyword : +
Action Parameters
Where,
<EventKeyword> can be any one of Focus, Form Accept, Before Print and After Print
<ConditionExpr> should return a logical value
<ActionKeyword> is the Action which is to be triggered
<Action Parameters> parameters of the actions specified.
ON is a list type attribute, so list of actions can be executed sequentially when the specific
event occurs.
Example:
[Form : TestForm]
On :FormAccept :Yes :HttpPost :@@SCURL :ASCII :SCPostNewIssue : +
SC NewIssueResp
286
Action, Event Framework and Key Definition
The action Http Post is executed when the event Form Accept is encountered. But the form
will not be accepted until the user explicitly calls the action Form Accept on event Form
Accept as follows:
Capabilities used
Event On: Form Accept
The action CALL
Function definition and use of MSGBOX
Code
[Report: Exer Action Association at Event]
Form : Exer Action Association at Event
Title : "Action Assoication at Event"
287
Action, Event Framework and Key Definition
Output
288
Action, Event Framework and Key Definition
Program Explanation
The report is used to demonstrate the action association at Event. The form Exer Action
Association at Event includes On : Form Accept, when the user accepts the form Exer
Action Association at Event, it invokes the user defined function Exer AAE Func and the
input value is passing as function parameter.
The MSGBOX is used to display the message box with the accepted value.
The Event Framework will be discussed in the subsequent topics in detail where
all the events available in TDL will be taken up with relevant examples
289
Action, Event Framework and Key Definition
While walking downward direction it only searches which Interface object has the required
key associated with it. Once the key is found it will walk backward and the action will be
performed on the object associated with action if it is object specification.
If the key is not found then the [System: Form Keys] and global keys to be searched and once
the key is found the required action will be performed.
Consider the following diagram for understanding the action evaluation sequence.
290
Action, Event Framework and Key Definition
When an event occurs it search for originator starts from Report till Field. If the same key is
defined in multiple definitions then the lowest in the hierarchy get highest priority for execu-
tion. For Object Specific Actions the search for the executer object will start from field level
and progress till report level. Once the Executer object is found the action is executed.
From the above diagram, we can infer the following
Part, Line and Field are recursive
Forms cannot have forms
User can define keys and Form can have Button / Keys
Report can have System: Form Keys or System: Menu Keys.
Example:
At field level a key is defined for event Down Arrow and action is to be performed is Form
Accept. Now the action defined can’t be performed by a field it is a Form action. So now the
field is the Originator of the action whereas the Form is the Executor object of action.
Originator Executer
The Originator originates the action The Executer executes the action associ-
by associating the Key or a Button ated with the Key or a Button initiated by
the originator
System Actions can be originated by a System Actions can be executed by the
a Menu, Button/ Key, Field, Function one which has originated the Action.
or System/Object Specific Events However, Object Specific Actions can be
whereas Object Specific Actions can executed by the Objects that have not
be originated by a Menu, Form, Line originated the Action
or a Field
The sequence followed to gather all The sequence followed to consume the
the Keys originating within a Report Keys originated is from Bottom to Top
is Top to Bottom i.e., from a Report to i.e., from a Field to a Report Definition.
a Field Definition. The lowest in the In other words, the lowest in the hierarchy
hierarchy gets the highest precedence. get the highest preference. For example, if
For example, if the same key is asso- the same key is relevant for both Part as
ciated in both Form as well as Field well as Line Definition, the Key will be
Definition, the Key at Field Definition executed in the context of the Line Defi-
will be considered for execution nition
291
Action, Event Framework and Key Definition
Example 1 Example 2
[Key: Create Ledger] [Key: Part Display PgUp]
Key : Alt + C Key : PgUp
Action : Create : Ledger Action : Part PgUp
[Field: CST Supplier Ledger] [System: Form Keys]
Key : Create Ledger Keys : Part Display PgUp
Associating the Key with the Field, Key Part Display PgUp is originated by
Field is the originator as well as Form but its executer is the Part
executer in this case
292
Action, Event Framework and Key Definition
Example:
[Key: Cancel Object]
Key : Ctrl + X
Action : Cancel Object
Scope : Current
If Scope is not specified, it is defaulted to ‘Selected Lines’, if there are any selections availa-
ble, else it defaulted to current. This reduces the requirement for the number of ‘Key’ descrip-
tion and shortcut for each action, as most of the actions typically support a selected and current
scope, now this can be achieved by using a single ‘Key’. Note that if scope is specified the
behaviour will be identical.
For the actions Print Report, Mail Report, Export Report and Upload Report while writing the
action statement a report name can be given. This allows user to print a different report other
than using the report available in Context as specified in the Scope. In the absence of the
Report Name parameter the current report is taken. If the scope is not specified the default
scope is ‘Report’. Report Scope makes the Report Level Object available in the Acted Report
i.e. the report name specified with action.
7.5.1 Limitations and Tips for Actions
A ‘Menu’ Action acts only on a ‘Menu’ Definition, and vice-versa.
A ‘Report’ Definition can be acted upon by most of the other ‘Actions’ except
‘Menu’ Action.
If a Menu item doesn't have an Action, default will be ‘Quit’.
Action can also take arguments; these are separated by colon (:)
Exercise 7.4
Objective
The objective of this program is to understand the Action Association at Button with Scope
Capabilities Used
Scope attribute at Button Definition
Mode attribute at Button Definition
Actions Remove Line, Select All, Unselect All
293
Action, Event Framework and Key Definition
Code
[Report: Exer Button Action with Scope]
Use : Day Book
Delete : Form
Add : Form : Exer Button Action with Scope
294
Action, Event Framework and Key Definition
Output
Program Explanation
The above reports are displayed the daybook to demonstrate the scope of actions. The Buttons
called Remove selected, Remove unselected, select all, and unselect all are added to the
form Exer Button Action with Scope. The buttons trigger the Actions to select the lines,
unselect the line and remove the selected or unselected lines.
The first report shows the selected lines from the report by using the button Select All and the
scope of this report is set as selected lines. The second report the scope is set as unselected
lines.
295
Action, Event Framework and Key Definition
The Button Exer BAS RemoveSelected is defined with the action Remove Line and the
scope as Selected Lines, i.e., the action Remove line is performed only for selected Lines.
Refer all the buttons in the code for the action it triggers and the scope for which it is applica-
ble.
7.6 Dynamic Actions
Dynamic Action capability allows the programmer to execute actions based on dynamic eval-
uation of parameters. The Action keyword can as well be evaluated dynamically. Normally
this would be useful for specifying condition based action specification in menu, key / button
etc. In case of functions, as the function inherently supports condition based actions via IF
ELSE etc, this would be useful when one required to write a generic function, which takes a
parameter and later passes that to an action (as its parameter) which does not allow expres-
sions and expects a constant.
This has been achieved with the introduction of the keyword "Action”. The syntax for specify-
ing the same is as given below.
Syntax
Action :<Action Keyword Expression>: <Action Parameter +
Expression>
Where,
Action is the keyword "Action" to be used for Dynamic Actions usage
<Action Keyword Expression> is an expression evaluating to an Action Keyword
<Action Parameter Expression> is an expression evaluating to Action Parameters
We can specify and initiate an Action from the following
Menu Item
Key Definition
In a User Defined Function
At present the capability is valid for
System Actions like Display, Alter etc
System Actions inside User Defined Functions
Example:1
Dynamic Actions in Key/Button Definition
[Button: Test Button]
Key : F6
Action : Action : Display : @@MyFor
;; The Button Test Button initiates a dynamic Action which takes the parameter as a formula
296
Action, Event Framework and Key Definition
[System : Formula]
MyFor : if ##SVCurrentCompany CONTAINS "ABC" Then "BalanceSheet" +
else "TrialBalance"
Observe the usage of Action keyword twice in this. The first usage is the
attribute "Action" for key definition. The second is the keyword "Action" intro-
duced specifically for executing Dynamic Actions.
Example:2
Dynamic Actions in User Defined Functions
[Button: Test Button]
Key : F6
Action : Call:TestFunc:"Balance Sheet"
Code
[Report: Exer Dynamic Action]
Form : Exer Dynamic Action
Title : "Dynamic Actions"
297
Action, Event Framework and Key Definition
298
Action, Event Framework and Key Definition
Output
Program Explanation
The above report displays the list of actions to be triggered and the Report name on which it is
performed, based on the selection from the table. When the user accepts the form Exer
Dynamic Action, it triggers the user-selected action. ShortNameField holds the action name,
which has to be performed, and NameField holds the ReportName on which it is to be per-
formed. The values from the corresponding fields are passed as parameters to the action
Action which is used for trigerring the dynamic action.
299
Action, Event Framework and Key Definition
Action — Menu
A menu action acts only on the menu definition and vice versa. The value of a menu action
must be a Menu name. This menu has to be further defined to list the items displaying another
Menu or a Report. A menu definition continues until all the items are used to display Reports
and there are no further menu actions assigned to the final menu items.
Example:1
;; The following code demonstrates the usage of Action Menu along with further Menu Definitions
[#Menu: Gateway of Tally]
Add: Key Item: Sample Final Accounts : F : Menu : +
Sample Final Accounts
[Menu: Sample Final Accounts]
;; Menu Definition to display when the above Item is activated
Add : Key Item : Trial Balance : T : Display : Trial Balance
Add : Key Item : Profit & Loss : P : Display : Profit and Loss
Add : Key Item : Balance Sheet : B : Display : Balance Sheet
In the example mentioned above:
The default menu Gateway of Tally is altered to add a new item Sample Final
Accounts with Menu action displaying the Sample Final Accounts Sub Menu.
The Sub Menu Sample Final Accounts is defined to display all the components of
Final Accounts i.e.,
Trial Balance
Balance Sheet
All the Items here use the Display Action. Hence, no further Menu Definition is
required.
Example:2
/* The following code demonstrates the usage of Menu and Display Actions and also the relevance of their association in Menu
and Reports (through Form)*/
300
Action, Event Framework and Key Definition
301
Action, Event Framework and Key Definition
Color : Blue
Border : Thin Bottom
Key : Execute Hyperlink
Set as : "Tally Solutions Pvt. Ltd"
Local : Key :Execute Hyperlink: Action: Browse URL: +
http://www.tally.co.in
Action – Display Collection
A Menu Item or a Button can be used to display a popup of Object names in a Collection,
which in turn, can trigger a Report. On choosing an Object from the popup, a report in display
mode is triggered by the action, Display Collection. This action can be used for displaying the
Masters or Reports pertaining to Groups, Ledgers, Stock Items, etc.
Example:
;; The following code demonstrates the usage of Display Collection Action
[#Menu: Gateway of Tally]
Add : Key Item: Ledger : L : Display Collection : Ledger
;; where Ledger is a predefined Collection in DefTDL
302
Action, Event Framework and Key Definition
Though the Action name is Display Collection, Display is meant for the subsequent Report,
which will be displayed on selection of an Object. Here, the Report is in display mode.
Example 7.6
Objective
The objective of this program is to understand the Action 'Display Collection'. In this Code,
list of Groups are displayed in a Trigger Report and on selection, subsequent Report is
displayed with SubGroups, Ledgers along with their Closing Balances.
Capabilities used
Action Display Collection
Collection Definition and its attributes in context of usage with Display Collection
Usage of Trigger attribute
Code
;; This Collection 'Exer DC Group Summary' is used to Display when the Menu Item 'Display Collection' is selected by
user
[Collection: Exer DC Group Summary]
Type : Group
/* Collection Attribute 'Trigger' accepts a Report Name which is used to display the preselection Report with the Table
for Selection*/
Trigger : Exer DC GS Trigger Report
;; Collection Attribute 'Report' accepts a Report Name which is used to display the Report post selection of the Required
Object
Report : Exer DC GS Final Report
/*Variable 'GroupName' retains the selected variable from the Trigger Report and is used to display the Final Report for
the selected Object*/
Variable : GroupName
Filter : Exer DC Non Empty Bal
;; Initial Trigger Report begins here
303
Action, Event Framework and Key Definition
304
Action, Event Framework and Key Definition
305
Action, Event Framework and Key Definition
[System: Formula]
Exer DC Non Empty Bal: NOT $$IsEmpty:$ClosingBalance
;; End-of-File
306
Action, Event Framework and Key Definition
Output
307
Action, Event Framework and Key Definition
Program Explanation
The Action Display Collection is triggered from the menu item. Within the collection defini-
tion Exer DC Group Summary the Trigger attribute specifies the report name Exer DC GS
Trigger Report which pops up a table of Groups for the user selection. Based on the Group
object selected, the corresponding report Exer DC GS Final Report specified with the Report
attribute is displayed with the ledgers and subgroups belonging to the group object selected in
the trigger report. The collection Exer DC GS Grps and Exer DC GS Leds filters the groups
and the ledgers based on the group selected i.e it applies the Child Of attribute to filter the
ledgers and groups.
Action – Print Collection
Menu Action Print Collection triggers a list and it displays the final Report in Print mode
based on user selection. This action is used to print the Collection of objects. Eg; Stock
Vouchers, Ledger Vouchers, Ledger Out Standings etc.
Syntax
[Menu: Menu Name]
Add: Key Item: [Position] : <Display Item> :<Unique Key>+
: <Action Keyword>:<Action Parameter>
308
Action, Event Framework and Key Definition
Where,
Action Keyword can be Print Collection which triggers a list and displays the final report
based on user selection
Example:
[#Menu: Printing Menu]
Add: Key Item: My Ledgers : L : Print Collection: Ledger Vouchers
In the above example, we have added the Item My Ledgers, which has an action Print Collec-
tion associated to it. It displays a collection bearing the List of ledgers which on user selection
enters the final report in Print Mode. On accepting it directly goes to the printer.
309
Action, Event Framework and Key Definition
310
Action, Event Framework and Key Definition
Example:
[Key: Form Accept]
Key : Ctrl + A
Action : Form Accept
Mode : Edit
The declaration [System: Form Keys] declares a list of Keys that are commonly required for
any Report. Since all the common Form operations like Save Form, Reject Form, Form End,
etc. are declared here; a new Form added does not require these keys to be associated since
they are inherited from the above declaration.
311
Action, Event Framework and Key Definition
Mode : Display
The declaration [System: Form Keys] declares a list of Keys that are commonly required for
any Part. Since all the common Part operations like Part Home, Part End, Part PgUp, etc. are
declared here; a new Part added does not require these keys to be associated since they are
inherited from the above declaration.
312
Action, Event Framework and Key Definition
The declaration [System: Form Keys] declares a list of Keys that are commonly required for
any Line. Since all the common Line operations like Explode, Display Object, Alter Object,
etc. are declared here; a new Line added does not require these keys to be associated since they
are inherited from the above declaration.
Example:
[Key : Field Copy]
Key : Ctrl + Alt + C
Action : Field Copy
313
Action, Event Framework and Key Definition
[Key: Calculator]
Key : Alt + C
Action : Calculator
Mode : Edit
The declaration [System: Form Keys] declares a list of Keys that are commonly required for
any Field. Since all the common Field operations like Field Copy, Field Paste, Field Erase,
etc. are declared here; a new Field added does not require these keys to be associated since
they are inherited from the above declaration. The Action Calculator is not required for all the
Fields hence it has not been declared in Form Keys usage List. The Action Calculator has
been associated to Fields where it is required. In the above example, NumDecimals Field is a
numeric field which may require calculations. Therefore, the Calculator Key associating the
Action Calculator is attached to the Field.
The complete listing of the various Predefined Actions and the related help is
available within the Action Browser provided with Tally.Developer 9.
314
Action, Event Framework and Key Definition
315
Action, Event Framework and Key Definition
316
Action, Event Framework and Key Definition
Same key combination can be repeated across reports functioning indifferently of each other.
An example in default TDL can be that of ALT+C. It triggers actions such as Create Ledger,
Create Group, Create Cost Centre, Create Stock Item, Calculator, advanced calculator etc.
Example:
(i) Path: “master\mbasic.500”
[Button: Master Group]
Key : Ctrl+G
Action : Replace : Group
Title : $$LocaleString :”Groups”
317
Action, Event Framework and Key Definition
If you create the Buttons, it will be visible in the tally screen. But, the key is not.
Where Next Report is key already defined in TDL. Following are the actions which can be
specified with the attribute Action.
Key Actions:
Set : Variable Name or Field Name: Formula
Multi Field Set : List of Field Names: Formula
Auto Set : Field Name : Formula
318
Action, Event Framework and Key Definition
Example:
(i) Path: “voucher\vchkeys.500”
[!Button : Normal RejOut Button]
Action : Set : SV Voucher Type: $$VchTypeRejOut
(ii) Path: “voucher\vchkeys.500”
[Button: Master Group]
Key : Ctrl+G
Action : Replace: Group
Title : $$LocaleString:”Groups
The attribute Action List
Syntax
Action List : <Key / button name/s>
319
Action, Event Framework and Key Definition
The attribute Action List allows the TDL programmer to activate more than one action at a
time. The parameters given are key / button names. These parameters (Key / button names)
have to have the same key combinations as the key where in the attribute Action List is
defined.
A typical example of the application of this attribute is the Quick Format / Neat Format button
which automatically selects / de-selects the columns / fields depending upon whether the form
is printed in draft mode or neat mode.
Example:
(i) Path: “voucher\vchkeys.500”
[Button: VCHInventory]
Key : F1
ActionList: VCH Set Inventory, VCHPayroll
(ii) Path: “voucher\vchkeys.500”
[Button: SalesOrderButton]
Key : Alt+F5
Title : $$LocaleString:”Sales Order”
ActionList: VCHInventory, SetChgSalesOrder, SetSalesOrderType
The attribute Mode
Syntax
Mode: [Display / Edit / Both]
The attribute Mode specifies whether the action associated to the key has to be applied in
Display mode, Edit mode or both the modes. If this attribute is not specified in the Key defini-
tion, then the default mode is Both.
Example:
(i) Path: “keys.500”
[Key: Field Insert Mode]
Key : Insert
Action : Field Insert Mode
Mode : Edit
(ii) Path: “keys.500”
[Key: Field Display Next]
Key : Right
Action : Field Next
Mode : Display
320
Action, Event Framework and Key Definition
The key can be made identifiable by using the rules given below.
The key should be a function key: F1, F2 etc.
The key could be defined based on the following combinations
Function keys from F1 to F12
Combination of Ctrl/Alt + Function keys
Combination of Ctrl/Alt + Alphabet etc.
If the key is defined, using the combination of alphabets then that alphabet
should be a part of the key definition name.
The Button and Key definition do have a co-relation. Key can exist by
itself whereas Button always needs a Key to be defined.
321
Action, Event Framework and Key Definition
System Events
In TDL a new type “Events” is introduced in System definition. All the system events are
defined under this definition. As of now TDL event framework supports following four
system events viz. System Start, System End, Load Company, Close Company.
322
Action, Event Framework and Key Definition
Syntax
[System: Events]
Label : EventKeyword : ConditionExpr : ActionKeyword :+
Action Parameters
Where,
<Label> is name assigned to the event handler. This has to be unique for each event handler.
<EventKeyword> can be any one of System Start, System End, Load Company, Close
Company.
<ConditionExpr> should return a logical value
<ActionKeyword> any one of the actions
<Action Parameters> parameters of the actions specified
The events System Start, System End are executed when the user launches or quits Tally appli-
cation respectively.
The events Load Company, Close Company are executed when the user loads or closes a
company respectively.
Example:
[System: Events]
AppStart1: System Start : TRUE : CALL : MyAppStart
The function ‘MyAppstart’ is called as soon as Tally application is launched. The following
are mainly used system events in TDL.
System Start
System End
Load Company
Close Company
7.10.3 Object Specific Events
Objects specific events can be specified for the associated object only. Eg. Before Print event
is specific to report object.
The attribute ON is used to specify the object specific events as follows:
Syntax
ON : EventKeyword : ConditionExpr : ActionKeyword : +
Action Parameters
323
Action, Event Framework and Key Definition
Where,
<EventKeyword> can be any one of Focus, Form Accept, Before Print and After Print,
on:Import etc.
<ConditionExpr> should return a logical value
<ActionKeyword> any one of the actions
<Action Parameters> parameters of the actions specified.
ON is a list type attribute, so list of actions can be executed sequentially when the specific
event occurs.
324
Action, Event Framework and Key Definition
325
Action, Event Framework and Key Definition
With the introduction of Events, Start Import, Import Object and End Import, the programmers
have got complete control to manipulate the data prior to importing the same into the
company. This can be useful in scenarios like data transfers between Inter Branch where
Delivery Note in a branch gets transformed into Receipt Note in the second branch; Sales
transaction in a Branch gets transformed into Purchase transaction in the second branch and so
on. Also, an action Import Object is introduced to begin the Import.
The following example gives the complete idea about the three events which we discussed
now. Here in this example, before importing the data, Narration Method is being altered and
first Ledger Name is being altered to the Branch Ledger. Before starting and after ending the
import process, appropriate messages are being displayed to the user.
Example:
[#Import File: Vouchers]
On : Start Import : Yes : Call : Start Import
On : Import Object : Yes : Call : Change Values
326
Action, Event Framework and Key Definition
Exercise 7.7
Objective
The objective of this program is to understand the usage of the Event 'On Focus'
Capabilities Used
On : Focus at Part, Line & Field
Function definition with Parameter
The use of $$Line
Code
[Report: Exer Event On Focus]
Form : Exer Event On Focus
Title : "Event On Focus"
327
Action, Event Framework and Key Definition
328
Action, Event Framework and Key Definition
Output
Program Explanation
The above report is used to display values in different fields by using on focus action.
Whenever the field get focus then the event get triggered and displays the corresponding
string. Here $$Line is used to get the line number.
Whenever the Line number is greater than 1 then the function Exer On Focus Line called and
it displays one message box with the information on next focus.
329
Chapter 8: Object Manipulation and
Storage in TDL
We have covered the concept of Objects, Methods and Collections in detail in the previous
chapters. There we had concentrated mainly on understanding the object structure, construction
of collections and retrieval of data from the Objects already stored as a part of the Tally
Database.
In this chapter our focus will be on the creation and manipulation of Objects and storing the
same in the Tally Database.
8.1 Object Manipulation & Storage An Introduction
As we already discussed, always information is stored in an object. Internal Objects are objects
provided by the platform. These data objects which are stored as a part of Tally Database can
be manipulated by Tally user i.e., Data can be added, deleted or updated from within Tally.
There are several Internal Objects like Company, Group, Ledger, Stock Group, Stock item,
Unit of measure, Voucher Type, Cost Category, Cost Centre, Budget and so on.
In order to manipulate or retrieve information into the Data Object through the User Interface,
the Data Object needs to be associated with the Interface Object. We have covered the various
association methodologies at the Report, Part, Line and Field level in the chapter on “Objects,
Collections & Internal Object Structure”. Our discussion there was focused on data retrieval
only. Predefined internal methods accessed using ‘$’ is used for data retrieval.
When we talk about manipulation of data, it means that either we need to store an altogether
new data or update the existing data which is stored as a part of the Internal Object. It is very
important to understand the existing structure of the specific Internal Object which is to be
manipulated. Whether it is creation of a new object or updation of an existing object the object
structure has be strictly adhered to. An Object in Tally follows the hierarchical data structure
i.e., an object can consist of methods and sub collections where each sub collection can have
methods and sub collections within it, and this structure can continue up to infinity. When an
Object needs to be manipulated with a particular data/information it needs to be reflected
against the predefined storage name associated with it. The storage name is same as the method
name available with the Object.
331
Chapter 8 - Object Manipulation & Storage in TDL
Detailed hierarchy and schema reference of the various Internal Objects can be
referred to from the Schema Browser Tab available with Tally.Developer 9
332
Chapter 8 - Object Manipulation & Storage in TDL
The value entered in the field will be stored in the method “Name” of the first object of the
Collection “CollName”.The field is in context of the Object where the collection specified is
available.
Values entered by the user in the Fields within the Report must be stored in relevant
Meth¬ods using Field Attribute- Storage
A Report usually will be associated with a data object, which it inherits from the previous
Report. In case it is the parent Report and no explicit association exists it will be associated
with anonymous object. The Report needs to be opened in the Create or Alter mode as
required.
There are specific Actions to launch a Report in Editable mode. These are the actions Create
and Alter. Create Action is used when a new object needs to be created and stored whereas an
Alter Action is used when some updations are to be performed on an existing Object.
There are specific Actions like “Create Collection” and “Alter Collection” which are used to
Create/Alter specific Objects of the Collection.
Now we will look into detail about how to Create /Alter Objects using the Actions as
mentioned above
333
Chapter 8 - Object Manipulation & Storage in TDL
All the persistent variable values can be stored in a Configuration File Tal-
lysav.tsf to be retained across sessions. We will be discussing more about
variable in the subsequent chapters.
Exercise 8.1(a)
Objective
The objective of this program is to understand how to create an Internal Object using Action
Create and the attribute Storage.
Capabilities Used
Usage of the action Create
Object Association at the report level
The field attribute- Storage
The attribute Table at Field level
Code
[Report: Exer Action Create]
Form : Exer Action Create
;; Object Association done at Report Level
Object : Ledger
Title : "Action Create"
334
Chapter 8 - Object Manipulation & Storage in TDL
Output
Program Explanation
Report Exer Action Create is associated with the Object Ledger which indicates that the
Report is meant for creating an instance of the Object Ledger.
The Name and Group information entered in the fields are stored in the Internal Methods
Name and Parent. This is done by using the attribute storage at the field level.
The field which accepts the value for the method parent displays the table of groups for user
selection.
335
Chapter 8 - Object Manipulation & Storage in TDL
Report invoked using the Action Create is terminated as soon as it is saves and return to the
menu. When the action Create Collection is used the Report is invoked repeatedly allowing
the creation of multiple objects till the user quits from the Report.
This action is generally used for creation of Masters such as Groups, Ledgers, Stock Items,
Voucher Types, etc.
Exercise 8.1(b)
Objective
The objective of this program is to understand how to create an Internal Object using Action
Create Collection.
Capabilities Used
Usage of the action Create Collection
Collection Attribute Type and Report
The attribute modifier Use at Report level
Code
[Menu: Exer Object Manipulation and Storage]
Key Item : "Action Create Collection": O : Create Collection:+
Exer Action Create Collection
/*This Collection triggers Report 'Exer Action Create Collection' which is used to Create the Objects. It creates collection
of objects, i.e., On creation of one Ledger, it will continue in the same screen for second*/
336
Chapter 8 - Object Manipulation & Storage in TDL
Output
Program Explanation
The menu item Exer Object Manipulation and Storage triggers the Action Create Collection
which takes the Collection “Exer Action Create Collection” as the parameter.
The collection “Exer Action Create Collection” is a Collection of type ledger. The Report
attribute of the collection specifies the name of the Report “Exer Action Create Collection”
which is launched in Create mode.
The definition for the report Exer Action Create is same as defined under the section Action-
Create.
Action – Alter
The Alter action also acts upon the Report definition. This action launches the Report in Alter
mode. The Report is invoked in the editable mode where the user can enter values within the
fields. These values are retained within the Tally Database as a part of Internal Object This
action is used when an existing Object is to be updated and persisted in the Tally database.
Example:1
[#Menu: Gateway of Tally]
Add: Key Item: Ledger Alteration: L : Alter: Alter Ledger
[Report: Alter Ledger]
Form : Alter Ledger
Object: Ledger : “ABC Ledger”
;; Object Association done at Report Level
In the example
Default Menu, Gateway of Tally have been altered to add a new Item Ledger Altera-
tion which allows the user to update an existing Ledger
Report Alter Ledger is associated with the Ledger Object “ABC ledger” which indi-
cates that the Report is meant for altering the specific ledger Object already existing
in the Tally Database
The storages for Name and Parent are defined in the same way as taken up in the
“Create Ledger” Report
Example:2
337
Chapter 8 - Object Manipulation & Storage in TDL
In the following example it demonstrates the usage of Alter action at button definition
[Button: My Reco Button]
Key : Alt + F5
Action: Alter: Bank Recon
;; Alter Action to trigger Bank Recon Report in Alter Mode
Title : “Reconcile”
Exercise 8.2
Objective
The objective of this program is to understand how to manipulate internal object using Field
Attribute 'Alter'.
Capabilities Used
The Field attribute Alter
The attribute Key at Line Definition
The attribute object at report level
Code
[Report: Exer Field Attribute Alter]
Form : Exer Field Attribute Alter
Title : "Field Attribute Alter to alter objects"
338
Chapter 8 - Object Manipulation & Storage in TDL
Set As : $Name
;;Variable 'LedgerName' retains the Ledger selected by the user for the subsequent report
Variable: LedgerName
339
Chapter 8 - Object Manipulation & Storage in TDL
340
Chapter 8 - Object Manipulation & Storage in TDL
[System: Formula]
Exer FAA NonEmptyCB: NOT $$IsEmpty:$ClosingBalance
;; End-of-File
Output
341
Chapter 8 - Object Manipulation & Storage in TDL
Program Explanation
The report Exer Field Attribute Alter is used to alter the ledger objects by using the field
attribute Alter. Two default Keys called Line Object Enter Alter, Line Click Object Enter Alter
are associated to the Line Definition Exer FAA Details that allows a selection of any of the
lines being repeated. Action associated with these Keys is Alter Object which means on hitting
the Key, the Object associated with the current Line must be altered
The attribute Alter is used at Field definition Exer FAA Name invokes the Report “Exer
Alter Ledger” in Alter Mode
The Report Exer Alter Ledger is associated with the Ledger Object, which is in context of the
field Exer FAA Name, and the variable Ledger Name retains the ledger name selected by the
user for the subsequent report Exer Alter Ledger.
342
Chapter 8 - Object Manipulation & Storage in TDL
For alteration, the Object to be altered needs to be selected from a different Report. This is
specified by using the attribute “Trigger” of the collection.
This action is generally useful for alteration of Masters such as Groups, Ledgers, Stock Items,
Voucher Types, etc.
Example:
;; The following code demonstrates the usage of Alter Collection Action
[#Menu: Gateway of Tally]
Add: Key Item: Ledger Alteration: L: Alter Collection: Ledger Coll
;; Collection definition Ledger Coll
[Collection : Ledger Coll ]
Type : Ledger
Report : Alter Ledger
Trigger : Select Ledger
Variable : Led Name
;;Report Definition “Alter Ledger” associated with the Object Ledger
[Report :Alter Ledger]
Object :Ledger
|
|
;;Trigger Report “Select Ledger” which allows selection of the specific ledger object for alteration in the Report “Alter Ledger”
[Report : Select Ledger]
|
|
;;Field within this report which displays a table of ledgers for selection
[Field: Set My Ledger]
Use : Name Field
Table : Ledger Coll
Show Table : Always
Modifies :LedName
In the example
The menu item triggers the Action Alter Collection which takes the Collection
“Ledger Coll” as the parameter.
The collection “Ledger Coll” is a Collection of type ledger. The Report attribute of
the collection specifies the name of the Report “Alter Ledger” which is launched in
Alter mode.
343
Chapter 8 - Object Manipulation & Storage in TDL
The Trigger attribute of the collection specifies the name of the Report “Select
Ledger” which allows the selection of a particular ledger within the field.
The field “Set My Ledger” displays a table of ledgers and modifies the value of the
variable “LedName” with the object name selected in the Trigger report
The Variable attribute in the collection specifies the variable which holds the name
of the Object selected above and subsequently in the Report “Alter Object”
The implementation and usage for the Actions Display Collection and Print
collection is done in the same way as Alter Collection. The Object selected in
the Trigger Report is subsequently displayed or Printed within the main Report
specified with the Report Attribute of the collection..
344
Chapter 8 - Object Manipulation & Storage in TDL
In case the Action is triggered from a menu, the primary object specification is man-
datory, as menu will never have a Data Object in context
A single Modify Object Action cannot modify methods of multiple primary Objects,
but can modify multiple methods of a single Object.
Example:1
[Key: Alter My Object]
Key : Ctrl + Z
Action : Modify Object : (Ledger,"MyLedger").BillAllocations+
[First, $Name="MyBill"].OpeningBalance : 100,+
..Address[Last].Address : "Bangalore"
The existing ledger My Ledger is being altered with new values for the Opening Balance for
the existing bill and Address. The key Alter My Object can be attached to any Menu or Form.
Example:2
[Key: Alter My Object]
Key : Ctrl + Z
Action : Modify Object :(Ledger,"MyLedger").BillAllocations[1] +
.OpeningBalance :1000,Name: ”My New Bill”,..Address[First]+
.Address :"Hongasandra Bangalore" , Opening Balance:5000
The existing ledger My Ledger is being altered with new values for the Opening Balance
applicable on the existing bill, Opening Balance of the ledger and the first line of the Address.
The key Alter My Object can be attached to any Menu or Form.
Example:3
[Key: Alter My Object]
Key : Ctrl + Z
Action : ModifyObject : LedgerEntries[1].BillAllocations[1].Name:+
“Test1”, Amount :“1000.00”, ..BillAllocations[2].+
Name: “Test2”, Amount : “2000.00”, ().Date : “1.4.08”
In a Voucher context, Key Alter My Object alters Name, Amount and Date methods of Sub
object Bill Allocation.
8.1.4 Action Modify Object in a Menu Definition
A button Alter My Object is added within the menu definition
345
Chapter 8 - Object Manipulation & Storage in TDL
346
Chapter 8 - Object Manipulation & Storage in TDL
347
Chapter 8 - Object Manipulation & Storage in TDL
Program Explanation
The user defined function Exer Action Modify Object is used to modify the opening balance
of the ledger “cash” to 150000 by using the action Modify Object and it displayed a message
by using the action MSGBOX.
Further, the action SET is used to set the value of the variable SLedger. The variable SLedger
is used as an object identifier for the subsequent default report “Ledger”. The action Display is
used to display the report “Ledger” with the object “cash” which is associated at the report
level.
348
Chapter 8 - Object Manipulation & Storage in TDL
Syntax
Action: Set Object Values: <SubObjectPathSpec>.<Method Name>:+
<Method Value>
Where,
<SubObjectPathSpec> is given as CollectionName [<Index Formula>, [<Condition>]]
<MethodName> refers to the name of the method in the specified path and
<Method Value> is the value to be set for the <Method Name>.
Example:
[Key : My Key]
Action : Set Object Values : Opening Balance : ($$AsAmount : 10)
This action alters the current object in memory. When the Primary object is saved the changes
will be updated in Tally database.
349
Chapter 8 - Object Manipulation & Storage in TDL
We will be taking up the detailed explanation and usage of these Actions and
Object Manipulation as a whole in the subsequent chapter on TDL procedural
Capabilities
8.3 Object Manipulation using Data gathered from External Data Sources
To meet the challenges of business environment it becomes absolutely mandatory to share
information seamlessly across applications. Integration becomes a crucial factor in avoiding
the duplication of data entry. There are many interfaces through which the applications can
integrate. Different applications use different interfaces for communicating with each other.
Examples of interfaces are ODBC, XML, SOAP, DLL etc.
We have already seen in the previous chapter that, data available over these interfaces can be
gathered for further processing into a Collection. Subsequently, this can be stored as an
Internal Object and form an integral part of the Tally Database either through a Report or using
the data manipulation capabilities of TDL/User Defined Functions.
Data available in SDF format can be imported in Tally by defining the file structure using
“Import File” definition and mapped to the an Internal Object using the “Import Object” defi-
nition.
Syntax
Storage at Import Object Definition
Storage : Storage Name : #FieldName
Example:
[!Import File: Ledger Import]
Repeat : #ImpLedName
Field : ImpLedName : 30
Field : ImpLedGroup : 30
Field : ImpLedOpBal : 15
Field : ImpSVStatus : 2
Field : CRLF : 2
;; Carriage Return Line Field
Object: LedgerObj
Empty : #SVStatus = "P"
350
Chapter 8 - Object Manipulation & Storage in TDL
In the example an Import File is created where the fields are defined with the specified width.
The corresponding Import Object definition associates the Object Ledger using the Object
attribute. The storage attribute is used to map the fields with the corresponding method/storage
names.
[Import Object: LedgerObj]
Object : Ledger
;; Ledger is an internal object.
Storage : Name : #ImpLedName
Storage : Parent : #ImpLedGroup
Storage : OpeningBalance : #ImpLedOpBal
For the detailed usage and examples refer the book “Tally.ERP 9 – Integration
Capabilities”
351
Chapter 9: TDL Procedural
Capabilities
9.1 Introduction
When we talk in general, from any programming language point of view there are Procedures
and Functions which are used to perform any Action either by returning a value or not. Proce-
dures are a fixed set of statements that are executed sequentially to perform a task. The same
task might be performed repetitively. Subroutines are procedures which are executed repeat-
edly. Generally subroutines are called from the main program. Procedures can accept zero or
more parameters as input to perform the specified operation. Some procedures which return a
value to the calling environment are generally referred as Functions.
As we already know, TDL is basically a non procedural language which allows the programmer
to specify the actions required to perform a task. The sequence in which these Actions get
triggered is purely based on user interaction. The Actions in turn act upon a particular defini-
tion. In TDL procedural capabilities are added with the introduction of a definition “Function”.
The fundamental aspects of conditional evaluation and looping have been introduced into the
language. The various procedural elements can be used for flow control, computation and
object data manipulation.
When a function is used to perform a specified task without returning a value, it can be
triggered as an “Action” on the occurrence of a System or User Driven event. When the
function is created primarily with an objective of achieving some computation result, it can be
referred from a field or an expression in the same way as In Built/Platform defined Functions.
Please refer to function browser provided along with Tally Developer 9 for a
detailed documentation on built in functions
353
TDL Procedural Capabilities
With the introduction of the definition Function, programmer has the capability to create
Functions as per his requirements and trigger it as an Action or as an In built function. We will
be referring to Functions created by the programmer as TDL/User Defined Functions.
The functions in TDL can be broadly classified into two categories:
1. In Built/Platform Defined Functions
2. TDL/User Defined Functions
TDL procedures may depend upon/call platform functions to perform some specific task. If a
function with the same name exists in the default TDL source code then the In Built functions
always take precedence over the user defined functions.
354
TDL Procedural Capabilities
In TDL, the definition type Function is used to create functions. Let take a look at the function
definition which is used to calculate the simple interest. It accepts three parameters as princi-
ple, rate and time period.
[Function: SI Calc]
;; Definition Block
Parameter: P : Amount
Parameter: R : Number
Parameter: T : Number
Returns : Amount
Variable : Interest: Amount
;; Procedural Block
01 : SET : Interest: (##P * ##R * ##T) / 100
02 : RETURN: ##Interest
The function definition is divided in two blocks viz. Definition and Procedural. The valid
statement in each block will be discussed in detail in the section ‘Function - Building Blocks’.
We have partly discussed on how a Function can be called as Actions in the chapter on
Actions. We will cover this in detail in the following section.
Calling a Function
Basically a Function is created with two purposes:
1.To be used as an Action performing a particular set of tasks without returning a value
The action thus created can be triggered on the occurrence of a System Driven/User Driven
Event.
For handling User Driven Events the Action can be associated at:
Key/Button Definition using the Action attribute
Menu Definition along with a Menu Item
Field Definition using the Action keyword
For handling System Driven Events the Action can be associated at:
System: Event definition using the Event keyword provided
Specific definition level using the On attribute and Event Keyword
355
TDL Procedural Capabilities
2.To be used as a Function performing some complex computation and returning the
value/result to the calling program
In such cases the Function will be called from a field or an expression where certain values
will be passed from the caller context to the function. The function performs some computa-
tions and returns the result/value to the calling field/expression.
356
TDL Procedural Capabilities
<Parameter List> is the list of parameters required by the procedure to perform the specified
task successfully. It’s optional.
Example:Calling the function at Field using $$
[Field: Call Function]
Use : Number Field
Set as : $$FactorialOf:#InputFld
The action CALL allows the spaces in function name where as if $$ is used then
the spaces are not allowed in the function name.
Passing Parameters
As explained earlier, the TDL Function may require some input from the calling environment
to perform the specified operation. The number of parameters required to be passed to the
function depends on the number of Parameters declared in the function definition. A default
value can be specified for the parameters. These parameters are considered as optional i.e.
while calling the function the values passed for this parameter is optional
The parameters can be passed as expressions to the function while invoking it. While calling
the procedure or function the parameters are separated by “:”. If less number of parameters are
passed then the remaining parameters must be defined as option parameter in the function def-
inition. If the number of parameters that are passed is more than the required parameters then
the remaining parameters are treated as a single value for the last parameter.
For eg: If a function takes three parameters, it is possible to pass only one or two parameters
while calling the functions, if default values for those parameters are specified inside the
function declaration.
Example:The function SICalc accepts three parameters but is a can be called as follows:
[Field : Simple Interest]
Set As : $$SICalc:#InterestPrincipal:#InterestRate
The value for the last parameter is specified in the declaration itself.
For e.g.: If a function takes three parameters and while calling if more than three parameters
are passed then, after considering values for two parameters, all the successive values
separated by colon are taken as third parameter.
357
TDL Procedural Capabilities
Example:The function SICalc accepts three parameters but is a can be called as follows:
After understanding the TDL procedure overview, now let’s understand the various statements
in the Function definition.
9.3 Function – Building Blocks
As explained earlier, the TDL functions are defined using the definition type Function. All the
statements specified in the function definition are implemented as Predefined Actions. We will
be referring to them as programming constructs and statements as per generic programming
norms.
The Function definition is divided in two blocks viz. Definition Block and Procedural Block.
Let’s take a glimpse on the structure of a Function.
358
TDL Procedural Capabilities
Returns : DataType
;; Procedural Block
Label 1 : Statement 1
Label 2 : Statement 2
|
Label n : Statement n
Definition Block
The definition Block is utilized for declaring various components that the TDL procedure will
require to perform the Tasks. The parameter, variable, object, local formulae and the return
data type are specified in this block. The definition block is followed by Procedural block in
which all the procedural statements are specified to perform the task.
Parameter Declaration
This is used to declare the list of parameters to be passed while calling code. The values
passed to the function are referred with these variable names inside the function. The attribute
Parameter of Function definition is used for specifying the parameters. The attribute Parameter
is of type Dual List.
Syntax
PARAMETER : <Variable Name> : <Data Type of the Variable>
Where,
<Variable Name> is the name of the Variable which holds the parameter sent while calling
the TDL procedure.
<Data Type of the Variable> is the Data type of the Variable sent while calling the TDL pro-
cedure.
359
TDL Procedural Capabilities
Syntax
VARIABLE : <Variable Names> [:<Data Type> [: <Value>]
Where,
<Variable Names> is the comma separated list of Simple or Compound Variables.
<Data Type> is an optional parameter to specify the data type of Simple Variable. If the data
type is specified, then it is called Inline declaration of variable. In case of Compound Variable,
data type cannot be specified here as it consists of members belonging to various data types. If
the data type is not mentioned, the primary variable definition is mandatory.
<Value> is an optional parameter used to specify the default/initial value provided for the
variable.
Example:The TDL procedure ‘FactorialOf’ requires intermediate Variables ‘Counter’
and ‘Factorial’ for calculation within the Function Definition.
[Function: FactorialOf]
Parameter : InputNumber : Number
Variable : Counter : Number
Variable : Factorial : Number
360
TDL Procedural Capabilities
Syntax
STATIC VARIABLE :<Variable Name> [:<Data Type of the Variable>]
Where,
<Variable Name> is the name of the Static Variable
<Data Type> is an optional parameter to specify the data type of Simple Variable. In case of
Compound Variable, data type cannot be specified here as it consists of members belonging to
various data types. If the data type is not mentioned, the primary variable definition is manda-
tory.
Example:
The static variable ‘Sample Static Var’ retains the value between successive calls to TDL
procedure ‘Static Var in Func’
[Function: Static Var in Func]
Static Variable : Sample Static Var : Number
Object Specification
TDL procedure will inherit the Object context of the caller. This can be overridden by using
the attribute Object for function definition. This now becomes the current object for the TDL
function.
361
TDL Procedural Capabilities
Syntax
Object: <Object Type> : <Object Identifier>
Where,
<Object Type> is the type of the object
<Object Identifier> is the unique identifier of the object
Example:
The current Object context for the TDL function ‘Sample Function’ is the Ledger ‘Party’
[Function: Sample Function]
Object : Ledger : “Party”
Example:
[Function: LV Index Based Retrieval]
Local Formula: Total List Items : $$ListCount:LVEmpIndex
Where,
<Data Type of the Return Value > is the Data type of the return value of the Function
362
TDL Procedural Capabilities
Example:
The Function ‘FactorialOf’ returns value of type ‘Number’ to the caller of the Function
[Function: FactorialOf]
Parameter : InputNumber : Number
Return : Number
Variable : Counter : Number
Variable : Factorial : Number
9.3.1 Procedural Block
This block contains a set of statements. These statements can either be a programming
construct or can be an Action specification. Every statement inside the procedural block has to
be uniquely identified by a label specification.The programming constructs are implemented
internally as Actions Only.
363
TDL Procedural Capabilities
User has option to override the context within the TDL function later or use the same context
being passed. He can change the current and target object at any point and also switch target
and current object with each other.
9.4.2 Parameter Evaluation Context
It is important to note that the parameter values which are passed to the TDL function are
always evaluated in context of the caller. Parameter declaration within the TDL function is just
to determine the data type, order and no of parameters. These are basically the placeholders for
values passed from caller object context. The target object context or context switch within the
TDL procedure does not affect the initial values of the parameters. Later within the TDL
procedure these values can be altered just like ordinary variables.
9.4.3 Return Value Evaluation
We have already discussed above that TDL function can return a value. This can be specified
by the TDL function by indicating the data type of the value it returns, no specification
assumed as a void TDL function (a TDL procedure / function which does not return a value).
Each statement used can return a value. This depends on the individual action. Some actions
may not return value. The data type of return value is also predefined by the action. Return
value of the last action executed can be extracted using an internal function ‘$$LastResult’.
Any error messages generated from the system can be obtained with $$LastError. This can
only be used to determine the result of the intermediate statements used within the TDL
function. The final value which is to be returned from the TDL function has to be explicitly
given using the RETURN attribute.
Function – $$TgtObject
The Context Evaluation function $$TgtObject evaluates the expression in the context of the
Target Object. Using the $$TgtObject values can be fetched from the target object without
making the target object as the current context object.
Syntax
$$TgtObject:<String Expression>
Where,
<String Expression> the expression and will be evaluated in the context of Target Object
Example:
The Ledgers Party 1 and Party 2 having some opening balance. The requirement is to add the
opening balance of both the party’s and set the resultant value as the opening balance of Party
2.
[Function: Sample Function]
Object : Ledger : "Party 1"
364
TDL Procedural Capabilities
Here Party 1 is the source object and Party 2 is the target object. The opening balance of
Party 2 is accessed using the $$TgtObject:$OpeningBalance.
Looping Constructs
Control Constructs
Actions
System Actions
Debugging Actions
365
TDL Procedural Capabilities
Syntax
IF : <Condition Expression>
STATEMENT 1
|
|
STATEMENT N
ENDIF
Where,
<Condition Exprn> is an expression which returns a logical value. If it is TRUE then the
specified statements are executed.
Example:
Lets take the example of writing a function code to calculate the factorial of the given number.
In the code we have to validate that the argument passed is a positive number. If Function
parameter sent to Function ‘FactorialOf’ is less than zero then it is multi-plied by -1 to find the
absolute value.
[Function: FactorialOf]
|
3 : IF ##InputNumber < 0
4 : SET : InputNumber: ##InputNumber * -1
5 : END IF
366
TDL Procedural Capabilities
IF – ELSE – ENDIF
The IF – ELSE –ENDIF statement is an extension of the simple IF-ENDIF statement. If
condition expression is true, then true block statement(s) are executed; otherwise the false
block state¬ment(s) are executed. In either case, either true block or false block will be
executed, not both.
Syntax
IF : <Condition Expression>
STATEMENT 1
|
|
STATEMENT N
ELSE
STATEMENT 1
|
STATEMENT M
ENDIF
Where,
<Condition Exprn> is an expression which returns a logical value. If it is TRUE then the
specified statements 1- N are executed other wise the statements 1 to M are executed.
367
TDL Procedural Capabilities
Example:
Consider the following code snippet to find greatest of three numbers passed as parameters to
the function ‘FindGreatestNumbers’.
[Function: FindGreatestNumbers]
|
01 : IF: ##A > ##B
02 : IF : ##A > ##C
03 : RETURN : ##A
04 : ELSE
05 : RETURN : ##C
06 : END IF
07 : ELSE
08 : IF : ##B > ##C
09 : RETURN : ##B
10 : ELSE
11 : RETURN : ##C
12 : END IF
13 : END IF
DO – IF
When a IF - ENDIF statement block contains only one statement, then the same can be written
in single line by using DO-IF statement.
Syntax
DO IF: <Condition Exprn> : <Action Keyword> : +
<Action Parameter>
Where,
<Condition Exprn> is an expression which returns a logical value. If it is TRUE then the
specified action is executed.
<Action Keyword> is any one of the valid statement/actions.
<Action Parameters> parameters of the actions specified
368
TDL Procedural Capabilities
Example:
Let’s take the same example of writing a function code to calculate the factorial of the given
number. If Function parameter sent to Function ‘FactorialOf’ is less than zero then it is
multi¬plied by -1 to find the absolute value. IF - END IF statement is re written using DO - IF
statement.
[Function: FactorialOf]
|
3: DO IF : ##InputNumber < 0 : ##InputNumber * -1
Most programming languages have constructions for repeating a loop until some condition
changes. A loop is a sequence of statements which is specified once but which may be carried
out several times in succession.
In looping, a sequence of statements is executed until some conditions for termination of the
loop are satisfied. A typical loop consists of two segments, one known as the body of the loop
and the other known as the control statement. The control statement checks condition and then
directs the repeated execution of the statements contained in the body of the loop.
There are variations of the loops based on the way the control statement is executed. In some
the condition is evaluated at the start of the loop, while others have the test at the end of the
loop. In the former case the body may be skipped completely, while in the latter case the body
is always executed at least once.
TDL allows following looping constructs for varied usage:
WHILE – END WHILE
FOR RANGE – END FOR
FOR TOKEN – END FOR
WALK COLLECTION – END WALK
FOR COLLECTION – END FOR
FOR IN/FOR EACH – END FOR
The looping can be done on the objects in collection, on the tokenized string, for a range of
values and condition based looping of a set of statement. Lets understand the usage of each
loop in depth.
WHILE – ENDWHILE
The WHILE – ENDWHILE is an entry controlled loop statement. The condition expression is
evaluated and if the condition is true, then the body of the loop is executed. After the execution
of the statements within the body, the condition expression is once again evaluated and if it is
true, the body is executed once again. This process of repeated execution of the body
continues until the condition expression finally becomes False and the control is transferred
out of the loop.
369
TDL Procedural Capabilities
Syntax
WHILE : <Condition Expression>
STATEMENT 1
|
STATEMENT N
ENDWHILE
Where,
<Condition Exprn> is an expression which returns a logical value. If it is TRUE then only the
specified statements 1- N are executed.
Example:
Let’s consider the same example of writing a function code to calculate the factorial of the
given number. The same function can be rewritten by using WHILE – ENDWHILE looping
construct. The Function ‘FactorialOf’ repeats statements 4 and 5 till given condition is satis-
fied.
[Function: FactorialOf]
|
3: WHILE : ##Counter <= ##InputNumber
4: SET : Factorial : ##Factorial * ##Counter
5: SET : Counter : ##Counter + 1
6: END WHILE
|
Exercise 9.1:
Objective
The objective of this program is to find the Exponentiation i.e. Nth Power of a Number using
TDL Procedural Capabilities (User Defined Function).
Capabilities Used
The procedural capability of TDL is used to calculate the Nth Power of a Number.
The Base number and the Exponent are passed as parameter to the user defined func-
tion which returns the calculated value to the calling field.
The field attribute Set Always is used to refresh the value in the field each time the
values in the fields it refers to are changed.
370
TDL Procedural Capabilities
Code
[Report: Exer Proc Powerof]
Form : Exer Proc Powerof
Title : "Calculate Power of a Number"
371
TDL Procedural Capabilities
372
TDL Procedural Capabilities
Output
Program Explanation
The report displays fields to accept the number and power of factor respectively. The resultant
Exponentiation is displayed in the Result field. The field Exer Proc PO Result calls the
function ExerProcPOCalc. The values of the field ExerProcPOBase and ExerProcPOPow-
erOf are passed to the function ExerProcPOCalc.
The function ExerProcPOCalc uses TDL procedural constructs Parameter, Variable,
Decrement and the looping construct WHILE for the calculating the Exponentiation of the
given number. The WHILE loop is executed till the value of the parameter “pPowerof “ is
greater than zero. The action SET is used to modify the value of the variable “Result” with the
product of previous value and the Base. The action RETURN is used to return the computed
value to the calling field.
In the field Exer Proc PO Result attribute Set Always is used to refresh the value whenever
the values in the fields ExerProcPOBase and “ExerProcPOPowerOf” are changed.
373
TDL Procedural Capabilities
The FOR RANGE loop allows repeating a loop for the given range of numbers or date values.
The range can either be incremental or decremental.
Syntax
FOR RANGE: <Iterator Var> : <Data type> : <StartRangeExpr> : +
<EndRangeExpr> [: <Increment Expr> [:+
<DateRangeKeyword>]]
STATEMENT 1
|
STATEMENT N
END FOR
Where,
<Iterator Var Name> is the name of variable used for the iteration. This variable is created
implicitly.
<Data Type> can be Number or Date only.
<StartRangeExpr> is an expression which evaluates to number or date values. It refers to the
starting value of the range.
<EndRangeExpr> is an expression which evaluates to number or date values. It refers to the
end value of the range.
<Increment Expr> is an expression which evaluates to number by which the <StartRange-
Expr> value is incremented. It’s optional and the default value is one.
<DateRangeKeyword> is optional and only applicable if the data type is Date. The values
can be any one of ‘Day’, ‘Week’, ‘Month’ and ‘Year’.
Example:
|
01: FOR RANGE : IteratorVar : Number : 2 : 10 : 2
02: LIST ADD : EvenNo : ##IteratorVar
03: END FOR
|
The values 2,4,6,8,10 are added in the List variable ‘EvenNo’ as the range of value i.e. 2 to 10
and the value is incremented by two with each iteration.
Example:
The following code snippet is used to calculate the number of weeks elapsed between System
date and Current Date set in Tally.
|
09 : FOR RANGE : IteratorVar : Date: ##SVCurrentDate : +
374
TDL Procedural Capabilities
$$MachineDate : 1 : "Week"
10 : LOG : ##IteratorVar
20 : INCREMENT : Cnt
30 : END FOR
50 : LOG : “No of weeks Back Dated :” + $$String: ##Cnt
60 : RETURN: ##Cnt
|
Assume that the range for this is 15 – Mar – 2009 to 30 – Mar – 2009. The values 15-Mar-
2009, 22-Mar-2009 and 29-Mar-2009 are logged as the increment is done by a ‘Week’ so there
are three iterations of the loop. The number of weeks is logged using the counter.
Example:
|
09 : FOR RANGE : IteratorVar : Date: ##SVFromDate : ##SVToDate :+
1 : "Month"
10 : LOG : $$MonthEnd:##IteratorVar
20 : END FOR
|
Assume that the range for this is 1 – Jan – 2009 to 5 – Mar – 2009. The values 31 – Jan -2009,
28 – Feb – 2009 and 31 –Mar -2009 are logged.
375
TDL Procedural Capabilities
Where,
<Iterator Var Name> is the name of variable user for the iteration. This variable is created
implicitly.
<Src String Exprn> can be any string expression separated by a <Delimiter Char>.
<Delimiter Char> can be any expression which evaluates into a character used for separating
string expression. The default separator char is ‘:’.
<Bracket Flag> is used to consider brackets while deciding the separator character.
Example:
[Function : Test Function]
|
01: FOR TOKEN : TokenVar : "Tally:Shopper :Tally Developer" : +
":" : FALSE
02: LOG : ##TokenVar
03: END FOR
The above code snippet will give the output as shown below:
Tally
Shopper
Tally Developer
376
TDL Procedural Capabilities
Where,
<Expression> can be any expression which evaluates to collection name.
<Rev Flag> can be an expression which evaluates to logical value. If it is True then the collec-
tion objects are traversed in reverse order. This parameter is optional. The Default value is
False.
Example:
Walking over all the Vouchers and counting the same
[Function: Count Vouchers]
|
002: WALK COLLECTION : Vouchers Coll
003: SET : Count : ##Count + 1
004: END WALK
|
Example:
[Function : Test Function]
Parameter : parmcoll
|
05 : WALK COLLECTION : ##parmColl : Yes
The collection name is passed as a parameter to the function ‘Test function’ and it is walked in
reverse order.
The code snippet to call the function ‘Test function’ from a key is as shown:
377
TDL Procedural Capabilities
The looping construct FOR COLLECTION provides a context free walk since the collection
object is not set as current object context while looping. It loops on the collection for the
specific value and returns the value in the iterator variable. The value of iterator variable can
be referred by the actions inside the FOR COLLECTION loop.
Syntax
FOR COLLECTION : <IteratorVar> : <Coll Exprn>[:+
<Value Exprn: <Rev Flag> ]
STATEMENT 1
|
STATEMENT N
END FOR
Where,
<Iterator Var> is the name of variable user for the iteration. This variable is created implic-
itly.
<Coll Exprn> can be any expression which evaluates to collection name.
<Value Exprn> can be an expression and the value of this is returned in the iterator variable.
If the value expression is not specified the name of the object is returned.
<Rev Flag> can be an expression which evaluates to logical value. If it’s True then the collec-
tion objects are traversed in reverse order. This parameter is optional. The Default value is
False.
Example:
[Function : Test Function]
|
30 : FOR COLLECTION : i : Group: $ClosingBalance > 1000
40 : LOG : ##i
50 : END FOR
|
The value Yes is logged in the file ‘TDLFunc.log’ for all objects where closing balance is
greater than 1000 else No.
The looping constructs “For Collection” and “Walk Collection” are mainly
used in conjunction with Object and Context Manipulation Actions. We are cat-
egorizing them here as they are mainly used to looping purposes.
378
TDL Procedural Capabilities
Function - $$LoopIndex
TDL Procedures give the sequential control to TDL programmers. During the sequential
execution the loops are used to iterate through a set of values. TDL allows nested loops as
well.
The function $$LoopIndex returns the count of how many times the current loop is executed.
In case of nested loops, the additional parameter <outer loop index number> can be used in the
inner loop to get the current iteration count of the outer loop.
Syntax
$$LoopIndex [: <Outer Loop Index Expr>]
Where,
<Outer Loop Index Expr> can be an expression which evaluates to number. It is optional and
the outer loop index number in the nested loop hierarchy from inner most loop to the outer
most loop. For the current loop the value is zero by default, for the parent loop One and so on.
379
TDL Procedural Capabilities
The variable Var will hold the count of how many times the FOR loop is executed while the
variable Var1 will have the count of WALK Collection loop execution.
Loops perform a set of operations repeatedly until the condition expression is satisfied or the
String/List Variable/Collection is exhausted. Sometimes, during the execution of loop at some
point it is required to skip the rest of the statements in the loop body and continue with the next
iteration or exit the loop.
Following Control Constructs are provided for the purpose
BREAK
CONTINUE
START BLOCK – END BLOCK
RETURN
380
TDL Procedural Capabilities
BREAK
When a Break statement is encountered inside the loop, the loop is immediately exited and
control is transferred to the statement immediately following the loop. When loops are nested,
the BREAK would only exit from the loop containing it. BREAK statement can be used inside
any of the looping constructs.
Syntax
BREAK
Example:
In Function ‘PrintNumbers’ loop is running from 1 to 10. But because of BREAK statement
loop will be terminated as counter reaches the 6.
[Function: PrintNumbers]
|
2: WHILE : ##Counter <= 10
3: LOG : ##Counter
4: IF : ##Counter > 5
5: BREAK
6: END IF
7: SET : Counter : ##Counter + 1
8: ENDWHILE
9: RETURN
CONTINUE
In some scenarios instead of terminating the loop, loop needs to be continued with next
iteration after skipping any statements in between. For this purpose CONTINUE statement can
be used. CONTINUE statement can be used inside any of the looping constructs.
Syntax
CONTINUE
Example:
Function to Count total number of Journal Vouchers
[Function: Count Journal]
|
02: WALK COLLECTION: Vouchers Coll
03: IF : NOT $$IsJournal:$VoucherTypeName
381
TDL Procedural Capabilities
04: CONTINUE
05: ENDIF
|
RETURN
This statement is used to return the flow of control to the calling program with or without
returning a value. When return is used the execution of the function is terminated and the
calling program continues from where it had called the function.
Syntax
RETURN : <Value Expression>
Where,
<Value Expression> is optional which returns the value to the calling environment. If the
value expression is omitted then the control is returned to the calling environment.
Example:
The Function ‘FactorialOf’ returns factorial of number
[Function: FactorialOf]
|
Returns : Number
|
70: RETURN : ##Factorial
|
START BLOCK - END BLOCK
During the execution of TDL procedure, it may be required to temporarily change the object
context for executing some intermediate actions. START BLOCK - END BLOCK are used in
this scenario. The process flow is as follows:
START BLOCK statement saves the current object context and switches to the tar-
get context,
All the action statements within the block are executed
END BLOCK statement restores back the source object context.
All the statements followed by the END BLOCK are executed with original object
context.
The object context available in the START BLOCK – END BLOCK is lost one the control
exits this block. In other words, the object context used within the block is not available
outside the block.
382
TDL Procedural Capabilities
The developer can specify the START BLOCK – END BLOCK in a nested hierarchy i.e.
START BLOCK – END BLOCK can be contained in another START BLOCK – END
BLOCK.
Syntax
START BLOCK
STATEMENT 1
|
STATEMENT N
END BLOCK
Example:
|
13 : SET : AmtVar : $$String:$Amt
14 : START BLOCK
15 : SET OBJECT
16 : SET VALUE : ActualQty : $$AsQty:##QtyVar
17 : SET VALUE : BilledQty: $$AsQty:##QtyVar
18 : SET VALUE : Amount : $$AsAmount:##AmtVar
18A: END BLOCK
19 : SET TARGET : ..
|
In the above code snippet, EDCollDetailsExtract collection is being walked over and the
values for Objects within Voucher Entry are being set.
After understanding the various programming constructs, it’s now time to understand various
actions in order to perform any operation.
9.5 Actions
As explained earlier, TDL is an action driven language, which provides a comprehensive set of
actions. All the global actions can be executed from the TDL function. Apart from these
actions, some of the actions can be executed only within the Function definition.
The functions have a comprehensive set of actions which can be used for various operations.
Classified as follows based on their usage:
System Actions
Object Context Manipulation
Variable Manipulation Actions
383
TDL Procedural Capabilities
384
TDL Procedural Capabilities
Syntax
SET VALUE: <Method Name> : <Value Formula>
Where,
<Method Name> is the name of the method
<Value Formula> is the value which needs to be set to the method.
Example:
|
01: SET VALUE : Ledger Name : $LedgerName
02: SET VALUE : IsDeemedPositive : $IsDeemedPositive
03: SET VALUE : Amount : $Amount
|
The above statements set the values of Ledger Entries Object from the current Object context.
RESET VALUE
The action RESET VALUE is used to set the value of a method for Target Object using the
value formula. If value formula is not specified then it sets the existing value to null.
Syntax
RESET VALUE : <MethodName> [: <Value Formula>]
Where,
<Method Name> is the name of the method.
<Value Formula> is an optional parameter and if it is used, it will reset the value of the
method.
Example:
|
01: SET VALUE : Ledger Name : $LedgerName
02: RESET VALUE : Ledger Name : “New Value”
|
In the above code snippet RESET VALUE resets the value of the method ‘Ledger Name’ to
‘New Value’.
NEW OBJECT
The action New Object creates a new object based on the object specification and sets it as
target object. Only primary object can be specified as parameter. The actions SAVE TARGET/
ALTER TARGET/CREATE TARGET can be used along with NEW OBJECT based on the
user requirement.
385
TDL Procedural Capabilities
Syntax
NEW OBJECT : <Object Type> : [: <Object Identifier>+
[: + <Forced Create Flag>]]
Where,
<Object Type> is the type of the object to be created and
<Object Identifier> is the unique identifier of the object. If this is an existing object in Tally
data base then the further manipulations are performed on that object else it creates a new
object altogether.
<Forced Create Flag> is optional and it is required only if the <Object Identifier> is speci-
fied. If the Flag is set to TRUE then if the object identified by <Object Identifier> exists, the
object is altered otherwise a new empty object of the specified type is created.
Example:
|
01 : NEW OBJECT: Group : ##EGroupName : TRUE
02 : SET VALUE: Name : ##NGroupName
03 : SAVE TARGET
|
If the ledger identified by ##EGroupName exists in Tally database then the objects is altered
by action SAVE TARGET else a new object is created as the Forced flag is set to ‘YES’.
386
TDL Procedural Capabilities
387
TDL Procedural Capabilities
Syntax
SAVE TARGET
SET OBJECT
The action SET OBJECT sets the specified object as current object in context. If no object
specification is given the target object will be set as the current object. The action accepts only
secondary object specification.
Syntax
SET OBJECT [: <Object Spec>]
Where,
<Object Spec> is the name of the sub object.
Example:
[Function: Sample Function]
Object : Ledger : "My Test Ledger"
|
01 : LOG : $Name
02 : SET OBJECT: BillAllocations[1]
03 : LOG : $Name
04 : SET OBJECT : ..
05 : LOG : $Name
Initially the context object is Ledger so $Name give the name of Ledger. By Using ‘SET
OBJECT’ current Object is changed to first Bill allocation. Now the statement ‘03: LOG :
$Name’ logs the Bill name. The statement ‘04 : SET OBJECT : ..’ changes current object back
to Ledger using doted notation.
388
TDL Procedural Capabilities
SET TARGET
The action SET TARGET sets the specified object as target object in context. If no object
specification is given the current object will be set as the target object.
Syntax
SET TARGET: <Object Spec>
Where,
<Object Spec> is the name of the Object
Example:
01 : SET TARGET : Group
This sets the Group object as the target object in context. Later by using other methods of this
target object can be set and saved to the Tally data base.
389
TDL Procedural Capabilities
EXCHANGE
During the execution of a TDL procedure, there may be a requirement to swap the values of
two variables. This can be performed for variables of same data type only. The action
EXCHANGE is used to interchange the value of two variables.
Syntax
EXCHANGE: <FirstVariableName> : <Second Variable Name>
Where,
<First Variable Name> and <Second Variable Name> are the Variables whose values needs
to be swapped.
Example:
|
01: EXCHANGE : Var1 : Var2
|
In the above statement both variables are of type Number and their values are swapped.
INCREMENT
This Action is used to increment the value of a Variable by specified number. INCREMENT
can be used inside the loop to increment value of the control variable.
Syntax
INCREMENT : <Variable Name> [ : < Increment Counter>]
Where,
<Variable Name> is the name of the Simple Non Repeat Variable of Number type whose
value needs to be incremented.
<Increment Counter> is an optional parameter which specifies the increment count. If this is
not specified then the variable by default is incremented by 1.
Example:
[Function: FactorialOf]
|
5: INCREMENT : Counter
6: INCREMENT : Factorial : 5
|
The value of the variable ‘Counter’ is incremented by 1 whereas the value of the variable
‘Factorial’ is incremented by 5. Assuming the initial value of both the variables is 1 then after
the execution of the statements the values will be 2 and 6 respectively.
390
TDL Procedural Capabilities
DECREMENT
The action DECREMENT is used to decrement the value of a Variable by specified number.
Syntax
DECREMENT : <Variable Name> [ : < Increment Counter>]
Where,
<Variable Name> is the name the Simple Non Repeat Variable of Number type whose value
needs to be decremented.
<Increment Counter> is an optional parameter which specifies the decrement count. If this
is not specified then the variable is decrement by 1.
Example:
[Function: FactorialOf]
|
5: DECREMENT : Counter
6: INCREMENT : Factorial : 5
|
The value of the variable ‘Counter’ is decremented by 1 whereas the value of the variable
‘Factorial’ is decremented by 5. Assuming the initial value of both the variables is 10 then
after the execution of the statements the values will be 9 and 5 respectively.
START PROGRESS
The action START PROGRESS is used to display the Progress Bar. The details like total
number of steps involved in the task, Title, Sub Title and Subject of the Progress Bar can be
displayed along with the progress bar.
Syntax
START PROGRESS : <Number of steps> :< Title> +
[:< Sub Title> :< Subject>]
391
TDL Procedural Capabilities
Where,
<Number of steps> denotes the whole task quantified as a number,
<Title>, <Sub Title> and <Subject> shows the Title, Sub Title and Subject of Progress Bar
respectively.
Example:
START PROGRESS: ##TotalSteps:“TDS Migration”:@@CmpMailName: +
“MigratingVouchers..”
SHOW PROGRESS
The action SHOW PROGRESS shows the current status of the task to the user.
Syntax
SHOW PROGRESS : <Number of Steps Completed>
Where,
<Number of Steps Completed> is a number denotes the amount of work completed
Example:Progress Bar showing the progress of the task
SHOW PROGRESS:##Counter
END PROGRESS
When a task is completed, Progress Bar can be stopped by using action END PROGRESS.
This Action does not take any parameter.
Syntax
END PROGRESS
In any programming language dialog boxes are used to display some information or to get
confirmation from the application user. TDL provides actions MSG BOX and QUERY BOX
to display dialog boxes. The parameters that are passed to these actions decide the behaviour
of the dialog box.
MSG BOX
The action MSG BOX is used to display a message box to user. It comes back to the original
screen on the press of a key. This is can be used by the programmers to display intermediate
values of variables during calculations thus helping in error diagnosis.
Syntax
MSG BOX : <Title Expression> : <Message Expression> : +
<Grey Back Flag>
392
TDL Procedural Capabilities
Where,
<Title Expression> is the value displayed on the title bar of the message window
<Message Expression> is the actual message which is displayed in the box. This can be an
expression as well i.e., the variable values can be concatenated and displayed along with the
message in the display area of the box
<Grey Back Flag> accepts logical value YES or NO. If the value is YES, the message box is
displayed with Grey background color.
Example:
01: MSGBOX: “Return Value” : ##Factorial
|
The above code snippet displayed the value of the variable ‘Factorial’ in the dialog box and
the string ‘Return Value’ is displayed as title of the box.
QUERY BOX
The action displays a confirmation box and waits for the user response. The user input in the
form of YES or NO is required.
Syntax
QUERY BOX : <Message Expression> : <Grey Back Flag> +
: <Esc As Yes>
Where,
<Message Expression> is the message which is displayed inside the box. This can be an
expression
<Grey Back Flag> accepts logical value YES or NO. If the value is YES, the message box is
displayed with Grey background color.
<Escape as Yes> is a flag which indicates the response when the user presses ESC key. This
can be specified as YES/NO. A YES value for this flag indicates that the response should be
treated as YES on press of an ESC key.
9.5.5 Debugging Actions
In scenarios, when the actual program output differs from the expected behaviour, the applica-
tion programmer needs to check the code and fix the problem. This process of locating and
correcting the errors in the code is referred as Debugging. While debugging a program the user
requires displaying the intermediate values in order to isolate the source of the problem.
Example:
The intermediate values of the expression can be displayed during expression evaluation. TDL
supports various actions to help the programmer in debugging. The actions allows to display
value in the Calculator window and also writes them to the log file ‘tdlfunc.log’ available in
the application directory. By default logging is enabled inside the function.
393
TDL Procedural Capabilities
LOG
The action LOG displays the value passed as parameter in the calculator window and writes
the same in the log file ‘tdlfunc.log’. This is very much helpful for debugging the expression
Syntax
LOG : < Expression>
Where,
<Expression> is an expression whose value needs to be passed to the calculator window.
Example: While calculating the factorial of a number, intermediated values are displayed in
the Calculator window using LOG action
[Function: FactorialOf]
|
3 : WHILE : ##Counter <= ##InputNumber
4 : SET : Factorial : ##Factorial * ##Counter
5 : SET : Counter : ##Counter + 1
5a: LOG : ##Factorial
|
The value of the variable ‘Factorial’ is displayed in the calculator window and is also logged
in the file ‘tdlfunc.log’.
SET LOG ON
While debugging a TDL function, sometimes it is required to conditionally Log the values of
an expression. If logging is stopped, then logging can be re-started based on the condition
Action SET LOG ON. This Action does not require any parameter.
Syntax
SET LOG ON
Syntax
[Function : Debugtest]
00 a : SET LOG ON
00 b : Log : "Tally"
The string “Tally” is displayed in the calculator window as well as it is logged in the file ‘tdl-
func.log’.
394
TDL Procedural Capabilities
395
TDL Procedural Capabilities
The string “Ltd.” is displayed in the calculator window but it is not logged in the file ‘tdl-
func.log’.
LOG OBJECT
The action Log Object a global action which allows logging the current object context details
in a file. It accepts filename as a parameter. In the specified file the current context object, cor-
responding methods and sub collections are logged.
Syntax
LOG OBJECT [:<path\filename>[:<Overwrite Flag>]]
Where,
<path/filename> is optional. It accepts the name of file along with the path in which the log is
created. If no file name is specified the contents of object are logged in "TDLfunc.log" when
logging is disabled otherwise it logs in to the Calculator window.
<Overwrite Flag> is used to specify whether the contents should be appended or overwritten.
The default is No, which appends the content in the file. If YES, then the file is overwritten.
Example:
[Function: FuncLedExp]
|
Object : Ledger
|
10: Log Object : LedgerObj.txt
In the file ‘LedgerObj.txt’ the current object context, its methods and collection details are
logged.
LOG TARGET
The action Log Target is function specific action which allows logging details of the target
object in a file. It accepts filename as a parameter in which the log of object, its method and
collection is created for the target object.
Syntax
Log Target[:<path\filename>[:<Overwrite Flag>]]
Where,
<path/filename> is optional. It accepts the name of file along with the path in which the log is
created. If no file name is specified the contents of object are logged in "TDLfunc.log" when
logging is disabled otherwise it logs in to the Calculator window.
<Overwrite Flag> is used to specify whether the contents should be appended or overwritten.
The default is No, which appends the content in the file. If YES, then the file is overwritten.
396
TDL Procedural Capabilities
Example:
[Function: FuncLedExp]
|
05: Set Target
|
10: Log Target : LedgerTgtObj.txt
In the file ‘LedgerTgtObj.txt’ the target object context, its methods and collection details are
logged.
Exercise 9.2:
Objective
The objective of this program is to create Groups and Ledgers by executing the action 'New
Object' within the Function definition.
Capabilities Used
The TDL Procedural programming constructs Variable, Local Formula, MSG Box,
While Loop etc are used.
The actions New Object, SET Value, Save Target are used to create the objects.
Code
[Function: Exer Action New Object]
Variable : Counter: Number: 5
Local Formula: LFRM: "Debtor " + ($$String:##Counter)
Local Formula: OpBal: ($$AsQty:##Counter)
Local Formula: CX1000: (##Counter * 1000)
;; Ensuring that the Group is available, if not creating the same
000: NEW OBJECT : Group: "Bangalore Debtors": Yes
;; Action 'SET VALUE' is used to set the value of a Method within the current Object
010: SET VALUE : Name : "Bangalore Debtors"
020: SET VALUE : Parent : "Sundry Debtors"
;; Action 'SAVE TARGET' is used to save the Target Object.
030: SAVE TARGET
040: MSGBOX : "Success" : "Group created/altered successfully"
050: WHILE: ##Counter > 0
;; Creating 5 Ledgers under the Group 'Bangalore Debtors'
397
TDL Procedural Capabilities
Output
398
TDL Procedural Capabilities
Program Explanation
The function Exer Action New Object creates the Group Object Bangalore Debtors using
the action NEW OBJECT. The Group Bangalore Debtors is created only if it does not exist
else it alters the same. The action SET VALUE sets the values of the methods Name and
Parent as Bangalore Debtors and Sundry Debtors. The action SAVE TARGET is used to
save the newly created Group in Tally Database.
Once the Group is created the success message is displayed using action MSG BOX as shown
in the image.
When the user escapes from the message box then the Ledgers are created. Since the value of
the variable Counter is set to 5; five Ledgers Debtor 1, Debtor 2, Debtor 3, Debtor 4 and
Debtor 5 are created. If a ledger with the same name already exists then the ledger is altered.
The action SET OBJECT is specified to set the ledger object as the current object in context
for entering the Bill details. The action INSERT COLLECTION is then used to enter the Bill
allocation details for the current ledger. The Action SET TARGET is used to move the context
from Bill Allocations to Ledger object.
On successful creation of Ledgers and their respective bill allocations, the success message is
displayed as shown in the second image.
399
TDL Procedural Capabilities
dynamically. Dynamic actions are supported within TDL functions also as per the syntax
given below
Syntax
ACTION : <Action Keyword Expression>: <Action Parameter Expres-
sion>
Where,
<Action Keyword Expression> is an expression evaluating to an Action Keyword i.e. any of
the global action name like Display, Print, Upload etc.
<Action Parameter Expression> is an expression evaluating to Action Parameters
Example:
[Button: Test Button]
Key : F6
Action : Call : TestFunc :"Balance Sheet"
400
TDL Procedural Capabilities
using the protocols FTP and HTTP. Since these artifacts operate on characters and not bytes
the file encoding ASCII/UNICODE does not have any effect on the operations.
The entire procedural Read/Write artifacts basically operate on two file contexts.
File Operations
A programming language which supports File Read/Write typically support following funda-
mental operations:
Open – This is an operation which identifies the file which needs to be opened for
Read/Write purpose
Close - This is an operation which closes the opened file after Read/Write
Read – This is an operation to read the data from an opened File
Write – This is an operation to write the data to an opened File
Seek - This is an operation to the character position in an already opened file
Truncate- This is an operation which will delete the particular no of characters/entire
contents of the file
401
TDL Procedural Capabilities
The TDL Artifacts used for supporting various Read/Write operations are Actions and Func-
tions. These are made to work only inside the TDL Procedural Block. Write operations are
handled using Actions and all file Access and Read operations are performed using Functions.
OPEN FILE
This action OPEN FILE is used to open a Text/Excel file for read/write operations. The File
can reside in Hard Disk, can be in main memory or can be in FTP/HTTP site. Also this Action
is used to open a file for read/write operations.
If no parameters are used then a memory buffer will be created and will act as a file. This file
will be in both read / write mode and will act as both source as well as target context.
Based on the mode specified (read / write) the file automatically becomes the source file or
target file respectively.
Syntax
OPEN FILE [: <File Name> [: <File Format> [: <Open Mode> +
[: <Encoding>]]]]
Where,
<File Name> can be a expression which evaluates to a regular disk file name like “C:\Out-
put.txt” or to a HTTP/FTP site like “ftp://ftp.tallysolutions.com/Output.txt”
<File Format> can be either Text or Excel. By default text mode will be considered if not
specified. Also during opening an existing file, if the mode does not match the Action will fail.
<Open Mode> can be read / write. By default it is read. If a file is opened for read purpose
then it must exist. If write mode is specified, and the file exists this will be open it for updating
or if file does not exist a new file is created. If the file is opened in the Write mode, it is also
possible to read from the file as well.
<Encoding> can be ASCII or Unicode. If not specified it will consider Unicode as default
value for Write Mode. In read mode this parameter will ignored and considered based on the
encoding of the file being read.
If the specified file does not exist and the mode is specified as Write then the action OPEN
FILE creates the file otherwise the file is opened in the specified mode.
402
TDL Procedural Capabilities
If the specified file does not exist and the mode is specified as Read then the action OPEN
FILE will fail.
Incase only the file name is specified then the default path is considered as the Tally.ERP9
application folder to open/create the file.
Example:1
|
10 : OPEN FILE : "Output.txt" : Text : Write : ASCII
|
The action opens a Text file ‘Output.txt’ in Write mode from the Tally.ERP9 application
Folder. If the file does not exist then the file with the given name is created in the Tally.ERP9
application Folder. In case the file already contains some text then the same file will be opened
for appending purpose.
Example:2
|
10: OPEN FILE : "http://www.tallysolutions.com/Output.txt" : Text
|
The action opens a Text File ‘Output.txt’ in Write mode at the HTTP URL specified. If the file
already exists the same file will be opened for appending purpose. (If the file does not exist
then it is created on the site if the user has Right to create the file)
Example:3
|
10 : OPEN FILE : "C:\Output.xls" : Excel : Read
|
The action opens a Excel File ‘Output.xls’ in Read mode under C drive and if the file does not
exist the action will fail.
403
TDL Procedural Capabilities
Files which are opened in the current function can only be closed by it. If a function inherits
file contexts from the caller function then it cannot close these files, however it can open its
own instances of the files, in such cases the caller context files will not be accessible.
CLOSE FILE
The action CLOSE FILE is used to close a opened source file.
Syntax
CLOSE FILE
Example:
|
10 : OPEN FILE : "Output.xls" : Excel : Read
|
30 : CLOSE FILE
|
In the example Excel file ‘Output.xls’ which is opened for reading purpose is closed.
404
TDL Procedural Capabilities
$$TgtFile
All file accessing functions for both text and excel files, operates on the source file context.
The function $$TgtFile can be used to switch to target file context temporarily. This function
which evaluates the expression passed in the context of a target file.
Syntax
$$TgtFile:<Expression>
Where
<Expression> is any expression which is evaluated the context of a target file.
Example:
In the example below, the objective is to Read the content of a cell in Sheet 1 and copy it to a
cell in the Sheet 2 of the same file. The function opens the file “ABC.xls” in Write mode.
[Function: Sample Func]
|
Variable : Temp : String
|
10 : SET : Temp : ""
20 : OPEN FILE : "Output.xls" : Excel : Write
|
30 : ADD SHEET : "Sheet 1"
40 : WRITE CELL : 1 : 1 : "Item A"
50 : SET : Temp : $$TgtFile:$$FileReadCell:1:1
60 : ADD SHEET : "Sheet 2"
|
70 : WRITE CELL : 1:1: ##Temp
80 : CLOSE TARGET FILE
In this example there is no file present in the source file context as the file is opened in the
Write mode. In that case, for reading a value from Sheet 1, the expression $$FileReadCell:1:1
will return no value. Prefixing the expression with $$Tgtfile will temporarily change the
context to Target File for the evaluation of expression and will fetch the value from cell 1 of
Sheet 1 existing in the Target File context.
$$FileSize
This function will return the size of the file specified in bytes. This function takes optional
parameter if the parameter is not given then it works on the current context file and returns the
size.
405
TDL Procedural Capabilities
Syntax
$$FileSize[:<FileName>]
Where
<FileName> is an expression which evaluates to the file name along with the path.
Example:
|
10 : Log : $$FileSize:”Output.xls”
|
The example gives the size of Excel file ‘Output.xls’ in terms of bytes.
WRITE FILE
This Action is used to append a file with the text specified. The write always starts from the
end of the file. This action always works on the target file context.
Syntax
WRITE FILE : <TextToWrite>
Where,
<TextToWrite> can be any expression which evaluates to data that need to be written to the
file.
Example:
|
10 : OPEN FILE : "Output.txt" : Text : Write
20 : WRITE FILE : "Krishna"
30 : CLOSE TARGET FILE
|
In the example a txt file ‘Output.txt’ is opened in write mode and the content ‘Krishna’ is
appended at the end of the file.
406
TDL Procedural Capabilities
TRUNCATE FILE
This action removes the content of the file by setting the file pointer to the beginning of the file
and inserting an end of file marker. This can be used to erase all characters from an existing
file before writing any new content to it.
Syntax
TRUNCATE FILE
Example:
|
10 : OPEN FILE: "Output.txt" : Text : Write
20 : TRUNCATE FILE
30 : WRITE FILE : "New Value"
40 : CLOSE TARGET FILE
|
The entire content of the existing txt file ‘Output.txt’ is removed and ‘New Value’ is inserted
subsequently.
407
TDL Procedural Capabilities
SEEK FILE
This Action operates on the Target File Context. This Action is used to move the file pointer to
a location as specified by the no of characters. As we know that it is possible to Read and
Write from the Target File context, all the subsequent Reads and Writes will be starting from
this position. By Default, if the file position is not specified Read pointer will be always be
from the beginning of file and write pointer will be from the end of the file.
We have already covered how to Read from Target File Context by using the
function $$TgtFile
Syntax
SEEK FILE:<File Position>
Where,
<File Position> can be any expression which evaluates to number which considered as
number of characters.
$$FileRead
This function is used to read data from a text file. This takes an optional parameter. If this is
not specified or parameter is having value as 0 then this will read one line and ignore the end
of line character. However the file pointer is positioned after the end of line character so that
next read operation starts on the next line.
If number of characters are mentioned this function will read that many number of characters.
Syntax
$$FileRead [:<CharsToRead>]
Where,
<CharsToRead> can be any expression which evaluates to number of characters to read.
408
TDL Procedural Capabilities
Example:
|
10 : OPEN FILE : “Output.txt" : Text : Read
|
20 : LOG : $$FileRead
30 : CLOSE FILE
|
The example reads the first line of the text file ‘Output.txt’.
$$FileIsEOF
This function is used to check if the current character being read is the End of file character.
Syntax
$$FileIsEOF
409
TDL Procedural Capabilities
Syntax
SET ACTIVE SHEET: <Sheet Name>
Where,
<Sheet Name> can be an expression which evaluates to the string and will be considered as
the name of the sheet.
Example:
|
10 : OPEN FILE: "Output.xls" : Excel : Read
20 : SET ACTIVE SHEET :"Sheet 2"
30 : Log : $$FileReadCell:1:1
40 : CLOSE FILE
|
The example opens an Excel sheet ‘Output.xls’ in Read mode and makes ‘Sheet 2’ as active
and reads the content from the first cell.
9.5.11 Writing to a File
Various Actions are introduced in order to write to a excel file. These Actions operate on the
Target File context. The scope of these Actions is within the TDL procedural block (User
Defined Functions) where the file is opened and the context is available.
ADD SHEET
This Action adds a sheet in the current workbook which is opened for writing. Sheet will
always be inserted at the end .If a sheet with the same name already exists the sheet will be
made as active.
Syntax
ADD SHEET : <Sheet Name>
Where,
<Sheet Name> can be an expression which evaluates to the string and will be considered as
the name of the sheet.
Example:
|
10 : OPEN FILE : "Output.xls" : Excel : Write
20 : ADD SHEET : "New Sheet"
|
410
TDL Procedural Capabilities
The example opens an existing Excel sheet ‘Output.xls’ in write mode and new sheet ‘New
Sheet’ will be inserted at the end of the workbook.
REMOVE SHEET
This Action removes the specified sheet from current workbook. The entire content in the
sheet will be removed. This Action will fail if the workbook has only one sheet or if the
specified sheet name does not exist in the workbook.
Syntax
REMOVE SHEET : <Sheet Name>
Where,
<Sheet Name> can be an expression which evaluates to the string and will be considered as
the name of the sheet.
Example:
|
10 : OPEN FILE : “Output.xls” : Excel : Write
20 : ADD SHEET : "New Sheet"
30 : REMOVE SHEET : "Sheet1"
|
The example creates a work book with a sheet ‘New Sheet’.
RENAME SHEET
The Excel work sheet can be renamed using the action RENAME SHEET.
Syntax
RENAME SHEET: <Old Sheet Name>: <New Sheet Name>
Where,
<Old Sheet Name> and <New Sheet Name> can be an expression which evaluates to the
string and will be considered as the name of the sheet.
Example:
01: OPEN FILE: "Output.xls" : Excel : Write
02: RENAME SHEET : @@OldSheetName : @@NewSheetName
03: CLOSE TARGET FILE
The sample code renames the worksheet identified by expression ‘OldSheetName’ to the
string identified expression ‘NewSheetName’.
411
TDL Procedural Capabilities
WRITE CELL
This action allows to write the specified content at the cell address specified by row and
column number of the currently active sheet.
Syntax
WRITE CELL: <Row Number> : <Column Number> : +
<Content To be Written>
Where,
<Row Number> and <Column Number> can be any expression which evaluates the number
which can be used to identify the cell
<Content To be Written> can be any expression which evaluates to data which needs to be
filled for the identified cell.
Example:
|
10 : OPEN FILE : "Output.xls" : Excel : Read : ASCII
15 : ADD SHEET : "New Sheet"
20 : WRITE CELL : 1 : 1 : "Krishana"
30 : CLOSE FILE
|
The example opens an Excel file ‘Output.xls’, adds a new sheet and in that sheet first cell will
have content as ‘Krishna’.
WRITE ROW
This Action writes multiple cell values at a specified row in the Active sheet. The numbers of
values separated by commas are written starting from the initial column number specified for
the row specified.
Syntax
WRITE ROW: <Row Number> : <Initial Column Number>: +
<Comma Separated Values>
Where,
<Row Number> and <Initial Column Number> can be any expression which evaluates the
number which can be used to identify the cell
<Comma Separated Values> can be expressions separated with comma which evaluates to
data that needs to be filled starting from cell as mentioned by <Row Number> and <Initial
Column Number>.
412
TDL Procedural Capabilities
Example:
|
10 : OPEN FILE : "Output.xls" : Excel : Write
20 : ADD SHEET : "New Sheet"
30 : WRITE ROW : 1 : 1 : @@Val1, @@Val2
40 : CLOSE TARGET FILE
|
The examples fills cell (1,A) and cell (1,B) with the values from expressions ‘Val1’ and ‘Val2’
WRITE COLUMN
This action writes multiple cell values at a specified column in the Active sheet. The no of
values separated by commas are written starting from the initial row no specified for the
column.
Syntax
WRITE COLUMN: <Initial Row Number>: <Column Number> : +
<Comma Separated Values>
Where,
<Initial Row Number> and <Column Number> can be any expression which evaluates the
number which can be used to identify the cell.
<Comma Separated Values> can be expressions separated with comma which evaluates to
data that needs to be filled starting from cell as mentioned by <Initial Row Number> and
<Column Number>.
Example:
|
10 : OPEN FILE: "Output.xls" : Excel : Write
20 : ADD SHEET : "New Sheet"
30 : WRITE Column : 5 : 5 : @@Val3, @@Va4
40 : CLOSE TARGET FILE
|
The example sets the values from expressions ‘Val3’ and ‘Val4’ in the cell (5,E) and cell (6,E)
respectively.
9.5.12 Reading a File
Some functions and actions are introduced which can operate on the Source File context to
read from the file or access some information from them. The scope of these functions is
413
TDL Procedural Capabilities
within the TDL procedural block (User Defined Functions) where the file is opened and the
context is available. It is also possible to read from the Target File Context by using the
function $$TgtFile.
$$FileReadCell
To read the content of a specific cell function $$FileReadCell can be used. This function
returns the content of the cell identified by using row and column number of the active sheet.
Syntax
$$FileReadCell : <Row Number> : <Column Number>
Where,
<Row Number> and <Column Number> can be expression which evaluates to the number
to identify row number and column number
Example:
|
10 : OPEN FILE: "Output.xls" : Excel : Read
20 : SET ACTIVE SHEET :"Sheet 1"
20 : Log : $$FileReadCell:1:1
|
The function $$FileReadCell Logs the contents of the first cell of the excel sheet ‘Sheet 1”.
$$FileGetSheetCount
Before performing any operation on the Excel file the user may require to know the number of
sheets in the Excel work book. The function $$FileGetSheetCount can be used which returns
number of sheets in the current workbook.
Syntax
$$FileGetSheetCount
Example:
|
10: OPEN FILE: "Output.xls" : Excel : Read
20: Log : $$FileGetSheetCount
|
The function $$FileGetSheetCount returns the total number of sheets in an Excel sheet ‘Out-
put.xls’
414
TDL Procedural Capabilities
$$ FileGetActiveSheetName
The developer might need to know the name of the active work sheet before performing in
operation on the Excel file. The function $$FileGetActiveSheetName can be used which
returns the name of the active sheet.
Syntax
$$FileGetActiveSheetName
Example:
|
10 : OPEN FILE: "Output.xls" : Excel : Read
20 : Log : $$FileGetActiveSheetName
|
The function $$FileGetActiveSheetName returns the name of the active sheet after opening
the Excel file ‘Output.xls’
$$ FileGetSheetName
If the work sheet index is available then the function $$FileGetSheetName can be used to
retrieve the name of the sheet. This Function returns the name of the sheet at a specified index.
Syntax
$$GetSheetName:< Sheet Index>
Where,
<Sheet Index > can be any expression which evaluates to number as Sheet Index.
Example:
|
10 : OPEN FILE: "Output.xls" : Excel : Read
|
20 : Log :$$FileGetSheetName:1
|
The function $$FileGetSheetName gives the name of the sheet available at index 1.
$$ FileGetSheetIdx
If the work sheet name is available then the function $$FileGetSheetIdx can be used to get the
index of the sheet. This function returns the Index of the specified sheet name.
415
TDL Procedural Capabilities
Syntax
$$FileGetSheetIdx:<Sheet Name>
Where,
<Sheet Name> can be any expression which evaluates to the name of the Excel work sheet.
Example:
|
10: OPEN FILE: "Output.xls" : Excel : Read
20: Log :$$FileGetSheetIdx:"Ledgers"
|
The function $$FileGetSheetIdx gives the index number of the work sheet ‘Ledgers’.
$$FileGetColumnName
If the column index is available then the function $$FileGetColumnName can be used to get
the column name. This function gives column name as alphabets for given index from the
current excel work sheet.
Syntax
$$FileGetColumnName:<Index>
Where.
<Index> can be any expression which evaluates to the Index number.
Example:
|
10 : OPEN FILE: "Output.xls" : Excel : Read
20 : Log : $$FileGetColumnName:10
|
The function $$FileGetColumnName returns value J for the specified index 10.
$$FileGetColumnIdx
If the column name is available then the function $$FileGetColumnIdx can be used to get
the column index. This function returns the index of the column for a given alphabetical name.
Syntax
$$FileGetColumnIdx:<Name>
Where,
<Name> can be any expression which evaluates to name of the column in alphabets.
416
TDL Procedural Capabilities
Example:
|
10: OPEN FILE: "Output.xls" : Excel : Read
|
20: Log :$$FileGetColumnIdx:AA
|
The function $$FileGetColumnIdx returns the column index value for the column ‘AA’ i.e.
27.
Exercise 9.3:
Objective
The objective of this program is to read from a text file which has the following format and
write to an Excel file:
Capabilities Used
The TDL Procedural programming constructs Variable, Local Formula, MSG Box,
While Loop etc. and various File IO Operations are used.
The actions New Object, SET Value, Save Target are used to create the objects.
Code
[Function: Exer RFT and WTE]
;; Read from Text and Write to Excel
Variable : Text Line: String
Variable : RowCounter : Number : 3
Variable : ColCounter : Number
/* 2 files are opened one for reading and other for writing i.e., one is the source (Text) other is the target (Excel) File
"TextFile.txt" of Type Text written earlier is opened in Read Mode*/
00: OPEN FILE : "TextFile.txt": Text : Read
;; File "WriteFile.xls" of Type Excel is opened in Write Mode
10: OPEN FILE : "WriteFile.xls": Excel: Write
20: ADD SHEET: "From Text File"
/*All the reading operations are performed on the source file i.e., FileRead Function reads from the source file which is
TextFile.txt*/
30: WRITE CELL: 1: 1: $$FileRead
;; Writing Column Titles in Excel File
40: WRITE CELL: 2 : 1 : "Name"
50: WRITE CELL: 2 : 2 : "Parent"
60: WRITE CELL: 2 : 3 : "Opening Balance"
;; Looping till the End of File is encountered in the Source Text File "TextFile.Txt"
417
TDL Procedural Capabilities
418
TDL Procedural Capabilities
Output
Program Explanation
The function Exer RFT and WTE is used to read from a Text file and write to an Excel file.
So two files are required for successful execution of this program. The action OPEN FILE is
used to open the file “TextFile.txt” in read mode by specifying the parameter as “Read”.
Whereas the file “Writefile.xls” is opened for writing by specifying “Write “. The action
ADD SHEET is used to add a new sheet “From Text File” in the Excel file “WriteFile.xls”
The reading form the “Textfile.txt” is done line by line. The function $$FileRead without any
parameter is used to Read the entire first line and action WRITE CELL is used to write it in
the specified row, column.
The looping construct WHILE is used to loop through the Text File to check for End of File.
The function $$FileIsEOF returns true is the End-Of File is reached. The exit condition for the
loop is when the Text “Printed” is encountered.
The variable “TextVar” is used to store the content of a line. In the text file ‘-‘(hyphen) is used
as a separator for Name, Group and Opening Balance. The looping construct For Token is
used to tokenize the Contents of variable “TextVar” and writing each token in in a cell identi-
fied by the value of variables “RowCounter” and “CollCounter”. The value of these variables
is incremented within the loop to determine the next Row and Column where the next value of
variable “TextVar” will be printed in Excel.
419
Chapter 10: Variable Framework
421
Variable Framework
A member variable can be a single instance or a list variable. A member variable can be a
compound variable and can have members again, and therefore any hierarchy can be created.
Compound variables help grouping of related information together into one specification.
List Variable
A variable at the declaration time can be either declared as a single instance or as a list. List
variable is a container (data structure) variable and hence they are not defined. Variables can
be declared as list.
List Variable can hold one or more variables which can be either a simple or compound varia-
bles. Each of these is called Element Variables. Element Variable holds value as well as key if
specified. The key is optional, and hence without a key also elements can be added to list vari-
ables. The value of key specified for each of the element variables must be unique.
a. Simple List Variable
Simple Variable can be declared as a list. Simple List Variables can hold multiple values of
single data type.
b. Compound List Variable
Compound Variable can be declared as a list. Compound List Variables can hold multiple
values of different data types.
10.2 Usage
422
Variable Framework
Where,
<Variable Name> is the name of the variable
<Data Type> is primary data type name
Example:
[Variable: GroupNameVar]
Type: String
In this example, a variable which holds the data type of string is defined.
Default
Default value of the variables can be specified during definition using DEFAULT attribute.
This is the initial value which is assigned to the variable when it is instantiated / declared. We
can also specify the default value during declaration / instantiation. The difference is that the
default value specified using this attribute at the definition time will be applicable to all
instances of the variable declared (at any scope). Default value specified while declaration will
be apply only to the specific instance.
Declaration and scope will be covered in detail in the subsequent topics. The
above explanation will be clearer after that.
Syntax
[Variable: <Variable Name>]
Default:<Default Value>
Where,
<Variable Name> is the name of the variable.
Example:
[Variable: GroupNameVar]
Type : String
Default : $$LocaleString:“SundryDebtors”
In this example, the default value for the variable is set as “Sundry Debtors”.
423
Variable Framework
Volatile
If the Volatile attribute in variable definition is set to Yes, then the variable is capable of
retaining previous values from the caller scope. The default value of this attribute is Yes. ie., if
the variable by the same name is declared in the called Report/Function and the volatile
attribute is set to “Yes”, then in the called Report it will assume the last value from the caller
Report. The default value of the attribute Volatile is always “Yes”.
In order to understand it better, let us elaborate the above further. When a variable is declared /
instantiated it assumes a default value. The default value which it assumes is controlled by the
following factors:
1. If volatile is set to “Yes” for a variable in its definition and is instantiated / declared
inside function/report, and the variable by the same name exists in the parent scope,
then it will take its default value from the parent scope. If no variable by the same
name exists in the parent scope, it will take the default value specified within the def-
inition.
2. If default value is specified within the declaration itself, it will assume that value.
If a new report Report2 is initiated, using a volatile variable GroupNameVar, from the current
report Report1, the same variable in Report 2 will have the default value as last value saved in
Report 1. Within Report 2 the variable can assume a new value. Once the previous report
Report1 is returned back from Report2, then the previous value of the variable will be
restored. A classic example of this is a drill down Trial Balance.
Syntax
[Variable: <Variable Name>]
Volatile : <Logical Value>
Where,
<Variable Name> is the name of the variable.
<Logical Value> is either Yes or No.
Example:
[Variable: GroupNameVar]
Type : String
Volatile : Yes
424
Variable Framework
Volatile Attribute of GroupNameVar Variable is set to Yes, which means that Group NameVar
can inherit values from one Report to another.Variables defined at the function level are Non
Volatile by default. They do not inherit the values from the caller scope.
Persistent
This Attribute decides the retention periodicity of the variable. i.e till when will it retain the
value, i) till application termination or ii) after application termination as well. Setting the
attribute Persistent to Yes, means that the value saved during the last application session will
be retained permanently in the system. When the next session of Tally is started it will take its
initial value from the value saved in the previous session. i.e., the latest value of the variable
will be retained across the sessions. Variables declared at the system scope can only be
persisted in the default file named tallycfg.tsf which will be available in the folder path
specified for Tally Configuration file. Each time Tally is restarted, these variable values are
accessed from this file.
A List variable at a system scope can also be persisted by specifying the persistent attribute for
its element variable (whether it is simple/compound) within the definition. Inline variables
even at system scope cannot be persisted. We will discuss about inline variable declaration in
the further topics:-
Syntax
[Variable: <Variable Name>]
Persistent : <Logical Value>
Where,
<Variable Name> is the name of the variable
<Logical Value> is either Yes or No.
Example:
[Variable: SV Backup Path]
Type : String
Persistent : Yes
The Attribute Persistent of the variable SV Backup Path has been set to Yes which means that
it retains the latest path given by the user even during the subsequent sessions of Tally.
425
Variable Framework
Repeat
The attribute Repeat for a variable is used for its usage in Columnar Reports. It accepts collec-
tion name and optional method name as parameters. Multiple values are stored in the variable
based on an implicit index. Method value of each object of the collection will be picked up
and stored in the variable based on implicit index. In case method name is not specified the
variable name is considered as the method name and picked up from the collection.
Syntax
[Variable: <Variable Name>]
Repeat : <Collection Name>[:<Method Name>]
Where,
<Variable Name> is the name of the variable
<Collection Name> can be an expression which evaluates to a collection name.
<Method Name> is the name of the method whose value needs to be picked up from each
object of the collection. If not specified, variable name is considered as the method name.
Example:
[Variable: SVCurrentCompany]
Volatile : Yes
Repeat : ##DSPRepeatCollection
Let us suppose the variable ‘DSPRepeatCollection’ holds the value “List of Primary Compa-
nies”. Method value ‘SVCurrentCompany’ will be gathered from the each object of the col-
lection and stored in the index 1, index2 and so on.
We will elaborate further about Repeat Attribute under the topic “Implication
of Repeat Variables in Columnar Report”
426
Variable Framework
Variable
The attribute Variable is used to define the member variable (Simple / Compound) for a
Compound Variable.
Syntax
[Variable: <Variable Name>]
Variable : <Variable Names> [:<Data Type>[:<Value>]]
Where,
<Variable Names> is the list of simple or compound variables separated by comma.
<Data Type> is used to specify the data type of simple variable. In case of compound
variable, data type cannot be specified here as it consists of members belonging to various data
types. If the data type is not mentioned, the primary variable definition is mandatory.
<Value> is the default/initial value provided for the variable.
Specifying both <Data Type>and <Value> are optional.
If the data type is specified, then it is called inline declaration of variable. [We will learn about
inline declarations and compound variables further].
Example:
[Variable: CLV Emp]
Variable : Name : String
Variable : Age : Number : 25
Variable : Salary : Amount
Variable : Relatives
In this example, the simple variables Name, Age, Salary and the compound variable ‘Rela-
tives’ are defined as members for the Compound Variable CLV Emp.
List Variable
The attribute List Variable is used to specify a list of either a Simple or Compound Variable.
Syntax
[Variable: <Variable Name>]
List Variable : <Variable Names> [:< Data Type>[:<Value>]]
Where,
<Variable Names> is the list of Simple or Compound Variables separated by comma.
427
Variable Framework
<Data Type> is the data type of Simple Variable. In case of Compound Variable, data type
cannot be specified here as it consists of members belonging to various data types.
<Value> it denotes the no of elements in the list
Specifying both <Data Type>and <Value> are optional.
Example:
[Variable: CLV Emp]
Variable : Name : String
Variable : Age : Number
Variable : Salary : Amount
List Variable : City : String : 3
List Variable : Relatives
[Variable: Relatives]
Variable : Name : String
Variable : Age : Number
Variable : Relation : String
Variable : Salary : Amount
In this example, in addition to simple variables, a simple list variable City and a compound list
variable Relatives are defined as members using the attribute List Variable. A separate defini-
tion is required for the compound list variable Relatives as it holds the multiple values of
different data types. [We will learn about List Variables in the forthcoming topics]
428
Variable Framework
Can have collections (compound col- Can have Compound List Variable as its
lections) member
*Cannot have objects under it Can have a Compound Variable as its
directly* member
We can have a comparison between the internal Data Object ‘Voucher’ and a Compound
Variable ‘CLV Emp’ to understand the similarities between an Object and Compound
Variable. For instance, the Compound Variable ‘CLV Emp’ is defined as below:
429
Variable Framework
System
Variables declared at system level will starts its life when the application starts, and will be
alive till the application termination
System variables are declared using a special [System: Variable] definition. The variables
declared at system scope are accessible everywhere in the system.
Syntax
[System: Variable]
Variable Name : <Initial Type Based Value>
Or
Variable : <Variable Names> [:<Data Type>[:<Value>]]
430
Variable Framework
Or
List Variable : <Variable Names> [:<Data Type>[:<Value>]]
Or
Variable : <Instance Names>:[<Variable Name>]
Or
List Variable : <Instance Names>:[<Variable Name>]
Where,
<Initial Type Based Value> is the initial value specified to the variable
<Instance Names> is the list of simple / compound / list variables separated by comma
(instance variables).
<Variable Name> is the simple or compound variable name.
The variables can be declared at the system scope by using the above. The attribute Variable
and List Variable usage is same as described above in the “Variable Definition”.
Example:1
[System : Variable]
BSVerticalFlag : No
The BSVerticalFlag Variable is declared in System Scope. Hence, this variable value being
modified in a Report is retained even after we quit and re-enter the Report.
Example:2
Below is the definition of a Compound Variable “Employee”
[Variable: Employee]
Variable : EmpName : String
Variable : Designation : String
Now we can create a variable instance using the definition of another variable.
[System: Variable]
Variable : Prem : Employee
;; an instance is declared with the name as ‘Prem’ and definition name as ‘Employee’. The variable instance ‘Prem’ will inherit
the entire structure of variable definition ‘Employee’.
Variable : Kamal, Vimal : Employee
;; two instances are declared with the names “Kamal” & “Vimal” and the definition name as “Employee”
List Variable : Employee2 : Employee
431
Variable Framework
;; a List Variable instance is declared with the name “Employee2” and the definition name as “Employee”
Example:3
[System: Variable]
Variable : Employee1 : String : “Suresh”
Variable : Employee2 : Employee1
In this example, we are trying to declare a variable instance ‘Employee2’ which is of type of
another variable ‘Employee1’. This will NOT work because the variable ‘Employee1’ is
declared as inline hence it is not having any defined structure.
Hence, inline variables can not be used to declare another variable instance.
Report
Variables declared at report definition are termed having Report Scope. These variables will
exist till the life of the report.
The variables declared at report scope are accessible from the report itself and all TDL
elements which are executed from within this report such as another report, function etc.
Report variables will get its default value from the definition specification or from the declara-
tion specification or values will be inherited from the owner scope if variable is marked as
volatile.
Report allows two special attributes SET and PRINT SET to set / override the values of the
variable during the startup of the report either in display / print mode respectively.
Form definition also has a SET attribute which overrides the variable’s value during startup
creation and subsequent re-creation of the form during any refresh / regeneration.
We will study about these value specification attributes in detail under the topic “Manipulating
Simple & Compound List Variables”.
Syntax
[Report : <Report Name>]
Variable : <Variable Names>
Or
Variable : <Variable Names> [:<Data Type>[:<Value>]]
Or
List Variable : <Variable Names> [:<Data Type>[:<Value>]]
432
Variable Framework
Or
Variable : <Instance Names>:[<Variable Name>]
Or
List Variable : <Instance Names>:[<Variable Name>]
Where,
<Instance Names> is the list of Simple / Compound / List Variables separated by comma
(instance variables).
<Variable Name> is the Simple or Compound variable name.
The variables can be declared at Report scope by using the above. The attribute Variable and
List Variable usage is same as described above in the “Variable definition”.
Example:
[#Report: Balance Sheet]
Variable : Explode Flag
Explode Flag Variable is made local to Report Balance Sheet by associating it using the Report
attribute ‘Variable’. This variable retains its value as long as we work with this Report. On
exiting the Report, the variable is destroyed and the values are lost.
Function
Function (User Defined Function) also allows the variables to be declared at its scope.
Function variables has lifetime till the end of the execution of the function.
Function variables can also be declared with default value. Function variables will never
inherit the value from the parent context. This means that a volatile attribute on function
variables has no effect. Function allows actions to change the value of the variables.
Function allows a special scope as STATIC. A static variables declared in a function are equiv-
alent to a system variables but can be accessed only within the defined function. Their initial
values are set only during the first call to the function, and later it retains the value for further
calls.
Only simple or compound variables can be declared as static. List variables are not currently
supported at static scope.
Syntax
[Function: <Function Name>]
Variable : <Variable Names>
433
Variable Framework
Or
Variable : <Variable Names> [:<Data Type>[:<Value>]]
Or
List Variable: <Variable Names> [:<Data Type>[:<Value>]]
Or
Variable : <Instance Names>:[<Variable Name>]
Or
List Variable: <Instance Names>:[<Variable Name>]
Or
Static Variable: <Variable Names>[:<Data Type >]
The variables can be declared at Function scope by using the above. The attribute Variable and
List Variable usage is same as described above in the “Variable definition”.
Example:1
[Function : FactorialOf]
Variable : Factorial
The Function ‘FactorialOf’ requires variable ‘‘Factorial’ for calculation within the Function.
Example:2
[Function : Sample Function]
Static Variable : Sample Static Var : Number
The static variable ‘Sample Static Var’ retains the value between successive calls to Function
‘Sample Function’.
Inline Declaration
Variables can also be defined (with limited behavior) during declaration itself, so a separate
definition would not be mandatory. These are called inline variable specification (i.e during
declaration itself the variables are defined inline)
Only the DATA TYPE and the DEFAULT VALUE can be specified as the behavior for inline
variables. If the DATA TYPE is specified as a variable name (i.e., not an implicit data type key
words such as String, Amount etc.,) or is left blank it is treated as pre-defined variables.
Persistence
Inline variables even at system scope cannot be persisted in the system file tallycfg.tsf.
However inline variables at System Scope and Report Scope can be persisted in a User
Specified File using the actions SAVE VARIABLE and LOAD VARIABLE.
434
Variable Framework
Syntax
Variable: <Variable Names> [:<Data Type>[:<Value>]]
Where,
<Variable Names> is a list of simple variables separated by comma
<Data Type> is the data type of simple variable
<Value> is the default/initial value provided for the variables and this value specification is
optional
Example:
[Report: Cust Group Report]
Variable: VarGroupName1, VarGroupName2 : String : “Sundry Debtors”
In this example, the Simple Variables VarGroupName1, VarGroupName2 of type string are
declared in a Report hence the following separate variable definitions are not required which
will help to reduce the coding complexity.
[Variable: VarGroupName1]
Type: String
[Variable: VarGroupName2]
Type : String
Syntax
List Variable : <Variable Names> [: <Data Type> [: <Value>]]
Where,
<Variable Names> is a list of simple variables separated by comma
<Data Type> is the data type of simple variable
<Value> it is treated as the count to initialize the list with the specified elements by default
435
Variable Framework
The number of elements can be specified only for an index based list.
Example:
[System: Variable]
List Variable: VarGroupName1, VarGroupName2 : String : 10
In this example, the variables VarGroupName1 and VarGroupName2 of string data type are
declared as inline simple list variables at system level and each variable will have 10 elements
by default.
SAVE VARIABLE
The action SAVE VARIABLE is used to persist the System and Report Scope Variables in a
user specified file.
Syntax
SAVE VARIABLE : <FileName> [:<Variable List>]
Where,
<File Name> is the name of file in which the system scope/ report scope variables are per-
sisted. 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 saved in the file.The
special character * also can be used to specify the variable list which means all at 'current
scope'.When * is used, it will ignore the persist flag and save all variables in the scope.
Leaving this parameter as BLANK will persist all the variables which are set “Persist:Yes” at
variable definition level.
Dotted notation syntax is also supported in the variable list specification. However this cannot
be used for SUB variables. This can be used only for accessing parent scope variables.
LOAD VARIABLE
The action LOAD VARIABLE is used to reload the System and Report Scope variables from
the specified file.
436
Variable Framework
Syntax
LOAD VARIABLE : <FileName> [:<Variable List>]
Where,
<File Name> is the name of file in which the system scope/ report scope variables are per-
sisted. Specifying file extension is mandatory while loading variable values.
<Variable List> is a list of comma separated variables that need to be loaded from the file.
While loading * i and ‘Persist’ flag of the variable are ignored. It is assumed that the variable
must have a persist flag OR it is saved forcefully and hence to be loaded.
Example:1
There is a requirement to persist values of all system scope variables in a user specified file
and load the values from the file whenever required. Refer to the below code snippet:-
[#Menu: Gateway of Tally]
Add: Button : SLSystemScopeSave, SLSystemScopeLoad
Buttons SLSystemScopeSave & SLSystemScopeLoad are added at the Gateway of Tally
Menu to execute the actions SAVE VARIABLE & LOAD VARIABLE.
[Button: SLSystemScopeSave]
Key : Alt+F
Action : SAVE VARIABLE : SLSystemScope.pvf : *
Title : "Save Sys Var"
Values of all system scope variables will be persisted in the file SLSystemScope.pvf on
execution of the action SAVE VARIABLE.
[Button: SLSystemScopeLoad]
Key : Alt + L
Action : LOAD VARIABLE : SLSystemScope.pvf
Title : "Load Sys Var"
Values of all system scope variables will be loaded from the file SLSystemScope.pvf on
execution of the action LOAD VARIABLE.
Example: 2
There is a requirement to persist values of all system scope variables which are set “Persist :
Yes” at variable definition level in a user specified file and load the values from the file
whenever required. Refer to the below code snippet:
437
Variable Framework
Example:3
There is a requirement to persist the system scope variables SVSymbolInSign & SVInMillions
in a user specified file and load values of these variables from the file whenever required.
Refer to the below code snippet:-
[#Menu: Gateway of Tally]
Add : Button : SLSystemScopeSave, SLSystemScopeLoad
Buttons SLSystemScopeSave & SLSystemScopeLoad are added at the Gateway of Tally
Menu to execute the actions SAVE VARIABLE & LOAD VARIABLE.
[Button: SLSystemScopeSave]
Key : Alt+F
Action : SAVE VARIABLE : SLSystemScope.pvf : SVSymbolInSign, +
SVInMillions
Title : "Save Sys Var"
Values of the system scope variables SVSymbolInSign & SVInMillions will be persisted in
the file SLSystemScope.pvf on execution of the action SAVE VARIABLE.
438
Variable Framework
[Button: SLSystemScopeLoad]
Key : Alt + L
Action : LOAD VARIABLE : SLSystemScope.pvf : SVSymbolInSign, +
SVInMillions
Title : "Load Sys Var"
Values of the system scope variables SVSymbolInSign & SVInMillions will be loaded from
the file SLSystemScope.pvf on execution of the action LOAD VARIABLE.
Example: 4
Let us suppose the following report is displayed in Create mode from a menu item.
[Report: Smp SLReport]
Form : Smp SLForm
Variable : SaveLoadVar1, SaveLoadVar2
The variables SaveLoadVar1 & SaveLoadVar2 are declared at Report Scope.
[Form: Smp SLForm]
Parts : Form SubTitle, Smp SL Part
Button : Smp SaveVar, Smp LoadVar
Buttons SmpSaveVar & SmpLoadVar are added at Form Level to execute the actions SAVE
VARIABLE & LOAD VARIABLE.
Let us look in to the below scenarios to persist & load System Scope as well as Report Scope
Variable values:-
i)Persist & Load all Report Scope Variables & a specific System Scope Variable
[Button: Smp SaveVar]
Key : Alt + S
Action : SAVE VARIABLE: SLReportCfg.pvf: *,().SVInMillions
Title : "Save Variable"
Values of all variables declared at report scope and the value of system scope variable SVIn-
Millions will be persisted in the file SLReportCfg.pvf on execution of the action SAVE
VARIABLE. (The variable SVInMillions is prefixed with (). to denote the same as System
Scope Variable).
[Button: Smp LoadVar]
Key: Alt + L
Action: LOAD VARIABLE : SLReportCfg.pvf : *,().SVInMillions
439
Variable Framework
ii)Persist & Load a specific Report Scope variable & a specific System Scope variable
[Button: Smp SaveVar]
Key : Alt + S
Action : SAVE VARIABLE : SLReportCfg.pvf : SaveLoadVar1,+
().SVInMillions
Title : "Save Variable"
Value of Report scope variable SaveLoadVar1 and value of system scope variable SVIn-
Millions will be persisted in the file SLReportCfg.pvf on execution of the action SAVE
VARIABLE.
[Button: Smp LoadVar]
Key : Alt + L
Action : LOAD VARIABLE : SLReportCfg.pvf : SaveLoadVar1,+
().SVInMillions
Title : "Load Variable"
Value of Report scope variable SaveLoadVar1 and value of system scope variable SVIn-
Millions will be loaded from the file SLReportCfg.pvf on execution of the action LOAD
VARIABLE.
Static Modification
Add / Delete / change modifiers can be used on variables to change the behavior.
Example:
[#Variable : SV From Date]
Delete: Default
440
Variable Framework
Dynamic Modification
When different reports require the same Compound Variable and some modifications are
required specific to respective reports like adding additional members (local to the report) are
possible through the Dynamic Modifier ‘Local’.
Example:
In our example, we have defined a Compound Variable CLVEMP as below
[Variable: CLV Emp]
Variable : Name : String
Variable : Designation : String
Variable : Age : Number
Variable : Salary : Amount
List Variable : Contact Nos : String
List Variable : Relatives
Variable : Contact Address
441
Variable Framework
Example:
[Variable: CLVEMP]
Variable: Contact Address
Local : Variable: Contact Address : Add : Variable : State : String
Concept
Key
List variables can hold multiple values of the variable type using a string based ‘Key’ specifi-
cation. 'Key' is of type String by default. We can specify a different datatype for a key only in
scenarios where we require key based sorting. It is optional to specify the key value while
adding values to the list variable. The TDL Programmer has to explicitly specify the key
value. Key is unique for all elements in the list. If an element is added with duplicate key, then
the existing element is over written.
It is advisable to use a key only when we require frequent access to the elements of the list
based on a key.
Index
An element of the list can be accessed via ‘Index’. Index of an element is the location/position
of the variable from the first element in the current sorting order. Even if we have specified
keys for elements of a list, index is generated internally. It is always possible to access each
element in the list by specifying the index within square brackets [] in the dotted notation
442
Variable Framework
syntax. This is explained below. Index can be negative as well. In that case it is possible to
access the elements in the reverse order of entry.
Syntax
<Element Variable Specification>.<Member Variable Specifica-
tion>.< Simple Member Value specification>
Where,
<Element Variable Specification> can be a compound variable or compound list variable
[Index Expression]
<Member Variable Specification>can be a compound variable member or compound list
member variable [Index Expression]
<Simple Member Value Specification> refers to the name of the simple member in the
specified path
<Index Expression>can be an expression that evaluates to number. Suffixing a variable with
index refers to an element variable. This can be positive or negative. Negative index denotes
reverse access.
Example:
The below compound variable is defined:-
[Variable: CLV Emp]
Variable : Name : String
Variable : Age : Number
Variable : Salary : Amount
List Variable : Relatives
443
Variable Framework
[Variable: Relatives]
Variable : Name : String
Variable : Age : Number
Variable : Relation : String
Variable : Salary : Amount
The same is declared at the System Scope, hence the same can be accessed anywhere in the
system.
[System: Variable]
List Variable : CLV Emp
Example:1
Suppose, we want to set the value of a simple variable ‘Employee Name’ which is declared at
Report Level
[Report: Employee Report]
Variable : Employee Name : String
SET : Employee Name : ##CLVEMP[1].Name
The variable Employee Name will be set with the value of member “Name” of the first
element of the Compound List Variable “CLVEMP”
Example: 2
In case we need to a display the age of first relative of the second employee we would use the
following statement in a field in a report
[Field: RelAge]
Set As : ##CLVEMP[2].Relatives[1].age
We will discuss in detail regarding the value specification attributes and actions with the
enhanced variable path specification in the further topics.
444
Variable Framework
Where,
<Definition Type> is the name of the definition such as Report, Function etc. in the current
execution chain.
<Definition Name Expression> can be an expression which evaluates to a definition name.
The Definition Name Expression is optional.
Exercise 9.1:
Objective
The objective of this program is to understand the scope of variable and extract value from
variables in different scopes
Capabilities Used
Scope specification in Variable Dotted Syntax at Field Level
Code:
[Function: Exer Variable Scopes]
VARIABLE : Exer Variable ;; Variable declared within Function Scope
445
Variable Framework
446
Variable Framework
[System: Variable]
/* Variable declared at System Scope */
Exer Variable : "This is System scope value"
447
Variable Framework
Output
Program Explanation
In this exercise, the Function Exer Variable Scopes is called from a Menu and the report
“Exer Variable Scopes” is displayed from the Function Exer Variable Scopes. Hence, the
current execution chain is Menu > Function Exer Variable Scopes > Report Exer Variable
Scopes.
A variable Exer Variable is defined and declared at the System Scope. The Same Variable is
declared and the value for the variable set both at Function and Report Level.
The report Exer Variable Scopes displays the value of the variables of different scopes such
as Current Scope (Report), Owner Scope (Function), System Scope etc. Variable values are
extracted at the field level by specifying scope /relative scope and absolute scope specifica-
tion.
Syntax
LIST ADD : <List Variable Specification> : <Key Formula> +
[:<Value Formula>[:<Member Specification>]]
Where,
< List Variable Specification > is the simple list or compound list variable specification
448
Variable Framework
Example:
Adding elements to Simple List Variable
1. Adding an element to Simple List Variable SLV Emp with a Key
2. Adding an element to Simple List Variable SLV Emp with a Key and a value
3. Adding an element to Simple List Variable SLV Emp with a Key and a value and sub-
sequently overriding a value corresponding to a particular key
449
Variable Framework
[System: Variable]
List Variable : CLV Emp
450
Variable Framework
The values are hard coded in the examples for explanation purpose. The above
Simple & Compound List Variable examples are used to explain further list
variable manipulations.
451
Variable Framework
Example:
Deleting elements from Simple List Variable
1. Deleting a single element from a Simple List Variable
452
Variable Framework
453
Variable Framework
The element identified by the index number ‘2’ will be deleted from the Simple List Variable
“SLV Emp” on execution of the action.
2. Deleting all elements from a Simple List Variable
Example:
1. Expanding Simple List Variable
454
Variable Framework
Value Specifications
The value for the Simple / List Variables (Simple & Compound) can be specified using the
Attributes at Report and Form Level and using Actions at User Defined Functions.
Report Level
The attributes SET and PRINTSET are used to specify the variable values at Report Level.
Attribute “SET”
The Report attribute SET can be used to specify a variable name and its value, which will be
set during the startup of the report.
Syntax
SET : <Variable Specification> : <Value Expression>
Where,
<Variable Specification> is the variable path specification
<Value Expression> can be an expression which evaluates to a value to the variable of the
specified data type.
455
Variable Framework
Example:
SET : CLVEmp[1].Name : “Kumar” ;; Setting value to Compound List Variable element’s member
Syntax
PRINT SET : <Variable Specification> : <Value Expression>
Where
<Variable Specification> is the variable path specification
<Value Expression> can be an expression which evaluates to a value to the variable of the
specified data type.
Example:
PRINTSET : Var: “ABC” ;; Setting value to Simple Variable
Form Level
Attribute “SET”
The Form attribute ‘SET’ is similar to Report SET attribute, while report sets the value once in
its life time, the form SET is executed during every regeneration / refresh of the report.
Syntax
SET : <Variable Specification> : <Value Expression>
Where,
<Variable Specification> is the variable path specification
<Value Expression> can be an expression which evaluates to a value to the variable of the
specified data type.
456
Variable Framework
Example:
SET: Var : “ABC” ;; Setting value to Simple Variable
SET: CVEmp[1].Name: “Kumar” ;; Setting value to Compound List Variable element’s member
Function Level
Action 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 it 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 program would search 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 an expression which evaluates to a value to the variable of the
specified data type.
Example:
SET : Var : “ABC” ;; Setting value to Simple Variable
SET : CLVEmp[1].Name : “Kumar” ;; Setting value to Compound List Variable element’s member
Action MULTISET
The action MULTI SET is used to set values of compound member variables in one call.
All member specifications are relative from the compound variable specification given.
457
Variable Framework
Syntax
MULTI SET : <CompoundVariable Specification>
: <Member Specification : Value> [, <Member Specification
: Value>, …]
Where,
<Compound Variable Specification> is the compound variable specification
<Member Specification : Value> list of name-value pair for setting member values
Example:
MULTISET : CLVEMP[1]: Name :”Vimal”,Age : 26, Salary : =
($$AsAmount:10000)
In this example, all the member variables for the first element of the Compound List Variable
CLVEMP are set using the MULTISET Action.
Action EXCHANGE
The Action Exchange can be used to swap the values between two variables provided both
belong to the same data type.
The same cannot be done for the Simple List or Compound List as a whole. However, value of
an element of Simple List and Compound List Member Variable belonging to 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
458
Variable Framework
Example:
Exchanging value of a Simple Variable to another Simple Variable
EXCHANGE : EmpVarOld: EmpVarNew
Both the variables are of String data type. The value of the variable EmpVarOld is exchanged
to the variable EmpVarNew on execution of the action.
Exchanging value of an element of Simple List Variable to the element of another
Simple List Variable
EXCHANGE: SlvEmpOld[1] : SlvEmpNew[1]
The value of the first element of SlvEmpOld is exchanged to the first element of the SlvEmp-
New. Both the Simple List Variables are of String data type
Exchanging value of a Simple Variable to a member variable of a Compound List
Variable
EXCHANGE : EMP Salary : CLVEmp[1].Salary
In this example, the value of a variable Emp Salary is exchanged to the member variable
Salary of the Compound List Variable CLVEmp. Both the simple variables are of string data
type.
Action 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. The action INCR is an alias for the
action INCREMENT.
Syntax
INCREMENT : <Simple Variable Specification> [: <NumIncrement
Expression>]
Where,
<Simple Variable Specification> is the simple variable specification
<NumIncrement Expression> can be an expression which evalues to a number. Based on
this, variable value will be incremented. It is optional. If not specified, the variable value will
be incremented by 1.
Example:
INCREMENT : Counter ;; Incrementing the variable value by 1
459
Variable Framework
Action DECREMENT
Decrement is a special action provided in function scope to decrement values of the variable.
This is supported only on simple variables of type number.The action DECR is an alias for the
action DECREMENT.
Syntax
DECREMENT :< Simple Variable Specification> [:< NumIncrementEx-
pression>]
Where,
<SimpleVarSpecification> is the simple variable specification
<NumIncrementExpr> can be an expression which evalues to a number. Based on this,
variable value will be decremented. It is optional. If not specified, the variable value will be
decrementd by 1.
Example:
DECREMENT : Counter ;; Decrementing the variable value by 1
Field Level
Attribute MODIFIES
The Field attribute Modifies is used to modify the value of the variable.
Syntax
Modifies : <Variable Specification>[:<Logical Flag> +
[:<Expression>]]
Where,
<Variable Specification> is the variable path specification
<Logical Flag> can be a logical value TRUE/FALSE. TRUE would set the value after the
field’s acceptance, and FALSE will set during the acceptance of the report having the field.
<Expression> can be an expression which evaluates to a value
Example:
[Field: VarModify Field]
Use : Name Field
Variable : VarModified
Modifies : VarModified: Yes: # VarModifyField + " -" +
##SVCurrentCompany
460
Variable Framework
Let us suppose the value entered in the field is PartyName and the current company name is
ABC Company Ltd. Value of the variable VarModified will be modified as Partyname-ABC
Company Ltd after accepting the field.
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 copied from
SimpleVar1 to SimpleVar2.
Copying from Compound Variable to Compound Variable. Let us suppose, the below
compound variables are defined:
[Variable: Employee1]
Variable : EmpName : String : "Praveen"
Variable : Designation: String : "Manager"
461
Variable Framework
[Variable: Employee2]
Variable : EmpName : String
Variable : Designation: String
In the below function, we are copying the contents from the Compound Variable Employee1
to Employee2
[Variable: Employee2]
Variable : EmpName : String
Variable : Designation: String
In the below 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.
462
Variable Framework
$$ListValue:SLVEMP:##KeyVar
In this example, the variable ‘KeyVar’ holds the key value. The function returns the value of
the element identified by the key from the simple list variable ‘SLV Emp’.
463
Variable Framework
$$ListValueEx
The Function $$ListValueEx returns the value of an element at the specified index in the list.
Syntax
$$ListValueEx : <List Variable Specification>:<Index Formula>+
[:< Member Specification>]
Where,
<List Variable Specification> is the simple or compound list variable specification
<Index Formula> can be an expression which evaluates to an index number
<Member Specification> this specification is required only if the value needs to be extracted
from a specific member of a compound list variable
Example:
Retrieving value from Simple List Variable
$$ListValueEx:SLVEmp:##IndexVar
In this example, the variable ‘IndexVar’ holds the index value. The function returns the value
of the element identified by the index from the simple list variable ‘SLV Emp’.
464
Variable Framework
Where,
<Element Variable Specification> can be a compound variable or compound list variable
[Index Expression]
<Member Variable Specification> can be a compound variable member or compound list
member variable [Index Expression]
<Simple Member Value Specification> refers to the name of the simple member in the
specified path
<Index Expression> can be an expression that evaluates to number. Suffixing a variable with
index refers to an element variable. This can be positive or negative. Negative index denotes
reverse access.
Example:
Retrieving Value from Simple List Variable
SET : TempVar : ##SLVEMP[3]
The value of the element identified by the index ‘3’ from the Simple List Variable ‘SLVEMP’
will be set to the variable ‘TempVar’.
465
Variable Framework
This is useful to walk keyed list variable elements in the current sorting order. If the element
does not have key then other loops like WHILE, FOR, etc can be used and these elements can
be operated via index.
Example:
Iterating the Simple List Variable Values
FOR IN : KeyVar : SLV Emp
LOG : $$String:$$ListValue:SLVEmp:##KeyVar
END FOR
In this example, the iterator variable KeyVar holds the Key value in every occurrence of the
iteration. In every iteration, the value of the element identified by the key is logged using the
function $$ListValue.
The looping construct FOR EACH is an alias for the looping construct FOR IN.
Where,
<List Variable Specification> is the simple list or compound list variable specification
<Index Specification> can be an expression which evaluates to a number.
466
Variable Framework
Example:
Retrieving key from a Simple List Variable
01 : LOG : $$ListKey:SLVEMP:2
In this example, Key of the second element of Simple List Variable ‘SLVEMP’ is retrieved.
In this example, Key of the first element of Compound List Variable ‘Relatives’ is retrieved.
‘Relatives’ is a member of Compound List Variable ‘CLVEMP’.
$$ListIndex
The function $$ListIndex returns the Corresponding index for the given Key
Syntax
$$ListIndex: <List Variable Specification>: +
<Key Specification>
Where,
<List Variable Specification> is the simple list or compound list variable specification
<Key Specification> can be an expression which evaluates to string value.
Example:
Retrieving index from a Simple List Variable
01 : LOG : $$ListIndex:SVEMP:E001
In this example, the index of the element identified by the key value ‘E001’ is retrieved from
the Simple List Variable ‘SLVEMP’
Retrieving index from a Compound List Variable
02: LOG : $$ListIndex:CLVEmp:E001
In this example, the index value of the element identified by the key value ‘E001’ is retrieved
from the Compound List Variable ‘CLVEMP’.
$$ListCount
The function $$ListCount retrieves the number of items in the list.
467
Variable Framework
Syntax
$$ListCount:<List Variable Specification>
<ListVariable Specification> is the simple list or compound list variable specification
Example:
01 : LOG : $$ListCount:SLVEMP
02 : LOG : $$ListCount:CLVEMP
$$ListFind
This function is used to check if a given key exists in the list or not. It returns a logical flag
indicating the existence of the key.
Syntax
$$ListFind:<List Variable Specification>:<Key Formula>
<List Variable Specification> is the simple list or compound list variable specification
<Key Formula> can be an expression which evaluates to a string value.
Example:
01 : LOG : $$ListFind:SLVEMP :E001
02 : LOG : $$ListFind:CLVEMP:E001
$$ListValueFind
This function can be used to check if a given value exists in the list. If a given list has more
than one same value, index can be used to retrieve the n’th matching value.
Syntax
$$ListValueFind:<List Variable Specification>:+
<Occurance Specification>:<Value Formula>+
[:<Member Specification>]
Where,
<List Variable Specification> is the simple list or compound list variable specification
<Occurance Specification> can be an expression which evaluates to a number
<Value Formula> can be an expression which evaluates to a value
<Member Specification> can be specified if the list element is compound. It is optional
Example:
;; Finding value from the Simple List Variable
01 : LOG : $$ListValueFind:SLVEMP:1:RAMESH
468
Variable Framework
;;Finding value from the Compound List Variable with member specification.
03 : LOG : $$ListValueFind:CLVEmp:1:PRIYA:Name
The function will return Yes if the value exists in the list else it will return No.
Some Common Functions Used
$$IsSysNameVar
This function checks if the variable has a value which is a SysName like Not Applicable, End
of List, etc. In case of repeated variables if any one value is a non-sysname returns FALSE.
Syntax
$$IsSysNameVar:<Variable Specification>
Where,
<Variable Specification> is the simple variable path specification
Example:
$$IsSysNameVar:EmpVar
In this example, the function $$IsSysNameVar returns logical value YES if the variable
EmpVar has sysname as value else it returns NO.
$$IsDefaultVar
This function determines that the content of the variable has a “Default” or blank as the value.
This function is applicable only for simple variables. In case of simple repeated variable, if
any one value is non-default, then this is not a default variable.
Syntax
$$IsDefaultVar:<Variable Specification>
Where,
<Variable Specification> is the simple variable path specification
Example:
[Field: DefaultVar]
Set as : $$IsDefaultVar:SVValuationMethod
In this Example the function $$IsDefaultVar returns logical value YES if value of variable
“SVValuationMethod“ is blank or "Default" else it returns NO.
$$IsActualsVar
This function checks if the content of the variable is blank or sysname or “ACTUALS”.
Syntax
$$IsActualsVar:<Variable Specification>
469
Variable Framework
Where,
<Variable Specification> is the simple variable path specification
Example:
$$IsActualsVar:SVBudget
In this example, the function $$IsActualsVar returns logical value YES if the value of variable
SVBudget is blank or sysname or “ACTUALS” else it returns NO.
$$IsCurrentVar
This function checks if the content of the variable is Blank or Sysname or “Stock in hand”.
Syntax
$$IsCurrentVar : <Variable Specification>
Where,
<Variable Specification> is the simple variable path specification
Example:
$$IsCurrentVar:DSPOrderCombo
In this Example, the function $$IsCurrentVar returns logical value “YES” if value of variable
“DSPOrderCombo“ is blank or sysname or "Stock-In-Hand" else it returns “No”.
$$ExecVar
This function returns the value of a variable in the parent report chain.
Syntax
$$ExecVar:<Variable Specification>
Where,
<Variable Specification> is the simple variable path specification
Example:
$$ExecVar:DSPShowMonthly
In this example, the function $$ExecVar returns the value of the variable DSPShowMonthly
from the parent report.
$$FieldVar
This function returns the value of the field which is acting as a variable with the specified
name.
470
Variable Framework
Syntax
$$FieldVar:<Variable Specification>
Where,
<Variable Specification> is the simple variable path specification
Example:
[Collection: GodownChildOfGodownName]
Type : Godown
Child of : $$FieldVar:DSPGodownName
In this example, $$FieldVar is used to fetch the value of the variable DSPGodownName
whose value is modified in a field. This value becomes the value for the ChildOf attribute.
$$ParentFieldVar
This function gets the field variable value from its parent report.
Syntax
$$ParentFieldVar:<Variable Specification>
Where,
<Variable Specification> is the simple variable path specification
Example:
[Field: ParentFieldVar]
Set as : $$ParentFieldVar:SVStockItem
In the above Example the function returns field variable value from its parent report for the
variable “SVStockItem”
471
Variable Framework
Where,
<List Variable Specification> is the simple list or compound list variable specification
<Collection Name> is the name of collection from which the values needs to be fetched to fill
the list variable.
<Key Formula> can be an expression which evaluates to string value. It is optional.
<Value Formula> can be an expression which returns a value. The data type of the value must
be same as that of list variable. Value formula is optional if not specified only KEY is set for
each added element
<Member Specification> Member specification can be given if the list contains a compound
variable.
If both key & value are not specified blank elements are added to the list.
Example:
Populating Simple List Variable from a Collection
LIST FILL : SLV Emp : Employees :$Name:$Name
All employee names from the collection ‘Employees’ will be added to the Simple List
Variable once the action LIST Fill is executed.
In this example, all employee names from the collection ‘Employees’ will be added to the first
member variable as there is no member specification.
In this example, Designations of all employees from the collection ‘Employees’ will be added
the member variable ‘Designation’.
LIST FILL: CLV EMP[1].Relatives:$Name:$SpouseName:Name
In this example, spouse name of all employees from the collection ‘Employees’ will be added
to the member variable ‘Name’ of a Compound List Variable ‘Relatives’. ‘Relatives’ is a
member variable of the Compound List Variable ‘CLVEMP’.
472
Variable Framework
The action LIST SORT is an alias for the action LIST KEY SORT.
Example:
Sorting Simple List based on Key
LIST KEY SORT : SLVEmp: Yes : String ;;Ascending order
473
Variable Framework
Where,
<List Variable Specification> is the simple list or compound list variable specification
<Ascending/DescendingFlag> can be YES/NO. YES is used 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.
<Member Specification> is the member specification incase of compound list. If not
specified then the list is sorted by the value of first member variable.
Example:
Sorting Simple List based on Value
474
Variable Framework
Syntax
LIST RESET SORT: <List Variable Specification>
Where,
<List Variable Specification> is the simple list or compound list variable specification
Example:
LIST RESET SORT: SLVEMP
LIST RESET SORT: CLVEMP
Where,
<Field Name> is the name of the field.
<Variable Name> is the name of variable.
Example:
[Field: EmployeeName]
Variable : EmpNameVar
Implication of Repeat Variables in Columnar Report
The report in which the number of columns added or deleted as per the user inputs is referred
to as Columnar Report. In a Columnar Report, Lines are repeated vertically and Fields are
repeated horizontally. The Columnar Report can be a
475
Variable Framework
476
Variable Framework
The variable ‘DSPRepeatCollection’ holds the collection name ‘CFBK Party’. The collection
definition is as below. This collection contains a method name ‘PName’. In this case, the
variable ‘PName’ would be filled with the method value from each object of the collection
“CFBK Party”.
The attribute Repeat determines that it is a Columnar Report. The number of columns
depends on the number of values available in the variable PName.
477
Variable Framework
The Field ‘CFBK Rep Party’ is repeated based on the number of values of variable (Num-
Sets). So those many numbers of instance of the field are created. Each field will have an
implicit index number (starting from 1). This implicit index is used to evaluate expressions in
the context of the field.
Common Functions used with Columnar Reports
$$NumSets
This function returns the number of columns in the report. It does not take any parameter. If
the report is an auto report or sub report, it returns the number of columns in the parent of the
auto/sub report.
Number of set is the maximum number of values a repeated variable can hold in that report.
Syntax
$$NumSets
Example:
[Field: CFBK Rep Col Total]
Use : Qty Primary Field
Set as : $$Total:CFBKRepParty
Border : Thin Left
Invisible: $$Numsets=1
In this example, the total column will be invisible if there is only one column in the report.
$$LowValue
This function can be used to get the lowest value in a set of values in the repeated variable.
Syntax
$$LowValue:<Variable Specification>
Where,
<Variable Specification> is a simple variable specification
Example:
Let us suppose, the Repeat Variables in a Columnar Report are SVFromDate and SVToDate
478
Variable Framework
The function $$Lowvalue returns the lowest value in a set of values in the repeat variable
SVFromDate
$$HighValue
This function can be used to get the highest value in a set of values in the repeated variable.
Syntax
$$HighValue:<Variable Specification>
Where,
<Variable Specification> is a simple variable specification
Example:
Let us suppose, the Repeat Variables in a Columnar Report are SVFromDate and SVToDate
Consider the below Field Definition in the same report:
[Field: VariableHighValue]
Use : Name Field
Set as : $$HighValue:SVToDate
The function $$HighValue returns the highest value in a set of values in the repeat variable
SVToDate
$$IsCommon
This function is used with repeated variable to check if all the values in the repeat set are same.
Syntax
$$IsCommon:<Variable Specification>
Where,
<Variable Specification> is a simple variable specification
Example:
Let us suppose, the Repeat Variable in a columnar report is SVCurrentCompany
Consider the below Field Definition in the same report
[Field: VariableIsCommon]
Use : Logical Field
Set as : $$IsCommon:SVCurrentCompany
479
Variable Framework
The function $$IsCommon returns a logical value ‘Yes’ if all the values in the SVCurrent-
Company are same otherwise it returns ‘No’
$$VarRangeValue
This function gets a list of variable values separated by specified separator character. If no
separator character is specified, by default comma (,) is taken as separator character.
Syntax
$$VarRangeValue:<Variable Specification>[:<Separator +
Character> [:<Start Position> [:<End Position>]]]
Where,
<Variable Specification> is the simple variable specification
<Separator Character> is the seperator character
<Start Position> is the index which denotes the starting position
<End Position> is the index which denotes the ending position
Specifying start and end positions are optional. If not specified, the function
will return all the values of the specified Repeat Variable separated by
comma(,)
If start and end positions are specified, the function will return the values of repeat variable
with in the specified index range. Again, specifying end position is optional. If end position is
not specified, the function will return the entire values from the starting position.
Example:1
$$VarRangeValue:SVFromDate
In this example, the function returns the entire set of values of the Repeat Variable SVFrom-
Date.
Example: 2
$$VarRangeValue:SVFromDate:",":1:5
In this example, the function returns the value of the specified index range (1 to 5) of the
Repeat Variable SVFromDate
Example:3
$$VarRangeValue:SVFromDate:",":3
In this example, the function returns the entire set of values from the Starting Index position of
the Repeat Variable SVFromDate
480
Variable Framework
481
Variable Framework
The Action Modify Variable is launched 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 varible 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)
The Action Modify System has launched the report Change Period in Auto Mode. The report
is having two fields SVFromDate and SVToDate
482
Variable Framework
[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.
Where,
<Part Name> is the name of the part
<Line Name> is the name of the line to be repeated
<Collection> is the name of the collection on which the line is repeated. It is optional when a
line is repeated to store / alter /display values of list variable.
483
Variable Framework
Example:
To accept the values from a user to the Simple List Variables SLVEMP, a report is opened in
create mode. Let us look in to the Part Definition
[Part: SLV List Values]
Lines : SLV List Title, SLV List Values
Repeat : SLV List Values
BreakOn : $$IsEmpty:#SLVAlias
Scroll : Vertical
In this example, the line is repeated without a collection and it will break if the fields value
‘SLV Alias ‘is empty.
Let us look in to the Field Definitions
[Line: SLV List Values]
Fields : SLV Alias, SLV Name
484
Variable Framework
Exercise 9.1
Objective
The objective of this program is to understand the concept of List Variable
485
Variable Framework
Capabilities Used
Attribute “List Variable” at the System Variable definition to declare the Compound
List Variable
Attribute ‘Repeat’ used at Part definition for repeating line without collection
Variable Dotted Syntax for setting value to the elements within the Compound List
Variable
Variable Dotted Syntax with ## prefix to extract values from the elements within the
Compound List Variable
Functions $$ListIndex and $$ListKey to find out the Key and Index of the Element.
Code
[Report: Exer List Variable]
Form : Exer List Variable
Title : "List Variable"
486
Variable Framework
/*Action 'List Add' adds an element to the Compound List Variable 'Exer LV Student' with a key assigned to it. */
00: LIST ADD: Exer LV Student : ##pStudent
/* Function 'ListIndex' is used to return the index of the Compound List Variable for a specific key */
10: SET : IndexFromKey : $$ListIndex:ExerLVStudent:##pStudent
/* Using Dotted Syntax, setting the value to the elements within the Compound List Variable*/
20: SET : ExerLVStudent[##IndexFromKey].ExerLVStudID:##pStudID
30: SET : ExerLVStudent[##IndexFromKey].ExerLVStudClass:##pStudClass
487
Variable Framework
[System: Variable]
/* Declaring the Compound Variable 'Exer LV Student' as a System Variable having list of values */
List Variable: Exer LV Student
/* Report to display List Variables */
488
Variable Framework
In this exercise,
We are accepting the details of students from the user such as Student Name, ID and
Class
Updating the values in to the list variable
Retrieving values from the list variable and displaying it to the user.
489
Variable Framework
The report Exer List Variable is opened in Alter Mode. The line Exer LV Details is repeated
without the collection in the part Exer List Variable. Repetition of the line will be stopped if
the value of the field Exer LV StudName is empty.
User inputs will be accepted at the field level and the function Exer LV Update will be called
on focusing the line satisfying the condition $$Line > 1. Parameters passed to the function
are Student Name, Student Id and Class (field names which are used to accept the user inputs).
In the function Exer LV Update, elements will be added to the list with Student Name as key
using the function $$ListAdd. Values to the elements will be added through Variable Dotted
Syntax using the element index. The function $$ListIndex is used to find out the element
index.
Retrieving Values from the List Variable
On accepting the form which is used to get the user inputs, the report Exer LV Display will be
displayed to show the List Variable values to the user.
In the part Exer LV Display, the line Exer LV Display is repeated without the collection. The
function $$ListCount returns the number of elements in the list variable which determines the
number of repeated lines using the part attribute Set.
The values from the list variable elements are extracted at the field level using the Variable
Dotted Syntax with ## operator prefix.
Variables in Collection
Inline variables can be declared at the collection level using the attributes Source Var,
Compute Var, Filter Var and Parm Var. The usage of declaring these inline variables at collec-
tion level is explained in the lesson Objects, Collections and Internal Object Structure
under the topic Variables in Collection.
490
Variable Framework
Where,
<Type> is the type of data source. File XML, HTTP XML, Report, Parent Report, Variable
<Identity> can be file path / scope key words / variable specification based on the type of data
source
<Encoding> can be ASCII or UNICODE. It is applicable for the data source types File XML
& HTTP XML
Example:
Simple List Variable as Data Source
[Collection: LV List Collection]
Data Source : Variable: SLVEmp
The elements of the Simple List Variable ‘SLVEmp’ will be available as objects in the collec-
tion ‘LV List Collection’
Let us suppose if a Line is repeated over the collection ‘LV List Collection’ and the value can
be retrieved in the field level as shown below:-
491
Variable Framework
In this example, we are walking to the sub-collection “Relatives” and then performing
grouping and aggregation.
Variables in Remoting
In a Tally.NET Environment where Tally at the remote end sends request to the Tally
Company at the Server, all client requests must contain the dependencies based on which data
is gathered. In other words, any request sent to the server must accompany the values config-
ured at the client to extract data from the server. For e.g., a Collection of Ledgers falling under
user selected group must accompany with the request sent to the server. Hence, the request to
the server must contain the Variable value which signifies the Group name.
Only the configuration information which is relevant to the data fetching from the Server
needs to be sent to the Server and not the ones which are User Interface related like Show
Vertical Balance Sheet, Show Percentages, etc.
When a Collection is sent to the Server, all the dependencies i.e., variable values are enclosed
within the requests automatically.
Consider the following examples
Example:1
[Collection: User Ledger Coll]
Type : Ledger
Child of : ##UserSelectedGroup
While sending this collection to the server, automatically the value for the variable UserSelect-
edGroup is also passed to the server and server responds accordingly.
Example:2
[Collection: Emp Coll]
Type : Cost Centre
Filter : EmpSpouseName
[System: Formula]
EmpSpouseName: $SpouseName= ##CLVEMP[1].Relatives[1].Name
492
Variable Framework
using an adhoc Compute within the collection. This Compute is required to set a manual
dependency on the variable and hence consider this while sending request to Server.
Let us consider the below example:
[Collection: User Ledger Coll]
Type: Ledger
Child of: $$UserFunc
[Function: UserFunc]
00 : RETURN : ##FuncVar
In this example, the function UserFunc returns the value through the variable ‘FuncVar’.
Hence, the variable ‘FuncVar’ need to be remoted using an adhoc Compute like below
493
Chapter 11: User Defined Fields,
Validation and Controls
Introduction
In the chapter on Object Manipulation, we have covered the concept creating and updating
Internal Objects and persisting the data/information as per the existing structure of the Object.
When an Object needs to be manipulated with a particular data/information it needs to be
reflected against the predefined storage name associated with it. The storage name is same as
the method name available with the Object.
In real life scenarios, as per business requirements the data storage requirements may not be
limited only to the methods already available within the Objects. The Tally user may require
additional fields on the screen apart from the ones available in the Default Tally. For eg : While
entering a Sales Voucher, the dispatch details should store Vehicle details also. In such scenar-
ios, the need to store or persist additional information as a part of existing Internal Object
becomes mandatory.
TDL provides the capability to store additional information as a part of the existing internal
object hierarchy in the form of User Defined Fields. This chapter will completely focus on
defining and storing User Defined Fields. Later, in the chapter we will also cover Validations
and Control which are the most important requirements to maintain integrity of data especially
when additional functionalities are incorporated apart from the ones provided in default.
495
User Defined Fields, Validation & Controls
1. The UDF must be defined i.e. a storage component needs to be defined with a spe-
cific data type. At this point the storage does not have a correlation with an Internal
Object
2. The field associated with the UDF needs to be in the context of a Data Object. If the
data is to be stored in a sub-object in the existing hierarchy of Internal Object, then
the field associated with UDF also needs to be in the same sub-object.
Syntax
[System: UDF]
<Name of UDF> : <Data Type>: <Index Number>
Where,
<Name of UDF> identifies the UDF and ideally it should describe the purpose for which it is
created. This is the storage/method name by which it is referred
<Data Type> Is the DataType of the UDF or the keyword “Aggregate”
<Index Number> is any number in the range from 1 and 59999.
The index numbers 1 to 29 is already used for default TDL which are as
follows:
1 - 29 of data type String
1 - 3 of data type Date and
1 - 2 of data type Number
Example:
[System: UDF]
MyUDF 1 : String : 1001
MyUDF 2 : Date : 1002
496
User Defined Fields, Validation & Controls
In the example above the UDF MyUDF1 is defined with a String Data Type and MyUDF2 is
defined with a Date DataType.
A UDF does not come into existence till some value is stored into it and is attached at with an
Internal Object. An UDF value can be stored along with an object already existing in the Tally
Database or to a new object being created for a specific Object type. Once the value is stored it
can be accessed and used from the specified level just like an ordinary method.
Example:
[Field: NewField]
Use : NameField
Storage : MyUDF
11.1.3 Retrieving values from a UDF
As we have discussed above, an UDF is attached to an Internal Object at a particular level in
the existing hierarchy structure. Once it is stored it can be accessed in the same way as an
existing internal method.
In the context of current object, the value of an UDF can be access by prefixing the $ to the
UDF name.
Syntax
$<UDF Name>
497
User Defined Fields, Validation & Controls
Example:
[Field: NewField]
Use : NameField
Set As : $MyUDF
Simple UDF
A simple UDF is used when a single or multiple values of a specific datatype needs to be
stored along with the Object specified. A UDF storing a single value of a specific datatype can
be correlated to a method eg : $closingbalance and a UDF storing multiple values of the same
datatype can be correlated to a simple collection eg name and address collection.
498
User Defined Fields, Validation & Controls
[System : UDF]
Vehicle: String: 700
In the example above the Report is in context of the Object “Company”. The field “CVeh” is
also in the context of Report Object at the first level only. So, the storage specification at the
field stores the value into the Single non repeat UDF “Vehicle”. Thereafter, the value thus
stored can be retrieved in a field which is in context of the Company Object using $vehicle.
Example:
Let us consider the example below to understand the storage and retrieval for the same
Since the implementation of a Simple UDF storing multiple values is exactly like a Simple
Collection, the repeat attribute of Part definition in this case will be as follows:
Syntax
[Part : <Part Name>]
Repeat : <Line name > : <Name of UDF>
Where,
<Part Name> is the name of the part.
<Line Name > is the name of line to be repeated.
<Name of UDF> is the name of the UDF to storing multiple values.
Example:
[Part: CompVeh]
Line : CompVeh
Repeat : CompVeh : Vehicle
Break On : $$IsEmpty:$Vehicle
Scroll : Vertical
[Line : CompVeh]
Field : CVeh
499
User Defined Fields, Validation & Controls
[Field : CVeh]
Use: Name Field
Storage: Vehicle
In the example the line containing the field CVeh is repeated over the Simple UDF Vehicle.
The data entry is repeated till the user enters an empty value. All the values entered are stored
in the UDF Vehicle and are attached to the Company Object associated to the Report. Thereaf-
ter the values stored in the UDF can be retrieved by using $vehicle in the field contained in the
line repeated over the UDF Vehicle.
Aggregate UDF
A Simple UDF can store single or multiple values of a specific datatype i. e it contains single
or repeated values of the same data type.
In real life business scenarios, this does not suffice the data storage requirements. In order to
store composite values of discrete datatypes repeating itself once or multiple times, Aggregate
UDF can be used. An aggregate UDF can contain multiple Simple UDF’s of different
datatypes where the Simple UDF can either be Single or Repeat. It can also contain other
aggregate UDFs within it and this nesting can continue upto infinity. This can be correlated
with Compound Collections.
500
User Defined Fields, Validation & Controls
<Index Number> is any number falling between 1 and 59999. The number falling between 1
to 9999 and 20001 to 59999 can be used for customisation.
<Component UDF> 1-N are the components of the aggregate UDF which are Simple or
aggregate UDFs.
Example:
A company wants to create and store multiple details of company vehicles. The details
required are: Vehicle Number, Brand, Year of Mfg., Purchase Cost, Type of Vehicle, Currently
in Service, Sold On date and Sold for Amount.
To store the required details the sub component simple UDFs are defined and to store that as
one entity one UDF of type Aggregate is defined as shown:
[System : UDF]
Company Vehicles : Aggregate : 1000
VVehicle Number : String : 1000
VBrand : String : 1001
VYear of Mfg : Number : 1000
VPurchase Cost : Amount : 1000
VType of Vehicle : String : 1002
VCurrently in Service : Logical : 1000
VSold On date : Date : 1000
VSold for : Amount : 1001
Aggregate UDF definition does not associate each component field with the aggregate UDF.
The association will take place only when the Line is repeated over aggregate UDF and the
fields within that stores value into the component UDFs.
Since the implementation of Aggregate UDF is exactly like a Compound Collection, the
repeat attribute of Part definition in this case will be as follows:
Syntax
Repeat : <Line name> : <Name of Aggregate UDF>
501
User Defined Fields, Validation & Controls
Where,
<Line Name > is the name of line to be repeated.
<Name of Aggregate UDF> is the name of UDF defined with Aggregate data type.
Example:
[Part : Comp Vehicle]
Line : Comp VehLn
Repeat : Comp VehLn : Company Vehicles
BreakOn : $$IsEmpty:$VBrand
|
|
[Field: CMP VBrand]
Use : Short Name Field
Storage : VBrand
502
User Defined Fields, Validation & Controls
<Condition> is any expression, which evaluates to a logical value. When the condition is true
then only the report will be displayed.
A sub form is not associated to the object at the report level. It inherits the object context from
the field which invokes it.
Example:
While entering the Voucher, a subform will be invoked from the field “ACLSLed” which is
used to accept the ledger name. The subform will be invoked only when the ledger name
selected is “Bill Collection” and the Voucher Type is “Receipt”. The subform is used to accept
the relevant details of the customers.
[#Field: ACLSLed]
Sub Form : BillDetail : ##SVVoucherType = "Receipt" +
AND $LedgerName = "Bill Collection"
The report “BillDetail” for the subform uses a Aggregate UDF to store the data. The UDF is
defined as follows:
[System : UDF]
CustName : String : 1000
BillNo : String : 1001
BillAmt : Amount : 1001
FPrint1 : String : 1002
BAggre : Aggregate : 1000
503
User Defined Fields, Validation & Controls
The aggregate UDF thus stored is attached to the Ledger Entries Object of the specific
Voucher. The Report Bill Details inherits the object context from the field ACLLed which is
associated at the Ledger Entries level of the object Voucher.
Usage – As a Table
The data stored in the Repeat UDF’s and Aggregate UDF’s are analogous to the Objects in the
Collection. This data can be displayed as a table. In order to use the data stored in the UDFs as
a table a collection needs to be constructed.
Collection using UDF stored at the Primary Object level
Since, the UDF will always be attached to an existing internal object, the type specification
will contain reference to the primary object.
Syntax
[Collection: <Collection Name>]
Type : <UDF Name> : <Primary Object Name>
Child Of : Object Identifier
Format : $<UDF Name>, 20
Example:
[Collection: CMP Vehicles]
Type : Vehicle : Company
Childof : ##SVCurrentCompany
Format : $Vehicle, 20
Title : "Company Vehicles"
We have seen in previous examples that the Repeat UDF “Vehicle” stores multiple values of
the same datatype and is associated with the Company Object. The collection “CMP Vehicles”
is constructed by specifying the type as “Vehicle” of a Company Object. The Child of
specifies the Company Object identifier which is the current company.
Once the collection is defined it can be used in the Table attribute of field definition. So when
the cursor is in the defined field the values stored in the UDF will be displayed as popup table.
[Field: EI Vehicles Det]
Use : Short Name Field
Table : CMP Vehicles, Not Applicable
Show Table : Always
504
User Defined Fields, Validation & Controls
Example:
Refer to the example used in using Subforms where the aggregate UDF “BAggr” with compo-
nents BillNo, BillAmt etc is attached at the Ledger Entries level. The source collection is con-
structed using Vouchers of type “Receipt”
[Collection :Src Bills]
Type : Vouchers : Voucher Type
Child Of : $$VchTypeReceipt
The BillTable collection walks over the Ledger Entries and then over BAggr UDF and then
fetches the methods “BillNo” and “BillAmt”. Format is specified for the methods to be
displayed in the Table.
[Collection : BillTable]
Source Collection : SrcBills
Walk : LedgerEntries, BAggr
Fetch : BillNo, BillAmt
Format : $BillNo, 10
Format : $BillAmt, 20
Exercise 11.1
Objective
The objective of this program is to understand the usage and implementation of the User
Defined Fields.
505
User Defined Fields, Validation & Controls
Capabilities Used
Simple and Aggregate UDF. Aggregate UDF is used to store multiple values.
The field attribute Storage is used to store the value in the UDF in the current object
context.
The field attribute Subform is used to display a form from the field.
Code
[Report: Exer User Defined Fields]
Form : Exer User Defined Fields
;; Object Company is associated so any Method or UDF stored will be stored as a part of Company Object and same can
;; be retrieved from Company Object whenever required
Object : Company
Title : "User Defined Fields"
506
User Defined Fields, Validation & Controls
507
User Defined Fields, Validation & Controls
508
User Defined Fields, Validation & Controls
509
User Defined Fields, Validation & Controls
[System: UDF]
;; All the UDFs are defined here with Data Type and the Index
Exer Company Vehicles : Aggregate : 1000
Exer Enable Company Vehicles : Logical : 1000
Exer VCurrently in Service : Logical : 1001
Exer VBrand : String : 1000
Exer VCompany : String : 1001
Exer VVehicle Number : String : 1002
Exer VType of Vehicle : String : 1003
Exer VYear of Mfg : Number : 1000
Exer VPurchase Cost : Amount : 1000
Exer VSold for : Amount : 1001
Exer VSold On Date : Date : 1000
;;End-of-File
510
User Defined Fields, Validation & Controls
Output
511
User Defined Fields, Validation & Controls
Program Explanation
The report displayed, prompts the user to Enable the Company Vehicles Module. When the
user enables the module, a report is displayed to accept the vehicle details like Model, Brand,
Date of purchase etc. The attribute Subform is used to display the report for entering vehicle
details.
In the report Exer Company Vehicle Details, line Exer Company Vehicles Details is
repeated over the aggregate UDF Exer Company Vehicles. At the field level, the attribute
Storage is used to save values entered by the user in to the UDF of appropriate data type. The
values are saved in the context of Company object which is associated at Report level. The
Break On attribute of Part is used to specify the termination condition to exit the sub form.
The field attribute Table is used to display the popup for the names of Vehicle Manufacturing
Company and Type of Vehicle. The table contains hardcoded values specified using the Table
attribute List Name.
The UDFs are defined under the definition System:UDF and their data type and index number
is also specified.
11.2 Validation and Controls
The validation can be applied at both Platform as well as TDL level. Platform always enforces
core database integrity constraints. For example a Voucher cannot be saved unless Debit and
Credit amount is matched. Second level validations can be done at the TDL level. This can be
well utilized by the application developers to enforce business requirements.
The Validation concept can be used for different purposes like
Each business will have unique organizational structure. Naturally this needs to be
reflected in the usage of Tally application. For example the restricting access of
Reports to the Data Entry Person or restricting Data Entry person to create Masters.
To assist the Data Entry operator to enter meaningful information. For Example PF
Date of Joining should not be less than Date of Joining.
To enforce the integrity constraints. For example Vouchers having manual number-
ing with ‘prevent duplicates’, duplication of Voucher numbers are not allowed.
Customized Reports can be brought under default security control
The following section discusses about developing TDL level validation with the help of Defi-
nitions, attributes and built-in functions.
512
User Defined Fields, Validation & Controls
fied, the cursor remains placed on the current field without moving to the subsequent field. It
does not display any error message.
Syntax
Validate : <Logical Formula>
Where,
<Logical Formula> returns True/False based on which the cursor movement is decided.
Example:
[Field: CMP Name]
Use : Name Field
Validate : NOT $$IsEmpty:$$Value
Storage : Name
Style : Large Bold
In the above code snippet:
The field CMP Name is a field in Default TDL which is used to create/ alter a Com-
pany.
Validate stops the cursor from moving forward, unless some value is entered in the
current field.
The function, IsEmpty returns a logical value as True, only if the parameter passed to
it contains NULL.
The function, Value returns the value entered in the current field.
Thus, the Attribute Validate used in the current field, controls the user from leaving the field
blank and forces a user input.
Unique
This attribute takes a logical value. If it is set to Yes, then the values keyed in the field have to
be unique. If the entries are duplicated, an error message, Duplicate Entry pops up. This
attribute is useful when a Line is repeated over UDF/Collection, in order to avoid a repetition
of values.
Syntax
Unique: [Yes / No]
513
User Defined Fields, Validation & Controls
Example:
[!Field: VCHPHYSStockItem]
Table : Unique Stock Item : $$Line = 1
Table : Unique Stock Item, EndofList
Unique : Yes
In this code snippet, the field, VCHPHYSStockItem is an optional field in DefTDL which is
used in a Physical Stock Voucher. The attribute, Unique avoids the repetition of Stock Item
names.
Notify
This attribute is similar to the attribute Validate. The only difference is that it flashes a warning
message and the cursor moves to the subsequent field. A System Formula is added to display
the warning message.
Syntax
Notify : <System Formula> : <Logical Condition>
Where,
<String Formula> is the name of the System Formula which is used to display as message in
message box
<Logical Formula> returns True/False based on this condition message box will trigger
Example:
[!Field: VCH NrmlBilledQty]
Notify : NegativeStock : ##VCFGNegativeStock AND +
@@IsOutwardType AND$$InCreateMode AND +
$$IsNegative:@@FinalStockTotal
In this code snippet, VCH NrmlBilledQty is a default optional field in DefTDL used in a
Voucher. The Notify attribute pops up as a warning message, if the entered quantity for a stock
item is more than the available stock and the cursor moves to the subsequent field.
Control
The attribute Control is similar to Notify. The only difference is that it does not allow the user
to proceed further after displaying a message. The cursor does not move to the subsequent
field.
514
User Defined Fields, Validation & Controls
Syntax
Control : <System Formula> : <Logical Condition>
Where
<String Formula> is the name of the System Formula which is used to display as message in
message box
<Logical Formula> returns True/False based on this condition message box will trigger
Example:
[Field: Employee PFDateOfJoining]
Use : Uni Date Field
Set as : If $$IsEmpty:$PFAccountNumber AND $$IsEmpty:+
$FPFAccountNumber Then "" Else If NOT +
$$FieldEdited OR $$IsEmpty:$PFJoiningDate+
Then $DateofJoin Else $$Value
Storage : PFJoiningDate
Width : 20
Align : Left
Style : Small Bold
Control : PFJoiningDateBelowJoinDate: +
If $$IsEmpty:$PFAccountNumber AND +
$$IsEmpty:$FPFAccountNumber Then No +
Else $$Value < #EmployeeDateOfJoin
Set Always: Yes
In this code snippet, the field, ‘Employee PFDateOfJoining’ is a default field. The control
always makes sure that Date of Joining for a Employee is always less than the Date Provident
Fund joining Date.
The difference between the field Attributes, Validate, Notify and Control are:
Field Attributes Displays Message Cursor Movement
Validate No Restricted
Notify Yes Not Restricted
Control Yes Restricted
515
User Defined Fields, Validation & Controls
Example:
[Form: Voucher]
Control : DateBelowBooksFrom :$Date < +
$BooksFrom:Company:##SVCurrentCompany
Control : DateBelowFromDate : $Date < $$SystemPeriodFrom
Control : DateBeyondToDate : $Date > $$SystemPeriodTo
In the example, Voucher is a default Form. While creating a voucher, the attribute, Control
does not accept dates beyond the financial period or before beginning of the books.
Syntax
Control: <Key Item Name> : <Logical condition>
Where,
<Key Item Name> is a string represents the Label of the Key Item
<Logical condition> returns True/False based this appearance of Menu Item is decided.
516
User Defined Fields, Validation & Controls
Example:
[Menu: Quick Setup]
Syntax
[Report: <Report Name>]
Family : <String Value>
Where,
<String Value> is a string which will appear under Security Control
517
User Defined Fields, Validation & Controls
Example:
[Report:Balance Sheet]
Family : $$Translate:"Balance Sheet"
In this code snippet, the Balance Sheet is added to the Security list. The users having rights to
display Balance sheet can only view the Report.
Function - $$Allow
This built-in function checks the permissions for the currently logged in user. This function
can be effectively used to enable or disable an interface based on the permissions for the
currently logged in user.
Syntax
$$Allow:<Literal Value1>:< Literal Value2>
Where,
<Literal Value1> is a string which decides the type of access.
<Literal Value2> is a string an is the name of Report which pops under default collection
‘Report List’.
Example:
[!Menu: Gateway of Tally]
Key Item : @@locAccountsInfo : A : Menu : Accounts Info. : +
NOT $$IsEmpty:$$SelectedCmps
Control : @@locAccountsInfo : $$Allow:Create:AccountsMasters +
OR $$Allow:Alter:AccountsMasters OR +
$$Allow:Display:AccountsMasters
In this code snippet, the Menu, ‘Gateway of Tally’ is a default optional menu. The Menu Item
‘Account Info.’ will be displayed only if the given condition is satisfied. The function ‘Allow’
checks whether the current user has the rights to access the report displayed under the current
Menu item. The value ‘Accounts Masters’ has been derived from the attribute Family at the
report definition.
Exercise 11.2:
Objective
The objective of this program is demonstrating the usage of various controls at the field level.
518
User Defined Fields, Validation & Controls
Capabilities Used
The field attributes Notify, Control and Validate are used.
Code
[Report: Exer Field Controls]
Form : Exer Field Controls
Title : "Field Controls"
519
User Defined Fields, Validation & Controls
Output
520
User Defined Fields, Validation & Controls
521
User Defined Fields, Validation & Controls
Program Explanation
The Report Exer Field Controls displays the fields and for each field a control is added. The
field attributes Notify, Control and Validate are used in fields for specifying the behavior when
the given condition is not satisfied.
In the first field the field attribute Notify is used to display the warning message Number
should be greater than 10 as shown in the first image. The Notify attribute displays the
warning message and allows the user to continue.
The second field uses the attribute Control to restrict the value entered in the field. If the
number entered is greater than 10 then it displays the error message “Number should be less
than 10" as shown in the second image. The Control attribute displays the error message and
won’t allow the user to continue until the number entered is less than 10.
The last field uses the attribute Validate to restrict the value entered in the field. If the number
entered is not in the range 10-20 then it won’t allow the user to continue until the number
entered is in between 10 and 20as shown in the third image. The attribute Validate won’t
display any warning/error message.
522
Chapter 12: Advanced Reporting and
Printing
Till now we have concentrated on the language capabilities from the perspective of understand-
ing the interface design elements, internal data object structure, data entry aspects, data storage
and alteration etc.
This is the conclusive chapter of our book and will focus primarily on the output rendering
capabilities. We will examine the Display and Print mode specifically in this chapter. The
initial sections will begin with a discussion on the design of the various Report Layouts and
data retrieval within it. The various printing techniques will be taken up in the subsequent
section.
12.1 Advanced Reporting
Reports are management tools. Their main purpose is to quickly grasp the essential elements
and relationships found in raw data. A business may require a Report for multiple purposes
like:
To satisfy statutory requirement
To know the health of the business
To know the inventory status
To generate a MIS Report
To print transaction documents like Invoice, Purchase Order etc.
Default Tally application have number of Accounting, Inventory, Payroll and statutory Reports
which is generated based on the vouchers till date. All the statutory requirements are com-
pletely handled by the default product. But a business may have a specific requirement in the
area of Accounting, Inventory and Payroll. This may lead to make amendments to the existing
default Reports or adding a new report(s).
523
Advanced Reporting and Printing
ment and logically navigate to other Reports. The Day Book, Stock Summary, Trial Balance,
Group Summary are the some of the default Tabular Reports in Tally.ERP 9.
A Tabular Report has the simplest format of all the Report formats. A typical Tabular Report
will have following components:
Report Title : It contains the Name of the Report, the Title for each column, the
Day/Period for which a Report is generated, etc
Report Details: It contains the actual information and this Line will be repeated
over the objects of a Collection.
Report Total: This component is optional and contains the Total of the respective
columns.
A Tabular Report can be made Interactive by adding the following features:
Adding Button/Key to change the period, to control the appearance of few columns
of the Report, etc
Adding explosions to the lines
Drill down to view detailed information about a particular Row (Hierarchical
Reports)
524
Advanced Reporting and Printing
Syntax
Total : <Fld1> [,<Fld2>, …]
Where,
<Fld1> is the name of the Field/Column whose running Total will be calculated at Field by
using Built-in Function $$Total
The Built-In function $$Total is used to calculate the running total for all the visible Fields of
a Column
Syntax
$$Total :<Fld1>
Where,
<Fld1> is the name of the Field which is mentioned under the Part definition under Total
attribute.
Example:
In the code snippet given below the part TB Part contains the Title Line TB Title, Detail line
TB Details and the total line TB Totals. The total attribute specifies the field name TB Amount
Field within the detail line. The total line TB Total contains a field which uses the function
$$Total to calculate the total of all the repeated fields TBAmountField contained within the
detail line.
525
Advanced Reporting and Printing
526
Advanced Reporting and Printing
The following screen shot is displayed when a user is clicked button to change the period to
view the report for a given period:
527
Advanced Reporting and Printing
[Report: Grp]
Delete: Object
Add : Object : Group
Use : Group
Form : TSPL Grp
528
Advanced Reporting and Printing
The following screen shot is displayed when a user clicks CTRL + ENTER on line Sales
Accounts:
529
Advanced Reporting and Printing
Example:
In the following code snippet the part “TB Group Explosion” is exploded from each line “TB
Details”. The Explode is evaluated when the Object pertaining to the line is a group and the
keys Shift+Enter is pressed. The part “TB Group Explosion” again repeats the line “TB
Details Explosion” over a collection which in turn explodes the same part “TB Group Explo-
sion” based on the same condition as above. The explodes happen recursively till the line
object is a ledger object.
[Line: TB Details]
Fields : TB Name Field, TB ParName Field
Right Fields: TB Dr Amt Field, TB Cr Amt Field
Explode : TB Group Explosion : $$IsGroup AND +
$$KeyExplode
[Part: TB Group Explosion]
Lines : TB Details Explosion
Repeat : TB Details Explosion : TB GroupsLedgers
Scroll : Vertical
[Collection: TB GroupsLedgers]
Collection : TB Groups, TB Ledgers
530
Advanced Reporting and Printing
[Collection: TB Groups]
Type : Group
Child Of : #SVGroup
Filter : Zero Filter
Fetch : Name, ClosingBalance
[Collection: TB Ledgers]
Type : Ledger
Child Of : #SVGroup
Filter : TSPL Zero Filter
Fetch : Name, ClosingBalance
[System: Formula]
Zero Filter : $ClosingBalance > 0 AND NOT $$IsLedgerProfit
531
Advanced Reporting and Printing
This Volatile attribute for this variable is set to “Yes” i.e this variable retains previous value
from the caller scope. The same variable is declared and is available in the called Report.
[Variable: Group Var]
Type : String
Default : ""
Volatile : Yes
[Report: TB]
Form : TB
Variable : GroupVar
532
Advanced Reporting and Printing
The called report displays the data from a collection which uses the value of the variable in the
ChildOf attribute of the collection.
[Collection: Collection]
Type : Group
Childof : ##GroupVar
The following screen is displayed when the user invokes the Report.
When the key Enter is pressed by the user, the next screen displays the Sub Groups of the
current Group as shown below:
533
Advanced Reporting and Printing
Exercise 12.1:
Objective
The objective of this program is to develop a Report to display Stock Group/Stock item
Details like Name, Opening, Inwards, Outwards and Closing quantities with drill-down
facility till Voucher.
Capabilities Used
Collection definition with attributes Type, Childof, Filter, Fetch and Collection
Part definition with attributes Scroll, Repeat and Total
Field Definition with attributes Display, Variable and Switch
Built-in Functions $$KeyExplode and $$Total
534
Advanced Reporting and Printing
Code
[Report: Exer HD Stock Summary]
Form : Exer HD Stock Summary
Title: "Stock Summary"
;; Declaring a Local Variable which holds the variable name while in drill down as the same Report is being invoked
every time the user drills down from a Group Name
Variable: Exer HD GroupName: String
;; Part Attribute 'Total' accepts a list of Field Names on which Totals are to be accumulated
Total : Exer HD SS Open Qty, Exer HD SS Inwd Qty, +
Exer HD SS Outw Qty, Exer HD SS Clsg Qty
Scroll : Vertical
CommonBorder : Yes
535
Advanced Reporting and Printing
Output
Program Explanation
The part Exer HD Stock Summary has three lines. The topmost line Exer HD SS Title is
utilized for displaying column Titles and is using the line Exer HD SS Details, so it will
inherit all the attributes of the line Exer HD SS Details. At line Exer HD SS Title we have
localized all the fields and set the values by using attribute ‘Set as’.
At part Exer HD Stock Summary, Total attribute is specified with the fields Exer HD SS
Open Qty, Exer HD SS Inwd Qty, Exer HD SS Outw Qty, and Exer HD SS Clsg Qty to
calculate running total at the bottom Line Exer HD SS Total.
At part Exer HD Stock Summary, second line Exer HD SS Details has been repeated over
collection Exer HD SS GroupsItem. Exer HD SS GroupsItems is a Union collection and at
any particular point of time the Objects were gathered from Collections Exer HD SS Group
and Exer HD SS Items. The objects for these collections are depending on the Childof
condition which in turn depends on Field acting as Variable ExerHDGroupName. The Value
of Variable ExerHDGroupName is decided at the Field Exer HD SS Name.
At the Field Exer HD SS Name the Enter key will display a Report Exer HD Stock
Summary. in case of StockGroup object or will display Report Item Monthly Summary in
case of Stock Item object. The attribute Variable will feed appropriate value the childof
condition of Collection Exer HD SS GroupsItem.
536
Advanced Reporting and Printing
The Line Exer HD SS Details is having exploded part if Shift + Enter key is pressed or the
F1 button is clicked and the current object is Stock Group. The Line Exer HD SS Details
Explosion inside the exploded part again recursively exploded till encounters Stock Group
object.
The Function $$KeyExplode is used to have indent at explode part.
537
Advanced Reporting and Printing
in detail line are to be accessed based on column and row values explicitly, matrix
reports are designed.
Report attribute-Repeat
The Repeat variable names over which the column/field needs to be repeated is specified at the
report level by using the Repeat attribute. This is a list type variable which accepts a list of
variable names separated by comma. These variables are system variables.
Both of these attributes Column Report and Repeat used together govern the display of the
buttons New Column, Alter Column and Delete Column on the screen. These buttons
control the appearance of addition, alteration and deletion of columns based on the user inputs
within the column report.
538
Advanced Reporting and Printing
Syntax
Repeat : <Variable names>
Where ,
<Variable names> is the list of repeat variable names separated by commas.
Line attribute-Repeat
In a multicolumn report, the report repeats a single field or a set of fields which is collectively
referred to as columns. This is specified using the Repeat attribute of the line. This attribute
provides the field names contained within the line which are to be repeated. The method
values referred to within the fields are accessed based on the internal linking with the corre-
sponding Repeat variable value.
Example:
Incorporating Multi Column Feature to Simple Trial Balance report.
These two attributes together add the three buttons as discussed above
[Report: MulCol Trial Balance]
ColumnReport: MultiColumns
Repeat : SVCurrentCompany, SVFromDate, SVToDate
539
Advanced Reporting and Printing
Step 2: Modifying the values of Repeat Variables within the column report
By clicking new column button, the report MultiColumns is displayed. This report contain
fields to accept user inputs corresponding to the Repeat variables. The modifies attribute of
the field is used to reflect the values entered in the fields into the variables.
[Field: MultiFromDate]
Use : Uni Date Field
Modifies : SVFromDate
[Field: MultiToDate]
Use : Uni Date Field
Modifies: SVToDate
[Field: MultiCompany]
Use : Name Field
Modifies : SVCurrentCompany
540
Advanced Reporting and Printing
Table : Company
The line “MulCol TB Details” is repeated over the collection “MulCol TB GroupLed”
[Part: MulCol TB Details]
Lines : MulCol TB Details
BottomLines: MulCol TB Total
Repeat : MulCol TB Details : MulCol TB GroupLed
The field “MulCol TB Amount Field” within the line MulCol TB Details “ is the field which is
repeated.
541
Advanced Reporting and Printing
If a set of fields are to be repeated then these must be components of the main field which is
specified in the repeat attribute of the line. The field “MulCol TB AmountField” is a
compound field containing the fields “MulCol TB DrAmt Field and MulCol TB CrAmt Field”
[Field: MulCol TB AmountField]
Fields : MulCol TB DrAmt Field, MulCol TB CrAmt Field
542
Advanced Reporting and Printing
543
Advanced Reporting and Printing
variable based on implicit index. In case method name is not specified the variable name is
considered as the method name and picked up from the collection.
Syntax
[Variable: <Variable Name>]
Repeat: <Collection Name>[:<Method Name>]
Where,
<Variable Name> is the name of the variable.
<Collection Name> can be an expression which evaluates to a collection name.
<Method name> is the name of the method whose value needs to be picked up from each
object of the collection. If not specified, variable name is considered as the method name.
Example:
Incorporating Auto Column Feature to Simple Trial Balance report in order to generate
columns based on periodicity or active companies based on user inputs
Step 2 :Displaying the Auto Column report using Action Auto Columns
The Button AutoButton is added to Form. Through this Button, the Report “AutoColumns
Report” is invoked for user intervention.
[Form: AutoCol Trial Balance]
BottomButton : AutoButton
[Button: AutoButton]
Key : Alt+N
Action : Auto Columns : AutoColumns Report
Title : $$LocaleString : "Auto Column”
544
Advanced Reporting and Printing
545
Advanced Reporting and Printing
Within this, the user will be given with options like ‘Days’,’ Monthly’, Yearly’ ‘Company’ etc
based on which the columns are repeated. Based on any of these options selected the Collec-
tion name, Variable name, periodicity etc will be populated with values. The table displayed
for selection is created using the collection of external Objects as defined below
[Collection: Auto Columns]
Title : $$LocaleString:"Column Details"
Object: CurrentCompany, Quarterly, Monthly,Yearly,HalfYearly
Format: $$Name, 15
The objects are defined which provide values for the methods VarName,CollName and perio-
dicity.
[Object: CurrentCompany]
Name : $$LocaleString:"Company"
VarName : "SVCurrentCompany"
546
Advanced Reporting and Printing
[Object: HalfYearly]
Name : $$LocaleString:"Half-Yearly"
VarName : "SVFromDate, SVToDate"
CollName : "Period Collection"
[Object: Monthly]
Name : $$LocaleString:"Monthly"
VarName : "SVFromDate, SVToDate"
CollName : "Period Collection"
Periodicity: "Month"
[Object: Yearly]
Name : $$LocaleString:"Yearly"
VarName : "SVFromDate, SVToDate"
CollName : "Period Collection"
Periodicity: "Year"
In case the collname is “Period Collection” periodicity is set as per option selected from the
table ie yearly, halfyearly, monthly etc and the VarName is "SVFromDate, SVToDate"
Columns can be repeated over any Repeat Variable which can assume values
from any collection. This is not limited to default collections as used above. We
will be covering such examples in the section on Matrix Reports.
547
Advanced Reporting and Printing
When the user selects any one of the options required, the system variables need to be
modified so that, the columns can be generated in the parent Report on the basis of these
values.
Field Select Auto displaying the table to select options Company, Monthly, HalfYearly,
Quarterly, Yearly
[Field: SelectAuto]
Use : Short Name Field
Table : TSPLAutoColumns
Show Table : Always
Invisible Field AutoColumns which sets the field with the method Varname as per object
selected in the table.ie if the object selected in the table is Company the field will be set with
the value SVCurrentCompany,if the object selected is either Monthly, Yearly etc., the field
will be set with the value SVFromDate, SVToDate
[Field: AutoColumns]
Use : Short Name Field
Invisible : Yes
Set as : $$Table:SelectAuto:$VarName
Set always : Yes
Skip : Yes
Invisible Field CollName which sets the field with the method CollName as per object
selected in the table. ie if the object selected in the table is Company the field will be set with
the value List of Primary Collection, if the object selected is either Monthly, Yearly etc the
field will be set with the value Period Collection.
[Field: CollName]
Use : Short Name Field
Invisible : Yes
Set as : $$Table:TSPLSelectAuto:$CollName
Modifies : DSPRepeatCollection
Set always : Yes
Skip : Yes
548
Advanced Reporting and Printing
Further this value will modify the value of the default variable DSPRepeatCollection. The
repeat variables SVCurrentCompany, SVFromDate and SVToDate assume multiple values
from the collection name as available within DSPRepeatCollection at that instance.
[Variable: SVCurrentCompany]
Volatile : Yes
Repeat : ##DSPRepeatCollection
Invisible Field SetPeriodicity which sets the field with the method Periodicity as per object
selected in the table. ie if the object selected in the table is “Company” the field will be set
with null “”, if the object selected is either Monthly, Yearly etc. the field will be set with the
value 3 month, month, year etc.
[Field: SetPeriodicity]
Use : Short Name Field
Invisible : Yes
Set as : If NOT $$IsEmpty:$$Table: SelectAuto:+
$Periodicity then $$Table: SelectAuto:+
$Periodicity else "Month"
Set always : Yes
Modifies : SVPeriodicity
Further this value will modify the value of the default variable “SVPeriodicity”. This variable
value is used within the Repeat attribute of the default collection “Period Collection”. The
objects are populated in period collection based on Periodicity.
[Collection: Period Collection]
Type : Period
Repeat : ##SVPeriodicity
The value available in the field “AutoColumns” is output to the calling report by using the
Output Attribute. In this example it is either “SVCurrentCompany” or “SVFromDate,SVTo-
Date”
[Form: AutoColumns]
No Confirm : Yes
Output : AutoColumns
549
Advanced Reporting and Printing
The line AutoCol TB Details is repeated over the collection AutoCol TB GroupLed
[Part: AutoCol TB Details]
Lines : AutoCol TB Details
BottomLines: AutoCol TB Total
Repeat : MulCol TB Details : MulCol TB GroupLed
The field AutoCol TB Amount Field within the line AutoCol TB Details is the field which is
repeated.
[Line: AutoCol TB Details]
Field : AutoCol TB Name Field, AutoCol TB Amount Field
Repeat: AutoCol TB Amount Field
If a set of fields are to be repeated then these must be components of the main field which is
specified in the repeat attribute of the line. The field “AutoCol TB AmountField” is a
compound field containing the fields “AutoCol TB DrAmt Field and AutoCol TB CrAmt
Field”
[Field: AutoCol TB AmountField]
Fields : AutoCol TB DrAmt Field, AutoCol TB CrAmt Field
In order to summarize the difference between two approaches of columnar reports let us refer
to the table below
550
Advanced Reporting and Printing
The attribute “Column Report” and The button with action specification
“Repeat” specification at the report level “AutoColumn” is added in the main form
adds the buttons “Add/Alter/Delete Col-
umn” automatically
The report to be invoked for user inputs is The report to be invoked for user inputs is
specified in the Column attribute of the specified as a parameter to the Action
report Auto Column
The column reports accepts the values for The autocolumn reports accepts the user
variables from the user inputs for the collection name which in
turn is used to populate the value of the
variable
The values provided to the variables is The output attribute of the form specifies
automatically used to repeat a column in the variable name which is to be sent and
the calling report used for repeating columns in the calling
report
Exercise 12.2
Objective
The objective of this program is to develop Stock Summary Multi column Report having
columns Name, Opening, Inwards, Outwards and Closing quantities with columnar capability.
Capabilities Used
Report attribute Column Report and Repeat
Form attribute Output
Part definition with attributes Scroll, Repeat and Total
Line attribute Repeat
Field Definition with attributes Display, Variable and Switch
Collection definition with attributes Type, Childof, Filter, Fetch and Collection
Action Auto Column
Built-in Functions $$KeyExplode, $$IsCommon and $$Total
551
Advanced Reporting and Printing
Code
[Report: Exer Columnar Stock Summary]
Form : Exer Columnar Stock Summary
Title : $$LocaleString:"Stock Summary"
Repeat : SVCurrentCompany, SVFromDate, SVToDate
/* When the attribute Column Report is mentioned, the attribute Repeat should also be mentioned. The New Column,
Alter Column and Delete Column buttons will automatically get activated once Column Report & Repeat attributes are
mentioned together in the report.*/
ColumnReport: Exer CSS MultiColumns
Variable : IsItemWise, SVPeriodicity
Variable : Exer CSS Group: String
;; PrintSet At Report Definition sets the Variable Value in Print Mode
PrintSet : Report Title : $$LocaleString:"Trial Balance"
Set : IsItemWise : No
552
Advanced Reporting and Printing
;; Every continuous page should have the above parts during Printing
[Part: Exer CSS Title]
Lines : Exer CSS T
itle1, Exer CSS Title2, Exer CSS SubTitle
Border : Thin Top
553
Advanced Reporting and Printing
554
Advanced Reporting and Printing
;; If Itemwise Option is selected by the user, Collection should have attribute BelongsTo set to Yes
;; as the Stock Items pertaining to all the Groups and Sub-Groups needs to be displayed together
[Field: Exer CSS QtySTField] ;;New Field Definition for the Page Totals
Fields : Exer CSS OpenST, Exer CSS InwdST, Exer CSS +
OutwST, Exer CSS ClsgST
Border : Thin Left
555
Advanced Reporting and Printing
556
Advanced Reporting and Printing
557
Advanced Reporting and Printing
;; Collection Definition
[Collection: Exer CSS GroupItem]
Collection : Exer CSS Group, Exer CSS Item
558
Advanced Reporting and Printing
559
Advanced Reporting and Printing
560
Advanced Reporting and Printing
;; Report AutoColumn
[Report: Exer CSS AutoColumns]
Auto : Yes
Title : $$LocaleString:"Auto Repeat Columns"
561
Advanced Reporting and Printing
Space Left : 1
Space Right : 1
Background : @@SV_UNYELLOW
Parts : Exer CSS AutoColumns
Output : Exer CSS AutoColumns
Option : Small Size Form
;; Output Attribute at Form Definition is used to return a Field value to the calling Report.
;;No Confirm Attribute at Form Definition will not prompt the user to save the auto-column screen
562
Advanced Reporting and Printing
563
Advanced Reporting and Printing
Modifies : SVToDate
Skip : Yes
/* Value of Variable 'SVToDate' is set here based on the Periodicity Method. MonthEnd is a Function gives the last day for
a given month*/
In the Report Exer Columnar Stock Summary, Exer CSS MultiColumns used as Colmnar
Report which is invoked to accept the user inputs. These inputs provide values to the various
repeat variables over which a column/field is repeated.
564
Advanced Reporting and Printing
565
Advanced Reporting and Printing
An optional form Set Auto Option is added based on the value returned by the function
$$SetAutoColumns taking the variable name “SVCurrentCompany” as parameter. The report
repeats on the basis of no of values stored in this variable. In our example it is the list of active
companies.
[Form: AutoCol Trial Balance]
Option: Set Auto Option : $$SetAutoColumns:SVCurrentCompany
Figure 12.7 Trial Balance of two different loaded companies for a specific period
566
Advanced Reporting and Printing
Example:
A report needs to be generated for displaying the Item Wise Party Wise Sales. The items are
displayed as title in rows and party names are displayed as titles across columns. The Billed
qty for each item to a particular party is displayed as information in the grid.
567
Advanced Reporting and Printing
The report CFBK Rep repeats the columns over the Repeat variable PName and sets the
value of the variable DoSetAutoColumn to yes and DSPRepeatCollection to CFBKParty.
[Report: CFBK Rep]
Variable: DoSetAutoColumn, PName
Repeat : PName
Set : DoSetAutoColumn : Yes
Set : DSPRepeatCollection : "CFBK Party"
Since the columns need to be preset before report invocation an optional form is added based
on the value returned by the function $$SetAutoColumn taking PName as the parameter.
[Form: CFBK Rep]
Option : Set Auto Vch Option : $$SetAutoColumns:PName
568
Advanced Reporting and Printing
[Variable: PName]
Type : String
Repeat : ##DSPRepeatCollection
The collection CFBKParty definition is given as below. This collection aggregates the
vouchers by Party ledger name and this is available in the collection with the method name
PName.The variable PName gets multiple values from the method PName of the collection
CFBK Party.
[Collection: CFBK Party]
Source Collection : CFBK Voucher
Walk : Ledger Entries
By : PName : $PartyLedgerName
Aggr Compute : Ptot: SUM: $Amount
The detail line “CFBK Rep Details” repeats over the collection “SMP Stock Item”
[Part: CFBK Rep]
Lines : CFBK Rep Title, CFBK Rep Details
BottomLines: CFBK Rep Total
Repeat : CFBK Rep Details: Smp Stock Item
Collection definition “SMP Stock Item” aggregates the vouchers by StockItemName which is
available in the collection with the method name “IName”
[Collection: Smp Stock Item]
Source Collection: CFBK Voucher
Walk : Inventory Entries
By : IName : $StockItemName
Aggr Compute : BilledQty: SUM: $BilledQty
569
Advanced Reporting and Printing
The line CFBK Rep Name contains the field CFBK Rep Name which displays the method
value IName. The field CFBK Rep Party is a repeated field.
[Line: CFBK Rep Details]
Fields : CFBK Rep Name, CFBK Rep Party, CFBK Rep Col Total
Repeat : CFBK Rep Party
The repeated field displays the value from a collection CFBKSummVoucher using the
function $$Collectionfieldbykey using the corresponding row and column field value as the
search key value.
[Field: CFBK Rep Party]
Use : Qty Primary Field
Set As : $$ReportObject:$$CollectionFieldByKey: +
$BilledQty:@MyFormula:CFBKSummVoucher
MyFormula: ##PName + #CFBKRepName
Format : "NoZero"
Border : Thin Left
The collection CFBK Rep Party aggregates the vouchers by PartyLedgerName and then by
StockItemName and calculates the sum of Billed Qty.The search key is defined which is a
combination of the PartyLedgerName and the StockItemName.When this collection is used
in the field CFBK Rep Party the value for the search key is provided by the corresponding
row and column title and the billedqty is accessed on the basis of that.
[Collection: CFBK Summ Voucher]
Source Collection: CFBK Voucher
Walk : Inventory Entries
By : PName : $PartyLedgerName
By : IName : $StockItemName
Aggr Compute : BilledQty: SUM : $BilledQty
Search Key : $PName + $IName
12.2 Printing
Printing is the most powerful aspect of Tally. Any report which is available as a part of the
application can just be printed on the click of a button. Moreover, this is completely configura-
570
Advanced Reporting and Printing
ble from the end users point of view. The various configuration setting help the user in
achieving the following:
The user can render the report to any output printer which is available as a part of
windows environment. i.e it is possible to direct the output to a Pdf writer, Snagit,
Fax machine etc. This enables saving the output in multiples formats as desired.
Various modes of printing available facilitate printing as per the mode selected ie
Neat, Dot Matrix & Draft mode
Printing can be configured as per the stationary available whether it preprinted/plain,
paper type, size etc.
By default Tally.ERP9 retrieves the recent printing configuration which can be from the
default printer settings or the last configuration specified in Tally.ERP9 application. The
default configuration screen is displayed as below:
From the programmer’s point of view, enabling printing for any report which is customized is
merely the task of adding the print button to the form. In addition to it, the various actions,
attributes and events for printing and configuration setting provide enormous control and flex-
ibility in the hands of the programmer for handling various requirements. These capabilities
571
Advanced Reporting and Printing
allow printing the same report in multiple formats, Invoice Printing, Multi-account printing,
Index page printing, providing horizontal/vertical page breaks, to name a few.
The printing capabilities in TDL are quite an exhaustive which is covered in detail in this
chapter. Let’s begin with the understanding of printing modes in Tally.ERP9.
12.2.1 Modes of Printing / Printing Formats
The user can specify the printing mode as per his requirement. The various print formats
available in Tally.ERP 9 are Dot matrix format, Neat mode and Quick/ Draft mode. The user
can change the print format by clicking on the button Print Format and then selecting the
format based on requirement.
Dot Matrix Format allows printing Tally.ERP 9 reports in text format using the dot matrix
printers. Dot Matrix mode is compatible with dot matrix printers. It is important to note that
only Epson printer drivers (LQ and FX series) can be used on selecting this format.
The default format for printing any report is Neat Mode. All the reports can be printed in
Quick/Draft mode except for cheques. The Neat mode and Quick/ Draft modes are compatible
with most of the printer drivers installed on the Windows Operating System.
The selected reports are available for preview only when the selected format is
Neat Mode
572
Advanced Reporting and Printing
In the succeeding section we will discuss the various techniques available with respect to
printing which allows us to effectively deliver the various printing capabilities
Printing the Current Report using default “Print Button”
Using Action “Print”, “Print Report” and “Print Collection”
Print Configuration using “Print” Attribute of the Report
Suppressing Configuration for the above Actions
Printing Single/Multiple Forms using “Print” Attribute of the Form
Multi Account Printing using “Collection” attribute of Report
Let us start understanding each technique in depth and the required attributes.
[Form: MyTrialBalance]
Top Part : Title Part
Part : Main body
Bottom Part: Total Part
Button : Print Button
The report ‘My Trial Balance’ is printed by pressing the Print button available on the Top
button bar. The print button triggers the Action Print Report which prints the report Trial
Balance in the same format in which is displayed. The default configuration screen is automat-
ically launched whenever this action Print Report is invoked.The Print Button is defined in
Default TDL as given below:
[Key: PrintButton]
Key : Alt+P
Title : $$LocaleString:"Print"
Type : PrintButton
Action : Print Report
573
Advanced Reporting and Printing
Syntax:
Print : <Report Name> [ :<Logical Value>]
Where,
<Report Name> is the name of report to be printed.
<Logical Value> can be TRUE, FALSE, and YES or NO. This value can be used to skip the
display of configuration setting if value of the required parameter is set.
Example:
[#Menu: Printing Menu]
Add : Key Item: My Day Book: D : Print: Day Book
In the above example, a menu item ‘My Day Book’ is added. On selection it prints the report
‘Daybook’. On accepting the print configuration screen, the report is printed.
Syntax
[Button: <Button Name>]
Action : Print Report [: <Report Name>]
574
Advanced Reporting and Printing
Where,
<Report Name> is a report name to be printed by using the action Print Report. This is an
optional parameter. In the absence of Report Name by default the current report is printed.
Example:
[Button: Print Selected Pay slips]
Key : Alt + F11
Title : "Print Selected Pay slips"
Action: Print Report : Multi Pay Slip Print
Example:
;; Menu definition specifying the Action “PrintCollection”
575
Advanced Reporting and Printing
Syntax
[Report : <Report Name>]
Print : <Report Name>
Where,
<Report Name> is a name of the configuration report to be displayed.
Example:
[Report: My Trial Balance]
Form : My Trial Balance Form
Print : TB Print Configure
When the user clicks on the Print button or presses ALT+P to print the report ‘My Trial
Balance’, the configuration report ‘TB Print Configure’ is displayed. The user must accept the
configuration screen to print the report. The report ‘TB Print Configure’ is a predefined report
in Tally for printing ‘Trial Balance’ report.
576
Advanced Reporting and Printing
There are situations when multiple reports are being printed in a sequence. Subsequent to each
Print action, if a configuration report is popped up for user input, this interrupts the flow,
thereby requiring a dedicated person to monitor the process which is time consuming too. The
configuration report can be suppressed by specifying a logical parameter. Since the configura-
tion report is suppressed, the value of the various variables used by Print action must be set to
required values.
Following section explains the print action specific variables and their acceptable values.
This screen captures the user input such as the “Printer Name”, “No. of Copies” to be printed
etc. The various action specific variables required by the Print action are modified based on
the user input. Following variables are used by Print action:
SVOutputType
The value of this variable is one of the predefined button type keywords like ‘Print Button’,
‘Export Button’, ‘Upload Button’, ‘Mail Button’. The variables value is used by the functions
$$InMailAction, $$InPrintAction, $$InUploadAction and $$InExportAction to determine the
execution of correct option in the form ‘SVPrintConfiguration’.
For eg, if the value of ‘SVOutputType’ is ‘Print Button’ then the optional form ‘SV Print-
Config’ in the report ‘SVPrintConfiguration’ is executed.
SVPrintMode
This variable is used by Print action and accepts printing mode as value. The Print mode can
be “Neat”, “DMP” or “Draft” which are system names. The default mode is Neat mode.
SVPrintFileName
This variable is applicable for Print action, only if “PrintToFile” option is selected by the user
while printing in DOT Matrix or Quick / Draft format. In this case the variable ‘SVPrint-
577
Advanced Reporting and Printing
FileName’ accepts the filename by using the function $$MakeExportName function to add
right extensions.
SVPrintToFile
This is a logical value which determines if the print output should be saved in a file and is
applicable only for DMP or Draft mode. If the value is TRUE the output is saved in the file
specified in the variable ‘SVPrintFileName’. If the vale is FALSE then the variable
‘SVPrinterName’ must contain a valid printer name.
SVPreview
This is a logical variable and is applicable only for Print action with neat mode format. If the
value is set to Yes then preview of the report is displayed. Otherwise the report is printed
without displaying the preview.
SVPrintCopies
The variable is applicable only for Print action. It accepts a number to print multiple copies.
SVPrePrinted
The variable is applicable only for Print action and it specifies whether a pre-printed stationary
or plain paper is to be used for printing.
578
Advanced Reporting and Printing
SVPrintRange
The variable is applicable only for Print action. This variable determines the range of pages to
be printed.
SVPrintStartPageNo
The variable is applicable only for Print action. This variable allows to specify the starting
page number.
SVPosMode
It determines if POS mode to be used. The default value of this variable is No.
Example:
[#Menu: Gateway of Tally]
Add : Key Item : Before : @@locQuit : Print Balance Sheet : N : +
CALL : Suppress Balance Sheet Config
579
Advanced Reporting and Printing
When the user selects the menu item “Print Balance Sheet”, the function “Suppress Balance
Sheet Config” is called to print the report “Balance Sheet” without displaying the print config-
uration report.
The values for the required variables are set in the function. In case the values are not set
explicitly then by default the values of these variables are set based on the previous print con-
figuration setting.
Syntax
Print : <Report Name>
Where,
<Report Name> is the name of the report to be printed along with the current report.
Example:
Consider the scenario where a customer purchases goods and wants a label printed for each of
the items purchased.
The attribute Print is used in the form ‘Sales Color’ to print the additional report ‘EI Label-
Printing’ along with the default report ‘Sales Color’.
580
Advanced Reporting and Printing
The above figure shows the Items entered in the Invoice. When the user selects Escape key
then the print configuration report is displayed as follows:
581
Advanced Reporting and Printing
On pressing ‘Yes’ in the figure given below, the label report is displayed as shown:
The above figure shows the labels printed based on the quantity of stock item.
582
Advanced Reporting and Printing
Where,
<Report Name> is the name of the report to be used form multi-account printing
<Collection Name> is the name of collection on which the report will repeat. The optional
<Variable Name> can be passed here which will inherit object name in the variable and
further the variable can be used in the report.
<Condition> can be any expression which when evaluated to True then only the report is
repeated over the specified collection.
Example:
Consider the following example to print all the vouchers of a Ledger. The logical variable
##InNewPages specifies whether to print the report for a particular ledger in a new page.
The report “TSPL Multi Ledger Printing” is repeated on the collection “TSPL ML Ledger
Coll” if the value of the variable “InNewPages” is True. The variable “Ledger Name” is the
variable which holds the Name of the current object of collection “TSPL ML Ledger Coll”.
583
Advanced Reporting and Printing
Syntax
[Form: <Form Name>]
Page Break : <Closing Part>, <Opening Part>
Where,
<Closing Part> and <Opening Part> are the names of part to be used at the end and
beginning of a page
Example:
Consider a Trial Balance report of a company, where we may require the title and the address
of the company in the first page and the grand total in the last page. In pages between first and
last page, we may require the text continued at the end of each page and Company Name &
Address at the beginning of each page.
584
Advanced Reporting and Printing
In the above example, Closing Page Break is defined to print Continued at end of every
continued page. Opening Page Break is defined to print Company Name and Report Title at
beginning of all continuing pages. Since more than one part is used within part definition, the
alignment if Vertical needs to be specified.
Syntax
[Part: <Part Name>]
Page Break : <Closing Line>, <Opening Line>
Where,
<Closing Line> and <Opening Line> are the names of Lines to be used at the end and
beginning of a page.
585
Advanced Reporting and Printing
Example:
Consider a Trial Balance report of a company, where we may require the running page totals to
be printed at the end and beginning of each page.
[Part: My Trial Balance]
Page Break : Cl Page Break, Op Page Break
In the above example, Line “Cl Page Break” is defined to use the pre-defined “Detail Line”
and the relevant fields are modified locally to set the respective values. Similarly, line “Op
Page Break” is defined to use the above defined line “Cl Page Break” which locally modifies
only the particulars field.
586
Advanced Reporting and Printing
It takes two field names as parameters, viz., first field for Closing Page Break and second field
for Opening Page Break.
The following figure depicts the location of the closing and opening page breaks.
Syntax
[Line: <Line Name>]
Page Break : <Closing Field>, <Opening Field>
Where,
<Closing Field> and <Opening Field> are the names of fields to be used at the end and
beginning of a page.
Example:
Consider a Columnar Sales Register report of a company, where multiple columns are being
printed running across the pages where we require some fixed columns in subsequent pages
which make it easy to map the columns in subsequent pages.
[#Line: DSP ColVchDetail]
Page Break : Cl Page Break, Op Page Break
587
Advanced Reporting and Printing
The following table summarizes the properties of the Page break at each level:
Form Level Page Break Part Level Page Break Line Level Page Break
It’s a Vertical Page Break It’s a Vertical Page Break It’s a Horizontal Page
Break
Page Break attribute Page Break attribute Page Break attribute
accepts Part Names as its accepts Line Names as its accepts Field Names as
value value its value
Capabilities Used
The procedural capability of TDL is used to calculate the Nth Power of a Number.
The field attribute Print is used in form “Sales Color” to print the Invoice user
defined format instead of default format.
The attribute Page Break is used at form level to print the closing and opening page
break.
588
Advanced Reporting and Printing
Code
[Report: Exer Sales Invoice Cust]
Use : Daybook
Local : Line: DB Title : Local : Field : Name Field : Set As :"List +
of Sales Invoices- Select a Sales Invoice required to be+
printed"
Local : Collection : Default: Add : Filter: Exer Sales Invoices
Title : "Sales Invoice Customization and Printing"
[System: Formula]
Exer Sales Invoices: $$IsSales:$VoucherTypeName
;; Sales Invoice Customization
589
Advanced Reporting and Printing
590
Advanced Reporting and Printing
591
Advanced Reporting and Printing
592
Advanced Reporting and Printing
593
Advanced Reporting and Printing
Output
594
Advanced Reporting and Printing
Program Explanation
The form Sales Color is modified to Print the invoice in user defined format instead of the
default Tally.ERP9 format.
The attribute Print is used at form level to print the report Exer Sales Inv Cust which is
nothing but the user defined invoice format. In the report Exer Sales Inv Cust Object
Voucher is associated. The attribute PrintSet is used in report definition to set the value to the
variable Report Title to Customized Sales Invoice in print mode only.
In the part Exer Sales Inv InvDetails the line Exer Sales Inv SubTotal is repeated over the
sub object Inventory Entries.
The attribute Page Break is used to print Closing and Opening Parts used as Form Page
Breaks. The part EXPINV PageBreak is used as closing page break whereas part Exer Sales
Inv OpPgBrk is used as closing. Opening Page Break gets printed on all the Pages except the
First Page and Closing Page Break gets printed on all the Pages except the Last Page.
595
Advanced Reporting and Printing
When the user selects Print, the Print screen is displayed as shown in Fig. 12:10. Once the user
select Yes, the Invoice is printed in the user defined format as shown in Fig. 12:11.
Assume that only four columns can be printed on one page so Tally.ERP9 will print the above
reports as follows:
596
Advanced Reporting and Printing
597
Advanced Reporting and Printing
Each page is printed in three Parts and are named as Page 1(A), Page 1 (B), Page 1 (C) and
Page 2(A), Page 2 (B), Page 2 (C) respectively.
The predefined system variables “SVStartPageNo” and “SVPrintRange” are used for multi-
page/part printing. In the variable “SVPrintRange”, if the page numbers are specified as range
then the selected pages are printed and if the part numbers are specified as range then the
selected parts are printed. The validation and the implementation of printing the specified
pages/parts is handled by the platform itself.
Additionaly the function $$PageNo and $$PartNo are used in the reports to display the page
number and part number respectively.
598
Advanced Reporting and Printing
So if the part range is specified as 2A – 3C then the parts that are printed are Page 2 (A), Page
3 (A), Page 1 (B), Page 2 (B) and Page 3 (C).
Example:
Consider the following example where the report ‘Trial Balance’ is printed based on the page
range specified by the user.
599
Advanced Reporting and Printing
600
Advanced Reporting and Printing
Syntax
Pre Printed : Yes
12.2.6 Printing related Events – Before Print/After Print
We have already covered in previous chapters that an action can be triggered based on an
implicit event. There may be scenarios where some actions need to be invoked when a report
is being printed.
The attribute On along with event keywords events ‘After Print’ and ‘Before Print’ can be
used to handle printing related events. ‘On’ attribute can be specified for the definitions
Report, Form, Part, Line and Field. The event Before Print can be specified only at Report
level whereas the event After Print can be specified at Report, Form, Part and Line level.
Example:
[Report : Test Report]
On : BEFORE PRINT : Yes :CALL: BeforeRepPrint
The function ‘BeforeRepPrint’ is executed first and then the report ‘Test Report’ is printed.
Example:
[Line : LV AccTitle]
On : After Print: Yes : CALL : SetIndexLV:#LedgerName
The function ‘SetIndexLV’ is called after printing the line ‘LV AccTitle’. So if there are 10
lines to be printed, the function will be called ten times.
601
Advanced Reporting and Printing
Printing Image
The image printing capability can be used in various business scenarios like Logo Printing in
Sales Invoices, Stock Items Printing with their Images and many more. The attribute Graph
Type of Part definition is used to print the image.
Syntax
[Part: <Part Name>]
Graph Type: <path\File name>
Where,
<Part Name> is the name of the part which contains the image. This part cannot be used to
display or print any other content. Any content is specified at Line/ field level is ignored but an
empty field is mandatory. Appropriate dimensions i.e. Part Height and Width must be
specified to print the image within this Part.
<Path\FileName> is the location and name of the image file to be printed. At present the
image format supported are JPEG and BMP only.
Example:
[Part: Image Part]
Lines : Dummy Line
Graph Type: “C:\Images\ImageFile.BMP”
602
Advanced Reporting and Printing
Printing Graph
There are scenarios where the user requires a graph to be printed along with the report. The
Tally.ERP9 application allows to print Bar graphs only. The attributes Graph Type of part def-
inition is used to enable the graph printing in Tally. The part should contain at least two fields
to get 'X' and 'Y' axis. In one field the attribute Graph Label is used and in the second field the
attribute Graph Value is used.
There can be just one field with Graph Label attribute, which displays the values on the X-
axis. But there can be number of fields with Graph Value which will display the Y-axis. Tally
automatically uses multiple colors to differentiate the various bars belonging to a set of values.
603
Advanced Reporting and Printing
Example:
Consider the following code snippet to display the graph of all Sundry Debtor ledgers and
show their corresponding Sales and Receipts for the period.
[Part : led Graph]
Line : LedGraph
Repeat : LedGraph : SD Ledgers
GraphType : Yes
Height : 100% Screen
Width : 100% Screen
Scroll : Vertical
The part “Led Graph” is enabled for displaying a graph by setting the value of the attribute
Graph Type as Yes.
[Line : LedGraph]
Fields: Led NameFld, LEd DrTurnOver, LEd CrTurnOver
The value of the field “Led NameFld” is used for labelling the X- Axis.
604
Advanced Reporting and Printing
Set as : $CreditTotals
GraphValue: Yes
The value of the fields “Led DrTurnOver” and “Led CrTurnOver” is used for generating the
Bars and labelling the Y- Axis.
[Collection : SD Ledgers]
Type : LEdger
Childof : $$GroupSundryDebtors
BelongsTo : Yes
The above figure shows the Sales and Receipts of the ledgers under group Sundry Debtors.
12.2.8 Additional Attributes and Functions
Earlier in the chapter, we have discussed the mandatory attributes required for usage in
printing for various techniques. In this section we will discuss a few more attributes and
functions which are used on a case to case basis as per requirement.
605
Advanced Reporting and Printing
Generic Attributes
Report Attribute-Print Set
The attribute Print Set is used at Report definition. It is used to set the value to the variable for
the report, only in print action/mode. This is a dual list attribute.
Syntax
Print Set : <Variable Name> : <Value>
Where,
<Variable Name> is the name of the variable
<Value> is the value to be set to the variable
Example:
[!Form: POS Invoice Color]
Background : @@SV_POS
Print : POS Invoice Print
Print After Save: “Yes”
Line Attribute – Next Page
The definition Line supports Next Page attribute to specify the condition for the current line to
be printed on the subsequent page. It accepts a logical formula as its parameter.
Syntax
[Line: <Line Name>]
Next Page : <Logical Formula>
Where,
<Logical Formula> can be any expression which returns the logical value.
606
Advanced Reporting and Printing
Example:
[Line: DSP Vch Explosion]
NextPage : NOT $$DoExplosionsFit
In the above example if the exploded part does not fit the current page then the entire line is
moved to the next page.
Example:
[!Form: Columnar Ledger]
DMPMode : Condensed
Syntax
PrintBG: <Color Name>
Where,
<Color Name> is the name of the color defined either in Default TDL or User TDL.
Example:
[Part: Party Details]
Background: Red
Print BG : Green
607
Advanced Reporting and Printing
In the above code the, the part “Party Details” has Red color as background in display mode
whereas Green in Print mode.
Example:
[Field: Party Ledger Name]
Print BG : Red
Color : Green
Print FG : White
$$InPrintMode
The function ‘InPrintMode’ checks whether the report is in the print mode or not. It returns
True if the report is in the print mode else it returns False.
Syntax
$$InPrintMode
Example:
[Line: Employee SalaryBorder]
Field : Simple Field
Invisible: NOT $$InPrintMode
Border : Thin Bottom: $$InPrintMode
608
Advanced Reporting and Printing
The line Employee Salary border is displayed in print mode with a thin border at the bottom.
$$InDMPMode
The function ‘InDMPMode’ checks if the format for printing the report is Dot Matrix mode. It
returns True if the print format selected for printing is Dot Matrix mode else it returns False.
Syntax
$$InDMPMode
Example:
[Field: BSAmt]
Option : Small Size Field : $$InDMPMode
The optional field ’Small Size Field’ is implemented only in the Dot Matrix mode.
$$InDraftMode
The function ‘InDraftMode’ checks if the format for printing the report is Quick/Draft mode.
It returns True if the print format selected for printing is Quick/draft mode else it returns False.
Syntax
$$InDraftMode
Example:
[Field: PJR To]
Set as : If $$IsDr:$Amount then "" else $$LocaleString:"To"
Width : If $$InDraftMode then 3 else 2
$$InPixelMode
The function ‘InPixelMode’ checks if the selected print format is Neat mode. The function
returns True if the report Neat mode is selected else it returns False.
Syntax
$$InPixelMode
Example:
[System: Formula]
NumberWidth : If NOT $$InPixelMode then 7 else 8
$$IsMultiPagePrintJob
The function ‘IsMultiPagePrintJob’ checks if the printing spans across multiple pages. It
returns TRUE if more than one page is being printed else returns FALSE.
609
Advanced Reporting and Printing
Syntax
$$IsMultiPagePrintJob
Example:
[Field: DSP PageNo]
Inactive : NOT ##PrintWithPageNo AND NOT $$IsMultiPartPrintJob
$$IsLastOfSet
This function is used to check if the current form is the last form being printed. It returns True
if the current form is the last form being printed else returns False.
Syntax
$$IsLastOfSet
Example:
[Line: DSP Vch Explosion]
Next Page : (($$LineNumber = $$LastLineNumber) AND +
$$IsLastOfSet)
$$DoExplosionsfit
In case of printing, if a line is exploded, then this function can be used to check whether the
exploded part fits within the current page. If the number of lines to be printed does not fit in
the available space for printing then the page break occurs. This function doesn’t require any
parameter and returns logical value. It returns logical value Yes if it is true.
Syntax
$$DoExplosionsFit
Example:
[Line: EXPSMP InvDetails]
NextPage : NOT $$DoExplosionsFit OR (($$LineNumber = +
$$LastLineNumber)
$$BalanceLines
This function is used to check balance number of lines in the repeated lines, including the
exploded part-lines present, in a given part. Scroll : Vertical must be specified at the Part defi-
nition in order to use this function. This function too does not require any parameter and
returns Numerical value.
Syntax
$$BalanceLines
Example:
[Line: LR Detail]
610
Advanced Reporting and Printing
$$IsFirstChildInNextPage
The function is used to check whether the child object is printed on the next page and its parent
object on the current page. This function can be used in the attribute ‘Next Page’ of Line defi-
nition to print the parent in the same page as of its first child.
Syntax
$$IsFirstChildInNextPage
Example:
[Line : MyTBDetails]
NextPage: $$IsFirstChildInNextPage
611
Project Work
Project Work: Inventory Management –
Garment Store
A Garment Store Glitz Apparels, who are using Tally.ERP9 require some modifications to suit
their business specific needs.The requirement is more focussed towards Inventory Manage-
ment. Details like Brand, Colour, Size, etc. need to be captured along with their Stock Items
and the same needs to be used during Voucher Entry, Label Printing and Invoice Printing.
While Purchasing the Items, labels for the Stock Items are being printed as many as number of
Items purchased. While selling the Items, the corresponding Brand, Product Type, Colour and
Size Information are being displayed.Sales Invoice For Cash and Credit Sales are required to be
customized as per their specific formats. Stock Summary Reports must be modified to contain
Columns for Brand, Colour, Size, etc. and Matrix Report on Itemwise Brandwise Sizes are
needed to have an analysis.
1. F11 Features
615
Project Work
616
Project Work
617
Project Work
618
Project Work
619
Project Work
620
Project Work
2. On enabling the above, a Sub Form must pop up requesting for relevant Brand, Prod-
uct and other details wherein the table from relevant master list must be displayed in
the respective fields and the entered values must be stored in UDF.
3. The Field Stock Item Name must be automatically set with the concatenated values
from Brand, Type, Colour & Size and the user should not be allowed to alter this
Field.
4. First Alias Field must be set with the auto generated code if the same is enabled in
F11 Features else user needs to enter values.
Code generation logic:
a. Gather a Collection of Items by grouping over the number portion of code and
sorting the objects in descending order.
b. Extract the Code from the first Object within the Collection, add one to it and con-
catenate the number with the Prefix, Suffix and the selected master codes.
5. Allow the user to enable Price List within the current Stock Item and on enabling, a
Sub Form must popup like the one displayed above
Hint:Grouping over Objects can be done using User Defined Functions and Action For Token
within.
3. Voucher Type Master Alteration
3.1 Purchase Voucher Type Creation
621
Project Work
622
Project Work
4. Voucher Entry
4.1 Garment Purchase Voucher
On saving the above Purchase Voucher, the following Label should be printed, 2 labels in a
row and as much labels as specified for each item within the current voucher, i.e., for 50 Pcs of
an Item, it should print 25 Rows and 2 Columns labels for this Item
623
Project Work
All the above should work only if the value for Use for Garment Purchase is
enabled in the Voucher Type Master
624
Project Work
All the above should work only if the value for Use for Garment Sales is
enabled in the Voucher Type Master
625
Project Work
5. Invoice
626
Project Work
627
Project Work
628
Project Work
7. Columnar Reports
7.1 Brandwise Itemwise Sizewise Sales (New Report)
629
Project Work
8. Color Scheme
630
Use Cases
Use Cases
633
Use Cases
Following is the screen capture of the Configuration with default Excel Format:
Since, Excel is widely used for representing columnar info, Excel format is selected by
default. But the user has the liberty to select any source Text or Excel and specify the appropri-
ate file info. If the user happens to select the Text Format, an additional parameter i.e., the
separator character which separates the columns, has to be specified apart from the other
details.
634
Use Cases
Following is the screen capture of the Configuration with Text Format selected:
Once the details are entered, a confirmation message is prompted to begin or cancel the import
process. If the user has enabled the option to display the error report, after the import process,
a report is shown with the stock items imported and the status i.e., imported successfully,
Item 1 already exists, Group Computer Peripherals does not exist, etc.
635
Use Cases
On viewing the List of Stock Items, the Items which display status in the above report as
Imported Successfully will also be available.
636
Use Cases
Following is the screen capture of the Stock Items post Import process:
637
Use Cases
[System: Variable]
UsCs SIC Source : "Excel"
UsCs SIC DirPath : "C:\Tally.ERP9"
2. On saving the configuration report i.e., on accepting the form, the function to import
the stock item is called.
638
Use Cases
c. If the source is Text, the text file is read line by line and added as an element to the
list variable.
639
Use Cases
5. Now the Stock Item objects are created. If the item cannot be imported then the item
details are written in the error file or compound variable based on the option selected
for displaying i.e., Report or Log.
640
Use Cases
610 : IF : ##UsCsSICDisplayReport
620 : LIST ADD EX : ItemImportStatus
630 : SET : ItemImportStatus[##Counter].ItemName:+
$SICStockItem
640 : SET : ItemImportStatus[##Counter].Status: ##LastStatus
650 : INCREMENT : Counter
660 : ENDIF
670 : END WALK
6. If the format selected is Report, then the stock item name and the status are updated
in a compound variable. If the format selected is Log file, then the Action WRITE
FILE LINE is used to write to a text file.
690 : IF : ##UsCsSICDisplayReport
700 : DISPLAY : UsCs SIC Error Report
710 : ENDIF
7. Post import process, if the user had chosen to display the log file then the log file
opens up.
720 : IF : ##UsCsSICOpenLogFile
730 : EXEC COMMAND: @@UsCsErrorFilePath
740 : ENDIF
8. In the error report, line is being repeated over the collection populated using the list
variable as the data source.
641
Use Cases
642
Use Cases
On accepting the configuration screen, the configuration gets applied to the report. By
clicking on Save Config Button, one can specify the Configuration Name and accept the same
as shown below:
Once the user accepts this screen, the configuration details will be saved in the file Stock
Summary_Base.pvf as the current report is Stock Summary. Hence, a Report specific con-
figuration can be maintained and retrieved. Similarly, we save another configuration with
name Stock Summary_Detailed.PVF
643
Use Cases
644
Use Cases
645
Use Cases
Again, to view the same report with another configuration, click on Load Config which
displays the list of configurations.
646
Use Cases
On selecting the required configuration, the base report will be configured with a selection as
shown below:
647
Use Cases
648
Use Cases
649
Use Cases
The collection is filtered to contain the report specific PVF files as follows:
[System: Formula]
UsCs OnlyPVFFiles: $Name CONTAINS "PVF" and ($Name CONTAINS +
$$ContextKeyword:Yes OR $Name CONTAINS +
$$ContextKeyword)
When the report is accepted, the action LOAD VARIABLE is then launched with the saved
variable values from the selected file loaded and the respective configuration settings are
applied to the current report.
3. Use Case III – Multiple Email Configurations
3.1 Scenario
ABC Company Ltd., a manufacturing company is having Head Office in Bangalore and
branch offices at Delhi, Mumbai, Kolkata and Chennai. The company is using Tally.ERP 9 in
all their locations.
The Head Office and Branch Offices are using the e-mail capability of Tally extensively to
send the reminder letters/outstanding statements to the customers.
The System Administrator at the Head office will be facilitating the Branch office staff for
email configurations in Tally. The company is using its own mail server and also using
another mail server “SIFY”. If there is a change in the mail server, the system admin needs to
communicate this information to the branch staff and they will be updating the email configu-
rations accordingly in Tally.ERP 9.
Now the company wants to set the email configurations centrally for all the branches so that
branch staff need not struggle for email configurations particularly when there is change in
mail server. This solution provides the facility of saving multiple configurations in different
files and later loading it from the file based on user selection.
3.2 Functional Demo
At present in Tally.ERP 9, the users need to set the email configurations locally and update
required details.
Configurations can be created centrally and shared among the locations. So that the users
need not set the email configuration every time. They have to simply load the configuration
from the file. This can be achieved using the actions SAVE VARIABLE & LOAD
VARIABLE.
Before looking into the design logic, we will have a functional demo.
Let us suppose ABC Company Ltd is using its own mail server and another mail server Sify in
Head Office and its branch offices.
650
Use Cases
The System Admin needs to save the Configurations for the mail servers Rediff Mail and Sify.
Hence, he has to specify the Email server as “User Defined” and enter the required configura-
tion settings as shown in the below screen capture.
651
Use Cases
Now the System Admin has to press Alt+S or click on the Button Save Config. The below
screen will appear and he has to enter the configuration file name.
Once the System Admin accepts this screen, the configuration details will be saved in the file
rediff.pvf. Similarly he has to create the Configuration for the mail server Sify.
The files will be created in the Tally.ERP 9 application folder as shown in the below screen
shot.
The admin can share these two files to the staff in HO and Branch Offices and they should
place the file in the respective Tally.ERP 9Application folders.
Loading Configurations
Gateway of Tally > F12 (Configure) > E-Mailing > the Email configuration screen will be
displayed with the previously set configurations.
652
Use Cases
Now the user at the HO/Branch wants to load the configurations for the email server Rediff.
He has to press Alt+L or click on the Button Load Config and enter the file name as shown in
the below screen shot
Accept the screen then the Email Configuration Report will display the configuration details
loaded from the file Rediff. Accept the email configuration screen and the settings will be
applicable to all the reports.
If the user wants to mail the report Balance Sheet, he will select the Balance Sheet report and
press Alt + M, the below configuration report will appear
We can observe here that the configuration details are prefilled as per our requirement. Simi-
larly, we can save/load multiple configurations.
653
Use Cases
Loading Configurations
A button is added to the Form. On clicking the same; a User Defined Function is invoked
which, in turn executes a report that accepts the File name from the user. The report scope
variables are being loaded from the file with the help of action LOAD VARIABLE.
Please refer to the below code snippet for Save and Load configurations.
[Function: UsCs SaveLoadVar]
Parameter: IsSaveVar : Logical: Yes
Variable : ConfigNamewithExt: String: Yes
654
Use Cases
60 : IF: ##IsSaveVar
70 : SAVE VARIABLE: ##ConfigNamewithExt
80 : ELSE:
90 : LOAD VARIABLE: ##ConfigNamewithExt
100 : ENDIF
110 : ENDIF
The corresponding field values need to reflect the values of the variables loaded from the file.
This is handled using the following code:
Local: Field: DSPMailServer: Set as: If #DSPMailServerName +
Contains $$SysName:UserDefined Then ##SVMailServer Else +
If #DSPMailServerName NOT Contains $$SysName:UserDefined +
Then $$GetMailServerAddr:#DSPMailServerName Else+
##SVMailServer
Local: Field: DSPMailServerName: Set As: ##SVMailServerName
Local: Field: DSPMailFormat: Set As: ##SVMailFormat
Local: Field: DSPMailUseSsl: Set As: ##SVMailUseSsl
Local: Field: DSPMailUseSSLOnStdPort : Set As : +
##SVMailUseSSLOnStdPort
Local: Field: DSPMailAuthUserName: Set As: ##SVMailAuthUserName
Local: Field: DSPFinalExportFormat: Set As: ##SVExportFormat
Also. if the field values are changed, the Report level variables need to be modified with those
values. This is handled using the following code:
Local: Field: DSP MailServerName: Modifies: SVMailServerName :
Yes
Local: Field : DSP MailServer: Modifies: SVMailServer : Yes
Local: Field : DSP MailFormat: Modifies: SVMailFormat : Yes
Local: Field : DSP MailUseSsl: Modifies: SVMailUseSsl : Yes
Local: Field : DSP MailUseSSLOnStdPort : Modifies: +
SVMailUseSSLOnStdPort: Yes
Local: Field : DSP MailAuthUserName : Modifies: +
SVMailAuthUserName: Yes
Local: Field : DSP FinalExportFormat: Modifies: +
655
Use Cases
SVExportFormat: Yes
On accepting the Form EMail Configuration, a User Defined Function is called to set the
System Variable values with the Report values such that, the altered configuration gets
effected in all the reports.
Please refer the below Code Snippet:
[Function: UsCs Update System Variables]
10 : SET : ().SVMailServerName: ##SVMailServerName
20 : SET : ().SVMailServer: ##SVMailServer
30 : SET : ().SVMailFormat: ##SVMailFormat
40 : SET : ().SVMailUseSsl: ##SVMailUseSsl
50 : SET : ().SVMailUseSSLOnStdPort: ##SVMailUseSSLOnStdPort
60 : SET : ().SVMailAuthUserName: ##SVMailAuthUserName
70 : SET : ().SVExportFormat: ##SVExportFormat
656
Use Cases
Figure 18 Daybook
657
Use Cases
A function is called from menu which duplicates all the Payment and Receipt vouchers of
Company and then shows the list of vouchers Duplicated during the current process.
658
Use Cases
4. The collection Ledger Entries of the current voucher is walked and a new ledger
entry object is inserted in the target object context. The values of the target Ledger
Entry object are set from the current Ledger Entry source object. After setting all the
Methods within the Sub Object ledger entries, the voucher object is once again set as
the target object with a Set Target : ...
659
Use Cases
5. The Duplicated vouchers are then saved to the data and a report displays all the dupli-
cated vouchers.
660
Use Cases
3. After clicking the option Inter Company Data Transfer, the second company open is
considered as Target Company.
4. The following confirmation screen appears:
5. All the payment vouchers from the company ABC Company Ltd. are transferred as
Receipt to the company Global Enterprises.
661
Use Cases
6. The Daybook for the Global Enterprises after data transfer is as shown.
a. A new menu item is added to call a function in order to transfer all payment entries
from ABC Company Ltd. to Global Enterprises.
2. Function description
a. We would require switching from ABC Company Ltd. to Global Enterprises
and after transfer of vouchers we need to switch back to ABC Company Ltd.
b. By default, the current company is considered as Source Company and the second
company from the list of opened companies is considered as target company.
00 : IF: $$SelectedCmps > 1
10 : SET : SrcCompany: ##SVCurrentCompany
;; First Non Source Company from the list of open companies is set as Target Company here
20 : SET : TgtCompany:$$FilterValue:$Name:+
662
Use Cases
ListOfCompanies:First:UsCsNotIsSrcCompany
c. A confirmation box is displayed for the data transfer
60 : QUERY BOX: "From the Company, " + ##SrcCompany +
",all the Payment Entries will be created \n”+
“as Receipt and Receipt Entries as Payment in+
the Company, "+ ##TgtCompany + "\n\n Are you +
sure?" : Yes:No
d. On the response as Yes from the user, the data from Source Company i.e. current
company is transferred to the target company. The collection of vouchers is
walked and the variable SVCurrentCompany is switched to target company.
70 : IF : $$LastResult
80 : WALK COLLECTION : UsCs PymtRcpt Vouchers
90 : SET : SVCurrentCompany : ##TgtCompany
;; Setting the current Source as Target
100 : SET TARGET
e. The voucher Type is changed to Receipt if it is Payment Voucher
f. Appropriate values are set for the methods of Ledger Entries collection
130 : WALK COLLECTION : LedgerEntries
140 : SET TARGET : LedgerEntries[$$LoopIndex]
150 : SET VALUE : Amount : if $$IsDr:$Amount then+
$$AsCrAmt:$Amount else $$AsDrAmt:$Amount
160 : SET VALUE: IsDeemedPositive: NOT $IsDeemedPositive
170 : SET TARGET: ..
180 : END WALK
190 : SET VALUE : Narration: ##VarNarration
;; Saving the Target Company Voucher
200 : SAVE TARGET
663
Use Cases
g. Altering the Source Company Voucher with Updated or Transferred Voucher Flag
220 : SET TARGET
230 : SET VALUE : UsCs UpdatedVch: Yes
240 : SAVE TARGET;; Saving the Source Company Voucher
250 : END WALK
260 : ENDIF
h. Now the target company is set as current company and its Day book is displayed
to show the Vouchers Transferred to the Target Company during the current ses-
sion.
270: SET : SVCurrentCompany: ##TgtCompany
;; Displaying the Vouchers Transferred to the Target Company during the current session
280: DISPLAY: UsCs ICDT Daybook
290: SET : SVCurrentCompany: ##SrcCompany
i. In case two companies are not loaded in Tally.ERP9 then an error message is dis-
played.
j. Since only payment and receipt vouchers of ABC Company Ltd. are required the
collection of vouchers is created as shown :
664
Use Cases
665
Use Cases
666
Use Cases
2. From the line, a part is exploded to display the Bill details for the Company displayed
in Line.
[Line: UsCs GrpCo CompanyName]
Left Field : UsCs GrpCo CompanyName
Space Top : 1% Screen
Space Bottom: 1% Screen
;; Exploding Bill Details always
Explode: UsCs GrpCo LEDBILL Details
3. The Bill details are displayed by repeating a line over the collection of Bill details
from all the selected companies
The collection UsCs GrpCo Ledger Bills is gathered once for each object in the collection
UsCs Group Company. The collection UsCs GrpCo Ledger Bills is defined as follows:
667
Use Cases
4. The Voucher details are displayed in the exploded part by repeating the line on col-
lection Ledger entries.
668
Use Cases
5. The collection to fetch the Bill's Total Amount at Voucher Level is defined as fol-
lows:
669
Use Cases
The calculated area is automatically set in the quantity field as shown below:
Subsequently, while moving from quantity field, it is checked if the quantity being sold is
available in stock. On availability, the cursor moves to the Rate else an error for Negative
Stock is displayed as shown below:
670
Use Cases
The cursor continues to be in quantity field. User has to enter the available quantity to move
ahead or Purchases if not entered, need to be entered first prior to this Sales entry.
On saving and printing the Invoice, default Invoice is overridden with the following format:
[#Line: EI ColumnOne]
Option : UsCs MRP ColumnOne : @@IsSales ;;Title Line1
671
Use Cases
The field is added in the beginning of right fields so that the column MRP is dis-
played prior to the Quantity field. The field is defined as follows
[Field: UsCs MRP]
Use : Rate Price Field
Width : 8
Align : Right
Border : Thin Left Right
Storage : UsCs MRP
Skip on : $$IsEnd:$StockItemName
2. The UDFs for storing the MRP values are defined as follows:
[System: UDF]
UsCs MRP : Rate : 5000
3. To capture the Length and Breadth details, a sub form is added.
From the default field VCHACC Stock Item, a sub form is displayed.
672
Use Cases
The UDFs to store the Length and Breadth of an item are defined with appropri-
ate data type.
[System: UDF]
UsCsStkLength : Number : 101
UsCsStkBreadth : Number : 102
The calculation of dimension is specified in the field as follows.
[Field: UsCs StkVCH Dimension]
Use : Number Field
Skip : Yes
Set always : Yes
Set as : $UsCsStkLength * $UsCsStkBreadth
Format : "NoZero, NoComma"
Align : Centre
Border : Thin Left Right
673
Use Cases
The calculated area is set in the Quantity field. A method is added to the objects
Inventory Entry and the same is set in the Quantity fields Actual Qty and Billed
QTY.
4. Further, a control is applied within the Quantity field so that the user can’t enter the
quantity, if it goes beyond availability.
674
Use Cases
Below are the code snippets shown for controlling Negative Stock along with the challenges
faced
Controlling the quantity by checking that the entered value is lesser than or equal
to the closing balance of the item as shown below:
[#Line: EI InvInfo]
Local : Field: VCHActualQty : Control : +
UsCs NegativeStock:$$Value > $ItemClBal +
AND @@IsOutwardType
Local: Field: VCHBilledQty:Control:UsCs NegativeStock +
:$$Value > $ItemClBal AND @@IsOutwardType
With the above method, we came across a loop hole. There was a possibility that
the user can select the same item in the current bill multiple times. In that case, vali-
dating only with the Item Closing Balance would not suffice. We also need to
include the quantities of the same Item entered above in the current bill. To do this,
the approach followed by us is to hold the entered Stock Items along with their
respective quantities in a list variable. The same is done using On Focus Event at
Line and User Defined Functions.as shown below:
[#Line: EI InvInfo]
On : Focus : Yes : CALL : UsCs Set List Variables : $$Line
675
Use Cases
The function is defined with the parameter and local variable as follows:
[Function: UsCs Set List Variables]
Parameter: pLine : Number
The items in the List variable are added using a key. The key is a combination of
item name.
The values are updated in the list variable “USCS ItemVar” based on the key
item name as follows:
100: SET : LineKey: #VCHStockItem
110: IF : NOT $$ListFind:UsCsItemVar:##LineKey
120: LIST ADD: UsCs ItemVar: ##LineKey
130: ENDIF
140: SET : LineIndex : $$ListIndex:UsCsItemVar:##LineKey
150: SET : UsCs ItemVar[##LineIndex].UsCs OrigItem: +
#VCHStockItem
160: SET : UsCs ItemVar[##LineIndex].UsCs OrigQty: if+
$$IsEmpty:##UsCsItemVar[##LineIndex].UsCsOrigQty+
then #VCHActualQty else if ##pLine = ##LineIndex+
then ##UsCsItemVar[##LineIndex].UsCsOrigQty else+
##UsCsItemVar[##LineIndex].UsCsOrigQty +
#VCHActualQty
170: ENDIF
Once the List Variables are updated with the values, the Quantity Field can be compared with
the current key combination entered quantity plus the closing balance for the current item.
Similarly, the same logic can be extended to the Batchwise supplementary form.
676
Use Cases
2. The existing invoice format is removed and the report “UsCs Global Invoice” is used
to specify the required invoice format
[!Form: UsCs Global Sales Color]
Delete: Print
Add : Print: UsCs Global Invoice
3. The report UsCs Global Invoice is designed as per the given format.
The default report Printed Invoice is used. The existing form is removed and a
new form is added in the report.
[Report: UsCs Global Invoice]
Use : Printed Invoice
Delete: Form
Add : Form: UsCs Global Invoice
In the form Page Break is specified at the form level as follows:
[Form: UsCs Global Invoice]
Use : STD Invoice Dimensions
|
Page Break: UsCs GI ClPgBrk, UsCs GI OpPgBrk
The company name is printed using @@CmpMailName.
The voucher information like Party name, Voucher number, shipping details etc
is printed using the methods like $PartyLedgerName, $VoucherNumber, $ Basic-
ShippingDate etc.
To print the billing address line is repeated over the Address collection
677
Use Cases
$$CollAmtTotal:InventoryEntries:$Amount
A line is repeated over a collection to display the company address and the col-
lection is defined as follows:
Repeat: UsCs GI Address: UsCs Company Address
678
References and Bibliography
http://www.tallysolutions.com/website/html/developernetwork/developernetwork-over-
view.php
http://www.tallysolutions.com/website/html/developernetwork/tallydefinitionlanguage.php
http://www.tallysolutions.com/website/html/developernetwork/whats-new.php
http://www.tallysolutions.com/website/html/downloads/tally-development-environment.php
http://www.tallysolutions.com/tallyweb/modules/operation/extranet/
CXTD9DownloadViewMgr.php
http://www.tallysolutions.com/website/html/developernetwork/integration-capabilities.php