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.
This constellation brings a syntax error after cleanup: (Rule: "Replace TRANSLATE with string functions"
TYPES: BEGIN OF mystructure,
string1 TYPE Char10,
string2 TYPE char10,
END OF mystructure.
DATA mytable TYPE TABLE OF mystructure.
LOOP AT mytable ASSIGNINGFIELD-SYMBOL(<mytableline>).
TRANSLATE<mytableline> toUPPER CASE.
ENDLOOP.
thanks for reporting this. Hm, that's indeed a problem, because ABAP cleaner can't determine the exact type of a variable if the definition is out of sight (and that's always the case if DDIC data elements are used as the type). So we'd either have to restrict this rule to cases where the technical type is completely visible (and even those certainly aren't trivial to determine), or deactivate the rule altogether, and add a kind of "use at your own risk" warning.
At least, since you get a syntax error right away, nothing bad can happen, since you can simply undo the cleanup in such cases. And as the rule has been around for over a year now (it was implemented in March 2023), there don't seem to be too many non-character-like cases out there…
Oh, tricky situation. Maybe a way could be to address this to someone at SAP directly. The to_upper( ) could be improved to be able to use structures as well, as long as they are charlike, that is how the old TRANSLATE` behaves anyway.
I think defaulting to an option that only works with types that can be fully determined, plus adding an option for "even for non-determinable types" with some kind of warning/explanation would be the right approach. I have this opinion because in my understanding you have been able to build all the other rules to "theoretically" run in the background.
thanks again for this example! I think an extra option is a good solution, so with the next release, you get:
This option will be activated by default (both for new installations and after the update), and if you deactivate it, a warning is shown:
I also enhanced the examples with some further explanation; with the option activated, none of the following will be changed:
" unlike TRANSLATE, the string functions do not work on structured data; therefore," changing the next statements might cause syntax errors. You can activate the option" 'Only replace TRANSLATE for known unstructured types' to restrict this cleanup rule" to cases in which ABAP cleaner can clearly determine the type (as above)DATA(ls_unknown_type) = get_charlike_structure( ).
DATA ls_ddic_type TYPE some_ddic_type.
DATA ls_other_type TYPE if_any_interface=>ty_s_typedef_out_of_sight.
TRANSLATE ls_unknown_type TOUPPER CASE.
TRANSLATE ls_ddic_type TOLOWER CASE.
TRANSLATE ls_other_type USING'a1b2'.
My 40 MB real-life sample code contains 47 instances of TRANSLATE (not too many, really), of which 20 instances are still changed with the option activated (because ABAP cleaner can see that the variable type is STRING, C, N, D, T, DATN, DATS, TIMN, TIMS, SSTRING, LANG, CLIKE, CSEQUENCE, CHARx, NUMCx, or one of the character-like SY-/SYST_ fields).
That's not perfect, but then, it would still be safe to deactivate the option, because the syntax check will immediately tell you if something goes wrong. However, definitely good to not have this as the default behavior.
And yes, there will be additional cases in which a human reader could easily determine from the context that the type isn't structured; but I wouldn't want to take this too far for just 1 instance per MB of code – given that we have so many other promising feature requests! :-)
Activity
jmgrassau commentedon Jun 12, 2024
Hi openPhiL,
thanks for reporting this. Hm, that's indeed a problem, because ABAP cleaner can't determine the exact type of a variable if the definition is out of sight (and that's always the case if DDIC data elements are used as the type). So we'd either have to restrict this rule to cases where the technical type is completely visible (and even those certainly aren't trivial to determine), or deactivate the rule altogether, and add a kind of "use at your own risk" warning.
At least, since you get a syntax error right away, nothing bad can happen, since you can simply undo the cleanup in such cases. And as the rule has been around for over a year now (it was implemented in March 2023), there don't seem to be too many non-character-like cases out there…
Kind regards,
Jörg-Michael
openPhiL commentedon Jun 13, 2024
Oh, tricky situation. Maybe a way could be to address this to someone at SAP directly. The to_upper( ) could be improved to be able to use structures as well, as long as they are charlike, that is how the old TRANSLATE` behaves anyway.
I think defaulting to an option that only works with types that can be fully determined, plus adding an option for "even for non-determinable types" with some kind of warning/explanation would be the right approach. I have this opinion because in my understanding you have been able to build all the other rules to "theoretically" run in the background.
jmgrassau commentedon Jul 6, 2024
Hi openPhiL,
thanks again for this example! I think an extra option is a good solution, so with the next release, you get:
This option will be activated by default (both for new installations and after the update), and if you deactivate it, a warning is shown:
I also enhanced the examples with some further explanation; with the option activated, none of the following will be changed:
My 40 MB real-life sample code contains 47 instances of TRANSLATE (not too many, really), of which 20 instances are still changed with the option activated (because ABAP cleaner can see that the variable type is STRING, C, N, D, T, DATN, DATS, TIMN, TIMS, SSTRING, LANG, CLIKE, CSEQUENCE, CHARx, NUMCx, or one of the character-like SY-/SYST_ fields).
That's not perfect, but then, it would still be safe to deactivate the option, because the syntax check will immediately tell you if something goes wrong. However, definitely good to not have this as the default behavior.
And yes, there will be additional cases in which a human reader could easily determine from the context that the type isn't structured; but I wouldn't want to take this too far for just 1 instance per MB of code – given that we have so many other promising feature requests! :-)
Kind regards,
Jörg-Michael
fix TranslateRule for unknown, potentially structured types (SAP#318)
fix TranslateRule for unknown, potentially structured types (#318)
jmgrassau commentedon Jul 8, 2024
Hi openPhiL,
thanks again for this issue! The new option is now available with version 1.18.0, which was just released!
Kind regards,
Jörg-Michael
ConjuringCoffee commentedon Jul 12, 2024
Great, now we can use the TRANSLATE rule safely again! 👍