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

ABAP objects help

Former Member
0 Likes
545

Hi All,

I have 3 questions.

1) When we create a class, there is a provision of selecting

defining or selecting exception classes under tab exception.

Path is method->parameter->exception. What is the significance of this?

Please provide me some examples as well?

2) I have an exception class ZCL_exception and a method to raise exception

I coded like this.

TRY.

if condition = 1.

RAISE EXCEPTION TYPE ZCX_apple

EXPORTING textid = ZCX_apple=>DATANOTFOUND.

endif.

CATCH ZCX_apple INTO exc.

text = exc->get_text( ).

MESSAGE text TYPE 'I'.

endtry.

but i am not not getting any message as output when I called this

method. Any idea the reason behind?

3) I want to validate the incoming message id using a method.

ie, if message id = 001, then message is 'DATANOTFOUND'.

if message id = 002, then message is 'invaliddata'.

it continues like this.

Is this logic possible to implement in a method

without using if else or switch case statements. ( I am thinking

of using an internal table) Any idea on this. Thanks in advance

for all the replies.

Michael

4 REPLIES 4
Read only

Former Member
0 Likes
497

hi,

The answer to first question is - You create a class defined methods and define paramters and exceptions to the method. In your program you can create an object of this class and call the method. When you call this method with the parameters then there is a possibility of some exception condition. if such exception condition arise, than the exception defined in the class is thrown by the method. You can catch this exception and handle your program accordingly.

For example. You have a global class-CL_GUI_FRONTEND_SERVICES where in you have a method named GET_CACHE_PROPwhich throws the exception PROP_NOT_FOUND when Property are not Declared in Cache. In the method implementation there is a raise statement- raise prop_not_found.

(along with other raise statements for other exceptions). If you call the method GET_CACHE_PROP of this class and it raises some exception (depending on some condition), then you need to handle this exception thrown by the method.

Regards,

Richa.

Read only

Former Member
0 Likes
497

Hi Michael,

Please find answers for your questions respectively

1. The Significance of EXCEPTION is to specify exeception class names which is raised in the method. So, Whenever calling another program or class or method these exceptions can captured and propagated to the calling program. If you are not done, Although you are getting exceptions you could able to capture. Don't specify the superclass name <b>'CX_STATIC_CHECK'</b> here. in this case also you cant able to handle exceptions.

<i>For example purpose please check the class CL_GUI_ALV_GRID and method SET_TABLE_FOR_FIRST_DISPLAY.</i>

2. You are raising the exception and trying to capture at same level. i.e is the reason you are unable to catch the exeception.

class cl_sample implementation.
method display.
..............
....
...
raise exception ....
end method.

try.
call method  cl_sample=>display.
catch ..........
* write your code here
endtry.

3. you can define new method there you can pass the message id, message no as input and retrieve the message from t100 table.

(NOTE: define all messages in message class)

Regards

Bhupal Reddy

Read only

Former Member
0 Likes
497

For #2.

data lo_ex type ref to ZCX_apple.

catch ZCX_apple into lo_ex.

raise exception type ZCX_apple

exporting

<parameters>

Regards,

Ramki.

Read only

former_member183804
Active Contributor
0 Likes
497

Hello Michael,

please find some answers below.

Kind Regards

1.) Exceptions & Signatures

Exceptions Classes derived from CX_STATIC_CHECK or CX_DYNAMIC_CHECK shoud be declared in the signature of any modularization unit that may raise such an exception. This tells the caller what error conditions may happen. For STATIC_CHECK a not handeled error condition will cause a syntax error.

2.) No Text

This depends on your implementation of Exception Class. Exeception Classes generated in SE24 should give the Text you defined on the according tab. I assume you have not maintained that tab. Another thing to check may be the logon language.

3.) Differ on IDs

Again it is possible to define Text IDs an the according tab. These IDs than can be passed via the constructor.