on 12-23-2009 8:05 AM
Hi...
I n file to file sceanrio, i need to rename the existing target file name...
I have searched in SDN. i have found like we can achive it by batch program.
can you please help how to do this...?
Regards,
Leela
Give some proper example, becasue target file name can be set as per you wish in Receiver File Adapter. Else if you need to some other things in you target file name then you have to use Dynamic Configuration in your message mapping. If this is the case then search on SDN, ther is a blog written by Michal on Dynamic configuration that will help you..
Regards,
Sarvesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Leela,
Try this udf
import java.io.File in the udf code
old_name = old filename
dir = directory
new_name = new filename
String old_file = dir + old_name
File oldfile = new File(file_name);
if(!oldfile.exists()) {
System.exit(0);
}
String new_file = dir + new_name;
File newfile = new File(new_name);
boolean Rename = oldfile.renameTo(newfile);
if(!Rename) {
System.exit(0);
}
Regards
Suraj
> We need to chjeck the target directory and filename is present or not.Then we need to rename the target filename with the loctaion.
Do you mean there will be always only one file at any time?
You have to write the UDF for Dynamic Configuration in order to rename the file with your location.
UDF Code
You have to pass you location name to this UDF in your mapping.
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters()
.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String SourceFileName = location;
conf.put(key, SourceFileName);
return "";
Note: You have to set the ASMA settings under Advanced Tab in both the adapters.
Now you second requirement is to first check if target directory and filename is present or not.
So this UDF has no control to check if file is present or not. The UDF will always write the filename with location.
Probably to perform this check before writing the file name you can try with
"Run operationg system command before message processing", otherwise you may have to write an adapter module for this.
Regards,
Sarvesh
> Tto perform the check before writing the file name is there is no other option with UDF ? other than "Run operationg system command before message processing", or an adapter module for this.
Well my ans for above ques is "NO". May be somebody from the forum can suggest you some other solution.
If you explain the whole mechanism step by step then also we may find some other alternate solution.
Hi Suraj,
I have tried the code which you have provided. But it showing the below errors.
Function fileRename, Line 1:
operator + cannot be applied to java.lang.String[],java.lang.String[] String old_file = dir + old_name; ^
Function fileRename, Line 2:
cannot find symbol symbol : variable file_name location: class com.sap.xi.tf._MM_FILETOFILE1_ File oldfile = new File(file_name);
Regards,
Leela
Hi Leela,
>>operator + cannot be applied to java.lang.Stringhttp://],java.lang.String[ String old_file = dir + old_name; ^
Hope you have three input to the UDF and all are of type string and not string array... also the udf is a simple udf.
String old_file = dir + old_name;
File oldfile = new File(old_file);
if(!oldfile.exists()) {
System.exit(0);
}
String new_file = dir + new_name;
File newfile = new File(new_name);
boolean Rename = oldfile.renameTo(newfile);
if(!Rename) {
System.exit(0);
}
return;
PS: Made few adjustment in the code. Use this and check
Regards
Suraj
HIi.. Suraj,
After replacing with the new code, i am getting the below error.
Function fileRename, Line 1:
operator + cannot be applied to java.lang.String[],java.lang.String[] String old_file = dir + old_name; ^
Function fileRename, Line 6:
operator + cannot be applied to java.lang.String[],java.lang.String[] String new_file = dir + new_name; ^
Function fileRename, Line 7:
cannot find symbol symbol : constructor File(java.lang.String[]) location: class java.io.File File newfile = new File(new_name);
Regards,
Leela
Hi Suraj...
Thanks for your code.... I am using Advanced UDF. I have changed to simple udf. Now it is not showing any errors.
While Testing... it is showing the below error..in moni.
<SAP:Code area="MAPPING">JCO_SYSTEM_FAILURE</SAP:Code>
<SAP:P1>connection to partner 'loopback:0' broken / CPIC-CALL: 'ThSAPCMRCV' : cmRc=20 th</SAP:P1>
Regards,
Leela
User | Count |
---|---|
85 | |
10 | |
9 | |
9 | |
6 | |
6 | |
6 | |
5 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.