SAP ABAP动态创建类 object

DATA: lo_node TYPE REF TO object. "”object – 对象类型

" 方法1
cl_crm_order_timer=>start( ).
DO 1000 TIMES.
CREATE OBJECT lo_node TYPE (‘CL_PRD01OV_MATERIALOV_CN00’).
ASSIGN lo_node->(‘BASE_ENTITY_NAME’) TO FIELD-SYMBOL().
ENDDO.
cl_crm_order_timer=>stop( ‘Field Symbol’ ).
WRITE:/ .

" 方法2
cl_crm_order_timer=>start( ).
SELECT SINGLE attvalue INTO @DATA(lv) FROM vseoattrib WHERE clsname = ‘CL_PRD01OV_MATERIALOV_CN00’
AND cmpname = ‘BASE_ENTITY_NAME’.
REPLACE ALL OCCURRENCES OF ‘’‘’ IN lv WITH space.
cl_crm_order_timer=>stop( ‘DB’ ).

WRITE:/ lv.

  data: LV_COMP                type ref to IF_GENIL_APPL_MODEL,
        LS_COMPONENT_ENTRY     type GENIL_COMP_MODEL_ENTRY,
        LO_MANAGER             type ref to CL_GENIL_ENHANCEMENT_MANAGER.

        create object LV_COMP
          type
          (-IMPL_CLASS)
          exporting
            IV_MODE           = CL_CRM_GENIL_ABSTR_COMPONENT=>DESIGNTIME_MODE
            IV_COMPONENT_NAME = LS_COMPONENT_ENTRY-COMPONENT.
      catch CX_SY_DYN_CALL_PARAM_NOT_FOUND.
  •       optional paramter IV_COMPONENT_NAME not supported by component
          create object LV_COMP
            type
            (-IMPL_CLASS)
            exporting
              IV_MODE = CL_CRM_GENIL_ABSTR_COMPONENT=>DESIGNTIME_MODE.
    

实例 :
DATA : lr_data TYPE REF TO object .
DATA : lv_comp TYPE REF TO object .
DATA : lr_data2 TYPE REF TO data .
TRY.
CREATE OBJECT lv_comp
TYPE
(‘ZCL_COMMON_REPORT’)
EXPORTING
iv_mode = ‘D’
iv_component_name = ‘ZMO_SS’.
CATCH cx_sy_dyn_call_param_not_found.

  •       optional paramter IV_COMPONENT_NAME not supported by component
    
    CREATE OBJECT lv_comp
    TYPE
    (‘ZCL_COMMON_REPORT’)
    EXPORTING
    iv_mode = ‘D’.
    ENDTRY.
    *DATA(lr_data) = NEW zcl_common_utility2( ) …
    CREATE OBJECT lr_data TYPE (‘ZCL_COMMON_UTILITY2’).
    *CREATE DATA lr_data TYPE (‘ZCL_COMMON_REPORT’) .

IF lr_data IS NOT BOUND .
CREATE DATA lr_data TYPE (‘ZCL_COMMON_REPORT’) .
ENDIF.**

动态调类用方法 :
实例 :
方法1 :
CALL METHOD iv_sproxy->(‘GET_PROTOCOL’)
EXPORTING
protocol_name = if_wsprotocol=>message_id
RECEIVING
protocol = lr_wsprotocol.

    lr_proto_msg_id ?= lr_wsprotocol .
    lv_msgguid   = lr_proto_msg_id->get_message_id( ) .

方法2 :
lr_proxy_basis ?= iv_sproxy .
lr_proto_msg_id2 ?= lr_proxy_basis->get_protocol( if_wsprotocol=>message_id ).
lv_msgguid2 = lr_proto_msg_id2->get_message_id( ).

你可能感兴趣的:(数据库,sql,eclipse)