Thread: COBOL

OCCURS DEPENDING ON - SPACES check stopped working after I changed OCC-VAL

Started by Tyler • user4 replies144 viewsLast activity 2 weeks ago
Post #1
0 votes
Tyler
Reputation
34
Posts: 19
Joined: Nov 8, 2025, 1:44 PM
Posted: Jul 26, 2026, 9:32 AM

COBOL 6. Nested table with DEPENDING ON. Used to loop looking for TEMP-ELEM = SPACES to find a free slot. After a change where OCC-VAL is less than the max (say 30 of 80), that SPACES check fails weirdly.

Tried LOW-VALUE, <= SPACES, VALUE SPACES on the field. Feels like the unused occurrences have junk left over from when the table was bigger.

Am I supposed to only walk up to OCC-VAL and never peek past it?

Post #2
0 votes
Marty
Reputation
412
Posts: 58
Joined: Aug 12, 2024, 9:14 AM
Posted: Jul 26, 2026, 10:32 AM

Yes. Do not search past the current DEPENDING ON count. Memory past OCC-VAL is not "empty slots" you can trust. Cap the UNTIL at IND > OCC-VAL.

To add an entry: bump OCC-VAL first (if under max), then MOVE into that new subscript.

Post #3
1 votes
Rick
Reputation
302
Posts: 22
Joined: Jun 14, 2024, 9:41 AM
Posted: Jul 26, 2026, 1:32 PM

Also watch nested ODO where the counters are global. Every parent ends up sharing the same count field. Put the count inside the parent structure.

Post #4
0 votes
Tyler
Reputation
34
Posts: 19
Joined: Nov 8, 2025, 1:44 PM
Posted: Jul 27, 2026, 11:32 AM

That was it. I was scanning the full 80. Loop stops at OCC-VAL now and I initialize the new slot when I add. Works.

You must be signed in to reply to this thread