Skip to main content

Can't access data when selecting records using embedded SQL in COBOL code

  • August 9, 2017
  • 3 replies
  • 0 views

 I am adding the following SQL to my COBOL program.  It returns ZEROES as the SQLCODE, but does not put the fields in my COBOL fields so that I can use them in my program.  

 

EXEC SQL
SELECT TOP 1
"CourtEventNo"
,"CrtCaseDefNo"
,"EventDate"
,"EventTime"
,"FineAmount"
,"DeleteInd"
FROM "CR_DefFineCase"
INTO
:J0901-CourtEventNo
,:J0901-CrtCaseDefNo
,:J0901-EventDate
,:J0901-EventTime
,:J0901-FineAmount
,:J0901-DeleteInd
WHERE "CrtCaseDefNo" = :WS-CRTCASE AND
"DeleteInd" = 'N'
ORDER BY
"EventDate" DESC
,"EventTime" DESC
,"CR_DefFineCaseSID" DESC
END-EXEC.

Our configuration

Studio Enterprise Edition 6.0    Platform Net Express       Database is MS SQLServer

 

We have 37 new tables for this project.  Can access tables by primary keys (SIDS), but all access using Alternate keys has been problematic.  This is the code from the first table which I have tried using both the middle tier software to access and embedded SQL.  Both return a SQLCODE value of zero, but no values in the fields declared in the INTO variables.  The second table I tried to access using embedded SQL with a cursor.  It works until it gets to the FETCH statement and then it bombs with a nonsensical error.


#EnterpriseDeveloper

3 replies

Chris Glazier
Forum|alt.badge.img+2
  • Moderator
  • 3696 replies
  • August 9, 2017

 I am adding the following SQL to my COBOL program.  It returns ZEROES as the SQLCODE, but does not put the fields in my COBOL fields so that I can use them in my program.  

 

EXEC SQL
SELECT TOP 1
"CourtEventNo"
,"CrtCaseDefNo"
,"EventDate"
,"EventTime"
,"FineAmount"
,"DeleteInd"
FROM "CR_DefFineCase"
INTO
:J0901-CourtEventNo
,:J0901-CrtCaseDefNo
,:J0901-EventDate
,:J0901-EventTime
,:J0901-FineAmount
,:J0901-DeleteInd
WHERE "CrtCaseDefNo" = :WS-CRTCASE AND
"DeleteInd" = 'N'
ORDER BY
"EventDate" DESC
,"EventTime" DESC
,"CR_DefFineCaseSID" DESC
END-EXEC.

Our configuration

Studio Enterprise Edition 6.0    Platform Net Express       Database is MS SQLServer

 

We have 37 new tables for this project.  Can access tables by primary keys (SIDS), but all access using Alternate keys has been problematic.  This is the code from the first table which I have tried using both the middle tier software to access and embedded SQL.  Both return a SQLCODE value of zero, but no values in the fields declared in the INTO variables.  The second table I tried to access using embedded SQL with a cursor.  It works until it gets to the FETCH statement and then it bombs with a nonsensical error.


#EnterpriseDeveloper
What version of SQL Server are you running and what is the name and the version number of the ODBC driver that you are using?

  • Author
  • Rocketeer
  • 19312 replies
  • August 9, 2017

 I am adding the following SQL to my COBOL program.  It returns ZEROES as the SQLCODE, but does not put the fields in my COBOL fields so that I can use them in my program.  

 

EXEC SQL
SELECT TOP 1
"CourtEventNo"
,"CrtCaseDefNo"
,"EventDate"
,"EventTime"
,"FineAmount"
,"DeleteInd"
FROM "CR_DefFineCase"
INTO
:J0901-CourtEventNo
,:J0901-CrtCaseDefNo
,:J0901-EventDate
,:J0901-EventTime
,:J0901-FineAmount
,:J0901-DeleteInd
WHERE "CrtCaseDefNo" = :WS-CRTCASE AND
"DeleteInd" = 'N'
ORDER BY
"EventDate" DESC
,"EventTime" DESC
,"CR_DefFineCaseSID" DESC
END-EXEC.

Our configuration

Studio Enterprise Edition 6.0    Platform Net Express       Database is MS SQLServer

 

We have 37 new tables for this project.  Can access tables by primary keys (SIDS), but all access using Alternate keys has been problematic.  This is the code from the first table which I have tried using both the middle tier software to access and embedded SQL.  Both return a SQLCODE value of zero, but no values in the fields declared in the INTO variables.  The second table I tried to access using embedded SQL with a cursor.  It works until it gets to the FETCH statement and then it bombs with a nonsensical error.


#EnterpriseDeveloper

SQL Server is 2008 R2 Service Pack 2.   ODBC is ODBC Driver 13 for SQL Server Version 2015.130.1601.05  Microsoft Corp  File MSODBCSQL13


  • Author
  • Rocketeer
  • 19312 replies
  • August 9, 2017

 I am adding the following SQL to my COBOL program.  It returns ZEROES as the SQLCODE, but does not put the fields in my COBOL fields so that I can use them in my program.  

 

EXEC SQL
SELECT TOP 1
"CourtEventNo"
,"CrtCaseDefNo"
,"EventDate"
,"EventTime"
,"FineAmount"
,"DeleteInd"
FROM "CR_DefFineCase"
INTO
:J0901-CourtEventNo
,:J0901-CrtCaseDefNo
,:J0901-EventDate
,:J0901-EventTime
,:J0901-FineAmount
,:J0901-DeleteInd
WHERE "CrtCaseDefNo" = :WS-CRTCASE AND
"DeleteInd" = 'N'
ORDER BY
"EventDate" DESC
,"EventTime" DESC
,"CR_DefFineCaseSID" DESC
END-EXEC.

Our configuration

Studio Enterprise Edition 6.0    Platform Net Express       Database is MS SQLServer

 

We have 37 new tables for this project.  Can access tables by primary keys (SIDS), but all access using Alternate keys has been problematic.  This is the code from the first table which I have tried using both the middle tier software to access and embedded SQL.  Both return a SQLCODE value of zero, but no values in the fields declared in the INTO variables.  The second table I tried to access using embedded SQL with a cursor.  It works until it gets to the FETCH statement and then it bombs with a nonsensical error.


#EnterpriseDeveloper

SQL Server is 2008 R2 Service Pack 2.   ODBC is ODBC Driver 13 for SQL Server Version 2015.130.1601.05  Microsoft Corp  File MSODBCSQL13