首页 > 其他分享 >如何使用 ABAP Function Module SEO_CLASS_CREATE_COMPLETE 创建 ABAP class

如何使用 ABAP Function Module SEO_CLASS_CREATE_COMPLETE 创建 ABAP class

时间:2023-08-24 22:56:21浏览次数:34  
标签:Function COMPLETE vseoclass lt source ABAP ls TYPE method

SEO_CLASS_CREATE_COMPLETE函数模块用于在SAP系统中创建一个完整的SAP类。在SAP ABAP中,类是面向对象编程的基本构建块,它允许开发者将数据和行为组织到一个单一的实体中。SAP的类通常用于描述业务对象、数据结构和业务逻辑,以实现灵活性和可维护性。

SEO_CLASS_CREATE_COMPLETE函数模块的主要用途包括:

  1. 创建类: 通过SEO_CLASS_CREATE_COMPLETE,开发者可以在SAP系统中创建一个新的ABAP类。这个类可以是一个普通的类,也可以是一个异常类、单例类或接口类。

  2. 定义属性和方法: 在创建类时,可以使用该函数模块来定义类的属性(成员变量)和方法。属性可以是公共的、受保护的或私有的,方法可以是实例方法或类方法。

  3. 处理事件: 除了属性和方法,SAP ABAP类还可以处理事件。通过SEO_CLASS_CREATE_COMPLETE,可以为类添加事件处理程序,以响应特定的事件。

  4. 实现接口: 如果一个类需要实现一个或多个接口,SEO_CLASS_CREATE_COMPLETE也可以用于为类添加接口的实现。

  5. 定义继承关系: SAP ABAP支持继承关系,允许一个类继承另一个类的属性和方法。通过SEO_CLASS_CREATE_COMPLETE,可以定义类之间的继承关系。

本文介绍使用下列 ABAP Function Module 生成新的 ABAP 类的方法。

SEO_CLASS_CREATE_COMPLETE

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 ` WRITE:/ 'before Hello World'.` TO ls_method_source-source.
APPEND '  mo_origin->print( ).'       TO ls_method_source-source.
APPEND ` WRITE:/ 'after Hello World'.` TO ls_method_source-source.

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
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.

标签:Function,COMPLETE,vseoclass,lt,source,ABAP,ls,TYPE,method
From: https://www.cnblogs.com/sap-jerry/p/17655413.html

相关文章

  • element-plus的el-select在切换时报ResizeObserver loop completed with undelivered
    报错场景:el-select放在了table的td里,我做的是根据el-select切换的动态表格。切换时就会报此错误。原因分析:分析发现,本场景在切换select时,其所在单元格尺寸发生了变化(因为我没有定表格内单元格的尺寸)。解决方案:保证el-select所在单元格尺寸不发生变化即可。......
  • SAP ABAP 模式(Pattern)、模板的创建与调用
    1.代码模板2.模式(Pattern) 调用3.标准模式,一些内置固定格式代码的填充  ......
  • The body might complete normally, causing 'null' to be returned, but the return
    你收到的警告信息表明onRefresh回调函数的代码体可能会在没有返回值的情况下正常完成,但是onRefresh的返回类型是Future<void>,这是一个不可为空的类型。要解决这个警告,你可以在onRefresh回调函数中明确返回一个Future<void>。你可以使用async关键字,并返回Future.value()......
  • SAP ABAP SQL编辑器
    事务码:DB02/DBACOCKPIT 结果: ......
  • SAP ABAP 编辑器快捷键
    转成小写Ctrl+L转成大写Ctrl+U大小写互转Ctrl+K剪切一行Ctrl+Shift+X删除一行Ctrl+Shift+L复制一行Ctrl+Shift+T粘贴Ctrl+V查询Ctrl+F转到行Ctrl+O撤销Ctrl+Z重做......
  • a start job is running for udev wait for complete device initialization
    astartjobisrunningforudevwaitforcompletedeviceinitializationreference:https://github.com/AdnanHodzic/displaylink-debian/issues/331diff/etc/init.d/systemd-udevd+systemctlmasksystemd-udev-settleudevadmtrigger--action=addudevadmsett......
  • Nodejs Function遇见WorkerProcessExitException : node exited with code -107374079
    问题描述NodejsFunction,使用BlobTrigger用于处理上传到StorageBlob的文件,但是最近发现偶发报错:Exceptionwhileexecutingfunction:Functions.AzureBlobTrigger--->Microsoft.Azure.WebJobs.Script.Workers.WorkerProcessExitException:nodeexitedwithcode-1073740791......
  • 【Azure Function App】Nodejs Function遇见WorkerProcessExitException : node exite
    问题描述NodejsFunction,使用BlobTrigger用于处理上传到StorageBlob的文件,但是最近发现偶发报错:Exceptionwhileexecutingfunction:Functions.AzureBlobTrigger--->Microsoft.Azure.WebJobs.Script.Workers.WorkerProcessExitException:nodeexitedwithcode-10737407......
  • [React Typescript] Function overload in React hook
    import{useState}from"react";import{Equal,Expect}from"../helpers/type-utils";typeUseStateReturnValue<T>={value:T;set:React.Dispatch<React.SetStateAction<T>>;};exportfunctionuseStateAsObjec......
  • 表单自动填充属性 autocomplete
    摘抄自:HTML属性:autocomplete-HTML(超文本标记语言)|MDN(mozilla.org)表单自动填充不同类型<!--该字段期望该值是一个人的全名--><inputname="name"id="name"autocomplete="name"/><!--该字段期望该值是一个电子邮件值--><inputname="email"id=&q......