Skip to content

Prefer ENUM to constants interfaces

Use ABAP-native enumerations with ENUM (available in releases >= 7.51)

CLASS /clean/message_severity DEFINITION PUBLIC ABSTRACT FINAL.
  PUBLIC SECTION.
    TYPES: BEGIN OF ENUM type,
             warning,
             error,
           END OF ENUM type.
ENDCLASS.

instead of mixing unrelated things or misleading people to the conclusion that constants collections could be “implemented”:

" anti-pattern
INTERFACE /dirty/common_constants.
  CONSTANTS:
    warning      TYPE symsgty VALUE 'W',
    transitional TYPE i       VALUE 1,
    error        TYPE symsgty VALUE 'E',
    persisted    TYPE i       VALUE 2.
ENDINTERFACE.

Enumerations describes alternative enumeration patterns (also applicable to older releases that do not support ENUM yet) and discusses their advantages and disadvantages.

Read more in Chapter 17: Smells and Heuristics: J3: Constants versus Enums of Robert C. Martin’s Clean Code.

From SAP/styleguides under CC BY 3.0 — more details
Last updated on