ABAP News for 7.40, SP08 – Optional Interface Methods
This will be my shortest blog ever (but c’mon its only 10 points worth anyway).
You can make the implementation of interface methods optional now.
METHODS meth DEFAULT IGNORE|FAIL …
All you need to know is documented, what should I write more 😎 .
Horst,
with all of the new functions that are being added to the ABAP language, would it be possible to also introduce an IS INSTANCE OF operator? This could be very handy:
IF lr_object IS INSTANCE OF if_printable.
lr_printable ?= lr_object.
lr_printable->print( ).
ELSE.
lr_generic_printer->print( lr_object ).
ENDIF.
At the moment, we have to rely on RTTI (cumbersome to write) or TRY-CAST-CATCH-CRASH-implementations which are not really clean either.
Thanks
Volker
Hi Volker,
You asked that before and before 😕 .
In the moment, the shortest way to write it is:
DATA oref TYPE REF TO object.
oref = NEW some_class( ).
IF CAST cl_abap_classdescr(
cl_abap_typedescr=>describe_by_name( 'some_class' )
)->applies_to( oref ) = 'X'.
...
ENDIF.
I'd like to have an INSTANCE OF too. I'm not in a position to demand it but I'll ask for it again 😉 .
Best
Horst
Hi Horst,
Yes, I've asked that before and I will keep asking for it. 🙂
I don't particularly like the implicit variable declarations that some of the new constructs allow for - with the first example from ABAP News for 7.40, SP08 - Open SQLhttp://scn.sap.com/community/abap/blog/2014/10/08/abap-news-for-740-sp08--open-sql, it's hard to tell what type result actually is. Personally, I don't want to maintain stuff like that. I figured, if so much cool stuff that somehow violates some basic long-standing principles like explicit variable declaration is being added, why not keep pushing for "my" feature requests?
Cheers
Volker
My mail to manager and product owner is on its way ...
I'd like to have an INSTANCE OF too. I'm not in a position to demand it but I'll ask for it again
It would be great. Currently we also use a helper method for this.
If it is implemented in kernel, it would be even faster.
Peter