cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple time formats

Former Member
0 Kudos

Hi,

I have 3 source fields

D_373 - for date. we are using yyyy:mm:dd format

D_337- for time

and D_623 for timezone.

we need target like

2016-10-10T06:12:00-06:00

YYYY-MM-DDTHH:MM:SS-TIMEZONE

issue is that they have multiple senders and they can send time as hhmm, hhmmss,hhmmssmm,hhmmssmmss.

We need a logic where when the format is hhmm we will add 00 and will change the format to hh:mm:ss and send it to target

when its hhmmss we will change it to hh:mm:ss

when it is more than hhmmss then we will change it to hh:mm:ss.

so all in all time should always be hh:mm:ss wheather the incoming time format is hhmm or hhmmss or hhmmssmm or hhmmssmmss .

Please suggest.

Accepted Solutions (1)

Accepted Solutions (1)

GauravKant
Contributor
0 Kudos

Hi Sherwin,

You can try my blog UDF for this.

You can do the necessary changes in format and timezone.

Hope it will help.

Regards,

Gaurav

former_member186851
Active Contributor
0 Kudos

Just add for loops in Gauravs UDF

Former Member
0 Kudos

HI Gaurav, Thanks for the reply. I only need help with time format. Date format and Time zone format is solved. I just need to sort this time format issue. Can you please suggest for the time format only?

Thanks

Former Member
0 Kudos

HI Raghuraman,, Can you help me with the UDF if possible? I need to deliver this today.

Thanks

former_member186851
Active Contributor
0 Kudos

Hello Sherwin.

Each partner will have some identifier,

Try to find it,Then we can achieve using normal functionality instead of UDF.

Former Member
0 Kudos

Hi,

We are using EDI 990 and the partners does not have any Identifier. That is why I am not able to do it without UDF.

former_member186851
Active Contributor
0 Kudos
former_member182412
Active Contributor
0 Kudos

Hi Sherwin,

Use below UDF:

Execution Type: Single Values


public String convertTime(String input, Container container) throws StreamTransformationException {

  SimpleDateFormat sdfIn = new SimpleDateFormat();

  SimpleDateFormat sdfOut = new SimpleDateFormat("hh:mm:ss");

  Date date = null;

  int length = input.length();

  try{

  switch (length) {

  case 4:

  sdfIn.applyPattern("hhmm");

  date = sdfIn.parse(input);

  break;

  case 6:

  sdfIn.applyPattern("hhmmss");

  date = sdfIn.parse(input);

  break;

  case 8:

  sdfIn.applyPattern("hhmmssmm");

  date = sdfIn.parse(input);

  break;

  case 10:

  sdfIn.applyPattern("hhmmssmmss");

  date = sdfIn.parse(input);

  break;

  }

  }catch(ParseException pe){

  throw new StreamTransformationException(pe.getMessage());

  }

  return sdfOut.format(date);

  }

Test:

Regards,

Praveen.

Former Member
0 Kudos

Thank you so much Praveen. When I am trying to use this UDF, I am getting syntax errors. I am using below udf.

SimpleDateFormat sdfIn = new SimpleDateFormat(); 

  SimpleDateFormat sdfOut = new SimpleDateFormat("hh:mm:ss"); 

  Date date = null; 

  int length = input.length(); 

  try{ 

  switch (length) { 

  case 4: 

  sdfIn.applyPattern("hhmm"); 

  date = sdfIn.parse(input); 

  break; 

  case 6: 

  sdfIn.applyPattern("hhmmss"); 

  date = sdfIn.parse(input); 

  break; 

  case 8: 

  sdfIn.applyPattern("hhmmssmm"); 

  date = sdfIn.parse(input); 

  break; 

  case 10: 

  sdfIn.applyPattern("hhmmssmmss"); 

  date = sdfIn.parse(input); 

  break; 

  } 

  }catch(ParseException pe){ 

  throw new StreamTransformationException(pe.getMessage()); 

  } 

  return sdfOut.format(date); 

  }

syntax error :

Source text of object Message Mapping: MM_EDIEvents2 | http://sap.com/xi/EM/EDIEvents has syntax errors:  
former_member182412
Active Contributor
0 Kudos

Hi Sherwin,

Remove the last closing bracket in your UDF. Also maintain these import statements.

Regards,

Praveen.

Former Member
0 Kudos

HI  Praveen,

I am now getting the below error.

Function Timeformat, Line 4:

error: cannot find symbol   int length = input.length();                       ^   symbol:   method length()   location: variable input of type TransformationInput

Function Timeformat, Line 9:

