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: 

Two Classes Referencing each Other's Constants

Former Member
0 Kudos
443

I have two global classes with public constant attributes defined.  Each references one of the other's constants in their public header.  This causes a syntax error in one of the classes.  Is there a problem with doing this?

1 ACCEPTED SOLUTION

Peter_Inotai
Active Contributor
0 Kudos
277

Which release do you have?

In the 7.02 ABAP news somewhere I saw that it could be a problem, that's why Multi-pass compiler was introduced in 7.02. After 7.02 it should not happen.

19 REPLIES 19

SuhaSaha
Advisor
Advisor
0 Kudos
277

This causes a syntax error in one of the classes.

Don't you think that without knowing the syntax error it'll be difficult for us to comment?

Former Member
0 Kudos
277

I was hoping that someone would know right away if there was a reason why you can't have mutually dependent public headers.

The syntax error is pretty generic.  Here is more detail:

I have two classes that I'll refer to as A and B.

Check on A passes.

Check on B fails with the following syntax error:

Class A, Public Section

Field "CO_STATUS_NEW" is unknown.  It is neither in one of the specified tables nor defined by a "DATA" statement. .

Note that the error is referencing class A, even though class A itself passes a check.  Double clicking the error specifically points to a reference in the public header of class A to the co_status_new attribute of class B.

There is a co_status_new constant in both class A and class B.  The definition in class A uses the value defined in class B, like so:

constants co_status_new type char01 value B=>co_status_new.

Class B has a different constant in its public header whose value is defined based on class A like so:

class A definition load.

constants co_relid type indx_relid value A=>co_relid.

Both of these classes are active, by the way, but I can't re-activate B, due to this syntax error.

former_member226239
Contributor
0 Kudos
277

I guess there is no issue with it if you do the following:

1. Create the first class, declare the constant and activate the class.

2. Create the second class, declare the constant and activate the class.

3. Now, reference the fields in the first and second class.

-Chandra

0 Kudos
277

See my reply to Suhas Saha for a little more info.

By removing the references to class B from the public header of class A, I am able to activate class B with no syntax error.  When I put the reference back, class A also activates with no syntax error, but when I run the check on B again, the syntax error is back.

0 Kudos
277

Is it possible for you to put the screen shots of the references in both the classes?

former_member182466
Contributor
0 Kudos
277

Did you try activating them both with ignoring the errors? If you added them both at the same time the activation might read the previous version of the other class leading to it not finding the new constant. Activating with ignoring this error will solve that.

0 Kudos
277

As I describe in my reply to Chandra, I was able to get them both active, but a check on class B still shows a syntax error.  I'm sure this is not OK to ignore.

Former Member
0 Kudos
277

If you have two classes that each reference each other.... Maybe you actually just need 1 class?

Or maybe you need to think of a better way to share these constants? ie: 1 class with just the constants (think Java enums), inheritance hierarchy, etc...

Without knowing the specifics of what you're trying to do it's hard to give concrete advice but I think you have a design problem.

0 Kudos
277

I'd agree to the design problem.

Create an interface with the constants and let both classes implement it. You don't need to put in any additional methods or attributes to the interface (but maybe you could).

Best regards - Jörg

0 Kudos
277

Thanks to everyone that has given feedback!

Lucas, these definitely should be separate classes.  One represents a queue and the other represents an item in the queue.

These constants are for possible values for certain fields in queue items, and certainly could all be defined solely on the queue item class or moved to an interface that is shared between the two classes as Jorg suggested.  That is certainly a good suggestion, Jorg.

However, I am not concerned so much with avoiding my syntax error as I am with understanding why I am getting it.  Although it would probably be better to move all of my constants off into a shared interface, I still don't see what is syntactically wrong with what I am doing currently.  Is there something about ABAP that makes this invalid?

I'm beginning to think so, because class A's public header has the statement:

class B definition load.

and class B's public header has the statement:

class A definition load.

Is this a circular dependency that ABAP cannot resolve?

SuhaSaha
Advisor
Advisor
0 Kudos
277

Which ABAP release are you on? As per ABAP 740 the LOAD addition is obsolete

Refer: ABAP Keyword Documentation

Peter_Inotai
Active Contributor
0 Kudos
278

Which release do you have?

In the 7.02 ABAP news somewhere I saw that it could be a problem, that's why Multi-pass compiler was introduced in 7.02. After 7.02 it should not happen.

0 Kudos
277

We are unfortunately on 7.01.

Thank you so much, Peter!  This is exactly what is going on.

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos
277

and 7.40 and 7.50 ...

0 Kudos
277

You're welcome, Christopher.

I'm happy that the problem was identified. From the other hand it's bad, that there is no easy solution except performing upgrade.

jitendra_it
Active Contributor
0 Kudos
277

Just adding to Peter's reply.

Below is link to 's blog which explains Multi-pass compiler.

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos
277

And I recognize the above slide too

0 Kudos
277

Thanks so much for the link, Jitendra!  The example that Horst uses is exactly my situation.

Horst, I'm so glad to see that this is fixed in a later version.  I hope that we will be able to upgrade to 7.02 eventually.  7.02 looks like a huge improvement in so many ways.

Thanks to everybody for replying!

0 Kudos
277

I hope I didn't break any copyrights with this slide