cancel
Showing results for 
Search instead for 
Did you mean: 

dynamic file name in receiver channal

Former Member
0 Kudos

Hi, All,

I would like to set dynamic file name in receiver channal. My xml payload will be like this:

<file_name>file1.txt</file_name>

<text_content>balabala......</text_content>

I would like to output an text file which text content will be the value of <text_content>, file name will be the value of <file_name> in the xml payload.

Is there anyone could help me?

Helpful answer will be surely awarded. Thanks

Yang

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello Meiying,

If i understand ur query correctly,u want the file name of the out put to come as it is in the input xml...right?

i had come across the same scenario,here is the solution i implemented.

write this UDF

define input parameter String a;

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

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

conf.put(key,a);

return a;

In graphical mapping map the filename from input is given to this UDF and this in turn is given to output any field e.g a node.

should help u out

Former Member
0 Kudos

Hi Meiying,

1. Delete the fields that you dont want like in your target message like "file_name". You dont need it. Delete it from your target message data type.

2. Create UDF based on Ashish Sinha or Mohd Tauseef replies. They are the same.

3. Call the UDF in your map. Now your question might be where do I need to call it when I dont have any target field to map. You need to call the UDF with some other node mapping that would always be true. The UDf will be called with two parameters; first parameter is the source node, second parameter is the field in your source message that has the file name. The target should be the target node. I am pasting the UDF with slight modification to Tauseef's UDF.

Input parameters;

sourcenode

inputfilename

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

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

conf.put(key,inputfilename);

return sourcenode;

4. In the file communication channel (receiver), check "Use Adapter-Specific Message Attributes". As soon as you check it, it will display other check boxes as well. Check "File Name".

The output file that is created will now be created with the file name from the source message field.

I hope this helps.

Regards

Haseeb

Former Member
0 Kudos

Hi, Haseeb,

Thank you for the reply. But I still have questions to be clarify (I am sorry that T never create a UDF).

1. "You need to call the UDF with some other node mapping that would always be true". Is this "other node" in source massage side or in target message side? I guess that is in source massage side, for example: I can map my UDF to field "FileName" in souce massage structure. Because I only have one field "FileText" in target message. It should be mapped to the field "FileText" in source message structure.

2. " first parameter is the source node". This "source node", in my example will be "MT", is that true.

3. "The target should be the target node". Where I put this "target node" in UDF?

4. In the file communication channel (receiver), I have checked everything as you indicated. But what I should put in the "File Name Scheme" under "File Access Parameters" tag. This field is required.

Thank you very much!

Meiying

Former Member
0 Kudos

Meiying,

Can you please provide your source and target structure.

We can then probably give you better instructions as to when to call the UDF and what parameters to pass.

As for the file name field in the channel, type anything in there as it will be ignored in our scenario.

Regards

Haseeb

Former Member
0 Kudos

Hi, Haseeb,

I am so glad for your kind help.

My source structure is like this

<DT_File><FileDirectory>...</FileDirectory><FileName>...</FileName><FileText>....</FileText></DT_File>

My target structure is like this:

<DT_FileOut>><FileText>....</FileText></DT_FileOut>

I would like to output a file which content is the value of <FileText> and filename is specified in field <FileName>, and put this file to the directory which specified in field <FileDirectory> .

Please help me this out. Thank you very much!

Meiying

Former Member
0 Kudos

Hi Meiying,

Try the solution which I am giving below.It will work for sure.

1. Create a xslt mapping between source and target structure as mentioned below instead of message mapping. Please recheck your source field names in case of any spelling mistake in the mapping given below.


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="urn:bakerhughes.com:quote:poc" xmlns:map="java:java.util.Map"
  xmlns:dyn="java:com.sap.aii.mapping.api.DynamicConfiguration"
  xmlns:key="java:com.sap.aii.mapping.api.DynamicConfigurationKey">
