🚀PROMO #PLANCARRERA2024 - 🔥Bonificaciones, Precios Congelados y Cuotas

 X 

✒️ABAP La performance en ABAP

ABAP La performance en ABAP

ABAP La performance en ABAP

Performance in ABAP

Performance refers to the analysis of the execution and efficiency of ABAP programs. In this analysis, there are three fundamental aspects:

  • The processing time of the program logic.
  • The processing time of accesses to database tables.
  • The processing time of the ABAP system.

Of these three times, the most resource-consuming one is the processing time of accesses to database tables, followed by the processing of logic, and finally the processing of the ABAP system.

For this analysis, we have the transaction SE30, which evaluates how the execution and processing time of the program are distributed.

To do this, upon entry, the name of the program is indicated, and the Evaluate button is pressed. This will show us how the percentage distribution of processing times for ABAP logic, the database, and the system.

The ideal situation would be for the highest percentage of processing to be the ABAP logic and the lowest to be the database table. To achieve this, it is necessary to adhere to good programming practices.

Good and Bad Practices in Database Access

  • Avoid SELECT*: The SELECT* statement retrieves ALL data from the specified or indicated table. Instead of fetching all, it is suggested to specify which data needs to be retrieved, like so:

Wrong:

SELECT * FROM zuser_table INTO TABLE it_users.

Right:

SELECT user_id, username, email
FROM zuser_table
INTO TABLE it_users.

  • Avoid SELECT ENDSELECT: The SELECT ENDSELECT statement generates a loop to process records retrieved from another database table. However, it's more efficient to use SELECT INTO TABLE.

Wrong:

SELECT * FROM zuser_table INTO TABLE it_users.
ENDSELECT.

Right:

SELECT user_id, username, email
FROM zuser_table
INTO TABLE it_users.

  • Avoid SELECT without WHERE: When using the SELECT statement without a condition, ALL records from the database table are processed or fetched. It is ideal to use WHERE with as many specifications as possible to reduce processing to what is necessary. It is also suggested to avoid negative conditions or the use of NE.

Wrong:

SELECT * FROM zuser_table INTO TABLE it_users.

Right:

SELECT user_id, username, email
FROM zuser_table
WHERE is_active = 'X'
INTO TABLE it_users.

  • Avoid SELECT within a LOOP: Executing one or more SELECT statements within a LOOP ENDLOOP will result in selecting each record while looping through the table. It's possible to use a SELECT SINGLE with specific conditions to select the first applicable case. Or retrieve all necessary records in internal tables first, then within the LOOP, access them using the READ TABLE statement. Additionally, retrieving all records from database table executes FOR ALL ENTRIES within the SELECT to retrieve records from the database into memory.

Wrong:

LOOP AT it_orders INTO wa_order.
SELECT * FROM zuser_table INTO wa_user WHERE user_id = wa_order-user_id.
" Process user data...
ENDLOOP.

Right:

SELECT * FROM zuser_table INTO TABLE @it_users WHERE user_id IN @it_orders-user_id.

LOOP AT it_orders INTO wa_order.
" Access user data from it_users table...
ENDLOOP.

  • Avoid using INSERT, UPDATE, MODIFY, and DELETE statements within a LOOP: Doing this inside the LOOP will generate a longer table and require more resources. Instead, it is recommended to use these statements at the end or outside the LOOP.

Wrong:

LOOP AT it_items INTO wa_item.
INSERT INTO zitem_table VALUES wa_item.
ENDLOOP.

Right:

INSERT zitem_table FROM TABLE it_items.

  • SELECT vs JOIN: When data from multiple database tables is required, using SELECT after SELECT is not recommended. Instead, use the JOIN statement as necessary. For example:

Wrong:

SELECT carrid, connid FROM spfli INTO TABLE @it_spfli.
SELECT dldate, planetype FROM sflight INTO TABLE @it_sflight.

Right:

SELECT tl~carrid, tl~connid, t2~dldate, t2~planetype, tl~countryfl
FROM spfli AS tl
INNER JOIN sflight AS t2
ON tl~carrid = t2~carrid AND tl~connid = t2~connid
INTO TABLE @it_combined_data.

Good and Bad Practices in ABAP Logic Processing

  • READ TABLE BINARY SEARCH: When searching for a record in a table using the READ TABLE statement, the search is done sequentially. However, binary search partitions the table, searching in halves, offering better performance. To implement it, the search field in the internal table must be sorted ascendingly or descendingly, and add the BINARY SEARCH clause at the end of the READ TABLE:

Bad Practice:

READ TABLE it_suppliers INTO wa_suppliers WITH KEY name = 'Ariel'.

Good Practice:

SORT it_suppliers BY name ASCENDING.
READ TABLE it_suppliers INTO wa_suppliers WITH KEY name = 'Ariel' BINARY SEARCH.

  • Avoid LOOP ENDLOOP within another LOOP ENDLOOP: Performing LOOPS within another LOOP generates an exponential search for records. It's suggested to use the WHERE conditional and binary search to optimize processing, like so:

Bad Practice:

