USING USER DEFINED FUCTIONS


SAP PI Interview Questions and SAP PI Tutorials

SAP PI Interview Questions and SAP PI Tutorials

USING USER DEFINED FUCTIONS

SAP PI Interview Questions and SAP PI Tutorials

SAP PI Interview Questions and SAP PI Tutorials

I have seen people waiting for long on the forum with no replies if they post out a query related to user defined functions . This blog is just the first step toward helping out those who face problems writing java code for user defined functions .
User defined Functions are written to add in the functionality in order to customize the graphical mapping programmes as per the requirement .Therefore the java code provided by me here can only be near to the requirement or can be sufficient enough to show a ray of light in the dark on how to go about it.
I will divide this blog in parts starting from general requirement to specific requirement User defined Functions.
Requirement 1 :  Many a times we face a requirement like if we are getting in a field value as blank in the source structure then we don’t need to move this to the target node and pass on the rest values in the same field .
User Defined Function for this:
Type : Context

Input Parameters  :  Queue for the input field whose value needs to be checked. For(int iCount=0;iCount<inputField.length;iCount++)
{
If(inputField.length()>0)
{
Result.addValue(inputField[iCount]);
}
}

Requirement 2 :  Many a times we face a requirement like we are getting in a floating point value in a field of an IDoc segment like 12.327- .Here if we see that the negative sign is after the floating point value and if we try to insert this into a database then it will throw out an error.Before inserting the value we need to covert the incoming value in the form -12.327.
User Defined Function for this:
Type : Context

Input Parameters  :  Queue for the input field whose value needs to be checked. for(int iCount =0; iCount <Float.length; iCount ++)
{
if(Float[iCount].endsWith(“-“))
{
result.addValue(“-“+Float[iCount].substring(0,Float[iCount].length()-1));
}
else
{
result.addValue(Float[iCount]);
}
}

Requirement 3 :  Sometimes we get in a long field value in the source structure say 500 characters and in the target structure we need to break  up this data in a group of  70 chars each and map it to the target field.
User Defined Function for this:
Type : Context

Input Parameters  :  Queue for the input field whose value needs to be checked.
String str = SourceString[0];
while(str.length()>70)
{
result.addValue(str.substring(0,70));
str=str.substring(71,str.length());
}
result.addValue(str);

SAP PI Interview Questions and SAP PI Tutorials

SAP PI Interview Questions and SAP PI Tutorials

Share this:
Share this page via Email Share this page via Stumble Upon Share this page via Digg this Share this page via Facebook Share this page via Twitter
www.pdf24.org    Send article as PDF   
This entry was posted in Step by Step Guides and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *