DCLOPT(*NOCHGDSLEN
The DCLOPT keyword specifies options related to declarations.
The parameter must be *NOCHGDSLEN.
When DCLOPT(*NOCHGDSLEN) is specified, you can
use %SIZE with a data structure parameter in a free-form
File or Definition statement if the following conditions are met:
- All the subfields are defined.
- If the data structure is defined with the DIM or OCCURS keyword, the dimension must be defined when %SIZE appears.
- The usage of %SIZE and the data structure definition must be either both in the global declarations or both in the same subprocedure.
The following additional rules apply:
- A data structure cannot be specified on an Input specification.
- If a data structure appears in the result field of a Calculation specification, the Length entry cannot be specified.
- If an externally-described file has Input or Output specifications generated, a field name in the file cannot be the name of a data structure. (Input and Output specifications are generated for any global file that does not have the QUALIFIED or LIKEFILE keyword.)
In the following example,
- Keyword DCLOPT(*NOCHGDSLEN) is specified in the Control statement.
- The data structure MYDS is defined without an explicit length.
- Subfield DATA is defined like LINE.
- The first file declaration is not valid because the value of %SIZE(MYDS) is not yet known.
- When field LINE is defined, all the subfields of MYDS are defined, and due to the presence of DCLOPT(*NOCHGDSLEN) in the Control statement, data structure MYDS is defined and its size is known.
- The second file declaration is valid because the value of %SIZE(MYDS) is known.
Without DCLOPT(*NOCHGDSLEN), neither file declaration would be valid because the size of MYDS would not be known until the compiler had processed all the statements of the procedure.
ctl-opt dclopt(*nochgdslen); // 1
dcl-ds myDs; // 2
seq zoned(6:2);
dat zoned(6);
data like(line); // 3
end-ds;
dcl-f myfile1 disk(%size(myDS)); // 4
dcl-s line char(100); // 5
dcl-f myfile2 disk(%size(myDS)); // 6