✒️ABAP El procesamiento de los datos
ABAP El procesamiento de los datos
ABAP Data Processing
Variable Initialization
Before utilizing variables in our program, we must ensure their content is empty, meaning the variables are clean. To initialize or clear the content of variables, we use the CLEAR statement.
CLEAR: variable_1, variable_2, variable_3, variable_4.
Depending on the variable type, the result of initialization will differ. For instance, if we declare the following variables:
DATA: d_date TYPE d,
t_time TYPE t,
i_quantity TYPE i,
s_title TYPE string,
c_name(40) TYPE c,
n_phone(13) TYPE n,
p_pi TYPE p DECIMALS 11.
The result of initializing them with CLEAR would be:
d_date → '00000000'.
t_time → '000000'.
i_quantity → 0.
s_title → ''.
c_name → ''.
n_phone → 0000000000000.
p_pi → 0,00000000000.
An essential statement for checking variable content is IS INITIAL; we can use this statement to check if a specific variable's content is initial or not, meaning if the content of the variable is empty or not. Example usage:
IF d_date IS INITIAL.
WRITE 'The date is empty'.
ENDIF.
Note: The IS INITIAL statement is valuable when working with internal tables.
Assigning Values to Variables
After declaring and initializing variables, the next step is to assign them a specific value. We have two alternatives. The first involves using simple assignment, like this:
i_quantity_1 = i_quantity_value_2.
The second alternative for assigning values to variables is using the MOVE statement:
MOVE i_quantity_1 TO i_quantity_value_2.
Note: If we assign the value of a variable to another, and they are of different types, there is no runtime error. For example, if we assign an integer-type variable's value to a character-type variable, ABAP will convert the integer content to character content at the time of assignment.
Variable Usage Reference
The usage reference functionality allows us to determine where in the code of an ABAP program a specific variable is used. This functionality is accessed in two different ways:
- Select the variable you want to know where it is used and click on the usage reference icon on the ABAP editor's standard toolbar.
- Double-click on the variable name in the program code; the system will take you to the variable declaration, where you can double-click on the variable declaration again to open the usage reference functionality.
String Operations
ABAP includes statements for character handling, crucial for the daily work of an ABAP programmer. They are:
- CONCATENATE: Used to concatenate multiple alphanumeric fields into one.
CONCATENATE c_field1 c_field2 c_field3 INTO c_field SEPARATED BY '.'.
- TRANSLATE: Used to convert characters from uppercase to lowercase or vice versa or to perform character substitutions based on certain rules.
TRANSLATE s_text TO UPPER CASE.
- REPLACE: Used to replace a part of a character string with another character string or character.
REPLACE 'Hello' WITH 'House' INTO s_text.
- SPLIT: Used to split an alphanumeric field into multiple fields by a separator.
SPLIT s_long_text AT ',' INTO c_field1 c_field2 c_field3 c_field4.
- SHIFT: Used to shift(transfer) the content of an alphanumeric field. It shifts the content of a field up to a given string.
SHIFT c_alphabet BY 5 PLACES. "Moving 5 chars to the left
- SEARCH: Used to find a character string within an alphanumeric field.
SEARCH c_alphabet FOR 'ABC'.
- CONDENSE: Used to remove blank spaces in alphanumeric fields. It removes any sequence of blank spaces, leaving only one between existing words in the field. Leading blank spaces also disappear.
CONDENSE wa_doctor.
Arithmetic Operations
In ABAP, the four basic operations - addition, subtraction, multiplication, and division - can be implemented in two different ways, yielding the same result.
- We can use ti_field1 = i_field2 + i_field3. he plus sign and the assignment, like this:
- We can alsoCOMPUTE i_field1 = i_field2 + i_field3. use the COMPUTE statement, achieving the same result in both ways:
The following statements are also used for arithmetic operations with data:
ADD 1 TO i_number. "Adds 1 to the variable I_NUMBER.
SUBTRACT 1 FROM i_number. "Subtracts 1 from the variable I_NUMBER.
MULTIPLY i_number BY 2. "Multiplies the variable I_NUMBER by 2.
DIVIDE i_number BY 2. "Divides the variable I_NUMBER by 2.
i_number = i_number + 1. "Adds 1 to the variable I_NUMBER.
i_number = i_number - 1. "Subtracts 1 from the variable I_NUMBER.
i_number = i_number * 2. "Multiplies the variable I_NUMBER by 2.
i_number = i_number / 2. "Divides the variable I_NUMBER by 2.
E.g.
REPORT ztest_abap_jega_3.
DATA: v_fecha(10) TYPE c,
v_fecha_actual(10) TYPE c.
START-OF-SELECTION.
CLEAR: v_fecha, v_fecha_actual.
v_fecha = sy-datum.
CONCATENATE v_fecha+6(2) v_fecha+4(2) v_fecha+0(4)
INTO v_fecha_actual SEPARATED BY '/'.
WRITE:/ 'La Fecha actual del sistema es:' , v_fecha_actual.
" Output: La Fecha actual del sistema es: 13/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