styleguides
styleguides copied to clipboard
FINAL new ABAP keyword - guidance
Hi colleagues, recently the new FINAL keyword has been introduced. Do you plan to document a common guidance for it? In my opinion this was something that I missed in ABAP for long time.
Thank you, Br. Petr
Hello @prokopp80 ,
Can you explain what new keyword FINAL are you referring?
Is it the FINAL for classes and methods? If yes, it exists for a long time yet.
Regards, Ruthiel
This is referring to the new FINAL
keyword for immutable inline declarations. It is available in the BTP Trial with SAP_BASIS 789. The online documentation does not include it yet. Should show up as a third item here: https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninline_declarations.htm
https://blogs.sap.com/2022/07/04/reverse-loop-finally-possible-with-step-addition-for-abap-internal-tables/comment-page-1/#comment-630060
Interesting, like const
vs let
in JavaScript.
I'd say then, that FINAL
should be preferred to declare variables that are not reassigned.
This is referring to the new
FINAL
keyword for immutable inline declarations. It is available in the BTP Trial with SAP_BASIS 789. The online documentation does not include it yet. Should show up as a third item here: https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abeninline_declarations.htm
https://blogs.sap.com/2022/07/04/reverse-loop-finally-possible-with-step-addition-for-abap-internal-tables/comment-page-1/#comment-630060
Thank you @fabianlupa for this explanation. First time hearing about that.
It seems like a constant but inside a specific context.
FINAL in ABAP means the variable value can be changed only at the single write position. But it can be changed more than once, e.g. in a LOOP.
https://blogs.sap.com/2022/10/25/finally-a-declaration-of-immutable-variables-with-final-in-abap/
The recommendation should probably be: prefer FINAL to DATA whenever possible.
I have closed the pull request I made to fix this issue for now. As Björn explained in his comment, the FINAL
keyword has more subtleties to it than I expected and needs a better description.