SAP / abap-cleaner

ABAP cleaner applies 95+ cleanup rules to ABAP code at a single keystroke
Apache License 2.0
453 stars 48 forks source link

Enhancement of alignment of table rows in value expression #174

Open Koch013 opened 1 year ago

Koch013 commented 1 year ago

Hi,

thanks for this great tool!

Maybe the alignment of table rows in a value expression can be enhanced a bit.

If I use abap cleaner on this statement

lt_my_tab = value #( ( col1 = 'ABC' column2 = 'DEFG' c3 = 'HIJK' column_4 = 'LMN' )
( col1 = 'A' column2 = 'B'  column_4 = 'CD' )
( col1 = '123456' column2 = '789101112' c3 = '13141516171819' column_4 = '2021' )
( col1 = '12' c3 = '34' column_4 = '567890' )
  ).

the result looks like this:

lt_my_tab = VALUE #( ( col1 = 'ABC' column2 = 'DEFG' c3 = 'HIJK' column_4 = 'LMN' )
                     ( col1 = 'A' column2 = 'B'  column_4 = 'CD' )
                     ( col1 = '123456' column2 = '789101112' c3 = '13141516171819' column_4 = '2021' )
                     ( col1 = '12' c3 = '34' column_4 = '567890' ) ).

This is a little bit better than the original, but I expected more something like this:

lt_my_tab = VALUE #( ( col1 = 'ABC'    column2 = 'DEFG'      c3 = 'HIJK'           column_4 = 'LMN' )
                     ( col1 = 'A'      column2 = 'B'                               column_4 = 'CD' )
                     ( col1 = '123456' column2 = '789101112' c3 = '13141516171819' column_4 = '2021' )
                     ( col1 = '12'                           c3 = '34'             column_4 = '567890' ) ).

or maybe this:

lt_my_tab = VALUE #( ( col1 = 'ABC'    column2 = 'DEFG'      c3 = 'HIJK'           column_4 = 'LMN' )
                     ( col1 = 'A'      column2 = 'B'         c3 = ''               column_4 = 'CD' )
                     ( col1 = '123456' column2 = '789101112' c3 = '13141516171819' column_4 = '2021' )
                     ( col1 = '12'     column2 = ''          c3 = '34'             column_4 = '567890' ) ).

Is it possible to implement this?

Thanks!

jmgrassau commented 1 year ago

Hi Koch013,

thanks for opening this – yes, this is also on my own wish list!

Things might get tricky in cases like this one:

lt_my_tab = VALUE #( ( col1 = 'ABC' column2 = 'DEFG' column_4 = 'LMN' )
                     ( col1 = '123456' c3 = '13141516171819' column_4 = '2021' ) ).

because without retrieving the DDIC information of this structure, there is no way to determine whether column2 comes before c3 or vice versa. But I hope these would be rare cases.

Kind regards, Jörg-Michael

StefanRutzmoser commented 1 year ago

Hi Jörg-Michael, in such a case I'd suggest to take the first line as reference. And whenever a new field is introduced, place it according to the first line. To make it more precise, I'd place the new field (c3) just before the next already known field (column_4). If no further "already known" field exists, place it to the end.

lt_my_tab = VALUE #( ( col1 = 'ABC' column2 = 'DEFG' column_4 = 'LMN' )
                     ( col1 = '123456' c3 = '13141516171819' column_4 = '2021' )
                     ( col5 = '5' ) ).

would lead to

lt_my_tab = VALUE #( ( col1 = 'ABC'    column2 = 'DEFG'                        column_4 = 'LMN' )
                     ( col1 = '123456'                  c3 = '13141516171819'  column_4 = '2021' )
                     (                                                                           col5 = '5' ) ).

Regards, Stefan

ConjuringCoffee commented 1 year ago

It sounds like this approach will require automatic re-ordering of the fields to support all cases, for example to handle this:

lt_my_tab = VALUE #( ( col1 = 'ABC' column2 = 'DEFG' column_4 = 'LMN' )
                     ( col1 = '123456' c3 = '2' column_4 = '2021' )
                     ( col1 = '123456' column_4 = '2022' c3 = '1' ) ).