cancel
Showing results for 
Search instead for 
Did you mean: 

file to file scenario

Former Member
0 Kudos

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 .

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Thanx people for helping me

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Go to this below refer link you can acheive:

[;

Former Member
0 Kudos

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,

Former Member
0 Kudos

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

for achieving the same

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.