cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic File Name depending on the Source File name

Former Member
0 Kudos

Hi Experts,

I have the problem like, Depending on the source file name, I need to create a new directory and new file name with the same content. So for this i have done the following steps.

1.Create a mapping, Top node mapped with UDF as follows

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

DynamicConfigurationKey key1 = DynamicConfigurationKey.create(

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

"Directory");

String source = conf.get(key);

String tar_fname =source.substring(19,21);

String tar_dirname =source.substring(14,18);

conf.put(key, tar_fname);

conf.put(key1, tar_dirname);

return " ";

2. Done the All the configuration in ID.

But I am getting the following FATAL error. Can you please suggest me what coulbd be the problem

My Error as follows:

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

- <!-- Request Message Mapping

-->

- <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">

<SAP:Category>Application</SAP:Category>

<SAP:Code area="MAPPING">EXCEPTION_DURING_EXECUTE</SAP:Code>

<SAP:P1>com/sap/xi/tf/_MM_Target_File_determined_</SAP:P1>

<SAP:P2>com.sap.aii.utilxi.misc.api.BaseRuntimeException</SAP:P2>

<SAP:P3>Fatal Error: com.sap.engine.lib.xml.parser.Parser~</SAP:P3>

<SAP:P4 />

<SAP:AdditionalText />

<SAP:ApplicationFaultMessage namespace="" />

<SAP:Stack>During the application mapping com/sap/xi/tf/_MM_Target_File_determined_ a com.sap.aii.utilxi.misc.api.BaseRuntimeException was thrown: Fatal Error: com.sap.engine.lib.xml.parser.Parser~</SAP:Stack>

<SAP:Retry>M</SAP:Retry>

</SAP:Error>

Please refer my other thread which help me to solve my problem partially.

Thanks in Advance,

Points will be awarded for helpful anwsers.

Warm Regards,

Vijay

Thanks in Advance

Best Regards,

Vijay

Message was edited by:

Gangisetty Vijaya Bhaskarudu

Accepted Solutions (1)

Accepted Solutions (1)

justin_santhanam
Active Contributor
0 Kudos

Vijay,

Please check the Substring parameter.Is it correct as per your input? One more thing which SP u are working in? I Believe this option is available from SP14 XI 3.0

Best regards,

raj.

Answers (4)

Answers (4)

Markus7
Participant
0 Kudos

Hi Matias

Your tip concerning the file receiver is good. Is it possible to have a CR/LF instead of only LF?

In a lot of scenarios this solution will do, but I see 2 possible problems

- empty lines are deleted

- space characters (space, tab, etc.) at the beginning and end of a line are deleted

-> So the file is not transferred 1:1, which might be a problem, e.g. with pdf, or if the empty lines and chars are required.

Nevertheless a very good idea!

Regards

Markus

Former Member
0 Kudos

Hi Vijay !

I think you are in the right path. I will create an UDF to get the source file name and source directory via DynamicConfiguration, then parse and set new values for those fields, like you do. Please check that in the receiver file adapter you checked the "create target directory" option, to allow the target directory to be created if it not exists.

I understand that your scenario is File to File, where target file should have a dynamic filename and directory.

For the content, you should use the same source and target message types. If your file content is text, you should create a data type like this:

<recordset>

<data max occurs=unbounded>

<rowdata>xxxxxxxxxxx</rowdata>

</data>

</recordset>

where "xxxxxxxxxx" is each line of the source file..

then in receiver file adapter using File Content Conversion, you set "recordset" as recordset structure field and in the below table you should enter "recordset.fieldSeparator" = 'nl' to get a NewLine special character after each row, in the target file.

To debug mapping problems, use the MappingTrace object and see if your udf are good. You cannot try the DynamicConfiguration during the mapping test in Repository, use hardcoded dummy values.

Regards,

Matias.

Former Member
0 Kudos

Hi Vijay,

we have to use the adapter specific attributes(File name) in the receiver file adapter and make use of this file name in mapping..

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

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

conf.put(key, "FileName");

I hope this can help you ....

Regards,

vasanth

Former Member
0 Kudos

Hi vijaya

yes its possible.

you have to create dynamic files and directory with same contnet as u specialed

by using advance udf function where u hv to import FTP related pakages and

and its methods to create and directory and and

use stream to write the content.

by summary i can suggest u:

1> u hv to use dynamic configuration

2> ftp related package in java and its methods to create dynaic directory and filename

3> and stream package to update the content of file..

Regards

Somu.