简体   繁体   English

是否可以在 abap OO 中实现 REJECT?

[英]Is it possible to implement a REJECT in abap OO?

Is it possible to implement the idea below?是否有可能实现下面的想法? The idea is that it works pretty much as a REJECT from the GET statement, but inside the OO paradigm.这个想法是它的工作原理与GET语句中的REJECT非常相似,但在 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.

Surely it can be done with multiple conditions in class2 methods and return statements, but the idea would be to simulate a reject which doesn't require the class2 to have any modifications, the whole job would be left to class1 to handle.当然,它可以在 class2 方法和return语句中使用多个条件来完成,但这个想法是模拟一个拒绝,不需要 class2 进行任何修改,整个工作将留给 class1 来处理。

One idea I had was to delete the current line from the class1 table that is being accessed, that would not work as expected, in fact, I am not sure how this would work.我的一个想法是从正在访问的 class1 表中删除当前行,这不会按预期工作,事实上,我不确定这将如何工作。

I think this is not possible to achieve, but I'd like to give it a try regardless.我认为这是不可能实现的,但无论如何我都想尝试一下。

Yes, it is possible through class-based exceptions inheriting from class CX_NO_CHECK .是的,通过继承自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.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM