2007 Jun 25 8:16 AM
in a function module if it is not returning any data and if we give a raise stament
suppose...functional module.
if sy-subrc <> 0.
raise ..statement
endif.
if this tihng happens then will it give short dump or some thing else will happen
what happens when a raise statement is triggered
can you please give a brief idea about it.
2007 Jun 25 8:36 AM
No it will not shortdump if you RAISE the exception correctly. The return code (sy-subrc) will be set according how the FM is called by the calling program.
E.g. of a FM raising an exception (Using RAISE statement), let's call this ZFM
Import param: i_var1 type i, i_var2 type i, i_oper type c length 1.
Export param: e_res type i.
Exception: divide_by_zero, invalid_operation.
FM Code:
case i_oper.
when '+'.
e_res = i_var1 + i_var2.
when '-'.
e_res = i_var1 - i_var2.
when '*'.
e_res = i_var1 * i_var2.
when '/'.
if i_var2 = 0.
raise divide_by_zero.
else.
e_res = i_var1 / i_var2.
endif.
when others.
raise invalid_operation.
endcase.Now suppose calling program ZXYZ calls the above FM ZFM:
data: v_res type i.
call function 'ZFM'
exporting
i_var1 = 5
i_var2 = 0
i_oper = '/'
importing
e_res = v_res
exceptions
divide_by_zero = 1
invalid_operation = 2.At this point, after the FM has been executed, the return code will be set to 1 because exception would have been raised in the FM that divide by zero is not allowed. After this the calling program could process further as per the return code exported by the FM:
case sy-subrc.
when 1.
message e000 with 'Division by 0 is not allowed'.
when 2.
message e000 with 'Incorrect operator used'.
endcase.Hope this helps!
in a function module if it is not returning any data and if we give a raise stament
suppose...functional module.
if sy-subrc <> 0.
raise ..statement
endif.
if this tihng happens then will it give short dump or some thing else will happen
what happens when a raise statement is triggered
can you please give a brief idea about it.
2007 Jun 25 8:19 AM
Hi
To understand message hanlding in FMs...refer this link
<a href=" http://help.sap.com/saphelp_nw04/helpdata/en/9f/db96ef35c111d1829f0000e829fbfe/frameset.htm ">http://help.sap.com/saphelp_nw04/helpdata/en/9f/db96ef35c111d1829f0000e829fbfe/frameset.htm</a>
Regards
Raj
2007 Jun 25 8:25 AM
Hi,
In any function module if you are raising an exception, you must catch this in the caller program. That means the calling of this function module should be included in the "TRY CATCH" block, where you can catch the exception thrown by this function module. If you don't have it like this it will definetly give a short dump saying that "Uncatched Exception so and so..".
Regards,
Jashua
2007 Jun 25 8:33 AM
can you please tell me how to use CATCH stament
have never used it.
waiting for your reply
2007 Jun 25 8:38 AM
Hi,
TRY.
CATCH XXXXXX( Exception name)
Here you can process your exception.
ENDTRY.
See below example code
PARAMETERS number TYPE i.
DATA: result TYPE p LENGTH 8 DECIMALS 2,
oref TYPE REF TO cx_root,
text TYPE string.
TRY.
IF ABS( number ) > 100.
RAISE EXCEPTION TYPE cx_demo_abs_too_large.
ENDIF.
PERFORM calculation USING number
CHANGING result
text.
CATCH cx_sy_arithmetic_error INTO oref.
text = oref->get_text( ).
CATCH cx_root INTO oref.
text = oref->get_text( ).
ENDTRY.
IF NOT text IS INITIAL.
WRITE / text.
ENDIF.
WRITE: / 'Final result:', result.
FORM calculation USING p_number LIKE number
CHANGING p_result LIKE result
p_text LIKE text
RAISING cx_sy_arithmetic_error.
DATA l_oref TYPE REF TO cx_root.
TRY.
p_result = 1 / p_number.
WRITE: / 'Result of division:', p_result.
p_result = SQRT( p_number ).
WRITE: / 'Result of square root:', p_result.
CATCH cx_sy_zerodivide INTO l_oref.
p_text = l_oref->get_text( ).
CLEANUP.
CLEAR p_result.
ENDTRY.
ENDFORM.
Regards,
Sesh
2007 Jun 25 8:36 AM
No it will not shortdump if you RAISE the exception correctly. The return code (sy-subrc) will be set according how the FM is called by the calling program.
E.g. of a FM raising an exception (Using RAISE statement), let's call this ZFM
Import param: i_var1 type i, i_var2 type i, i_oper type c length 1.
Export param: e_res type i.
Exception: divide_by_zero, invalid_operation.
FM Code:
case i_oper.
when '+'.
e_res = i_var1 + i_var2.
when '-'.
e_res = i_var1 - i_var2.
when '*'.
e_res = i_var1 * i_var2.
when '/'.
if i_var2 = 0.
raise divide_by_zero.
else.
e_res = i_var1 / i_var2.
endif.
when others.
raise invalid_operation.
endcase.Now suppose calling program ZXYZ calls the above FM ZFM:
data: v_res type i.
call function 'ZFM'
exporting
i_var1 = 5
i_var2 = 0
i_oper = '/'
importing
e_res = v_res
exceptions
divide_by_zero = 1
invalid_operation = 2.At this point, after the FM has been executed, the return code will be set to 1 because exception would have been raised in the FM that divide by zero is not allowed. After this the calling program could process further as per the return code exported by the FM:
case sy-subrc.
when 1.
message e000 with 'Division by 0 is not allowed'.
when 2.
message e000 with 'Incorrect operator used'.
endcase.Hope this helps!