View previous topic :: View next topic |
Author |
Message |
vijay Beginner
Joined: 09 May 2003 Posts: 131 Topics: 64
|
Posted: Mon Jun 14, 2004 10:09 am Post subject: COBOL Search with Index Doubt |
|
|
step 1)
I'm looking at a production problem.An input file with 18 records is loaded into
an internal table like this
Code: |
*
01 FILLER.
05 MAX-AC PIC S9(9) COMP SYNC.
05 W-AC-TABLE OCCURS 1 TO 10
DEPENDING ON MAX-AC
INDEXED BY INDEX-J.
07 W-AC PIC S9(3) COMP-3.
EJECT
|
*==============================================================*
Code: |
0000-GET-AC.
READ FILEIN AT END CLOSE FILEIN
GO TO 0000-EXIT.
ADD 1 TO MAX-AC
MOVE FILEIN-CLIENT TO W-AC (MAX-AC)
GO TO 0000-GET-AC.
0000-EXIT. EXIT.
**** The working storage has occurs 1 to 10 though the file has 18 records.
|
*==============================================================*
step 2)
I've another input file.for ex: E-AC-N0 = 100 from this file and this value is not in the
internal table ,now goes through this section
Code: |
0100-BC.
SET INDEX-J TO 1
SEARCH W-AC-TABLE VARYING INDEX-J
AT END GO TO 0100-EXIT
WHEN W-AC (INDEX-J) = E-AC-NO
GO TO 0100-BD
END-SEARCH
0100-EXIT. EXIT.
|
...
0100-BD.
.
.
....
For e-ac-no = 100 ,the above logic works and it goes to 0100-exit.
...>>>>>>
Now I added another record in the file that updates the internal table,so internal table has 19 entries.
and the program goes to step2 above for the same e-ac-no (=100,which is not in the internal table).
But this time it abends in the section.reason--> invalid value in W-AC (INDEX-J) .
The INDEX-J value is 19 and W-AC (INDEX-J) value is x'40f0' .Not sure how this worked when there were
18 records and not when there were 19 records.
If I change 'OCCURS 1 TO 10 ' to 'OCCURS 1 TO 20' in the working storage ,it works in both the
cases.But I'm not sure why it abended in the previous case.
Could somebody help me withis please? |
|
Back to top |
|
 |
Mike Chantrey Intermediate
Joined: 10 Sep 2003 Posts: 234 Topics: 1 Location: Wansford
|
Posted: Fri Jun 18, 2004 6:58 am Post subject: |
|
|
If you don't have subscript checking on (compiler option) there's nothing to stop you writing occurances beyond what's defined in the OCCURS. The extra data will overwrite whatever follows the array in storage. Depending on what is there and how far you go past the end of the array, the program may work correctly, it may complete with incorrect results or it may abend in various ways.
All programs should be tested with subscript range checking on; it can be turned off for production release if required for efficiency. |
|
Back to top |
|
 |
Mike Chantrey Intermediate
Joined: 10 Sep 2003 Posts: 234 Topics: 1 Location: Wansford
|
Posted: Fri Jun 18, 2004 7:04 am Post subject: |
|
|
The above comment applies to fixed tables (no DEPENDING clause); I'm not sure exactly what happens if you have a DEPENDING and its value exceeds the maximum allowed, but judging by your results it looks as if the results may well be the same. |
|
Back to top |
|
 |
|
|