Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Creating Objects and Values →  CREATE OBJECT 

CREATE OBJECT - TYPE

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


CREATE OBJECT oref [area_handle] 
                   TYPE { class  [parameter_list] }
                      | { (name) [parameter_list|parameter_tables] }.

Effect

For class, any concrete class that is more specific than or identical to the static type of the object reference variable oref can be specified. oref can be a class reference variable or an interface reference variable. An instance of the specified class class is created.

As an alternative to being specified directly, name can be used to specify a character-like data object that contains the class name in uppercase letters when the statement is executed. The class name in name can also be an absolute type name.


Notes

Security Note

If used wrongly, creating objects dynamically can present a serious security risk. Names of classes that are passed to a program from the outside must be checked thoroughly before being used in dynamic statements. The system class CL_ABAP_DYN_PRG, for example, can be used to do this. See Dynamic Calls.


Example

Creates an instance of a class c1 using an explicit reference to the class. The static type of the reference variable is the root class object and is therefore more general than any other class.

CLASS c1 DEFINITION. 
  ... 
ENDCLASS. 

... 

DATA oref TYPE REF TO object. 

... 

CREATE OBJECT oref TYPE c1.