Quantcast
Channel: Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 741

USEFUL UDFS - 2

$
0
0


Dear SCN Users,

 

In continuation to http://scn.sap.com/community/pi-and-soa-middleware/blog/2015/03/16/useful-udfs, adding some more UDFs.

 

11. UDF tostrip Left Zero

 

q.jpg

    

Code:

 

   if(str == null)

    {

            return null;

    }

   int i;

   char[] chars = str.toCharArray();

   for(i = 0; i < str.length(); i++)

   {

                  if(chars[i] != '0')

            {

              break;

     }

   }

   return(i == 0) ? str : str.substring(i);

 

Output:

 

q.jpg

12. UDF to add Values in Queue/Context:

 

  q.jpg

Code:

 

String output = "";

double total = 0.0;

for(int i=0;i<var1.length;i++)

total=total+Double.valueOf(var1[i].trim()).doubleValue();

output=total+"";

result.addValue(output);

 

Output:

 

q.jpg

 

13. UDF to remove duplicate/repeated entries in Context/queue

 

q.jpg

 

Code:

 

int i;

String val = new String();

for ( i = 0 ; i < input.length ; i++)

{

  if ( input[i].equals(ResultList.CC))

     {

         result.addValue(ResultList.CC);

         val = "";

         continue;

      }

   if ( val.equals(input[i] ));

  else

      {

         result.addValue(input[i]);

         val = input[i]; 

       }

}

 

Output:

q.jpg

 

NOTE: Sort the values before inputing the UDF

 

14. UDF to make 2 digits after the decimal point

 

After the decimal point if there is one digit in the input value, then this udf is used to add zero at the end to make 2 digits after the decimal. Example: if the input values is 1.1, then this udf used to display 1.10.

 

q.jpg

 

Code:

 

int len = value.indexOf(".") ;

int tot_len = value.length();

String result = "";

if (len > -1)

{

            if((tot_len - len) == 2)

            {

                                                result = value.substring(0,len);

                                                String temp1 = value.substring(len,tot_len);

                                                return result + temp1 + "0";

            }

            if((tot_len - len) == 3)

            {

                                      return value ;

            }

  return value ;

}

else

return value   ;

 

Output:

q.jpg

 

15. UDF To change Supress to empty value

 

q.jpg

Code:

 

for (int i=0;i<value.length;i++)

{

if(value[i].equals(ResultList.SUPPRESS))

result.addValue("");

else

result.addValue(value[i]);

}

 

Output:

 

q.jpg

 

Will be adding more UDFs soon.

 

 

 


Viewing all articles
Browse latest Browse all 741

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>