This is my first post on SCN. We have few threads on File Lookup but i face few challenges when i was going through it. Thus i thought to create a simple step by step document for the same.
PI has two standard types of lookup available in ESR (i.e. JDBC and RFC lookup). But we can achieve two more types of lookup in PI to fulfill our needs, those are File and SOAP lookup.
File Lookup is done when we want to map a value against an incoming payload value. In this scenario file may be maintained on some other server. We do a lookup to read the value against incoming field and map that value to the target payload.
To achieve this functionality we need to write a small UDF, which will leverage our requirement.
Step1: Create a UDF and import two packages as mentioned in screenshot.
java.net.URL
java.net.URLConnection
Step2: Copy paste below code in your PDF
(You need to replace username, password, server,path directory and filename in below code accordingly.)
String custId = "";
try{
URL url =new URL("ftp://<UserName>:<Password>@<IPAddress>/ <pathtodirectory>/ <filename.txt>");
URLConnection con = url.openConnection();
InputStream lookupStream = con.getInputStream();
InputStreamReader reader = new InputStreamReader(lookupStream);
BufferedReader buffer = new BufferedReader(reader);
String read;
while((read=buffer.readLine()) != null){
String temp = read.substring(0,key.length());
if(key.equals(temp)){
custId = read.substring(key.length()+1,read.length());
if ( read.substring(key.length()+1,read.length()) != "00"){
int num = Integer.parseInt( read.substring(key.length()+1,read.length()));
num = num+2;
custId = Integer.toString(num);
}
}
}
- buffer.close();
} catch (Exception e){
return e.toString();
}
return custId;
Step3: Create a file on external server which has input and output separated by "=".
Step4: We can verify our code through Display queue in message monitor's tab by giving input in the source field.
Below screenshot shows if we are getting output as expected.
This is the simplest way of doing a file lookup in SAP PI through UDF.
Note: File Lookup is not encouraged by SAP.
I hope you all like this post.!!!!!!