Highlighted
Valued Contributor.
Valued Contributor.
2096 views

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?

0 Likes
3 Replies
Highlighted
Valued Contributor.
Valued Contributor.

RE: Initializing working storage at compile time.

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:

1

2

3

4

5

6

7

8

9

!0

!1

!2

!3

etc...

0 Likes
Highlighted
Valued Contributor.
Valued Contributor.

RE: Initializing working storage at compile time.

One more note...

When we run this program compiled in the old 16-bit MF 3.423 it works fine.  

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Initializing working storage at compile time.

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.

Thanks.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.