Before Understanding the Data type first understand the Data object. Data objects are variables that we declare in the program. It occupies some memory where you can store the data from external sources. Data can be of different types, so data types are responsible for defining the type of data of the data object. Data types are crucial for memory optimization in the ABAP programming language.
Data Types in SAP
Types Of Data Types
There are three types of Data Types
- Elementary Types
- Complex Types
- Reference Types
Elementary Data Types
Elementary data types are single fields. These types are by default in the system kernel. They are categories into two parts:
- Predefined types
- User defined types.
Predefined types
There are different predefined types that are by default available in the SAP system kernel.
- C : C refers to characters whenever we have to process characters characters we use C data types. By default its size is 1 character but you can additionally specify the length using 'LENGTH' keyword.
- N : N refers to numeric character, if we want to store numbers we use N data types. You can additionally specify the length using 'LENGTH' keyword. You can't perform arithmetic operation on this type of data object.
- I : I refers to integer, it is used in storing I integer value. It's size is fixed and can not specify extra length. It's size is also fixed and you can perform arithmetic operation on this type data object.
- D : This data type is use when we have to declare date. It's size is fixed and when we declare D the system will create a data object whose size is of 8 characters.
- T : This data type is for Time. It's size is fixed and system will create a data object whose size is of 6 character.
- F : F stands for floating point. This data type is use when we have to store very large number. It's size is also fixed and you can perform arithmetic operation on this type data object.
- P : P stands for Packed decimal . It is use to store integer with up to n decimal points. You can specify length of P.
- Decfloat16 : It is decimal floating point of size 8 bytes that can store up to 16 digits it is combination of both integer and floating point.
- Decfloat34 : This is the another version of decimal floating point of size 16 bytes that can store up to 34 digits.
- X : This is used for hexadecimal values and for storing binary data.
- STRING : This data type can store alphanumeric character, it is of dynamic length that means memory allocation done at run time. This helps in memory optimization.
- XSTRING : It's purpose is same as of X data type both is used for hexadecimal values but XSTRING is of dynamic length. It is commonly used for handling binary files such as images.
Here we are providing you the table that specifies the data type, length, initial field lengths and valid field lengths.
|
Not Fixed
|
1
| 1 to 65535
|
not fixed
|
1
| 1 to 65535
|
fixed
| 8 characters
| 8 character
|
fixed
|
4
|
4
|
fixed
|
8
|
8
|
not fixed
|
8
|
8
|
not fixed
|
1
|
1-65,535
|
fixed
| 6 characters
| 6 characters
|
fixed
| 8 (16 digits)
| 8 (16 digits)
|
fixed
| 16 (34 digits)
| 16 (34 digits)
|
dynamic
| Allocated at Run time
| Allocated at Run time
|
dynamic
| Allocated at Run time
| Allocated at Run time
|
Syntax:
DATA variable_name TYPE data_type.
Example: //Declaring zip code
DATA zip_code TYPE c LENGTH 6.
//Initializing ZIP_CODE
ZIP_CODE='201308'.
//PRINT ZIP_CODE
Write ZIP_CODE.
OUTPUT: 201308
User Defined Types: User defined type is something that you can define in your program that is know as local user defined or you can define it to centrally in the system that is known as global user define types.
Complex Data Types
Complex data types are combination of different elementary data types. It is similar to struct or record in other programming language by which you can create structured data structure with multiple fields. This helps you in organizing and representing the complex data in an efficient and optimize way.
Types of complex data types
This data type are classified into two types:
- Structure type
- Table type.
Structure Data Type: This is a type of complex data type of ABAP programming language that contains or defines a collection of fields each filed has its own data type. Fields data type may be same or different which helps to organize and represent complex data.
Syntax: Fields are defined using the BEGIN OF and END OF statements within the TYPES declaration.
DATA: BEGIN OF name
fields TYPE field1_data_types,
END OF name
Example: Here is an example of structure data type
DATA: BEGIN OF employee
empId TYPE n,
name TYPE c,
department TYPE c,
dateOfJoining TYPE d,
END OF employee
Here we have create a Structure data type named employee. That contains fields empID that refers to Id of an employee that is of type N(numeric character), name reference to name of the employee of type C(character), department reference to department of type C(character) and dateOfJoining reference to Joining date of employee of Type D(Date).
Table Data Types: It is another type of complex data type, that allows you to define a structure for table of data. when there are collections of data in ABAP program then we use this data types. Another name of this data types are array data types because it defines dynamic arrays that can hold multiple data records of the same data type.
Syntax:
TYPES: BEGIN OF table-name OCCURS initial size,
field_name_1 TYPE data_type_1,
field_name_2 TYPE data_type_2,
...
END OF table-name.
Syntax for using this table data type
DATA: table-name1 TYPE TABLE OF table-name .
Example: Here is an example of table data types
TYPES: DATA: BEGIN OF employee
empId TYPE n,
name TYPE c,
department TYPE c,
END OF employee
How to use this table data types
DATA: is_employee TYPE employee,
it_employee TYPE TABLE OF employee
Now add data records
is_employee - empId =01,
is_employee - name = 'John Doe',
ls_employee - department = 'HR'.
Now append data to the internal table it_employee
APPEND is_employee TO it_employee
Reference Data Types:
Reference data types are the deep data types that describe the reference variable of the data object ,reference variable is reference variable is used to store references or pointers to data objects rather than the actual data itself. This concept is similar to pointers in other programming languages.
Syntax:
DATA: ref_string TYPE REF TO string,
ref_table TYPE REF TO TABLE OF string.
Reference data types are particularly useful when you need to work with objects dynamically or pass objects by reference, enabling you to manipulate the underlying data or behavior.
Similar Reads
SAP Advanced Business Application Programming (ABAP)
SAP ABAP stands for Advanced Business Application Programming. SAP ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP SE. ABAP is primarily used for developing and customizing applications within the SAP ecosystem, which i
6 min read
What is SAP ABAP: A Brief Overview
SAP ABAP (Advanced Business Application Programming) is a high-level programming language created by the German software company SAP SE. ABAP is primarily used for developing and customizing applications within the SAP ecosystem, which includes enterprise resource planning (ERP) systems and other bu
8 min read
SAP ABAP | Basic Syntax & Statements
The German software company SAP created the high-level programming language, ABAP (Advanced Business Application Programming) primarily, this language serves as a tool for developing applications within the SAP R/3 system. Designed with simplicity and ease of learning in mind, ABAP syntax allows eff
9 min read
SAP ABAP | Understanding Variables
What is a Variable?Variable are named data objects that refer to the memory location allocated during the program execution for processing. As the name indicates, users can use refer to the range of values that may be stored inside and the range of actions that can be carried out on the variable.Syn
7 min read
SAP ABAP Keywords
The core of many global enterprises, SAP ABAP stands for Advanced Business Application Programming. It is the heart and soul of SAP systems. It gives users the ability to expand and modify SAP apps to satisfy particular business needs. The fundamental building blocks of SAP ABAP are its keywords, wh
5 min read
SAP ABAP | Constants & Literals Explained
In the world of SAP ABAP (Advanced Business Application Programming), the use of Constants and Literals is necessary for the effective handling of data. Literals are used to denote specific data types such as numbers, characters, strings, and boolean values. Constants & Literals in SAP What are
7 min read
SAP ABAP | Data Types
Before Understanding the Data type first understand the Data object. Data objects are variables that we declare in the program. It occupies some memory where you can store the data from external sources. Data can be of different types, so data types are responsible for defining the type of data of t
6 min read
Relational operators in SAP ABAP
Relational operators in SAP ABAP are symbols or combinations of symbols that compare values and return a Boolean result (either true or false). These operators allow developers to establish relationships between variables, constants, or expressions, facilitating decision-making processes in the prog
6 min read
Operators in SAP ABAP
High-level programming languages like SAP ABAP (Advanced Business Application Programming) are used to create apps in the SAP environment. Operators are essential for the execution of many different operations in SAP ABAP, ranging from straightforward arithmetic computations to complex logical analy
7 min read