Thou shalt always use a predefined structure with ALV

images/thumbnail.jpg - Thumbnail

It is common to find an ALV data structure explicitly defined in the code. If this is done, the field catalog has to be manually constructed. If a predefined structure (from DDIC or declared as a TYPE) is used instead, the field catalog can be automatically built. This approach is always better and results in less code, even if the field catalog needs to be adjusted here and there. https://abapinho.com/en/2011/12/automatizar-catalogo-alv/

Thou shalt use TRANSPORTING NO FIELDS

images/thumbnail.jpg - Thumbnail

Many times we do READ TABLE itbl or LOOP AT itbl just to do a CHECK SY-SUBRC = 0. In these cases, the actual data read is not needed. For these cases always use TRANSPORTING NO FIELDS. This way is faster and avoids having to declare a target structure.

Debugging an infinite loop already in execution

images/thumbnail.jpg - Thumbnail

Imagine you have a program executing an infinite cycle or, at least, a cycle with 70x7 iterations. It is neverending, and you want to know what’s going on there.

In the past you had to go to SM50, select the process and choose from the menu “Administration | Program | Debug”.

But now there is a much easier way.

How many includes is a class made of?

images/thumbnail.jpg - Thumbnail

No matter how many times things go around in ABAP, everything ends up in SE38. Even the methods of the ABAP classes are saved in includes.

Sometimes, when there is a dump, it says the problem is, for example, here: CL_MESSAGE_HELPER=============CM001.

Unreleasing a released transport order

images/thumbnail.jpg - Thumbnail

You’ve released a transport order because you thought everything was ready. However, one more minor modification was still missing. So now you will have to create a new order and transport both of them. What a drag.

Don’t worry.

Presenting the EGSAP_TECH app

images/thumbnail.jpg - Thumbnail

Do you know about the EGSAP_TECH app? It’s a SAP knowledge bank.

Here is a description in the words of its own creators:

SELECT-OPTIONS default behavior

images/thumbnail.jpg - Thumbnail

Abapinho received a letter.

Mr. Abapinho,

Everybody knows how to set default values in select options using the DEFAULT keyword. What some people may not know is that one can also set the default option, sign and even if allows for intervals or just fixed values.

Chained exceptions

images/thumbnail.jpg - Thumbnail

Today I will teach you how to chain exceptions. It’s a very practical solution to a complicated, not so obvious problem. Let’s start by describing the problem. Imagine you are in the application BANANA. The application is quite complex. It has three modules: BANANA1, BANANA2 and BANANA3. Each one has its exception class ZCX_BANANA1, ZCX_BANANA2 and ZCX_BANANA3. Since the application is in fact well designed, all the exception classes inherit from the same ZCX_BANANA.

Ignore function module exceptions

images/thumbnail.jpg - Thumbnail

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

CALL FUNCTION 'GO_BUT_PLEASE_COME_BACK'
  EXPORTING
    ali = 'To the moon'
  EXCEPTIONS
    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,

Thou shalt use exception classes

images/thumbnail.jpg - Thumbnail

In classes, consider using exceptions classes over the old ones. These have great advantages and, once understood, are simple and allow for simpler code. https://zevolving.com/2011/12/class-based-exception/

Thou shalt use readily translatable explicit literals in programs

images/thumbnail.jpg - Thumbnail

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. https://abapinho.com/en/2011/11/programas-poliglotas/

Thou shalt use SALV instead of the old ALV functions

images/thumbnail.jpg - Thumbnail

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. https://scn.sap.com/docs/DOC-10365 https://scn.sap.com/docs/DOC-10366

Let's concatenate

images/thumbnail.jpg - Thumbnail

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.

Communication by event between programmes

images/thumbnail.jpg - Thumbnail

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.

Write in multiple lines at the same time

images/thumbnail.jpg - Thumbnail

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