概述
逻辑顺序:先建立接口及接口下的方法 =》 在类中声明接口 =》在类中实现接口类下的方法 =》定义类的实例,并调用接口下的方法
REPORT ZTEST01.
*----------------------------------------------------------------------*
* INTERFACE ZIF_LCL_CLASS
*----------------------------------------------------------------------*
INTERFACE ZIF_LCL_CLASS. <="自定义接口
METHODS DISPLAY. <="自定义接口下的方法 DISPLAY( )
ENDINTERFACE. "ZIF_LCL_CLASS
*----------------------------------------------------------------------*
* CLASS LCL_CLASS DEFINITION
*----------------------------------------------------------------------*
CLASS LCL_CLASS DEFINITION.
PUBLIC SECTION.
INTERFACES ZIF_LCL_CLASS. <="在类中声明接口
METHODS: OUTPUT IMPORTING PP_LENGTH TYPE I
RETURNING VALUE(PP_TOTAL) TYPE I.
PRIVATE SECTION.
DATA: IM_TOTAL TYPE I,
IM_LENGTH TYPE I.
ENDCLASS. "LCL_CLASS DEFINITION
*----------------------------------------------------------------------*
* CLASS LCL_CLASS IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS LCL_CLASS IMPLEMENTATION.
METHOD ZIF_LCL_CLASS~DISPLAY. <="接口中方法DISPLAY的实现,同时调用PUBLIC SECTION中的另外一个方法
write:/ 'This is only for the interface test.'.
OUTPUT( EXPORTING PP_LENGTH = IM_LENGTH
RECEIVING PP_TOTAL = IM_TOTAL ).
ENDMETHOD. "ZIF_LCL_CLASS~DISPLAY_RESULT
*
METHOD OUTPUT. <="方法OUTPUT的实现
PP_TOTAL = PP_LENGTH * 22.
IM_TOTAL = PP_TOTAL.
ENDMETHOD.
ENDCLASS. "LCL_CLASS IMPLEMENTATION
DATA:CLASS_OBJ TYPE REF TO LCL_CLASS.
DATA: LV_TOTAL TYPE I.
CREATE OBJECT:CLASS_OBJ."创建类的实例
CALL METHOD:CLASS_OBJ->ZIF_LCL_CLASS~DISPLAY.
CLASS_OBJ->OUTPUT( EXPORTING PP_LENGTH = '4'
RECEIVING PP_TOTAL = LV_TOTAL ).
WRITE:/ LV_TOTAL.
最后
以上就是花痴美女为你收集整理的程序中自定义接口和方法的全部内容,希望文章能够帮你解决程序中自定义接口和方法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复