abap 数据库操作部分
时间:2010-08-20 来源:漠北的天空
DATA c_tb TYPE zcouy_tb OCCURS 0 WITH HEADER LINE .
*----Insert------
c_tb-countryid = 000 .
c_tb-countryname = 'kk' .
c_tb-cityid = 13 .
append c_tb .
c_tb-countryid = 000 .
c_tb-countryname = 'jj' .
c_tb-cityid = 14 .
append c_tb .
loop at c_tb .
INSERT INTO zcouy_tb VALUES c_tb .
IF sy-subrc = 0 .
WRITE : / ' insert success ' .
ENDIF .
endloop .
*----update -----
update zcouy_tb
cityid = 1
where cityid = 14 .
*----delete -----
delete from zcouy_tb where countryname = 'CH' .
*----select -----
SELECT *
FROM zcouy_tb
INTO c_tb
where cityid = 1 .
WRITE : / c_tb .
ENDSELECT .
*----max,min,group by ,having -----
DATA:d_countryid TYPE zcouy_tb-countryid ,
d_maxname TYPE zcouy_tb-countryname ,
d_minname TYPE zcouy_tb-countryname ,
d_cityid TYPE zcouy_tb-cityid ,
num TYPE i .
SELECT countryid MAX( countryname ) AS max MIN( countryname ) COUNT( *
)
cityid
INTO (d_countryid ,d_maxname , d_minname ,num, d_cityid)
FROM zcouy_tb
GROUP BY countryid cityid
HAVING COUNT( * ) > 0
ORDER BY max DESCENDING .
WRITE : / d_countryid,d_maxname,d_minname,num,d_cityid .
ENDSELECT .