Tuesday, June 18, 2013

A Quick look at Routines in Datastage

Datasatge has 2 types of routines ,Below are the 2 types.

1.Before/After Subroutine.
2.Transformer routines/Functions.

Before/After Subroutines :

 These are built-in routines.which can be called in before or after subroutines. Below is the list of the same.

1.DSSendMail :Used to Send mail using Local send mail program.
2.DSWaitForFile : This routine is called to suspend a job until a named job either exists, or does not exist.
3.DSReport :Used to Generate Job Execution Report.
4.ExecDos: This routine executes a command via an MS-DOS shell. The command executed is specified in the routine's input argument.
5.ExecDOSSilent. As ExecDOS, but does not write the command line to the job log.
6. ExecTCL. This routine executes a command via an Info Sphere Information Server engine shell. The command executed is specified in the routine's input argument.
7.ExecSH:This routine executes a command via a UNIX Korn shell.
8.ExecSHSilent:As ExecSH, but does not write the command line to the job log.

Transformer Routines:

Transformer Routines are custom developed functions, as you all know even DS has some limitations corresponding to inbuilt functions(TRIM,PadString,.etc), like in DS version 8.1 we don’t have any function to return ASCII value of a character, Now from  8.5 they have introduced seq() function for above mentioned scenario.

            These Custom routines are developed in C++ Writing a routine in CPP and linking it to our datastage project is really simple task as follows,

v      Write CPP code 
v      Compiling with the required flags.
v      Put the output file in a shared dir.
v      Link it in the datastage.
v      Use it in a transformer like other functions.

Below is the Sample C++ Code :

#include <string>
#include <iostream.h>

using namespace std;
int addNumber(int a,int b)
{
     return a+b;
}

Note :We need to make sure ,our code should not contain main() function as it is not required.

Compiling with the required flags:

 Get the values of below 2 Environment variables.

1.APT_COMPILER
2.APT_COMPILER_OPT

Use as below to compile the code from unix prompt.

APT_COMPILER<Space> APT_COMPILER_OPT<space>File_Name(with Cpp Code).

v      Once you run the above command it will create object file at same path with .o as extension. Now login to DS Designer at routines folder do a right click and select new Parallel routine.
v      In new opened window put required details like Name and Select type as External Function external subroutine name as the function name we need to access, . Select proper return type and also provide the complete path of the .o file.
v      Now Select Arguments tab and add required arguments ,select proper Data types for arguments.
v      Now you are all done. Go to your job open any transformer and in any expression just select the ellipsis button [...] you will get the list and there select routine. There you will get our new routine listed.

But remember few points while writing the function i.e the cpp code,

v      Data stage cannot accept return type as string, so we need to design our function to return char* instead.

v      The same applies to input arguments too. So our function can accept char* only not string. But later in the cpp code we can change it to string.

0 comments:

 

Datastage Doctrina Copyright © 2011 -- Template created by O Pregador -- Powered by Blogger

Receive all updates, tips and tricks via Facebook. Just Click the Like Button Below