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 –
Type | Description | Keyword |
---|---|---|
Fixed length data types | Text/Character field | C |
Numeric text | N | |
Integers | I | |
Packed number | P | |
Floating point | F | |
Date | D | |
Time | T | |
Byte/Hexadecimal field | X | |
Variable length data types | Text string | STRING |
XSTRING | XSTRING |
Below table specifies the data type, length, range and description of each data type.
Data type Keyword | Length | Range | Description |
---|---|---|---|
C | 1 character = 1 character | 1 to 65535 | Used for regular text information. Left justified and spaces padded to right. Default data type when none specified. |
N | 1 character = 1 character | 1 to 65535 | Used for set of digits. Right justified and zeroes padded to left. |
I | 4 bytes | -2147483648 to 2147483647 | Used for integers. Right justified and zeroes padded to left. |
P | 8 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. |
F | 8 bytes | 1E-307 to IE+307 positive or negative |
Specified as floating point. Can be used for all calculations. |
D | 8 characters | 8 characters | Used for internal representation of YYYYMMDD using Georgian calendar date. Can set default format in profile. Several output formats supported. Supports arithmetic operations. |
T | 6 characters | 6 characters | Used to store the time. Format is HHMMSS. Several output formats supported. Supports arithmetic operations. |
X | 1 byte | Any byte values (00 to FF) | Used to store hexadecimal values in binary format. 2 hex digits stored in 1 byte. |
STRING | Variable length | Any alphanumeric characters | Used for any alphanumeric characters. |
XSTRING | Variable length | Any 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 –
*&---------------------------------------------------------------------*
*& ReportZ_ELEMETARY_DATATYPE
*&---------------------------------------------------------------------*
*& Program Written by TUTORIALSCAMPUS
*&---------------------------------------------------------------------*
REPORTZ_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 –
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.