on 01-31-2011 11:51 PM
Hi All,
i have 2 files - File1 from File2 from 2 different folders- single comm channel FTP (FCC). i have to pass a constant A and B respectively to a field in target structure.
my options are -
either create a new field in source str populating different constants and then map to the target str
or a udf to get the source file name or the source folder so that i can map the constant using the value mapping/FixValue mapping.
please suggest. thanks.
rajib
Hi,
please use the UDF to determine the file name. Then based on file name either pass A or B to your target field.
The code is as given below. Just tweak the code to pass either A or B as per your requirement.
public String G_GetFileName(Container container) throws StreamTransformationException{
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String ourSourceFileName = conf.get(key);
return ourSourceFileName;
Regards,
Deepak.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bhasker,
i have put the below imports like this - com.sap.aii.mapping.api.DynamicConfigurationKey;com.sap.aii.mapping.api.DynamicConfiguration;com.sap.aii.mapping.api.StreamTransformationException;com.sap.aii.mapping.api.StreamTransformation;
and code -
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
String ourSourceFileName = conf.get(key);
return ourSourceFileName;
getting error -
RuntimeException in Message-Mapping transformation: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._MM_File2Bapi_ method G_GetFileName$[com.sap.aii.mappingtool.tf3.rt.Context@5db43aa]
Your coding looks good except import statement not found in the first line. You get runtime exception. This will occur if the file does not reside in the directory.
Basically key is null and you are trying to do lookup using key. If you want to avoid exception during no file exist, you can check not null condition
if(key != null){
String ourSourceFileName = conf.get(key);
}
But still that does not help...for mapping to target fields.
thanks.
ok i think i am near now. am able to pass the file name directly to the target through the udf.
But i have 2 files from different location now and got the file names using this udf. Now both files has dates at the end. so am not able to pass AAA for File1.txt and BBB for File2.txt. am trying this through the fixed value mapping. please suggest.
after the file name extraction code, i have included (* -for date n timestamps):
if(ourSourceFileName.equals("ABC*.txt"))
return "FILE1";
else if(ourSourceFileName.equals("XYZ*.txt"))
return "FILE2";
Go for this option.
either create a new field in source str populating different constants and then map to the target string
UDF can be avoided if you have an easy option.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.