05-25-2010 9:14 AM
Hi All,
In ABAP you can call a method in a short way. However how do I catch the exceptions if the exception is not an exception class.
For instance:
l_case = cl_scmg_case_api=>open_case( im_case_guid = me->caseguid im_enqueue = 'X' ).
The exceptions are "catchable" if you call the method in the "long" way.
call method cl_scmg_case_api=>open_case
exporting
im_case_guid = lv_guid
* im_enqueue = SPACE
* im_mode = IF_SRM_SP_ENQUEUE=>MODE_EXCLUSIVE
* im_scope = IF_SRM_SP_ENQUEUE=>SCOPE_DIALOG
* im_update_task = IF_SRM=>FALSE
* im_check_authority = SPACE
* im_close_after_commit = SPACE
receiving
re_case =
exceptions
failed = 1
enqueue_failed = 2
invalid_guid = 3
cx_srm_gsp_back = 4
no_authority = 5
illegal_case_type = 6
others = 7
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
Regards,
Bert
05-25-2010 9:43 AM
It's not very pretty, but you do it like this:
l_case = cl_scmg_case_api=>open_case( EXPORTING im_case_guid = me->caseguid im_enqueue = 'X'
EXCEPTIONS failed = 1 ...
matt
05-25-2010 9:43 AM
It's not very pretty, but you do it like this:
l_case = cl_scmg_case_api=>open_case( EXPORTING im_case_guid = me->caseguid im_enqueue = 'X'
EXCEPTIONS failed = 1 ...
matt
05-25-2010 9:57 AM
05-29-2010 3:11 AM
Hi,
you have another -not very nice but possible - option.
If you dont catch it in your statement ABAP runtime will raise an exception
of type "cx_sy_no_handler".
You can put all your function calls into a try block and catch it at the end.
... in the catch block you should still have the sy-message variables available
to propagate it.
May be that helps bit.
Regards
05-29-2010 7:46 AM
Euurg. Not nice at all! At least that was my first thought. However, if it makes the code more readily understandable, then maybe it isn't so bad.
05-30-2010 12:29 AM
@Matt, as far as I'm concerned your solution is the only solution and I keep wondering if other people try to come up with creative "alternatives" because you stated it's not pretty...
<br/>
-
<br/>
@Marcel/Clemens: As I stated, Matt's solution works perfectly fine, I don't see why one would try to come up with questionable solutions. I.e. here's what the documentation tells us about [non-class based exceptions|http://help.sap.com/abapdocu_70/en/ABAPRAISE_EXCEPTION.htm]:
If the exception is triggered in a method or function module whose caller does not assign a return value to the exception, a runtime error is then triggered whose short dump contains the name of the exception.
The exception CX_SY_NO_HANDLER, is only used with [class based exceptions|http://help.sap.com/abapdocu_70/en/ABENEXCEPTIONS_EVENTS.htm] as far as I know. A quick test with a [TRY-ENDTRY|http://help.sap.com/abapdocu_70/en/ABAPTRY.htm] wrapper around a method call raising a non-class based exception via [RAISE|http://help.sap.com/abapdocu_70/en/ABAPRAISE_EXCEPTION.htm] gave me the expected short dump (for either of your suggestions). Maybe I'm missing something, but as far as I can tell the solutions cannot work...
05-30-2010 10:54 AM
Harald,
thank you for enlightening us, always with a pinch of welcome lightning, but I like that
I think I could have made the same kind of erroneous answer, ABAP language has tortuous (but often logical) syntaxes and functions.
But I wouldn't have asked the question as the solution is in the manual (and the online abap help), as very often : [ABAP doc for method parameters|http://help.sap.com/abapdocu_70/en/ABAPCALL_METHOD_PARAMETERS.htm] (it is said in the main [CALL METHOD|http://help.sap.com/abapdocu_70/en/ABAPCALL_METHOD.htm] article, that the list of parameters is the same whatever you used the leading "CALL METHOD" or not)
sandra
PS: could you tell us your secrets how you are able to make all these hyperlinks so quickly? 😄
Edited by: Sandra Rossi on May 30, 2010 11:56 AM
05-30-2010 11:22 AM
could you tell us your secrets how you are able to make all these hyperlinks so quickly?
I wish there was a secret and that it really was quickly...
There's no magic, but I usually try to provide references to official SAP documents to give others the chance to evaluate more easily if I'm telling rubbish or not (though I'm aware that the links cannot always do that, but I think they help). Actually, I sometimes have to discard some lengthy answer (with nice links), because before posting I usually try to check for any updates and often other people have answered much faster (often without any official SAP references though)...
But I wouldn't have asked the question as the solution is in the manual
Yep, I fully agree and I would usually avoid answering such questions. However, I think it's important to question answers that we think are incorrect. I've seen too much stuff out here that's not right, though most of the times I'm too lazy to comment (especially on the trivial questions). I know I also have my share of incorrect answers/advises, but for all our benefit I'm hoping that somebody will jump in and correct me....
05-29-2010 8:40 PM
Hi Bert,
quick'n dirty;
TRY.
l_case = cl_scmg_case_api=>open_case( im_case_guid = me->caseguid im_enqueue = 'X' ).
CATCH cx_root.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDTRY.
Regards,
Clemens