Table of Contents

 

Key Value Map

In many business applications, it is often necessary to quickly retrieve a value based on a specific key without searching through an entire collection. A Map definition is used to create a key-value mapping, where each unique key is associated with a corresponding value. This allows developers to perform fast and efficient lookups, improving both the performance and readability of the code.

A Map stores data in the form of key-value pairs. When a key is provided, the corresponding value can be retrieved directly without iterating through the complete collection. This makes Map definitions especially useful when frequently accessed data needs to be searched or referenced during report generation, validations, calculations, or other processing tasks.

Syntax

[Key Value Map : <definition name>]

Key Type : <Sys Id/Error Id/String/Long>

Key Value : <Key value> : <TDL Expression>

Key : <Key value>

Default : <TDL Expression>

➥ Click here to download Key Value Map Sample

Since the lookup is based on a unique key, Map definitions provide an efficient way to organize and access data. They help reduce processing time, simplify the code, and improve maintainability, making them a preferred choice whenever quick access to mapped values is required.

Attributes

When working with a Map definition, there may be situations where the specified key does not exist in the map. In such cases, instead of returning no value or causing unexpected behavior, a Default attribute can be used to specify an alternate TDL expression. This expression is evaluated and its result is returned whenever a matching key is not found. Since the Default attribute is evaluated only when no matching key is available, it provides a safe and efficient way to handle missing mappings. It is especially useful when a default value, calculation, or expression should be returned instead of leaving the result empty or undefined.

Syntax

[Key Value Map : <>]

Default : <TDL Expression>

Example

[Key Value Map : TSPL IndiaStateCode]

Key Type : Sys Id

Default : ($$InitValue:String)

In this example, the Key represents a unique system-defined identifier for an Indian state or union territory. If the specified key is not available in the map, the Default attribute returns an empty string.

The Key attribute is used to specify one or more constant values that act as the keys in a Map definition. These keys are used to search the map and retrieve the corresponding mapped value. By defining unique keys, the Map can quickly locate the required value without searching through the entire collection, making lookups faster and the code more efficient and easier to maintain.

Syntax

[Key Value Map : <>]

Key : <Key value>

Example

[Key Value Map : GSTPLT PartyRegType]

Key Type : Sys Id

Key : Regular

Key : Composition

Key : GSTRegularSEZ

Key : DeemedExporter

Key : RegularExports

 

In this example, the Key attribute is used within the Key Value Map definition GSTPLT PartyRegType to define a set of constant keys such as Regular, Composition, GSTRegularSEZ, DeemedExporter, and RegularExports. These keys act as unique identifiers for the map entries. During execution, when one of these key values is provided in a lookup, the map uses it to quickly locate and retrieve the corresponding mapped value, enabling efficient and organized data retrieval.

The Key Type attribute is used to specify the data type of the key in a Map definition. Since a Map performs lookups based on keys, it is important that the keys are stored and searched using the correct data type. By defining the key type, developers can ensure that key values are interpreted correctly during lookup operations. This helps improve the accuracy of searches, avoids data type mismatches, and enables efficient retrieval of the mapped values.

Syntax

[Key Value Map : <definition name>]

Key Type : <Sys Id/Error Id/String/Long>

Example

[Key Value Map : TSPL IndiaStateCode]

Key Type : Sys Id

 

This example defines a Key Value Map named TSPL IndiaStateCode.

The Key Type is set to Sys Id, indicating that the keys are system-defined identifiers.

The Value attribute is used to specify the TDL expression associated with a key in a Map definition. Each key is mapped to a corresponding TDL expression, and when the key is found during a lookup, the mapped expression is evaluated and its result is returned. This attribute helps establish the relationship between keys and their corresponding values, enabling fast, accurate, and efficient data retrieval.

Syntax

[Key Value Map : <>]

Key Value : <Key value> : <TDL Expression>

Example

[Key Value Map : TSPL IndiaStateCode]

Key Type : Sys Id

Key Value  : AndamanNicobarIslands     : “35”

Key Value  : AndhraPradesh             : “37”

Key Value  : ArunachalPradesh          : “12”

Key Value  : Assam                     : “18”

 

This example defines a Key Value Map named TSPL IndiaStateCode. Each Key Value maps a state identifier, such as AndhraPradesh or Assam,
to its corresponding state code.

Is this information useful?
YesNo
TallyHelpwhatsAppbanner
Is this information useful?
YesNo
TARA