"
Supported by

Modify one field in all lines of an internal table

metralhadora_lego

What I’m about to show you is not exactly new. It has even been used in Abapinho before. But since there is still a lot of people out there using LOOP to change a single field of an internal table, I thought it would be worth talking about it.

Say you have an internal table with one million and two hundred thousand entries and want to change the field ICON so that it has ‘@FM@‘ in all lines.

Instead of doing this:


LOOP AT lt_data ASSIGNING <data>.
  <data>-icon = '@FM@'.
ENDLOOP.

Try doing this instead:


ls_data-icon = '@FM@‘.
MODIFY lt_data FROM ls_data TRANSPORTING icon WHERE icon <> ‘DONALD DUCK’.

You can obviously replace the condition value with any other Disney character.

Thank you Sérgio Serra for suggesting that it could be interesting talking about this.
Thank you Andrew Becraft for the photo.

Greetings from Abapinho.

Bye bye READ TABLE

implosion

Pré 7.4:


DATA l_idade type i.
READ TABLE lt_folk
  INTO ls_folk WITH KEY name = l_name.
l_age = ls_folk-age.

Pós 7.4:


data(l_age) = lt_folk[ name = l_name ]-age )

Thanks Sérgio Fraga for the tip.

Greeetings from Abapinho.

So much new stuff in 7.4, I don’t know where to begin

space1999

Abapinho will slowly start posting tips specific to AS ABAP 7.4. Slowly because there are still only a few people with access to this version. But there are so many new things to tell that I feel tempted to start posting all of them.

ABAP was a flabby middle aged guy with a beer belly. It underwent major plastic surgery and now looks like a lean 20 year old kid who can party until 9am, drink 7 gin tonics and then, before going to bed, do 100 burpees just to sleep better.

Before 7.4:


SELECT z1~campo1 z1~campo2 z1~campo3 z1~campo4 z1~campo5
       z2~campo6
 FROM z1
 INNER JOIN z2
 ON z1~campo1 = z2~campo1
 INTO CORRESPONDING FIELDS OF TABLE lt_data
 WHERE z1~campo2 = 'MALAQUIAS'.

Since 7.4:


SELECT z1~*
       z2~campo6
 FROM z1
 INNER JOIN z2
 ON z1~campo1 = z2~campo1
 INTO CORRESPONDING FIELDS OF TABLE lt_data
 WHERE z1~campo2 = 'MALAQUIAS'.

Greetings from Abapinho.

Breakpoint in message from inside the debugger

ctt

You’re in the middle of a debug and want it to stop at a specific message.

What to do?

Ler o resto do artigo! »

Multiple OR selections in SE16N

orgate

If you are one of those persons who still uses SE16, this article is not for you. If you keep reading, you might find yet another reason to finally start using SE16N (as if all others were not enough already).

Imagine that you want to select all materials whose name contains “PREGO” and whose type is “FERRAGENS”, and all materials whose name contains “GUARDANAPO” and whose type is “COMIDA”. In other words, “PREGO_NO_PAO” or “GUARDANAPO_PAPEL” won’t be part of the result set. What you want is this:

(MATNR = “PREGO%” AND MTART = “FERR” ) OR (MATNR = “GUARDANAPO%” AND MAKT = “COMI” )

As you know, using SE16N in a regular way (which doesn’t use what I’m about to show you) you would need to execute it twice and manually compare data, because the selection screen does not allow you to make multiple OR selections.

Or does it?

Ler o resto do artigo! »

DELETE vs CLEAR vs REFRESH vs FREE

A worker at the Summer Palace takes a break from sweeping to make a phone call. Beijing, China.

DELETE
CLEAR
REFRESH
FREE

These are different ways of deleting all data from an internal table. They look the same. But they aren’t.

Ler o resto do artigo! »

CASE inside a SELECT (available soon)

fruit_salad

Get ready because you’ll soon be running into a lot of surprises. ABAP is learning new tricks. Look at this one:


CONSTANTS:
  lc_menina TYPE STRING VALUE ‘GIRL',
  lc_menino TYPE STRING VALUE ‘BOY’,
  lc_senhor TYPE STRING VALUE ’GENTLEMAN’,
  lc_senhora TYPE STRING VALUE ‘LADY’.

SELECT nome,  
 CASE
   WHEN sexo_id = ‘M' AND idade < 18 THEN @lc_menino
   WHEN sexo_id = ‘F’ AND idade < 18 THEN @lc_menina
   WHEN sexo_id = ‘M' AND idade >=18 THEN @lc_senhor
   WHEN sexo_id = ‘F’ AND idade >=18 THEN @lc_senhora
 END AS titulo
FROM zpessoa
WHERE pessoa_id = @pessoa_id
INTO CORRESPONDING FIELDS OF @lt_pessoas.

You just have to wait for version 7.40.

Thank you Sérgio Fraga for the tip.

Thank you Anil Wadghule for the photo.

Greetings from Abapinho.

Search for notes directly in Google Chrome

google-chrome

Google Chrome has an app for searching SAP notes. It’s called SAP Notes finder.

You can install it here.

Thank you Fernanda Mirabile and Talita Polanczyk for the tip.

Greetings from Abapinho.

Best practices
Consider converting WRITE reports into ALVs

ashtanga15

Reports still writing directly to the screen are very hard to maintain whenever changes to the layout are required. On such occasions, review the code and, if the effort involved is not too big, consider converting it to ALV. Always involve the functional people in this decision.

(Português) Curso online grátis de depuração

logo

Sorry, this entry is only available in Português. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

