Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

OO class and events program

Former Member
0 Kudos

Hi All,

I am not an experienced ABAP OO programmer. Here is the requirement.

I need to develop an ABAP OO program which has to send an SMTP mail for all exceptions. The exceptions need to be handled using event handling functionality inside try catch statements. There are plenty of exceptions which need to be handled using events. I have written a sample template for this purpose. Please help me out to develop this in a better way.

Pasting the code below.

CLASS CL_NETAPP_EXCEPTION definition INHERITING FROM CX_AI_APPLICATION_FAULT.

.

.

PUBLIC SECTION.

CLASS-DATA: MESSAGE_TEXT TYPE STRING,

MESSAGE_ID TYPE STRING.

EVENTS smtpnotification.

EVENTS ALERTNOTIFICATION.

ENDCLASS.

START-OF-SELECTION.

  • when data is not found, raise exception.

select producttype from product where prodtype = 'xxxx'.

if sy-subrc ne 0.

CL_NETAPP_EXCEPTION=>MESSAGE_TEXT = 'DATA NOT FOUND'.

CL_NETAPP_EXCEPTION=>MESSAGE_ID = 'i001'.

endif.

*these are some of the other exceptions.

*CL_NETAPP_EXCEPTION=>MESSAGE_TEXT = 'CRM connection failure'.

*CL_NETAPP_EXCEPTION=>MESSAGE_ID = 'i002'.

*CL_NETAPP_EXCEPTION=>MESSAGE_TEXT = 'INPUT FORMAT INCORRECT'.

*CL_NETAPP_EXCEPTION=>MESSAGE_ID = 'i003'.

CLASS CL_NETAPP_EXCEPTION IMPLEMENTATION.

*call function 'xxxxx' for inserting or updating data.

ENDCLASS.

CLASS CL_NETAPP_EVENTHANDLER DEFINITION.

PUBLIC SECTION.

METHODS: SMTPNOTIFICATION,

ALERTHANDLERNOTIFICATION.

EVENTS: SMTPNOTIFICATIONEVE.

EVENTS: ALERTHANDLERNOTIFICATIONEVE.

ENDCLASS.

CLASS CL_NETAPP_EVENTHANDLER IMPLEMENTATION.

METHOD SMTPNOTIFICATION.

TRY.

IF CL_NETAPP_EXCEPTION=>MESSAGE_ID ne space.

*send mail notification when there is an exception.

CALL FUNCTION 'SMTP_DISPATCH_REQUEST'.

ENDIF.

RAISE EVENT SMTPNOTIFICATIONEVE.

ENDTRY.

ENDMETHOD.

ENDCLASS.

Thanks

Deno

2 REPLIES 2

uwe_schieferstein
Active Contributor
0 Kudos

Hello Deno

I am very confused about your coding and your actual requirement. I assume that your report has to verify data records. If verification fails the report should send in most (all?) cases a SMTP mail.

If this scenario is close to your requirements then a possible solution could look like this:

* Assumption: you have an itab containing the data to be verified
  LOOP at gt_itab INTO gs_record.

* You have created a class (e.g. ZCL_MYCLASS) that does all the verifications for a single record. 
* In addition, you have created an exception class (e.g. ZCX_MYCLASS) that has all exceptions defined.
* All methods of ZCL_MYCLASS including the constructor method use the exception class in their interfaces.

  TRY.
    CLEAR: go_error.  " error object of type zcx_myclass
    CREATE OBJECT go_myclass
      EXPORTING
        is_data = gs_record.

    go_myclass->verify_data( ). " method contains all other verification methods
    
  CATCH zcx_myclass INTO go_error.
*   Send SMTP mail: go_error->get_text( ) contains error message    
  ENDTRY.
  

  ENDLOOP.

Regards

Uwe

0 Kudos

Hi,

My suggestion would be define one common exception class of your own. And for every exception for which you want to raise an event you need to do the following.

You catch every exception and then wrap it with your own common exception class and raise this exception.

Then you only need to code the event raising code for this exception, with this you will have your event raising only for one exception, in future if you need to do any modification to the event say add one more export parameter for the event then you only need to search for this exception and change.

Hope this idea helps you.

Regards,

Sesh