我想为我的持久化类创建一个抽象超类,它提供了一些函数来查询作为该类成员的任何其他持久类。
因此,当我收到以下错误时,我尝试将此抽象类添加为超类:
持久化类的超类必须是持久的
消息号OO629
有什么好的解决方法吗? (我的意思是制作一个接口并将函数复制粘贴到每个子类中的不同之处)
Here is what I want to do (Try IE if it does not work with chrome or friefox
简短摘要:
user
)user_has_tag
)中的所有“链接”,将其填入属性tag
)。这是我的抽象超类(通用函数QUERY_BY_UUID
:
CLASS zcl_ps_hrmobject DEFINITION
PUBLIC
ABSTRACT
CREATE PUBLIC .
PUBLIC SECTION.
METHODS get_uuid
RETURNING
VALUE(ro_uuid) TYPE uuid .
PROTECTED SECTION.
METHODS query_by_uuid
IMPORTING
!ir_agent TYPE REF TO object
RETURNING
VALUE(rt_entries) TYPE osreftab
RAISING
cx_os_object_not_found
cx_os_query_error .
METHODS get_query
RETURNING
VALUE(rr_query) TYPE REF TO if_os_query .
PRIVATE SECTION.
CONSTANTS lc_query_method_name TYPE string VALUE 'IF_OS_CA_PERSISTENCY~GET_PERSISTENT_BY_QUERY'. "#EC NOTEXT
DATA mlr_query TYPE REF TO if_os_query .
ENDCLASS.
CLASS zcl_ps_hrmobject IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZCL_PS_HRMOBJECT->GET_QUERY
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RR_QUERY TYPE REF TO IF_OS_QUERY
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_query.
rr_query = me->mlr_query.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_PS_HRMOBJECT->GET_UUID
* +-------------------------------------------------------------------------------------------------+
* | [<-()] RO_UUID TYPE UUID
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD get_uuid.
* must be implemented in subclass
RAISE EXCEPTION TYPE cx_os_no_implementation
* EXPORTING
* textid =
* previous =
.
ENDMETHOD.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Protected Method ZCL_PS_HRMOBJECT->QUERY_BY_UUID
* +-------------------------------------------------------------------------------------------------+
* | [--->] IR_AGENT TYPE REF TO OBJECT
* | [<-()] RT_ENTRIES TYPE OSREFTAB
* | [!CX!] CX_OS_OBJECT_NOT_FOUND
* | [!CX!] CX_OS_QUERY_ERROR
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD query_by_uuid.
DATA: lr_query TYPE REF TO if_os_query,
lr_uuid TYPE uuid.
lr_query = me->get_query( ).
lr_uuid = me->get_uuid( ).
*TRY.
CALL METHOD ir_agent->(lc_query_method_name)
EXPORTING
i_query = lr_query
* i_parameter_tab =
i_par1 = lr_uuid
* i_par2 =
* i_par3 =
* i_subclasses = OSCON_FALSE
* i_upto = 0
* i_options = IF_OS_QUERY_OPTIONS=>DEFAULT_OPTIONS
RECEIVING
result = rt_entries.
* CATCH cx_os_object_not_found .
* CATCH cx_os_query_error .
*ENDTRY.
ENDMETHOD.
ENDCLASS.
答案 0 :(得分:0)
没有。您的描述听起来似乎可能需要仔细查看生成的代理类和查询服务提供的方法。
答案 1 :(得分:0)
我用接口和静态辅助类解决了这个问题。
界面强制执行三个getter:
get_uuid ( )
get_query ( )
get_query_method_name ( )
现在每个Element都实现了这个接口。
在helperclass中我现在有了我想要的Query_by_uuid函数,它获得了该接口的实例类型(ir_root_instance
)。
这里的功能
METHOD QUERY_BY_UUID.
DATA: lr_query TYPE REF TO if_os_query,
lr_uuid TYPE uuid,
lv_query_method_name TYPE string.
lr_query = ir_root_instance->get_query( ).
lr_uuid = ir_root_instance->get_uuid( ).
lv_query_method_name = ir_root_instance->get_query_method_name( ).
*TRY.
CALL METHOD ir_agent->(lv_query_method_name)
EXPORTING
i_query = lr_query
* i_parameter_tab =
i_par1 = lr_uuid
* i_par2 =
* i_par3 =
* i_subclasses = OSCON_FALSE
* i_upto = 0
* i_options = IF_OS_QUERY_OPTIONS=>DEFAULT_OPTIONS
RECEIVING
result = rt_entry.
* CATCH cx_os_object_not_found .
* CATCH cx_os_query_error .
*ENDTRY.
ENDMETHOD.