SAP syntax for Class creation:
CREATE OBJECT
CREATE OBJECT oref
TYPE {class|(name)} [parameter list].
... PARAMETER-TABLE ptab
... EXCEPTION-TABLE etab
Effect
We 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 internal tables ptab and etab must be defined with reference to the tables ABAP_PARMBIND_TAB and ABAP_EXCPBIND_TAB.
Sample program where the class name is passed as variable and the exporting parameter is passed in Parameter-table.
Report: z_dyn_classname.
CLASS cl_abap_objectdescr DEFINITIONLOAD.DATA: container TYPErefto object,
pic_container TYPErefto CL_GUI_CONTAINER,
exc_ref TYPEREFTO cx_root,
lo_cast_error TYPEREFTO cx_sy_move_cast_error,
exc_text TYPE string.* Picture ControlDATA picture TYPEREFTO cl_gui_picture.
DATA: classTYPE string VALUE'CL_GUI_DIALOGBOX_CONTAINER',
ptab TYPE abap_parmbind_tab,
ptab_line TYPE abap_parmbind.
Callscreen100.
Module STATUS_0100 output.
ptab_line-name = 'WIDTH'.
ptab_line-kind = cl_abap_objectdescr=>exporting.GETREFERENCEOF1000INTO ptab_line-value.INSERT ptab_line INTOTABLE ptab.
ptab_line-name = 'PARENT'.
ptab_line-kind = cl_abap_objectdescr=>exporting.GETREFERENCEOF CL_GUI_CONTAINER=>DESKTOP
INTO ptab_line-value.INSERT ptab_line INTOTABLE ptab.
ptab_line-name = 'HEIGHT'.
ptab_line-kind = cl_abap_objectdescr=>exporting.GETREFERENCEOF300INTO ptab_line-value.INSERT ptab_line INTOTABLE 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.TRY.
* Now, the Widening cast to move the reference from the* generic object to dialogbox parent container class (more specific class).
pic_container ?= container.CATCH cx_sy_move_cast_error INTO lo_cast_error.
WRITE: / 'Widening cast failed'.
ENDTRY.
CREATE OBJECT picture
EXPORTING parent = pic_container.
* Request an URL from the data provider by exporting the pic_data.
DATA url(255).
CLEAR URL.
PERFORM load_pic_from_db CHANGING url.
* load picture
CALLMETHOD picture->load_picture_from_url
EXPORTING url = url.
CALLMETHOD cl_gui_cfw=>flush
EXCEPTIONS cntl_system_error = 1
cntl_error = 2.
IF sy-subrc <> 0.* error handling
ENDIF.endmodule. ”STATUS_0100 OUTPUT
FORM load_pic_from_db CHANGING url.
DATA query_table LIKE w3query OCCURS1WITHHEADERLINE.
DATA html_table LIKE w3html OCCURS1.
DATA return_code LIKE w3param-ret_code.
DATA content_type LIKE w3param-cont_type.
DATA content_length LIKE w3param-cont_len.
DATA pic_data LIKE w3mime OCCURS0.
DATA pic_size TYPEi.
REFRESH query_table.
query_table-name = '_OBJECT_ID'.
query_table-value = 'ENJOYSAP_LOGO'.
APPEND query_table.
CALLFUNCTION'WWW_GET_MIME_OBJECT'
TABLES
query_string = query_table
html = html_table
mime = pic_data
CHANGING
return_code = return_code
content_type = content_type
content_length = content_length
EXCEPTIONS
OBJECT_NOT_FOUND = 1
parameter_not_found = 2
OTHERS = 3.
IF sy-subrc = 0.
pic_size = content_length.
ENDIF.
CALLFUNCTION'DP_CREATE_URL'
EXPORTING
type = 'image'
subtype = cndp_sap_tab_unknown
size = pic_size
lifetime = cndp_lifetime_transaction
TABLES
data = pic_data
CHANGING
URL = url
EXCEPTIONS
OTHERS = 1.
ENDFORM. ”LOAD_PIC_FROM_DB
Expected output: