我有以下情况。
具有本地接口定义的包含
*&---------------------------------------------------------------------*
*& Include ZZZ_INCL_INTERFACE
*&---------------------------------------------------------------------*
INTERFACE lif_test.
METHODS:
test.
ENDINTERFACE. "lif_test
使用此包含并定义实现此接口的类的报告。
*&---------------------------------------------------------------------*
*& Report ZZZ_IMPL_A
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zzz_impl_a.
INCLUDE zzz_incl_interface.
*----------------------------------------------------------------------*
* CLASS lcl_test_a DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test_a DEFINITION FINAL.
PUBLIC SECTION.
INTERFACES:
lif_test.
ENDCLASS. "lcl_test_a DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_test_a IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test_a IMPLEMENTATION.
METHOD lif_test~test.
ENDMETHOD. "lif_test~test
ENDCLASS. "lcl_test_a IMPLEMENTATION
第二个报告也使用此包含并定义了一个新类,该类也实现了包含中定义的相同接口。
*&---------------------------------------------------------------------*
*& Report ZZZ_IMPL_B
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zzz_impl_b.
INCLUDE zzz_incl_interface.
*----------------------------------------------------------------------*
* CLASS lcl_test_b DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test_b DEFINITION FINAL.
PUBLIC SECTION.
INTERFACES:
lif_test.
ENDCLASS. "lcl_test_b DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_test_b IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test_b IMPLEMENTATION.
METHOD lif_test~test.
ENDMETHOD. "lif_test~test
ENDCLASS. "lcl_test_b IMPLEMENTATION
CLASS lcl_main DEFINITION FINAL CREATE PRIVATE.
PUBLIC SECTION.
CLASS-METHODS:
main.
ENDCLASS.
CLASS lcl_main IMPLEMENTATION.
METHOD main.
DATA:
l_rif_test TYPE REF TO lif_test.
CREATE OBJECT l_rif_test TYPE ('\PROGRAM=ZZZ_IMPL_B\CLASS=LCL_TEST_B').
CREATE OBJECT l_rif_test TYPE ('\PROGRAM=ZZZ_IMPL_A\CLASS=LCL_TEST_A').
ENDMETHOD.
ENDCLASS.
END-OF-SELECTION.
lcl_main=>main( ).
该行CREATE OBJECT l_rif_test TYPE ('\PROGRAM=ZZZ_IMPL_A\CLASS=LCL_TEST_A')
生成一个简短的转储,说明动态创建的对象不是lif_test
. 有人能解释一下为什么会这样吗?它看起来像是语言定义中的一个大漏洞。从一开始就停止任何讨论:不,我不能使用接口的字典定义。
编辑:尝试转换第二个创建的对象的实例时,会获得更具描述性的简短转储CREATE OBJECT
。
DATA:
l_rcl_object TYPE REF TO object.
*...
CREATE OBJECT l_rcl_object TYPE ('\PROGRAM=ZZZ_IMPL_A\CLASS=LCL_TEST_A').
l_rif_test ?= l_rcl_object.
短转储有它
The content of the source variable does not fit in the target variable.
Source type: "\PROGRAM=ZZZ_IMPL_A\CLASS=LCL_TEST_A"
Target type: "\PROGRAM=ZZZ_IMPL_B\INTERFACE=LIF_TEST"
看起来当我在两个地方包含接口的本地定义时,它们变成了两个单独的定义,一个是 program ZZZ_IMPL_B
,另一个是ZZZ_IMPL_A
.