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

Handling exceptions

Former Member
0 Likes
1,608

Hi Folks!

I have a requirement where I need to handle an exception. What i'm doing is a batch input, though I doing it over a standard transaction, I need to be sure that if a dump occurs in the time executing the transaction, I can catch it and execute some cleanup process.

Something like this:

Controlled block:

Perform transaction 'XK02'.

IF an error ocurred, catch and execute cleanup.

I've got an example, however it is through objects and I'm getting an error that CX_ROOT is unknown.

<i>report DEMO_HANDLE_EXCEPTIONS.

parameters NUMBER type I.

data RESULT type P decimals 2.

data OREF type ref to CX_ROOT.

data TEXT type STRING.

start-of-selection.

write: / 'Testing divison and Sqare root with', NUMBER.

uline.

try.

if ABS( NUMBER ) > 100.

raise exception type CX_DEMO_ABS_TOO_LARGE.

endif.

try.

RESULT = 1 / NUMBER.

write: / 'Result of division:', RESULT.

RESULT = SQRT( NUMBER ).

write: / 'Result of square root:', RESULT.

catch CX_SY_ZERODIVIDE into OREF.

TEXT = OREF->GET_TEXT( ).

cleanup.

clear RESULT.

endtry.

catch CX_SY_ARITHMETIC_ERROR into OREF.

TEXT = OREF->GET_TEXT( ).

catch CX_ROOT into OREF.

TEXT = OREF->GET_TEXT( ).

endtry.

if not TEXT is initial.

write / TEXT.

endif.

write: / 'Final result:', RESULT.</i>

Please guide me how I could handle this, the cleanup it's pretty critical.

Thanks.

Regards,

Gilberto Li

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,479

Hello Gilberto

If you are doing standard BDC using

CALL TRANSACTION 'XK02' USING lt_bdcdata
                        MESSAGES INTO lt_messages.

then you can collect all messages of the batch-input and analyse them afterwards. So you do not need any TRY/CATCH block.

However, if the syntax check says that CX_ROOT does not exist this would mean that you are working on an old release not having this root exception class.

Regards

Uwe

4 REPLIES 4
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,480

Hello Gilberto

If you are doing standard BDC using

CALL TRANSACTION 'XK02' USING lt_bdcdata
                        MESSAGES INTO lt_messages.

then you can collect all messages of the batch-input and analyse them afterwards. So you do not need any TRY/CATCH block.

However, if the syntax check says that CX_ROOT does not exist this would mean that you are working on an old release not having this root exception class.

Regards

Uwe

Read only

0 Likes
1,479

Hi Uwe, thanks for your reply.

1. You're right, i'm working on an older version that doesn't have the exception handling feature, I was suspecting that.

2. I know you can collect the error messages, however what if while executing the batch input it gives a dump, the execution of the calling program (the program making the call transaction) will be ended too, and I need to process some clean up operations if this happens.

3. I know that usually and the probabilities that a standard transaction gives a dump its pretty low, but I still need to prevent that if an error(not a transaction error, by error I meaning a dump) still occurs do the clean up that it's critical.

Thanks again.

Regards,

Gilberto Li

Read only

0 Likes
1,479

I don't think that is possible. How can you catch and process an error thrown by a standard application. I know the probability is low, but if it happens then you have to fix it by implementing OSS notes if there is any for that error.

Thanks,

Read only

0 Likes
1,479

Hi Somen, thanks for your reply.

Yes, I think this isn't possible either now. I thought in a beggining that a exception handling could do the trick, but now that I know I can't count with it, it seems that I won't be able to control an error.

I will have to deal with the low probabilities of a standard transaction givin a dump, and if it happens fix it as soon as possible with OSS Notes.

Thanks again.

Regards,

Gilberto Li.