Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type pool or class of constants?

Tags:

abap

What is the difference between Type-pool and creating a class for constants? What is better? My question is for a large group of constants and to be accessible to other groups.

Thank you

EDIT - Thank you for the answers and I will improve my question. I need something to store constants and I will use them on programs or other classes. Basically, I wanted to know if it is better to use a type-pool or a class with constants (only). I can have more than one class or type-pool.

like image 892
Leafsen Avatar asked Feb 03 '26 23:02

Leafsen


2 Answers

The documentation mentions this:

Since it is possible to also define data types and constants in the public visibility section of global classes, type groups are obsolete and should no longer be created. Existing type groups can still be used.

A sensibly named interface with the constants you desire is the way to go. An additional benefit is that ABAP OO enforces some more rules.

like image 159
peterulb Avatar answered Feb 06 '26 11:02

peterulb


Agree with @petul's answer, except for one detail: I'd recommend creating one enumeration-like class per logical group of constants, instead of collecting constants in interfaces.

Consider using the new enum language feature for specifying the constant values.

Interfaces can be accidentally "implemented", which doesn't make sense here. Classes can prevent this with final.

Making one class per logical group simplifies finding the constants with IDE features such as Ctrl+Shift+A search in the ABAP Development Tools. Constants that are randomly thrown together into interfaces are hard to find later on.

Classes allow adding enumeration-like helper methods like converters, existence checks, numbering all values.

Classes also allow adding unit tests, such as ensuring that the constant collection is still in sync with the fixed values of an underlying domain.

like image 38
Florian Avatar answered Feb 06 '26 12:02

Florian