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
}
}

}
}
}

No comments:

Post a Comment

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, ...