Logo DWBI.org Login / Sign Up
Sign Up
Have Login?
Login
New Account?
Recovery
Go to Login
Informatica

Calling C executable from Java Transform

Updated on Sep 30, 2020

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.

  1. 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.
  2. The C++ executable recieves the filename as arguments calculates the VAR for the corresponding file and outputs the VAR value.
  3. 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.

Mapping to call C exec from Java
Mapping to call C exec from Java
Java Ports Tab
Java Ports Tab
Java Code- Import Packages
Java Code- Import Packages
Java Code to call C++ executable
Java Code to call C++ executable

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.