其他分享
首页 > 其他分享> > ABAP创建全局类

ABAP创建全局类

作者:互联网

ABAP创建全局类

  1 *&---------------------------------------------------------------------*
  2 *& Report Z3426_CLASS004
  3 *&---------------------------------------------------------------------*
  4 *&
  5 *&---------------------------------------------------------------------*
  6 REPORT z3426_class004.
  7 
  8 DATA ls_vseoclass      TYPE vseoclass.
  9 DATA ls_imp_if         TYPE seor_implementing_r.
 10 DATA lt_imp_if         TYPE seor_implementings_r.
 11 DATA ls_imp_det        TYPE seoredef.
 12 DATA lt_methods_source TYPE seo_method_source_table.
 13 DATA ls_method_source  TYPE seo_method_source.
 14 DATA lv_method         TYPE LINE OF seoo_methods_r.
 15 
 16 DATA:lt_implementation TYPE seop_source_string,
 17      ls_mtdkey         TYPE seocpdkey,
 18      cv_implementation TYPE seor_implementings_r,
 19      ls_source_code    TYPE seo_method_source,
 20      lt_methods        TYPE seoo_methods_r,
 21      lt_parameters     TYPE seos_parameters_r,
 22      lt_attribute      TYPE seoo_attributes_r,
 23      ls_attribute      LIKE vseoattrib,
 24      ls_parameter      LIKE vseoparam,
 25      ls_method         LIKE vseomethod.
 26 
 27 DATA: lv_classname LIKE ls_vseoclass-clsname VALUE 'ZCL_3426001'.
 28 
 29 * 设置类的抬头参数
 30 ls_vseoclass-clsname   = lv_classname.
 31 ls_vseoclass-state     = seoc_state_implemented.
 32 ls_vseoclass-exposure  = seoc_exposure_public.
 33 ls_vseoclass-descript  = `陈辉自定义类测试`.
 34 ls_vseoclass-langu     = sy-langu.
 35 ls_vseoclass-clsccincl = abap_true.
 36 ls_vseoclass-unicode   = abap_true.
 37 ls_vseoclass-fixpt     = abap_true.
 38 ls_vseoclass-clsfinal  = abap_true.
 39 
 40 *设置类的属性
 41 ls_attribute-clsname = lv_classname.
 42 ls_attribute-cmpname = 'OV_STR'."类的属性
 43 ls_attribute-state = 1.
 44 ls_attribute-attdecltyp = 0.
 45 ls_attribute-attexpvirt = 0.
 46 ls_attribute-typtype = 1.
 47 ls_attribute-type = 'STRING'.
 48 ls_attribute-descript = '类的属性'.
 49 APPEND ls_attribute TO lt_attribute.
 50 CLEAR:ls_attribute.
 51 
 52 *方法声明
 53 ls_method-clsname = lv_classname.
 54 ls_method-cmpname = 'CONSTRUCTOR'.
 55 ls_method-state = 1. "implemented
 56 ls_method-exposure = 2. "public
 57 APPEND ls_method TO lt_methods.
 58 
 59 ls_method-clsname = lv_classname.
 60 ls_method-cmpname = 'GET_STR'.
 61 ls_method-state = 1. "implemented
 62 ls_method-exposure = 2. "public
 63 APPEND ls_method TO lt_methods.
 64 
 65 *设置方法的入参,出参
 66 ls_parameter-clsname = lv_classname.
 67 ls_parameter-cmpname = 'CONSTRUCTOR'.
 68 ls_parameter-sconame = ''.
 69 ls_parameter-version = 1."0    未激活 1    活动
 70 ls_parameter-descript = '构造方法'.
 71 ls_parameter-type = 'STRING'.
 72 ls_parameter-langu = sy-langu.
 73 ls_parameter-sconame = 'IV_STR'.
 74 ls_parameter-cmptype = 1. "*0 属性 1 方法 2 事件3 类型
 75 ls_parameter-mtdtype = 0. "METHOD
 76 ls_parameter-pardecltyp = 0. "IMPORTING
 77 ls_parameter-parpasstyp = 1. "pass by reference
 78 ls_parameter-typtype = 1. "0  属性参考 (LIKE) 1  类型参考 (TYPE) 2  对象 (TYPE) 3  对象参考 (TYPE REF TO) 4  查看代码 5  框式组件 (TYPE ... BOXED)
 79 APPEND ls_parameter TO lt_parameters.
 80 CLEAR:ls_parameter.
 81 
 82 ls_parameter-clsname = lv_classname.
 83 ls_parameter-cmpname = 'GET_STR'.
 84 ls_parameter-sconame = ''.
 85 ls_parameter-version = 1."0    未激活 1    活动
 86 ls_parameter-descript = '入参'.
 87 ls_parameter-type = 'STRING'.
 88 ls_parameter-langu = sy-langu.
 89 ls_parameter-sconame = 'IV_STR'.
 90 ls_parameter-cmptype = 1. "*0 属性 1 方法 2 事件3 类型
 91 ls_parameter-mtdtype = 0. "METHOD
 92 ls_parameter-pardecltyp = 0. "IMPORTING
 93 ls_parameter-parpasstyp = 1. "pass by reference
 94 ls_parameter-typtype = 1. "0  属性参考 (LIKE) 1  类型参考 (TYPE) 2  对象 (TYPE) 3  对象参考 (TYPE REF TO) 4  查看代码 5  框式组件 (TYPE ... BOXED)
 95 ls_parameter-paroptionl = 'X'."可选
 96 APPEND ls_parameter TO lt_parameters.
 97 
 98 CLEAR:ls_parameter.
 99 ls_parameter-clsname = lv_classname.
