SAP ABAP中的游标用法
2018-11-09 本文已影响69人
df6e4e8a0635
更多内容请关注公众号:SAP Technical
*"Native SQL语句不能以句点号结尾;
*"不能在EXEC SQL…ENDEXEC间有注释,即不能有星号与双引号的出现;
*"参数占位符使用冒号,而不是问号;
DATA: ARG1 TYPE STRING VALUE '300'.
TABLES: T001.
"打开游标
EXEC SQL.
OPEN c1 FOR SELECT MANDT, BUKRS FROM T001
WHERE MANDT = :arg1 AND BUKRS >= '1001' and bukrs <= '1999'
ENDEXEC.
"读取游标
DO.
EXEC SQL.
FETCH NEXT c1 INTO :t001-mandt, :t001-bukrs
ENDEXEC.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
WRITE: / T001-MANDT, T001-BUKRS.
ENDIF.
ENDDO.
"关闭游标
EXEC SQL.
CLOSE c1
ENDEXEC.