View previous topic :: View next topic |
Author |
Message |
misi01 Advanced
Joined: 02 Dec 2002 Posts: 629 Topics: 176 Location: Stockholm, Sweden
|
Posted: Wed Jun 24, 2020 7:32 am Post subject: Open and fetch SQL cursor |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Wed Jun 24, 2020 2:30 pm Post subject: |
|
|
misi01,
The standard should ALWAYS be
_________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
|
haatvedt Beginner
Joined: 14 Nov 2003 Posts: 66 Topics: 0 Location: St Cloud, Minnesota USA
|
Posted: Wed Jun 24, 2020 4:11 pm Post subject: |
|
|
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 |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 629 Topics: 176 Location: Stockholm, Sweden
|
Posted: Thu Jun 25, 2020 12:39 am Post subject: |
|
|
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 |
|
|
haatvedt Beginner
Joined: 14 Nov 2003 Posts: 66 Topics: 0 Location: St Cloud, Minnesota USA
|
Posted: Fri Jun 26, 2020 4:49 pm Post subject: |
|
|
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 |
|
|
|
|