You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何向方法传递两个参数?能否通过lo_newfal->set_params( ls_nbew-einri, ls_nbew-falnr)形式为set_params设置两个参数?

Hey there! Let's tackle your two questions about ABAP method parameter passing—since einri (facility number) and falnr (case number) are involved, I’m guessing you’re working with SAP Healthcare/IS-H case objects.

1. How to Pass Two Parameters to a Method

In ABAP, there are two common, reliable ways to pass parameters to a method:

Positional Parameter Passing

This is the straightforward approach where you pass values in the exact order the method defines its parameters. For example, if your set_params method is defined like this:

METHOD set_params
  IMPORTING
    iv_einri TYPE einri
    iv_falnr TYPE falnr.

You can pass the two values directly in the order of iv_einri first, then iv_falnr.

Named Parameter Passing

This method explicitly maps your values to the method’s parameter names, which is far more readable (especially if the method has multiple parameters) and avoids mistakes if the parameter order ever changes. Using named parameters for your case would look like:

lo_newfal->set_params(
  iv_einri = ls_nbew-einri
  iv_falnr = ls_nbew-falnr
).
2. Is lo_newfal->set_params( ls_nbew-einri, ls_nbew-falnr ) Valid?

Short answer: It depends on your ABAP version and the method’s parameter definition.

  • ABAP Version Requirement: This simplified positional syntax (omitting the IMPORTING keyword and just listing values separated by commas) is only supported in ABAP 7.40 and newer. If you’re on an older version, you’ll need to use the classic syntax with the IMPORTING keyword:
    lo_newfal->set_params(
      IMPORTING
        iv_einri = ls_nbew-einri
        iv_falnr = ls_nbew-falnr
    ).
    
  • Parameter Order & Type Match: Even on a newer ABAP version, this syntax only works if:
    1. The first parameter of set_params expects a value of type einri (matching ls_nbew-einri), and the second expects falnr (matching ls_nbew-falnr).
    2. Both parameters are defined as IMPORTING (since you’re passing values to the method, not receiving them back).

Pro Tip

While the simplified positional syntax is concise, I’d recommend using named parameters most of the time. It makes your code easier to read for other developers (or future you!) and prevents bugs if the method’s parameter order is ever modified.

内容的提问来源于stack exchange,提问作者DarkIceDust

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 09:57:44