Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Does this code work as intended - Cursor

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Does this code work as intended - Cursor
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: 2284
Location: @my desk

PostPosted: Sat Nov 29, 2008 4:21 pm    Post subject:
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    Post subject: Reply to: Does this code work as intended - Cursor !
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    Post subject: Correction to apply !
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10274
Location: italy

PostPosted: Sat Nov 29, 2008 5:19 pm    Post subject: Reply to: Does this code work as intended - Cursor !
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

Site Director


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

PostPosted: Sun Nov 30, 2008 4:44 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts UNIT=AFF for Easytrieve code gandikk JCL & VSAM 7 Wed Jul 12, 2017 11:42 pm
No new posts DB2 Program abending without giving a... rahulgarg14 DB2 7 Mon May 29, 2017 8:10 pm
No new posts Testing rerad cursor for status with ... John F Dutcher DB2 8 Fri May 19, 2017 9:35 pm
No new posts Job failing with USER = 4093 REASON C... Pradeepa S ABENDS & Debugging 1 Wed May 17, 2017 3:35 pm
No new posts Fileaid 2 commands instream work. In ... descann Compuware & Other Tools 2 Tue May 16, 2017 3:31 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us