Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182455
Active Contributor

Dear Users,

Here are some UDFs that might me helpful in your business scenarios.

1. UDF for Date Conversion :

          This UDF is used to convert the given date into required time zone and date format, it takes actual date as first input, required time zone as second input and format as third input which is validated based upon the second input. it validates the format of the both inputs and if true, returns actual date otherwise throws an exception. To use this, we need to import the UTIL and TEXT pages.

       

Code :

                       DateFormat df1 =new SimpleDateFormat(DateFormat);

           

                       df1.setTimeZone(TimeZone.getDefault());

           

                        DateFormat df2 = new SimpleDateFormat(DateFormat);

                       df2.setTimeZone(TimeZone.getTimeZone(ReqTimeZone));

                       String target = " ";

                       try

                      {

 

                       Date d = df1.parse(CurrentDate);

   

                      target = df2.format(d);

                      }

                     catch( Exception e)

                    {}

                    Return target;

  Input :


                   

Output :


                      




2. Combining Array Elements:


             This is Queue type UDF.It takes a string and delimiter value as arrays and combines all the array elements with a delimiter and sends as single value.


                     


Code :

                  String res="",delimiter="";

                  res = StrArray[0]

                  delimiter = Separator[0];

                  for(int i=1;i<strArray.length;i++)

                  res = res+delimiter+StrArray[i];

                  result.addValue(res);


Input and Output :


                 


3 . Checking Mandatory Field

                      This is a simple type UDF. It takes a single value and checks if the node exists or not. If the node exists, it returns same value, Otherwise it throws an exception.


                


Code :

                  if (!var1.equals("")&&(var1.length()>0))

                  return var1;

                  else

                  throw new RuntimeException("This field is mandatory : value is missing");


                 

Input   :


                


Output     :



                 


4. Remove Domain Name


               This is simple type UDF. It takes a mail id as input and removes the domain name.


               


Code :


                  String Pattern = "@xyz.com";

                  String StrippedString = str.replaceAll(pattern,"");

                  return strippedstring;

             

                                    Input :                                                                            Output                                                                                                        


                 

5. Checks for the end of the List

                      This is Queue type UDF. It takes a set of values as input and sends all the values to output until the end of the list field appears for the first time.

                  

Code :

                 int i = 0;

           

                 int j = 0;

                 // check for the presence of EOD

                 while (!var1[i].equals("EOD"))

           

                  {

           

                  // add the values till EOD is not present

                  result.addvalue(var1[i]);

                  i=i+1;

                  }

                                         Input :                                                             Output

                   

7 Comments
Labels in this area