on 11-20-2006 4:15 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Gaurav.
My issue is now solved!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
9 | |
9 | |
7 | |
7 | |
6 | |
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.