如何向方法传递两个参数?能否通过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.
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 ).
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
IMPORTINGkeyword 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 theIMPORTINGkeyword: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:
- The first parameter of
set_paramsexpects a value of typeeinri(matchingls_nbew-einri), and the second expectsfalnr(matchingls_nbew-falnr). - Both parameters are defined as
IMPORTING(since you’re passing values to the method, not receiving them back).
- The first parameter of
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

