Conditional CALL during OpenCOBOL development

I write a fair number of experimental OpenCOBOL programs. Not for production use, but for proof of concepts and tutorials.

My coding style is still evolving, and there are always new discoveries that make things easier.

CALL "function" ON EXCEPTION CONTINUE …

Well met,

I write a fair number of experimental OpenCOBOL programs. Not for production use, but for proof of concepts and tutorials.

My coding style is still evolving, and there are always new discoveries that make things easier.

A new one (old really, but new to me) is CALL … ON EXCEPTION. Handy.


OCOBOL >>SOURCE FORMAT IS FIXED
*> ***************************************************************
*> Author: Brian Tiffin
*> Date: 20110701
*> Purpose: Try C library formatted printing, and CALL exception
*> Tectonics: cobc -x callon.cob
*> or cobc -x callon.cob CBL_OC_DUMP.cob
*> ***************************************************************
identification division.
program-id. callon.

data division.
working-storage section.
01 result usage binary-long.

01 pie usage float-short.
01 stuff pic x(12) value 'abcdefghijkl'.

*> ***************************************************************
procedure division.
move 3.141592654 to pie

*> Get a dump of the memory at pie, but don't stop if not linked
call "CBL_OC_DUMP" using pie 4 on exception continue end-call

*> Call C's printf, abort if not available
call static "printf" using
"float-short: %10.8f" & x"0a00"
by value pie
returning result
end-call
display pie space length of pie space result end-display

*> Get a dump of the memory used by stuff, don't stop if no link
call "CBL_OC_DUMP" using stuff 12 on exception continue end-call

*> Get a dump of the memory used by stuff, abort if not linked <*
call "CBL_OC_DUMP" using stuff 12 end-call

goback.
end program callon.

So now experimenting can be


$ cobc -x -debug callon.cob CBL_OC_DUMP.cob
$ ./callon

Offset HEX-- -- -- -5 -- -- -- -- 10 -- -- -- -- 15 -- CHARS----1----5-
000000 db 0f 49 40 ..I@............

float-short: 3.14159274
3.1415927 4 +0000000024

Offset HEX-- -- -- -5 -- -- -- -- 10 -- -- -- -- 15 -- CHARS----1----5-
000000 61 62 63 64 65 66 67 68 69 6a 6b 6c abcdefghijkl....

or when a memory dump isn't needed,


$ cobc -x -debug callon.cob
$ ./callon
float-short: 3.14159274
3.1415927 4 +0000000024

Easy peasy experimenting and no executable complaining when I forget to include the memory dump module.

CALL … ON EXCEPTION CONTINUE for the ease of use win.

Cheers,
Brian

Leave a Reply

Your email address will not be published. Required fields are marked *