The Safe Navigation Operator (?:) allows you to write code expressions that involve conditional execution of a chain of object-oriented ABL cascading element references in a short-hand way. It simplifies code navigation through chained code elements such as objects, object properties, and methods which may potentially return null references. You can use the Safe Navigation Operator and eliminate elaborate conditional code to validate the return of each element in the chain.

For example, consider the following chained expression:

retVal = Handle:method1():method2():method3().
If a NULL value is returned by any of the methods in the chain, then the AVM raises an error condition. To catch the occurrence of the NULL value anywhere in the chain, elaborate conditional code is required. The Safe Navigation Operator allows you to write compact code and guarantees that an error condition that occurs anywhere in the chained expression results in the termination of the expression and returns an unknown (?) value. You can replace the previous expression using the Safe Navigation Operator as shown below:
retVal = Handle?:method1()?:method2()?:method3().

Syntax

{object-reference}?:{class-member-name}.
object-reference
Reference to an instance of an ABL class that defines the specific data member as an instance member (non-static).
class-member-name
The name of a data member or member method you want to access. A class member is an element that is defined in and at the level of a class definition.
Note: The Safe Navigation Operator can be used everywhere the colon syntax is used to de-reference an ABL object’s elements. For more information on the rules for using the Safe Navigation Operator, see "?: Safe navigation operator" in the ABL Reference.

Example: Single chain

object-reference?:class-member-name

obj1 = obj2?:getTotal().
DEFINE VARIABLE refA_char AS CHAR.
refA_char = new myClass()?:refA.
MESSAGE "Value of refA is " refA_char.

Example: Multiple chain

object-reference?:identifier1?:identifier2?:identifier3

obj1 = obj2?:getObject()?:getObjTotal().