"
Etiqueta > style
Supported by

Finally, expressions can be concatenated

Finally, the SAP NetWeaver 7.0 Enhancement Package 2 makes ABAP start to seem like a normal programming language.

It even allows expressions to be concatenated, no less!

Ler o resto do artigo! »

Decimal to alphanumeric without depending on the user

When reading a file with numeric values to an internal table or vice versa, the success of the conversion depends on whether the user has defined the dot or comma as the decimal separator. It is customary to then go and read the user setting and then adjust the values from the file with a dot or a comma as required.

But this is unfortunate and rather inelegant. There should be a way of not making this depend on the user.

And there is.

Ler o resto do artigo! »

Share constants among several classes

Imagine you have a herd of related classes sharing between them a whole bunch of constants. Saying the same thing a different way, would you like all the classes of the herd to have easy access to the bunch of constants?

(If you’re confused, then let me tell you that the “herd” thing was just to baffle you)

Carrying on…..

Ler o resto do artigo! »

Create RANGEs in DDIC without getting all wound up

I am using RANGEs more and more. I use them at breakfast, lunch, and dinner and outside meal times. It’s like soy sauce. A few spoonfuls and everything is instantly tastier.

Ler o resto do artigo! »

Benefits of LIKE LINE OF

Let’s start by assuming that you have some dignity and so you don’t use internal tables with HEADER LINE anymore ;)

Given this, let’s suppose you declare an internal table:

Ler o resto do artigo! »

INSERT and APPEND with ASSIGNING FIELD-SYMBOL

The harsh truth, at all costs, is that structures are out of date. Nowadays FIELD-SYMBOLS are in.

When you make a LOOP to an internal table of course that you also use ASSIGNING FIELD-SYMBOL instead of INTO Structure,correct?

But what was screwing everything over was APPEND and INSERT. I did not know how to use a structure to add records

Ler o resto do artigo! »

If you still don’t use ABAP Objects you’re chicken

SAP has a book called Official ABAP Programming Guidelines which describes rules and best practices on how to program in ABAP. In there you can read:

Page 42: Rule 3.1: Use ABAP Objects whenever possible for new and further developments. Classic processing blocks may be newly created in exceptional cases only.

Page 45: Within such a [classic] processing block, however, you should immediately delegate the execution to a suitable method (see Rule 6.37, No Implementation in Function Modules and Subroutines, and Rule 6.44, No Implementation in Dialog Modules and Event Blocks).

So, if you still use Classic ABAP you’re chicken :)

Thanks dawnhops for the photo.

Greetings from Abapinho.

More RANGEs, less SELECTs

The dictionary has the following entry for “style”: “set of formal aspects and expressive resources that characterise a text.”

It is preferable to read a text with style than one without. If ABAP were a language, a program in ABAP would be a text. When it comes to style, there are programs that seem to have been written by the feet, while there are others that one would swear the quill that wrote them was guided by the pure hand of an eighteenth century lady plagued by the troubles of love. Fortunately, I think it’s not possible to write programs in ABAP as tacky as the last sentence.

The “style” label is used here in Abapinho to identify articles that talk about just that: style. These articles try to find ways to improve the style of ABAP programs. This is one of Abapinho’s favourite labels, as you can see here. And what you are reading is another of those articles.

Moving on.

Ler o resto do artigo! »

Gregarious constants

If you are one of those who insert the values directly in code instead of using constants, then read no more and go and stand over there in the corner on punishment for 1 hour to learn not to be lazy. If you’ve come back from punishment or you usually use constants, then please continue reading.

Ler o resto do artigo! »

Search object attributes in an internal table

There are increasingly more objects in ABAP, gradually less fear of them and, lo and behold, more and more people are writing and using them. It is normal and desirable, if objects begin to appear everywhere, to start to stuff them into internal tables. I also stored a load of objects in tables a while back, unfortunately I did not know at that time what I am going to teach you here. It could have come in handy.

So, what exactly am I going to teach you here?

Ler o resto do artigo! »

What does a message say?

