✒️ABAP La declaración de datos
ABAP La declaración de datos
Data Types
ABAP is a typed programming language, meaning each variable has a specific type. There are two types:
Complete Types: These have a fixed length set by the standard system. There are eight standard complete data types:
D: Dates in AAAAMMDD format, 8 fixed digits.
T: Times in HHMMSS format, 6 fixed digits.
I: Integer numbers, 4 bytes. (-2,147,483,648 to 2,147,483,648)
F: Floating-point or decimal numbers, 8 bytes.
DECFLOAT16: Decimal floating-point numbers, 8 bytes.
DECFLOAT34: Decimal floating-point numbers, 16 bytes.
STRING: Character string, dynamic length.
XSTRING: Byte sequences of dynamic length (hexadecimal string).
Incomplete Types: The length is not fixed by the standard system, so the programmer must specify it when declaring the variable. There are four standard incomplete data types:
C: Character string, where the length must be specified.
N: Numeric character string, where the length must be specified.
X: Byte sequence (hexadecimal string), where the length must be specified.
P: Packed numbers, where the length and the number of decimal places can be specified.
These 12 variable types are also referred to as primitives. They allow the creation of complete data, two-dimensional structures, or objects from the SAP data dictionary.
To declare a variable, we use the reserved words DATA and TYPE, as follows:
DATA: v_date TYPE d.
To declare a variable with a specific value, we add the word VALUE as follows:
DATA: v_date TYPE d VALUE '20240212'.
DATA: v_time TYPE t VALUE '15:50:00'.
DATA: v_amount TYPE i VALUE '200'.
DATA: v_text TYPE string VALUE 'Hello World'.
DATA: v_name_and_surname(40) TYPE c VALUE 'Jaime Gomez'. "Specify the length; otherwise, it assumes 1
DATA: v_phone(13) TYPE n VALUE '5236987456321'.
DATA: v_pi TYPE p DECIMALS 13 VALUE '3.14159265359'.
Another way is to declare variables using TYPE and assigning the variable to an existing data type in the SAP data dictionary, like this:
"KUNNR is the customer number from the master customer table KNA1
DATA: v_customer_number TYPE kunnr.
It's also possible to declare variables that are of the same type as other variables already created in the system using the LIKE statement:
"Carrid is a field storing the airline's name in the standard SFLIGHT table - SE11: SAP Data Dictionary
DATA: v_carrid LIKE sflight-carrid.
Data Structures
Data structures are types composed of various data types. They are a set of related fields, with components that can be fields, other structures, or tables. The structure exists in memory for the program's duration and is primarily used with internal tables. There are four ways to declare a structure:
- Using DATA:
"Calling the entire table
DATA: flight_data TYPE sflight.
- Using DATA with specific fields:
DATA: BEGIN OF flight_data2,
carrid TYPE s_carr_id, "Airline name
connid TYPE s_conn_id, "Connection code
fldate TYPE s_date, "Date
price TYPE s_price, "Price
END OF flight_data2.
- Using the above structure with complete and incomplete standard data types:
DATA: BEGIN OF flight_data3,
carrid(3) TYPE c, "Airline name
connid(4) TYPE n, "Connection code
fldate TYPE d, "Date
price TYPE p DECIMALS 13, "Price
END OF flight_data3.
- Using TYPES, which are structure formats that can be used by any other structure without rewriting the code:
TYPES: BEGIN OF ty_flight,
carrid TYPE s_carr_id, "Airline name
connid TYPE s_conn_id, "Connection code
fldate TYPE s_date, "Date
price TYPE s_price, "Price
END OF ty_flight.
DATA: flight_data4 TYPE ty_flight.
The choice of form depends on the case, but the fourth form is recommended.
Constants
A constant is a variable declared in a program whose value remains constant during program execution. We use the reserved word CONSTANTS, specifying the data type, value, and length for incomplete data:
CONSTANTS: c_name TYPE string VALUE 'Jega'.
CONSTANTS: c_x(1) TYPE c VALUE 'X'.
Includes and Subroutines
Includes: These are a type of program or object used to modularize and make code more readable and maintainable. There are two types of INCLUDES:
- Data Includes: Group data declarations.
- Subroutine Includes: Group subroutine declarations.
"Double click on the include name / Create the object / Assign package / Create new transport order
INCLUDE ztest_program_data.
System Variables
These are found in the SYST database table. Some commonly used ones include:
- SY-SUBRC: Checks post-execution if the result was successful or not. If successful, it will have a value of 0.
- SY-DATUM: System date in AAAAMMDD format.
- SY-UZEIT: System time in HHMMSS format.
- SY-TABIX: Index of an internal table.
At the beginning of the program, it is suggested to comment on who created or modified it, "signature," the date, improvement number, description, and associated order.
*&---------------------------------------------------------------------*
* {Begin} - JG - M123 - 12/02/2024
*&---------------------------------------------------------------------*
*& Name: Report Z_Name of report
*& Description: des....
*& version: version number
*&---------------------------------------------------------------------*
* {End} - JG - M123 - 12/02/2024
*&---------------------------------------------------------------------*
 
 
 
Sobre el autor
Publicación académica de Jaime Eduardo Gomez Arango, en su ámbito de estudios para la Carrera Consultor ABAP.
Jaime Eduardo Gomez Arango
Profesión: Ingeniero de Sistemas y Computación - España - Legajo: SW34C
✒️Autor de: 99 Publicaciones Académicas
🎓Cursando Actualmente: Consultor ABAP Nivel Avanzado
🎓Egresado del módulo:
Disponibilidad Laboral: FullTime
Presentación:
Ingeniero de sistemas y computación con 8 años de experiencia el desarrollo frontend & backend (react/node) y en cloud (aws), actualmente desarrollando habilidades en sap btp, ui5, abap y fiori.
Certificación Académica de Jaime Gomez