ABAP constants

Summary: in this tutorial, you will learn how to use the ABAP constants keyword to declare constants in the program.

Introduction to ABAP constants #

Constants are data objects whose values cannot be changed by the program at runtime using assignments. Their contents are constants.

To declare a constant in the program, you use the constants keyword as follows:

constants constant_name type data_type value intial_value.

In this syntax:

  • First, specify the constant name after the constants keyword. The name of a constant has at most 30 characters and starts with a letter.
  • Second, select a data type for the constant after the type keyword.
  • Third, specify the value of the constant after the value keyword. This is only place where you can specify the constant value.

The following example declares a constant named gc_tax_rate with type f and value 0.07.

constants gc_tax_rate type f value '0.07'.

The following shows how to use the constant gc_tax_rate to calculate the net price:

data gv_price type f value 100.
constants gc_tax_rate type f value '0.07'.

data(net_price) = gv_price * ( 1 - gc_tax_rate ).

To declare multiple constants, you use the chain statement as follows:

constants:
   constant_name_1 type data_type value constant_value_1,
   constant_name_2 type data_type value constant_value_2,
   ...
   constant_name_n type data_type value constant_value_n.

Summary #

  • Use the keyword constants to declare data object whose values does not change in the program.

Was this tutorial helpful?