cancel
Showing results for 
Search instead for 
Did you mean: 

udf to pass constant corrsponding to 2 file names from different location

Former Member
0 Kudos

if i have one source file, i m able to pass the file name directly to the target through the udf below:

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;

But i have 2 files from different location. Now both files has dates at the end. how can i pass AAA for File1.txt and BBB for File2.txt. .

after the above code, i have included below code too, but not working(*-for date n timestamps):

if(ourSourceFileName.equals("ABC*.txt"))

return "FILE1";

else if(ourSourceFileName.equals("XYZ*.txt"))

return "FILE2";

please suggest

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Rajib,

Try this:

if(ourSourceFileName.contains("ABC"))

return "FILE1";

else if(ourSourceFileName.contains("XYZ"))

return "FILE2";

Regards,

Aravind

Edited by: ajnayak on Feb 2, 2011 5:10 AM

Former Member
0 Kudos

hi,

am getting error on activating object with this code u provided ...

Source code has syntax error: /usr/sap/DXI/DVEBMGS31/j2ee/cluster/server0/./temp/classpath_resolver/Map430093802ee311e08d0700144f1e71f0/source/com/sap/xi/tf/_MM_ZBAPI_.java:840: cannot resolve symbol

symbol : method contains (java.lang.String) location: class java.lang.String if(ourSourceFileName.contains("ABC*.txt")) ^

cannot resolve symbol

symbol : method contains (java.lang.String) location: class java.lang.String else if(ourSourceFileName.contains("XYZ2*.txt"))

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Java String class does not have method contains... Use equals("txt")

Former Member
0 Kudos

Hi Basker,

Error in activating object in IR - heres the total code i have used for this purpose. plz help in getting this.

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;

if(ourSourceFileName.equals("SOURCE_1*.txt"))

return "File1";

else if(ourSourceFileName.equals("SOURCE_2*.txt"))

return "File2";

Source code has syntax error: /usr/sap/DXI/DVEBMGS31/j2ee/cluster/server0/./temp/classpath_resolver/Map27461f402eff11e0898d00144f1e71f0/source/com/sap/xi/tf/_MM_UPDATE_.java:839: unreachable statement if(ourSourceFileName.equals("SOURCE1_*.txt")) ^ /usr/sap/DXI/DVEBMGS31/j2ee/cluster/server0/./temp/classpath_resolver/Map27461f402eff11e0898d00144f1e71f0/source/com/sap/xi/tf/_MM_UPDATE_.java:844: missing return statement } ^ 2 errors

Former Member
0 Kudos

The error is due to function doesnt return any values. you need to change the condition statement in the UDF. Try use the below,

Instead of equals use "startswith" Method.

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;

if(ourSourceFileName.startswith("SOURCE_1"))

return "File1";

else if(ourSourceFileName.startswith("SOURCE_2"))

return "File2";

else

return "";

Regards

Ramg

Former Member
0 Kudos

same kinda error on activating IR:

Source code has syntax error: /usr/sap/DXI/DVEBMGS31/j2ee/cluster/server0/./temp/classpath_resolver/Map54bc18702f0511e0c01b00144f1e71f0/source/com/sap/xi/tf/_MM_UPDATE_.java:840: cannot resolve symbol symbol : method startswith (java.lang.String) location: class java.lang.String if(ourSourceFileName.startswith("source1")) ^ /usr/sap/DXI/DVEBMGS31/j2ee/cluster/server0/./temp/classpath_resolver/Map54bc18702f0511e0c01b00144f1e71f0/source/com/sap/xi/tf/_MM_UPDATE_.java:842: cannot resolve symbol symbol : method startswith (java.lang.String) location: class java.lang.String else if(ourSourceFileName.startswith("source2")) ^ 2 errors

am i missing on the import parameter or anywher?

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Error in code method name startsWith() Rememeber Java is case sensitive.

Former Member
0 Kudos

same error baskar, u gotta help me man..tried many options but failed in activating only.

Source code has syntax error: /usr/sap/DXI/DVEBMGS31/j2ee/cluster/server0/./temp/classpath_resolver/Mape9cb9d202f1c11e0c90800144f1e71f0/source/com/sap/xi/tf/_MM_UPDATE_.java:840: unreachable statement if(ourSourceFileName.startsWith("ABC")) ^ 1 error

Former Member
0 Kudos

gr88 issue resolved. thanks a lot baskar..

Answers (1)

Answers (1)

Former Member
0 Kudos

the problem is the 2 file names from diff locations are not constant - they are coming with the date n timestamps. so in the condition I have to give ABC_.txt then File1 else if XYZ.txt then File2.

can someone plz suggest?

the udf got the file name and i am putting If Then Else. it is working for constant file names but is i put *.txt , not going thru the condition