Hello Hari,
I have 2 examples in this reply.
The first is using Optim Privacy Table OPTIM_US_PERSON.
This example will preform a "LOOKUP" and if the value is not found, the default value "Default Value" would be used
Good luck!
Example #1
function cm_transform()
stat_parm = 'PRO=LOOKUP,SOURCE="SSN",SEARCH="SSN",'
stat_parm = stat_parm .. 'DEST="FIRSTNAME",REPLACE="LASTNAME",'
stat_parm = stat_parm .. 'LIB=DB2LUW,CONN=PRIVACY,'
stat_parm = stat_parm .. 'ID="PRIVACY.OPTIM_US_PERSON",'
stat_parm = stat_parm .. 'FLDDEF1=(NAME="SSN",dt=WVARCHAR_SZ),'
stat_parm = stat_parm .. 'FLDDEF2=(NAME="FIRSTNAME",dt=WVARCHAR_SZ)'
--stat_parm = stat_parm .. 'WHENNOTFOUND=PRESERVE'
--stat_parm = stat_parm .. 'PRESERVENULL="FIRSTNAME"'
iFname = optim.source.getcolumnvalue("FIRSTNAME")
issn = optim.source.getcolumnvalue("SSN")
print('SSN --> ' .. issn)
rcstatus, maskValue1 =
pcall(optim.mask,issn,stat_parm)
if rcstatus == true then
optim.target.setcolumnvalue(maskValue1)
else
optim.target.setcolumnvalue("Default Value")
print('value was nil')
end
end
The second example is similar that a default value will be provided if the LOOKUP replacement is not found,
However, this Lua Chunk will provide the Optim ODPP error.code and error.reason.
Good luck,
Example #2
function cm_starttable()
cntx = 0
cnt_not_found = 0
cnt_found = 0
end
function cm_transform()
stat_parm = 'PRO=LOOKUP,SOURCE="xMASK_RULEID,PLAN_ID,xSYSTEM_CODE,GROUP_NUM,PLAN_NUM",'
stat_parm = stat_parm ..'SEARCH="MASK_RULEID,PLAN_ID,SYSTEM_CODE,GROUP_NUM,PLAN_NUM",'
stat_parm = stat_parm .. 'DEST="LONG_NAME",REPLACE="SHORT_NAME",'
stat_parm = stat_parm .. 'LIB=DB2LUW,CONN=PRIVACY,'
stat_parm = stat_parm .. 'ID="LKUP.REFRESH_MAPPING_PLAN_NAME",'
stat_parm = stat_parm .. 'FLDDEF1=(NAME="xMASK_RULEID",dt=WVARCHAR_SZ),'
stat_parm = stat_parm .. 'FLDDEF2=(NAME="PLAN_ID",dt=LONG_LONG),'
stat_parm = stat_parm .. 'FLDDEF3=(NAME="xSYSTEM_CODE",dt=WVARCHAR_SZ),'
stat_parm = stat_parm .. 'FLDDEF4=(NAME="GROUP_NUM",dt=WVARCHAR_SZ),'
stat_parm = stat_parm .. 'FLDDEF5=(NAME="PLAN_NUM",dt=WVARCHAR_SZ),'
stat_parm = stat_parm .. 'FLDDEF6=(NAME="LONG_NAME",dt=WVARCHAR_SZ)'
cntx = cntx + 1
--print(string.format("cntx --> %d",cntx))
iMaskRuleID = 'SSDEMQ'
--iMaskRuleID = optim.source.getcolumnvalue("MASK_RULEID")
iSystemCD = 'VSYS'
--iSystemCD = optim.source.getcolumnvalue("SYSTEM_CODE")
iShortName = optim.source.getcolumnvalue("SHORT_NAME")
iGroupNum = optim.source.getcolumnvalue("GROUP_NUM")
iLongName = optim.source.getcolumnvalue("LONG_NAME")
iPlanNum = optim.source.getcolumnvalue("PLAN_NUM")
iPlanID = optim.source.getcolumnasdouble("PLAN_ID")
rcstatus, maskValue1 =
pcall(optim.mask,iMaskRuleID,iPlanID,iSystemCD,iGroupNum,iPlanNum,stat_parm)
if rcstatus == true then
--print('rcstatus = true')
cnt_found = cnt_found + 1
print(string.format("cnt_found default --> %d",cnt_found))
--print(cntfound,string.format("cnt_found default --> %d",cnt_found))
optim.target.setcolumnvalue("LONG_NAME",maskValue1)
else
cnt_not_found = cnt_not_found + 1
process_error(maskValue1,"optim.mask(()")
optim.print("**** optim.mask failed ****. See return values " ..
"above.\n\n")
optim.target.setcolumnvalue("Default Value")
print(string.format("cnt_not_found --> %d",cnt_not_found))
-- print('value was nil ' .. cntx1)
end
end
-- Function To Trim Space characters
function all_trim(s)
return s:match( "^%s*(.-)%s*$" )
end
function process_error(error, funcname)
print('in function')
colname = optim.target.getcolumnname()
-- optim.mask() error processor will report an error on row
-- failure.
-- error.code : set to 1 to indicate the "drop row condition"
-- error.reason : set to ODPP reason code (6030 for example
-- when LOOKUP row not found)
-- error.message: for example: IOQDP0439E: Lookup data not found
--
-- Other potential errors may return other reason and message values.
--
if type(error) == "table" then
-- print('1st if')
if error.code ~= nil then
print(string.format("%d",error.code) .. " " .. string.format("%d",error.reason))
print('error message --> ' .. error.message)
else
optim.print(string.format("The error code returned by"..
"function %s is nil.\n",funcname))
end
else
optim.print(string.format("Function %s for column %s" ..
" returned the following"..
" error: %s\n", funcname, colname, error))
end
end
Bruce Fischer | Complex Data Privacy Specialist
Information Management
Phone +1(218)252-8726
bfischer@abmartin.com
1999 S. Bascom Ste 700
Campbell, CA 95008
Unstructured Data Masking
Data Privacy/Test data Management - fabrication, optimization, obfuscation