Skip to content

Don't access types through instance variables

When using a data type that is defined in a class or interface, access the type definition via the class/interface and not via an instance of the class/interface.

CLASS lcl DEFINITION.
  PUBLIC SECTION.
    TYPES foo TYPE i.
ENDCLASS.
CLASS lcl IMPLEMENTATION.
ENDCLASS.

INTERFACE lif.
  TYPES blah TYPE lcl=>foo.  
ENDINTERFACE.

Using the instance for the data type would be confusing, as it suggests that the type is instance specific.

" anti-pattern
CLASS lcl DEFINITION.
  PUBLIC SECTION.
    TYPES foo TYPE i.
ENDCLASS.
CLASS lcl IMPLEMENTATION.
ENDCLASS.

INTERFACE lif.
  DATA(ref) = new lcl( ).
  TYPES blah TYPE ref->foo.
ENDINTERFACE.
From SAP/styleguides under CC BY 3.0 — more details
Last updated on