"
Etiqueta > performance
Supported by

LOOP FROM INDEX

It’s very easy to get tied up in knots where performance is concerned when you’re working with internal tables – especially when they’re getting really big. In fact these problems often only arise after a few months, when the tables tend to grow as time goes by.

For example, when you’re looping two tables, one of headers and another of entries, do you do this?


LOOP AT itab1 ASSIGNING <fs1>.
   LOOP AT itab2 ASSGNING <fs2> WHERE field1 = <fs1>-field1.
   ENDLOOP.
ENDLOOP.

Did you know that for big tables this can take ages because LOOP WHERE makes a sequential reading of itab2 for each entry in itab1?

Why don’t you do this instead?


SORT itab2 BY field1.
 
LOOP AT itab1 ASSIGNING <fs1>.

   READ TABLE itab2 WITH KEY field1 = <fs1>-field1 
      BINARY SEARCH TRANSPORTING NO FIELDS.
   CHECK SY-SUBRC = 0.
   lv_tabix = sy-tabix.       
 
   LOOP AT itab2 FROM lv_tabix ASSIGNING <fs2>.
      IF <fs2>-field1 <> <fs1>-field1.
         EXIT.
      ENDIF.
   ENDLOOP.

ENDLOOP.

It makes all the difference in the world in terms of performance. The more data points there are in itab2, the greater the difference.

This advantage of LOOP FROM INDEX also works if you use a SORTED TABLE instead of normal internal tables. But we’ll keep this for another article.

Thanks to Bruno Filipa for this tip.

Greetings from Abapinho.

SAT – The new execution analysis tool

Since I was small I have been using the SE30 transaction for two different things:

  • To analyze a (normally standard) program I don’t know in order to find out what functions it uses, what BADIs it offers, etc;
  • To analyze a program of mine to search for performance problems.

The simple truth is that the SE30 transaction is a total mess. It’s extremely limited and inflexible and it’s useless for any more complex analysis.

The people at SAP seem to agree and have decided to replace it with the fantastic new tool, SAT – ABAP Runtime Analysis, which is more sophisticated all-round. As you might expect, you can access it through the SAT transaction.

If it’s not yet on your system you’ll have to wait for an upgrade. If you already have it, good luck with your research.

Here is a set of screencasts from SAP to teach you how to use the new SAT.

Greetings from Abapinho.

(Português) Macros – Velocidade de ponta

Sorry, this entry is only available in European Portuguese. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

Normalmente quando há um pedaço de código que pretendemos reutilizar várias vezes, transformamo-lo numa sub-rotina que pode depois ser invocada repetidamente. Embora a SAP não saiba estruturar o seu próprio código, ainda assim, o ABAP, coitadinho, permite-o. E até disponibiliza várias alternativas para modularizar o código. Eu conto quatro alternativas que listo aqui, da mais rígida para a mais flácida: METHOD, FUNCTION, FORM, DEFINE. Se os 3 primeiros são já familiar de todos, o último – DEFINE – quase ninguém usa. O DEFINE permite definir macros em ABAP. E o que são macros? São sub-rotinas aparentes.

Aparentes porquê?

Ler o resto do artigo! »

(Português) READ TABLE blablabla TRANSPORTING NO FIELDS

Sorry, this entry is only available in European Portuguese. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

Por vezes ao fazer READ TABLE a uma tabela interna queremos apenas verificar se um determinado registo existe, e não nos preocupamos com os dados retornados. Algo tipo:


READ TABLE lt_kna1 INTO wa_kna1 WITH KEY kunnr = l_kunnr.
CHECK SY-SUBRC = 0.

Ora já que a estrutura WA_KNA1 não vai ser necessária de qualquer forma, mais vale não a usar, usando antes a opção TRANSPORTING NO FIELDS:


READ TABLE lt_kna1 TRANSPORTING NO FIELDS WITH KEY kunnr = l_kunnr.
CHECK SY-SUBRC = 0.

O Abapinho saúda-vos.


About Abapinho
Abapinho runs on WordPress
Articles (RSS) e Comments (RSS).