`

sap parameters 与select-options区别

阅读更多
我们经常会遇到如下的需求,在页面的几个输入框中输入参数,然后在根据输入条件显示结果集列表。这是最常见的report形式。可是问题是,在使用parameters作为参数的时候,某一项的值没有输入,sql执行后的结果与我们期望的不相符,根源在于某一字段为空,查询条件就会去搜索这一字段为空的值,结果往往是没有符合条件的结果。

对应这种情况,可以采取多种方法解决,如使用range,或者使用动态sql语句。但是也可以使用select options 来代替parameters进行输入参数定义。因为select options定义出来的实际上是一个内表,在查询的时候使用IN,即使没有输入,查询语句会忽略这一项的匹配,而不会取数据库里找寻没有值或为空的记录匹配。这样的查询结果才是我们所需要的。

然而,select options 默认会产生两个输入框,这与parameters有些不同,不过没有关系,在定义select options的时候只需要加上一些特殊操作即可以只显示第一个输入框,这样在外观上与parameters就很相似了。

如: SELECT-OPTIONS: so_gjahr FOR bsik-gjahr NO INTERVALS . 这样在查询的时候就不能按照 '=' 来设置查询条件了,而应该应 'IN' 来设置这个条件,即:…… where bsik-gjahr IN so_gjahr ……。这样,即使so_gjahr即使没有输入也不会影响到最终查询的结果。


abap 面试!

37. What are select options and how are they different from parameters?
select options provide
ranges where as parameters do not.
SELECT-OPTIONS declares an internal table which is automatically filled with values
or ranges
of values entered by the end user. For each SELECT-OPTIONS , the system creates a selection table.
SELECT-OPTIONS FOR .
A selection table is an internal table with fields SIGN, OPTION, LOW and
HIGH.
The type of LOW and HIGH is the same as that of .
The SIGN field can take the following values: I
Inclusive (should apply) E Exclusive (should not apply)
The OPTION field can take the following values: EQ Equal GT
Greater than NE Not equal BT Between LE Less
than or equal NB Not between LT Less than CP Contains pattern GE Greater
than or equal NP No pattern.
Select Options vs Parameters
PARAMETERS allow users to enter a single
value into an internal field within a report.
SELECT-OPTIONS allow users to fill an internal table with a range of
values.
For each PARAMETERS or SELECT-OPTIONS statement you should define text elements by choosing
Goto - Text
elements - Selection texts - Change.
Eg:- Parameters name(30).
when the user executes the ABAP/4 program,an
input field for 'name' will appear on the selection screen.You can change the comments on the left side of the input fields
by using text elements as described in Selection Texts.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics