Summary -

In this topic, we described about the below sections -

Elementary types are the smallest individual units of types. Elementary type is a single data type used to define the data. In elementary type, only one data type is used to declare a variable for the data.

Elementary data types are divided into two types based on the legth of the declaration. Those are -

  • Elementary fixed length data types
  • Elementary variable length data types

Below table specifies the list of elementary data types -

TypeDescriptionKeyword
Fixed length data types Text/Character field C
Numeric textN
IntegersI
Packed numberP
Floating pointF
DateD
TimeT
Byte/Hexadecimal fieldX
Variable length data typesText stringSTRING
XSTRINGXSTRING

Below table specifies the data type, length, range and description of each data type.

Data type KeywordLengthRangeDescription
C1 character = 1 character1 to 65535Used for regular text information.
Left justified and spaces padded to right.
Default data type when none specified.
N1 character = 1 character1 to 65535Used for set of digits.
Right justified and zeroes padded to left.
I4 bytes-2147483648 to 2147483647Used for integers.
Right justified and zeroes padded to left.
P8 bytes [- 10 ^ (2len -1) + 1] to [+ 10 ^ (2len -1) + 1]
(where length = fixed length)
Numbers stored in compressed format.
Right justified and zeroes padded to left.
Can be used for all calculations.
F8 bytes1E-307 to IE+307
positive or negative
Specified as floating point.
Can be used for all calculations.
D8 characters8 charactersUsed for internal representation of YYYYMMDD using Georgian calendar date.
Can set default format in profile.
Several output formats supported.
Supports arithmetic operations.
T6 characters6 charactersUsed to store the time.
Format is HHMMSS.
Several output formats supported.
Supports arithmetic operations.
X1 byteAny byte values (00 to FF)Used to store hexadecimal values in binary format.
2 hex digits stored in 1 byte.
STRINGVariable lengthAny alphanumeric charactersUsed for any alphanumeric characters.
XSTRINGVariable lengthAny byte values (00 to FF)Used for any alphanumeric characters stored in hex decimal format.

Example -

Write a program with all elementary data types.


Code -

*&---------------------------------------------------------------------*
*& Report  Z_ELEMETARY_DATATYPE
*&---------------------------------------------------------------------*
*& Program Written by TUTORIALSCAMPUS
*&---------------------------------------------------------------------*

REPORT  Z_ELEMETARY_DATATYPE.

* Declaring W_CHAR of character type of length 30 and 
*initialized with 'character data type'.
DATA W_CHAR(30) TYPE C VALUE 'character data type'.

* Declaring W_NUM of type Numeric with length of 1 byte.
DATA W_NUM TYPE N VALUE 100.

* Declaring W_INT of integer type.
DATA W_INT TYPE I VALUE 100.

* Declaring W_PCK of type compressed format.
DATA W_PCK TYPE P VALUE 100.

* Declaring W_FLT of type Floating point.
DATA W_FLT TYPE F VALUE 100.

* Declaring W_DATE of type Date.
DATA W_DATE TYPE D.

* Declaring W_TIME of type Time.
DATA W_TIME TYPE T.

* Declaring W_HEX of type hexadecimal binary format.
DATA W_HEX TYPE X VALUE 100.

* Assinging current date from system variable.
W_DATE = SY-DATUM.

* Assinging current time from system variable.
W_TIME = SY-UZEIT.

* Displaying all variables.
WRITE : 'W_CHAR: ', W_CHAR,
      / 'W_NUM : ', W_NUM,
      / 'W_INT : ', W_INT,
      / 'W_PCK : ', W_PCK,
      / 'W_FLT : ', W_FLT,
      / 'W_DATE: ', W_DATE,
      / 'W_TIME: ', W_TIME,
      / 'W_HEX : ', W_HEX.


Output -

Elementary Data Type Output

Explaining Example -

W_CHAR is a character type of length 30 and left justified. So all the data gets displayed in the output.

W_NUM is numeric type, 1 character length and right justified. So the last digit of right side(0) gets displayed in the output.

W_INT is integer type, 4 bytes length and right justified. So the 100 value right justified and spaces padded to the left in remaining places.

W_PCK is packed number type, 8 bytes length and right justified. So the 100 value right justified and spaces padded to the left in remaining places.

W_FLT is floating type and 8 bytes length. So the result 100 displayed in exponential format.

W_DATE is date type and 8 characters length. So the result of run date displayed in DDMMYYYY format.

W_TIME is time type and 6 characters length. So the result of run time displayed in HHMMSS format.

W_HEX is binary type and displayed as hexa decimal value. So the result 100 displayed in hexadecimal format value 64.