on 09-12-2012 7:32 AM
Hi Experts,
I have 2 requirements.
My scenario is Idoc to file.
1) My requirement is, I need file name at receiver side as file name+time stamp.
2) I need to append the file.
But in PI it is allowing only either to Use add time stamp or append file in file construction mode.
Can any one please let me know how can i achive both.
Regards
Swetha
Hi swetha
you can handle this by using first append.
and then us OS command to rename with time stemp.
Regards
Gagandeep
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi swetha,
Try the following UDF,
public String Dynamic(String FileName, String Date, Container container) throws StreamTransformationException{
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File" , "FileName");
String myFileName = "" ;
myFileName = FileName + "_" + Date + ".csv";
conf.put(key, myFileName);
return myFileName;
}
1st parameter for this UDF is constant(i.e, ur desired file name).
2nd parameter is Date (use current date function and specify date and time format )
Don't forget to map udf to any node , then only ur dynamic configuration will work. Have alook at attached files.
Please let me know the result.
Regards
Hari.
Hi Hari,
It is throwing error
Just for your reference so that u can cross check......................While creating UDF i had given first argument as FileName and second argument as Date
and execution type Single Values
And in the constant i had given my file name which is
AndwATTInv_.csv
It is throwing below error
Check result for Message Mapping: MM_ATT_Invoice_Out | http://com.commscope.com/ATTCSVEDI/Invoice:
Starting compilation
Source text of object Message Mapping: MM_ATT_Invoice_Out | http://com.commscope.com/ATTCSVEDI/Invoice has syntax errors:
Function Dynamic, Line 1:
not a statement StreamTransformationException{ ^
Function Dynamic, Line 1:
';' expected StreamTransformationException{ ^ 2 errors
mightbe below approach is helpful for ur requirement :
on message mepping :
you can use timestamp and dynamic configuration udf's for dynamically call filename on mapping :
filename_ + time stamp udf + concat + contatnt(.csv) +concat+ dynamic conf udf -> target node
udf:
time stamp:
public String AddTimestamp(String var1, Container container) throws StreamTransformationException{
String DATE_FORMAT_NOW = "yyyyMMdd-HHmmss";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());
dynamic conf:
public String DynamicConfig(String a, Container container) throws StreamTransformationException{
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
conf.put(key,a);
return "";
in Communication channel :
you have to enable flag UseAsma properties and file name .
and you can use Append From File Construction mode .
Thanks,
Message was edited by: S Sankar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
please follw below printscreen:
addTimeStamp:
public String addTimeStamp(Container container) throws StreamTransformationException{
String DATE_FORMAT_NOW = "yyyyMMdd-HHmmss";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());
and add pkg in as below printscreen:
dynamicConf udf:
public String dynamicConf(String a, Container container) throws StreamTransformationException{
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
conf.put(key,a);
return "";
thats all....
On Communication channel:
and for dynamic generate file name:
>>
1) My requirement is, I need file name at receiver side as file name+time stamp.
Normally we add timestamp to file name to distinguish each files in the directory.
Do you mean to have only the date along with file name?
If so, you can use dynamic configuration in mapping and then use append option in receiver file channel.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
if both date and time (along with Seconds is used) then everytime a new file will get created and append will not happen as append time with seconds will be a unique value...
so you need to use hours and minutes if only a single to be generated per hour else as said above maintain one file per day .else you can have the data appended to the file..
HTH
Rajesh
You can refer below blog to know the steps to achieve your file name like File_YYYYMMDD.csv using Dynamic Configuration in mapping.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
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.