Skip to content

Instantly share code, notes, and snippets.

@viksingh
Forked from SriniBlog/DBLookupUDF.java
Created February 9, 2018 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viksingh/31adbcf08e83a4309aefea0e123a6654 to your computer and use it in GitHub Desktop.
Save viksingh/31adbcf08e83a4309aefea0e123a6654 to your computer and use it in GitHub Desktop.
DB Lookup from Standard SAP PI UDF to execute select query and get the records. This UDF can be used to call JDBC channel and execute the select query to fetch the records from database.
public String getDBLookupUDF(Container container) throws StreamTransformationException{
GlobalContainer globalContainer;
MappingTrace trace;
java.util.Map map;
trace = container.getTrace();
globalContainer = container.getGlobalContainer();
map = globalContainer.getTransformationParameters();
//Variables Used
String Query = " ";
Channel channel = null;
DataBaseAccessor accessor = null;
DataBaseResult resultSet = null;
Query = "Select FIELD1, FIELD2 from PIDB_CUSTOMTABLE";
String returnValue = "";
try{
trace.addInfo("Query: " + Query);
//Make sure the PI DB parameters are properly configured in the channel
channel = LookupService.getChannel( "BS_PI_SYSTEM","CC_PI_DB_JDBC_RECEIVER");
accessor = LookupService.getDataBaseAccessor(channel);
resultSet = accessor.execute(Query);
for(Iterator rows = resultSet.getRows();rows.hasNext();)
{
java.util.Map rowMap = (java.util.Map) rows.next();
returnValue = returnValue + "FIELD1: " + (String) rowMap.get("FIELD1") + "\r\n";
returnValue = returnValue + "FIELD2: " + (String) rowMap.get("FIELD2") + "\r\n";
}
}catch(Exception ee){
returnValue = "";
}
return returnValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment