cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic File Name - UDF

Former Member
0 Kudos

Hi Master,

I written the UDF for Getting the Dynamic File name.

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

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

// Retrieve the filename

String FileName = conf.get(key);

This is working ok - but I want to return these values so I can be used in mapping.

when I try to add the statement return FileName; , the compiler then complains with the following error:

cannot return a value from method whose result type is void return FileName;

Please help me,

Thanks,

Anu

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi,

>

>For this code to work make a small change in your communication channel.

>Goto Adapter-Specific Message Attributes (Tick it)->File Name(Tick it).

>

>After that you can access File Name...there are also some more parameters you can access. Without >checking it File Name will be null.

>

Have you done this?

Are you getting any error when you run the scenario...Then what is it?

Or you are getting null as FileName..in that case check the above quoted reply.

Regards

Former Member
0 Kudos

Exactly,

I tested put(key,a);

it gave the same error.

But as i said earlier your original code is perfectly fine, unless you do any formatting error.

In which you used String FileName = conf.get(key); use that only please.

I have tested the same and it's working for me....

Regards

Former Member
0 Kudos

Hi Anu

your code seeems to be right just do this small configuration in ID

If you want the dynamic file name then you ned to make a small configuration

Go to your communication channel ->Adapter-Specific Message Attributes (check the radio button)->File Name(check it).

With out checking these boxes you can not receive dynamic file name and it will return NULL

After doing this configuration you can get the dynamic file name that .

Regards

Sandeep

Former Member
0 Kudos

Hi,

For this code to work make a small change in your communication channel.

Goto Adapter-Specific Message Attributes (Tick it)->File Name(Tick it).

After that you can access File Name...there are also some more parameters you can access. Without checking it File Name will be null.

Your code is perfectly fine.

Regards

Former Member
0 Kudos

Hi Anu,

Use this code,

it will return the file name as a field:

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

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

String Outputfile = conf.put(key,a);

return Outputfile;

Regards,

Nithiyanandam

Former Member
0 Kudos

Thanks Nithiyanandam,

I am using the Same code. But i am getting the Syntax error:

Source code has syntax error: E:/usr/sap/DX1/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Mapaf708c00d6bb11dd83ee00101816a382/source/com/sap/xi/tf/_MM_I_FF_O_RFC_.java:13: cannot resolve symbol symbol : class variable location: class com.sap.xi.tf._MM_I_FF_O_RFC_ variable a; ^ 1 error

-


UDF Name: FileName

while creating the UDF, I select the first radio button(Value). not Context and Queue.

I written the below code.

-


DynamicConfiguration conf = (DynamicConfiguration) container

.getTransformationParameters()

.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create(

"http://sap.com/xi/XI/System/File",

"FileName");

String FileName = conf.put(key, a);

return FileName;

-


Thanks,

ANU

Former Member
0 Kudos

Hi,

The Return Filename; statement should work out. You can have one more alternative as to have one global variable "File_Name" in mapping and then pass the value of FileName in it and use anywhere in the mapping.

Thanks

Swarup

SudhirT
Active Contributor
0 Kudos

Hi Anu,

Use exactly the following code with radio button at Value

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 SourceFileName = conf.get(key);

return SourceFileName;

Thanks!

Former Member
0 Kudos

I am using Same Code,

//write your code here

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

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

"FileName");

String SourceFileName = conf.get(key);

return SourceFileName;

But i am not able to get the file name as a source field.

I want to map the Dynamic file name to my RFC input.

If i am passing the constant file name Scenario working fine.

When i am using the UDF, my file name is mapping empty. Means my udf is not working.

My UDF is not returning the File name as a source field.

i appricate your help,

Thanks,

Anu.

Former Member
0 Kudos

Dear ANU,

Are you getting the same Syntax error still or just not getting the file name.

IT shouldn't give any syntax error as code look sytax error free.( unless you place some variable without ur knowledge in any part of the editor)

Regards

Praveen

Former Member
0 Kudos

Thanks a lot..

My code is working fine.

Now my requirment is,

I pick the file, which has time stamp.. i want to remove the time stamp for the file..

Could you please guide me, how can i remove the time stamp from file name..

I appreciate yours help..

Thanks,

ANU

Former Member
0 Kudos

Hi,

For this you need to know the constant timestamp length also. lets say its of 20 chars.

for e.g. testfile_01032009 11:02:20:300

Then Just add below statement in your code before the Return statement.

String SourceFileName1 = new String("");

//select last 20 chars

SourceFileName1 = SourcefileName.substring((SourceFileName.length()-20), SourceFileName.length);

return StringFileName1;

Thanks

swarup

SudhirT
Active Contributor
0 Kudos

While creating the UDF, Please select the first radio button(Value). dont select the Context and Queue. Then the return statement will work.

Thanks!

Former Member
0 Kudos

Hi,

Try this...

String FileName = "" + conf.get(key);

This wont give error even if FileName is null.

Regards