2007/07/22

using WHILE Loop - OWB10gR2

The diagram below details the usage of WHILE loop operator in OWB10gR2.








The requirement is to check for the existence of a file on the server at a specified location. If the file exists, then complete with success and then execute the mapping. If the file does not exists then to loop through a specified period of time an hour, checking for the arrival of file for every 1 minute, and to end with Error status if the file has not arrived in the specified time.

The way I have achived this task is -

1. Defined a variable "CHK_FILE_STATUS" under START activity.
2. Assign a value 0 to the variable "CHK_FILE_STATUS"
Assigning Value "0"



3. Then, in the while loop put a condition to loop for an hour.


4. Use the File_Exists condition and specify the full path for the file to be checked for.
5. From File_Exists operator Use two transitions.
6. If File_Exists returns "Exists" then branch to Success.
7. If File_Exists returns anything other than "Exists" then loop through the logic to increment the variable "CHK_FILE_EXISTS" by 1.

8. Wait for a 60 seconds (delay) before checking for the arrival of file.


9. The while condition will be evaluated and the "FILE_EXISTS" will be checked until the variable "CHK_FILE_EXISTS" reaches the count 61 ( 1 hours).
10. If the file arrives before the count reaches 61, the WHILE loop will be broken to END_SUCCESS otherwise after 60mins, the loop breaks to END_ERROR.


2007/07/19

OMB+(Tcl) script for copying attributes between groups

At the current client site am working on, the source tables have morethan 500 columns. And the mappings involved SET operators to process the data, and it was a pain to type in all the attributes in SET operators. so I have written the below TCL script which copies the attributes from one group to other in the same as order as defined in group1.

The script is -

puts "proc add_GRP is created"
puts "==================="
puts "Input Parameters:"
puts "======================="
puts "PROJECT MODULES MAP OPR_NAME SRCGRP TGTGRP"
puts "========================="
proc add_grp { PROJ MOD MAP OPRNAME SRCGRP TGTGRP } {

OMBCC '/$PROJ/$MOD'
set cc [ OMBDCC ]
set ccon [ lindex [ split $cc " "] 1 ]

puts $ccon

set atrlst [ OMBRETRIEVE MAPPING '$ccon/$MAP' OPERATOR '$OPRNAME' GROUP '$SRCGRP' GET ATTRIBUTES ]

foreach aname $atrlst {
set dt ""
set ln ""
set pr ""
set sc ""

set prop [ OMBRETRIEVE MAPPING '$ccon/$MAP' OPERATOR '$OPRNAME' GROUP '$SRCGRP' ATTRIBUTE '$aname' GET PROPERTIES (DATATYPE, LENGTH, PRECISION, SCALE) ]
#puts "$aname ---- $prop"

#splitting the above into individual var

set dt [ lindex [ split $prop " " ] 0 ]
set ln [ lindex [ split $prop " " ] 1 ]
set pr [ lindex [ split $prop " " ] 2 ]
set sc [ lindex [ split $prop " " ] 3 ]
#puts "$aname -------- $dt"

set tgtatrlst [ OMBRETRIEVE MAPPING '$ccon/$MAP' OPERATOR '$OPRNAME' GROUP '$TGTGRP' GET ATTRIBUTES ]

# check whether the attribute already exists

if { [lsearch $tgtatrlst $aname] == -1 } {
puts "Adding $aname"
OMBALTER MAPPING '$MAP' ADD ATTRIBUTE '$aname' OF GROUP '$TGTGRP' OF OPERATOR '$OPRNAME'
OMBCOMMIT
# change attribute properties

if { $dt == "NUMBER" } {
puts "Changing length and precision for $aname -------- FOR $dt "
OMBALTER MAPPING '$MAP' MODIFY ATTRIBUTE '$aname' OF GROUP '$TGTGRP' OF OPERATOR '$OPRNAME' SET PROPERTIES (PRECISION, SCALE) VALUES ($pr,$sc)
} else {
if { $dt == "DATE" } {
OMBALTER MAPPING '$MAP' MODIFY ATTRIBUTE '$aname' OF GROUP '$TGTGRP' OF OPERATOR '$OPRNAME' SET PROPERTIES (DATATYPE) VALUES ('$dt')
} else {
puts "changing for $aname -------- $dt"
OMBALTER MAPPING '$MAP' MODIFY ATTRIBUTE '$aname' OF GROUP '$TGTGRP' OF OPERATOR '$OPRNAME' SET PROPERTIES (DATATYPE,LENGTH) VALUES ('$dt',$ln)
OMBCOMMIT
}
}

}
}
}

File Handling with Python

This little utility is for copying files from source to target directories.  On the way it checks whether a directory exists in the target, ...