Calling C executable from Java Transform
We are going to do is, to call C++ Executable from Informatica, using Passive Java Transform and capture the output of the C++ using Java and write the result to corresponding target column.
There was a requirement to call a C++ executable binary from Informatica. The C++ program basically takes one input file name in the command line and calculates "value at risk" (VAR) values based on all the financial transaction records present in the given input file and outputs the final VAR value. This value along with other source data needs to be populated in the Target.
Here is the test environment setup.
- We have a source flat-file having 4 input columns out of which one column TCN bears the partial-filename which needs to be passed as argument to C++ executable.
- The C++ executable recieves the filename as arguments calculates the VAR for the corresponding file and outputs the VAR value.
- We capture the VAR value using the same Informatica Java Transform that calls the C++ executable and populate the corresponding target field.
Sample Source and Target Record.
Source:-
ID,TCN,UNIT,PV_TOTAL
1,009115,USB,23.98
2,009116,USB,22.21
3,009117,USB,22.02
Target:-
ID,TCN,UNIT,PV_TOTAL,VAR
1,009115,USB,23.98,1.03
2,009116,USB,22.21,1.50
3,009117,USB,22.02,1.22
Please find the Informatica Mapping and the Java Transformation properties below. Note the Java Transformation used is a Passive one.
Find the corresponding Java Code.
try
{
String CPP_Exec = "C:\\Users\\Saurav\\My Documents\\calc_var.exe";
String ip_fname = InputTCN;
String filename = CPP_Exec + " " + ip_fname;
String op_VAR;
Process p = Runtime.getRuntime().exec(filename);
BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream()));
while((op_VAR = input.readLine()) != null)
{
System.out.println(op_VAR);
VAR= Integer.parseInt(op_VAR.trim());
}
input.close();
}
catch(Exception e)
{
e.printStackTrace();
}
Finally we are done. Calling a C++ executable from Informatica using Java Transformation.