error: incompatible types: TransformationInput cannot be converted to String   date = sdfIn.parse(input);                        ^

Function Timeformat, Line 13:

error: incompatible types: TransformationInput cannot be converted to String   date = sdfIn.parse(input);                        ^

Function Timeformat, Line 17:

error: incompatible types: TransformationInput cannot be converted to String   date = sdfIn.parse(input);                        ^

Function Timeformat, Line 21:

error: incompatible types: TransformationInput cannot be converted to String   date = sdfIn.parse(input);                        ^ Note: /usr/sap/DX8/J52/j2ee/cluster/server0/./temp/classpath_resolver/Map9f52471e798311e6b8c500001f77e33a/source/com/sap/xi/tf/_MM_EDIEvents2_.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 5 errors 4 warnings

former_member182412
Active Contributor
0 Kudos

Hi Sherwin,

Make sure are you creating the UDF like below.

Regards,

Praveen.

Former Member
0 Kudos

Thankyou so much Praveen. The error is resolved.

Former Member
0 Kudos

HI Praveen,

I am getting an issue. when the date is passed as 23.55.55 it is giving output as 23.01.55. it should give it as 23.55.55. Can you please suggest?

Thanks,

Sherwin.

manoj_khavatkopp
Active Contributor
0 Kudos

Sherwin,

Do you mean when the input is 235555 then you get output as 11:55:55 ?

Br,

Manoj

Former Member
0 Kudos

HI Manoj,

No, when i am sending 235555, I am getting 23:01:55.

manoj_khavatkopp
Active Contributor
0 Kudos

Have you modified the UDF ?  if yes you can post the same here to make the necessary changes ?

I tested the same above udf and i get result like below.

Former Member
0 Kudos

HI, Yes, I changed the udf. I am using now capital HHMMSS in place of hhmmss, also the case 8, 10 are now case 7 and 8.. so now the issue is even if i pass 025545 or 235045... the results are 02:07:45, 23:02:45 respectively

SimpleDateFormat sdfIn = new SimpleDateFormat(); 

  SimpleDateFormat sdfOut = new SimpleDateFormat("HH:MM:SS"); 

  Date date = null; 

  int length = input.length(); 

  try{ 

  switch (length) { 

  case 4: 

  sdfIn.applyPattern("HHMM"); 

  date = sdfIn.parse(input); 

  break; 

  case 6: 

  sdfIn.applyPattern("HHMMSS"); 

  date = sdfIn.parse(input); 

  break; 

  case 7: 

  sdfIn.applyPattern("HHMMSSD"); 

  date = sdfIn.parse(input); 

  break; 

  case 8: 

  sdfIn.applyPattern("HHMMSSDD"); 

  date = sdfIn.parse(input); 

  break; 

  } 

  }catch(ParseException pe){ 

  throw new StreamTransformationException(pe.getMessage()); 

  } 

  return sdfOut.format(date);


Thanks,

Sherwin

manoj_khavatkopp
Active Contributor
0 Kudos

SimpleDateFormat sdfIn = new SimpleDateFormat();

  SimpleDateFormat sdfOut = new SimpleDateFormat("HH:mm:SS");

  Date date = null;

  int length = input.length();

  try{

  switch (length) {

  case 4:

  sdfIn.applyPattern("HHmm");

  date = sdfIn.parse(input);

  break;

  case 6:

  sdfIn.applyPattern("HHmmSS");

  date = sdfIn.parse(input);

  break;

  case 7:

  sdfIn.applyPattern("HHmmSSD");

  date = sdfIn.parse(input);

  break;

  case 8:

  sdfIn.applyPattern("HHmmSSDD");

  date = sdfIn.parse(input);

  break;

  }

  }catch(ParseException pe){

  throw new StreamTransformationException(pe.getMessage());

  }

  return sdfOut.format(date);

M= Month , m = minute

Former Member
0 Kudos

HI Manoj,

Thank you so much. Its resolved.

BR,

Sherwin

Answers (2)

Answers (2)

former_member186851
Active Contributor
0 Kudos

Hello Sherwin,

As Harish mentioned you need to have a qualifier.After that you can try as per the below link

Former Member
0 Kudos

HI , I am using EDI 990. Its an inbound. There is no qualifier. I think I have to use UDF but I am not good with it so need help for making a UDF.

Harish
Active Contributor
0 Kudos

Hi Sherwin,

there should be a qualifier field which define the format of time. Can you please specify which EDIFACT document you are using?

regards,

Harish

Former Member
0 Kudos

HI , I am using EDI 990. Its an inbound. There is no qualifier. I think I have to use UDF but I am not good with it so need help for making a UDF.