<xsl:output method="text"/>
<xsl:param name="inputparam"/>
<xsl:template match="/">
<xsl:variable name="filename" >
<xsl:value-of select="ns0:MT_SourceFile/FileName"/>
</xsl:variable>
<xsl:variable name="filedir" >
<xsl:value-of select="ns0:MT_SourceFile/FileDirectory"/>
</xsl:variable>
<xsl:variable name="dynamic-conf" select="map:get($inputparam, 'DynamicConfiguration')" />
<xsl:variable name="dynamic-key"  select="key:create('http://sap.com/xi/XI/System/File', 'FileName')" />
<xsl:variable name="dynamic-keyDir"  select="key:create('http://sap.com/xi/XI/System/File', 'Directory')" />
<xsl:variable name="dummy" 
        select="dyn:put($dynamic-conf, $dynamic-key, $filename)" /> 
<xsl:variable name="dummyDir" 
        select="dyn:put($dynamic-conf, $dynamic-keyDir, $filedir)" /> 

	<MT_TargetFile>
		<FileText>
		    <xsl:value-of select="ns0:MT_SourceFile/FileText"/>
		</FileText>
	</MT_TargetFile>
	</xsl:template>
</xsl:stylesheet>

2. In the receiver communication channel , use message protocol as "File" and check "Adapter Specific Message Attributes", inside that check "FileName" and "Directory" and set File Construction mode as "Create"

This will work for sure. Let me know in case of any issues.

thanks

amit

reward point if answer is helpful

Former Member
0 Kudos

Hi, Amit,

Thanks for the help. But you bring me a new project. I never create an xslt mapping. So I have to learn it first. :). If you can give me some information on it or step by step instruction, that will be great helpful. Anyway, I love to try. It may take me for a while to get it done. I will let you know. Thanks.

Meiying

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

Hi, Amit,

I am sorry I make you confuse. Actually my problem is where I can put the XSLT mapping? How I can make it to have relationship with target message and source message. I don't know if I make sense this time. Thanks.

Meiying

Former Member
0 Kudos

Hi,

You need to save the code which i sent in .xls file, zip it and add it in imported archives in IR.

Now in your Interface mapping select the drop down with Type as XSL and select your xsl mapping. Hope this answer your questions.

thanks

amit

Former Member
0 Kudos

Hi, Amit,

Thanks for the instruction. It is helpful. I finished everything as you indicated. I tested my scenorio. I got an error saying " Attempt to process file failed with com.sap.aii.adapter.file.configuration.InvalidDynamicConfigurationValueException: The Adapter Message Property FileName provided in the message header has an invalid value: ''

I checked message monitoring. In payload, it is empty. Do you think I need to change xmlns:ns0="urn:bakerhughes.com:quote:poc" in your code to point to my name space? Since in your code, nowhere specify my name space. I checked my xslt mapping and make sure eveything is spelling correct. Thanks.

Meiying

Former Member
0 Kudos

Hi,

Yes you need to change the namespace to point to your namespace.

thanks

amit

Former Member
0 Kudos

Thank you so much, Amit! It works very well!!!!

I reward you points.

Meiying

Answers (4)

Answers (4)

aashish_sinha
Active Contributor
0 Kudos

Hi,

refer this code snippet..

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);

return ourSourceFileName;

for more details check out this blog

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

and this link

http://help.sap.com/saphelp_nw04/helpdata/en/43/03612cdecc6e76e10000000a422035/content.htm

Regards

Aashish Sinha

PS : reward points if helpful

Former Member
0 Kudos

Thanks everybody's kind reply. I am trying and will let you know the result.

Yang

Former Member
0 Kudos

Hi,

You can get dynamic file name by variable substitution but your question is,, you dont want to see that file name in your file content. this is some tricky which i never worked on. So, let me try and get back to you.

Thanks,

Vijay Kumar T.

Former Member
0 Kudos

Yes, you are right. I don't want file directory and file name in my output file. Any idea? Thanks,

Yang

Former Member
0 Kudos

I don't want file directory and file name in my output file

-->

See if this helps

Solution to the problem encountered using Variable Substitution with XI-SP12

To supress filename in output file

Former Member
0 Kudos

Thanks,Mugdha.

I looked at the blog. But I could not find the "Content Conversion Paramters" part in my CC configuraion. I use FTP adapter.

Thanks.

yang

Former Member
0 Kudos

Hi yang,

It will be there in the Mesage Protocol drop down of your FTP Communication Channel.

thanks

amit

Former Member
0 Kudos

