ABAP Exception Class ZCX_RETURN3 | SAP Blogs

WRITTEN BY: supportmymoto.com STAFF

As an ABAP programmer we should program Object Oriented code (aka OO code). So for exception / error dealing with we have to use Exception courses as a substitute of utilizing the outdated procedural methods of error dealing with like SY-SUBRC and BAPIRETURN information.

Nevertheless typically now we have to name BAPIs, or much less favourite different perform modules or FORM routines. In new OO code now we have to deal with the procedural errors and convert them to OO Exceptions.

Some years in the past I began to create an exception class for dealing with all type of procedural error messages (outdated procedural and new OO messages) and mixing it with the great outdated SAP messages (T: SE91).

This class is known as ZCX_RETURN3. It might probably deal with all sort errors.

ZCX_RETURN2 was the earlier model. Based mostly on the feedback on the weblog submit of ZCX_RETURN2 I’ve redesigned it into ZCX_RETURN3. Essential change is, that it now helps the brand new RAISE EXCEPTION … [USING] MESSAGE assertion and that the static occasion creation strategies (manufacturing facility strategies) are eliminated to advertise inheriting this class for specialised exception courses as a substitute of utilizing this class as generic exception class.

On this weblog submit is defined the way it works. It additionally accommodates references to associated blogs for code templates for shortly including error dealing with code.

Most likely most used exception class instantiations are for:

  • BAPI errors
  • SE91 message errors

Therefor the 2 examples beneath will present how this works.
The examples are primarily based on instantiating ZCX_RETURN3, however making a sub class of ZCX_RETURN3 can also be potential.

Instance 1: Elevating BAPI errors

For instance you name a BAPI perform module routine which returns a BAPI return desk of kind BAPIRET2.

        DATA:
          lt_return TYPE bapiret2_t.

        CALL FUNCTION 'BAPI_USER_CREATE1'
          EXPORTING
            username="DUMMY"
            logondata = ls_logondata
            password  = ls_password
            handle   = ls_address
          TABLES
            return    = lt_return.

        DATA(lx_return) = NEW zcx_return3( ).
        lx_return->add_bapiret2_table( lt_return ).

        IF lx_return->has_messages( ) = abap_true.
          RAISE EXCEPTION lx_return.
        ENDIF.

The return desk variable LT_RETURN will obtain the error messages from the BAPI.

See also  Developer Brings 64-Bit ROM Support to the Moto G5 Plus

The category ZCX_RETURN3 will probably be instantiated or a subclass of ZCX_RETURN3.

Technique ADD_BAPIRET2_TABLE will add the messages to the exception object.

If LT_RETURN accommodates a number of messages with kind E, A or X, then methodology HAS_MESSAGES() will return ABAP_TRUE. After which RAISE EXCEPTION will increase it.

Instance 2: Elevating SAP and customized message

        SELECT SINGLE
            kunnr
          FROM kna1
          WHERE kunnr = @gv_kunnr
          INTO @DATA(ls_kna1).

        IF sy-subrc <> 0.

          RAISE EXCEPTION TYPE zcx_return3
            MESSAGE e001
              WITH gv_kunnr.

        ENDIF.

Operate modules, FORM routines and ABAP statements can fill SY-SUBRC. If the worth is <> 0, then an error occurred.

The brand new 7.50 syntax is used. RAISE EXCEPTION TYPE with MESSAGE will retrieve the message from desk T100 and lift it as exception in a single assertion.

The category ZCX_RETURN3 has many ADD strategies for including totally different type of error varieties and changing them to its personal attribute inside desk GT_RETURN of kind BAPIRET2_T.

For retrieving the information use the GET-methods:

  • IF_MESSAGE~GET_TEXT
    Get the message textual content of the primary error.
  • IF_MESSAGE~GET_LONGTEXT
    Get the lengthy textual content of T:SE91 of the primary error.
  • GET_BAPIRET2_STRUC
    Get the primary error of GT_RETURN.
  • GET_BAPIRET2_TABLE
    Get all errors from desk GT_RETURN.

