04-02-2008 7:48 AM
Hi,
My problem is i have program which calls a method on a class. But if the class has a syntax error the program dumps.
I want the program to finish its run even though the class dumps.
So my question is:
Is there a way to syntax check an ABAP Class before using it?
04-02-2008 10:43 AM
Hi,
If it's a local class i don't think so, but use a global class with SE24.
Regards
04-02-2008 11:22 AM
Hi Marc,
It is a global class.
But I need some code on how to check the class at runtime.
Best Regards
Rasmus
04-03-2008 1:09 PM
04-03-2008 1:21 PM
What is the class. SO that we can check and let you know.
what is the method you are using .
04-04-2008 12:27 PM
Ok here goes.
The is a dynamic method call to a class which implements the interface ZBWIF_VAR_EXIT
First i select all classes that implements 'ZBWIF_VAR_EXIT'
Then i try to run the method from the interface.
This is to check if a the class should be used to call the next method(contains the variable i want to reach).
If my_var is in the class i will call another method on the class.
if not i just go to next class.
Select CLSNAME
into l_clsname
from VSEOIMPLEM
where REFCLSNAME = 'ZBWIF_VAR_EXIT'.
try.
call method (l_clsname)=>('ZBWIF_VAR_EXIT~VAR_RESP')
EXPORTING
i_vnam = i_vnam
i_step = i_step
IMPORTING
e_my_var = l_my_var.
catch cx_root into lex_root.
clear l_my_var.
endtry.
if l_my_var = 'X'.
exit.
endif.
endselect .
*** next method called
If for some reason a class fails the syntax check this code dumps when i try to call the method.
All project/solutions implements the interface in a class. So it is accros the entire system if the code dumps.
Even if some class fail the code should still continue because it could be that the correct variable is in another class. Thoose class that are ok should still work.
So i need to check if the l_clsname is syntax wise correct before i call the method.
11-25-2021 6:14 PM
11-26-2021 7:11 AM
How ? why ? managing an error in a method of a class ? it is not a nonsens! you cannot import a TR containing error in the code. Why do you want to manage it ?
11-26-2021 7:18 AM
@Frederic Girod to solve the requesters initial problem: Check the syntax of a class programmatically before attempting to call it dynamically.
11-26-2021 10:00 AM
I agree with Frederic, I wouldn't answer a non-sense question 😉
but maybe you can write a new question so that it makes more sense to do a syntax check (e.g. in my case I created a program which extracts data from all SM30 tables/views and sometimes there are some invalid programs which make the program fails), and answer it.
11-26-2021 11:07 AM
I am sorry, please explain why the original question would make no sense? In fact, I had the very same issue - I am providing a service that calls a certain interface method on all implementations of a particular interface in order to find the correct implementation for a particular question. In fact, that is even a common programming pattern.
Now if I call that interface-method for a class, which has syntax errors, there is no way to catch them, the whole program is torn down. Hence the only way to provide a result and not a short dump is to pre-check each implementing class for syntax errors, and if there are any, not to call the method for that class. The mentioned function module does exactly this, it checks the syntax of a given class.
However, there is a flaw, it is not very quick. So if your answer is time critical (i.e. subsecond), that is not the way to go, but instead you rather live with the dump and notify the person who provided the faulty implementation of your interface to fix it. Because naturally, such issues occur in development systems only which is probably important to note.
11-26-2021 6:51 AM
Yes, but in case of classes tedious.
You must compose the includes of the class pool into the internal table. I've done it and it works.