Application Development and Automation 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: 
Read only

class-constants, class-data, for report constants?

Former Member
2,863

How to get static Values in ABAP?

a)

apparently there is no "class-constants" in ABAP

e.g. so there is no:

class zmyclass definition final.
   public section.
     class-constants

b)

so using instead class-data and read only

e.g.

class zmyclass definition final.
   public section.
     class-data c_example type char2 value 'eg' read-only.

yet, when zmyclass is a global class,

while this works:


REPORT Z1.

PARAMETERS p_1 type char2 default zmyclass=>C_EXAMPLE.

this gives Syntax Error (Field C_EXAMPLE is unkown.) ...


REPORT Z1.

constants c_1 type char2 value zmyclass=>C_EXAMPLE.

1 ACCEPTED SOLUTION
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
1,511

Hi,

it's the other way around.

There is no "instance"-CONSTANTS in ABAP. As documented, the usage of CONSTANTS in the declaration part of a class defines a static attribute (CONSTANTS is implicitly the same as "CLASS-"CONSTANTS).

If you use CONSTANTS instead of CLASS-DATA in your global class, you can use the constant of the global class behind VALUE in your program.

Horst

Hi,

it's the other way around.

There is no "instance"-CONSTANTS in ABAP. As documented, the usage of CONSTANTS in the declaration part of a class defines a static attribute (CONSTANTS is implicitly the same as "CLASS-"CONSTANTS).

If you use CONSTANTS instead of CLASS-DATA in your global class, you can use the constant of the global class behind VALUE in your program.

Horst

1 REPLY 1
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
1,512

Hi,

it's the other way around.

There is no "instance"-CONSTANTS in ABAP. As documented, the usage of CONSTANTS in the declaration part of a class defines a static attribute (CONSTANTS is implicitly the same as "CLASS-"CONSTANTS).

If you use CONSTANTS instead of CLASS-DATA in your global class, you can use the constant of the global class behind VALUE in your program.

Horst