on 02-06-2008 12:29 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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.
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.
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
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.
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.
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.
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.
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
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
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
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
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.