Sample Collection Guide > Synchronizing Active Tasks

Synchronization of Active Tasks

Objective: Already active jobs should be synchronized manually.

Objects used: Script object and Sync object

Script elements used: ADD, :ATTACH_SYNC, :BEGINREAD, FORMAT, GET_SYNC, GET_UC_OBJECT_NR, :PRINT, :READ, SET_SYNC and :STOP


Sync objects can be used for synchronizing tasks. Each executable object contains a Sync tab where all the required actions can be selected. Subsequent synchronization when the tasks are already active is also possible.

Sync objects

In a Sync object, you can define the conditions (such as EXCLUSIVE - "The databaseA database is an organized collection of data including relevant data structures. is used exclusively"). Names, values and the total number of conditions can be freely selected depending on your requirements. The Sync object obtains one of these conditions and changes it as soon as actions are taken. These actions are also defined in the Sync object and can then be selected in the Sync tabs of objects (see illustration).

In each executable object you can select the required Sync object and specify the corresponding action for the particular points in the execution of tasks (Action: "RELEASE" when task is ended, for example). Tasks can so be synchronized on the basis of the current condition and the defined reaction to it.

The following example is to show how two tasks can be synchronized by defining one task as the successor of the other. The detailed procedure is described below:

The states "FREE", "TASK1" and "TASK2" can now be determined for the Sync object. Three actions are required for controlling the Sync object states: "SET_TASK1", "SET_TASK2" and "SET_FREE".

The following table is to explain the interaction of the Sync object and the tasks:

Precondition: The Sync object is in the condition "FREE"

Definition in...

Action

Result

SET_SYNC (in the script)

SET_TASK1

Task 1 can start

Task 1

SET_TASK2 (at the end)

Task2 can start

Task 2

SET_FREE (at the start)

Sync object is available again

With the settings described above, two tasks can be synchronized with one Sync object. In this example we use two Sync objects, which is sufficient. Usually, manual synchronization is only used in exceptional cases, when an additional task should be included in an ongoing process, for example. A clearly-defined name including a number is helpful as the particular Sync objects can be accessed through counter readings.

Script

The subsequent synchronization of the two tasks is implemented through script elements. Therefore, a Script object must be created which includes the necessary procedure.

In the following script, an input dialog is created first in which the two task names can later on be entered. Then it is necessary to check if these tasks are really active (i.e. they have a RunID). Otherwise, the script is aborted.

Afterwards, a WHILE loop checks if SYNC objects are available. The names are all checked sequentially through a counter variable (SYNC.JOB.ABHAENGIGKEIT_nn).

The script function GET_SYNC is used to read the current status of the Sync object. Only if it is in the status "FREE", the tasks can use it. If there is no such Sync object, the script is aborted. If a Sync object is available, it can be entered in the two tasks with the script element ATTACH_SYNC.

!Number of available SYNC objects
:
SET &number_sync# = 2


!Specifying the task and its successor

:
BEGINREAD 'Defining a dynamic dependency'
:  
PRINT 'ATTENTION: The tasks must already be active !!!'
:  
PRINT ''
:  
READ &task1#,'00','Name of the predecessor',,M
:  
READ &task2#,'00','Name of the successor',,M
:
ENDREAD 

!Is the task active?
:
SET &RunIDa1# = GET_UC_OBJECT_NR(JOBS,'&task1#')
:
IF &RunIDa1# = ''
:   
STOP MSG,50,'Predecessor (&task1#) is not active!'
:
ENDIF 


!Is task 2 active?

:
SET &RunIDa2# = GET_UC_OBJECT_NR(JOBS,'&task2#')
:
IF &RunIDa2# = ''
:   
STOP MSG,50,'successor (&task2#) is not active!'
:
ENDIF 

Retrieving a free SYNC object through a counter
!(SYNC.JOB.DEPENDENCY_01, SYNC.JOB.DEPENDENCY_02)

:
SET &status# = ''
:
SET &counter# = 0

:
WHILE &status# <> 'FREE'
:  
SET &counter# = ADD(&counter#,1)
:  
SET &counter# = FORMAT(&counter#,'00')
:  
IF &counter# > &number_sync#
:     
STOP MSG,50,'No free Sync object available!'
:  
ENDIF
:  
SET &status# =  GET_SYNC('SYNC.JOB.DEPENDENCY_&counter#','STATE')
:
ENDWHILE 

!Adding the SYNCs
:
SET &ret# = SET_SYNC('SYNC.JOB.DEPENDENCY_&counter#','SET_TASK1')
:
ATTACH_SYNC JOBS,&RunIDa1#,'SYNC.JOB.DEPENDENCY_&counter#',,,SET_TASK2,W
:
ATTACH_SYNC JOBS,&RunIDa2#,'SYNC.JOB.DEPENDENCY_&counter#',SET_FREE,,,W