Pitfalls and Opportunities
Data Services functions work in pretty much the same way as most programming language functions do. They take input variables, do some work, and then return a value. Functions in Data Services can even return multiple values, which is a necessary feature since it has no array or hashtable structures found in your purer “functions only return one value” languages, like JAVA, C++, or Python.
In most function-or object-based programming languages, variables that are local to the function are reinitialized (or force the coder to reinitialize) for every instance of the function. These are called dynamic variables. Many languages allow an explicit override of this behavior. But, in Data Services, these internal variables keep their state between instances by default, making them always static.
Example
In this example, a simple row generation ( 3 rows) is hooked to a query transform with the following custom function:
Here’s the mapping with the function:
Our results:
The first time the function is called, our variable is null, so the conditional in the function (returning 1) is not called. The variable is then set, and 0 is returned. On subsequent calls, the interpreter remembers the value of our variable, and triggers the conditional statement to pass.
Therefore, in normal circumstances, be sure to explicitly re-initialize local variables at the top of the function.
This is a good practice anyway, and instances like this remind you why.
To download full PDF and Continue Reading…
About Britton Gray
Britton Gray has been working in software development and Business Intelligence for the past fourteen years, and has been working with SAP BusinessObjects reporting, analytics, and information management tools for six years. He is certifies in Data Integrator and Web Intelligence, and enjoys developing end-to-end BI solutions that enable customers to gain new insights into their data.
Add comment