Chapter 9 Generation Reference Guide (GTL)
The foreach_item macro is used for iterating on object collections. The template specified inside the block is translated over all objects contained in the specified collection. The block defines a new scope wherein the active object at iteration i is the i-th collection member.
If a comparison is specified, items in the collection are pre-sorted according to the corresponding rule before being iterated upon:
.foreach_item '(' <collection-scope> [',' <head> [',' <tail> [',' <simple-condition> [',' <comparison> ]]]]')' <complex-template> .next ['(' <separator> ')']
All collections are accessible for a given object. Each PowerDesigner object can have one or several collections corresponding to the objects it interacts with. Collections express the link between objects, for example a table has collections of columns, indexes, business rules and so on.
Collections are represented in the PowerDesigner public metamodel by associations between objects. The roles of the associations correspond to the collections of an object.
For more information about object collections, see "Associations and collections" in the "PowerDesigner Public Metamodel" chapter.
Parameter | Type | Description |
---|---|---|
<collection-scope> | Simple template | Collection over which iteration is performed |
<head> (optional) | Text | Generated before output, if there is one |
<tail> (optional) | Text | Appended to the output, if there is one |
<simple-condition> (optional) | Simple condition | If specified, only objects satisfying the given condition are considered during the iteration |
<comparison> | Simple condition | <comparison> is evaluated in a scope where two local objects respectively named 'Item1' and 'Item2' are defined. These correspond to items in the collection. <comparison> should evaluate to true if Item1 is to be placed after Item2 in the iteration |
<separator> (optional) | Text | Generated between non empty evaluations of <complex-template> |
Macro parameters delimiters
Macro parameters may be delimited by double quotes. The delimiters are required whenever the parameter value includes commas, braces, leading or trailing blanks. The escape sequence for double quotes inside a parameter value is \"
.
The output is the concatenated evaluations of <complex-template> over all the objects in the collection.
Example:
Attribute | Data type | Initial value |
---|---|---|
cust_name | String | __ |
cust_foreign | Boolean | false |
.foreach_item(Attributes,,,,%Item1.Code% >= %Item2.Code%)) Attribute %Code%[ = %InitialValue%]; .next(\n)
The result is:
Attribute cust_foreign = false
Attribute cust_name;
The four commas after (Attributes,,,, means that all parameters (head, tail, condition and comparison) are skipped.
Copyright (C) 2005. Sybase Inc. All rights reserved. |