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

Feature request: Use newer expressions

Open jelliottp opened this issue 1 year ago • 13 comments

There are a number of newer expressions that seem like a good fit for a rule to replace the old syntax, such as:

  • [ ] 1. CORRESPONDING #( ) - refer to #266
  • [ ] 2. String templates - partially complete in 1.15.0 refer to #116
  • [x] 3. line_exists( ) 1.14.0
  • [x] 4. lines( ) 1.14.0
  • [x] 5. condense() 1.15.0
  • [x] 6. translate( ) 1.0.0
  • [ ] 7. concat_lines_of( )
  • [ ] 8. shift_left( ) & shift_right( )
  • [x] 9. to_upper( ) & to_lower( ) 1.0.0
  • [x] 10. line_index( ) 1.14.0
  • [ ] 11. REF #( )

jelliottp avatar May 26 '23 16:05 jelliottp

Hi Josh,

great, that sounds very promising for multiple new cleanup rules! We'd have to check about limitations for automation in the individual cases, of course, but looking forward to this!

Kind regards, Jörg-Michael

jmgrassau avatar May 30 '23 13:05 jmgrassau

Hi Josh,

just to keep you updated, I now implemented an important prerequisite to some of these ideas, namely

  • some helper functions to determine which ABAP commands change relevant system fields (sy-subrc, sy-tabix, sy-index, sy-tfill, sy-tleng), and
  • a "ProgramFlowAnalyzer" (extended by "SyFieldAnalyzer") to find out which subsequent commands read them, before another command changes them again.

This is needed, obviously, because these newer expressions don't change the system fields, and we must excluded unexpected cases from cleanup (e.g. when the system field is first stored in a variable and evaluated at a different point).

To be continued!

Kind regards, Jörg-Michael

P.S.: Points 6 and 7 are already implemented with the "Replace TRANSLATE with string functions" rule, but line_index( ) could be added to the list.

jmgrassau avatar Jul 10 '23 07:07 jmgrassau

Hi Josh,

FYI, for point 10 "String templates", a dedicated issue #116 was opened, so discussion for this particular point could be continued there.

Kind regards, Jörg-Michael

jmgrassau avatar Sep 30 '23 09:09 jmgrassau

Hi @jmgrassau, just circling back to this one. The tool has become very stable and useful! Do you think any of these would make it as a priority soon?

jelliottp avatar Feb 14 '24 15:02 jelliottp

Hi Josh,

thanks for the reminder, and really sorry that (due to limited capacity) there was no progress here for such a long time!

Hm, if you could choose, which of those 10 open ideas would you find most useful to start with?

Kind regards, Jörg-Michael

jmgrassau avatar Feb 20 '24 07:02 jmgrassau

I think CORRESPONDING #( ) is probably the most common one I see right now so I’d start there. I believe it would need to include the BASE addition to be a safe conversion from MOVE-CORRESPONDING. String templates in #116 is also important.

I’ll also try to re-order the rest based on priority, and others can give their input here as well.

jelliottp avatar Feb 20 '24 15:02 jelliottp

Hi Josh,

okay, starting small with an upcoming cleanup rule that changes DESCRIBE TABLE itab LINES lin into lin = lines( itab ):

image

However, the examples show that this is not entirely trivial:

image

Kind regards, Jörg-Michael

jmgrassau avatar Mar 07 '24 14:03 jmgrassau

Great! Looks good, and you are right there are some outliers to be aware of.

jelliottp avatar Mar 07 '24 17:03 jelliottp

Hi Josh,

release 1.14.0 will also offer the new rule "Replace READ TABLE with table expression" (for 3. line_exists( ) and 10. line_index( ), and additionally for ASSIGN):

image

Examples:

image

However, unfortunately, the rule can't automate everything, which is also explained in the examples:

image

Kind regards, Jörg-Michael

P.S.: Is 6. translate( ) fulfilled with the rule "Replace TRANSLATE with string functions" or is anything missing there?

jmgrassau avatar Mar 11 '24 12:03 jmgrassau

These are great additions, thank you!

Also, yes translate() is already covered so I've checked that one off as well.

jelliottp avatar Mar 11 '24 12:03 jelliottp

Hi Josh,

perfect, thanks once again for this inspiring list! (And nicely done with the ticks, references and version numbers!) Already doing some research on some of the other points …

Kind regards, Jörg-Michael

jmgrassau avatar Mar 11 '24 13:03 jmgrassau

There's a dedicated issue for CORRESPONDING now: https://github.com/SAP/abap-cleaner/issues/266

ConjuringCoffee avatar Mar 11 '24 14:03 ConjuringCoffee

Hi Josh,

version 1.15.0, which was just released, now includes the new cleanup rules "Use string templates to assemble text" (for 2.) and "Replace CONDENSE with string function" (for 5.)!

Kind regards, Jörg-Michael

jmgrassau avatar Mar 25 '24 11:03 jmgrassau