Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using an include with constants in ABAP OO

Tags:

oop

abap

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?

like image 340
Gerd Castan Avatar asked Feb 03 '17 09:02

Gerd Castan


People also ask

How do you declare a constant variable in SAP ABAP?

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.

Is it possible to declare an internal table of constants?

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.

What is inheritance in OO ABAP?

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.

When you try to change value of some parameter which is declared using keyword constants what happens?

It cannot subsequently be changed. value of a constant, a syntax error or runtime error occurs.


1 Answers

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.

like image 121
vwegert Avatar answered Sep 30 '22 13:09

vwegert