cancel
Showing results for 
Search instead for 
Did you mean: 

Return And Exception statements in UDF

Former Member
0 Kudos

Hi All,

I am trying to use UDF in my scenario.

Can anyone please say how to add return statement in UDF as bcuz default return type is void.

I am not able to change it .

Also I tried to add exception in my function but again I failed .

Can anyone help me to solve both of these problem please?

I am using PI 7.0

Thanks

Rabi

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Return Value depends on Execution type which you select while writing UDF.

If the Execution type is Single values then return value is String,if the execution type is All values of Context or All values of Queue then return resultList.

Check the below Link

Former Member
0 Kudos

Hi All,

This is great .

Thanks you all.

But I want to know how can I add exception to the method I am declaring .

Whether this is possible or not in PI.

Please help me to solve this.

Thanks

Rabi

Former Member
0 Kudos

To declare an Exception field as a parameter in the UDF, you need to declare a parameter typed "Exception".

If you want to know if an exception can be thrown, this is not possible in my opinion (how can be managed in graphical mapping??)

Answers (3)

Answers (3)

Former Member
0 Kudos

To return an exception, you can declare a variable type Exception in Return Definition of UDF.

Then use the TRY-CATCH statement in the UDF to get the exception.

try {
//Code
} catch (Exception e) {
    // Exception
    String lv_exception_text = e.getMessage().toString();
    return lv_exception_text.
}

Shabarish_Nair
Active Contributor
0 Kudos

if you are using a simple UDF, you can write the return statement to pass the output value

else in case of advanced UDF, you will use the resultlist

ex. http://wiki.sdn.sap.com/wiki/display/Snippets/UDFforZeroPaddingon+Left

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

Can anyone please say how to add return statement in UDF as bcuz default return type is void.

I am not able to change it .

Return type is not possible for context and queue type UDF. Use result.addValue(String); instead.

Hope this helps,

Mark