on 09-12-2016 5:58 PM
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can try some logic as per below link,I dont have system to try
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.
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: |
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
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
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.