Elevating could be completed with the brand new 7.50 RAISE EXCEPTION with MESSAGE and in addition by including BAPI return information and different messages.

See the code templates in:

Weblog submit: ABAP Exception Class ZCX_RETURN3 – Elevate code templates

This may be completed for various functions like ABAP packages / studies, ABAP Gateway, ABAP Proxy, IDocs and RFC perform modules.

See also  Status Profile Functionality for SAP SD Professionals

Weblog submit: ABAP Exception Class ZCX_RETURN3 – Catch code templates

Obtain

Set up ZCX_RETURN3 class

Choice 1: with Eclipse (that is the popular method)

That is the popular method, as a result of in Eclipse all code could be copied and pasted without delay.

  • Decide or create an ABAP package deal for the category ZCX_RETURN3.
  • Create a brand new class: ZCX_RETURN3.
  • Copy and paste the code of the ZCX_RETURN3_750.abap file.
    For ABAP < 7.50, use the file ZCX_RETURN3.abap.

Choice 2: with ABAP workbench (not the popular method)

  • Decide or create an ABAP package deal for the category ZCX_RETURN3.
  • Create in SE80 class: ZCX_RETURN3.
    Tremendous class: CX_STATIC_CHECK
    Description: RETURN3 exception class
    Inst. Technology: PublicClass kind: Exception class
    With messages of message courses as exception texts: OFF
    Closing: OFFPackage: ZCA_DOMAIN
  • Activate the category.
  • Menu: Goto -> Sections -> Public part.
  • Definition half
    • Copy and paste the Definition a part of the file ZCX_RETURN3 into SE80 editor
  • Implementation half.
    • Double click on on each methodology and duplicate and paste the ABAP code.
      Use the Panel on the left (Explorer view) to navigate to the following methodology.

Creating new procedural routines just isn’t allowed anymore until you want it for technical causes. For instance.

  • Operate module may be wanted for tRFC, qRFC, distant enabled or replace job.
  • New FORM routines aren’t allowed.
  • New Macros aren’t allowed.
  • ABAP program occasions are allowed, as a result of they’re wanted for technical causes.

Within the procedural routine solely calling strategies is allowed and catching OO exceptions for these strategies. It’s not allowed to boost OO exceptions.

See also  Beginner's Guide to Changing App Icons on Xperia Devices

It’s already model 3, therefor the three within the title. Compared the model 1, the naming of the strategies have been improved and the coding is refactored by consistency of doing creating the occasion and consequently it’s simplified. Compared the model 2 the static manufacturing facility strategies are eliminated and it has been made relevant for 7.50 RAISE EXCEPTION with MESSAGE.

ABAP BAPI BO Class Generator nonetheless makes use of an older model named ZCX_RETURN.

Benefits

  1. By utilizing the The place-used record in T: SE91, you could find the ABAP code location.
  2. They’ve a reputation / quantity mixture which establish every message uniquely.
  3. They are often translated.
  4. They’ll deal with 4 variables.
  5. They are often added to the Utility log (T: SLG1 / SLG0).
  6. They’re utilized by all BAPI RETURN construction varieties and desk varieties.

Ideas

  1. Make a Message class per ABAP class.
    Purpose for that is that the messages belong to Enterprise Object, Enterprise Subobject or different kind of sophistication.
    By retaining the messages grouped collectively by ABAP class, it’s simpler to repeat particular ABAP courses with their messages to a different system.
  2. Don’t reuse messages on a number of code places.
    Purpose for that is that the purpose is that the where-used record from SE91 will solely return one code location.
    That’s why you shouldn’t use or create generic SE91 messages like ‘&1 &2 &3 &4’ with solely variables and with none textual content.
NOTE : Please do not copy - https://supportmymoto.com

Leave a Reply