Examples of Parameter Usage

  

DEVELOPER

Each example uses variants of one scenario: that of a Task with one formal numeric parameter PARAM1 that executes FUNCT1, which in turn links to FUNCT2. The Task is called with PARAM1 having a value of one. FUNCT1 and FUNCT2 each have one numeric parameter, F1_VAR1 and F2_VAR1 respectively. PARAM1 is mapped to both F1_VAR1 and F2_VAR1. FUNCT1 increments the value of F1_VAR1 twice, and FUNCT2 increments the value of F2_VAR1 three times.

The following examples examine the effect of different parameter usage on these parameters.

Example 1

PARAM1 has Both usage. F1_VAR1 has Both usage.  As F1_VAR1 is mapped to PARAM1 and has Both usage, a change in F1_VAR1’s value will update the value of PARAM1. As PARAM1 has Both usage, such a change will be passed back to the caller at the termination of the Task (whether through the normal Task Exit function or through an Error function).

Therefore, F1_VAR1 will be initialised to one when FUNCT1 starts executing. At the end of FUNCT1, F1_VAR has the value of three, which is written into the storage area for PARAM1 in the TGDA.

If F2_VAR2 has In usage, it will be initialised to three, not the old value of PARAM1 supplied by the caller. At the end of FUNCT2, F2_VAR1 has the value of six. That value is not written back to PARAM1 in the TGDA, as F2_VAR1 has In usage. If the Task terminates after the end of FUNCT2, the value of three is returned in PARAM1 to the Task’s caller.

Example 2

PARAM1 has In usage, F1_VAR1 has Both usage. F1_VAR1 will be initialised to one. At the end of FUNCT1, F1_VAR1 has a value of three. That value of F1_VAR1 will be written back to PARAM1’s storage area in the TGDA, as F1_VAR1 has Both usage. If the Task continues to execute, F2_VAR1 will be initialised to three, not the initial value of one passed in by the Task’s caller. Irrespective of when the Task terminates, the updated value of PARAM1 in the TGDA will not be returned to the caller, as PARAM1 is defined with In usage.

Example 3

PARAM1 has Both usage, F1_VAR1 has In usage, F2_VAR1 has Both usage. F1_VAR1 is initialised to one. At the end of executing FUNCT1, F1_VAR1 has the value of three. The value in PARAM1’s storage area in the TGDA is not updated, as F1_VAR1 has only In usage. If the Task finishes at this point, the caller receives back the value of one for PARAM1. If the Task continues by executing FUNCT2, F2_VAR1 is initialised to one. At the end of FUNCT2, F2_VAR1’s value is changed to four, and is written to PARAM1’s storage area in the TGDA. At the end of the Task, the value of PARAM1 that is transferred back to the caller is four, as PARAM1 has Both usage.

Comment on this topic

Topic ID: 540052