Declarations (Business Logic)

Syntax

  • var <variable name> [: collectionof? elementsof? <static path expression> | <data type>]?[= literal | <path expression>]?;

Description

The implementation language is a statically-typed language that allows you to use declared variables only. You always need to declare the variable before you can use it in a statement. If you declare a variable within a code block (so-called variable scoping), that is, within the braces ({...}), the scope of this variable is limited to this code block.

Note

Variable shadowing is not supported, that is, variables cannot reuse names that are already declared in an enclosing scope.

End of the note

The variable type is automatically inferred upon first assignment of the variable. You can assign an initial value either by specifying a literal or by specifying a path expression, that is, elements of other already existing variables or elements of the this context. Assignments use copy semantics, that is, a temporary copy is created when individual elements are accessed using the this context. Node variables have reference semantics.

Alternatively, you can explicitly specify the variable type in the variable declaration. For this, you can use basic data types as well as global data types (GDTs).

You can also derive the underlying type of a business object node by using the elementsof modifier followed by a static path expression that identifies a business object node. This is useful if you define initial node data that can be passed as a parameter to the Create operation of a business object node. Do not use the elementsof modifier if you want to derive the type of an element from a static path expression.

Example

  • var counter = 0;
  • var amount : Amount;
  • //To use the "Amount" GDT , you need to import the AP.Common.GDT namespace first
  • var strVar = "test";
  • var strVar : LANGUAGEINDEPENDENT_Text;
  • //To use the "LANGUAGEINDEPENDENT_Text" GDT , you need to import the AP.common.GDT namespace first
  • var boolVar = true;
  • var name = this.Name;
  • var nodeData : elementsof ExampleBO.Item;
  • var nodeData : ExampleBO.Item.Element;
  • var coll : collectionof ExampleBO.Item;
  • var coll : collectionof elementsof ExampleBO.Item;