select应用区分

一般在从数据库读取数据的时候,一般的select语法已经足够用了,但在应用的时候要注意各种写法之间的区别,做了个小例子,分析一下:

例程概要:

从凭证头表bkpf读取符合条件的凭证号码。

抽取条件:

1。记账日期符合画面输入条件;

2。记账凭证类型不等于104091

[@more@]

selset写法:

1。for all entries的应用

* for all entries
select belnr
from bkpf
into table it_bkpf
for all entries in it_blart
where budat >= s_budat-low
and budat <= s_budat-high
and blart <> it_blart-blart.

分析:这种写法是错误的。因为blart的限制条件无效。

2。where table的应用

* where table
select belnr
from bkpf
into table it_bkpf
where (it_where).

分析:it_where的内容如下

* where budat >= s_budat-low
* and budat <= s_budat-high
* and blart <> '40'
* and blart <> '91'
* and blart <> '10'.

3。not in range的应用

* not in range
select belnr
from bkpf
into table it_bkpf
where budat >= s_budat-low
and budat <= s_budat-high
and blart not in r_blart.

分析:把104091编辑到range表里。

总结:以上三种写法1错误,23正确。所以应注意,在使用for all entries的时候,不要进行<>的判断。对于23的写法,可能结果正确,但是在select之前要进行一些必要的编辑,也就是会增加一些代码。

当然实现方法很多,各有利弊,使用中应该因地制宜。

附:测试程序代码。

tables: bkpf.

SELECT-OPTIONS: s_budat for bkpf-budat.

types: begin of typ_where,
data1(10) type c,
where1(10) type c,
data2(15) type c,
where2(10) type c,
end of typ_where.

types: begin of typ_bkpf,
belnr type bkpf-belnr,
end of typ_bkpf.

types: begin of typ_blart,
blart type bkpf-blart,
end of typ_blart.

data: it_bkpf type standard table of typ_bkpf,
wa_bkpf type typ_bkpf.

data: it_blart type standard table of typ_blart,
wa_blart type typ_blart.

data: it_where type standard table of typ_where,
wa_where type typ_where.

ranges: r_blart for bkpf-blart.

data: v_line type i.

start-of-selection.
*edit blart
wa_blart-blart = '40'.
append wa_blart to it_blart.

wa_blart-blart = '91'.
append wa_blart to it_blart.

* wa_blart-blart = '10'.
* append wa_blart to it_blart.

*edit where
wa_where-data1 = 'BUDAT'.
wa_where-where1 = ' >='.
wa_where-data2 = ' S_BUDAT-LOW'.
wa_where-where2 = ' AND'.
append wa_where to it_where.

wa_where-data1 = 'BUDAT'.
wa_where-where1 = ' <='.
wa_where-data2 = ' S_BUDAT-HIGH'.
wa_where-where2 = ' AND'.
append wa_where to it_where.

loop at it_blart into wa_blart.
wa_where-data1 = 'BLART'.
wa_where-where1 = ' <>'.
* wa_where-data2 = ' WA_BLART-BLART'.

wa_where-data2 = WA_BLART-BLART.

wa_where-where2 = ' AND'.

at last.
wa_where-where2 = space.
endat.

append wa_where to it_where.
clear wa_where.
endloop.

*edit range
loop at it_blart into wa_blart.
r_blart-sign = 'I'.
r_blart-option = 'EQ'.
r_blart-low = wa_blart-blart.
r_blart-high = space.

append r_blart.
clear r_blart.
endloop.


* for all entries
select belnr
from bkpf
into table it_bkpf
for all entries in it_blart
where budat >= s_budat-low
and budat <= s_budat-high
and blart <> it_blart-blart.

v_line = lines( it_bkpf ).
write: /1 'for all entries:',
20 v_line.

* where table
select belnr
from bkpf
into table it_bkpf
where (it_where).
* where budat >= s_budat-low
* and budat <= s_budat-high
* and blart <> '40'
* and blart <> '91'
* and blart <> '10'.

v_line = lines( it_bkpf ).
write: /1 'where table:',
20 v_line.

* not in range
select belnr
from bkpf
into table it_bkpf
where budat >= s_budat-low
and budat <= s_budat-high
and blart not in r_blart.

v_line = lines( it_bkpf ).
write: /1 'not in range:',
20 v_line.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/547380/viewspace-970413/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/547380/viewspace-970413/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值