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

Enhancement of alignment of table rows in value expression

Open Koch013 opened this issue 2 years ago • 3 comments

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!

Koch013 avatar Oct 26 '23 07:10 Koch013

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

jmgrassau avatar Oct 28 '23 06:10 jmgrassau

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

StefanRutzmoser avatar Nov 15 '23 12:11 StefanRutzmoser

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' ) ).

ConjuringCoffee avatar Nov 15 '23 13:11 ConjuringCoffee