Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: No line between DATA declaration of a table and initialization #303

Closed
vonglan opened this issue May 15, 2024 · 4 comments

Comments

@vonglan
Copy link

vonglan commented May 15, 2024

Hi,
to loop over a list of "options", I want to create a "quasi-constant" table containing these constants.
I think there is no way in ABAP other than to do it like this:

  METHOD get_confirmed_quantity.
    DATA conf_cats TYPE STANDARD TABLE OF zb_c_purgdocsupplierconfirmati-SupplierConfirmationCategory WITH EMPTY KEY.

    conf_cats = VALUE #( ( 'AB' ) ( 'LA' ) ). " sometime there is just Lieferavis without Order Confirmation

    LOOP AT conf_cats INTO DATA(conf_cat).

However, ABAPCleaner then separates the DATA and its initialization, which I would prefer it not to do in this special case.
(I know, this is a very small detail, still I wanted to share this.)
Best regards,
Edo

@jmgrassau
Copy link
Member

Hi Edo,

currently, I'd rather label this "no defect", because the idea behind this empty line – to separate upfront declarations from executable statements – is still valid here, isn't it?

If you prefer an inline declaration, you could alternatively define a table type first (maybe even on class or global level is this table type could be useful in different places?) and then use it as the type of the VALUE constructor:

  METHOD get_confirmed_quantity.
    TYPES ty_tt_sup_conf_cat TYPE STANDARD TABLE OF zb_c_purgdocsupplierconfirmati-SupplierConfirmationCategory WITH EMPTY KEY.

    DATA(conf_cats) = VALUE ty_tt_sup_conf_cat( ( 'AB' ) ( 'LA' ) ). 

    LOOP AT conf_cats INTO DATA(conf_cat).

Kind regards,
Jörg-Michael

@vonglan
Copy link
Author

vonglan commented Jun 3, 2024

Hi Jörg-Michael,

maybe we misunderstood each other?
I want to use the variable as a constant (semantically). Technically however, ABAP does not offer a syntax for this (only for simple variables, not for tables).

Because it is semantically a "declaration of a constant" I do not like to have the separation line in the middle of it.
The question is whether ABAPCleaner can detect such a "pseudo-constant" (a table which is immediately initialized) and suppress the line separation at this position.

Again, I am aware it is a very tiny detail (not a defect at all), but I wanted to let you know that this use case exists.

Best regards,
Edo

@jmgrassau
Copy link
Member

Hi Edo,

ah, yes, now I understand your point! But then a number of questions come to mind:

  • What if the VALUE statement used an importing variable in some place – VALUE ty_tt_any( ( 'A' ) ( 'B' ) ( iv_any ) ( iv_other ) ) – then it wouldn't be a "pseudo-constant" anymore, right?
  • What if the VALUE statement used a constant, possibly in the form of cl_any_inferface=>co_any_constant? – I guess you could still consider it a "pseudo-constant", but ABAP cleaner couldn't determine whether the identifier really represents a constant.
  • What if multiple tables of this kind were initialized, would it be better to have the four lines as "declaration 1 – initialization 1 – declaration 2 – initialization 2", or rather "declaration 1 – declaration 2 – initialization 1 – initialization 2"?

So, my feeling is that this is really rather a limitation of the ABAP language… just as you said, there is no technical equivalent for this (very valid) semantic scenario, and I assume that the initialization is indeed performed at runtime each time the method is called (not at compile time into a static storage).

Kind regards,
Jörg-Michael

@vonglan
Copy link
Author

vonglan commented Jun 10, 2024

Hi Jörg-Michael,
I think you are right. This cannot be easily overcome by ABAP Cleaner.
Best regards,
Edo

@vonglan vonglan closed this as completed Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants