on 12-05-2012 11:53 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.