MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Open and fetch SQL cursor

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 625
Topics: 175
Location: Stockholm, Sweden

PostPosted: Wed Jun 24, 2020 7:32 am    Post subject: Open and fetch SQL cursor Reply with quote

I've seen two basic coding examples of the above. One is to do a perform of the OPEN cursor section, followed by a perform on the FETCH cursor section.

I've also seen an example where the user does a perform on the FETCH section, which in turn contains a test for a "has the cursor been opened yet, if not, then FIRST open the cursor", THEN do the FETCH.

What does it look like in your installations?

(Personally, I think the second example is an abomination, but that's my taste)
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12369
Topics: 75
Location: San Jose

PostPosted: Wed Jun 24, 2020 2:30 pm    Post subject: Reply with quote

misi01,

The standard should ALWAYS be
Code:

OPEN
FETCH
CLOSE

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
haatvedt
Beginner


Joined: 14 Nov 2003
Posts: 66
Topics: 0
Location: St Cloud, Minnesota USA

PostPosted: Wed Jun 24, 2020 4:11 pm    Post subject: Reply with quote

Code:
PERFORM 100-OPEN-CURSOR THRU 100-EXIT.

PERFORM WITH TEST AFTER UNTIL SQLCODE NOT EQUAL ZERO
    PERFORM 200-FETCH-CURSOR THRU 200-EXIT
END-PERFORM.

IF SQLCODE NOT EQUAL +100
    PERFORM 8000-DSNTIAR-ERROR THRU 8000-EXIT
    GO TO ABEND-ROUTINE
END-IF.

PERFORM 300-CLOSE-CURSOR THRU 300-EXIT.

_________________
Chuck Haatvedt

email --> clastnameatcharterdotnet

(replace lastname, at, dot with appropriate
characters)
Back to top
View user's profile Send private message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 625
Topics: 175
Location: Stockholm, Sweden

PostPosted: Thu Jun 25, 2020 12:39 am    Post subject: Reply with quote

Chuck. Your code example is interesting inasmuch as I've NEVER seen anyone here in Sweden code "perform ....... thru ......"

People here ONLY code a simple "perform ......".

Not sure if that's because people here write the code as something like

WA-OPEN-CSR100 SECTION.
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
haatvedt
Beginner


Joined: 14 Nov 2003
Posts: 66
Topics: 0
Location: St Cloud, Minnesota USA

PostPosted: Fri Jun 26, 2020 4:49 pm    Post subject: Reply with quote

Michael,

This is not to start a flame war about coding styles. I've always found that organizations produce better code if they have some coding standards and attempt to adhere to them.

I started coding professionally in 1978, the first IBM shop that I worked at had a standard that all PERFORM verbs must include the THRU option. Also GO TO statements were allowed but only to the EXIT of the current paragraph. SECTION's were to be avoided except for internal SORT INPUT / OUTPUT PROCEDURES (at the time, that was required but not so any longer).

I have encountered programs which mixed coding styles, some PERFORM's / some PERFORM THRU's / and some GO TO statements. That lead to some very challenging maintenance issues.

So what ever style / coding convention is used by your employer, I would recommend that it should be adhered to.
_________________
Chuck Haatvedt

email --> clastnameatcharterdotnet

(replace lastname, at, dot with appropriate
characters)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group