cancel
Showing results for 
Search instead for 
Did you mean: 

Get source file name in the structure itself or in the payload

Former Member
0 Kudos

Hi everyone,

I have a task regarding mapping

In my structure , i defined a field for Filename . What I need is, what ever source file name am sending, that should be mapped into this filed.

If am sending inputfile.txt.

My output file should appear like this,

<?xml version="1.0"?>

         <message id=u201DmessageIDu201D>

                 <header>

                         <filename>D:\\inputfile.txt</filename>
                 </header>

                 <body>

                          FileContent

                 </body>

         </message>

Any help would be appreciated. Do I need to create any UDF. If So please provide.

Regards,

Varun

Accepted Solutions (1)

Accepted Solutions (1)

varun_k
Contributor
0 Kudos

Hii,

Thanks everyone for your replies. If I use the specified UDF, I am getting error as

key is already defined in FnameDir$(java.lang.String,com.sap.aii.mappingtool.tf3.rt.Container)

Regards,

Varun

santhosh_kumarv
Active Contributor
0 Kudos

Hi Varun,

are u using the same UDF that I replied. also note that the variable key should be declared only once.

Use this without changing any thing. It works for me...

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
 
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
 
String ourSourceFileName = conf.get(key);
key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
 
String dir =  conf.get(key);
 
return dir+'/'+ourSourceFileName;

Also let us know where do you het this error..

Thanks

SaNv...

Former Member
0 Kudos

correction to UDF

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
 
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String ourSourceFileName = conf.get(key);
 
DynamicConfigurationKey key = 
DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
String directory =  conf.get(key);
//concatenate directory and filename
 
return  concatenatedString;

still if same problem comes then use 2 different UDF and split filename and directory code.. then using concat function you can get final string

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi Varun,

Please check whether the Message type attribute of the file adapter is rightly configured or not.Please do the needfull over there also.

Thanks,

Arijit

Former Member
0 Kudos

After performing the above said functions.

perform a variable substitution at the receiver channel

File name scheme %var%.extension

Enable Variable substitution

var -->payload:messageid,1,header,1,filename,1

Former Member
0 Kudos

dont refer the above link..it appers to be broken

prashant

Former Member
0 Kudos

Hi,

i think this will help u...

http://torials/XI/Variable/substitution.htm

Prashant

Former Member
0 Kudos

use this UDF

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

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

DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
String directory =  conf.get(key);
//concatenate directory and filename

return  concatenatedString;

UDF---> filename

santhosh_kumarv
Active Contributor
0 Kudos

>>Do I need to create any UDF. If So please provide.

Yes. You need to use UDF.

1. In the sender File cc check the option Set Adapter-Specific Message Attribute, Filename and Directory.

2.Use this UDF.

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

String dir =  conf.get(key);
 
return dir+'/'+ourSourceFileName;

map the output of the UDF to the target structure

Thanks

SaNv...

Former Member
0 Kudos

Hi,

Yes, you have to create the UDF for this.

Refer this blog by Michal Krawczyk.

Rgds,

Yuga