OpenSQL 与列之间的比较
OpenSQL with comparison between columns
我可以在 OpenSQL 中比较 table 的列吗?
目前代码如下所示:
SELECT SINGLE menge wemng ebeln ebelp
INTO (eket-menge,
eket-wemng,
eket-ebeln,
eket-ebelp)
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp.
IF eket-menge NE eket-wemng.
我想避免检索 menge = wemng
处的行,但这不起作用:
SELECT menge wemng ebeln ebelp
INTO (eket-menge,
eket-wemng,
eket-ebeln,
eket-ebelp)
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp
AND menge <> wemng.
ABAP 认为 wemng
应该是一个变量。
我该怎么做?
请检查以下查询:
SELECT menge wemng ebeln ebelp
INTO (eket-menge,
eket-wemng,
eket-ebeln,
eket-ebelp)
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp
AND menge <> eket~wemng.
但是此时你得到错误:
Incorrect nesting: Before the statement "ENDIF", the control structure introduced by "SELECT" must be concluded with "ENDSELECT".
所以你应该创建一些内部 table 来处理这个
SELECT menge wemng ebeln ebelp
INTO TABLE lt_eket
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp
AND menge <> eket~wemng.
或使用SELECT SINGLE
SELECT SINGLE menge wemng ebeln ebelp
INTO (eket-menge,
eket-wemng,
eket-ebeln,
eket-ebelp)
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp
AND menge <> eket~wemng.
在 WHERE 条件下比较两列时,您应该使用列选择器 (~)。这是设计使然。
ABAPDOCU 说:
Column selector
Character ~. A column (col) of a database table (dbtab) can be
addressed in a SELECT statement by means of dbtab~col. This type of
addressing is necessary when multiple database tables are accessed if
the name of a column occurs in a number of different database tables
or if two columns are compared with each other in a comparison in the
WHERE condition.
所以,在你的情况下:
SELECT menge wemng ebeln ebelp
INTO (eket-menge,
eket-wemng,
eket-ebeln,
eket-ebelp)
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp
AND menge <> eket~wemng.
...
我可以在 OpenSQL 中比较 table 的列吗?
目前代码如下所示:
SELECT SINGLE menge wemng ebeln ebelp
INTO (eket-menge,
eket-wemng,
eket-ebeln,
eket-ebelp)
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp.
IF eket-menge NE eket-wemng.
我想避免检索 menge = wemng
处的行,但这不起作用:
SELECT menge wemng ebeln ebelp
INTO (eket-menge,
eket-wemng,
eket-ebeln,
eket-ebelp)
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp
AND menge <> wemng.
ABAP 认为 wemng
应该是一个变量。
我该怎么做?
请检查以下查询:
SELECT menge wemng ebeln ebelp
INTO (eket-menge,
eket-wemng,
eket-ebeln,
eket-ebelp)
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp
AND menge <> eket~wemng.
但是此时你得到错误:
Incorrect nesting: Before the statement "ENDIF", the control structure introduced by "SELECT" must be concluded with "ENDSELECT".
所以你应该创建一些内部 table 来处理这个
SELECT menge wemng ebeln ebelp
INTO TABLE lt_eket
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp
AND menge <> eket~wemng.
或使用SELECT SINGLE
SELECT SINGLE menge wemng ebeln ebelp
INTO (eket-menge,
eket-wemng,
eket-ebeln,
eket-ebelp)
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp
AND menge <> eket~wemng.
在 WHERE 条件下比较两列时,您应该使用列选择器 (~)。这是设计使然。
ABAPDOCU 说:
Column selector
Character ~. A column (col) of a database table (dbtab) can be addressed in a SELECT statement by means of dbtab~col. This type of addressing is necessary when multiple database tables are accessed if the name of a column occurs in a number of different database tables or if two columns are compared with each other in a comparison in the WHERE condition.
所以,在你的情况下:
SELECT menge wemng ebeln ebelp
INTO (eket-menge,
eket-wemng,
eket-ebeln,
eket-ebelp)
FROM eket
WHERE ebeln = ekpo-ebeln
AND ebelp = ekpo-ebelp
AND menge <> eket~wemng.
...