ABAP Workbench中SQL的正确语法是什么?

时间:2016-07-22 14:19:58

标签: sql sap abap

我试图在ABAP中创建一个SQL语句,它选择多个字段,但无法找出适当的语法。

这就是我所做的,它产生了一个错误:

SELECT field1, field2
  FROM table INTO txtbox
  WHERE field3 = txtInput. 
ENDSELECT.

所有字段都在同一个表中。

2 个答案:

答案 0 :(得分:2)

首先,您尝试将2个字段选择为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.

答案 1 :(得分:0)

语法可能取决于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.