The blog seems does not work for me. But thanks any way.

yang

Former Member
0 Kudos

Hi,

Can you not have your target message structure without those fields?

You can set the file name in your mapping as suggested by Aashish Sinha and then check "Use adapter specific variables" in your channel. The file will be named based on the value you assigned to it during mapping.

Regards

Haseeb

Former Member
0 Kudos

Hi, Haseeb,

Thanks for the reply. If it works, I would like to try. I look at the blog which provided by Aashish Sinha.

I have some questions here.

1. do you mean, in sender msg structure would like :<MT><FileName>abc.txt</FileName><FileText>bababa..</FileText></MT>

and in receive side, msg structure will be :<MT><FileText>bababa..</FileText></MT>. In the msg mapping, I need to create a FM using the code that Aashish Sinha provided. Then map it to the field FileName in sender side?

2. how can I set up variable in the Variable Substitution for target File name?

Can you provide more detail? Like what the sender msg and receiver msg structure would like. And how I can do the mapping and set variable?

Thank you very much!

Yang

Former Member
0 Kudos

Please look at the below description from help.sap.com. You can use the below steps to name the file from a value in the payload. You would have to use File Content Conversion to insert the value of the <text_content> in the file.

Variable Substitution (Target Directory/File Name Scheme)

If you set the Enable indicator, you can enter variables for the Target Directory and File Name Scheme. Enter the names of the variables and references in the table.

● Enter each variable that you reference in the Target Directory and File Name Scheme fields without the surrounding percentage sign under Name of Variables in the table.

The variables can refer to attributes of the message header or elements of the message payload.

○ If the variables are to refer to an attribute of the message header, add the prefix message: to the name of the variable under Reference. You can specify the following attributes of the message header:

sender_party, sender_service, receiver_party, receiver_service, interface_name, interface_namespace,

message_id (message ID with hyphens, for example 9fbe1ff1-9a0d-11d9-8665-cbf10a126331)

message_id_hex (message ID in hexadecimal format, for example 9fbe1ff19a0d11d98665cbf10a126331)

For example, if you want to specify the interface name from the message header in the target directory or in the file name scheme, enter message:interface_name as the reference.

If one of the message attributes contains characters that are not permitted in a file name, for example \, /, :, *, ?, ", <, >, |, then these characters are replaced by an underscore ("_").

○ If the variable refers to an element in XML schema, add the prefix payload: to the information under Reference. The reference then comprises a pseudo path description in the form of a comma-separated list with the schema namea,na,nameb,nb,....

namea,nameb,...corresponds to the element name and na,nb,... corresponds to the occurrence of the element name at the respective level in the document.

The description begins at the root of the document and ends at the respective element.

To reference the element that is in bold in the example, the following expression is used: payload:root,1,e1,1,e2,2

The parser searches for the first occurrence of the root element at the first level. It then searches for the first occurrence of e1 at the second level and for the second occurrence of e2 at the third level. The content of the last element (u201CExample Valueu201D) is set as the value for a specified variable.

<?xml version="1.0" encoding="UTF-8" ?>

<root>

<dummy>

<e1>

<e2>Data_1</e2>

<f/>

<g attr="abc">text</g>

<e2>Data_2</e2>

</e1>

</dummy>

<e1>

<e2>illegal/value</e2>

<f/>

<g attr="abc">text</g>

<e2 attr="fghij">Example Value</e2>

</e1>

</root>

Thanks

Praveen M

Former Member
0 Kudos

Hi,

I think you may also refer to this thread:

Thread: receiver determination based on the filename of the incoming xml file

I hope it helps.

Regards,

Lex

Former Member
0 Kudos

Hi,

You can get dynamic filename from payload using variable substitution.

Hope,this thread will give u clear idea.

Go thru below blogs.

Dynamic File Name Part 1

/people/jayakrishnan.nair/blog/2005/06/20/dynamic-file-name-using-xi-30-sp12-part--i

Dynamic File Name Part 2

/people/jayakrishnan.nair/blog/2005/06/28/dynamic-file-namexslt-mapping-with-java-enhancement-using-xi-30-sp12-part-ii

Edited by: Srinisap on Jun 30, 2008 11:13 AM