cancel
Showing results for 
Search instead for 
Did you mean: 

Please help me on to write UDF

Former Member
0 Kudos

Hi,

The condition is,

Source Fields (Time)

PICKUP_TIME

DELKEY_TEXT_WE

Target Field(Date/Time)

EarliestTime

IF PICKUP_TIME is not equal to 00:00:00 then Read value from: PICKUP_TIME and reduce this by 30 min. and place the result into: EarliestTime. Else

if map value from DELKEY_TEXT_WE position 6 until 13

into: EarliestTime.

Please help me on this...like how to implement UDF

Thanks & Regards,

Y.Raj.

Accepted Solutions (1)

Accepted Solutions (1)

former_member518917
Participant
0 Kudos

u can try:

// UDF <input parameters: String picktime, String DELKEYTEXT

String EarliestTime="";

if(!picktime.equals("00:00:00")){

SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

try{

Date newDt = sdf.parse(picktime);

newDt.setMinutes(newDt.getMinutes()-30);

EarliestTime = sdf.format(newDt);

}catch(Exception e){

}

return EarliestTime;

}else{

return DELKEYTEXT.substring(6,13);

}

Regards

Ritu...

Edited by: Ritu Sinha on Sep 19, 2008 12:06 PM

Former Member
0 Kudos

Hi Ritu Sinha,

It's really v.v.helpful for me to get it resolved.

Thanks alot..

Regards,

Y.Raj.

Former Member
0 Kudos

Hi Ritu Sinha,

I has used the UDF which u given earlier is giving one error.

that is, based on the ELSE condition here,

if map value from DELKEYTEXT pos. 6 until 13 into: EarliestTime

if i give DELKEYTEXT value = ravi then receiver side is giving this following error.

The message is: Exception:[java.lang.StringIndexOutOfBoundsException] in class

Note : if i give morethan 16 chars. mapping is working fine

Please suggest me here how can i resolve this..

Thanks & Regards,

Y.Raj.

Former Member
0 Kudos

Hi Ritu Sinha,

A small requirement has been changed here.

the input for picktime has time format: hhmmss instead of hh:mm:ss.

but, the result is the same i need to get it.

ie., hh:mm:ss

Please suggest me here

Thanks & Regards,

Y.Raj.

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

Just make a small change in udf

// UDF <input parameters: String picktime, String DELKEYTEXT

String EarliestTime="";

if(!picktime.equals("000000"))

{

SimpleDateFormat sdf = new SimpleDateFormat("HHmmss");

SimpleDateFormat sdf1= new SimpleDateFormat("HH:mm:ss");

try{

Date newDt = sdf.parse(picktime);

newDt.setMinutes(newDt.getMinutes()-30);

EarliestTime = sdf1.format(newDt);

}catch(Exception e){

}

return EarliestTime;

}else{

if(DELKEY_TEXT_Z5.length() > 5)

{

return DELKEY_TEXT_Z5.substring(5,13);

}

else

{

return DELKEY_TEXT_Z5;

}

}

changes are in bold

Edited by: malini balasubramaniam on Oct 20, 2008 3:36 PM

Former Member
0 Kudos

Hi Malini,

Thanks a lot for your support for this blog.

Regards,

Y.Raj.

Former Member
0 Kudos

Hi Ritu Sinha,

A small requirement has been changed here.

the input for picktime has time format: hhmmss instead of hh:mm:ss.

but, the result is the same i need to get it.

ie., hh:mm:ss

Please suggest me here

Thanks & Regards,

Y.Raj.

prasad_ulagappan2
Contributor
0 Kudos

Change the code like "if(!picktime.equals("000000")){" in the earlier UDF...

Former Member
0 Kudos

Hi,

I have tried with that...but, am getting the blank.

Please find the code below here which am using UDF

String EarliestTime="";

if(!PICK_TIME.equals("000000")){

SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");

try{

Date newDt = sdf.parse(PICK_TIME);

newDt.setMinutes(newDt.getMinutes()-30);

EarliestTime = sdf.format(newDt);

}catch(Exception e){

}

return EarliestTime;

}else

{

if(DELKEY_TEXT_Z5.length() > 5)

{

return DELKEY_TEXT_Z5.substring(5,13);

}

else

{

return DELKEY_TEXT_Z5;

}

}

Thanks & Regards,

Y.Raj.

prasad_ulagappan2
Contributor
0 Kudos

Did you check the values in the input?

Former Member
0 Kudos

This is becoz the Delkey is less than 13 characters.

what is ur requirement in this case?

shud it display ravi as such..

Then make a check on the length of delkey time(in else part of the same udf)

else{

if(DELKEYTEXT.length() > 13)

{

return DELKEYTEXT.substring(6,13);

}

else

{

return DELKEYTEXT;

}

}

Edited by: malini balasubramaniam on Sep 30, 2008 9:31 AM

Former Member
0 Kudos

Thank you

Regards,

Y.Raj.

Former Member
0 Kudos

Hi,

Please help me on this..

condition :

if map value from DELKEYTEXT pos. 6 until 13 into: EarliestTime

if i give DELKEYTEXT value = ravi then receiver side is giving this following error.

The message is: Exception:[java.lang.StringIndexOutOfBoundsException] in class

Note : if i give morethan 16 chars. mapping is working fine.

Thanks & Regards,

Y.Raj.

Edited by: YeswanthRaj Kumar on Sep 30, 2008 9:10 AM

Former Member
0 Kudos

I have replied to this in ur previous post. Pls check it.