Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Advantages of Exception classes


I think that I not completly understand the concept behind exception classes.

The problem I have is, taht can´t see any advantages by using exception classes instead of using

the MESSAGE statement.

Let´s have to following scenario:

I´ve a global class called ZCL_MATERIAL. This class has a method called LOAD_MATERIAL which tries to load the MARA record.

Now the following situations can occur:

Case 1: Material doesn´t exist --> ERROR

Case 2: Deletion Flag is set for material --> WARNING

To this method an exception class (ZCX_MATERIAL) is assigned.

During runtime the appropriated exceptions will be raised:

Case 1: RAISE EXCEPTION TYPE zcx_material

text_id = zcx_material=>not_found.

Case 2: RAISE EXCEPTION TYPE zcx_material

text_id = zcx_material=>marked_for_deletion.

A simple report calling this Method within a try/end try block:

data lo_excp type ref to zcs_material.


lo_material->load_material( ).

catch zcx_material into lo_excp.

message lo_excp type '?????'. "..error or warning


I want to output the message text via the MESSAGE statement. But the TYPE parameter (see question marks)

is a bit confusing to me. As this parameter is not optional I always has to specify them. But with which type?

It´s possible that warning or an error messages (exception) occurs.

Comparing to simple MESSAGE ... RAISING statements within methods, using exception classes means that I have to

do a lot more of coding without having a benefit.....

Can anybody explain in simple words whats the advantage of exception classes and how to use them in the case I mentioned above?

Many thanks in advance for your help,


Former Member
Not what you were looking for? View more on this topic or Ask a question