cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic FileName and Directory - UDF

Former Member
0 Kudos

My scenario is to get Target Directory Name based on part of Filename. How can I do that using UDF. I will select adapter specific parametrs and like to change using UDF. TO achive this I will create a dummy field names in the target structure. Can someone let give me UDF code?.

For Example: Source FileName : SD00123456Prod.csv

Target Directory Should be /Sales/

Target File: Prod.csv

Thanks for any help.

Accepted Solutions (1)

Accepted Solutions (1)

moorthy
Active Contributor
0 Kudos

HI,

Have a look into this blog-

/people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14

Regards.

Moorthy

Former Member
0 Kudos

Moorthy,

Do I have to Import any for this UDF? and Name of the UDF can be anything right? Thanx a lot for quick reply.

When I do check in the message mapping of the function its showing lot of erros. So Do I have to import anything into function ?

Here is the Function I created.

public String SourceFileName(Container container){

DynamicConfiguration conf = (DynamicConfiguration) container

.getTransformationParameters()

.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create(

“http://sap.com/xi/XI/System/File”,

“FileName”);

String valueOld = conf.get(key);

if (valueOld != null) {

String valueNew = valueOld.replaceAll(“input”,”output”);

conf.put(key, valueNew);

}

}

former_member206604
Active Contributor
0 Kudos

Hi,

<i>>>>Do I have to Import any for this UDF? and Name of the UDF can be anything right?</i>

Yes you can have anything.

You cannot test this in the design, this will get executed only during runtime. So when you execute in design you will get errors.

Thanks,

Prakash

Former Member
0 Kudos

Prakash, but I'm getting errors when I'm activating the Message Mapping Object. I didn't changed any. Just copied from the Blog

former_member206604
Active Contributor
0 Kudos

Hi,

I hope you have posted only the part in bold in the editor

public String SourceFileName(Container container){

<b>DynamicConfiguration conf = (DynamicConfiguration) container

.getTransformationParameters()

.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create(

“http://sap.com/xi/XI/System/File”,

“FileName”);

String valueOld = conf.get(key);

if (valueOld != null) {

String valueNew = valueOld.replaceAll(“input”,”output”);

conf.put(key, valueNew);

}</b>

}

moorthy
Active Contributor
0 Kudos

HI,

What is the error ?

<i>String valueOld = conf.get(key);

if (valueOld != null) {

String valueNew = valueOld.replaceAll(“input”,”output”);

conf.put(key, valueNew);

}</i>

I think the error may be because of some problem with syntax etc. You did not write <i>return</i> Statement..check carefully with the blog.

Regards,

Moorthy

Former Member
0 Kudos

Ram,

Give your mail id. I will send you a step by step document?

---Satish

Former Member
0 Kudos

Satish thanks for the offer. My Id ramkrishi12@yahoo.com

Former Member
0 Kudos

Ram,

I have send you the document which should resolve your issue.

---Satish

Former Member
0 Kudos

I changed function this time. I took exact coy of Michals Blog.

Function:

public String SourceFileName(Container container){

container.getTransformationParameters().get

(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create

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

String ourSourceFileName = conf.get(key);

return ourSourceFileName;

}

Now the error when activate message mapping:

Activation of the change list canceled Check result for Message Mapping Source_2_Target | http://test.com: Starting compilation Source code has syntax error: /usr/sap/DPI/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Map36d73f104e5e11db977f001125a56eca/source/com/sap/xi/tf/_Source_2_Target_.java:55: cannot resolve symbol symbol : variable conf location: class com.sap.xi.tf._Source_2_Target_ String ourSourceFileName = conf.get(key); ^ 1 error

former_member206604
Active Contributor
0 Kudos

Hi,

You are in which SP, hope SP14 or above.

There is nothing workng with your code..

Thanks,

Prakash

Former Member
0 Kudos

Prakash, we are in PI7.0, the very latest version of XI

Message was edited by: Ram Krish

former_member206604
Active Contributor
0 Kudos

Hi,

Ok got it..

You have missed the declaration of the variable conf

<b>DynamicConfiguration conf =</b> (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

Thanks,

Prakash

moorthy
Active Contributor
0 Kudos

As it clearly tells me that there is a syntax error. check the Braces etc..

check the declaration part-

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

Regards,

Moorthy

Former Member
0 Kudos

Prakash, Moorthy you got it. the Declaration has paroblem. I donno but I just did cut and paste. I appreciate all your help. Though you both answered almost at exact times I flagged Prakash solved problem. I hope Moorthy understands me and appreciate his prompt response by being one one the top contributors in the forum and thanks a lot guys.

moorthy
Active Contributor
0 Kudos

Nice to know it worked

No Problem..

-Moorthy

Answers (0)