on 04-29-2008 5:48 AM
Hi all,
I need help for one mapping concept i.e.
we will get souce side one date (DD/MM/YYY) for that we hv to add some days and generate target date .
so, can any one tell me how to do this.....with udf...
Thanks & Regards,
Mahesh.
Hi,
I think you need a simple udf like this:
where "a" is the input parameter that should match the date format of the dateFormat object.
imports: java.util.Calendar;java.text.SimpleDateFormat;java.text.DateFormat;
public String addOneDay(String a,Container container){
String notifyDates = a;
Calendar calendar = Calendar.getInstance ( ) ;
DateFormat dateFormat = new SimpleDateFormat ( "yyyy-MM-dd" ) ;
try {
Date date = dateFormat.parse ( notifyDates ) ;
calendar.setTime ( date ) ;
calendar.add ( Calendar.DATE, 1 ) ; // Add here that how many days u wanna add
return dateFormat.format ( calendar.getTime ( ) ) ;
} catch ( Exception e ) {
return "error";
}
}
regards
Aashish Sinha
PS : reward points if helpful
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Raj,
i was tryed ur 2 solutions.
in 1st solution whatever date i will provide as soruce its giving 20081026 like this
for 2nd solution, i got this error.
Source code has syntax error: /usr/sap/XID/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Map34838900155211dd806d00093d14d008/source/com/sap/xi/tf/_MM_IT0009_.java:69: cannot resolve symbol symbol : variable date location: class com.sap.xi.tf._MM_IT0009_ int ip_date = Integer.parseInt(date); ^ 1 error
plz help me to resolve this.
Thanks & Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mahesh,
1) inputValue is your DATE value I consider it for number of values.It works for single value also.
2) Do mapping as follows,
inputValue>RemoveContext> UDF>SplitByValue>TargetField
Following the code for UDF.
String[] splitCodes = null;
for(int i = 0; i < inputValue.length; i++)
{
if( !(inputValue<i>.equals("")))
{
splitCodes = iDVal<i>.split("/");
int posVal = 0;
if(posVal < splitCodes.length)
splitCodes[posVal] = splitCodes[posVal] + "10"
result.addValue(splitCodes[posVal]+ "/" + splitCodes[1] + "/" + splitCodes[2]);
}
}
Instead of 10 you can use data which you want to add as days.
Regards ,
Rohit.
Reward points if helpful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mahesh,
you can customize following UDFs according to your requirement.
//Add current date with required days(180) and convert the date output to string format and return it
// Declarations
int date,
days_added=180,
day,
month,
year;
Calendar cal;
// Get current date
cal = Calendar.getInstance();
// Add required days to current date
cal.add(Calendar.DATE, days_added);
// Convert date format to string format
day = cal.get(Calendar.DATE);
month = cal.get(Calendar.MONTH)+ 1;
year = cal.get(Calendar.YEAR);
date = year * 10000 + month * 100 + day;
return (""+date);
or
string in YYYYMMDD as input and similar format string in output
// Declarations
int ip_date = Integer.parseInt(date);
int days_added=180;
Calendar cal;
// Read day, month and year from input string
int day = ip_date % 100;
int month = (ip_date/100) % 100 - 1;
int year = ip_date / 10000;
// Convert the above to date format and add the no of days
cal = Calendar.getInstance();
cal.set(year, month, day);
cal.add(Calendar.DATE, days_added);
day = cal.get(Calendar.DATE);
month = cal.get(Calendar.MONTH)+ 1;
year = cal.get(Calendar.YEAR);
ip_date = year * 10000 + month * 100 + day;
return (""+ip_date);
Hope it solves your problem
Regards
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
7 | |
7 | |
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.