我想询问如何在具有多个输入字段的选择屏幕中进行基本搜索过滤。
我尝试通过使用多个if语句,然后是解决我当前问题的条款,但如果我只使用少数输入(目前为2,'id''和'number'(,该代码不会太长,但是如果它超过10个左右,则这样做是错误的
我到目前为止尝试的是这样的:
IF lv_id IS INITIAL and lv_nr IS INITIAL.
SELECT * from DBase INTO TABLE Local_Table.
ELSEIF lv_id IS NOT INITIAL AND lv_nr IS INITIAL.
SELECT * from DBase INTO TABLE Local_Table WHERE ID = lv_nr.
ELSEIF lv_id IS INITIAL AND lv_nr IS NOT INITIAL.
SELECT * from DBase INTO TABLE Local_Table WHERE Number = lv_nr.
ELSEIF lv_id IS NOT INITIAL AND lv_nr IS NOT INITIAL.
SELECT * from DBase INTO TABLE Local_Table WHERE ID = lv_id AND Number = lv_nr.
预期的结果是,搜索可以通过没有输入或多个不阐明输入来正确执行,而无需编写很长的代码,以防输入数量很高。
您可以在有多个条件时在您的Where子句中使用in Operator。
首先,您需要为每个参数定义一个选择表,必须填充它们或将其留空。
types: begin of myselopt ,
sign type char1 ,
option type char2 ,
low type ... (depends on the type you want select)
high type ... ,
end of myselopt .
types : t_selopt type table of myselopt .
data: gt_selopt type t_selopt ,
gt_selopt_2 type t_selopt_2 . #needs to be defined first
if lv_id is not initial .
insert value #( sign = 'I' option = 'EQ' low = lv_id ) into table gt_selopt .
endif .
if lv_nr is not initial .
insert value #( sign = 'I' option = 'EQ' low = lv_nr ) into table gt_selopt_2 .
endif .
您必须为要查询的每个参数执行此操作。而且您的查询看起来像这样
select * from dbaste into table local_table where id in gt_selopt
and number in gt_selopt_2 .
您可以将输入字段定义为SELECT-OPTIONS
(带有可选的NO INTERVALS NO-EXTENSION
来模仿PARAMETERS
的外观(。然后只需在您的WHERE
子句中使用IN
操作员:
REPORT.
DATA: your_ztable TYPE your_ztable.
SELECT-OPTIONS: s_id FOR your_ztable-id NO INTERVALS NO-EXTENSION,
s_nr FOR your_ztable-number NO INTERVALS NO-EXTENSION.
AT SELECTION-SCREEN.
SELECT * FROM your_ztable
WHERE id IN @s_id
AND number IN @s_nr
INTO TABLE @DATA(local_table).
串联条件下的这种方法怎么样?
DATA:
lv_where TYPE string.
IF lv_id IS NOT INITIAL.
CONCATENATE ' AND ID' space '=' space '"' lv_id '"' INTO lv_where.
ENDIF.
IF lv_nr IS NOT INITIAL.
CONCATENATE ' AND Number' space '=' space '"' lv_nr '"' INTO lv_where.
ENDIF.
IF lv_where IS NOT INITIAL.
SHIFT lv_where By 5 PLACES. " to remove leading _AND_ (
ENDIF.
SELECT * from DBase INTO TABLE Local_Table WHERE (lv_where).