on 12-06-2011 5:54 AM
Hi All,
I am having file to file scenario in which i am having file name in the format of text_yyyymmdd.txt.
i want to read this file name and by separating the date in file name. please help me .
Hi,
In sender communication channel use Adapter Specific Message Properties. Tick on this two options
"set Adapter Specific Message Properties" and "Filename". Now you need this UDF, no need of any input parameter to the function
public String getFileName(Container container){
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String s = conf.get(key);
s=s.substring(s.indexOf("_")+1,s.indexOf("."));
return s;
}
So if your filename is "PN001_20110709.txt" the UDF will separete the date part and in target field you will obtain "20110709".
If you want the file name without the date then the UDF is as below
public String getFileName(Container container){
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String s = conf.get(key);
s=s.substring(0,s.indexOf("_"))+s.substring(s.indexOf('.'), s.length());
return s;
}
So if your filename is "PN001_20110709.txt" the UDF will produce "PN001.txt".
Regards
Anupam
Edited by: anupamsap on Dec 6, 2011 7:25 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI,
file to file scenario
I am having file to file scenario in which i am having file name in the format of text_yyyymmdd.txt.
i want to read this file name and by separating the date in file name.
that is possiable with ASMA in ADVAnced mode in Communication channels.
In Sender and receiver communication channels -> in adavaned tab -> enabled USE ASMA -> Source file stamp .
thats all.
other wise you have to write simple udf: (text_yyyymmdd.txt.)
source field(text) -> constant(_) ->concat -> udf -> constant(.txt)->concat -> target field.
udf:
String AddTimestamp(String var1, Container container) throws StreamTransformationException{
String DATE_FORMAT_NOW = "yyyyMMddHHmmssSSS";
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
return sdf.format(cal.getTime());
thanks,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
1. Enable ASMA properties in sender file communication channel and Write a UDF using Dynamic Configuration and get the filename. Make use of this blog by michal
2. With the help of the code described, obtain the Dynamic configuration parameters where you get the file name.
3. With the help of UDF extract the date from the file name.
regards,
ganesh.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
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.