4

メソッド foo( ) 内で関数モジュールを呼び出したい ABAP-OO クラスがあります。メソッド foo( ) を使用しなければならない 2 つのケース (A & B) があります。ケース A がデフォルトであり、次のような汎用モジュールが必要であるとします。

METHOD foo.
  CALL FUNCTION 'A_FUNCTION'
    EXPORTING
      required_param_x = something
      required_param_y = something_else.
      " optional_param = " i am commented out and only need for case B
ENDMETHOD.

ケース B は「特殊」であり、上記の optional_param を設定する必要もあります。私の現在の状況は、そのような2番目の方法を持つことです:

METHOD foo_b_case.
  CALL FUNCTION 'A_FUNCTION'
    EXPORTING
      required_param_x = something
      required_param_y = something_else
      optional_param = case_b_stuff.
ENDMETHOD.

もちろん、これは非常に冗長です。上記のように、私の実際のコーディングもはるかに複雑です。私の質問は、どうすればそのメソッド foo_b_case( ) を取り除き、foo( ) を両方のケースに適したものにすることができるでしょうか?

たとえば、パラメーター「case_b_stuff」をオプションにして、それぞれの場合に渡すだけです。「case_b_stuff」が初期の場合、ABAP は「optional_param」をどのように処理しますか?

4

2 に答える 2

2

as already explained in the comment, first check what default value the function module for that optional parameter has. If there is none, submitting an initial value is fine. If there is a default value, submitting an initial value would override the default behavior. To make sure the FM works as expected, initialize your parameter variable with the default value of the FM in question and only override it if needed.

于 2014-11-06T09:37:22.330 に答える