styleguides icon indicating copy to clipboard operation
styleguides copied to clipboard

FINAL new ABAP keyword - guidance

Open prokopp80 opened this issue 2 years ago • 6 comments

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

prokopp80 avatar Sep 21 '22 13:09 prokopp80

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

ruthiel avatar Oct 14 '22 21:10 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

image

https://blogs.sap.com/2022/07/04/reverse-loop-finally-possible-with-step-addition-for-abap-internal-tables/comment-page-1/#comment-630060

fabianlupa avatar Oct 15 '22 12:10 fabianlupa

Interesting, like const vs let in JavaScript.

I'd say then, that FINAL should be preferred to declare variables that are not reassigned.

jordao76 avatar Oct 15 '22 12:10 jordao76

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

image

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.

ruthiel avatar Oct 16 '22 20:10 ruthiel

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.

nomssi avatar Jan 08 '23 00:01 nomssi

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.

ConjuringCoffee avatar May 26 '23 12:05 ConjuringCoffee