cancel
Showing results for 
Search instead for 
Did you mean: 

File copy scenario

Former Member
0 Kudos

Hi ,

Is it possible to decide the "destination folder" ( where file needs to be copied) based on the sender file name ( no mapping exists only ID settings ) . As shown in the below example based on text 100 on the source file the destination should file should be copied under folder 100.

If not What would be the best approach to achieve this ?

sender -> receiver

scr/PI/folder100.txt -> dest/PI/100/folder100.txt

scrt/PI/foder200.txt -> dest/PI/200/folder200.txt

Thanks in advance ,

Raj

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

As Your requirement is to read a .txt file from the specified sender folder example scr/PI/folder100.txt and put the same file folder100.txt to the Receiver folder which is dynamically created based on the last three digits of the sender file name here in this case it is dest/PI/100/folder100.txt.

As you have to write a UDF for dynamically specifying the receiver folder,You have to create a Mapping,for this you have to create a DT ,MT,SI,MM, and MI.As your structure of source file is same as Target same MT can be used while creating the outbound and inbound service Interface.

To read a .txt file you have to use the File Content Conversion in the Sender File Communication Channel

and To put a .txt file to the receiver folder you have to use the File Content Conversion in the receiver Communication Channel

It is possible to design a scenario without IR if your requirent would have been to just put the same file from sender folder to receiver folder which is static in this case no mapping is required.you refer this for more details on [When to go for designing scenario without IR|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/4383] [original link is broken] [original link is broken] [original link is broken];

Former Member
0 Kudos

PI Guru's,

I am still looking for a solution as we have many new scenarios of this kind which don't require any mapping and no IR development and I need to determine destination folder based on the sub string in the source file name.

Options tried which did not work :

I cant use Variable substitution since I have no mapping and the string which I am looking to determine the destination folder is not in payload .

I am not sure if I can use UDF's without mapping ?

Is there any way to dynamically determine the destination directory based on the sender file name.

(NO Mapping , No IR simple as is file move )

Thanks,

Raj

Former Member
0 Kudos

You can invoke OS command (either windows batch file or unix shell script), put it in file receiver, after message processing.

Other option could be that you need to write customized module, change the dynamic configuration parameter values as you put on UDF.

Regards

Liang

Edited by: Liang Ji on Oct 20, 2010 11:19 PM

Former Member
0 Kudos

Hi Raj,

Please follow Ramkumar ganesh reply but a little change in the code of UDF you create as your requirement is


scr/PI/folder100.txt -> dest/PI/100/folder100.txt
scrt/PI/foder200.txt -> dest/PI/200/folder200.txt

UDF code



DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
 
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
 
DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "Directory");
 
 
String fileName = conf.get(key);
 
String newDir = u201Cdest/PI/u201D+fileName.substring(5,7)+u201D/u201D;
conf.put(key1, newDir);
 
return "";

also select the Adapter specific message attribute,FileName,Directory in the advance tab of each of the file communication channel .

Former Member
0 Kudos

del

Edited by: Raj on Jun 15, 2010 11:22 PM

Former Member
0 Kudos

Thanks a lot Srini,Ram,Fatima,

Need some more information based on your inputs .

What would be my IR and ID setting to achieve this dynamic folder selection based on file name.

Since I have a simple file pass u201C as isu201D will I have to do content conversion in the mapping ?

It would be really helpful to me and future forum readers if you can put all the things together

And explain this in detail ( step-by-step if possible ) .

Thanks,

Raj

rajasekhar_reddy14
Active Contributor
0 Kudos

> What would be my IR and ID setting to achieve this dynamic folder selection based on file name.

Develop one to one mapping and add UDF to to tagget node.Create DT,MT,MI,MM,IM ..interface design same as other interface

> Since I have a simple file pass u201C as isu201D will I have to do content conversion in the mapping ?

What type of file you are copying fron one directory to other?? XML file or flat files, if it is not XML file then you have to implement FCC at sender side.

Regards,

Raj

Former Member
0 Kudos

Hi Raj,

I think its possible with the context object "File name" in the receiver determination.

As you mentioned , you have no mapping,so in the receiver determination,there would be a radio button for context object.

It will have some standard context objects in the list once selected.

Select the filename and mention

filename ->folder100.txt if you want to send to the BS|communication channel for folder100 in the target.

Similarly you can add the conditions in the receiver determination for different folders as required.

Hope this helps, try out.

If you are having file name in the payload ( if its possible to create source and target structure),then you can have a simple mapping and dynamic configuration UDF to set the target. and also you can use variable substitution in the receiver channel.

Regards,

Srinivas

Former Member
0 Kudos

Hi Srinivas,

My ID setting are as follows and I am using PI 7.1

i am using Business Service with one sender communication channel ( file adapter ) and one receiver communication channel ( file adapter ) .

In Receiver determination under " Configured receivers" I found the option to add "filename" but not sure how to route the file to specific folder based on this setting . Do I have to have multiple receiver commmunication channels ?

can you please provide more details ?

Thanks a lot .

-Raj

Former Member
0 Kudos

Hi Raj,

I think you need to have multiple business services to do the receiver determination if you want to do using ID configuration only.But not sure if writing an adapter module will help.

Regards,

Srinivas

Former Member
0 Kudos

Srinivas,

Finally will this scenario be easy to achieve if i use IR message mapping ? If yes can you let me know steps .

Thanks for all your help .

Raj

Former Member
0 Kudos

Hi

Message Mapping : create UDF with the below code and map it to Root tag of the target structure.

Java Mapping : Include hte piece of code in ur java code.

http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=95093307



DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");

DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "Directory");
 

String fileName = conf.get(key);
String fileDir = conf.get(key1);

String newDir = fileDir+"\"+fileName.replaceAll(".txt","")+"\";
conf.put(key1, newDir);

return "";

Regards

Ramg

Former Member
0 Kudos

Hi

If your Source payload will contain the "filename" then you can use variable Substitution method in Receiver Channels.

If not then you have go for

1. UDF in message mapping

2, Java mapping

I suggest you to go with java mapping, Sicec your interface is simple pass thru,

Regards

Ramg