Non class-based exception can be used in functions and methods. Below I will show you how.
A. Creating a non class-based in a function.
Enter your variable in the exception parameter of your function in se37. Make sure to unmark the exception classes check box.
Then, inside your function, you can trigger the exception by raising it. The syntax is shown below:
IF sy-subrc <> 0.
RAISE ex_error.
ENDIF.
The calling program that calls the function should capture the exception as shown below:
CALL FUNCTION 'Z_CUSTOMER_INFO'
EXPORTING
kunnr = wa_main-kunnr
bukrs = wa_main-bukrs
IMPORTING
address1 = address1
address2 = address2
EXCEPTION
EXPORTING
kunnr = wa_main-kunnr
bukrs = wa_main-bukrs
IMPORTING
address1 = address1
address2 = address2
EXCEPTION
ex_error = 1.
IF sy-subrc = 1. "exception value will bee assigned to sy-subrc
MESSAGE 'ERROR OCCURRED'TYPE 'E' DISPLAY LIKE 'I'.
ENDIF.
Watch out for my next blog, the class-based exception.
No comments:
Post a Comment