Logo DWBI.org Login / Sign Up
Sign Up
Have Login?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Login
New Account?
Recovery
Go to Login
By continuing you indicate that you agree to Terms of Service and Privacy Policy of the site.
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.

PrimeChess

PrimeChess.org

PrimeChess.org makes elite chess training accessible and affordable for everyone. For the past 6 years, we have offered free chess camps for kids in Singapore and India, and during that time, we also observed many average-rated coaches charging far too much for their services.

To change that, we assembled a team of top-rated coaches including International Masters (IM) or coaches with multiple IM or GM norms, to provide online classes starting from $50 per month (8 classes each month + 4 tournaments)

This affordability is only possible if we get more students. This is why it will be very helpful if you could please pass-on this message to others.

Exclucively For Indian Residents: 
Basic - ₹1500
Intermediate- ₹2000
Advanced - ₹2500

Top 10 Articles