Official Content

There are at least two ways to work with collections of Structured Data Types:

  • Define the SDT object as a collection, or
  • Define the SDT object as one of the repetitive items, and work with a collection variable.

This is a particular case of the more general: how to work with collections whatever.

Let's see an example to understand better. Suppose that you need to work with a client's collection from a certain object. There are two ways to do so:

Define the SDT as a collection


Note that although 'Client' is, indeed, a structured data representing each item of the collection, it does not exist as an independent, defined SDT. The defined SDT is the collection one, 'Clients'.

Later, to work with the collection you'll have to define a &myClients variable and through it iterate a &eachClient variable:

VariableSDTMyClientsProperties VariableSDTEachClientProperties

So that you can do:

For &eachClient in &myClients 
     ... // Something with &eachClient

Note the 'Collection' variable property set as 'False' in the above example.

Define the SDT item only


Here you are only representing an item of the collection, but not the collection itself. So, how do you work with the collection?

Again, by defining two variables:

VariableSDTEachClientProperties2 VariableSDTMyClientsCollection

Note the way to work with a clients collection through a 'Collection' variable (myClients is set as a collection of the indicated Data Type, in our case, 'Client' SDT. It could be any Data Type as Character or any other)

The same code is used:

For &eachClient in &myClients     
    ...  // Something with &eachClient

The way you choose to work with a collection will depend on the need of having defined the item itself. For example, if you need to return it from a Data Provider object, because in the Output property of the Data Provider you cannot specify Clients.Client, that is, a non-defined SDT. In that case, you will need to choose the second option seen before.

What if you define both SDTs?

That is, in the same Knowledge Base, 'Clients' SDT and 'Client' SDT, as they appeared before. Be careful, because GeneXus will not understand that 'Clients.Client' and 'Client' are the same! For example, if you define the following SDTs:

Client SDT with Address Address SDT

Contrary to what one might think, the member Address of a Client is not of the 'Address' SDT data type. In fact, it is of the Client.Address data type.

If it was not what you wanted and you need both Addresses to be the same you define it as follows:

Client SDT with Independent SDT Address Address SDT

See also

Recursive SDTs
Structured Data Type editor
New operator (SDT)


Start Video Loading Compound Data Types (SDT) using Data Providers
Start Video Two ways of returning a collection using a Data Provider

Last update: November 2023 | © GeneXus. All rights reserved. GeneXus Powered by Globant