cancel
Showing results for 
Search instead for 
Did you mean: 

same sender file name with a different extension

Former Member
0 Kudos

Hello Friends,

My scenario is I have an xyz.xml file coming and i need to have the same file name in the receiver but with a different extension as xyz.csv and the source file name will not be the same, it will be changing.

Can you please help me on this.this is a bit urgent to me.

Thanks in advance.

Regards,

Kumar

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I believe the only option for you to do this is thru File adapter module where you dynamically set the file name based on the input file name

regards

krishna

Former Member
0 Kudos

Hi,

I have set the adapter specific message attributes in both the sender and the receiver channel to File Name, I am getting the same file name in the target but the file extension is not changing.

Please help.

Regards,

Kumar

Former Member
0 Kudos

Hi

>>I have set the adapter specific message attributes in both the sender and the receiver channel to File Name

This wont do the trick.

What you have to do is to get the file name in the receiver File adapter module and change the extension to whatever you want and the push the file from the Module by using a ftp library like apache commons.

regards

krishna

Former Member
0 Kudos

Hello Krishna,

Can you please guide me on how to do this?

Regards,

Kumar

Former Member
0 Kudos

Hi

Follow the "how to guide to create adapter modules"

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/02706f11-0d01-0010-e5ae-ac2...

Within the adapter module , read the source file name with a code like

obj = inputModuleData.getPrincipalData();

String filename = "";

msg = (Message) obj;

XMLPayload xmlpayload = msg.getDocument();

Channel ch = new Channel(moduleContext.getChannelID());

filename = ch.getValueAsString("file.sourceFileName");

and then later set the name of the file for the receiver

regards

krishna

justin_santhanam
Active Contributor
0 Kudos

Kumar,

Write <b>UDF</b> with <b>no input</b> parameters.

DynamicConfiguration conf = (DynamicConfiguration) container

.getTransformationParameters()

.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create(

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

“FileName”);

String fname = conf.get(key);

StringTokenizer st = new StringTokenizer(fname,".");

String[] name = new String[2];

while(st.hasMoreElements())

{

for(int i=0;i<1;i++)

{

name<b>[</b>i<b>]</b>=st.nextElement();

}

}

String finalname = name[0]+".csv";

conf.put(key,finalname);

<b>Mapping Logic</b>

UDF -


> Target Rootnode.

Make sure that u checked the Adapter specific message attributes in both comm.channel.

If you have doubts reply back.

Best regards,

raj.

Message was edited by:

Raj

Former Member
0 Kudos

Hi

Go ahead with the method suggested by "Raj" for a easier solution

regards

krishna

Former Member
0 Kudos

Hello Raj,

Thanks for the help. I have created the UDF and when i test my mappings i am getting an error as

Source code has syntax error: /usr/sap/DXI/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Map39000520257b11dc82766685770b97b3/source/com/sap/xi/tf/_MM_COAL_LABSAMPLE_.java:249: illegal character: \8220 ?http://sap.com/xi/XI/System/File?, ^ /usr/sap/DXI/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Map39000520257b11dc82766685770b97b3/source/com/sap/xi/tf/_MM_COAL_LABSAMPLE_.java:250: illegal character: \8220 ?FileName?); ^ /usr/sap/DXI/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Map39000520257b11dc82766685770b97b3/source/com/sap/xi/tf/_MM_COAL_LABSAMPLE_.java:250: illegal character: \8221 ?FileName?); ^ /usr/sap/DXI/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Map39000520257b11dc82766685770b97b3/source/com/sap/xi/tf/_MM_COAL_LABSAMPLE_.java:250: ')' expected ?FileName?); ^ 4 errors

Please let me know what mistake i have done.

Regards,

Chaitanya

justin_santhanam
Active Contributor
0 Kudos

Kumar,

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

Also import java.util.*; in the import section of UDF.

Please make sure abt the above line. Its throwing error over there.

Best regards,

raj.

justin_santhanam
Active Contributor
0 Kudos

Kumar,

Try the below.

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

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

String fname = conf.get(key);

StringTokenizer st = new StringTokenizer(fname,".");

String[] name = new String[2];

while(st.hasMoreElements())

{

for(int i=0;i<1;i++)

{

name<b>[</b>i<b>]</b>=(String)st.nextElement();

}

}

String finalname = name[0]+".csv";

conf.put(key,finalname);

return "";

Former Member
0 Kudos

Hello Raj,

I have checked the above line but still the issue is same.

/usr/sap/DXI/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Mapedb3fac0257c11dc8ade6685770b97b3/source/com/sap/xi/tf/_MM_COAL_LABSAMPLE_.java:248: illegal character: \8220 DynamicConfigurationKey key = DynamicConfigurationKey.create(?http://sap.com/xi/XI/System/File?,?FileName?); ^ /usr/sap/DXI/DVEBMGS01/j2ee/cluster/server0/./temp/classpath_resolver/Mapedb3fac0257c11dc8ade6685770b97b3/source/com/sap/xi/tf/_MM_COAL_LABSAMPLE_.java:249: ')' expected String fname = conf.get(key); ^ 2 errors

Please help.

regards,

Kumar

justin_santhanam
Active Contributor
0 Kudos

Kumar,

Please try the above code. If you execute the mapping then u will get Runtime exception. Then its fine.

Now run your scenario. And see the output, and lemme know the progression.

Best regards,

raj.

Former Member
0 Kudos

Hello Raj,

Now I am getting the file extension as .csv but the file name is coming as xml.csv.

Please let me know.

Thanks & Regards,

Kumar

Former Member
0 Kudos

Hi Raj

I have given my file name as test.xml, but now i am getting it as xml.csv.

Please help...

Regards,

Kumar

justin_santhanam
Active Contributor
0 Kudos

Kumar,

Please try the below.

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

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

String fname = conf.get(key);

StringTokenizer st = new StringTokenizer(fname,".");

String finalname = (String)st.nextElement()+".csv";

conf.put(key,finalname);

return "";

Best regards,

raj.

Former Member
0 Kudos

Hello Raj,

This code is placing the file as with the same source file name and with the same extension.

Please help.

Regards,

Kumar

Former Member
0 Kudos

Hello Raj,

It is working....Loads of Thanks !!!!!!!!!!!!!!!!

Points awarded!!!!!!!!!!

Thank u once agian

Regards,

Kumar

justin_santhanam
Active Contributor
0 Kudos

Sorry Kumar,

Juz now came from meeting. Good to hear its working!!

Best regards,

raj.

Answers (0)