You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Jörg-Michael, please take a look at the example below. There is an inline DATA declaration that is filled using COND which is calling a method. The rule "Use FINAL for immutable variables" does not change this case to FINAL.
Thanks!
REPORT yexample.
CLASSlcl_example DEFINITION.
PUBLIC SECTION.
METHODSrun.
METHODS get_result
RETURNINGVALUE(rv_result) TYPE i.
ENDCLASS.
CLASSlcl_example IMPLEMENTATION.
METHODrun.
DATA(lv_test) =COND #( WHEN get_result( ) THEN1 ELSE2 ).
WRITE lv_test.
ENDMETHOD.
METHODget_result.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
NEW lcl_example( )->run( ).
The text was updated successfully, but these errors were encountered:
this is (or was) deliberate, because with older ABAP versions, you could get syntax errors for some cases:
" FINAL is only possible if the method call is at the last position:FINAL(ls_data_1) =VALUE test( name='Test'count=1id= get_any_integer( ) ).
" previously, using FINAL triggered the syntax error 'The field "LS_DATA_2-NAME" cannot be modified.'FINAL(ls_data_2) =VALUE test( id=1count= get_any_integer( )
name='Test' ).
" previously, using FINAL triggered the syntax error 'The field "LS_DATA_3-ID" cannot be modified.'FINAL(ls_data_3) =VALUE test( count= get_any_integer( )
id=1name='Test' ).
" previously, using FINAL triggered a syntax error:FINAL(lv_data_4) =COND i( WHEN lv_condition =abap_trueTHEN get_any_integer( ) ELSE get_any_integer( ) ).
This was why cases with method calls behind the inline declaration are currently skipped by the rule "Use FINAL for immutable variables".
Actually, checking again now, these syntax errors seem to be gone, but not sure whether that's true for all releases and update statuses out there. So, this might be a typical case of an option …
Hi Jörg-Michael, please take a look at the example below. There is an inline
DATA
declaration that is filled usingCOND
which is calling a method. The rule "Use FINAL for immutable variables" does not change this case toFINAL
.Thanks!
The text was updated successfully, but these errors were encountered: