CALLING THE VALIDATION FUNCTION INTO VALIDATION TRANSFORMATION
This Blog explains how to call a Validation function inside a Validation Transformation.
Source table: EMP
Description:
- we need to check for the Probation period based on the JOIN_DATE, Probation period is 6 months from JOIN_DATE to Current month, and if Probation period is completed for 6 months this can be moved to a Probation completed table else it needs to be moved to Probation_not_completed table.
- In this scenario we are validating the data from the database table by using Validation function instead of Column validation in Validation rules.
Use Case:
- Validation function is used to Filter or Replace the source data set by writing script in Validation function under Custom function tab and call the same function in Validation transformation and produce desired output data set.
STEP:1
Creating a Validation function which is used to validate the Probation Period of each Employee record.
Let's go to custom function tab, and we can see validation function inside it.
Validation functions:
Imported from Information Steward:
These functions were created in Information Steward and imported; they are not editable in Data services.
Locally Created:
These functions are reusable, Custom and Validation functions were created in Data services.
- Right click on Validation function, then New and one popup window will be displaying with name Custom function.
- Enter the Name i.e., Name of the function 'VF_PROBATION_PERIOD_CHECK ' and click on Next button
After clicking Next button one popup window will be displaying with Smart Editor, and by using Smart Editor we can create our own functions by writing script functions in SAP Data services, and we can edit and delete Custom functions from Custom functions tab under the Object library.
- Need to be creating Parameter named as 'p_joindate', and by using parameter we can capture the required data.
- Right click on parameter and click on insert and give name of the parameter and required Data type and input parameter type.
Next create a local variable named as 'lv_month_count' and here local variable is used to check the input date that the probation period is completed or not.
Next Need to write script by using Variable and Parameter.
#$p_joindate is used to capture the JOIN_DATE data
#lv_month_count(variable) is used to check the input date
#Return 1 means will evaluate the input data and if the above condition is satisfied then
Return the data into Probation Completed table.
$lv_month_count =date_diff( $p_joindate ,sysdate( ),'MM');
print($lv_month_count);
if($lv_month_count>=6)
Return 1;
else
Return 0;
STEP 2:
- Next we can create Job, Workflow and Data flow as usual.
- Drag Source table and Valid Transformation into Data flow.
- Double click on validation transformation and go to Add to provide details.
- Give name and select required validation function and pass the parameter and select 'argument' means give Hard coded value or specified field.
STEP 3:
Add a target table in the dataflow and give the connection between Validation Transform and target table and choose the Validation condition as 'PASS'.
Drag the tables and give the connection to the 'Fail' and 'Rule violation' condition.
In the above figure you can see in the highlighted rows in the input, where the date is not having
more than 6 months with current month count.
Output for “Pass” condition:
Output for “Fail” condition:
Output for “Rule Violation” condition:
Summary:
So, in this way by using validation function also we can validate data and transform it based on rules.
















Comments
Post a Comment