Function Module return value
When we call a function module how will the sy-subrc value will be set ? Is it based upon the exception value ? say a FM is called and it is returning a value other than 0 and not matches with the eception values, how can we identify why the FM call failed ?
Thanks and Regards,
Srinivas Adavi replied
CALL FUNCTION 'F4IF_DETERMINE_SEARCHHELP' EXPORTING TABNAME = TABNAME FIELDNAME = FIELDNAME selection_screen = selection_screen IMPORTING SHLP = SHLP_TOP EXCEPTIONS FIELD_NOT_FOUND = 1 NO_HELP_FOR_FIELD = 2 INCONSISTENT_HELP = 3 OTHERS = 4.
In the above call, as you can see, the numbers 1, 2, 3 are given by you when you are calling it. The call function will set the sy-subrc to the value that is against the given exception. Within the function module, the exception is raised by its name. So in this function module code, you will see the code like
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 RAISING FIELD_NOT_FOUND.
Then you will get a sy-subrc of 1 because that is the number you gave. But if give a number 10 instead of 1 for FIELD_NOT_FOUND, your sy-subrc will be 10.
If you are getting a value other than the ones specified in exceptions, then you have to trap it in OTHERS exception. This is an exception not raised, but just occured in the function module.
Hope this clarifies.