SQL 的正确语法是什么?
What is the proper syntax for SQL?
我正在尝试在 ABAP 中创建一个 SQL 语句来选择多个字段,但无法找出正确的语法。
这是我正在做的,但产生了一个错误:
SELECT field1, field2
FROM table INTO txtbox
WHERE field3 = txtInput.
ENDSELECT.
所有字段都在同一个 table 中。
首先,您尝试将 2 个字段 select 放入 1 个变量中。这是你想要达到的目标吗? txtbox是结构体吗?
其次,与语法相关 - 根据 ABAP 版本,您应该编写其中之一
SELECT field1, field2
FROM table INTO @txtbox
WHERE field3 = @txtInput.
ENDSELECT.
或
SELECT field1 field2
FROM table INTO txtbox
WHERE field3 = txtInput.
ENDSELECT.
语法可能取决于 ABAP 的版本。
您的问题可能是由于错误声明/选择要查询的变量造成的。
一些示例:
*Select all fields of a SAP database table into in internal table
SELECT *
FROM ekko
INTO TABLE it_ekko.
*Select directly into an internal table
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO TABLE it_bseg.
* Select directly into an internal table where fields are in a
* different order or not all fields are specified
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO CORRESPONDING FIELDS OF TABLE it_bseg.
*Select... endselect command (to structure)
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO wa_bseg.
APPEND wa_bseg TO it_bseg.
ENDSELECT.
*Select FOR ALL ENTRIES command
SELECT bukrs belnr gjahr bldat monat budat xblnr awtyp awkey
UP TO 100 ROWS
FROM bkpf
INTO TABLE it_bkpf.
IF sy-subrc EQ 0.
* The FOR ALL ENTRIES comand only retrieves data which matches
* entries within a particular internal table.
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO TABLE it_bseg
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs EQ it_bkpf-bukrs AND
belnr EQ it_bkpf-belnr AND
gjahr EQ it_bkpf-gjahr.
ENDIF.
我正在尝试在 ABAP 中创建一个 SQL 语句来选择多个字段,但无法找出正确的语法。
这是我正在做的,但产生了一个错误:
SELECT field1, field2
FROM table INTO txtbox
WHERE field3 = txtInput.
ENDSELECT.
所有字段都在同一个 table 中。
首先,您尝试将 2 个字段 select 放入 1 个变量中。这是你想要达到的目标吗? txtbox是结构体吗?
其次,与语法相关 - 根据 ABAP 版本,您应该编写其中之一
SELECT field1, field2
FROM table INTO @txtbox
WHERE field3 = @txtInput.
ENDSELECT.
或
SELECT field1 field2
FROM table INTO txtbox
WHERE field3 = txtInput.
ENDSELECT.
语法可能取决于 ABAP 的版本。
您的问题可能是由于错误声明/选择要查询的变量造成的。
一些示例:
*Select all fields of a SAP database table into in internal table
SELECT *
FROM ekko
INTO TABLE it_ekko.
*Select directly into an internal table
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO TABLE it_bseg.
* Select directly into an internal table where fields are in a
* different order or not all fields are specified
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO CORRESPONDING FIELDS OF TABLE it_bseg.
*Select... endselect command (to structure)
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO wa_bseg.
APPEND wa_bseg TO it_bseg.
ENDSELECT.
*Select FOR ALL ENTRIES command
SELECT bukrs belnr gjahr bldat monat budat xblnr awtyp awkey
UP TO 100 ROWS
FROM bkpf
INTO TABLE it_bkpf.
IF sy-subrc EQ 0.
* The FOR ALL ENTRIES comand only retrieves data which matches
* entries within a particular internal table.
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
dmbtr mwart hwbas aufnr projk shkzg kokrs
FROM bseg
INTO TABLE it_bseg
FOR ALL ENTRIES IN it_bkpf
WHERE bukrs EQ it_bkpf-bukrs AND
belnr EQ it_bkpf-belnr AND
gjahr EQ it_bkpf-gjahr.
ENDIF.