Tables 的使用

write / 'select statement'.
tables ztabczw1.
select * from ztabczw1.
  write: / ztabczw1-sysid, ztabczw1-username, ztabczw1-age, ztabczw1-birthdate.
endselect.

skip.
write / 'select single statement'.
select single * from ztabczw1 where sysid = 1.
if sy-dbcnt > 0.
  write: / ztabczw1-sysid, ztabczw1-username, ztabczw1-age, ztabczw1-birthdate.
endif.

skip.
write / 'select table values into workarea'.
data wa type ztabczw1.
select * from ztabczw1 into wa.
  write: / wa-sysid, wa-username, wa-age, wa-birthdate.
endselect.

skip.
write / 'select table values into internal table'.
DATA ITAB like ztabczw1 OCCURS 10 WITH HEADER LINE.
data cDate(8) type c.
SELECT * FROM ztabczw1 INTO table ITAB.
loop at ITAB.
  cDate = ITAB-birthdate.
  write: / ITAB-sysid, ITAB-username, ITAB-age, cDate.
endloop.

SKIP.
write / 'select table value with where clause into internal table'.
*select * from ztabczw1 into table ITAB WHERE AGE BETWEEN 20 AND 24.
*select * from ztabczw1 into table ITAB WHERE username like 'CHUZHAOWE_'.
select * from ztabczw1 into table ITAB WHERE username in ('CHUZHAOWEI', 'LIYAN','XUXIUZHI') ORDER BY AGE SYSID DESCENDING.
 loop at ITAB.
  cDate = ITAB-birthdate.
  write: / ITAB-sysid, ITAB-username, ITAB-age, cDate.
endloop.
CLEAR ITAB[].
FREE ITAB.

*SKIP.
*write / 'INSERT values into table with work area'.
*wa-sysid = 4.
*wa-username = 'zhangsan'.
*wa-age = 26.
*wa-birthdate = '19851122'.
*insert inTO ztabczw1 values wa.
*write / 'insert successful.'.

*SKIP.
*write / 'INSERT values into table with internal table'.
*ITAB-sysid = 5.
*ITAB-username = 'lisi'.
*ITAB-age = 27.
*ITAB-birthdate = '19840507'.
*append ITAB.
*
*ITAB-sysid = 6.
*ITAB-username = 'wang''er'.
*ITAB-age = 27.
*ITAB-birthdate = '19840707'.
*append ITAB.
*
*insert ztabczw1 from TABLE ITAB accepting duplicate keys.
*write: / 'sy-subrc is ', sy-subrc.

skip.
write / 'Update table'.
update ztabczw1 set username = 'LISI' AGE = 29 WHERE SYSID = 5.
commit work and wait.
write: / 'sy-subrc is ', sy-subrc.

skip.
write / 'delete table'.
delete from ztabczw1 where sysid = 6.
commit work and wait.
write: / 'sy-subrc is ', sy-subrc.

skip.
write / 'database cursor'.
CLEAR ITAB[].
FREE ITAB.
data c1 type CURSOR.
open cursor c1 for select * from ztabczw1.
fetch next cursor c1 into wa.
while sy-subrc = 0.
  write: / wa-sysid, wa-username, wa-age, wa-birthdate.
  fetch next cursor c1 into wa.
endwhile.
*fetch next cursor c1 into wa.
*if sy-subrc = 0.
*  write: / wa-sysid, wa-username, wa-age, wa-birthdate.
*endif.
close cursor c1.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值