ABAP Data Objects

DATA Keyword

Data objects or variables in ABAP are defined with DATA statement. You use an elementary type, or a local type, or a data dictionary global type to define data object.

*defining data objects

TYPES: ty_decimal TYPE P LENGTH 5 decimals 2.
DATA   gv_decimal TYPE ty_decimal. "declaration using local type

DATA:  gv_number TYPE I VALUE 100, "data declaration using elementary type
       gv_name TYPE C LENGTH 30,
       gv_kunnr TYPE kunnr. "declaration using data element of ABAP dictionary
DATA : gv_firstname LIKE gv_name, "using LIKE addition
       gv_lastname LIKE gv_name.
TYPE and LIKE

When creating a Data Object referring to a Data Type use TYPE. Use LIKE keyword when defining data object by referring another data object.

With VALUE keyword you can pre-assign value to Data object.

CONSTANTS

Use CONSTANTS statement to declare constant in ABAP program. You cannot change the value of constant. VALUE keyword is mandatory for defining constants.

CONSTANTS gv_dicsount TYPE I VALUE 10.

Naming conventions for types and data objects

Global variable ( that is a data object that is globally visible within the program ) – prefix name with gv_

Local variable ( is data objects local to a processing block such as subroutines ) – prefix name with lv_

Prefix with ty_ when declaring a type.

prefix with gc_ for global constants.