10 2 Chaining Multiple Intrinsic Functions

LANSA Technical

10.2 Chaining Multiple Intrinsic Functions

As Intrinsic Functions by definition return a result factor, it is possible to chain multiple Intrinsic Functions on one line of code.

Consider the following requirement. Set the caption of a form to tomorrow's week day e.g Tuesday or Wednesday.

While the code itself is not entirely difficult from a logical perspective, it could require a number of different variables to store the various pieces of data as the required result is calculated. We would have to take today's date, advance it by one, taking in to consideration month and year ends etc., and then convert the result to the day of the week. Whilst this is possible using BIFs, it would require a number of lines of code and some temporary storage.

However, by using multiple Intrinsic Functions, each of which will operate on the result of the preceding function, we can keep the code concise and readable. For example

Mthroutine Name(Get_Tomorrow_DOW)

Define_Map For(*Result) Class(#prim_alph) Name(#oTomorrow_DOW)

 

Define Field(#Today) Type(*Date)

 

#oTomorrow_DOW := #Today.Now.Adjust( 1 ).AsDayOfWeek

 

Endroutine

 

In the code above, the Now Intrinsic is used to set #Today to today's date. The Adjust intrinsic is then used to advance the date by one day. Finally, the result of the adjusting the date is converted to a day of the week by way of the AsDayOfWeek function.

Some intrinsic functions appear to have minimal value. For example, Pred (predecessor) subtracts 1 from a number and returns it as the result. The major use for such Intrinsic Functions is as a component of a more complex evaluation. Rather than using temporary variables, or embedding expressions, which require a further set of parentheses, we can use the intrinsic.

In the following simple example, number1 is compared to number2 or number 3, but requires embedded expressions, and consequently extra sets of parentheses.

If ((#Number1 - 1) = #Number2) or ((#Number1 - 1) = #Number3))

Endif

 

This can also be written using the Pred intrinsic as follows

If ((#Number1.pred = #Number2) or (#Number1.pred = #Number3))

Endif

 

It is difficult to clearly demonstrate the benefit of embedded Intrinsic Functions using short examples in isolation. However, when writing complex code, any simplification that results from minimizing expression and parenthesis use, must be of benefit.

Ý 10. Intrinsic Functions