"
Supported by

I like LIKE

In the ‘bad old days’ when the ABAP was even more old-fashioned than today, variable statements were all made through LIKE and were referenced to table fields:


DATA: V_KUNNR LIKE KNA1-KUNNR.

Then, SAP came to its senses and began to realize the nonsense in this, gradually persuading people to make standardized statements, introducing TYPE:


DATA: V_KUNNR TYPE KUNNR.

And now that TYPE is such a mainstream tool that it became virtually mandatory when using ABAP OO, LIKE strikes again with a new philosophy. A philosophy I totally support.

If you have a variable and wish to state another auxiliary variable to be used in relation to the first one, the latest craze in ABAP computing style is to resort to LIKE. However, this time, referencing the variable rather than the type:


DATA: V_KUNNR TYPE KUNNR,
      V_KUNNR_AUX LIKE V_KUNNR.

This makes the code more clear, since only by looking at the data statement we understand the relations between the several variables stated a lot better.

The most common example would be LIKE LINE OF, which has been handled here on Abapinho before:


DATA: T_KUNNR TYPE STANDARD TABLE OF KUNNR,
      T_KUNNR_AUX_ LIKE T_KUNNR               " aux table
      S_KUNNR LIKE LINE OF T_KUNNR.           " aux line

Thus, whenever you declare auxiliary variables, use LIKE to clarify with which they relate to.

Greetings from Abapinho

2 comentários a “I like LIKE”

  1. Adriano Diz:

    E também a manutenção fica muito mais simplificada ;)

  2. Nuno Godinho Diz:

    Exacto!

Deixe um comentário


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