Thursday, December 20, 2007

Avoid nested SELECT-ENDSELECT loops

Nested selects and loops are avoided through the use of dictionary VIEWs, ABAP joins or by using the FOR ALL ENTRIES addition in the SELECT statement.

---------------------------AVOID-------------------------
SELECT *
FROM sflight
INTO xflight
WHERE planetype = '727-200'.

SELECT *
FROM sbook
INTO xbook
WHERE carrid = xflight-carrid
AND connid = xflight-connid
AND fldate = xsflight-fldate.

WRITE: / xflight-carrid,
xflight-connid,
xbook-bookid.

ENDSELECT.
ENDSELECT.

---------------------------USE-------------------------
SELECT f~carrid
f~connid
b~bookid
INTO (xcarrid, xconnid, xbookid)
FROM sflight
AS f INNER JOIN sbook AS b
ON f~carrid = b~carrid
AND f~connid = b~connid
AND f~fldate = b~fldate
WHERE planetype = '727-200'.

WRITE: / xcarrid,
xconnid,
xbookid.
ENDSELECT.

No comments:

Blog Archive