SAP Tutorials Blog

 

CONSTANTS Statement

We can declare the named data objects with the help of CONSTANTS statement.

Following is the syntax −

CONSTANTS <f> TYPE <type> VALUE <val>.

The CONSTANTS statement is similar to the DATA statement.

<f> specifies a name for the constant. TYPE <type> represents a constant named <f>, which inherits the same technical attributes as the existing data type <type>. VALUE <val> assigns an initial value to the declared constant name <f>.

Note − We should use the VALUE clause in the CONSTANTS statement. The clause ‘VALUE’ is used to assign an initial value to the constant during its declaration.

We have 3 types of constants such as elementary, complex and reference constants. The following statement shows how to define constants by using the CONSTANTS statement −


REPORT YR_SEP_12. 

CONSTANTS PQR TYPE P DECIMALS 4 VALUE '1.2356'. 

Write: / 'The value of PQR is:', PQR.

The output is −


The value of PQR is: 1.2356

Here it refers to elementary data type and is known as elementary constant.


Following is an example for complex constants −


BEGIN OF EMPLOYEE,  

Name(25) TYPE C VALUE 'Management Team',  

Organization(40) TYPE C VALUE 'Tutorials Point Ltd',  

Place(10) TYPE C VALUE 'India',  

END OF EMPLOYEE.

In the above code snippet, EMPLOYEE is a complex constant that is composed of the Name, Organization and Place fields.


The following statement declares a constant reference −

CONSTANTS null_pointer TYPE REF TO object VALUE IS INITIAL.

We can use the constant reference in comparisons or we may pass it on to procedures.


Serkan AKKAVAK

Computer Engineer BSc

SAP Department Manager

Contact : serkurumsal@yandex.com