‎2007 Nov 16 1:55 PM
the next code:
***********************
CLASS bank_application IMPLEMENTATION.
METHOD main.
DATA: account1 TYPE REF TO account,
account2 TYPE REF TO account,
amnt TYPE i,
exc_ref TYPE REF TO cx_negative_amount,
text TYPE string.
CREATE OBJECT: account1 EXPORTING id = `...`,
account2 EXPORTING id = `...`.
TRY.
amnt = ...
account1->transfer( EXPORTING amount = amnt
target = account2 ).
CATCH cx_negative_amount INTO exc_ref.
text = exc_ref->get_text( ).
MESSAGE text TYPE 'I'.
ENDTRY.
ENDMETHOD.
ENDCLASS.
*******************************
the statement endcatch? Why?
Is used the statement endcatch when I want continue type code after <b>"MESSAGE text TYPE 'I'."</b>?
cordial greetings
‎2007 Nov 28 3:19 PM
Hi Lopes,
Look at example <a href="https://wiki.sdn.sap.com/wiki/display/Snippets/ABAPObjects-DefiningaClass-basedexceptions">ABAP Objects - Defining a Class-based exceptions</a>.
When you're using exception class you don't use ENDCATCH.
When the exception is triggered the system continue the process after ENDTRY.
You must use ENDCATCH when you're using SYSTEM-EXCEPTIONS as the follow example:
DATA: result TYPE i,
number TYPE i.
CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 4
OTHERS = 8.
* The value of number is 0 ( 1 / 0 )
result = 1 / number.
ENDCATCH.
* If sy-subrc is not equal 0 the SYSTEM-EXCEPTIONS was triggered
IF sy-subrc is NOT INITIAL.
* error
ENDIF.
Regards,
Marcelo Ramos