<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using exceptions in SE24 global class Builder in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-exceptions-in-se24-global-class-builder/m-p/3667608#M883391</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for replying Uwe. I'm afraid I'm not asking the question correctly. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I want to have is an "IF" or "CASE" statement in my method. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When the IF test is false, I want to RAISE an exception similar to what you'd do in a function module.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 Apr 2008 20:09:29 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-04-10T20:09:29Z</dc:date>
    <item>
      <title>Using exceptions in SE24 global class Builder</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-exceptions-in-se24-global-class-builder/m-p/3667606#M883389</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to learn how to use SE24 and I'm a bit stumped on handling exception. &lt;/P&gt;&lt;P&gt;Here's a trivial example showing what I'd like to do. &lt;/P&gt;&lt;P&gt;Can anyone tell me what's wrong. Or point me to a reference. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*&amp;amp; N1	TYPE INT1	Byte Value
*&amp;amp; N2	TYPE INT1	Byte Value
*&amp;amp; OUT	TYPE INT1	Byte Value
*&amp;amp; CX_SY_ARITHMETIC_ERROR		System Exception for Arithmetic Errors

METHOD mult2.
  data: exc type REF TO cx_sy_arithmetic_error .
  out = n1 * n2 .
  IF out &amp;gt; 9.
    RAISE EXCEPTION type exc
  ENDIF.
ENDMETHOD.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2008 19:30:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-exceptions-in-se24-global-class-builder/m-p/3667606#M883389</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-10T19:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: Using exceptions in SE24 global class Builder</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-exceptions-in-se24-global-class-builder/m-p/3667607#M883390</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Ed&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using exception classes the rule is the same as in Java:&lt;/P&gt;&lt;P&gt;Either &lt;STRONG&gt;THROW or CATCH&lt;/STRONG&gt; the exception.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To catch means to surround the problematic piece of coding using a TRY-CATCH-ENDTRY block.&lt;/P&gt;&lt;P&gt;To throw means to define the exception class as part of the method signature.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The sample report &lt;STRONG&gt;ZUS_SDN_EXCEPTION_IN_LOCCLASS&lt;/STRONG&gt; demonstrates how to throw and catch the exception.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Report  ZUS_SDN_EXCEPTION_IN_LOCCLASS
*&amp;amp;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Thread: Using exceptions in SE24 global class Builder
*&amp;amp; &amp;lt;a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="817903"&amp;gt;&amp;lt;/a&amp;gt;
*&amp;amp;---------------------------------------------------------------------*

REPORT  zus_sdn_exception_in_locclass.


*----------------------------------------------------------------------*
*       CLASS lcl_myclass DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_myclass DEFINITION.
  PUBLIC SECTION.

    CLASS-METHODS:
      divide
        IMPORTING
          id_enumerator TYPE i
          id_denominator  TYPE i
        RETURNING
          value(rd_result)  TYPE i
        RAISING
          cx_sy_zerodivide.

ENDCLASS.                    "lcl_myclass DEFINITION



*----------------------------------------------------------------------*
*       CLASS lcl_myclass IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_myclass IMPLEMENTATION.

  METHOD divide.

    " raises division by zero error if id_denominator = 0
        rd_result = id_enumerator / id_denominator.

    " NOTE: since the exception class is defined within the
    "       method signature we do not need to catch it here.

    " BUT: Either catch or throw. Since we throw the exception class
    "      the caller of the method (= main program) must catch it.

  ENDMETHOD.                    "divide

ENDCLASS.                    "lcl_myclass IMPLEMENTATION


DATA: go_error      TYPE REF TO cx_root,
      gd_msg        TYPE bapi_msg.

DATA: go_myclass    TYPE REF TO lcl_myclass,
      gd_result     TYPE i.

PARAMETER:
  p_enum      TYPE i  DEFAULT '10',
  p_denom     TYPE i  DEFAULT '1'.

START-OF-SELECTION.


  TRY.
      CALL METHOD lcl_myclass=&amp;gt;divide
        EXPORTING
          id_enumerator  = p_enum
          id_denominator = p_denom
        RECEIVING
          rd_result      = gd_result.

      WRITE: / p_enum, '/', p_denom, '=', gd_result.

    CATCH cx_sy_zerodivide INTO go_error.
      gd_msg = go_error-&amp;gt;get_text( ).
      MESSAGE gd_msg TYPE 'I'.
  ENDTRY.


END-OF-SELECTION.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2008 19:52:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-exceptions-in-se24-global-class-builder/m-p/3667607#M883390</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2008-04-10T19:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using exceptions in SE24 global class Builder</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-exceptions-in-se24-global-class-builder/m-p/3667608#M883391</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for replying Uwe. I'm afraid I'm not asking the question correctly. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I want to have is an "IF" or "CASE" statement in my method. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When the IF test is false, I want to RAISE an exception similar to what you'd do in a function module.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2008 20:09:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-exceptions-in-se24-global-class-builder/m-p/3667608#M883391</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-10T20:09:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using exceptions in SE24 global class Builder</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-exceptions-in-se24-global-class-builder/m-p/3667609#M883392</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Ed&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have modified my sample report to show both ways: classical exceptions and exception classes. However, since exception classes are much more powerful I recommend to use them instead of classical exceptions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please note that you cannot mix classical exceptions with exception classes in the same class. Therefore I inactivated method DIVIDE_3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Report  ZUS_SDN_EXCEPTION_IN_LOCCLASS
*&amp;amp;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp; Thread: Using exceptions in SE24 global class Builder
*&amp;amp; &amp;lt;a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="817903"&amp;gt;&amp;lt;/a&amp;gt;
*&amp;amp;---------------------------------------------------------------------*

