on 08-29-2012 6:06 AM
Hi All,
We have a requirement where we need to pick a file for previous month on first day of every new month, where file name is "YY_MMUSD.tex"
For ex. on 1/09/2012 we have to pick a file for month of august i.e. 12_08USD.tex.
But the problem is when its first month of the year..i.e. on 01/01.2013 we should pick the file for month of December'12 12_12USD.tex.
Could you please suggest us how this can be achieved.
Hi,
You can use the class java.util.Calendar in your UDF, for example:
Calendar calendar = Calendar.getInstance();
calendar.set(2013,0,1);
calendar.add(Calendar.MONTH, -1); //Month before
calendar.get(Calendar.MONTH);
calendar.get(Calendar.YEAR);
Be careful because the month number starts at 0.
Best regards,
Roberto
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ayura,
You need scripts to pick up the file from source folder( say /usr/A). The script goes through list of all files in a directory. It checks each file name in the directory and compares with current date. If the file satifies the condition you stated it moves ( not copy ) the file to a destination folder (say /usr/B). PI server picks up file only from /usr/B. How you should write this script depends on the operating system of the PI server. If its linux/Unix system you can use shell scripts. You can also use java code to do all jobs but the java code has to executed from a script. You can request BASIS team to schedule running of this script once a month.
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anupam,
Thanks for your reply.
But source is a coorporate directory and we cannot run a script there.Hence we are using extended receiver determination and transferring only the required file to the target side.
In extended receiver determination we are having difficulty while asigning a condition to the service level node according to which it should pick only the file of previous month.
As for jan'13 it should pick only one file out of all and i.e of dec'12 .
Hence year should also be decremented.
Hi Ayura,
Below UDF provides you the exact filename expected by the scenario.
public static String selectFile()
{
String s="";
try
{
java.text.DateFormat dateFormat ;
java.util.Calendar calendar = java.util.Calendar.getInstance();
//calendar.set(2013,0,1);
//System.out.println("current calendar time = " + dateFormat.format(calendar.getTime()));
if(calendar.get(java.util.Calendar.DAY_OF_MONTH)==1)
{
calendar.add(java.util.Calendar.MONTH, -1);
//System.out.println("calendar one month back = " + dateFormat.format(calendar.getTime()));
dateFormat = new SimpleDateFormat("yy");
String yy=dateFormat.format(calendar.getTime());
dateFormat = new SimpleDateFormat("MM");
String mm=dateFormat.format(calendar.getTime());
s=yy+"_"+mm+"USD.tex";
//System.out.println(s);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return s;
}
I have left some lines as comment (in green) you can use them to test the code in your system. line 09 I have set calender date to 1st day of the year.
In line 11 I am checking if the day is first day of the month or not. Thus the UDF will provide you with correct filename only on 1st of the month else it will provide blank values. the default value can be set on line 03.
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.