"
Etiqueta > style
Supported by

Best practices
Thou shalt use command TABLES only when unavoidable

Using SELECT-OPTIONS is one of the very few reasons for using TABLES. For all other cases, explicitly declare a local variable for the equivalent structure. TABLES basically creates obscure global variables which increase ambiguity in the code. And global variables should be avoided anyway.

Best practices
Thou shalt use FIELD-SYMBOLs instead of working areas

READ TABLE itbl ASSIGNING is always faster than READ TABLE itbl INTO wa.
Besides, when making changes to internal tables, not only it doesn’t require the explicit MODIFY but it also does away with the auxiliary TABIX variable.
The only situation in which a working area is better is when adding new lines to an internal table.
Some people contend that working areas should still be used when no changes are to be made to the data. This is still slower, but visually can be more intuitive.

Packages 2.0

SAP R/3 repository is a wonderful thing. A vast warehouse of data elements, structures, tables and much more, readily available to one and all. As developers, it is extremely convenient to quickly pick these elements and pull them into our programs as necessity conveys, while our string of thought remains virtually uninterrupted.
Well, not all is sunshine and roses. If you are not careful with the mushrooms you pick you might get a poisoned one.

Ler o resto do artigo! »

Best practices
Thou shalt group related parts together

Sometimes you find an IMPORT in the code but you have no idea where the corresponding EXPORT is. When communication is needed between programs, it should be done using a pair of methods belonging to the same class. This way, when we run into one, we’ll always know where the other one is.
Anyway, try to use EXPORT/IMPORT only when unavoidable. If possible, use static class variables instead.

Best practices
Thou shalt avoid dynamic messages

When you need to send a dynamic message by parameter, make sure you still use the MESSAGE command, so that the “where-used” doesn’t loose track of it. When you do MESSAGE E001 INTO V_DUMMY, the message details become available in the system variables: SY-MSGNO, SY-MSGTY, etc.
Also, message texts should never be hardcoded, they should always be defined in SE91.
https://abapinho.com/2009/09/evitar-mensagens-dinamicas/ (portuguese)

Best practices
Thou shalt not use direct code in user-exits

All code to be put in user-exits (BADIs, enhancements, SMOD, etc.) should be encapsulated.

  • It’s common for an user-exit to include multiple independent parts. Each of these parts should be encapsulated in its own method. Even if it is only one line;
  • This should apply to both new implementations and changes to existing code;
  • A change to existing code should always be seen as an opportunity to organize existing code into methods, since it will have to be tested again anyway;
  • If a class associated to the respective user-exit still doesn’t exist, one should be created;
  • The name of the class should be clearly related to the name of the user-exit. Ex: for user-exit ZXF01U01 uses class Z3F_CL_ZXF01U01.

https://abapinho.com/en/2012/03/metodos-privados-em-badis/
https://abapinho.com/2009/03/melhorar-os-melhoramentos/ (in portuguese)

Best practices
Thou shalt not implement in classical processing blocks

Official ABAP Programming Guidelines (page 34): [When a classical processing block is required], you should immediately delegate the execution to a suitable method (see Rule 6.37, No Implementations in Function Modules and Subroutines, and Rule 6.44, No Implementations in Dialog Modules and Event Blocks).

SELECT within SELECT

ABAP programmers don’t explore the possibilities of SQL, probably for historical reasons. There are many who instead of using INNER JOINs still think it’s faster to do several SELECTs for internal tables and then process the data in ABAP. But the truth is that even if there are exceptions, the rule is: the lower the number of accesses to the database, the better the performance. And it makes sense because, after all, they were written explicitly for this; relational databases are much more adept at processing relational data than an ABAP program.

There are of course things that, due to their complexity, cannot be done with a simple INNER JOIN. Nevertheless, some of these things can be done in a single SELECT.

Ler o resto do artigo! »

Abapinho’s best practices

Recently, I have compiled a set of personal best practices. I decided to share them here by creating a new category (which will soon appear on the menu to the left) into which they will be grouped. The original idea was to make a PDF file but, since they are constantly being reviewed and expanded, this was largely impractical. As such, they will be published one by one.

The goal is for these practices to be visible in their entirety as a user-friendly, accessible reference. I don’t know about you, but I, for one, will be using them.

Not all of them will be to everyone’s liking. And this is good. I say this selfishly, for I hope anyone who is dissatisfied will make themselves known and their ideas and opinions can help me improve them or rethink them.

Whether to your liking or not, I hope that one or two will at least be inspiring.

Stay tuned. They will soon begin to appear.

Greetings from Abapinho.

The ABAP detective

When a development is completed in SAP, the time to send it to other systems where it can be duly tested and then executed by users has finally arrived.
Before that occurs, however, it has to be checked for lapses, errors and other problems that could lead to our programmes behaving in an unpredictable manner.
There is a very useful tool that allows some of these errors and gaps to be filtered out. It is called ABAP Code Inspector.

Ler o resto do artigo! »

APPEND LINES OF class->method() TO itbl

ABAP is getting smarter all the time. Back in my day, no one did anything with it. And now, slowly, more than a fifth of a century late, it’s trying to imitate C and Java, and becoming more flexible.

I was going to do something like this:

Ler o resto do artigo! »

Always use message classes in exception classes.

Exception classes let you state multiple texts describing the different possible errors that they can represent.

However, there exists an option to associate it with a message class (SE91). This allows texts to be defined as classic SE91 messages instead of being defined directly in the exception class. And it has advantages.

Ler o resto do artigo! »

Don’t mix Z functions with maintenance views!

Today’s hint is not a hint – it’s an advice.

After creating a table, you create its maintenance views. The maintenance views dwell within a group of functions. This group of functions is requested from you at the time of their creation. Since, after all, that’s no more than a set of generated code, and most of it is, nonetheless, standard includes. Loads.

I give you the problem: there are those who create their own Z functions and put them in groups of functions with maintenance views. It’s true. Some do this.

Ler o resto do artigo! »

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.

Ler o resto do artigo! »

Writing money without any decimal worries

Some people read the TCURX to find out the number of decimal places of a CURRENCY when they need to write a money field to an alphanumeric variable.

Are you one of those people? Don’t be.

Ler o resto do artigo! »


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