是否可以在 abap OO 中实现 REJECT?
Is it possible to implement a REJECT in abap OO?
是否可以实现下面的想法?这个想法是它的工作原理与 REJECT from the 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 table 中删除当前行,这不会按预期工作,事实上,我不确定这将如何工作。
我认为这是不可能实现的,但无论如何我都想试一试。
是的,可以通过 class-based exceptions 继承自 class 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.
是否可以实现下面的想法?这个想法是它的工作原理与 REJECT from the 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 table 中删除当前行,这不会按预期工作,事实上,我不确定这将如何工作。
我认为这是不可能实现的,但无论如何我都想试一试。
是的,可以通过 class-based exceptions 继承自 class 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.