
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
How to get Visual Cobol to fail for divide by zero and subscript out of range errors?
Hello,
I run this program:
and program executes with the displays shown below on console.
Any suggestions would be helpful.
After some more research, it seems that
$SET CHECKDIV"ENTCOBOL" triggers runtime divide by zero errors.
I am confused why this is not the default for divide by zero runtime errors in general.
Very confusing for new programmers when code works, but not really.
As for the subscript out of range,
$SET SSRANGE
or
$SET BOUND
These seem to imply they should help, but neither triggers a runtime error in my sample code.
I also tried $SET DIALECT"ENTCOBOL" and this was not helpful either.
I am confused why this is not the default for subscript out of range runtime errors in general.
Very confusing for new programmers when code works, but not really.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
You should be using indexes, however with variable length records sending the subscript negative can read the record length (binary number). A trick used on OS/390 mainframes. For subscript out of range just do a simple if test for < 1 or > max items.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
You do not have to check denominators = 0 before every divide? There is an option to force divide by zero errors 'CHECKDIV', so why not an option the check subscripts? Still not clear why this option is not on by default, but at least it exists.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
The BOUND directive is turned on by default and this will check for invalid subscript errors only if a data-item is being used as the subscript. This will trigger a RTS error 153.
You are using literals as subscripts line 0 and 3 and these will generate a compiler warning instead which basically tells you to fix the problem before you run the code.
Example:
If you change the line:
move 3 to ws-tbl-items(3).
to
move 3 to ws-tbl-items(my-num).
where my-num is defined in working-storage as:
01 my-num pic 9 value 3.
Then a RTS error 153 will be generated.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Thank you for the info about subscripts being variable versus literal being handled differently for the subscript out of range condition. Where is this documented, so I can read more about it?
What other compiler-directive options are turned on by default?
Where is this documented, so I can read more about it?
I have tried searching for the detail on both of these without much success.
thanks.