Table of contents

Official Content

An Inline Formula is a local formula defined within an object code (for example in the middle of a Procedure Source, in an object subroutine, in a Data Provider statement, etc.).

In other words, a formula can be locally assigned to an attribute or variable, as a sentence or statement in the middle of the code, or in a where clause, etc.


<variable>|<attribute> = <UnconditionalFormula>} | <UnconditionalFormula>

An inline formula (<UnconditionalFormula>), can be either horizontal or aggregate.

The main difference regarding Global Formulas is that inline may not consist of several conditional expressions, not even a single conditional one. In addition, in any inline formula, variables could be involved in the expression (because the formula does only exists in this local piece of code where the variable is known).

Whereas you really don't know all the places where a global formula is going to be triggered. This is the meaning of "global". It can be used everywhere an attribute of the corresponding base table is allowed)

While Global Formulas always have a table in its context (the table where the formula attribute would be stored if it were not virtual), inline formulas do not have to. For what kind of formulas? Those that don't need context to be evaluated: Aggregate Formulas.

Why the context is meaningful?

Because it will affect the calculation result, allowing to add filtering conditions to the data considered.


Assume you have a FlightInstance Transaction object to store a real flight from one country/city to another, with a second level, FlighInstanceSeat, to store the passengers of the flight. Suppose a Procedure object needs to know at the beginning if there already are more than 100 seats assigned to passengers in the corresponding table.

   &success = Count(FlightInstancePassengerSeatNumber) > 100

Here there is no context table for the formula. It is triggered isolated, counting all the records of its base table, FlightInstanceSeat. It will count all the passengers for all the flight instances stored.

On the other hand, if the above code were inside a for each command, such as:

   for each FlightInstance
   where Count( FlightInstancePassengerSeatNumber) > 100
      print flightInstanceInfo //FlightInstanceNumber, FlightInstanceDate

The formula does have a context: the FlightInstance table, the base table of the For each. Thus, not all the passenger seats were going to be counted, but only those corresponding to each FlightInstance record considered in each "for each" iteration. So, only the flights with more than one hundred passengers will be printed in the output.

If you had defined a global formula attribute FlightInstanceNumberOfPassengers at FlightInstance transaction level, you could have defined equivalently as follows:

   for each FlightInstance
   where FlightInstanceNumberOfPassengers > 100
      print flightInstanceInfo //FlightInstanceNumber, FlightInstanceDate

Furthermore, if there is a contextual table, all the attributes of its extended table could be used inside the formula, as known. For example, having a variable &fromDate previously loaded:

   for each FlightInstance
   where Count( FlightInstancePassengerSeatNumber, FlightDate >= &fromDate) > 100


Inline formulas that are horizontal always have a context table: at least its own base table. It is exactly the same as horizontal global formulas. Thus, they can not be specified without a context where the attributes could assume value.

For example:

   &age = &today.Year() - PassengerBirthDate.Year()

this assignment isolated makes no sense. What passenger birth date are you talking about? The situation would be different if this assignment were:

for each FlightInstanceSeat
    &age = &today.Year() - PassengerBirthDate.Year()

Here GeneXus infers the passenger is that of each "for each" iteration, that is, that associated with the for each base table record where you are positioned each time. The "for each" navigates the table that stores the passengers assigned to seats: FlightInstanceSeat. Note in this case the context table, FlightInstanceSeat, is not exactly the base table of the formula, Passenger, but the former contains in its extended the latter.

So, inline formulas can be defined according to their context:


Start Video Inline Formulas

Last update: April 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant