Keep code blocks short
Unfortunately that is not what happens in most of the Z code I have seen in my life as an ABAP programmer. Both IFs and LOOPs tend to grow bigger than anyone can deal with. I recently ran into a LOOP with over 1500 lines.
ABAP inside SQL statements
Did you know that, if you SAP is recent enough, you can use complex ABAP expressions in the middle of SQL commands?
if you love your neighbour, avoid CLEAR
Please stop. Too many regressions happen because someone forgets to CLEAR or to not CLEAR a variable.
Don't be so negative
Legibility is very important in all written text. Except, maybe, in concrete poetry.
As a follow up to the previous post, here are a couple of rules to help you deal with the negative in boolean expressions.
IF conditions should be simple to read
Because…why should they be complex to read? It would only make it harder to maintain in the future.
Just because an IF condition is complex doesn’t mean it has to be complicated.
SELECT with CASE
ABAP SQL is becoming more and more interesting and powerful. My latest discovery is the ability to use CASE in SELECT.
I already miss you Sérgio!
My dear friend Sérgio Fraga passed away. Abapinho also belongs to him. Forever. Thank you my friend for everything you were.
The RANGEs double negatives
SELECT WHERE field IN (*, x)
Ok let’s go slowly on this one.
Picture a scenario in which you have a customizing table with several levels of detail which may or may not be defined:
-
BUKRS (empresa)
-
WERKS (plant)
-
LGORT (depósito)
When one of the fields is empty, we treat it as a wildcard, meaning all values are valid.
Insert without raising exception in internal table with unique key
How many times in your ABAP consultant life did you have to deal with dumps happening as a consequence of a program trying to insert duplicate lines into an internal table defined with a UNIQUE KEY?
Enough.
Manually populate a LISTBOX
In 2012 I wondered why LISTBOX is so rarely used. I taught how to use it with standard data elements, which automatically populate it. Today I’ll teach you how you can populate it yourself.
SELECTION-SCREEN FUNCTION KEY N
There’s so many things you can do on the selection screen. Here’s another one: five buttons in the toolbar.
Send emails to a distribution list
When you need to send an email to multiple email addresses, the usual approach is to store that list of email addresses in a custom table and then add each one as recipient to the BCS request.
But I recently learned a much nicer way to achieve the same result.