cancel
Showing results for 
Search instead for 
Did you mean: 

Create user defined function to add a number to a date field

Former Member
0 Kudos

Hello,

I have a scenario where I need to create a user defined function in my message mapping. In my source message I have a field for a "date" and a field for "number of days". My custom function needs to add the number of days to the date field.

I am an ABAP programmer and I do not have experience with Java. Can someone help me with this function or give me a Java function example?

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Rhonda

In the message mapping, create a new User Defined function (UDF) and copy the following code to the function

try

{

String start = BaseDate.toString();

SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy");

Date d = sdf.parse(start);

GregorianCalendar gc = new GregorianCalendar();

gc.setTime(d);

gc.add(Calendar.DAY_OF_YEAR, Integer.parseInt(Days));

Date end = gc.getTime();

return gc.getTime().toString();

}

catch(Exception e)

{

return "";

}

(Comment - You may need to change the date format in the second line based on the format of the incoming date)

Copy the following statement in the Imports statement of the UDF --

java.text.*;java.util.Date;java.util.Calendar;java.util.GregorianCalendar;

Now, in the graphical mapping use the UDF. Assign the "date" field to the first hook of the UDF and the "number of days" field to the second hook of the UDF. That should be it.

Regards

Gaurav

PS - Please assign points if you find the answer helpful

Message was edited by:

Gaurav Walia

Comment addded

Answers (4)

Answers (4)

Former Member
0 Kudos

Thank you Gaurav.

My issue is now solved!

former_member187339
Active Contributor
0 Kudos

Hi,

Refer this site, it will help you.

http://www.freejavaguide.com/javasource4.htm

Regards

Suraj

MichalKrawczyk
Active Contributor
0 Kudos
Former Member
0 Kudos

Hi,

I don't understand what you really want.

You have two field in the source file.

date

number of days

how looks your target message ?

where you want to add the "number of days"?

is there are field in the target message? than you don't need user function.

for type conversion do something like this

Date date = new SimpleDateFormat("MM/dd/yy").parse("05/18/05");

Regards,

Robin