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.
Tables 的使用
最新推荐文章于 2022-10-09 22:44:32 发布