A COBOL program using Datacom SELECT INTO SQL statement is getting syntax errors in COBOL preprocessor DBXMMPR:
EXEC SQL
SELECT ORG
,ORG_ID
,BOOK_ID
INTO :C-ORG
,:C-ORG-ID
,:C-BOOK-ID
FROM CDE
WHERE ORG = :C-ORG
ORDER BY ORG DESC
FETCH FIRST 1 ROW ONLY
END-EXEC.
Error message:
DB21012E ---- PREPARE STATEMENT FAILED (QHOST)
BAD SYNTAX: <CDE WHERE ORG = :C-ORG ORDER >
SQLCA-SQLCODE = -20
SQLCA-SQLSTATE = 42601
Release : 15.1
Component : DATACOM SQL
The SELECT INTO statement is only meant to return one row so the ORDER BY and FETCH clauses are not valid syntax.
Removing the two clauses resolves the syntax error.
See the Datacom documentation section Select-Into Statement