abap逻辑数据库:ABAP数据库操作

ABAP数据库操作(学习SAP程序设计的整理-数据库) 
1、abap语言使用的数据库语言:opensql,Nativesql(特定数据库自身sql) 
2、使用OPenSQL注意的原则: 
a、尽可能减少满足条件的数据条目数量。 
b、减少数据的传输量,以减少网络流量。 
c、减少访问的数据库表量。 
d、减少查询难度,可以通过整理选择标准来实现。 
e、减少数据库负载。 
3、使用Nativesql有两个前提: 
a、知道使用数据库的类型。 
b、了解该数据库的SQL语法。 
4、ABAP的数据定义由数据字典创建。 
5、提取数据方式:内表,工作区,变量。 
6、select语句: 
select<result>from<source>into<target> 
where<condition>[groupby<field>] 
[having<cond>][orderby<field>]. 
7、选择单行全部数据: 
selectsingle*fromspfliintowa_spfliwherecityform=’singapore’andinto 
cityto=’beijing’. 
8、选择单行指定字段: 
selectsinglecarridconnidfromspfliinto(wa_carrid,wa_connid)wherecityform=’singapore’ 
andintocityto=’beijing’. 
9、选择相关字段: 
selectsinglecarridconnid*fromspfliintocorrespondingfieldsof 
wa_spfliwherecityform=’singapore’andintocityto=’beijing’. 
10、循环选择: 
select* 
fromspfliintowa_spfli. 
write:/wa_spfli-carrid,wa_spfli-connid. 
endselect. 
11、选择至内表: 
select* 
fromspfliintotableta_spfli. 
读取时: 
loopatta_spfli. 
write:/ta_spfli-carridta_spfli-connid. 
endloop. 
12、指定查询条件 
比较运算符:=<><><=>= 
范围限定运算符:[not]between 
字符比较运算符:[not]like’_’替代单个字符,’%’任意字符 
忽略符号: 
select....wherefunclike’EDIT#_%’escape’#’.escape是指忽略’#’。 
检查值列表: 
select.....wherecityin(’Berlin’,’Rome’,’London’).指定城市’Berlin’,’Rome’,’London’。 
检查空值:where...fis[not]null..... 
检查选择表:where...f[not]inseltab....seltab是选择标准表,是具有特定格式的内表,可以 
通过select-options语句添加到程序和报表选择屏幕,并由报表用户填充,在可以在程序中创建(如使用 
range语句) 
13、动态指定查询条件: 
reportZ_test. 
data:cond(72)typec, 
itabliketableofcond, 
city1(10)value’BEIJING’, [Page]
city1(10)value’SINGAPORE’, 
itab_spfliliketalbeofspfliwithheaderline... 
concatenate’cityfrom=’’’city1’’’’intocond. 
appendcondtoitab. 
concatenate’cityfto’=’’’city2’’’’intocond. 
appendcondtoitab. 
select*intotableitab_spflifromspfli 
where(itab). 
14、多表结合查询(嵌套,效率较低): 
reprotz_test. 
data:wa_carridtypespfli-carrid, 
wa_connidtypespfli-connid, 
wa_carrnametypescarr-carrname. 
selectcarridconnid 
fromspfliinto(wa_carrid,wa_connid) 
wherecityform=’singapore’andintocityto=’beijing’. 
selectcarrnamefromscarrintowa_carrnamewherecarrid=wa_carrid. 
writewa_carrname. 
endselect. 
endselect. 
15、forallentries选项 
reprotz_test. 
data:beginofwa_spfli, 
carridtypespfli-carrid, 
connidtypespfli-connid, 
endofwa_spfli, 
beginofwa_scarr, 
carridtypescarr-carrid, 
carrnametypescarr-carrname, 
endofwa_scarr, 
spfli_tabliketableofwa_spfli. 
selectcarridconnid 
fromspfli 
intotablespfli_tab 
wherecityfrom=’Singapore’. 
selectcarridcarrname 
fromscarr 
intowa_scarr 
forallentiresinspfli_tab 
wherecarrid=spfli_tab-carrid. 
... 
endselect. 
16、使用视图 
reprotz_test. 
data:wa_carridtypescarrspfli-carrid, 
wa_connidtypescarrspfli-connid, 
wa_carrnametypescarrspfli-carrname. 
selectcarridcarrnameconnid 
fromscarrspfli 
into(wa_carrid,wa_carrname,wa_connid) 
wherecityfrom=’Singapore’. 
... 
endselect. 
17、结合查询 
内连接:innerjoin主表和结合表都满足on的条件 
左连接:leftjoin主选择表的数据,即使在结合表中不存在,也会查询出,以空白显示。


文章来自: 本站原创
引用通告地址: http://www.is21.cn/trackback.asp?tbID=570
Tags:
评论: 0 | 引用: 0 | 查看次数: 2611
发表评论
你没有权限发表留言!