O Pedro Lima (responsável pelo OnSAP) fez um curso online grátis a ensinar os rudimentos da depuração em ABAP. Espreitem pois está bem feito e porque estas iniciativas merecem todo o nosso apoio. Tenho a certeza de que o Pedro fará mais cursos se vir que há público interessado.

Aqui

Nota: o curso é em inglês.

O Abapinho saúda-vos

No more english translations

uk_flag

Sadly, Abapinho will not be able to continue posting the English translation of the Portuguese posts. I am sorry to all the readers who don’t speak Portuguese.

Abapinho’s main goal has always been to publish ABAP content written in Portuguese. But the possibility of also publishing them in English was a great asset because it allowed us to reach a much wider audience. We were able to do it for several years because the translations were sponsored. Unfortunately, at least for now, this will no longer be possible. For this I ask your understanding.

Greetings from Abapinho.

(Português) CALL FUNCTION com DESTINATION ‘NONE’ cria nova LUW

elvis_boca

Sorry, this entry is only available in Português. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

Sabias que quando invocas uma função com a opção DESTINATION ‘NONE’ estás a iniciar uma nova LUW?

Isto pode parecer apenas uma curiosidade, mas há um caso em que pode fazer toda a diferença: sabes aqueles módulos de função que ao serem chamados uma segunda vez têm um comportamento diferente da primeira vez? Isto acontece porque eles hão-de ter alterado alguma variável global ao grupo de funções. Ora se iniciares uma nova LUW quando chamares a função, o seu grupo de funções é automaticamente inicializado e assim garantes que o comportamento da função é o esperado.

Há um exemplo disto na nota OSS 770626.

Obrigado Artur Moreira pela dica.

Quanto à foto, decidi que os dentes do Elvis são uma boa forma de representar LUWs.

O Abapinho saúda-vos.

(Português) Debug de um job

bug_em_ecra

Sorry, this entry is only available in Português. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

Para fazeres debug a um programa que faça parte de um job faz o seguinte:

Ler o resto do artigo! »

Converting an exception into an exception

estafetas

If you’re still not using exception classes, then you’re making a mistake. Cause they are very healthy for your code. They’re not only good nutrients for the system, they also make it lean and less vulnerable to diseases.

There are cases where you still need to deal with the old exceptions. For example, when a function module is invoked.

In this article I am presenting a suggestion that seems a little complex, but it works very well if you need to integrate the old exceptions with exception class in a simple way. And though it is sophisticated, you only need to do it once. Once it’s done, it’s easy to use.

Ler o resto do artigo! »

(Português) Novo livro “UI5 para desenvolvedores SAP/ABAP”

abap101

Sorry, this entry is only available in Português. For the sake of viewer convenience, the content is shown below in the alternative language. You may click the link to switch the active language.

O Flávio Pagoti, do blog ABAP101 publicou um livro em português sobre SAPUI5/OPENUI5.

Aqui está o artigo do ABAP101 a anunciar o livro. Lá encontras um link para o comprar. Custa $9,99.

A minha principal motivação quando decidi criar o Abapinho foi exactamente combater a gritante falta de conteúdos técnicos de qualidade escritos em português. Hoje as coisas estão um pouco melhores, em particular no mundo do ABAP onde há vários blogs de óptima qualidade. É fantástico que surjam publicações em português nesta área, ainda por cima de um assunto tão novo e inovador como este. Desejo-lhe muito sucesso.

Se prezas a tua carreira como ABAPer aconselho-te a começares a dar atenção a estas novas tecnologias e abordagens. Aqui tens uma oportunidade não só de o fazer como de apoiares a criação de conteúdos técnicos em português.

O Abapinho saúda-vos.

Teach ABAP to juggle

linhas_paralelas

What can be done when a night is not enough to complete the daily processes?

Ler o resto do artigo! »

Best practices
Thou shalt modularize, modularize, modularize

ashtanga02

Historically ABAP programs tend to grow very loooong. All programming best practices teach us there is not a single advantage in this approach.
If any routine, be it a program, a method, a function or anything else, becomes longer than 200-300 lines, question it and seriously consider refactoring it into several sub-routines.
This has the added advantage of potentially increasing code reuse. But the greatest advantage is encapsulation, isolating variables in their local context, instead of having all of them together, resulting in safer and more readable code.
The Official ABAP Programming Guidelines book advises this in its chapter 2.2 KISS (pages 32-34).
http://help.sap.com/abapdocu_731/en/abenencapsulation_guidl.htm

Best practices
Thou shalt reuse, thou shalt not rewrite

ashtanga03

If the same piece of code is repeated at least once, question yourself why and try to avoid it by creating a reusable routine.
If there is more than one SELECT for the same table in a program, make sure you can’t merge them into a single one. Sometimes a smart use of RANGEs to unify parameters can avoid the need for multiple SELECTs.
If the same code is used in 2 different programs, don’t repeat the code. Instead, create a class for it which can be shared by both and move the reused code to the common class.
http://abapinho.com/en/2012/06/mais-ranges-menos-selects/

Best practices
Thou shalt avoid global variables

ashtanga04

The more global variables a program has, the most obscure it becomes. Please avoid them. This is a basic rule of good programming and should always be followed. Even if several variables have to be passed by parameter, it takes slightly more effort but yields a much more readable and safer code.
Exceptions can be made for simple reports which run around a single internal table, which can be declared globally without compromising clarity.

How to ask if the line exists without seeming fashioned

carris

Long ago, you used the expression “groovy, man”. Later came “great, man”. Then there was “cool”. Today you say “awesome”. It’s important not to get confused and not make a fool of yourself. 

And how do you ask an internal table if a line exists exists?

Ler o resto do artigo! »


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