on 08-03-2011 4:01 AM
Hi Experts,
I have requirement regarding Date subtraction in SAP PI.
I have acondition in which few fields are coming from a file with data. Among, the different fields there is a start date field.
The condition is such that I have to transfer that part of the file in which the start date = currentdate-5;
Which means for the maybe 6 fields maybe wherever there is condition startdate = currentdate-5, that part of the file needs to be picked.
Now, I am unable to write the UDF in which this date calculation is there, also problem occurring when month is the previous one.
Please advice.
Date today = new Date();
*Check the date with your argument.
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -5);
Regards
Pothana
Edited by: Pothana Yadav on Aug 3, 2011 8:47 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check the below mentioned blog for your requirement..
/people/sarvesh.singh3/blog/2009/02/13/yes-it-is-possible-with-datetrans-function
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aniruddha,
You have not specified the format in which you are receiving the date. For example mm/dd/yyyy or dd/mm/yyyy.
I have assumed dd/MM/yyyy. The format of date, you can alter after going through this link http://download.oracle.com/javase/1.4.2/docs/api/java/text/SimpleDateFormat.html
The UDF required is shown below
public String compareDates(String startDate,Container container){
String forwardDate="0";
try
{
String pattern = "MM/dd/yyyy";
int i;
final int MilliSecondsInADay=1000 * 60 * 60 * 24 ;
java.text.SimpleDateFormat Dateformat = new java.text.SimpleDateFormat(pattern);
java.util.Date today=new java.util.Date();
java.util.Date fiveDayPreviousDate=new java.util.Date(Dateformat.format(new java.util.Date(today.getTime()- 5* MilliSecondsInADay)));
i=(Dateformat.parse(startDate)).compareTo(fiveDayPreviousDate);
forwardDate=new Integer(i).toString();
}
catch(Exception e)
{
e.printStackTrace();
}
return forwardDate;
}
you can alter the "String pattern" as per your input date. This function returns "0", if the startDate is five days previous to current system date. These values will only be forwarded to target message structure. Ensure that the target field has minimum occurence as zero. Now you perform the following graphical mapping to achieve desired result
Link:[mapping|http://postimage.org/image/15k6bbuec/]
Here ITEMSET is the field carrying date. Here is the result
Link[ result screenshot|http://postimage.org/image/2zoe7em84/]
considering todays date is 08/03/2011 then the date 5 days earlier is 07/29/2011. So if the startDate value is 07/29/2011 then value is passed to target, for any other startdate value will not reach the target. Check this screenshot for positive output
Link[ result after mapping|http://postimage.org/image/xzt589tw/]
Hope this helps.
regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use standard function datetrans and currentdate to achive your requirement with little tricks.......
like separately calculate month and date and year
or you can write UDF
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.