SAP ABAP — Data Types
Data Types
The Data Type field specifies the representation used internally by the database to store the value for that field.
Data type is used to describe the technical characteristics the data. For each data type, we need various variables to declare and process the data.
Some of the fields and numbers can be modified using one or more names as the following:
· byte
· numeric
· character-like
In the program we use TYPES keyword to define the data types.
DATA: TY_NAME(10) TYPE C,
TY_LENGTH TYPE P DECIMALS 2,
TY_COUNT TYPE I,
TY_ID(5) TYPE N.
Using Types Will Make Your Code Clearer and Easier to Read
Example
REPORT Z_ABAP_DEVELOPER_TEST.
TYPES: DOLLARS(16) TYPE P DECIMALS 2,
TRY(16) TYPE P DECIMALS 2.
DATA: BEGIN OF AMERICAN_SUMS,
PETTY_CASH TYPE DOLLARS,
PAY_OUTS TYPE DOLLARS,
END OF AMERICAN_SUMS,
BEGIN OF TURKISH_SUMS,
PETTY_CASH TYPE TRY,
PAY_OUTS TYPE TRY,
END OF TURKISH_SUMS.
AMERICAN_SUMS-PAY_OUTS = ‘2500.20’.
TURKISH_SUMS-PAY_OUTS = 10420.
WRITE: / AMERICAN_SUMS-PAY_OUTS,
/ TURKISH_SUMS-PAY_OUTS.
Output:
Structure Data Types
Structure types are used to group the elements that logically belong together. Structure data types are defined with BEGIN OF and END OF keywords.
DATA: BEGIN OF TY_STUDENT,
ID(4) TYPE N,
NAME(20) TYPE C,
AGE TYPE I,
CLASS(10) TYPE C,
END OF TY_STUDENT.
Example
REPORT Z_ABAP_DEVELOPER_TEST.
WRITE / ‘Welcome to Feyzas ABAP Tutorial ‘.
ULINE.
DATA: BEGIN OF FLD_AREA1,
DATA1 VALUE ‘1’,
DATA2 VALUE ‘2’,
DATA3 VALUE ‘3’,
DATA4 VALUE ‘4’,
DATA5 VALUE ‘5’,
DATA6 VALUE ‘6’,
DATA7 VALUE ‘7’,
DATA8 VALUE ‘8’,
END OF FLD_AREA1,
FLD_AREA2 LIKE FLD_AREA1.
FLD_AREA2 = FLD_AREA1.
WRITE: / FLD_AREA2-DATA1, FLD_AREA1-DATA2, FLD_AREA2-DATA6, FLD_AREA1-DATA3.
WRITE: / FLD_AREA1-DATA5, FLD_AREA2-DATA7, FLD_AREA2-DATA4, FLD_AREA1-DATA8.
Output: