Supported by

Ignore function module exceptions


When calling a function module which returns exceptions you normally give them sequential numbers like this:

    ali = 'To the moon'
    NOT_FOUND = 1
    GOT_LOST  = 2
    OTHERS    = 3.

But Code Inspector may be configured to report a warning if afterwards you are not careful to add an IF or a CASE to look at SY-SUBRC,
Ler o resto do artigo! »

Best practices
Thou shalt use use exception classes


In classes, consider using exceptions classes over the old ones. These have great advantages and, once understood, are simple and allow for simpler code.




Best practices
Thou shalt use readily translatable explicit literals in programs


In reports, instead of WRITE TEXT-001, use WRITE ‘bla bla bla’(001). This way a default text will always be there and besides the readability of the program is improved.


Best practices
Thou shalt use SALV instead of the old ALV functions


SALV classes are more versatile and more recent than the old function modules. So, for new ALVs always use SALV. The only exception is editable ALVs which SALV classes are still very incapable of doing.



Let’s concatenate


We start with two variables:

DATA word1 TYPE string.
DATA word2 TYPE string.
DATA: phrase TYPE string.

word1 = ‘this’.
word2 = ‘that’.

And we want to concatenate them adding the word “plus” between them and, of course, separate them by space.

Ler o resto do artigo! »

Communication by event between programmes


In Greek mythology, the gods’ most commonly used means of communication with mortals was rape. They would rape for no reason whatsoever.

The closest thing we have to rape in ABAP is the command “SUBMIT”, which is also the most common way of communicating between two programmes.

Ler o resto do artigo! »

Write in multiple lines at the same time


The ABAP editor has many curious functionalities.
You can even write in multiple lines at the same time.

Ler o resto do artigo! »

Where is the boolean?


It’s not.

But they – the people who make and remake the ABAP itself – are trying to mend this unfortunate situation.

Look at this new functionality:

Ler o resto do artigo! »



Did you know that you can do a LOOP on an internal table of one type into a structure of a different type?

Ler o resto do artigo! »

Best practices


Since data operations are much more optimized in the database server than in ABAP, it is always better to use the first as much as possible. FOR ALL ENTRIES should only be used when INNER JOIN doesn’t give us what we need or is not possible (like with BSEG for example). Artificial ranges are also a possible alternative to FOR ALL ENTRIES but be careful not to reach the SQL parser limit. It depends on the database server but as a rule of thumb avoid ranges with more than 1000 lines.
When using FOR ALL ENTRIES always make sure the internal table is not empty or else all lines of the database table will be fetched.

Best practices
Thou shalt not use CHECKs directly in user-exits


User-exits (and enhancements) are usually crowded with CHECKs. The tragic consequence is that, if the check fails, nothing else after it will run. Not even the standard code. Always try to correct these. Encapsulating the code inside a routine (ideally a method) is enough to render it harmless.

Block indent


To indent a block of lines do the following:

Ler o resto do artigo! »

Best practices
Thou shalt use LIKE LINE OF itbl


When declaring structures which will receive data from an internal table, instead of declaring its type directly, use LIKE LINE OF. This way not only it becomes clear that they are related but also, if you happen to change the type of the internal table, you won’t have to worry about updating the structure’s type.

Clearing the buffers of an SAP session


I keep learning new transaction commands. Today I learned some which solve a problem which, although rarely, has happened to me in the past.

Did this happen to you? You make a change to a text of a data element you’re using in a table to be edited through SM30. But when you go and edit that table in SM30 the old text is still there. You activate objects, close windows, open windows, no matter what you do, the new text is not shown.

Ler o resto do artigo! »

Best practices
Thou shalt not COMMIT in user-exits


Never do COMMITs inside user-exits. Also, make sure any external routine you call from there doesn’t do any COMMIT either.

Automatic model just using CTRL-SPACE


Of course you already know the “Model” button in the ABAP editor that allows you to automatically add models for function modules, calls for methods and others.

The new editor has now grown a bit (it’s now only 10 years behind Eclipse instead of 20) and it allows you to automatically complete some commands through the CTRL-SPACE shortcut.

Ler o resto do artigo! »

Best practices
Thou shalt consider using SM34 clusters


If a development requires more than one customising table consider grouping their maintenance views under a cluster. This way it will be more intuitive to maintain them. This makes even more sense if one depends on the other since in the cluster definition these relations can be explicitly defined.

Example: Como encavalitar tabelas (portuguese)

Best practices
Thou shalt not SELECT *


Always try to select only the fields you’ll need. Selecting others is a waste of resources.
Exception made for the use of FM *_SINGLE_READ because, even though these do select all fields, since they cache the data, they are still faster when used multiple times for the same key.
If you just want to check if a record exists, select just one field, if possible the one you’re using as criteria to avoid declaring an extra variable. Example: SELECT KUNNR INTO V_KUNNR FROM KNA1 WHERE KUNNR = V_KUNNR.
http://abapinho.com/2010/11/select-todos-os-campos/ (portuguese)

Best practices
Thou shalt use a constants table


Whenever you feel a constant value can change and you can’t add it as a user parameter, store it in ZCONSTS. This table should never be used directly. Instead, a class like ZCL_CONSTS should be created to properly access it, like shown in this article:
http://abapinho.com/2009/06/constantes/ (portuguese only)

Resist the temptation of using T900 or similar tables for this purpose. It’s true that a lot of people do it. But it’s ugly, durty and besides these tables don’t even have an adequate key because they were not designed with this in mind.

Unlocking objects in a transport request


When you touch an object and add it to a transport request, it becomes locked there by default. In a transport request you can also lock objects which are not yet locked in another order. But, once locked, how to unlock them?

Ler o resto do artigo! »

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