Inline FormulasOfficial 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 in several conditional expressions, not even a single conditional one. In addition, as 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 we 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 a global formula always has a table in its context (the table where the formula attribute would be stored if it were not virtual), an inline formula does 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 we have a FlightInstance transaction 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 needs to know at the begining if there already are more than 100 seats assigned to passengers in the corresponding table.

   &success = Count( FlightInstancePassengerSeatNumber ) > 100

Here there is not a 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, 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 output. 

If we had defined a global formula attribute FlightInstanceNumberOfPassengers at FlightInstance transaction level, we 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 we talking about? 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 to the for each base table record where we 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 Local Formulas

Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.