利用ABAP代码动态生成ABAP类

  • 2020 年 1 月 21 日
  • 筆記

REPORT ZDYANMIC.   DATA ls_vseoclass      TYPE vseoclass.    DATA ls_imp_if         TYPE seor_implementing_r.    DATA lt_imp_if         TYPE seor_implementings_r.    DATA ls_imp_det        TYPE seoredef.    DATA lt_methods_source TYPE seo_method_source_table.    DATA ls_method_source  TYPE seo_method_source.    DATA lv_method         type LINE OF SEOO_METHODS_R.      data: lv_classname LIKE ls_vseoclass-clsname value 'ZCLJERRY8'.      ls_vseoclass-clsname   = lv_classname.    ls_vseoclass-state     = seoc_state_implemented.    ls_vseoclass-exposure  = seoc_exposure_public.    ls_vseoclass-descript  = `Dynamic proxy generated by Jerry's code`.    ls_vseoclass-langu     = sy-langu.    ls_vseoclass-clsccincl = abap_true.    ls_vseoclass-unicode   = abap_true.    ls_vseoclass-fixpt     = abap_true.    ls_vseoclass-clsfinal  = abap_true.      ls_imp_det = ls_imp_if-clsname       = lv_classname.    ls_imp_det = ls_imp_if-refclsname    = 'IF_HELLOWORLD'.    ls_imp_if-state      = seoc_state_implemented.    APPEND ls_imp_if TO lt_imp_if.         CLEAR: ls_method_source.       datA: lv_name type string.       ls_method_source-cpdname = 'IF_HELLOWORLD~PRINT'.       APPEND '  mo_origin->print( ).'       TO ls_method_source-source.         "#EC NOTEXT         APPEND ls_method_source TO lt_methods_source.              clear: ls_method_source.       ls_method_source-cpdname = 'CONSTRUCTOR'.       APPEND 'mo_origin = io_origin.' TO ls_method_source-source.       APPEND ls_method_source TO lt_methods_source.      DATA:          lt_implementation  TYPE seop_source_string,          ls_mtdkey          TYPE seocpdkey,          CV_IMPLEMENTATION TYPE SEOR_IMPLEMENTINGS_R,          ls_source_code     TYPE seo_method_source,          lt_methods TYPE SEOO_METHODS_R,          lt_parameters TYPE SEOS_PARAMETERS_R,          lt_attribute TYPE SEOO_ATTRIBUTES_R,          ls_attribute LIKE LINE OF lt_attribute,          ls_parameter LIKE LINE OF lt_parameters,          ls_method LIKE LINE OF lt_methods.      ls_method-clsname = lv_classname.    ls_method-cmpname = 'CONSTRUCTOR'.    LS_METHOD-state = 1. "implemented    ls_method-exposure = 2. "public    APPEND LS_METHOD TO LT_METHODS.      ls_parameter-clsname = lv_classname.    ls_parameter-cmpname = 'CONSTRUCTOR'.    ls_parameter-version = 1.    ls_parameter-descript = 'Jerry'.    ls_parameter-type = 'IF_HELLOWORLD'.    ls_parameter-SCONAME = 'IO_ORIGIN'.    ls_parameter-CMPTYPE = 1. "METHOD    ls_parameter-mtdtype = 0. "METHOD    ls_parameter-pardecltyp = 0. "IMPORTING    ls_parameter-parpasstyp = 1. "pass by reference    ls_parameter-typtype = 3. "type ref to    "ls_parameter- SCOTYPE = 0. "PARAMETER    append ls_parameter TO lt_parameters.      ls_attribute-clsname = lv_classname.    ls_attribute-cmpname = 'MO_ORIGIN'.    ls_attribute-state = 1.    ls_attribute-attdecltyp = 0.    ls_attribute-attexpvirt = 0. "private    ls_attribute-typtype = 3. "type ref to    ls_attribute-type = 'IF_HELLOWORLD'.    APPEND ls_attribute TO lt_attribute.      CALL FUNCTION 'SEO_CLASS_CREATE_COMPLETE'      EXPORTING        devclass                   = '$TMP'        version                    = seoc_version_active        authority_check            = abap_true        overwrite                  = abap_true        suppress_method_generation = abap_false        genflag                    = abap_false        method_sources             = lt_methods_source        suppress_dialog            = abap_true      CHANGING        class                      = ls_vseoclass        methods =  lt_methods        parameters = lt_parameters        implementings              = lt_imp_if        attributes = lt_attribute      EXCEPTIONS        existing                   = 1        is_interface               = 2        db_error                   = 3        component_error            = 4        no_access                  = 5        other                      = 6        OTHERS                     = 7.    WRITE: / sy-subrc.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":