If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > cobol cursor error

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-11-11, 17:16
nexuz nexuz is offline
Registered User
 
Join Date: Apr 2011
Posts: 7
cobol cursor error

hi all!

I'm currently working on a cobol program for school.
The purpose is that it checks absences from students, without a certificate (for example: a doctor's note).
Now I have programmed a cursor that queries all absent records of a particular student, I open my cursor and fetch it, the first fetch does everything right but the second time I fetch, it returns SQLCODE = -000001.

I can't find any explanation about this error code, maybe one of you can help me out...?

Code:
          EXEC SQL DECLARE absent_without_certificate_cursor CURSOR FOR
            SELECT a.idabsent,a.from_date,a.to_date
            FROM absences a
            WHERE idstudent = :idstudent_db AND 
            0 = (SELECT COUNT(*) FROM certificates c
            WHERE c.idabsent = a.idabsent)
          END-EXEC
ps: At school we use Legacy perCobol ide for programming in cobol.
Reply With Quote
  #2 (permalink)  
Old 04-11-11, 18:17
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
It would help if you post (or attach) your entire program.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 04-12-11, 05:56
nexuz nexuz is offline
Registered User
 
Join Date: Apr 2011
Posts: 7
Yeah, I could do that but its entirly written in dutch ^^
this is the paragraph were it wents wrong:

Code:
 get_absences_without_certificate.
          EXEC SQL 
            OPEN absent_without_certificate_cursor
          END-EXEC
           
          
         EXEC SQL 
            FETCH absent_without_certificate_cursor
            INTO :idabsent_db,:from_date_db,:to_date_db
          END-EXEC

          
          display "first time fetch: " SQLCODE
          accept stoper
         
          IF SQLCODE = 100
            MOVE 0 TO absent_without_certificate_counter          
          END-IF
            
          PERFORM UNTIL SQLCODE = 100
            PERFORM determine_difference_between_absent_date_and_current_date
            IF difference_between_absent_date_and_current_date > CONSTANT_DAYS
               PERFORM mark_absent_as_illigal
             END-IF

 
         EXEC SQL 
            FETCH absent_without_certificate_cursor
            INTO :idabsent_db,:from_date_db,:to_date_db
          END-EXEC


         display "after first time: " SQLCODE
         accept stoper

          END-PERFORM

          EXEC SQL 
            CLOSE absent_without_certificate_cursor
          END-EXEC      
          .
After the green fetch the SQLCODE is 000000, but after the red fetch the SQLCODE is -000001. in my database I have 2 absent records for this student, but even if there were no absent records in the database, why isn't my SQLCODE not 100?

Last edited by nexuz; 04-12-11 at 06:00.
Reply With Quote
  #4 (permalink)  
Old 04-12-11, 06:09
nexuz nexuz is offline
Registered User
 
Join Date: Apr 2011
Posts: 7
I have also a student_cursor that gets all the students from the database

Code:
          EXEC SQL DECLARE students_cursor CURSOR FOR
            SELECT idperson,firstname,lasname
            FROM person            
            WHERE idtypeperson like "student"
          END-EXEC
when I fetch this cursor, nothing wents wrong, at the end SQLCODE becomes 100.

So, I don't understand why my absent_without_certificate cursor doesn't work, maybe it is the sub-query I used, but that would be strange because I tested the query in mysql.
I really need some help with this, if this problem is solved, than my program is ready
Reply With Quote
  #5 (permalink)  
Old 04-12-11, 06:43
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Are there still schools where they teach cobol+SQL? GOOD NEWS
You tested your query in mysql and you access db2 from your cobol program? How do you pre-compile/compile and link? a return code of 1 indicates problems in that direction.
I would advice you to limit the length of you cursor names. Maybe it will work on the newer versions of the software, but later in practice you will only find short code-like cursornames. Better get used to it.
Reply With Quote
  #6 (permalink)  
Old 04-12-11, 07:16
nexuz nexuz is offline
Registered User
 
Join Date: Apr 2011
Posts: 7
The length of my cursor names got a little bit longer by translating them into English .

I use the PERcobol ide of LegacyJ, it compiles the cobol source-code to java source-code so basically it isn't really cobol anymore.

But I find it kinda strange, all my other cursors don't have this problem, also I have never had such a problem(s) with cursors and finally it is strange that the first fetch of my cursor does do the right thing
*the idabsent_db,
*the from_date_db
*the to_date_db
variables are all containing the correct values as in the database.
Only at the moment the second fetch starts fetching it goes wrong, the fetch returns a SQLCODE -000001 and my program is getting in a timeless loop.

On the internet I can't find anything about this error code -000001
Reply With Quote
  #7 (permalink)  
Old 04-12-11, 16:55
nexuz nexuz is offline
Registered User
 
Join Date: Apr 2011
Posts: 7
hi, problem solved in further in my program I did an update to the database and imediately I did a commit, now according to cobol you can't do a commit while you are fetching, I placed my my commit statement outside de perform loop and now everything works correctly.

thanks for the replies!
Reply With Quote
  #8 (permalink)  
Old 04-13-11, 00:35
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,198
You may want to try defining the cursor using the WITH HOLD option. This allows you to do a commit without closing the cursor (doing intermediate commits is usually a good idea to decrease lock contention). But not sure if that is supported in your PERcobol ide of LegacyJ environment.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #9 (permalink)  
Old 04-13-11, 05:02
nexuz nexuz is offline
Registered User
 
Join Date: Apr 2011
Posts: 7
nope its not supported by PERcobol, thanks anyway for the tip
Reply With Quote
  #10 (permalink)  
Old 04-14-11, 06:15
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
Quote:
Originally Posted by nexuz View Post
I use the PERcobol ide of LegacyJ, it compiles the cobol source-code to java source-code so basically it isn't really cobol anymore.
So you do not use the db2 precompiler (db2prep)? What happens to your EXEC SQL lines? Are they converted to JDBC? Just out of interest: I'd like to see a piece of the generated java code please.
Reply With Quote
  #11 (permalink)  
Old 04-14-11, 10:46
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Exclamation DB2 made easy !

Why do not make easy change to the cursor ?

Code:
EXEC SQL DECLARE absent_without_certificate_cursor 
            CURSOR FOR
        SELECT a.idabsent,a.from_date,a.to_date
        FROM absences a  
        Where  WHERE idstudent = :idstudent_db 
                  AND not exists            
                (SELECT  1  FROM certificates c
                   WHERE    c.idabsent = a.idabsent ) 
END-EXEC
Lenny

Last edited by Lenny77; 04-14-11 at 11:22.
Reply With Quote
  #12 (permalink)  
Old 04-14-11, 16:12
nexuz nexuz is offline
Registered User
 
Join Date: Apr 2011
Posts: 7
Quote:
Originally Posted by dr_te_z View Post
So you do not use the db2 precompiler (db2prep)? What happens to your EXEC SQL lines? Are they converted to JDBC? Just out of interest: I'd like to see a piece of the generated java code please.
Yes it generates a preparedStatement in java code en executes that
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On