100 ls_parameter-cmpname = 'GET_STR'.
101 ls_parameter-sconame = ''.
102 ls_parameter-version = 1."0    未激活 1    活动
103 ls_parameter-descript = '出参'.
104 ls_parameter-type = 'STRING'.
105 ls_parameter-langu = sy-langu.
106 ls_parameter-sconame = 'OV_STR'.
107 ls_parameter-cmptype = 1. "*0 属性 1 方法 2 事件3 类型
108 ls_parameter-mtdtype = 0. "METHOD
109 ls_parameter-pardecltyp = 1. "0 导入 1  导出 2  更改 3  返回
110 ls_parameter-parpasstyp = 1. "pass by reference
111 ls_parameter-typtype = 1. "0  属性参考 (LIKE) 1  类型参考 (TYPE) 2  对象 (TYPE) 3  对象参考 (TYPE REF TO) 4  查看代码 5  框式组件 (TYPE ... BOXED)
112 APPEND ls_parameter TO lt_parameters.
113 
114 * 实现类的构造方法
115 CLEAR: ls_method_source.
116 ls_method_source-cpdname = 'CONSTRUCTOR'.
117 ls_method_source-source = VALUE #(
118 ( `   WRITE:'HELLO WORLD'.` )
119 ( `   WRITE:'HELLO WORLD'.` )
120 ( `   WRITE:'HELLO WORLD'.` )
121 ( `   WRITE:'HELLO WORLD'.` )
122 ( `   WRITE:'HELLO WORLD'.` )
123 ( `   WRITE:'HELLO WORLD'.` )
124 ( `   WRITE:'HELLO WORLD'.` )
125 ( `   WRITE:'HELLO WORLD'.` )
126 ( `   WRITE:'HELLO WORLD'.` )
127 ( `   WRITE:'HELLO WORLD'.` )
128 ( `   WRITE:'HELLO WORLD'.` )
129 ( `   WRITE:'HELLO WORLD'.` )
130 ( `   WRITE:'HELLO WORLD'.` )
131 ( `   WRITE:'HELLO WORLD'.` )
132 ( `   WRITE:'HELLO WORLD'.` )
133 ( `   WRITE:'HELLO WORLD'.` )
134 ( `   WRITE:'HELLO WORLD'.` )
135 ( `   WRITE:'HELLO WORLD'.` )
136 ( `   WRITE:'HELLO WORLD'.` )
137 ( `   WRITE:'HELLO WORLD'.` )
138 ( `   WRITE:'HELLO WORLD'.` )
139 ( `   WRITE:'HELLO WORLD'.` )
140 ( `   WRITE:'HELLO WORLD'.` )
141 ( `   WRITE:'HELLO WORLD'.` )
142 ( `   WRITE:'HELLO WORLD'.` )
143 ( `   WRITE:'HELLO WORLD'.` )
144 ( `   WRITE:'HELLO WORLD'.` )
145 ( `   WRITE:'HELLO WORLD'.` ) ).
146 APPEND ls_method_source TO lt_methods_source.
147 CLEAR:ls_method_source.
148 
149 * 实现类的自定义方法
150 CLEAR: ls_method_source.
151 ls_method_source-cpdname = 'GET_STR'.
152 ls_method_source-source = VALUE #(
153 ( `   WRITE:'HELLO WORLD'.` )
154 ( `   OV_STR = '返回参数测试' && IV_STR && SY-DATUM && SY-UZEIT.` )
155  ).
156 APPEND ls_method_source TO lt_methods_source.
157 CLEAR:ls_method_source.
158 
159 CALL FUNCTION 'SEO_CLASS_CREATE_COMPLETE'
160   EXPORTING
161     devclass                   = '$TMP'
162     version                    = seoc_version_active
163     authority_check            = abap_true
164     overwrite                  = abap_true
165     suppress_method_generation = abap_false
166     genflag                    = abap_false
167     method_sources             = lt_methods_source
168     suppress_dialog            = abap_true
169   CHANGING
170     class                      = ls_vseoclass
171     methods                    = lt_methods
172     parameters                 = lt_parameters
173     implementings              = lt_imp_if
174     attributes                 = lt_attribute
175   EXCEPTIONS
176     existing                   = 1
177     is_interface               = 2
178     db_error                   = 3
179     component_error            = 4
180     no_access                  = 5
181     other                      = 6
182     OTHERS                     = 7.
183 
184 IF sy-subrc <> 0.
185   WRITE '类创建失败!'.
186 ELSE.
187   WRITE '类创建成功!'.
188 ENDIF.
View Code

 

标签:创建,method,WRITE,ABAP,ls,WORLD,全局,parameter,HELLO
来源: https://www.cnblogs.com/1187163927ch/p/16326032.html