Application Development 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: 

Syntax check Class at runtime

Former Member
0 Kudos

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?

11 REPLIES 11

Former Member
0 Kudos

Hi,

If it's a local class i don't think so, but use a global class with SE24.

Regards

0 Kudos

Hi Marc,

It is a global class.

But I need some code on how to check the class at runtime.

Best Regards

Rasmus

0 Kudos

Anyone else ?

former_member188685
Active Contributor
0 Kudos

What is the class. SO that we can check and let you know.

what is the method you are using .

0 Kudos

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.

thomas_rinneberg
Explorer

Call function module SEO_CLASS_CHECK_CLASSPOOL

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 ?

0 Kudos

@Frederic Girod to solve the requesters initial problem: Check the syntax of a class programmatically before attempting to call it dynamically.

0 Kudos

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.

0 Kudos

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.

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Yes, but in case of classes tedious.

https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abapsyntax-check_for_...

You must compose the includes of the class pool into the internal table. I've done it and it works.