"
Supported by

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

SE16N’s technical view

ferramentas

Hi. How’ve you been? How’s life? All cool? This tip is so simple that if we don’t talk for a while it will all end too quickly. The sun is shinning. It rained in the morning but now it stopped.

Moving on.

Every time I see someone still using SE16 I wonder why, since SE16N is so much better and already exists for so long. But this is not the tip.

The tip is that in SE16N you can turn a technical view on which, besides the field’s technical name, gives you more useful information on the field.

Before:

se16n_vista_tecnica_desligada

You can find it under the “Extras” menu:

se16n_vista_tecnica

After:

se16n_vista_tecnica_ligada

Thank you Sérgio Fraga for the tip.

And thank you OZinOH for the photo.

Greetings from Abapinho.

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

ashtanga25

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.

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

Deleting packages that do not want to be deleted

pacote_leite

When you try to delete a package where you have created objects that have meanwhile been deleted, and the package looks empty in SE80, when you try to delete it, it won’t work because it says the package still contains objects.

For some silly reason, SE80 does not show every type of object associated with packages. In addition, when an object is deleted, its entry is often times not deleted correctly. SAP is full of shortcomings. But it’s what we have, and it’s what brings us the bacon, so let’s not say too many bad things about it.

Abapinho has the solution for you.

Ler o resto do artigo! »

Best practices
Thou shalt not implement in classical processing blocks

asthanga26

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).

0 is Private, 1 is Protected, 2 is Public

relampago

Simple tip to speed up entering data in (some) fields.
Ler o resto do artigo! »

Best practices
Thou shalt use ABAP OO whenever possible

ashtanga01

All new developments should be implemented using ABAP Objects unless still impossible (RFC, IN UPDATE TASK, screens, etc).
Existing developments, when rewritten, should also be converted to OO, if it proves to be realistic.
Official ABAP Programming Guidelines (page 32) rule 3.1: Use ABAP Objects whenever possible for new and further developments. Classical processing blocks may be newly created in exceptional cases only.

  • http://www.erpdb.info/wp-content/uploads/2008/09/why-abap-objects.pdf
  • http://scn.sap.com/people/thomas.jung/blog/2007/12/19/update-your-abap-development-skills-to-sap-netweaver-70
  • http://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Objects

Read the texts of a program

Fahrenheit_451

An easy way of programmatically accessing the texts of any program:

 
DATA: t_textos TYPE TABLE OF textpool. 
READ TEXTPOOL sy-repid INTO t_textos 
  LANGUAGE sy-langu STATE 'A’. 

Now, you have all of the texts available in the internal table T_TEXTOS.

As if this were not enough, you can also change the texts programmatically with the following commands:

 
INSERT TEXTPOOL sy-repid FROM t_textos LANGUAGE sy-langu. 
DELETE TEXTPOOL PROGRAM LANGUAGE 'E’. 

According to SAP, these last two commands are for internal use only. You can use them, but at your own risk. I’ll have nothing to do with it. Unless they force me otherwise, I’ll stick to “READ” only.

Thanks to Miguel Durão for the tip.

Greetings from Abapinho.

SELECT within SELECT

peixecomepeixe

Ler o resto do artigo! »

Get information on a remote system by RFC

pesca

Here’s a cool mini-function to obtain some details of a remote system accessible by RFC:

RFC_SYSTEM_INFO

I cannot give any example here because it would reveal very important secret information about my client which would certainly be used by the baddies to perform industrial espionage. But it is easy to test in SE37.

Thanks to kingofthebigmacs for the photo.

Greetings from Abapinho.

Request Based Debugging

coelhocartola

Ler o resto do artigo! »


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