REPORT  zus_sdn_exception_in_locclass.


*----------------------------------------------------------------------*
*       CLASS lcl_myclass DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_myclass DEFINITION.
  PUBLIC SECTION.

    CLASS-METHODS:
      " use exception class
      divide
        IMPORTING
          id_enumerator TYPE i
          id_denominator  TYPE i
        RETURNING
          value(rd_result)  TYPE i
        RAISING
          cx_sy_zerodivide,

      " use exception class
      divide_2
        IMPORTING
          id_enumerator TYPE i
          id_denominator  TYPE i
        RETURNING
          value(rd_result)  TYPE i
        RAISING
          cx_sy_zerodivide.


**      " use classical exception
**      divide_3
**        IMPORTING
**          id_enumerator TYPE i
**          id_denominator  TYPE i
**        RETURNING
**          value(rd_result)  TYPE i
**        EXCEPTIONS
**          arithmetic_error.


ENDCLASS.                    "lcl_myclass DEFINITION



*----------------------------------------------------------------------*
*       CLASS lcl_myclass IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_myclass IMPLEMENTATION.

  METHOD divide.

    " raises division by zero error if id_denominator = 0
    rd_result = id_enumerator / id_denominator.

    " NOTE: since the exception class is defined within the
    "       method signature we do not need to catch it here.

    " BUT: Either catch or throw. Since we throw the exception class
    "      the caller of the method (= main program) must catch it.

  ENDMETHOD.                    "divide


  METHOD divide_2.

    IF ( id_denominator = 0 ).
      RAISE EXCEPTION TYPE cx_sy_zerodivide
        EXPORTING
          textid = cx_sy_zerodivide=&amp;gt;cx_sy_arithmetic_error
          operation = 'DIVIDE'.

    ELSE.
      rd_result = id_enumerator / id_denominator.
    ENDIF.


  ENDMETHOD.                                                "divide_2


**  METHOD divide_3.
**    IF ( id_denominator = 0 ).
**      RAISE EXCEPTION arithmetic_error.
**    ELSE.
**      rd_result = id_enumerator / id_denominator.
**    ENDIF.
**  ENDMETHOD.                                                "divide_3

ENDCLASS.                    "lcl_myclass IMPLEMENTATION


DATA: go_error      TYPE REF TO cx_root,
      gd_msg        TYPE bapi_msg.

DATA: go_myclass    TYPE REF TO lcl_myclass,
      gd_result     TYPE i.

PARAMETER:
  p_enum      TYPE i  DEFAULT '10',
  p_denom     TYPE i  DEFAULT '1'.

START-OF-SELECTION.


**  TRY.
**      CALL METHOD lcl_myclass=&amp;gt;divide
**        EXPORTING
**          id_enumerator  = p_enum
**          id_denominator = p_denom
**        RECEIVING
**          rd_result      = gd_result.
**
**      WRITE: / p_enum, '/', p_denom, '=', gd_result.
**
**    CATCH cx_sy_zerodivide INTO go_error.
**      gd_msg = go_error-&amp;gt;get_text( ).
**      MESSAGE gd_msg TYPE 'I'.
**  ENDTRY.


  TRY.
      CALL METHOD lcl_myclass=&amp;gt;divide_2
        EXPORTING
          id_enumerator  = p_enum
          id_denominator = p_denom
        RECEIVING
          rd_result      = gd_result.

      WRITE: / p_enum, '/', p_denom, '=', gd_result.

    CATCH cx_sy_zerodivide INTO go_error.
      gd_msg = go_error-&amp;gt;get_text( ).
      MESSAGE gd_msg TYPE 'I'.
  ENDTRY.


**  CALL METHOD lcl_myclass=&amp;gt;divide_3
**    EXPORTING
**      id_enumerator    = p_enum
**      id_denominator   = p_denom
**    RECEIVING
**      rd_result        = gd_result
**    EXCEPTIONS
**      arithmetic_error = 1.
**  IF ( syst-subrc = 0 ).
**    WRITE: / p_enum, '/', p_denom, '=', gd_result.
**  ELSE.
**    MESSAGE 'Arithmetic error'  TYPE 'I'.
**  ENDIF.


END-OF-SELECTION.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;  Uwe&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2008 21:11:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-exceptions-in-se24-global-class-builder/m-p/3667609#M883392</guid>
      <dc:creator>uwe_schieferstein</dc:creator>
      <dc:date>2008-04-10T21:11:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using exceptions in SE24 global class Builder</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/using-exceptions-in-se24-global-class-builder/m-p/3667610#M883393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Perfect. That REALLY helped a great deal. &lt;/P&gt;&lt;P&gt;Thanks so much.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Apr 2008 21:31:10 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/using-exceptions-in-se24-global-class-builder/m-p/3667610#M883393</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-10T21:31:10Z</dc:date>
    </item>
  </channel>
</rss>

