ABAP Know How: 3 lines of code, 2 commented out
Sometimes, “little chunks of knowledge” can be as little as a few lines of code.
And most of them are commented out.
With this blog post, I’ll give you an example for it, explain why keeping them somewhere is useful for me, and invite you to let me know if you have similar cases.
My example is this:
* data lo_report TYPE REF TO lcl_report. * CREATE OBJECT lo_report. DATA(lo_report) = NEW lcl_report( ).
Defining a reference variable to a class,
and creating an instance of that class (that is: creating an object of that class),
and assigning that object to the reference variable
used to be to be 2 lines of code.
But it now can be done just as well in one line of code.
I try to use the new version, but I’m not always sure on first try.
Like, all those don’t work, and I remember failing with a least a few of them:
*FALSE exmaples: lo_report = new lcl_report( ) DATA(lo_report) = NEW lcl_report. DATA(lo_report) = NEW lcl_report(). DATA(lo_report) = NEW lcl_report( )
So I think it’s clear, that we benefit from having those “3lines of code, 2 commented out” examples.
But I don’t want them in my coding!
1. I don’t want useless comments. I’ll delete them!
2. How would I find such an example again? (I know I did that somewhere, but where?)
So, this all leads to my plan: I’ll use a SAP Community blog post for those things:
1. It’s the right place
2. I don’t need screenshots, my sources can be #textOnly!
3. it still looks nice, just like in the editor, as I can put it in a code block.
4. I can add new things by editing or as a comment.
5. Maybe most important: publicly shared knowledge is good knowledge: I have a convenient place to look thinks up again and others can also benefit.
What do you think about that?