Write generic code with ORDA

Automatically translated from English

ORDA was one of the major announcements of 4D Summit 2018, opening a world of new possibilities in 4D. To learn more about ORDA and its benefits, check out this post to see how ORDA will change the way you work.


With ORDA, data is accessed through an abstraction layer: the datastore. A datastore is an object providing an interface to the database and its data through objects. For example, a table is mapped to a dataclass object, a field is an attribute of a dataclass. The new ds command returns a reference on the application datastore. If you want to learn more, take a look at the overview article in the documentation.

To guide you through the exploration of ORDA features, we’ve prepared a glossary of the different terms and concepts, along with their definition.

ORDA also provides some useful information about the database’s structure.

This can be very helpful when writing generic code …. without knowing a database’s structure.

Download the dynamic sort tool TIP

Here’s an example:

Since the dataStore returned by the ds command is an object, it can be iterated through using a for each loop to get its attributes (aka the dataClasses).

This allows you to write generic code applicable to all tables exposed in the dataStore.

In the example below, we build a collection of objects containing the dataClasses.

For each ($dataClassName;ds)
  $dataClassObj:=New object
End for each

This collection can be displayed in a list box to allow users to select a dataClass. Then, we can continue with generic code on the selected dataClass.

A dataClass object can also be iterated through with a for each loop to get its attributes containing useful properties:

    • name: name of the dataClassAttribute in the data model
    • kind: the category of the attribute:
      • “storage”: equivalent to a field in the 4D database
      • “relatedEntity”: an N -> 1 relation attribute
      • “relatedEntities”: an 1 -> N relation attribute
    • relatedDataClass: the name of the dataclass related to the attribute (if kind is “relatedEntity” or “relatedEntities”)


Given all this information, you can write generic code without knowing your database’s structure.

In the provided TIP example database, you’ll learn how to dynamically:

  • select a dataClass of the dataStore,
  • build a list box with all the dataClass properties including first level related entity, and
  • build a sort tool.


Here is an overview of this TIP:

• Product Owner •

Marie-Sophie Landrieu-Yvert has joined the 4D Product team as a Product Owner in 2017. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.

Marie-Sophie graduated from the ESIGELEC Engineering School and began her career as an engineer at IBM in 1995. She participated on various projects (maintenance or build projects) and worked as a Cobol developer. Then she worked as an UML designer and Java developer. Lately her main roles were analyzing and writing functional requirements, coordinate business and development teams.