Category > Tips & tricks

Pass internal tables by value is good

images/thumbnail.jpg - Thumbnail

When a method returns a value as a RETURNING parameter this is always done by value and not by reference. Several of my methods return internal tables, some of them quite large. It always worried me the idea that, since it’s being passed by value, ABAP would be returning a copy of the internal table, impacting both performance and the program’s used memory.

Fortunately, I recently learned that this is not​ a problem.

INSERT dbtab ACCEPTING DUPLICATE KEYS

images/thumbnail.jpg - Thumbnail

When you try to insert a record with a key which already exists in the table the program dumps. This, in some cases, is not desirable because, even if you don’t care, it forces you to check if the keys already exist before trying to insert then. But ABAP has a solution for these situations: INSERT dbtab FROM TABLE itab [ACCEPTING DUPLICATE KEYS]. Don’t worry because this will not violate the first law of thermodynamics: the duplicate records are not inserted.

Export and import the ABAP Workbench settings

images/thumbnail.jpg - Thumbnail

Sometimes a thing is right under your nose and your still don’t see it.

At my current client I daily work with a lot of different systems. When I make a change in a setting of one system, either because I’m lazy or because I forget, I end up not applying it to all the others.

But there is a simple way to copy all the ABAP Workbench settings at once from one system to the other.

Use the Split Screen Editor in the version comparison

images/thumbnail.jpg - Thumbnail

By default, the ABAP version comparison tool is horrible. It displays both versions in a single column and, even though the differences are highlighted, it’s awfully confusing. But it doesn’t have to be this way. Press the “settings” button at the top and you’ll find that there are 3 different display modes (besides some other nice options): one-column, two-columns and, surprise, the Split Screen Editor. This is probably the option you’ll want to choose since it’s the most powerful.

Spot the differences with SE39

images/thumbnail.jpg - Thumbnail

Earlier today I was doing a QC review to a new program named ZSDFAKSPE with almost 1000 lines and no comment whatsoever. An obvious clone of a standard program called SDFAKSPE.

So I decided to use the Spli-screen editor, found in transaction SE39. Having entered both programs I could then compare them side-by-side.

Source-code based class development

images/thumbnail.jpg - Thumbnail

Being used to develop in Java and C++, the way transaction SE24 forces you to navigate between each of its parts and the fact that every method has its own include was very confusing to me when I first started using it. Why does SAP always have to make things so complicated? I eventually got used to it. At some point in time SE24 introduced the option source-code based which shows the class and all its methods in a single text.

Jump to your last change

images/thumbnail.jpg - Thumbnail

Imagine that you’re editing one of those ancient programs with thousands of lines (yes because today you know that it’s wrong not to modularize (it’s a sin really) your methods (yes because today you always use methods) don’t have more than 200 lines).

I call you and you call me

images/thumbnail.jpg - Thumbnail

You you call a function via RFC you need to provide the RFC DESTINATION for the remote system:

CALL FUNCTION ZSNEEZED
  DESTINATION sistema_longe_daqui.

What if, for some reason, the function running in the remote system needs to call a function in the original system? How would you do it?

Undo in debugger layout

images/thumbnail.jpg - Thumbnail

Although a substantial part of an ABAP programmer time is spent debugging code, most programmers I know don’t invest much in getting to know the ABAP debugger. Maybe because they spent too many years working with its previous version which was truly archaic and worthless. But the new one can do much more than you usually ask of it. And Abapinho intends to teach you how.

Today I’ll teach you just a simple key.

Debugging with baby steps

images/thumbnail.jpg - Thumbnail

When you debug you use F5 key to move to the next statement (or go inside a sub-routine). But imagine an IF with multiple conditions:

IF A = 1 AND B = 2 AND C = 3.
  WRITE 'I like the word glauc'.
ENDIF.

When you debug through that IF using F5 and one of the expressions is false you’ll step out of the IF without knowing which of the three was false.

But the new debugger has a new very neat functionality which can help you to better understand what happened there.

SAP helps you translate to any language

images/thumbnail.jpg - Thumbnail

Every once in a while I find yet another hidden SAP virtue. I just found out that there is a transaction which, for a given word in a given language, will help you translate it to another language by showing you which other translations already exist for that same word. How cool is that? Ok, it’s not Google Translate, but it’s a nice help. Oh, I almost forgot. The transaction is called STERM.

Native SQL

images/thumbnail.jpg - Thumbnail

Sometimes ABAP SQL doesn’t allow you to do something you’d be able to do using the database’s native SQL. It can still be done.

Fix bug in SAP standard using an implicit enhancement

images/thumbnail.jpg - Thumbnail

You just found a bug in a standard FORM (or FM or METHDO): FORM EQUAL_VALUE CHANGING W_DATE TYPE SYDATUM. W_DATE = SY-DATUM - 1. ENDFORM. You report the error to SAP but you know it will take them several days, weeks or months to publish a correction. And you need it corrected right now. You decide to act. So you use the implicit enhancement at the start of the FORM to replace the standard code with your own (just until the correction arrives, of course):

Disable value history for a single field

images/thumbnail.jpg - Thumbnail

SapGUI usually keeps a history of the last values entered on each field. This is usually a good thing. But you may very well not want it to happen (in case you’re entering pornographic values in a specific field for example). You could always turn it off globally in the SapGUI settings.

But what if you just want to disable it in one particular field? Abapinho tells you how to do it.

Add parameters to standard methods and functions

images/thumbnail.jpg - Thumbnail

We are all aware of SAP implicit enhancements which allow you to add code to the top or bottom of any block of standard code (methods, functions, etc). We’ve all used it to make a change to a BAPI or other standard piece of code.

But only recently did I find that you can also use these implicit enhancements to add parameters to standard methods and functions.