Calculated Collections (Profile)

Calculated collections define a read-only connection between an object instance and a group of other objects of the specified type. The collection displays as a sub-tab on the Dependencies tab of the object property sheet. The logic of the collection is defined using VBScript.

For example, in an OOM, you may need to create a list of sequence diagrams using an operation, and can create a calculated collection on the operation metaclass that retrieves this information. In a BPM, you could create a calculated collection on the process metaclass that lists the CDM entities created from data associated with the process.

You can loop on calculated collections with GTL (see Accessing Collections of Sub-Objects or Related Objects) You can use calculated collections to fine-tune impact analysis to better evaluate the impact of a change. For example, in a model where columns and domains can diverge, you can create a calculated collection on the domain metaclass that lists all the columns that use the domain and have the same data type.

Note: Calculated collections, unlike extended collections (see Extended Collections and Compositions (Profile)) cannot be modified by the user.
  1. Right-click a metaclass, stereotype, or criterion and select New > Calculated Collection.
  2. Enter the following properties as appropriate:

    Property

    Description

    Name

    Specifies the name of the calculated collection for use in scripts.

    Label

    Specifies the display name of the collection, which will appear as the name of the tab associated with the collection in the parent object property sheet.

    Comment

    [optional] Describes the calculated collection.

    Target Type

    Specifies the metaclass whose instances will appear in the collection. The list displays only metaclasses that can be directly instantiated in the current model or package, such as classes or tables, and not sub-objects such as class attributes or table columns.

    Click the Select a Metaclass tool to the right of this field to choose a metaclass from another type of model.

    Target Stereotype

    [optional] Specifies a stereotype to filter the target type. You can select an existing stereotype from the list or enter a new one.

    List Columns

    Specifies the columns displayed by default on the collection property sheet tab.
  3. Click the Calculated Collection Script tab and enter a script that will calculate which objects will form the collection.
    The following script recreates the list on the Outgoing References sub-tab on a table's Dependencies tab:
    Function %Collection%(obj, coll) ' Required
       dim r
       For each r in obj.outreferences   
          coll.Add r                  ' Populates collection
       Next
       %Collection% = True            ' Required
    End Function                      ' Required
    Note: You can reuse functions on the Global Script tab (see Global Script (Profile)) but you should be aware that if you declare global variables they will not be reinitialized each time the collection is calculated, and will keep their value until you modify the resource file, or the PowerDesigner session ends. This may cause errors, especially when variables reference objects that can be modified or deleted. Make sure you reinitialize the global variable if you do not want to keep the value from a previous run.
  4. Click Apply to save your changes.


  5. To view the collection, open the property sheet of a metaclass instance to the Dependencies tab and select the appropriate sub-tab.
  6. [optional] Add the collection to your model reports. Calculated collections are automatically available in the new Report Editor as lists under the appropriate metaclass book. You can add calculated collections to a legacy report, by changing the collection of the appropriate metaclass book or list (see Core Features Guide > Storing, Sharing and Reporting on Models > Reports > The Legacy Report Editor > Modifying the Collection of an Item).