The column map procedure example illustrates the structure of a column map procedure with its standard functions: cm_load, cm_unload, cm_starttable, cm_endtable, and cm_transform.
-------------------------------------------------------------------------------
--
-- IBM Optim sample column map procedure
--
-- Name: OptimSample
--
-- Revision: 1.0
--
-- Description: Demonstrates all capabilities of Optim/Lua column map procedures
--
-- Input: Zero or more parameters, which will simply be echoed back to the
-- Optim process report
--
--
-- Output: Section in Optim process report showing information from this
-- column map procedure. The column itself is left unchanged.
--
--
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- cm_load function - Called before any tables are processed
-------------------------------------------------------------------------------
function cm_load()
optim.print(" *** Start of Process ***")
colinfoshown = false
-- Display parameters passed from Column Map
optim.print(" Argument Count: " .. string.format("%d", optim.parms.num()))
for i = 1, optim.parms.num(), 1 do
optim.print(" Argument " .. string.format("%d", i-1) .. " " .. optim.parms.get(i-1))
end
end
-------------------------------------------------------------------------------
-- cm_unload function - Called after all tables are processed
-------------------------------------------------------------------------------
function cm_unload()
optim.print(" *** End of Process ***")
end
-------------------------------------------------------------------------------
-- cm_starttable function - Called at the start of processing for each table
-------------------------------------------------------------------------------
function cm_starttable()
optim.print(" \nStart of processing table")
fullname = optim.source.getdbalias() .. "." .. optim.source.getcreatorid() .. "." .. optim.source.gettablename()
optim.print(" Source Table: " .. fullname)
fullname = optim.target.getdbalias() .. "." .. optim.target.getcreatorid() .. "." .. optim.target.gettablename()
optim.print(" Target Table: " .. fullname)
end
-------------------------------------------------------------------------------
-- cm_endtable function - Called at the end of processing for each table
-------------------------------------------------------------------------------
function cm_endtable()
optim.print(" \nEnd of processing table")
end
-------------------------------------------------------------------------------
-- cm_transform function - Called for each row processed
-------------------------------------------------------------------------------
function cm_transform()
if (not colinfoshown) then
colinfoshown = true
optim.print(" Processing column " .. optim.source.getcolumnname())
optim.print(" Type: " .. optim.source.getcolumntype())
optim.print(" Length: " .. optim.source.getcolumnlength())
end
-- This statement gets the value in the column for which cm_transform was called
-- Optionally, the name of another column can be specified, for example:
-- optim.source.getcolumnvalue("COL1") will return the value in column COL1
oldvalue = optim.source.getcolumnvalue()
-- This code sets that target column to the same value as the source column
-- Logic to change the value would be placed here.
-- If you wish to NOT insert this row into the target table, call the optim.rejectrow() function
newvalue = oldvalue
optim.target.setcolumnvalue(newvalue)
end