Clean data declarations
While writing code, you should always keep present how easy it will be to maintain. This is particularly important in data declarations. And so easy to do right.
Dirty and hard to maintain
Look at this very typical data declaration:
DATA: customers TYPE STANDARD TABLE OF kna1, counter TYPE i.
Now imagine that you need to introduce a third variable called
grand_total of type
DATA: customers TYPE STANDARD TABLE OF kna1, counter TYPE i, grand_total TYPE f.
Because of how untidy this data declaration is, even though you only added a new variable, you were forced to change the two existing ones:
- Replacing the period with a comma in the
counterline because the command no longer ends there;
- Indenting the
TYPEof both existing lines so that they all remain aligned.
At first sight this is not a big deal. But when, sometime in the future, someone tries to compare both versions, the 3 line swill show up as having been modified, even though 2 of them were not really modified.
Oh so clean ABAP
In order to avoid this, you just have to take these two Clean ABAP rules into consideration:
This is less common in ABAP, but much cleaner:
DATA customers TYPE STANDARD TABLE OF kna1. DATA counter TYPE i.
This way, when you add a new variable, you no longer have to modify any of the existing lines:
DATA customers TYPE STANDARD TABLE OF kna1. DATA counter TYPE i. DATA grand_total TYPE f.
Much cleaner, right?
Also, keep in mind that, whenever possible, you should try to declare variables inline when you first need them instead of upfront, like Clean ABAP also suggests here.
Greetings from Abapinho.