cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to read a file name and use some of its contents to map fields in target.

Former Member
0 Kudos

I have a scenario where I need to take the month and year from the file name and map it to suitable fields in the target. Ex - filename_apr2014 from this i should be able to read the month and year and map it. How to do this? I tried the udf -

public String getFileName(Container container){

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

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;

got this error while testing the mapping -

Runtime exception when processing target-field mapping /ns0:MT_<<>>_Output/I<<>>; root message: Exception:[java.lang.NullPointerException: while trying to invoke the method com.sap.aii.mapping.api.DynamicConfiguration.get(com.sap.aii.mapping.api.DynamicConfigurationKey) of a null object loaded from a local variable at slot 2] in class <<>> method getSourceFileName[com.sap.aii.mappingtool.tf7.rt.Context@5b04fc0f]

See error logs for details  

Accepted Solutions (1)

Accepted Solutions (1)

former_member184720
Active Contributor
0 Kudos

Hi Satish - You declared "conf" twice.

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


UDF -


String filename    = "";

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

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

filename = conf.get(key);

return filename;



-------------------------


And did you define the variable slot 2 in any of your UDF's?


The above UDF return the filename and you should handle the sub string later..

Former Member
0 Kudos

I did not include any variable. conf was pasted twice. thanks for your reply

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello,

>>got this error while testing the mapping -

U cannot test DC using message mapping test tab (but u can test ur mapping apart from DC if you put try/catch in ur DC code)

DC will read filename at runtime and u will get to see the same when u execute E2E test.

Note - updating try/catch statement.

Thanks

Amit Srivastava

Former Member
0 Kudos

please let me know the udf with try catch block.

former_member184720
Active Contributor
0 Kudos

try

{

String filename    = "";

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

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

filename = conf.get(key);

return filename;

}

catch(Exception e)

{

     String exception = e.toString();

      return exception;

}

But you won't be able to test the dynamic file name here unless you do E2E

Former Member
0 Kudos

Thanks

former_member184720
Active Contributor
0 Kudos

Please close the thread if your issue has resolved..