Do you want to obtain the text from a message when you only know the ID and the number, but you don’t know how? Find out here:


DATA text TYPE string.
MESSAGE ID '00' TYPE 'E' NUMBER '163' WITH '123' INTO text.

That’s all it is. Now inside the text variable, you find the following text:

“Client 123 does not exist in the system”

Thanks to Peteris B for the photo.

Greetings from Abapinho.

Automating the ALV field catalogue

Sometimes I ask myself what percentage of the world’s ABAP code is unnecessary. A paradigmatic example of how time can be wasted writing code which is of no use to anyone and only creates problems is the ALV’s all-too-common field description definition sitting directly in ABAP.

Ler o resto do artigo! »

Fair thee well DESCRIBE TABLE. And good riddance.

For twelve long years
When I wanted to count
The lines of an itab
I did what everyone does:
DESCRIBE TABLE itab LINES linhas.

Until the other day
When (my eyes didn’t deceive me)
I saw something so new,
You wouldn’t believe me:
LINES( itab ).

It gives the same outcome
And does away with declaring
The damn variable.

So instead of:


DATA: linhas TYPE i.
DESCRIBE TABLE itabl LINES linhas.
IF linhas = 42.
  WRITE 'A tua tabela é a verdade'.
ENDIF.

Just do this:


IF LINES( itbl ) = 42.
  WRITE 'A tua tabela é a verdade'.
ENDIF.

It is proof that
If SAP wanted to
It would make
An effort and ABAP
Would be a cool app.

But apparently it doesn’t care,
And ABAP is crap.

Rubbish poem. Sorry. It is all I could do.

Greetings from Abapinho.

The drag queen message

The AT SELECTION-SCREEN modules of a report can throw error messages and send you back to the selection screen. But once you get past the START-OF-SELECTION, if you get an error message, the program ends. The solution to getting an error and returning to the selection screen, is to disguise the message:

 
START-OF-SELECTION.
  IF condicao_desejada. 
    MESSAGE S208(00) with 'Erro!' DISPLAY LIKE 'E'. 
    EXIT. 
  ENDIF. 
  WRITE 'Olá, eu sou o resto do programa'. 

The type S message pretended to be type E. It seemed to be E – but it was joking.

If you try it out, you’ll see that the system returns an error but it does not exit the program completely; it goes back to the selection screen and does not run the rest of the program (because of the EXIT).

Thanks to Sérgio Lopes for this tip.

(And thanks to Tiago Celestino for the photo)

Greetings from Abapinho.

The round-about routes of VALUE CHECK

Have you ever come up against something in ABAP that seems to be one thing but is in fact another? The documentation says it is this and everything seems to indicate that it is, but after all it isn’t.

You’ve probably needed to, when setting a parameter in the report selection screen, check the possibilities of what the user can input to the available values in the data type of that parameter, right? VALUE CHECK exists for this.
It seems simple. For example, it was assumed that the following might work:


PARAMETERS: P_BUKRS LIKE T001-BUKRS OBLIGATORY VALUE CHECK.

When you check, it doesn’t work.

The T001-BUKRS field is the BUKRS type, which is of the BUKRS domain which in turn has the T001 table of values defined, for which BUKRS is the only primary key.
Even so this, lamentably, does not work. It does not work because, for some unfortunate reason, contrary to what would make sense and is understood from the documentation, CHECK VALUE does not take into account the domain of the field it validates. For this to work, the referred field needs to have an external key for the table of values.

In our case, therefore, although the table containing the list of possible values of BUKRS is T001, for VALUE CHECK to work we have to first refer to some other table that has T001 defined as the external key.
Such as T001K, for example:


PARAMETERS: P_BUKRS LIKE T001K-BUKRS OBLIGATORY VALUE CHECK.

Now it will work.

In summary: as you already know the table with possible values, instead of being able to use it you have to find another that defines it as the external key. This is complicating the simple with round-about routes. A rhetorician would call it circumlocution. I call it stupidity. I bet it’s a bug that SAP has proudly decided to ignore for ever.

Thank you Luís Rocha for the tip.

Greetings from Abapinho.


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