cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic file name error

former_member183906
Active Contributor
0 Kudos

Hi,

I want file name as output in a target message field. I have SAP PI 7.1.

What will be input and what will be java code for it.

Now, i am passing a constant null value as input to UDF which has below code.Its giving error.

public String getFileName(String var1, Container container) throws StreamTransformationException

{

String S= "";

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

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

S= conf.get(key);

return S ;

}

Now I am getting below error while testing it in message mapping tab :

Runtime exception when processing target-field mapping /ns1:Mail/Subject; 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 an object loaded from local variable '<4>'] in class com.sap.xi.tf._mm_HR_to_MailReceive_ method getFileName[, com.sap.aii.mappingtool.tf7.rt.Context@58dca53d]

Please guide on it.

regards

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

Hi SAP PI,

               The code in UDF seems to be ok. The settings in sender file adapter should be as shown below

the UDF does not require any input variable

public String getFileName(Container container) throws StreamTransformationException

{

String S= "";

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

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

S= conf.get(key);

return S ;

}

As Amit Srivastava has rightly pointed out the UDF will give errors during testing without try catch block.  I feel if you would run the scenario end to end , there will be no errors even without try/catch block.

Regards

Anupam

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello,

U can't test the DC code at mapping level..it will only work at runtime.

However, if u want to test ur mapping (apart from DC) at design time then use try/catch block in ur UDF code.

http://scn.sap.com/community/pi-and-soa-middleware/blog/2009/03/26/dynamic-configuration-vs-variable...

Thanks

Amit Srivastava

Former Member
0 Kudos

HI,

The udf will work at runtime level only and it will be available for receiver communication channel to create the file name from mapping. 

I think you can't capture the file name in target field.

Thanks,

Satish.