(1)方式一:使用动态where条件
将where条件通过concatenate进行字符串拼接后,放到内表中,然后再select where中使用该内表,从而实现动态where 条件的功能。
tables : spfli.
data : itab(72) occurs 10 with header line.
parameters : city1(10) type c ,city2(10) type c .
concatenate 'CITYFROM = ''' city1 '''' into itab.
append itab.
concatenate 'or CITYFROM = ''' city2 '''' into itab.
append itab.
loop at itab.
write : itab.
endloop.
skip.
select * from spfli where (itab).
write : / spfli-cityfrom.
endselect .
(2)方式二:使用for all entries in的方式。
tables : spfli.
data : begin of itab occurs 10 ,
cityfrom like spfli-cityfrom,
cityto like spfli-cityto,
end of itab.
itab-cityfrom = 'NEW YORK'.
itab-cityto = 'SAN FRANCISCO'.
append itab.
itab-cityfrom = 'ROME'.
itab-cityto = 'TOKYO'.
append itab.
select * from spfli for all entries in itab where
cityfrom = itab-cityfrom and cityto = itab-cityto .
write : / spfli-cityfrom ,spfli-cityto.
endselect