Skip to content

Constants also need descriptive names

There is a historic tendency in ABAP to wrap every literal in constants, often with names that merely repeat their content or even just their type:

" anti-pattern 
CONSTANTS: 
  c_01 TYPE spart VALUE '01',
  c_mmsta TYPE mmsta VALUE '90'.

There is little benefit to either variant. It is not informative for the reader, and if the value ever needs to change then a constant named by its value must also be renamed.

If a coded constant is declared in code then it should describe its meaning not its content.

CONSTANTS status_inactive TYPE mmsta VALUE '90'.

It is of course acceptable to repeat the constant’s value if it is already descriptive enough:

CONSTANTS status_cancelled TYPE sww_wistat value 'CANCELLED'.

Note: This section is a specialization of Use descriptive names, applied to constants.

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