cancel
Showing results for 
Search instead for 
Did you mean: 

Udf Regarding Date Validation

Former Member
0 Kudos

Hi,

Actually I had written an UDF ,the situtaion is the date comes from my source system is in between july to december then my year must be incremented by 1 and need to display in target or else same year must be displayed.

Example: 25-09-2012    2013

               25-02-2012     2012

Well For this I had wriiten an Udf

public void date(String[] var2, ResultList result, Container container) throws

     int y=Integer.parseInt(var2[0]);

          int m=Integer.parseInt(var2[1]);

          Calendar c=Calendar.getInstance();

          c.set(y,m,1);

          int month=c.get(Calendar.MONTH);

          int year=c.get(Calendar.YEAR);

          java.text.SimpleDateFormat dformat = new java.text.SimpleDateFormat("ddMMyyyy");

          java.util.Date date = new java.util.Date();

//          result.addValue(var2[year]);

//          System.out.println(var2);

if (month >= 5 && month <= 11)

          {

            year = c.get(Calendar.YEAR);

            year++;

          //  System.out.println(year);

          result.addValue(var2[year]);

          }

//          else{

//          result.addValue(var2[year]);

//          }

My issue is When I was passing the date

Exception:[java.lang.ArrayIndexOutOfBoundsException: 1] in class com.sap.xi.tf._MM_EMP_ method date[[Ljava.lang.String;@5c74be38, com.sap.aii.mappingtool.tf7.rt.ResultListImpl@74747df3, com.sap.aii.mappingtool.tf7.rt.Context@bf91840]

What need to do to send an date as an argument.

Thanks & Regards,

Jyothi Vure

Accepted Solutions (0)

Answers (5)

Answers (5)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Lakshmi Naik,

                   

               Could you please try this UDF of type value

public static String getYear(String date,Container container) throws StreamTransformationException
{

     java.text.Format formatter;
     formatter = new java.text.SimpleDateFormat("dd-MM-yyyy");
     java.util.Date d;
     try{

            d= (java.util.Date)formatter.parseObject(date);
     }
     catch(java.text.ParseException e)
     {    
            throw new com.sap.aii.mapping.api.StreamTransformationException("DATE field in not in correct format");
     }
     java.util.Calendar cal = java.util.Calendar.getInstance();
     cal.setTime(d);
     int month = cal.get(java.util.Calendar.MONTH);
     int year=cal.get(java.util.Calendar.YEAR);
     if(month>=7 && month<=12)
     {
            year++;
     }
     return ""+year;
}

Regards

Anupam

Former Member
0 Kudos

Hi Jyothi,

     Firstly, Make sure you have mentioned Single Values, in the UDF properties. You can do this when you create the UDF, or if you have already written the code inside your UDF, you can edit it and change the property.

     Secondly, make sure you have data available in the input.

Regards,

Lakshmi Naik

gagandeep_batra
Active Contributor
0 Kudos

Hi Naga,

You can achieve your requirement without udf using date transform function also..

i try below that might help you.........

i tool empno as input for date...

Regards

Gagan

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Are you sending single date value field or multiple values in queue? If it is single field just declare execution type single value and type argument as something like this...

Former Member
0 Kudos

Hello Jyothi Vure,

When creating a UDF, you can select the execution type. This defines whether you get the whole queue as an input, only the values between two context changes, or the single values.

In your case I would select the option "single values".

By that you will get a String field instead of a String array as an input. The function will be called for every value in the queue separately.

Actually var2[0] reads the initial context change. It could also work with your approach if you use var2[1] which should be the first actual value in your queue.

Regards,

Jürgen