CREATE OBJECT - parameter_list

Syntax

... { [EXPORTING  p1 = a1 p2 = a2 ...]
      [EXCEPTIONS exc1 = n1 exc2 = n2 ...] }
  | { [PARAMETER-TABLE ptab]
      [EXCEPTION-TABLE etab] }.

Extras:

1. ... EXPORTING  p1 = a1 p2 = a2 ...

2. ... EXCEPTIONS exc1 = n1 exc2 = n2 ...

3. ... PARAMETER-TABLE ptab

4. ... EXCEPTION-TABLE etab

Effect

The additions EXPORTING and EXCEPTIONS are used to statically pass actual parameters to the instance constructor or to assign return values to the not class-based exceptions. For doing this dynamically, the additions PARAMETER-TABLE and EXCEPTION-TABLE are used.

Addition 1

... EXPORTING  p1 = a1 p2 = a2 ...

Addition 2

... EXCEPTIONS exc1 = n1 exc2 = n2 ...

Effect

When using the addition EXPORTING, you must specify the non-optional input parameter and you can specify the optional input parameters p1 p2 ... of the instance constructor of the instanced class using the actual parameters a1 a2 ...

If a subclass does not have an explicitly implemented instance constructor, the interface of the instance constructor from the next-highest superclass that explicitly implements the instance constructor is used.

You can use the addition EXCEPTIONS to assign return values to not class-based exceptions exc1 exc2... The syntax and meaning of the additions are the same as in the parameter list for the CALL METHOD statement.

If you dynamically specify a class in name, you can only use the additions EXPORTING or EXCEPTIONS as of release 6.10. Prior to release 6.10, you can only specify classes whose instance constructor does not expect any input parameters.

Example

Generation of a dialog box of the GUI control framework (CFW) and transfer of the input parameters to the instance constructor of the global class CL_GUI_DIALOGBOX_CONTAINER. The class is defined implicitly using the static type of the reference variable dialog_box.

DATA dialog_box TYPE REF TO cl_gui_dialogbox_container.

CREATE OBJECT dialog_box
       EXPORTING parent = cl_gui_container=>desktop
                 width  = 1000
                 height = 350.

Addition 3

... PARAMETER-TABLE ptab

Addition 4

... EXCEPTION-TABLE etab

Effect

You can use these additions when the instanced class is specified dynamically in name. You use the special internal tables ptab and etab to assign actual parameters to the input parameters of the instance constructor or return values to not class-based exceptions .

The syntax and meaning of the additions are the same as in the dynamic form of the CALL METHOD statement. The internal tables ptab and etab must be defined with reference to the tables ABAP_PARMBIND_TAB and ABAP_EXCPBIND_TAB from the ABAP type group.

Example

Dynamic generation of a dialog box in the GUI control framework (CFW) and dynamic transfer of the input parameters to the instance constructor of the global class CL_GUI_DIALOGBOX_CONTAINER. The class is explicitly defined using the addition TYPE.

TYPE-POOLS abap.

CLASS cl_abap_objectdescr DEFINITION LOAD.

DATA: container TYPE REF TO cl_gui_container,
      exc_ref TYPE REF TO cx_root,
      exc_text TYPE string.

DATA: class TYPE string VALUE `CL_GUI_DIALOGBOX_CONTAINER`,
      ptab TYPE abap_parmbind_tab,
      ptab_line TYPE abap_parmbind.

ptab_line-name = 'PARENT'.
ptab_line-kind = cl_abap_objectdescr=>exporting.
GET REFERENCE OF CL_GUI_CONTAINER=>DESKTOP
              INTO ptab_line-value.
INSERT ptab_line INTO TABLE ptab.

ptab_line-name = 'WIDTH'.
ptab_line-kind = cl_abap_objectdescr=>exporting.
GET REFERENCE OF 1000 INTO ptab_line-value.
INSERT ptab_line INTO TABLE ptab.

ptab_line-name = 'HEIGHT'.
ptab_line-kind = cl_abap_objectdescr=>exporting.
GET REFERENCE OF 300 INTO ptab_line-value.
INSERT ptab_line INTO TABLE ptab.

TRY.
    CREATE OBJECT container TYPE (class)
                  PARAMETER-TABLE ptab.
  CATCH cx_sy_create_object_error INTO exc_ref.
    exc_text = exc_ref->get_text( ).
    MESSAGE exc_text TYPE 'I'.
ENDTRY.