Entering content frame

The LIKE Addition Locate the document in its SAP Library structure

You use the LIKE addition, similarly to the TYP E addition , in various ABAP statements for defining data types and specifying the types of interface parameters or field symbols. The addition

LIKE <obj>

can be used in the same ABAP statements as the TYPE addition to refer to any data object <obj> that is already visible at that point in the program. The expression <obj> is either the name of the data object or the expression

LINE OF <table-object>

In this case, the LIKE addition describes the line type of a table object that is visible at that point in the program.

You use LIKE to make the new object or type inherit the technical attributes of an existing data object.

ABAP Statements with LIKE References

TYPES <t> LIKE <obj>.

The new data type <t> inherits all of the technical attributes of the data object <obj>.

DATA <f> LIKE <obj>.

CLASS-DATA <f> LIKE <obj>.

CONSTANTS <f> LIKE <obj>.

STATICS <f> LIKE <obj>.

PARAMETERS <f> LIKE <obj>.

The data object <f> inherits all of the technical attributes of the data object <obj>.

CREATE DATA <dref> LIKE <obj>.

FORM <sub> ... USING|CHANGING <p> LIKE <obj> ...

The technical attributes of the formal parameter <p> are inherited from those of the declared data object <obj>. You can then only pass actual parameters that have these attributes.

METHODS <meth> ... IMPORTING|EXPORTING|CHANGING <p> LIKE <obj> ...

The technical attributes of the formal parameter <p> are inherited from those of the declared data type <type>. You can then only pass actual parameters that have these attributes.

FIELD-SYMBOLS <fs> LIKE <obj>.

The technical attributes of the field symbol <FS> are inherited from those of the declared data object <obj>. You can then only assign data objects that have these attributes.

Visibility of Data Objects

As a rule, you can use LIKE to refer to any object that has been declared using DATA or a similar statement, and is visible in the current context. The object only has to have been declared. It is irrelevant whether the data object already exists in memory when you make the LIKE reference.

DATA <ref> TYPE REF TO <cl_global>.

DATA: f1 LIKE <cl_global>=><attr>,
      f2 LIKE <ref>-><attr>.

You can access the technical properties of an instance attribute using the class name and a reference variable without first having to create an object. The properties of the attributes of a class are not instance-specific and belong to the static attributes of the class.

 

 

Leaving content frame