ABAP 原生 SQL 游标
我正在尝试在 abap 中编写一些本机 SQL,但遇到了一些问题。
这是我的代码:
method GET_SOMEDATA.
DATA: lt_table TYPE TABLE OF /BI0/TCUSTOMER,
c1 TYPE /BI0/TCUSTOMER.
DATA: BEGIN OF wa,
customer TYPE /BI0/OICUSTOMER,
txtsh TYPE RSTXTSH,
txtmd TYPE RSTXTMD,
txtlg TYPE RSTXTLG,
END OF wa.
EXEC SQL.
OPEN c1 FOR
SELECT * FROM /BI0/TCUSTOMER
WHERE customer LIKE '229'.
ENDEXEC.
DO.
EXEC SQL.
FETCH NEXT c1 INTO :wa-customer, :wa-txtmd
* ERROR: CX_SY_NATIVE_SQL_ERROR
ENDEXEC.
IF sy-subrc = 0.
* <process data>
ENDIF.
ENDDO.
EXEC SQL.
CLOSE c1
ENDEXEC.
endmethod.
调用后 “将下一个 c1 提取到:wa-customer,:wa-txtmd” 我收到“CX_SY_NATIVE_SQL_ERROR” - 我猜我的光标有问题 - 但我不知道。一些帮助会很棒。
I'm trying to write some native SQL in abap but got some problems.
Here's my code:
method GET_SOMEDATA.
DATA: lt_table TYPE TABLE OF /BI0/TCUSTOMER,
c1 TYPE /BI0/TCUSTOMER.
DATA: BEGIN OF wa,
customer TYPE /BI0/OICUSTOMER,
txtsh TYPE RSTXTSH,
txtmd TYPE RSTXTMD,
txtlg TYPE RSTXTLG,
END OF wa.
EXEC SQL.
OPEN c1 FOR
SELECT * FROM /BI0/TCUSTOMER
WHERE customer LIKE '229'.
ENDEXEC.
DO.
EXEC SQL.
FETCH NEXT c1 INTO :wa-customer, :wa-txtmd
* ERROR: CX_SY_NATIVE_SQL_ERROR
ENDEXEC.
IF sy-subrc = 0.
* <process data>
ENDIF.
ENDDO.
EXEC SQL.
CLOSE c1
ENDEXEC.
endmethod.
After calling
"FETCH NEXT c1 INTO :wa-customer, :wa-txtmd"
I'm getting an "CX_SY_NATIVE_SQL_ERROR" - I guesse something with my cursor is not ok - but I have no idea. Some help would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
规则 1:不要使用本机 SQL。
规则 2:不要使用本机 SQL。
规则 3:不要使用本机 SQL。
...
规则 n:不要使用本机 SQL。
规则n+1:说真的,不要。
规则 n+2:如果确实需要,请记住您必须手动指定客户端。
规则 n+3:不要在 Native SQL 中使用 SELECT *,始终按名称专门选择字段。原因:您无法 FETCH ... INTO CORRESPONDING FieldS,但必须注意目标字段的序列、数字和数据类型是否匹配。如果您的表 /BI0/TCUSTOMER 不仅包含两个类型为 /BI0/OICUSTOMER 和 RSTXTMD 的字段,那么这很可能是导致异常的原因。
Rule 1: Don't use Native SQL.
Rule 2: Don't use Native SQL.
Rule 3: Don't use Native SQL.
...
Rule n: Don't use Native SQL.
Rule n+1: Seriously, don't.
Rule n+2: If you really have to, remember you'll have to specify the client manually.
Rule n+3: Don't use SELECT * in Native SQL, always select the fields specifically by name. Reason: You can't FETCH ... INTO CORRESPONDING FIELDS but have to take care that the sequence, number and data types of the target fields match. If your table /BI0/TCUSTOMER does not only consist of two fields typed as /BI0/OICUSTOMER and RSTXTMD, that's most probably the cause for the exception.