Monday, March 25, 2013

The odiRef.getObjectName() function


Many a times it happens that a column value in a table (source or target) needs to be looked up in another table which is not present in the interface as a source. And there is no way you can join it with your source table. So how do we dynamically pull a record using a select query on the target or say, filters ?

Enter the odiRef.getObjectName() function
This function returns the object name, in our case, the table name that we need to dynamically pull data from.
Example:
Suppose you have a table called LOOKUP_TAB (KEY|VALUE format) from which you need to pull a record and insert it in a target column
In the mapping, you can write a query directly as

(select "value" from <%=odiRef.getObjectName( "L" ,"LOOKUP_TAB","D")%> where "key"='the_key')
Make sure you put this query in braces

At runtime, the schema name is automatically prefixed to the table, now, which schema will it take ?
Answer is the staging schema, or if 'staging schema different from target' is unchecked, it becomes the target schema.
This function comes in very handy for lookups ... you can also hard-code the schema and table name while writing the query like this (select "value" from Staging_schema."LOOKUP_TAB" where "key"='the_key')

But everytime the staging schema name changes, you will have to edit the interface hence odiRef.getObjectName() is a good way to do that.


No comments: