2015 Nov 04 3:07 PM
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?
2015 Nov 05 10:11 AM
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.
2015 Nov 04 3:11 PM
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?
2015 Nov 04 5:54 PM
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.
2015 Nov 04 5:03 PM
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
2015 Nov 04 5:56 PM
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.
2015 Nov 04 6:08 PM
Is it possible for you to put the screen shots of the references in both the classes?
2015 Nov 04 5:04 PM
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.
2015 Nov 04 5:58 PM
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.
2015 Nov 04 6:28 PM
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.
2015 Nov 04 7:40 PM
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
2015 Nov 04 11:07 PM
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?
2015 Nov 05 9:47 AM
Which ABAP release are you on? As per ABAP 740 the LOAD addition is obsolete
Refer: ABAP Keyword Documentation
2015 Nov 05 10:11 AM
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.
2015 Nov 05 5:04 PM
We are unfortunately on 7.01.
Thank you so much, Peter! This is exactly what is going on.
2015 Nov 05 5:48 PM
2015 Nov 06 10:45 AM
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.
2015 Nov 05 3:41 PM
2015 Nov 05 3:43 PM
2015 Nov 05 5:07 PM
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!
2015 Nov 06 10:44 AM