cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping conversion help needed for date

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

This function I copied and giving me some syntax errors.

Can you help me what this does?

Thanks

Mike

Former Member
0 Kudos

Anybody can help me on writing a conversion for this ..Thanks and appreciate

Former Member
0 Kudos

Hi

the UDF is ok. Did you put the library java.util.regex.*; on the Imports box.?

Former Member
0 Kudos

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

Former Member
0 Kudos

Can you put the syntax error?.

the UDF is very simple. it souldn't have problem.

Former Member
0 Kudos

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

Former Member
0 Kudos

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;

Former Member
0 Kudos

And one more thing

It should be changed only for 59 or 60. All other seconds are not changed..

Thanks

Former Member
0 Kudos

cannot find symbol symbol : variable strInput location: 
class com.sap.xi.tf._MM_BB_tosyncopy_directory_
matcher m = d.matcher(strInput);

The variable in java is case-sensitive.

Change StrInput by strInput

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Anybody?

Former Member
0 Kudos

> 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;

Former Member
0 Kudos

Hi Mike,

check if the seconds value

if it is equals to 59 or 60 then return (substring(0,19)000sunstring(23,29))

else (means not 59 and not 60) return same value.

Regards

Ramesh

Former Member
0 Kudos

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

Former Member
0 Kudos

Thanks Ram. But there is a catch in this.

This will replace even 58.892 seconds to 58.000 seconds which is wrong.

I need to replace only these two

60.890 to 59.000

and 59.908 to 59.000

please let me know.

Thanks for the help again

Former Member
0 Kudos

If you are sure about these only values need to be change, the nyou can use replece all function alone no need for REGEX

Parameter: strInput



  String[] s =  { "60.890", "59.908" };
             
             for(int i =0; i < s.length; i++){
            	 
            	 strInput = strInput.replaceAll( s<i>,"59.000");
             }

return strInput;

Regards

Ramg

Former Member
0 Kudos

Thanks for the reply.

60.890 to 59.000

and 59.908 to 59.000 .. this is just an example.

My requirement is to change values in dates for seconds starting with 60.XXX and 59.XXX to 59.000.

the UDF you gave changes for 58.XXX and 57.XXX and 56.XXX etc etc....

Hope it is clear now.

Former Member
0 Kudos

Have you tried the UDF which I suggested..

Former Member
0 Kudos

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

Former Member
0 Kudos

Thx Ram. Great work!!! you guys Rock and also thanks to sarvesh for his udf design

thanks

mike

Answers (1)

Answers (1)

Former Member
0 Kudos

you may have to write a UDF with the Date Class type.