I have an ABAP include containing only constants. (Not my code)
I want to use these constants in an ABAP OO method. (My code)
How can I use these constants in an object oriented ABAP environment without copying them?
The idea is to define these constants once and only once. And they are already defined in this include.
Additional question: is it possible to create a class that contains the constants of the above include in a public section, so that I do the include only once and use these constants in an object oriented way from other classes?
We can declare the named data objects with the help of CONSTANTS statement. CONSTANTS <f> TYPE <type> VALUE <val>. The CONSTANTS statement is similar to the DATA statement. <f> specifies a name for the constant.
Constant internal tables, reference variables, and structures with not purely character-like flat components can be assigned their initial value by IS INITIAL only, and are therefore always initial.
Inheritance. The concept of inheritance allows you to derive new classes from existing classes. To do this, you use the INHERITING FROM addition of the CLASS ... DEFINITION. The new class adopts or inherits all components of the existing class.
It cannot subsequently be changed. value of a constant, a syntax error or runtime error occurs.
Assuming that the include really only contains constant definitions: From the Class Builder, select Goto --> Class-relevant Local Definitions and place an INCLUDE
statement there. This should make the constants available throughout your implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With