More process flow basics - for loops

Here we create a typical programming loop within the process flow iterating over a number of activities based on a numeric index. The flow created represents the following pseudocode;

  assign_rslt := 0;
  for (int iter_idx:=0; iter_idx < number_iterations; iter_idx++) {
    // my activity in the for loop is simply assigning the for loop variable
    // to another variable, this can be much more complex and involve other activity types
    assign_rslt := iter_idx;
  }

Using OMB this can be created as below, the script will create a process flow module named FLOW_EXAMPLE, a package named FLOWPACK and a flow named FLOW_FOR_LOOP. The flow can be deployed and executed after the flow module has been editing and configured and the location set. It has no dependencies since the content of the flow is very simple to illustrate the activities.

set flow_mod_name FLOW_EXAMPLE
set flow_pack FLOWPACK
set flow_name FLOW_FOR_LOOP
set iter_cnt 20
OMBCC '/$OMB_CURRENT_PROJECT'
catch { OMBCREATE PROCESS_FLOW_MODULE '$flow_mod_name' }
OMBCC '$flow_mod_name'
catch { OMBCREATE PROCESS_FLOW_PACKAGE '$flow_pack' }
OMBCC '$flow_pack'

OMBCREATE PROCESS_FLOW '$flow_name'
OMBALTER PROCESS_FLOW '$flow_name' ADD PARAMETER 'NUMBER_ITERATIONS' SET PROPERTIES (DIRECTION,DATATYPE,VALUE) VALUES ('IN','INTEGER','$iter_cnt')
OMBALTER PROCESS_FLOW '$flow_name' ADD VARIABLE 'ITER_IDX' SET PROPERTIES (DATATYPE,VALUE) VALUES ('INTEGER','0')
OMBALTER PROCESS_FLOW '$flow_name' ADD VARIABLE 'ASSIGN_RSLT' SET PROPERTIES (DATATYPE,VALUE) VALUES ('INTEGER','0')

OMBALTER PROCESS_FLOW '$flow_name' ADD ASSIGN ACTIVITY 'ACTIV_IN_LOOP'
OMBALTER PROCESS_FLOW '$flow_name' ADD FOR_LOOP ACTIVITY 'FOR_LOOP'
OMBALTER PROCESS_FLOW '$flow_name' ADD END_LOOP ACTIVITY 'END_LOOP'

OMBALTER PROCESS_FLOW '$flow_name' ADD TRANSITION 'ST_2_GC' FROM  ACTIVITY 'START1' TO 'FOR_LOOP'
OMBALTER PROCESS_FLOW '$flow_name' ADD TRANSITION 'WH_2_GF' FROM  ACTIVITY 'FOR_LOOP' TO 'ACTIV_IN_LOOP' SET PROPERTIES (TRANSITION_CONDITION) VALUES ('LOOP')
OMBALTER PROCESS_FLOW '$flow_name' ADD TRANSITION 'AS_2_EL' FROM  ACTIVITY 'ACTIV_IN_LOOP' TO 'END_LOOP'
OMBALTER PROCESS_FLOW '$flow_name' ADD TRANSITION 'EL_2_WL' FROM  ACTIVITY 'END_LOOP' TO 'FOR_LOOP'
OMBALTER PROCESS_FLOW '$flow_name' ADD TRANSITION 'WH_2_EN' FROM  ACTIVITY 'FOR_LOOP' TO 'END_SUCCESS' SET PROPERTIES (TRANSITION_CONDITION) VALUES ('EXIT')

OMBALTER PROCESS_FLOW '$flow_name' MODIFY ACTIVITY 'FOR_LOOP' MODIFY PARAMETER 'CONDITION' SET PROPERTIES (VALUE) VALUES ('ITER_IDX < NUMBER_ITERATIONS')
OMBALTER PROCESS_FLOW '$flow_name' MODIFY ACTIVITY 'FOR_LOOP' MODIFY PARAMETER 'INITIAL_VALUE' SET PROPERTIES (VALUE) VALUES ('0')
OMBALTER PROCESS_FLOW '$flow_name' MODIFY ACTIVITY 'FOR_LOOP' MODIFY PARAMETER 'VARIABLE' SET PROPERTIES (BINDING) VALUES ('ITER_IDX')
OMBALTER PROCESS_FLOW '$flow_name' MODIFY ACTIVITY 'FOR_LOOP' MODIFY PARAMETER 'NEXT_VALUE' SET PROPERTIES (VALUE,ISLITERALVALUE) VALUES ('ITER_IDX + 1', 'FALSE')

# Define the assign activity in the loop
OMBALTER PROCESS_FLOW '$flow_name' MODIFY ACTIVITY 'ACTIV_IN_LOOP' MODIFY PARAMETER 'VARIABLE' SET PROPERTIES (BINDING) VALUES ('ASSIGN_RSLT')
OMBALTER PROCESS_FLOW '$flow_name' MODIFY ACTIVITY 'ACTIV_IN_LOOP' MODIFY PARAMETER 'VALUE' SET PROPERTIES (VALUE) VALUES ('ITER_IDX')


There are a few properties such as the TRANSITION_CONDITION (values LOOP and EXIT) that are important. The actual for loop activity has a bunch of parameters that constitute the loop variable, the initial value the increment expression and the exit criteria. Hope this helps.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

ETL, CDC, Real-Time DI and Data Quality for the Oracle Database from the inside.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today