ABAP Define DATA

  Define Data

Over View

The DATA is define the place that is stores a value that is called a variable. When created the add-on programs, we always are using the DATA define.
It is refer other type and we can have a value into local place in the add-on programs.
In this page it would create a variable refer other type.

Sample code

*a variable 
DATA: V_CHRA(10)   TYPE C.           "Character of 10 length
DATA: V_NUM(10)    TYPE N.           "Numeric of 10 length
DATA: V_INT        TYPE I.           "Integer
DATA: V_DEC(18)    TYPE P DECIMAL 3. "Decimal place 3
DAtA: V_STR        TYPE STRING.      "String
DATA: V_VBELN      TYPE VBAK-VBELN.  "Refer Sales Order Number(Character of 10 length)

*In case use local Type
TYPES: 
  BEGIN OF TY_Z1,
    V_COL1 TYPE C,
    V_COL2 TYPE C,
    V_COL3 TYPE C,
  END OF TY_Z1.

*Work Area
DATA: WK_Z1 TYPE TY_Z1.

*Internal Table
DATA: IT_Z1 TYPE TABLE OF TY_Z1. "Standard table

Description

Let’s confirm it.
「DATA: V_CHRA(10) TYPE C」 is define that can store characters of 10 length.
If change the length, please change (10). and if omission it, it will be character of 1 length.

「DATA: V_NUM(10) TYPE N」 is define that can store numeric of 10 length and we can use 0-9 only.
If it is store a value 777, actually the value stores as like 0000000777.

「DATA: V_INT TYPE I」 cannot use decimal place.
「DATA: V_DEC(18) TYPE P DECIMAL 3」 is define that can store decimal place. It always use if use currency and quantity.
「DAtA: V_STR TYPE STRING」 is string, but we almost use char than string.
「DATA: V_VBELN TYPE VBAK-VBELN」 is popular in add-on program. In this case, a variable refer the column VBELN of table VBAK.

If define as 「DATA: WK_Z1 TYPE TY_Z1」、we can use as like WK_Z1-V_COL1、WK_Z1-V_COL2、K_Z1-V_COL3.
Internal table can use column above with multiple record.

Please refer here for Define type