cancel
Showing results for 
Search instead for 
Did you mean: 

Message Mapping - unique ID and consecutive number

Former Member
0 Kudos

Hi experts,

I need to build a graphical message mapping and an ABAP mapping on my SAP PI 7.11 system.

I need to fill a field with something unique (max 14 positions). Initially, I suggested to concatenate system date (yyyymmdd) and system time (hhmmss), but when we change between summer and winter time, it could be that we have exactly the same numbers. that' why I need something else.

Second, I need to fill several segments containing a field where I need to fill in a counter value. How can I manage that?

Thanks a lot

Dimitri

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

> I need to fill a field with something unique (max 14 positions). Initially, I suggested to concatenate system date (yyyymmdd) and system time (hhmmss), but when we change between summer and winter time, it could be that we have exactly the same numbers. that' why I need something else.

Why don't you go for UTC time, because UTC does not change with a change of seasons. And also just to make it more secure, use the mili seconds in your time pattern e.g. hhmmss.SSS, But this will exceed the limit of 14 positions. Any way still you can go ahead with UTC time in my opinion.

Regards,

Sarvesh

Former Member
0 Kudos

Hi Sarvesh,

The miliseconds look fine for me... I think yymmddhhmmssSSS should be unique...

I didn't know I could add milliseconds in a message mapping. This is easier than adding Java functions I think.

Thanks a lot.

Dimitri

Former Member
0 Kudos

In ABAP, there is a function (TZON_FIXDST_FROM_VARIABLE) available to check if we are in summer or winter time.

How can I do this in a graphical message mapping?

Thanks a lot

Dimitri

Former Member
0 Kudos

> The miliseconds look fine for me... I think yymmddhhmmssSSS should be unique...

> I didn't know I could add milliseconds in a message mapping. This is easier than adding Java functions I think.

If you are going to use CurrentDate in XI then use the std function "CurrentDate" and douple click the current date input the format "yyyy-MM-dd HH:mm:ss.SSS". But if you are taking your date from some other place then simply use the std function "DateTrans" and in the source format define your incoming date format and in the target format define "yyyy-MM-dd HH:mm:ss.SSS" and then map this to the above UDF to convert the time into UTC.

Regards,

Sarvesh

Answers (3)

Answers (3)

Former Member
0 Kudos

In ABAP, there is a function (TZON_FIXDST_FROM_VARIABLE) available to check if we are in summer or winter time.

How can I do this in a graphical message mapping?

Thanks a lot

Dimitri

Former Member
0 Kudos

In Graphical mapping you have to use UDF to convert it into UTC as shown below.

Note: You need to pass the date into below udf in "yyyy-MM-dd HH:mm:ss.SSS" format, you have different timestamp format then modify the udf accordingly.

One more thing I am adding 'T' in my output to separate date & time, so if you don't like to add 'T' then just remove from the udf.

UDF Code:

Imports: java.util.Date;java.util.TimeZone;java.text.SimpleDateFormat;java.text.DateFormat;

String strDate =a;
Date date=null;
 
SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
 
try{
 
String dt = strDate; 
date = sdfSource.parse(dt);

String timeZoneId = "UTC";
  
Calendar mbCal = new GregorianCalendar(TimeZone.getTimeZone(timeZoneId));
mbCal.setTimeInMillis(date.getTime());
  
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, mbCal.get(Calendar.YEAR));
cal.set(Calendar.MONTH, mbCal.get(Calendar.MONTH));
cal.set(Calendar.DAY_OF_MONTH, mbCal.get(Calendar.DAY_OF_MONTH));
cal.set(Calendar.HOUR_OF_DAY, mbCal.get(Calendar.HOUR_OF_DAY));
cal.set(Calendar.MINUTE, mbCal.get(Calendar.MINUTE));
cal.set(Calendar.SECOND, mbCal.get(Calendar.SECOND));
cal.set(Calendar.MILLISECOND, mbCal.get(Calendar.MILLISECOND));
 
Date newdt = cal.getTime();
 
SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
strDate = sdfDestination.format(newdt);
 
}
 
catch (Exception e)
{
String exception = e.toString();

return exception;
}
 
return strDate;

former_member200962
Active Contributor
0 Kudos
I need to fill several segments containing a field where I need to fill in a counter value.

Use Index function for this....i have screenshots attached on SDN --> WIKI --> Process Integration --> Attachment --> the first two should give you an idea ... do not use Counter function....it fails when context changes.

Regards,

Abhishek.

Former Member
0 Kudos

Hi,

Why not using JAVA hashcode type methods (either native .HashCode() method, but nut sure for its uniqueness, or more advanced algorithms, like SHA-1 etc) or a GUID factory class (SAP has one, can't remember package name) ...

Try googling hashcode and JAVA you'll find a lot of examples

Rgds

Chris