View previous topic :: View next topic
|
Author |
Message |
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
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 |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
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 |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
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 |
|
|
ramsri
Active User
Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
The condition which I referred has not occurred so far. I want to fix that part but unable to interpret it correctly
Thanks. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
any program will work as written,
and the answer to the question "... program will work as written?"
will alway be YES
since we do not know what the program was intended to do
the question is a bit <ILLOGIC> ...
I dare to say
describe in plain words what the program is supposed to do |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|