LOOP AT it_suppliers INTO wa_suppliers.
LOOP AT it_users INTO wa_users.
" Processing logic
ENDLOOP.
ENDLOOP.

Good Practice:

SORT it_users BY name ASCENDING.
LOOP AT it_suppliers INTO wa_suppliers WHERE dni GT '50000000'.
READ TABLE it_users INTO wa_user WITH KEY dni = wa_suppliers-dni BINARY SEARCH.
ENDLOOP.

  • LOOP CHECK vs LOOP WHERE: While CHECK and IF-ENDIF statements can be used as filters within a LOOP, they are not recommended as they read all records. It's optimal to implement WHERE with specific conditions.

Bad Practice:

LOOP AT it_customers INTO wa_customer.
CHECK wa_customer-status = 'Active'.
" Processing logic for active customers
ENDLOOP.

Good Practice:

LOOP AT it_customers INTO wa_customer WHERE status = 'Active'.
" Processing logic for active customers
ENDLOOP.

  • Don't forget WHEN OTHERS in CASE statement: In the CASE-ENDCASE conditional, it's crucial to specify the case where none of the indicated cases are found, as otherwise, the system will throw an error or lead to unexpected situations. Implement the alternative WHEN OTHERS.

Bad Practice:

CASE lv_condition.
WHEN 'A'.
" Case A logic
WHEN 'B'.
" Case B logic
ENDCASE.

Good Practice:

CASE lv_condition.
WHEN 'A'.
" Case A logic
WHEN 'B'.
" Case B logic
WHEN OTHERS.
" Handling unexpected conditions
ENDCASE.

  • APPEND from one internal table to another internal table: When adding records from one internal table to another of the same type, the worst option is to take the content of one table in a LOOP, transferring the information record by record to the other table. Instead, it's more efficient to use the APPEND LINES OF statement in a single line to transfer the content from one table to another, like so:

Bad Practice:

LOOP AT itab1 INTO wa_itab1.
APPEND wa_itab1 TO itab2.
ENDLOOP.

Good Practice:

APPEND LINES OF itab1 TO itab2.

  • INSERT from one internal table to another internal table: When it's necessary to insert records from one internal table to another of the same type, the worst option is to insert record by record from one table to another. Instead, it's optimal to insert the content at a specific position from one table to another using the INSERT LINES OF statement, like so:

Bad Practice:

LOOP AT itab1 INTO wa_itab1.
INSERT wa_itab1 INTO TABLE itab2.
ENDLOOP.

Good Practice:

INSERT LINES OF itab1 INTO TABLE itab2 INDEX lv_index.

  • Removing duplicate records from an internal table: When it's necessary to check and eliminate duplicate records from a table, primarily, the fields to be examined must be sorted. The worst option would be to check record by record if the first record looks like the next one and if so, delete it. However, it's possible to use the DELETE ADJACENT DUPLICATES statement along with COMPARING to compare the specified fields in this process.

Bad Practice:

DELETE ADJACENT DUPLICATES FROM itab.

Good Practice:

DELETE ADJACENT DUPLICATES FROM itab COMPARING field1 field2.

  • Copying internal tables: When it's necessary to copy records from one internal table to another of the same type, the worst option is to clear the content of one table to pass the information from the other there. However, it's optimal to assign table1[] = table2[], overriding the content of one table with another.

Bad Practice:

CLEAR itab2.

LOOP AT itab1 INTO wa_itab1.
APPEND wa_itab1 TO itab2.
ENDLOOP.

Good Practice:

itab2[] = itab1[].

  • Comparison of internal tables: When it's necessary to compare two internal tables to determine if their content is the same, the worst way is to do it manually. However, there's an optimal way to carry out this task using an IF-ENDIF within which the tables will be assigned, and in a single line, it will be determined if there's a duplicate, like so:

Bad Practice:

LOOP AT itab1 INTO wa_itab1.
READ TABLE itab2 INTO wa_itab2 WITH KEY field1 = wa_itab1-field1.

IF sy-subrc <> 0.
" Records not matching
ENDIF.
ENDLOOP.

Good Practice:

IF itab1[] = itab2[].
" Processing logic for equal tables
ENDIF.


 

 

 


Sobre el autor

Publicación académica de Jaime Eduardo Gomez Arango, en su ámbito de estudios para la Carrera Consultor ABAP.

SAP Master

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

✒️+Comunidad Académica CVOSOFT

Continúe aprendiendo sobre el tema "La performance en ABAP" de la mano de nuestros alumnos.

SAP Senior

Performance ABAP. Performance: Nos referimos al análisis del desempeño de un programa o transacción. Buenas o malas practicas en el performance o utilización de otro código. Transacción estándar: SE30 para el performance dar clic en el botón Tips & Tricks. Verificar todas las carpetas para verificar el performan, seleccionamos un código y ahí damos clic en el botón Medir tiempo ejec. Permite grabar en archivo los códigos que se ejecutan. Permite testear el código que se escribe. Evaluar como se distribuye en tiempo de procesamiento de un programa ABAP. Ingresar el nombre del programa, ejecutar y presionar el botón evaluar.

