"
Supported by

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

ashtanga10

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

sokoban

To indent a block of lines do the following:

Ler o resto do artigo! »

Best practices
Thou shalt use LIKE LINE OF itbl

ashtanga11

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

pilha_cigarros

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

ashtanga16

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

productionline

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

ashtanga18

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 *

ashtanga05

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

ashtanga19

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

houdini

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! »

Best practices
Thou shalt build up and adopt toolkits with common tools

ashtanga23

Code which is used very often should be made available centrally, if possible under a single package (ex: ZTOOLS) so that it’s easily identified.

  • There is a lot of code already available on the Internet to accomplish several common functions (ex: ABAP2XLSX). Adopt it;
  • For your most common tasks, develop your own tools which you can reuse and add them to the central library;
  • Advertise the existence of that library among your colleagues to avoid that they waste time come up with duplicate code wasting;
  • Whenever you develop specific code which you think can one day be reused somewhere else consider making it more generic and add it to the central library.

Put it between parentheses

parentesis

Sweet little trick: when in SE38 you need to surround a word or expression with () or [] or ‘’, just select it and press ( or [ or ‘ and it immediately becomes (it) or [it] or ‘it’.

Thank you Sérgio Fraga for the tip.

Best practices
Thou shalt not REPLACE ‘.’ with ‘,’ just like that

ashtanga20

If you need to adapt the content of a file with amounts, always take into consideration the user settings (USR01-DSCFM).
If you need to convert a string to a number use FM MOVE_CHAR_TO_NUM.
If you need to convert a number to a string use WRITE curr TO str [CURRENCY waers].

Best practices
Thou shalt use command TABLES only when unavoidable

ashtanga21

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

ashtanga22

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

Esparguete150

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

ashtanga24

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.

Contemplating the package

snakes-ladders

You are looking at a class in SE24, a table in SE11 or a program in SE80. Now you want to see the package of this object and its content. Until recently, I would do this: first I would look in the object’s characteristics to see its package, then open a new session, go to SE80 and write the package there.

Now I’ve learned a much easier way.

Ler o resto do artigo! »

Best practices
Thou shalt avoid dynamic messages

ashtanga09

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.
http://abapinho.com/2009/09/evitar-mensagens-dinamicas/ (portuguese)

Find out who transported a request

iwantyou

The other day, a series of things crashed in our test machine. All of a sudden, no one could work on it. We found a series of transport requests improperly transported to STMS. The user who appears to be associated with each of these requests is its owner. But is it the owner’s fault? Didn’t someone else do the transport?

How can we find out?

Ler o resto do artigo! »


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