abap-cleaner icon indicating copy to clipboard operation
abap-cleaner copied to clipboard

LT_* sorted before LS_*

Open VladGhitulescu opened this issue 1 year ago • 3 comments

Hey,

I've just discovered that in the DATA-declarations the table elements (LT_) are sorted before structures (LS_) by abap-cleaner.

Before:

CleanShot 2024-01-16 at 13 53 52

After:

CleanShot 2024-01-16 at 13 54 14

  1. Why?
  2. Is there a way to change this?

Thanks!

Regards, Vlad

VladGhitulescu avatar Jan 16 '24 12:01 VladGhitulescu

I guess it could makes sense for LIKE LINE OF?

fabianlupa avatar Jan 16 '24 17:01 fabianlupa

Hi Vlad,

this is because "Rearrange local declarations" (with the option "Rearrange DATA: … order by first usage") determines the first usage of each variable in the code and then rearranges the DATA declarations in that order. So, from your example I would expect that the variable lt_addrnr_objnr is used at an earlier point in the following code than the variable ls_addrnr_objnr.

This is indeed different with LIKE, because then, the first usage is already within the DATA section. For example, in this code,

    DATA ls_any_struc TYPE ty_s_struc.
    DATA lt_any_table LIKE STANDARD TABLE OF ls_any_struc.

    lt_any_table = VALUE #( ).
    ls_any_struc = VALUE #( ).

the order will (and must) be kept, because ls_any_struc is already used in the DATA section (and therefore it is used before lt_any_table).

Kind regards, Jörg-Michael

jmgrassau avatar Jan 17 '24 07:01 jmgrassau

Hey @jmgrassau & @fabianlupa

you're both right, that makes sense now - my expectations had only personal preference.

VladGhitulescu avatar Jan 17 '24 09:01 VladGhitulescu