是否可以实现下面的想法?这个想法是,它几乎可以作为拒绝Get语句的拒绝,但是在OO范式内。
start-of-selection
lv_max_lines = class1->get_max_lines( ).
do lv_max_lines.
class2->method1( class1->get_line_by_index( sy-index ) ).
enddo.
class 2 implementation.
method method1.
method2( is_line ).
endmethod.
method method2.
method3( is_line ).
endmethod.
method method3.
if ls_line <> what_I_need.
class1->reject( ). "or
class1->reject( is_line ).
"go back straight to start of selection and execute next iteration,
"ignoring the rest of method3 and metho2 and method1 from class2.
endif.
"more process
endmethod.
endclass.
肯定可以在Class2方法和return
语句中使用多个条件来完成,但是这个想法是模拟不需要Class2进行任何修改的拒绝,整个作业将留给Class1进行处理。
我的一个想法是从访问的class1表中删除当前行,这不会按预期工作,实际上,我不确定这将如何工作。
我认为这是无法实现的,但是我想尝试一下。
是的,可以通过从类CX_NO_CHECK
继承的基于类的异常。
" inherit cx_no_check to let the exception bubble upwards
" without having to redeclare it
class bad_input definition inheriting from cx_no_check.
endclass.
start-of-selection
lv_max_lines = class1->get_max_lines( ).
do lv_max_lines times.
try.
class2->method1( class1->get_line_by_index( sy-index ) ).
catch bad_input.
" do nothing, just continue with the next line
endtry.
enddo.
class class2 definition.
public section.
methods method1 importing is_line type whatever.
private section.
methods method2 importing is_line type whatever.
methods method3
importing
is_line type whatever.
endclass.
class class2 implementation.
method method1.
method2( is_line ).
endmethod.
method method2.
method3( is_line ).
endmethod.
method method3.
if ls_line <> what_I_need.
raise exception new bad_input( ).
endif.
"more process
endmethod.
endclass.