cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic file naming

Former Member
0 Kudos

Hi Experts,

I am thinking to use UDF in the message mapping for dynamically creating the reciever file name i.e, <source_file_name>_<timestamp>.xml (Timestamp format is hh-mm-ss).

Scenario is to Archive files(.xml and .txt) on a FTP server.

Please help me in writing UDF, which of the source and target fields I should map to UDF and how to configure the File(FTP) adapter.

Thanks in advance,

MK

Accepted Solutions (0)

Answers (1)

Answers (1)

justin_santhanam
Active Contributor
0 Kudos

Mk,

See the below code and the mapping logic.

-- Check the ASMA File for both sender/receiver channels.

Write the below code UDF in mapping program

//Get Input Date and Time. Don't pass anything to this UDF except the Date.

//Map the output to the root node of the target.

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

String ret = fname"_"Date;

return "";

Hope it helps!

If u face any issues, let us know.

raj.

Former Member
0 Kudos

Hi Raj,

After creating interface objects and on testing the message mapping I got the below error,

RuntimeException in Message-Mapping transformation: Runtime exception during processing target field mapping /ns0:recv_mt. The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._ven_mm_ method DynamicFN$[, com.sap.aii.mappingtool.tf3.rt.Context@787f8a7a]

please suggest to rectify it.

Thank you,

MK

justin_santhanam
Active Contributor
0 Kudos

MK,

These parameters are runtime values. Hence if u do testing in Message Mapping it will throw an exception. Execute the scenario and see the results.

raj.

Former Member
0 Kudos

Hi Raj,

on executing the scenario, i got the following error,

Delivery of the message to the application using connection File_http://sap.com/xi/XI/System failed, due to: com.sap.aii.af.ra.ms.api.RecoverableException: Error during variable substitution: com.sap.aii.adapter.file.varsubst.VariableDataSourceException: The following variable was not found in the message payload: var1: com.sap.aii.adapter.file.configuration.DynamicConfigurationException: Error during variable substitution: com.sap.aii.adapter.file.varsubst.VariableDataSourceException: The following variable was not found in the message payload: var1.

the way i configured Reciever channel is:

File name: %var1%.xml

Variable substitution:

var1: payload:mt_venr,1

(where mt_venr is the reciever message type)

Mapping done is:

mt_vens

|_ type.......|DynamicFN|........mt_venr

|_record...................................record

........| _ field1 ............................... field1

........| _ field2 ................................ field2

Please help to rectify the error.

Thank you,

MK

justin_santhanam
Active Contributor
0 Kudos

MK,

Why u are using Varialble Substitution in Receiver Channel? No need for Variable substitution. See Variable substitution is the alternate solution for using Dynamic Configuration. In the receiver channel just check ASMA that's it. In comm.channel under parameters File name give whatever u want.

The logic is the UDF which u wrote will set the File properties headers in runtime. Hence don't confuse with it.

raj.

Former Member
0 Kudos

Hi Raj,

Rectified the above error, but reciever file name i got is same as sender file name i.e, without timestamp.

please tell me how to pass Date to the UDF.

Thanks in advance,

MK

justin_santhanam
Active Contributor
0 Kudos

MK,

Please keep this as reference http://sapient.xi.googlepages.com/xi-excellentintegration

Take the standard function DATE , double click on it now select the pattern whihc u want it. Then pass it to the UDF.

raj.

Former Member
0 Kudos

thanks Raj,

the UDF i wrote is:

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

java.util.Date d= new java.util.Date();

int dt = d.getDate();

String fname = conf.get(key);

String ret = fname"_Price_"dt;

return "fname";

but reciever file name is same as sender file name i.e, with out timestamp.

suggest further to rectify.

thank you

justin_santhanam
Active Contributor
0 Kudos

MK,

Sorry Buddy forget to include one line of code.

Use the below code

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

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

java.util.Date d= new java.util.Date();

int dt = d.getDate();

String fname = conf.get(key);

String ret = fname"Price"dt;

conf.put(key,ret);

return " ";

raj.

Former Member
0 Kudos

Thanks Raj,

I am not getting source data into target file:

for example:

source file:

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

<ns0:send_mt xmlns:ns0="ttp://saf.com/pro/arch">

<record>

<vendname>Mic</vendname>

<vendid>121</vendid>

</record>

<type/>

</ns0:send_mt>

Reciever file:

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

<ns0:recv_mt xmlns:ns0="http://saf.com/pro/arch">

<type> </type>

</ns0:recv_mt>

And the receiver file name i got is :

file01.xmlprice6 (If sender file name: file01.xml )

but the requirement is file01_price<timestamp>.xml

Please suggest further.

Thank you.

Former Member
0 Kudos

Hi Raj,

rectified and able to get source data.

But the reciever file name is

file01.xmlprice6 (If sender file name: file01.xml )

the requirement is file01_price<timestamp>.xml

Please suggest further.

Thank you.

justin_santhanam
Active Contributor
0 Kudos

MK,

If you want the above code to work as per ur reqmt, then follow the below code. I thought u will do all the String functions...

