This is a test message to test the length of the message box.
ABAP Obsolete Assignment, Calculation
Created by Software-Heroes

ABAP Obsolete - Assignment and calculation


How does it actually work with the assignments and the calculation in ABAP? Here you will find out the current language constructs and what you should avoid.

In our series of obsolete statements, we deal with the topic of assignment and calculation today and show you a few new constructs that are delivered with the current releases. The issue of obsolete statements is particularly important in the cloud, since some things work differently under steampunk.



An assignment in which the source and target types are different was previously carried out with a MOVE. With this, the system knew that it should convert to the target type as long as it's possible. But this command was no longer needed, a simple assignment is enough. Therefore, the statement is now completely obsolete and is no longer needed.

  ld_number  TYPE n LENGTH 10 VALUE 6513,
  ld_integer TYPE i.

" Old style
MOVE ld_number TO ld_integer.

" New style
ld_integer = ld_number.


The COMPUTE command produces a similar result and can be omitted in the same way. This command is used less often than MOVE.

" Old style
COMPUTE ld_number = ld_integer.

" New style
ld_integer = ld_number.


For assignments, as in other programming languages, you can therefore simply make the assignment. It will automatically try to convert from the source to the target types if possible. Else you will get a shortdump.



Even if the statements for the calculation are a bit dusty and actually still come from Cobol, they are still available in current ABAP coding. Furthermore, you can sometimes find them in older code. You should no longer use this form of calculation. Here you tend to use the generally accepted style of calculating with two variables.

" Old style
ADD 1 TO ld_number.
SUBTRACT 1 FROM ld_number.
MULTIPLY ld_number BY 2.
DIVIDE ld_number BY 4.

" New style
ld_number = ld_number + 1.
ld_number = ld_number - 1.
ld_number = ld_number * 2.
ld_number = ld_number / 4.


With the last major HANA release 1909 (last year), the typical constructs from other programming languages now work. This shortens typing, especially with longer variable names and provides more clarity. But be careful if you are working on backwards compatible code! Not that you run into problems with older versions there.

" New style Release > 7.54 or HANA 1909
ld_number += 1.
ld_number -= 1.
ld_number *= 2.
ld_number /= 4.



This means that ABAP is moving further and further away from its actual basis, Cobol, and is opening up more to general programming languages such as Java. For many younger developers, it is going in exactly the right direction and thus polishes up the dusty image somewhat.


SAP blog

Included topics:
Comments (0)

And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.

ABAP - Naming conventions

Category - ABAP

How important is it nowadays to adhere to naming conventions or even to use naming conventions in the modern ABAP environment? We want to look at that in this article.



Category - ABAP

APPEND already has a long history in ABAP, but this will play less and less of a role in the future. We'll show you why.


ABAP Obsolete - Ranges and Headers

Category - ABAP

Generate a decent range for an interface? Tables with or without header lines? We show you what is still possible and what you should rather be.



Category - ABAP

Again we have for you a most used ABAP term for which there is already a new alternative, this time not just one alternative.



Category - ABAP

Type pools are obsolete, but the use continues. How best to deal with it in the future, you will find out here today.