Initializing working storage at compile time.
We have a lot of old code that doesn't properly initialize working storage variables and we are getting strange results in our numeric fields. I was hoping to use a compiler directive to accomplish the initialization. I am compiling at the command line and compiling into INTs. I came across the INIT-BY-TYPE compiler directive that seems like it should do what I need, but I am having trouble getting it to work from the command line.
My current compile line looks like this:
cobol prog1.cbl int() REMOVE"CONTROL";
I've tried including the INIT-BY-TYPE directive but I keep getting errors. How do you include this directive on the command line?
Just a few more details... We have a program that has a counter defined as:
RECORDS-READ PIC 9(5).
In the procedure division the counter gets added to for each record read :
READ INPUTFILE NEXT RECORD AT END GO TO CLOSE-UP.
ADD 1 TO RECORDS-READ.
DISPLAY RECORDS-READ AT 1230.
We are seeing the counter as follows:
You do need the INIT-BY-TYPE directive but unfortunately it is a new directive that will only be available as of Visual COBOL 2.2 update 1 which will be released at the beginning of June so it is not supported in the version that you are currently using.
Currently we have support for the DEFAULT-BYTE directive which allows you to specify a single character value to which all of working-storage will be initialized.
If you used DEFAULT-BYTE"48" all of your fields would be initialized to zeroes which would be fine for numerics but probably isn't what you want for pic x fields.
If you used DEFAULT-BYTE"32" then all of your fields would be initialized to spaces which might be ok if you also set the directive SPZERO on which causes spaces in numerics to be treated as though they were zeroes.
This might be your best bet, other than using an INITIALIZE statement or VALUE clause to explicitly initialize your data, al least until 2.2 update 1 becomes available.