cancel
Showing results for 
Search instead for 
Did you mean: 

Questions according to date format in message mapping

stefan_grube
Active Contributor
0 Kudos

Hi,

I need following date formats filled by the graphical mapping tool:

1. I want the current date in format 2007-10-01T11:57:45.147562Z

2. The local date 2007-10-01T11:57:45.147562Z time zone ETC should be changed to UTC

Could anyone provide a user defined function (UDF) for this?

Best regards

Stefan

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Stefan,

I have recently made this User Defined Function, which calls a UTCLocalConverter class

UTCToLocal

Imports:com.sap.aii.mapping.api.AbstractTrace;nl.gasunie.pi.mapping.utils.date.UTCLocalConverter;com.sap.aii.mapping.api.StreamTransformationException;

//write your code here

String localDateTime = null;

try {

UTCLocalConverter converter = new UTCLocalConverter();

localDateTime = converter.getLocalDateTime(utcDateTime, dateFormat);

} catch (Exception e) {

AbstractTrace trace =container.getTrace();

trace.addWarning(e.getMessage());

}

return localDateTime;

Class UTCLocalConverter

package nl.gasunie.pi.mapping.utils.date;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import java.util.TimeZone;

/**

  • @author ex23257

*/

public class UTCLocalConverter {

private String utcDateTime;

private String localDateTime;

private String dateTimeFormat;

private int calculateOffSet() {

Calendar cal = Calendar.getInstance();

TimeZone timeZone = cal.getTimeZone();

int offSet = timeZone.getRawOffset();

return offSet;

}

private void setLocalDateString(String utcDateTime, String dateTimeFormat)

throws Exception {

try {

SimpleDateFormat dataFormat = new SimpleDateFormat(dateTimeFormat);

Date utcDate;

utcDate = dataFormat.parse(utcDateTime);

Calendar cal = Calendar.getInstance();

cal.setTime(utcDate);

cal.setTimeInMillis(cal.getTimeInMillis() + calculateOffSet());

Date localDate = cal.getTime();

this.localDateTime = dataFormat.format(localDate);

} catch (Exception e) {

throw new Exception(

"Error in Class UTCLocalConverter.setLocalDateString: "

+ e.getMessage());

}

}

/** Converts a UTC date time string to local time.

  • example:

  • UTCLocalConverter converter = new UTCLocalConter();

  • String localDateTime = converter.getLocalDateTime( "2007-12-31 12:46:69","yyyyMMdd HH:mm:ss" );

*/

public String getLocalDateTime(String utcDateTime, String dateTimeFormat)

throws Exception {

try {

setLocalDateString(utcDateTime, dateTimeFormat);

} catch (Exception e) {

throw new Exception(e.getMessage());

}

return localDateTime;

}

}

Maybe this help you.

Regards Sander

justin_santhanam
Active Contributor
0 Kudos

Stefan,

What is your input date format? Could you please give us the sample input you are getting inside UDF.

raj.

stefan_grube
Active Contributor
0 Kudos

For the first point, there is no input format at all, as the mapping tool should create the current date.

For the second point, it is:

2007-10-01T11:57:45.147562Z

Regards

Stefan

Former Member
0 Kudos

Hi,

Check below links for UDF's

http://flickr.com/photos/8764045@N06/

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/be05e290-0201-0010-e997-b6e...

Example 1

http://www.flickr.com/photo_zoom.gne?id=544183191&size=o

http://www.flickr.com/photo_zoom.gne?id=544183195&size=o

http://www.flickr.com/photo_zoom.gne?id=544183225&size=o

http://www.flickr.com/photo_zoom.gne?id=544183233&size=o

Example 2

http://www.flickr.com/photo_zoom.gne?id=545133789&size=o

http://www.flickr.com/photo_zoom.gne?id=545133791&size=o

http://www.flickr.com/photo_zoom.gne?id=545133801&size=o

http://www.flickr.com/photo_zoom.gne?id=545133807&size=o

http://www.flickr.com/photo_zoom.gne?id=545133811&size=o

http://www.flickr.com/photo_zoom.gne?id=545138911&size=o

http://www.flickr.com/photo_zoom.gne?id=545138913&size=o

http://www.flickr.com/photo_zoom.gne?id=545138915&size=o

http://www.flickr.com/photo_zoom.gne?id=545138917&size=o

http://www.flickr.com/photo_zoom.gne?id=545138947&size=o

http://www.flickr.com/photo_zoom.gne?id=545138951&size=o

http://www.flickr.com/photo_zoom.gne?id=545005958&size=o

Example 3

http://www.flickr.com/photo_zoom.gne?id=549186611&size=o

http://www.flickr.com/photo_zoom.gne?id=549186651&size=o

http://java.sun.com/j2se/1.5.0/docs/api/

/people/krishna.moorthyp/blog/2006/07/29/documentation-html-editor-in-xi

/people/sap.user72/blog/2006/02/06/xi-mapping-tool-exports

http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm

http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm

/people/stefan.grube/blog/2005/12/30/test-user-defined-functions-for-the-xi-graphical-mapping-tool-in-developer-studio

http://help.sap.com/bp_bpmv130/Documentation/Operation/MappingXI30.pdf

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d046c490-0201-0010-84b6-9df523cb...

Regards,

Phani