¡Caminando hacia el éxito!

Aprende en Comunidad

Avalados por :

Optimización de Búsqueda en ABAP: Casos de Uso y Ejemplos Prácticos

  • Creado 01/03/2024
  • Modificado 01/03/2024
  • 13 Vistas
0
Cargando...
Hi,

When you start to code ABAP you are probably not paying much attention to the table typekind you use (STANDARD, SORTED, HASHED), and you usually forget to use the statement addition BINARY SEARCH.

Most probably you know that the use of this addition improves performance, but when you're starting you may not be aware of how much it does. When using LOOP WHERE the BINARY SEARCH is performed under the hood, so for newbies it can become even more complex to understand when and why ABAP is doing this search optimally for you.

I coded a little example testing 4 cases:

  1. LOOP WHERE over a STANDARD TABLE (Sorted with a sort statement)

  2. LOOP WHERE over a SORTED TABLE

  3. READ TABLE BINARY SEARCH + LOOP FROM INDEX over a STANDARD TABLE (Sorted with a sort statement)

  4. READ TABLE BINARY SEARCH + LOOP FROM INDEX over a SORTED TABLE


I prepared the variables below for my program:
  TYPES: BEGIN OF lt_head,
           docnr TYPE n LENGTH 10,
           gjahr TYPE gjahr,
         END OF lt_head,

         BEGIN OF lt_position,
           docnr TYPE n LENGTH 10,
           gjahr TYPE gjahr,
           posnr TYPE n LENGTH 3,
         END OF lt_position.

  DATA: li_head TYPE STANDARD TABLE OF lt_head
                WITH HEADER LINE,
        li_positions TYPE STANDARD TABLE OF lt_position
                     WITH HEADER LINE,
        li_positions_sorted TYPE SORTED TABLE OF lt_position
                            WITH NON-UNIQUE KEY docnr gjahr posnr
                            WITH HEADER LINE.

LI_HEAD will contain 5000 entries and each of these entries will contain 5 entries in the LI_POSITIONS and LI_POSITIONS_SORTED tables. The program is going to perform just the LOOPs, no code inside, as shown below (You can ignore the macros I used to get runtime measurement):
  START_MEASUREMENT 'SORT'.
  SORT li_positions BY docnr gjahr posnr.
  END_MEASUREMENT 'SORT'.

  START_MEASUREMENT 'LOOP WHERE'.
  LOOP AT li_head.
    LOOP AT li_positions WHERE docnr = li_head-docnr
                           AND gjahr = li_head-gjahr.
    ENDLOOP.
  ENDLOOP.
  END_MEAS    
            
Pedro Pascal
Se unió el 07/03/2018
Pinterest
Telegram
Linkedin
Whatsapp

Sin respuestas

No hay respuestas para mostrar No hay respuestas para mostrar Se el primero en responder

contacto@primeinstitute.com

(+51) 1641 9379
(+57) 1489 6964

© 2024 Copyright. Todos los derechos reservados.

Desarrollado por Prime Institute

¡Hola! Soy Diana, asesora académica de Prime Institute, indícame en que curso estas interesado, saludos!
Hola ¿Puedo ayudarte?