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

DDL Align JOINs and ASSOCIATIONs with new cardinality syntax

Open jrodriguez-rc opened this issue 1 year ago • 4 comments

With the new cardinality syntax, the align rule doesn't work properly Image

jrodriguez-rc avatar Dec 27 '24 08:12 jrodriguez-rc

Hi Jaime,

thanks a lot for reporting this bug! That's odd, I thought I had covered this syntax… but it seems that ABAP cleaner wrongly expects the source name already after the "to" keyword. Will look into it!

Here's some (copyable and obfuscated) code (mostly for myself to try it out and create tests :-)

define view entity I_AnyView
  as select from any_source
  
  association of one to exact one I_OtherView as _Other on $projection.OtherField = _Other.OtherField
  association to parent I_ParentView as _Parent on $projection.AnyField = _Parent.AnyField
  association of one to one I_ThirdView as _Third on $projection.OtherField = _Third.ThirdField
  association of exact one to exact one I_FourthView as _Fourth on $projection.FourthField = _Fourth.FourthField
  association of one to one I_FifthView as _Fifth on $projection.FifthField = _Fifth.FifthField
{
  key AnyField as AnyField
}

Kind regards, Jörg-Michael

jmgrassau avatar Jan 07 '25 08:01 jmgrassau

Hi Jaime,

actually, apart from fixing this bug, it's quite a nice idea to align those "to" keywords if the cardinality is textual, so I added this as an option to the "Align JOINs and ASSOCIATIONs" rule:

Image

With the next release, this will result in:

Image

By deactivating this option, you get:

Image

You can combine it with the "Align ASSOCIATIONs together with JOINs" option (which is deactivated by default), but that might be taking things too far:

Image

Kind regards, Jörg-Michael

jmgrassau avatar Jan 08 '25 08:01 jmgrassau

Hi Jörg-Michael,

Nice, thank you!

Just one very rare case, how it works with a combination of both syntax?

association [0..1] to I_Country      as _Country1 on $projection.Country = _Country1.Country
association of one to one I_Country as _Country2 on $projection.Country = _Country2.Country

jrodriguez-rc avatar Jan 08 '25 08:01 jrodriguez-rc

Hi Jaime,

as of now, if there is at least one association with textual cardinality, all the "to" keywords get aligned, even those with numeric cardinality:

Image

Kind regards, Jörg-Michael

jmgrassau avatar Jan 08 '25 09:01 jmgrassau

Hi Jaime,

sorry to keep you waiting for so long – this should now be part of version 1.21.2!

Kind regards, Jörg-Michael

jmgrassau avatar Jul 08 '25 05:07 jmgrassau

Hi Jörg-Michael

?ve been cheching and it seems that it isn't align correctly when there are spaces between the association text: Image

Perhaps it is not just aling the "TO" keyword, it's about aling all the keyword in the textual cardinality:

Source to Association
exact one to exact one
exact one to many
exact one to one
many to exact one
many to many
many to one
one to exact one
one to many
one to one

Final result could be something like this:

  association [0..1] 	   to           /RHP/R_ValueSet as _ValueSet on $projection.ValueSet = _ValueSet.UUID
  association of exact one to exact one /RHP/R_ValueSet as _ValueSet on $projection.ValueSet = _ValueSet.UUID
  association of exact one to many      /RHP/R_ValueSet as _ValueSet on $projection.ValueSet = _ValueSet.UUID
  association of exact one to one       /RHP/R_ValueSet as _ValueSet on $projection.ValueSet = _ValueSet.UUID
  association of many      to exact one /RHP/R_ValueSet as _ValueSet on $projection.ValueSet = _ValueSet.UUID
  association of many      to many      /RHP/R_ValueSet as _ValueSet on $projection.ValueSet = _ValueSet.UUID
  association of many      to one       /RHP/R_ValueSet as _ValueSet on $projection.ValueSet = _ValueSet.UUID
  association of one       to exact one /RHP/R_ValueSet as _ValueSet on $projection.ValueSet = _ValueSet.UUID
  association of one       to many      /RHP/R_ValueSet as _ValueSet on $projection.ValueSet = _ValueSet.UUID
  association of one       to one       /RHP/R_ValueSet as _ValueSet on $projection.ValueSet = _ValueSet.UUID

jrodriguez-rc avatar Jul 08 '25 09:07 jrodriguez-rc