abap-cleaner
abap-cleaner copied to clipboard
Change Variable names as per Naming convention( New Feature Suggestion )
Scenario : In our projects we copy some of the old code from one system to the other. We have different naming conventions in the destination system. Expectation: Can we add the Naming conventions feature where tool should be able to
- Load naming conventions file (excel file or in any configurable format )
- Change the naming of variables as per the file. For example, Work areas and Internal tables wa_struct --> ls_struct it_table --> lt_table v_var --> lv_var
Hi Dev4Develop,
that would indeed be great, but I'm afraid this is (mostly) out of scope for ABAP cleaner, because ABAP cleaner only works on the code document that it gets, without making additional backend calls. With that,
- identifiers that are used in other objects (child classes, test includes, other classes etc.) cannot be changed, because multiple objects would have to be touched for that – so attributes, parameter names, method names etc. can't be changed by ABAP cleaner;
- even local variables inside a method would be hard to change, because if
DATA any_name TYPE any_type.is defined, ABAP cleaner can't call DDIC to find out what exactlyany_typeis (e.g. whether it is a table type and the variable should get a table prefix).
Having said that, the examples you provided would actually work, because those all seem to be local examples (so ABAP cleaner would "see" the whole scope of those variables), and existing prefixes such as wa_ could be replaced with ls_ without ABAP cleaner even knowing the exact type. (Unless we're unfortunate and there is a base class that has an attribute or method which happens to be called lt_table…)
So, if there was a cleanup rule to rename local variables with certain patterns (e.g. rename wa_* to ls_*), would that help? And approx. how many patterns would we need? (Because I wonder whether entering those on the ABAP cleaner UI wouldn't be better than importing files, because we'd simply have more control to get correct input).
Kind regards, Jörg-Michael
Hi @jmgrassau
Thanks for the quick response.
1."......attributes, parameter names, method names etc. can't be changed by ABAP cleaner;" - Agree with you. Scope of this feature will be limited to data declarations ( DATA, TYPES ) in a code document.
2. Yes, this should help provided that we give all possible patterns. Additionally, for internal tables, we can automate as per desired naming. Check below samples.
Below are few samples and expected output.
DATA wa_header TYPE VBAK. --> ls_header
DATA counter TYPE i.---> lv_counter
I understand above two are not possible as Cleaner cannot check DDIC. But I think we can achieve below ones using Identifier TYPE TABLE OF.
DATA theader TYPE TABLE OF VBAK. ---> lt_theader
DATA it_item TYPE TABLE OF VBAP. ---> lt_item
TYPES : BEGIN OF item,---> ty_item
vbeln TYPE vbeln,
posnr TYPE posnr ,
END OF item.
Possible patterns Workarea : wa_* to ls_* w_* to ls_* Itab : t_* to lt_* it_* to lt_* variables: v_* to lv_*
"Renaming Local Declarations using Patterns" can be a useful feature and internal table can be addon. Do let me know your thoughts.
In my opinion this feature would make more sense in ATC with (mass) quick fixes where it can be fully featured instead of a compromise.
@jmgrassau I would like to contribute on this feature. Let me know how to work.
In my opinion this feature would make more sense in ATC with (mass) quick fixes where it can be fully featured instead of a compromise.
Any blogs how to implement this in ATC ?
ATC: its done, 5+ years ago, https://blogs.sap.com/2018/05/11/all-your-abap-prefixes-are-belong-to-us/
ATC: its done, 5+ years ago, https://blogs.sap.com/2018/05/11/all-your-abap-prefixes-are-belong-to-us/
I don't see the 'Quick fix' feature implemented in any of the blogs mentioned above.
The expectation is to automate renaming variables as per ATC suggestions. Let me know if I'm missing something.