Your basic problem is that to read the file and get the record count, the program has to be executing. In order to execute, the program has to be compiled. The size of arrays in the program (except for LINKAGE SECTION and FD OCCURS DEPENDING ON arrays) is fixed at compile time. So your choices are:
- set up your code to read the file, get the record count, and change ANOTHER program's source to include that count, then submit a compile and execution of that program
- you might be able to use a subprogram to save each array element as it is read in the main program and passed to the subprogram -- whether or not this works depends upon the details of what you're doing with the array
- give up your idea as unwieldy at best and impossible at worst, explain to us what the REAL problem you are attempting to solve is, and let us suggest methods that COBOL does support and allow instead of what you want to do.