cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Both Dirctory and File Name Dynamically in File Adapter.

former_member204873
Contributor
0 Kudos

hi All,

I am trying to use both Dirctory Name and File Name Dynamically in File Adapter.

My UDF is like this:

String Name ="";

Name = fileName;

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

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

conf.put(key, Name);

int x = fileName.indexOf(".");

int y = fileName.length();

Name = fileName.substring(0, x);

Name = fileName + ".pgp";

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

conf.put(keyDir, Name);

But at runtime only File Name is available Dynamically. Directory Name is not coming. Is there anything wrong in the above code, or is it that it is not possible to set both the names dynamically.

Thanks,

Mayank

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Goto Sxmb_Moni and check in the Adapter properties for Dynamic configuration and you will see that both File Name and Directory is coming provided you checked both the check box in your adapter.

Now problem with your directory is ...you are not using it anywhere in your code

See you have appended your extension .pgp to the File name:

Name = fileName.substring(0, x);

Name = fileName + ".pgp";

but for directory where are you sending the info:

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

conf.put(keyDir, Name);

See if you want to append directory name with file name then apply string function APPEND else if you want to map it to the target node as it is then write the code

result.addValue("Name");

And becuse you've put keyDir into Name it will give you the output as directory in the target node.

Hope it help you..

Naina

Former Member
0 Kudos

Mayank

Also make two user defined functions:

1. To Amend Filename and

2. To ammend directory and then map like

1. xyz -> ud_fileName -> File

2 abc -> ud_Directory -> Directory.

Changing both filename and directory value in one UD is possible but assigning both to target is not

Naina

Answers (3)

Answers (3)

Former Member
0 Kudos

change your code as


String Name ="";
Name = fileName;
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File", "FileName");

int x = fileName.indexOf(".");
int y = fileName.length();
Name = fileName.substring(0, x);
Name = fileName + ".pgp";
//here change the file name after assigning value to Name variable.
conf.put(key, Name);
DynamicConfigurationKey keyDir = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File", "Directory");
conf.put(keyDir, Name);

also in your code you are not changing the directory name anywhere.that is why may it is not dynamically getting created.

former_member204873
Contributor
0 Kudos

hi fatima,

Actually logic is to have different Directory and File Name, in directory name i have to remove characters after '.', so my code is like what i mentioned in the initial post.

It looks like that this code is not working:

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

conf.put(keyDir, Name);

Also if i have two different DynamicConfigurationKey's , how can i retreive same in the channel.

Thanks.

Shabarish_Nair
Active Contributor
0 Kudos

in sxmb_moni, open the message got to the response node -> SOAP Header -> Dynamic Configuration

Do you see the values set by you here? if so the code is working fine.

Then the only reason might be that you have not enabled the ASMA for file name and directory in CC.

Maybe recreate the CC or do a complete cache refresh

former_member204873
Contributor
0 Kudos

in sxmb_moni, open the message got to the response node -> SOAP Header -> Dynamic Configuration only filename is coming.Directory name is not there.

Shabarish_Nair
Active Contributor
0 Kudos

check your logic in this part of the code

int x = fileName.indexOf(".");
int y = fileName.length();

Name = fileName.substring(0, x);

Name = fileName + ".pgp";

can you modify the code to;

String Name ="";
Name = fileName;

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

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

String DName = "Test Directory";

DynamicConfigurationKey keyDir = DynamicConfigurationKey.create( "http://sap.com/xi/XI/System/File", "Directory");
conf.put(keyDir, DName);

see if the code is working now.

if it is then u will have to revisit the logic of creating the directory name in your code.

What exactly is your requirement in terms of filename and directory?

former_member204873
Contributor
0 Kudos

hi Shabharish,

I got the issue and there was sone cache issue, it's working now ,, Thanks.

Now i want to use it in Variable substitution, so how can i retreive the same,

Before i was using single DC value, so i added below in the module tab :

AF_Modules/DynamicConfigurationBean

key.0 write http://sap.com/xi/XI/System/File Filename

value.0 message.interface

http://wiki.sdn.sap.com/wiki/display/XI/CombiningthreedifferentaspectsofPIinoneshot

File Name that i am setting in UDF will be used in Adapter Module only, so i don't have to use same in ASMA in channel. But i want to retrieve Directory name to use it in Variable Substitution.

How can i do so?

I tried using:

keyDir.0 write http://sap.com/xi/XI/System/File Directory

value.0 message.interface

But Directory Name created in the FTP location is as the Service interface name.

Thanks,

Mayank

Edited by: Mayank Gupta on Jun 24, 2010 6:19 AM

former_member204873
Contributor
0 Kudos

hi Shailesh and Abid,

ASMA property for both(Directory and file name) is selected in the channel, any other suggesions.

Thanks.

Former Member
0 Kudos

Make sure if you have checked the Adapter Specific Message attribute for Directory as well.

Shailesh

Former Member
0 Kudos

Hi,

Shailesh : Nice to see your contribution on sdn

Mayank: Checked the ASMA property as sugessted by Shailesh.

Regards,

Abid