Skip to Content
0
Former Member
Nov 13, 2006 at 11:27 AM

OO class and events program

13 Views

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