Acceder a esta publicación

Creado y Compartido por: Rafael Razo

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Senior

PERFORMANCE Cuando hablamos de Performance nos referimos al analisis del desempeño de un programa o transaccion. Para revisar el performance ir a la transaccion SE30. una vez ahi presionar el boton Tips & Tricks aqui se van analizando las diferentes practicas de programacion ABAP para determinar cuales son buenas y cuales no son recomendables. Abrir la carpeta interface SQL seleccionar "Select aggregates" aqui vemos dos codigos abap que realizan lo mismo de dos formas diferentes el objetivo es obtener el maximo valor. para obtener la performance de ambos codigo presionamos el boton "Medir tiempo ejec." comparamos la diferencia en micro segundos de uno y otro. De la misma manera se van revisando y comparando los...

Acceder a esta publicación

Creado y Compartido por: David Camacho Espinoza

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Senior

Performance en ABAP

Acceder a esta publicación

Creado y Compartido por: Luis Manuel Olivier Melo

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Master

PERFOMANCE. La transacción SE30 es util para el analisis y el performance de un programa, utilizando el botón trips & tricks. Aqui vamos analizando las diferentes practicas de programación ABAP que utilizamos. Para medir el performance hacemos clic en el botón medir tiempo ejec y verificamos el tiempo de ejecución.

Acceder a esta publicación

Creado y Compartido por: Maria Ysabel Colina De Magdaleno

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Senior

Al igual que en otros lenguajes de programación el performance cumple un rol importante en la calidad de nuestro codigo pero hay que tomar en cuenta que mientras mas facil es para el programador desarrollar una solucion de menor performance sera.

Acceder a esta publicación

Creado y Compartido por: Faharid Manjarrez

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Master

Performance en ABAP Performance de los programas. se refiere al análisis del desempeño y rendimiento los programas para ello trabajaremos con la transacción SE30 presionamos el botón TIPS and TRICKS (F6) para determinar las practicas que son buenas y cuales no son recomendables y debemos dejar de utilizarla. Los tiempos de procesamiento entre un programa ABAP se divide entre ABAP, la base de datos y el sistema. El principal para evaluar la performance es el tiempo de la base de datos ya que es el que más recurso consume y más tiempo requiere, mientras más alto sea el porcentaje de procesamiento de la base de datos en comparación de los otros dos porcentajes, los tiempos de duración...

Acceder a esta publicación

Creado y Compartido por: Jeferson José Peña Curvelo

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Senior

Performance de los programas: es el analisis del desempeño y rendimiento del programa, para ello vamos a trabajar con una transaccion estander se sap que es sumamente util para el analisis de la performance TX:SE30

Acceder a esta publicación

Creado y Compartido por: Cristian Merlo

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Senior

Los tiempos de procesamiento de un programa ABAP se dividen entre ABAP , la base de datos y el sistema, el que demos de tomar en cuenta principalmente es el tiempo de la base datos, ya que este es el que mas recursos consume y por consiguiente mas tiempo requiere, cuando mas alto sea el porcentaje del procesamiento de la base de datos en comparacion a los otros dos procentajes los tiempos de duracion del programa se iran por las nubes,lo ideal es que el procentaje de procesamiento ABAP sea lo mas alto posible y el procesamiento de la base de datos sea el mas bajo posible, para lograr esto utilizaremos todas las tecnicas de optimizacion de performance.

Acceder a esta publicación

Creado y Compartido por: Marco Antonio Vazquez Gonzalez

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Master

La transacción que se usa para analizar la performance de los programas abap es la SE30 En esta transacción se usa la opción : Tips & Tricks

Acceder a esta publicación

Creado y Compartido por: Juan Carlos Ayala Chira

*** CVOSOFT - Nuestros Alumnos - Nuestro Mayor Orgullo como Academia ***

SAP Master

*****************Performance en ABAP [ 8º de 8 ] La Performance es un elemento en Sistemas que tiene mucha importancia y a veces no nos damos cuenta que, con pequeños cambios en la forma de programar, podemos lograr que mejore muchísimo, aunque estemos hablando de tiempos en microsegundos. Para poder verificar la Performance de un Programa, se puede entrar a la Trx SE30 y ejecutarlo, obteniendo un análisis de los tiempos insumidos. Una forma más detallada es viendo con distintas alternativas de codificación, como cambian los tiempos consumidos. 1) Buscar Valor Máximo. Recomendable SELECT MAX. 2) SELECT con especificación de campos a recuperar. 3) SELECT INTO TABLE. 4) INSERT FROM TABLE....

Acceder a esta publicación

Creado y Compartido por: Jose Angel Valles Bustos

 


 

👌Genial!, estos fueron los últimos artículos sobre más de 79.000 publicaciones académicas abiertas, libres y gratuitas compartidas con la comunidad, para acceder a ellas le dejamos el enlace a CVOPEN ACADEMY.

Buscador de Publicaciones:

 


 

No sea Juan... Solo podrá llegar alto si realiza su formación con los mejores!