Introducing Procedures

Objective

After completing this lesson, you will be able to explore the fundamentals of procedures

Introduction into Procedures

Procedures in SAP AVC employ an imperative model by executing a specific sequence of statements to derive values. While constraints are generally preferred, some applications still require the use of procedures.

The figure lists the paradigms for procedures.

The procedure runs only once per processing cycle and does not re-evaluate within that same roundtrip.

The execution of a procedure strictly distinguishes between the left and right sides of an assignment operator:

  • the right side is for reading
  • the left side is for writing

The primary purpose of a procedure is to calculate a value and explicitly assign it to a characteristic.

Addtionally, procedures can actively remove a characteristic’s valuation, an action that is not possible within the declarative logic of a constraint.

In exceptional cases, a procedure can be used to indirectly exclude values from a characteristic’s domain.

The figure describes the execution order of procedures according to the assigned sort number.

The execution order for multiple procedures is controlled by an assigned sort number. They are processed in ascending order (e.g., 10, 20, 30), and this entire sequence runs only once per processing roundtrip

Within any single procedure, the system executes the statements from the first statement at the top to the last statement at the bottom. The outcome of a previous statement is available to all subsequent statements.

The execution flow of procedures is governed by a strict, two-level order that determines if and when a procedure is run:

The figure shows the difference between skipping a single statement versus explicitly terminating a procedure, which prevents all subsequent statements from being executed.

If the expression on the right side of a procedural statement is ambiguous - for example, if a needed value is missing - the system implicitly skips that specific statement and continues execution with the next statement.

The EXIT IF syntax gives you explicit control to terminate the entire procedure based on a condition you define. All subsequent statements within that same procedure are ignored and will not be executed.

Caution

Unlike AVC’s behavior of skipping a single line, classic LO-VC will stop processing the entire procedure if it encounters a statement with a missing value.

The figure describes the operators and if-syntax in procedures.

The unidirectional nature of procedures means that the left and right sides of an assignment serve distinct functions and are governed by different rule.

Characteristic to the left of the operator:

  • must refer to $SELF: the characteristic being changed must belong to the current object where the procedure is running
  • is the target of the action: Its value can be set, retracted have its domain restricted

Characteristic to the right of the operator:

  • can refer to $SELF, $PARENT or $ROOT
  • are unchangeable: the values of characteristics on the right side are used for reading only
  • must be valued: for the statement to execute correctly, any characteristic on the right side must have a value. If a value is missing, the statement is skipped.

Characteristics used within conditional logic, such as in an IF statement, must follow a specific set of rules:

  • can refer to $SELF, $PARENT or $ROOT
  • are unchangeable: the characteristics are used for reading only; their values cannot be modified within the condition itself
  • must be valued: the condition check relies on the characteristic having an assigned value to evaluate correctly

If a characteristic used within a condition is not valued, the condition cannot be evaluated as true. As a result, the system effectively treats the condition as false.

The figure lists the special syntax that can only be used in procedures. This is used for retracting the current valuation, setting a valuation, and procedure processing.

The use of syntax exclusive to procedures means that constraints, despite being the preferred method for relationship knowledge, cannot be used in all applications. For such use cases, procedures are required.

The same applies to syntax that can be used in procedures, preconditions, and selection conditions, but not in constraints.

Hint

Modeling for good performance: Don't use overwriting procedures at all if possible - e.g. incremental calculation. In practice, this can often be easily achieved. If overwrites can’t be avoided, try not to address the affected characteristics in constraints additionally.
The figure lists the syntax that can only be used in procedures, preconditions, and selection conditions. This includes the minimum/maximum syntax, special syntax for multi-value characteristics, and how to check if a characteristic has been assigned a value.