on 06-10-2010 5:21 PM
Hi Experts,
I need help in message mapping convesion for date field
The source date field can have value '2010-06-04T02:09:59.610-07:00' or 2010-06-04T02:09:60.610-07:00
I have to change it to '2010-06-04T02:09:59.000-07:00'. ie, if the seconds are 59.XXX, or 60.XXX, then change to 59.000.
Please let me know the best way to do this
Thanks
Mike
Hi
You can use REGEX in UDF to achieve this. Please use the below code,
Imports : java.util.regex.*;
parameter : strInput
String strOutput = "";
String pattern = "(.*\\.)(.*?)(\\-.*)";
Pattern d = Pattern.compile(pattern);
Matcher m = d.matcher(strInput);
if(m.find())
strOutput = m.group(1) + "000" + m.group(3);
return strOutput;
Regards
Ramg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I did. This is what I did .
Only one parameter in the signature StrInput.
And the function.
I have a source date field which has the format. 2010-06-04T02:09:59.610-07:00
And this needs to be mapped with the date function and then to the target field.
Here, since it is a parameter, I am not able to map the source field to the date function.
And even I tried changing to argument, But still getting array error.
Can you please elaborate step by step how to declare the variables and then use the function by mapping to source and target fields. Appreciate
Function dateConvert, Line 4:
cannot find symbol symbol : variable strInput location: class com.sap.xi.tf._MM_BB_tosyncopy_directory_
matcher m = d.matcher(strInput);
The source code is below
public String dateConvert(String StrInput, Container container) throws StreamTransformationException{
String strOutput = "";
String pattern = "(.*
.)(.?)(
-.)";
Pattern d = Pattern.compile(pattern);
matcher m = d.matcher(strInput);
if(m.find())
strOutput = m.group(1) + "000" + m.group(3);
return strOutput;
And I am using sourcedate->dateConvert->targetDate in mapping
Thanks
Mike
Very helpful. that is resolved now.
Now, it is getting converted for 59.XXX to 59.000 and 60.XXX to 60.000.
But I need to change to 59.000 for both 59.XXX and 60.XXX.
All other seconds such as 58, 57, 56, 32, 34, 45, 47, etc etc need not be converted using the date function.
Please let me know how this can be achieved.
Mike
Again, to make it more clear
The source date field can have any date value such as
2010-06-04T02:09:59.610-07:00 -
This needs to be changed to 2010-06-04T02:09:59.000-07:00
2010-06-04T02:09:60.610-07:00 -- This needs to be changed to 2010-06-04T02:09:59.000-07:00
2010-06-04T02:09:60.000-07:00 -- This needs to be changed to 2010-06-04T02:09:59.000-07:00
2010-06-04T02:09:59.000-07:00 - This need not be changed
2010-06-04T02:09:58.610-07:00 -- This need not be changed
2010-06-04T02:09:57.610-07:00 etc etc - These need not be changed.
The only change using date function is for the first two dates, in which 59.XXX and 60.XXX need to be replaced with 59.000
Using the above date function, all the seconds 59.XXX, 58.XXX, 60.XXX, etc etc,,, are converted to 59.000, 58.000 and 60.000
I dont need this as per the requirement. So looks like the UDF needs to be altered a little to accomodate my requirement.
Please help me.
Thanks
Mike
> The only change using date function is for the first two dates, in which 59.XXX and 60.XXX need to be replaced with 59.000
If you want to replace the values only for 59.xxx and 60.xxx with 59.000 then use this simple udf..
Just pass one input argument 'a' to udf.
String str4 = "";
String str1 = a.substring(0, 17);
String str2 = a.substring(17, 19);
String str3 = a.substring(23, 29);
if(str2.equals("59") || str2.equals("60"))
{
str4 = str1 + "59.000" + str3;
return str4;
}
return a;
As per your requirement use the code which i sugessted with a simple change...
String strOutput = "";
String pattern = "(.*\\.)(.*?)(\\-.*)";
Pattern d = Pattern.compile(pattern);
Matcher m = d.matcher(strInput);
// included repalce all to change 60 to 59.....
if(m.find())
strOutput = m.group(1).replaceAll(":60.", ":59.") + "000"+m.group(3);
return strOutput;
Regards
Ramg
Try the below code.. hope it will resolve ur issue. I have modified a bit!!
String strOutput = "";
String pattern = "(.*\\:)(.*)(\\-.*)";
Pattern d = Pattern.compile(pattern);
Matcher m = d.matcher(strInput);
if(m.find()) {
if(m.group(2).startsWith("59") || m.group(2).startsWith("60") )
strOutput = m.group(1) + "59.000" + m.group(3);
else
strOutput = strInput;
}
return strOutput;
Regards
Ramg
you may have to write a UDF with the Date Class type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
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.