on 08-26-2011 12:15 PM
Hi all,
How can we change the standard date time stamp from
filename_yyyymmdd-hhmmss-mil
to
filename_yymmdd_hhmmss
i.e., I want "underscores" instead of "hyphens" and also I do not want the MilliSeconds.
I read in the forums that I have to use the combination of variable substitution and mapping functions to do this, but not sure how exactly.
Can the experts help me with this please?
Many thanks.
Hello Ramesh,
You can make this possible using runtime filename creation using UDF.
Please go though the below steps.
Message mapping:
Create an UDF and include the piece of code that captures the Filename and Timestamp from source side via ASMA.
Modify them according to our requirement by adding the <Timestamp> at the end of <filename> with _.
Map the UDF to any of the top level node so that the modified filename will be available for the target communication channel
UDF Code is:
try {
String filename = "";
String timestamp = "";
DynamicConfiguration conf1 = (DynamicConfiguration) container
.getTransformationParameters()
.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key1 = DynamicConfigurationKey.create( "http:/"+"/sap.com/xi/XI/System/File","FileName");
DynamicConfigurationKey key2 = DynamicConfigurationKey.create( "http:/"+"/sap.com/xi/XI/System/File","SourceFileTimestamp");
filename = conf1.get(key1);
timestamp = conf1.get(key2);
filename = filenametimestamp".xml";
filename = filename.replaceAll( "-" ,"_" );
conf1.put(key1,filename);
return filename;
}
catch(Exception e)
{
String exception = e.toString();
return exception;
}
Click on Advanced tab and check the Option u201CSetAdapterSpecificMessageAttributesu201D in addition to that check the attribute that are required to be captured during run time. In our case File Name and Source File Time Stamp are required to be checked
In the receiver communication channel Mention u2018 * u2018as File Name Scheme.
Click on Advanced tab and check the Option u201CSetAdapterSpecificMessageAttributesu201D in addition to that check the attribute u201CFile Nameu201D which will carry the modified value in the UDF .
i hope this will help you.
Monica
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Another option is to use Variable substitution in Receiver File adapter if you want to get rid off this UDF.
for example if date and time field is there in your structure then modify it according to your req. like yymmdd/hhmmss and then use this two field as a reference in variable substitution(1st enable this option check box) and create var1 and var2 varible.
then in file name schema = filename_%var1%_%var2%.xml
it should work.
Monica
Edited by: monica bhosale on Aug 26, 2011 1:53 PM
Many thanks Monica and Gaurav!
Monica,
I forgot to mention this is a webservice to file scenario. I did the necessary file content conversions for xml to csv format. So I am not capturing any file name from the source side, I am just creating the file name while writing the file in the file receiver channel.
So do I have to have two more file channels (a receiver and sender) between my actual webservice and file receiver channels?
Or is there a simple way?
Thanks.
Hi Ramesh,
You need to write an UDF in message mapping to do that. You can consider the following as a sample:
String desiredfilename = "Anytexthere";
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
SimpleDateFormat dateformat = new SimpleDateFormat("yyMMddHHmmss");
String timestamp = dateformat.format(new Date());
String dateStr = timestamp.substring(0, 6);
String timeStr = timestamp.substring(6);
String filename= desiredFilename + "_" + dateStr + "_" + timeStr;
conf.put(key, filename);
return "";
Hope this will help.
Regards, Gaurav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.