Application Development and Automation 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: 
Read only

How to raise custom exceptions?

Former Member
0 Likes
1,439

Folks,

In my ABAP code, I need to raise an exception:


    IF sy-subrc = 1.
       RAISE table_not_available.
    ENDIF.

Here, instead of raising a generic exception such as table_not_available, I would like to raise a more meaningful exception where the table name is also displayed as part of the exception. Something like:

RAISE 'Table ' + tableName + ' not available.'

How can I create such custom exceptions?

Thank you in advance for your help.

Regards,

Peter

Folks,

In my ABAP code, I need to raise an exception:


    IF sy-subrc = 1.
       RAISE table_not_available.
    ENDIF.

Here, instead of raising a generic exception such as table_not_available, I would like to raise a more meaningful exception where the table name is also displayed as part of the exception. Something like:

RAISE 'Table ' + tableName + ' not available.'

How can I create such custom exceptions?

Thank you in advance for your help.

Regards,

Peter

3 REPLIES 3
Read only

Former Member
0 Likes
894

Try doing this via Message statement under the exception.........I am not sure whether u can raise exception like this.

Read only

Former Member
0 Likes
894

Try:

REPORT ztest LINE-SIZE 132 MESSAGE-ID 00 LINE-COUNT 65.

DATA: tab_name(20) VALUE 'BKPF'.

sy-subrc = 1.

IF sy-subrc = 1.
  MESSAGE e398 WITH 'Table ' tab_name 'not available' RAISING
               table_not_available.
ENDIF.

Rob

Read only

0 Likes
894

Hello,

Thank you for your help. I will try this out.

Regards,

Peter