Column map procedure example: National ID masking

The column map procedure example illustrates how the mask_parms function masks a column that contains a national ID.

-------------------------------------------------------------------------------
--
--   IBM Optim sample column map procedure
--
--   Name:          OptimNID
--
--   Revision:      1.0
--
--   Description:   Masks a national ID column based on the value of another 
--                  column or a script argument with the country code.
--
--   Input:         Parameter 1 (Required):
--                  A string country code (eg. US for United States)
--                  --OR--
--                  COL(column-name) where column-name is the name of a column
--                  that contains the country code
--
--                  Parameter 2 (Optional):
--                  A string containing additional parameters to be copied into the
--                  optimmask invocation
--                  This is in addition to the mask_parms_constant field that is
--                  delcared at the start of this script.
--
--
--
--   Output:       - The masked column data as set by the optim.target.setcolumnvalue function
--                 - Text directed to the Optim report by the display function
--
--   Return Codes: 0 - Successful execution
--                 1 - Reject row (Use in cm_transform;  row will not be inserted to 
--                     destination table)
--                 2 - Abort process
--
--                 Two helper functions are specified to specify conditions other than 
--                 return code 0.
--                 There is no need to code a return statement when using these 
--                 functions.
--                 error(string) - This call will cause the Optim process to abort
--                                 and string will be shown in the Optim report
--                                 as an error message.
--                 optim.rejectrow()   - This call will cause Optim to reject the row
--                                       currently being processed The row will
--                                       not be inserted into the destination table.-
--
--
-------------------------------------------------------------------------------

function cm_transform()

    -- Change this field to contain parameters that should
    -- be placed into all optim.mask calls
    local mask_parms_constant = 'MTD=REPEATABLE'

    --
    -- Obtain parameters:
    --
    nparm = optim.parms.num()
    if nparm  ~= 1 and nparm ~= 2 then
       msg = "Call to column map procedure for column "
                  msg = msg ..  optim.source.getcolumnname()
       msg = msg .. " must have 1 or 2 parameters"
       error(msg)
    end
    parm1 = optim.parms.get(0)
    if (nparm == 2) then
       parm2 = optim.parms.get(1)
    end

    --
    -- Get country code into swivalue field based on parameters
    --
    if string.lower(string.sub(parm1, 1, 4)) == 'col(' then
       closeparen = string.find(parm1, ')', 5, true)
       if (not closeparen) then
           error("No closing parenthesis found in expression: " .. parm1)
       end
       colname = string.sub(parm1, 5, closeparen-1)
       swivalue = optim.source.getcolumnvalue(colname)
    else
       swivalue = parm1
    end

    --
    -- Construct call to optimmask, make the call,
               -- and place new value into target column
    --
    mask_parms = 'PRO=NID, SWI=' .. swivalue .. ', ' .. mask_parms_constant
    if (parm2) then
       mask_parms = mask_parms .. ', ' .. parm2
    end
    oldvalue = optim.source.getcolumnvalue()
        newvalue = optim.mask(oldvalue, mask_parms)
        optim.target.setcolumnvalue(newvalue)
end


Feedback