As I said earlier, while creating UDF create it with single input argument.

Now Double click on the CurrentDate(standard function) and give the format that looks like

ddMMyyyy HH-mm-ss

Now your mapping must look like

CurrentDate - UDF-Rootnode of target.

//Let consider ur input argument name is input_date

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

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

java.util.Date d= new java.util.Date();

int dt = d.getDate();

String fname = conf.get(key);

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

String ret = st.nextToken()"_Price" input_date"."st.nextToken();

conf.put(key,ret);

return " ";

I hope it helps u now!!

raj.

Former Member
0 Kudos

Thanks Raj,

On execution of the scenario, i am getting the following error,

Success Write to FTP server "xxx.xx.xx.x", directory "/sap/out/target", -> file "xi_input_Price07/02/2008 05/29/30.xml"

Success Transfer: "BIN" mode, size 158 bytes, character encoding -

Success Connect to FTP server "xxx.xx.xx.x", directory "/sap/out/target"

Error Attempt to process file failed with com.sap.aii.adapter.file.ftp.FTPEx: 550 xi_input_Price07/02/2008 05/29/30.xml: The system cannot find the path specified.

I have given the correct FTP server and directory path and they were working fine before.

Please suggest to resolve it.

justin_santhanam
Active Contributor
0 Kudos

Mk,

Go to desktop try to create a filename with 10/20/2007.xml , let me know if it allows u to create. It won't MK. You can have file name like 10-20-2007.xml. Hence try to give the date format like this.

raj.

Former Member
0 Kudos

Thanks Raj,

I received small change in the requirement, that is to archive all the files starting with file1.*

for this, we don't really need to develop design objects, but to determine target file name from the source file name in the required format i have to use the mapping.

so can i change the present scenario as below:

Just create 1 datatype, 2 message types , 2 interfaces

Data type :

ven_dt

|___filename.

Mapping:

currentdate---->DyanmicFN--->filename

will i get the source data in target file.

thank you,

MK

Former Member
0 Kudos

.

justin_santhanam
Active Contributor
0 Kudos

MK,

Your source xml has only one field?

raj.

Former Member
0 Kudos

Hi Raj,

as i need to archive two different type of files, is it not possible to do with out knowing source structure.

Please suggest further.

Thank you,

MK

justin_santhanam
Active Contributor
0 Kudos

Mk,

It's very long back, could you please tell what u want to do? you want to archive two files?

raj.

Former Member
0 Kudos

Sorry Raj, got stuck into some support work.

i have to archive two different type of files ( total 8 files ).

justin_santhanam
Active Contributor
0 Kudos

Mk,

Can u explain ur scenario from end to end. The previous discussions were on dynamic file name. So not clear abt ur reqmt. is it file to file scenario?

raj.

Former Member
0 Kudos

Thanks for your quick responses.

Yes, it is a file to file(FTP) scenario. where we need to archive two different type files within a FTP server.

and the requirement is that archive file name = <source file name>_Price_<timestamp>.

justin_santhanam
Active Contributor
0 Kudos

MK,

So if u mean two different file types mean the two files with different structures also or only the file name is different.

raj,.

Former Member
0 Kudos

yes, files with different structures.

justin_santhanam
Active Contributor
0 Kudos

MK,

Since all the source are different strcutures, you need to create n.no of interfaces+ n.no of scenarios. You can apply the same logic for mapping which we discussed earlier. Could you tell me where u got stuck up, so that I can take up from ther!

raj.

Former Member
0 Kudos

As i got two different type of files and we want to archive file content as is( so we don't need any mapping between source and target message). Is it possible to pass the two different messages to the target directory through the same interface.

i got stuck at defining Datatype, as one of the file is a txt file of very huge size.

Thank you,

MK

nisarkhan_n
Active Contributor
0 Kudos

it is possible to create two different messages in thesame interface provided you maintain differnt XML, WSDL for each in IR and in ID....untill and unless the struvcture are same.

Former Member
0 Kudos

Hi Raj,

Got the other requirement, interface to be available to run manually at any point of time to archive files.

how can we achieve it. And the other thing is XI may archive an incomplete file, because source files take 40 min to get completely loaded into the source directory(on a daily basis).

Please suggest to resolve the issue.

Thank you,

MK

nisarkhan_n
Active Contributor
0 Kudos

Xi will not archive incomplete file if you tell it the file is incomplete to do this..

do the following to take care of this issue

"file.checkFileModificationInterval=<msecs>

Use this parameter to define a length of time (default value: 0) for the file/FTP adapter to wait after the file has been read to see if the file length changes. If this is the case, the system repeats the read procedure. This is useful if the files to be imported by the adapter are generated dynamically without being locked on the operating system level (for example, files received from FTP servers). Without this workaround, the file/FTP adapter cannot recognize whether the generation of the file is complete in such applications with operating system functions."

check this for more details:

http://help.sap.com/saphelp_nw2004s/helpdata/en/0d/00453c91f37151e10000000a11402f/content.htm