Category > Tips & tricks
Supported by
Supported by Inetum

CASE inside a SELECT (available soon)

images/thumbnail.jpg - Thumbnail

Get ready because you’ll soon be running into a lot of surprises. ABAP is learning new tricks. Look at this one: CONSTANTS: lc_menina TYPE STRING VALUE ‘GIRL', lc_menino TYPE STRING VALUE ‘BOY’, lc_senhor TYPE STRING VALUE ’GENTLEMAN’, lc_senhora TYPE STRING VALUE ‘LADY’. SELECT nome, CASE WHEN sexo_id = ‘M' AND idade < 18 THEN @lc_menino WHEN sexo_id = ‘F’ AND idade < 18 THEN @lc_menina WHEN sexo_id = ‘M' AND idade >=18 THEN @lc_senhor WHEN sexo_id = ‘F’ AND idade >=18 THEN @lc_senhora END AS titulo FROM zpessoa WHERE pessoa_id = @pessoa_id INTO CORRESPONDING FIELDS OF @lt_pessoas.

Search for notes directly in Google Chrome

images/thumbnail.jpg - Thumbnail

Google Chrome has an app for searching SAP notes. It’s called SAP Notes finder. You can install it here. Thank you Fernanda Mirabile and Talita Polanczyk for the tip. Greetings from Abapinho.

[:pt]CALL FUNCTION com DESTINATION ‘NONE' cria nova LUW[:]

images/thumbnail.jpg - Thumbnail

[:pt]Sabias que quando invocas uma função com a opção DESTINATION ‘NONE’ estás a iniciar uma nova LUW? Isto pode parecer apenas uma curiosidade, mas há um caso em que pode fazer toda a diferença: sabes aqueles módulos de função que ao serem chamados uma segunda vez têm um comportamento diferente da primeira vez? Isto acontece porque eles hão-de ter alterado alguma variável global ao grupo de funções. Ora se iniciares uma nova LUW quando chamares a função, o seu grupo de funções é automaticamente inicializado e assim garantes que o comportamento da função é o esperado.

[:pt]Debug de um job[:]

images/thumbnail.jpg - Thumbnail

[:pt]Para fazeres debug a um programa que faça parte de um job faz o seguinte:

How to ask if the line exists without seeming fashioned

images/thumbnail.jpg - Thumbnail

Long ago, you used the expression “groovy, man”. Later came “great, man”. Then there was “cool”. Today you say “awesome”. It’s important not to get confused and not make a fool of yourself.

And how do you ask an internal table if a line exists exists?

Stop the functions module's error messages

images/thumbnail.jpg - Thumbnail

There are standard functions that trigger messages where they shouldn’t. And they shouldn’t because we want to use these functions in non-interactive programs and then, instead of returning the error, an error message is triggered and ruins the whole process.

However, being aware of this problem, SAP has provided a quite elegant (but not well documented) way of solving this problem.

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.

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.

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,

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.

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.

Where is the boolean?

images/thumbnail.jpg - Thumbnail

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:

LOOP AT tbl ASSIGNING &lt;line&gt; CASTING

images/thumbnail.jpg - Thumbnail

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