I try to explore and embrace cleanABAP and you might know that I have started with the very easy “get rid of empty lines”.

There are other things I can do, in regards to make the code denser and thus cleaner, easier to understand, so I see more code with one glace and need less scrolling. -> Optimize for reading.

Here is an example:

I might start with this (some old code I find and want to clean)

        lref_srv_wt->to_create_move_hu(
          EXPORTING
            iv_commit_work = abap_true
            iv_wait        = abap_true
            it_create_hu   = lt_create_hu
          IMPORTING
            ev_tanum       = DATA(lv_tanum) 
            ).

1. Remove unneeded line breaks:

        lref_srv_wt->to_create_move_hu( EXPORTING iv_commit_work = abap_true
            iv_wait        = abap_true
            it_create_hu   = lt_create_hu
          IMPORTING ev_tanum       = DATA(lv_tanum) ).

2. Indent, to align it:

        lref_srv_wt->to_create_move_hu( EXPORTING iv_commit_work = abap_true
                                                  iv_wait        = abap_true
                                                  it_create_hu   = lt_create_hu
                                        IMPORTING ev_tanum       = DATA(lv_tanum) ).

 

( I actually had to look up https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#align-parameters for making sure I am done here, as I had the temptation to also remove unneeded whitespace, braking the alignment on = but making my code denser.

Like so:

	lref_srv_wt->to_create_move_hu( EXPORTING iv_commit_work = abap_true
                                              iv_wait = abap_true
                                              it_create_hu = lt_create_hu
                                    IMPORTING ev_tanum = DATA(lv_tanum) ).	

 

Further [but more complicated, as in: there are prerequisites to it] things I could do:

[If had control over the method to_create_move_hu:] – change the exporting parameter to a returning one, thus:
-> saving another line
-> being able to remove the then uneeded EXPORTING (https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#omit-the-optional-keyword-exporting)

lv_tanum = lref_srv_wt->to_create_move_hu( iv_commit_work = abap_true
                                           iv_wait        = abap_true
                                           it_create_hu   = lt_create_hu ). 
[ If I had control over the rules I agreed to when joining the project] I also could get rid of Hungarian notation / prefixes ( https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#avoid-encodings-esp-hungarian-notation-and-prefixes )

tanum = srv_wt->to_create_move_hu( commit_work = abap_true
                                   wait        = abap_true
                                   create_hu   = create_hu ). 

It does look a lot better, doesn’t it?

 

So what I did here, is give an example of how I do apply some rules of cleanAbap.

But my original thought was another one, and here I would appreciate some help: Steps 1 and 2 are not hard to do at all, they are really easy. They are so easy that I feel like I should not have to do them by hand: It should be one click/keystroke/quick-assist.
Is there a way AdT can help me do that? (Ref. my question: https://answers.sap.com/questions/13558374/adt-code-formater-to-help-towards-cleanabap-empty.html )

Sara Sampaio

Sara Sampaio

Author Since: March 10, 2022

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x