SAP Native SQL
1、 Native SQL语句的执行,都是在EXEC和ENDEXEC之间,里面的SQL语句,语法检查不够完善,在他们书写的SQL语句,语法规则是由数据库系统决定的,例如Oracle和DB2等会有所差别。另外需要注意的是,所有的native SQL语句都绕过SAP buffering(缓存)。
2、 EXEC SQL [PERFORMING subr].
...
...
ENDEXEC.
当没有使用扩展的参数performing的时候,sy-subrc的返回码为0(成功)和4(失败)。
当使用performing参数的时候,会激活隐性游标处理,使sy-subrc返回码总是为4.
另一个可用的系统字段为是sy-dbcnt,为native SQL处理的表行数。
Note:当使用扩展参数performing的时候,在exec和endexec之间仅能使用一条select语句,在类中禁用此扩展参数,每次SQL语句成功读取一条数据后,都会调用子例程subr一次,并且
子例程subr不能有任何引用传递的参数。
示例①
DATA wa TYPE spfli-carrid.
EXEC SQL PERFORMING evaluate.
SELECT carrid FROM spfliINTO :wa
ENDEXEC.
FORM evaluate.
WRITE / wa.
ENDFORM.
EXEC SQL PERFORMING evaluate.
SELECT carrid FROM spfliINTO :wa
ENDEXEC.
FORM evaluate.
WRITE / wa.
ENDFORM.
示例②
DATA: exc_ref TYPE REF TO cx_sy_native_sql_error,
error_text TYPE string.
error_text TYPE string.
TRY.
EXEC SQL.
INSERT INTO scarr
(MANDT, CARRID, CARRNAME, CURRCODE, URL)
VALUES ('000', 'FF', 'Funny Flyers', 'EUR',
'www.ff');
INSERT INTO scarr
(MANDT, CARRID, CARRNAME, CURRCODE, URL)
VALUES ('000', 'EF', 'Easy Flyers', 'EUR',
'www.ef');
ENDEXEC.
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY.
EXEC SQL.
INSERT INTO scarr
(MANDT, CARRID, CARRNAME, CURRCODE, URL)
VALUES ('000', 'FF', 'Funny Flyers', 'EUR',
'www.ff');
INSERT INTO scarr
(MANDT, CARRID, CARRNAME, CURRCODE, URL)
VALUES ('000', 'EF', 'Easy Flyers', 'EUR',
'www.ef');
ENDEXEC.
CATCH cx_sy_native_sql_error INTO exc_ref.
error_text = exc_ref->get_text( ).
MESSAGE error_text TYPE 'I'.
ENDTRY.
3、 可捕获的异常
CX_SY_NATIVE_SQL_ERROR
4、 SAP 特有的native SQL
Host variables
PARAMETERS: p_carrid TYPE spfli-carrid,
p_connid TYPE spfli-connid.
DATA: BEGIN OF wa,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
END OF wa.
EXEC SQL.
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto,
END OF wa.
EXEC SQL.
SELECT cityfrom, cityto
INTO :wa
FROM spfli
WHERE carrid = :p_carrid AND connid = :p_connid
ENDEXEC.
INTO :wa
FROM spfli
WHERE carrid = :p_carrid AND connid = :p_connid
ENDEXEC.
Statements for cursor processing
PARAMETERS p_carrid TYPE spfli-carrid.
DATA: connid TYPE spfli-connid,
cityfrom TYPE spfli-cityfrom,
cityto TYPE spfli-cityto.
EXEC SQL.
OPEN dbcur FOR
OPEN dbcur FOR
SELECT connid, cityfrom, cityto
FROM spfli
db2数据库sql语句WHERE carrid= :p_carrid
ENDEXEC.
DO.
EXEC SQL.
FETCH NEXT dbcurINTO :connid, :cityfrom, :cityto
ENDEXEC.
IF sy-subrc<> 0.
EXIT.
ELSE.
...
ENDIF.
ENDDO.
FROM spfli
db2数据库sql语句WHERE carrid= :p_carrid
ENDEXEC.
DO.
EXEC SQL.
FETCH NEXT dbcurINTO :connid, :cityfrom, :cityto
ENDEXEC.
IF sy-subrc<> 0.
EXIT.
ELSE.
...
ENDIF.
ENDDO.
EXEC SQL.
CLOSE dbcur
ENDEXEC.
Database procedure calls
参考帮助文档EXEC SQL - EXECUTE
Statements for establishing database connections
参考帮助文档EXEC SQL – CONNECT
5、 ORACLE数据库语法(双击打开)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论