IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Does this code work as intended - Cursor


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Sat Nov 29, 2008 4:10 pm
Reply with quote

Hi,

I have found below code and not able to understand if it works as the way it was written ! Would you please explain if it needs to be corrected?

Code:

WORKING-STORAGE SECTION.
01  WS-PROCESS-YEAR-TABLE.                                                   
    05  WS-PRYR-TABLE.                                           
        10  WS-PRYR-TBL           OCCURS 20 TIMES     
                                  INDEXED BY WS-PRYR-IDX.
            15  WS-TBL-PRYR-YR    PIC X(04).           
            15  WS-TBL-PRYR-ID    PIC X(01).           

01 WS-PRYR-YR                     PIC X(04).
01 WS-PRYR-ID                     PIC X(04).

01 C-MAX-PRYR-VALUE               PIC S9(03) COMP-3 VALUE +20.

***** PRYR-CURSOR *****                           
     EXEC SQL                             
         DECLARE PRYRCURS CURSOR FOR       
          SELECT PRYR_NBR,PRYR_ID             
            FROM PRODDB.PRYR_DB         
           WHERE PRYR_NBR <> SPACE
           ORDER BY PRYR_ID,PRYR_NBR     
     END-EXEC                             

.
.

1000-LOAD-PRYR.                         
                                           
    PERFORM 1100-OPEN-PRYRCURS               
    PERFORM 1200-FETCH-PRYRCURS             
       VARYING WS-PRYR-IDX FROM +1 BY +1
         UNTIL WS-NO-MORE-PRYR       
    PERFORM 1300-CLOSE-PRYRCURS.             

.
.

1100-OPEN-PRYRCURS.                           
                                             
    EXEC SQL                                 
        OPEN PRYRCURS                         
    END-EXEC.                                 
                                             
    IF SQLCODE = +0                           
        CONTINUE                             
    ELSE                                     
        DISPLAY 'PRYRCURS - OPEN FAILED' 
    END-IF.
.
.

1200-FETCH-PRYRCURS.                                             
                                                                 
    EXEC SQL                                                     
        FETCH PRYRCURS                                           
         INTO :WS-PRYR-YR,                                   
              :WS-PRYR-ID                               
    END-EXEC.                                                   
                                                                 
    IF SQLCODE = +0                                             
        IF WS-PRYR-IDX > C-MAX-PRYR-VALUE                               
             CONTINUE                                           
        ELSE                                                     
            MOVE WS-PRYR-YR   TO WS-TBL-PRYR-YR(WS-PRYR-IDX)   
            MOVE WS-PRYR-ID   TO WS-TBL-PRYR-ID(WS-PRYR-IDX)
        END-IF                                                   
    ELSE                                                         
        IF SQLCODE = +100                                       
            IF WS-PRYR-IDX > C-MAX-PRYR-VALUE                           
                SET WS-DISPLAY-IDX  TO WS-PRYR-IDX               
                SUBTRACT +1        FROM WS-DISPLAY-IDX         
                                                               
                DISPLAY 'PRYR TABLE EXCEEDED MAX VALUES'               
                DISPLAY WS-DISPLAY-IDX ' ROWS ONLY LOADED'
                PERFORM 9999-CALL-ABEND-PARA                   
            ELSE                                               
                SET WS-NO-MORE-PRYR TO TRUE                     
            END-IF                                             
        ELSE                                                   
            DISPLAY 'PRYRCURS - FETCH FAILED'             

.
.

1300-CLOSE-PRYRCURS.                           
                                             
    EXEC SQL                                 
        CLOSE PRYRCURS                         
    END-EXEC.                                 
                                             
    IF SQLCODE = +0                           
        CONTINUE                             
    ELSE                                     
        DISPLAY 'PRYRCURS - CLOSE FAILED'

.
.


I am concerned about "1200-FETCH-PRYRCURS" paragraph because the limit is checked in both IF and ELSE parts ! Is it possible that the maximum value could be reached when a +100 occurs?

Please explain.

Thanks.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Sat Nov 29, 2008 4:21 pm
Reply with quote

Quote:
I have found below code and not able to understand if it works as the way it was written
Neither do we. What do you expect this program to give and what it's giving currently?
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Sat Nov 29, 2008 4:54 pm
Reply with quote

Arun,

This program was recently written by a person (resigned) and gone into production without proper testing. So, want to make sure if this works as intended especially for the maximum value comparison !

Thanks.
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Sat Nov 29, 2008 4:57 pm
Reply with quote

The condition which I referred has not occurred so far. I want to fix that part but unable to interpret it correctly icon_redface.gif

Thanks.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Sat Nov 29, 2008 5:19 pm
Reply with quote

any program will work as written,
and the answer to the question "... program will work as written?"
will alway be YES icon_biggrin.gif

since we do not know what the program was intended to do
the question is a bit <ILLOGIC> ...
I dare to say icon_cool.gif

describe in plain words what the program is supposed to do
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Nov 30, 2008 4:44 am
Reply with quote

Hello,

If the program was recently written, complete specifications of what the code should do are available.

Suggest you sit down with whoever wrote the specs and make sure you understand what the code should should do in every case. Then create test data to validate that the code does indeed do what the designer intended.

We cannot help much because we don't know the rules and even if we did, the code posted is not compelte. There are references to to data names not posted.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Compile rexx code with jcl CLIST & REXX 6
No new posts REXX code to expand copybook in a cob... CLIST & REXX 2
No new posts VSAM return code 23 - for a Random read COBOL Programming 4
Search our Forums:

Back to Top