Page 1 of 1

Declare a file varibile length in cobol

PostPosted: Sun Apr 06, 2014 2:24 pm
by cdavide1989
I run a batch COBOL program BATCH sequential files of fixed length.
Since I only need one to run I was wondering it is possible to declare COBOL program in a file and from time to time decide the length of the record?
Same thing with the JCL.
Thanks

Re: Declare a file varibile length in cobol

PostPosted: Sun Apr 06, 2014 4:35 pm
by BillyBoyo
It is not really clear what you mean. Look at RECORD CONTAINS 0. If that is not what you want, please explain better with some examples.

Re: Declare a file varibile length in cobol

PostPosted: Sun Apr 06, 2014 6:06 pm
by cdavide1989
Thanks for the reply, I try to explain.
I have a program that accepts as input a parameter card and based on the value of the card I decide what file to use (each file has a different record lunquezza) I would like to declare a single file within the program and to vary its length records based on parameter to the card.

Re: Declare a file varibile length in cobol

PostPosted: Sun Apr 06, 2014 6:24 pm
by Robert Sample
What you want to do CANNOT be done -- period. COBOL requires that the file record length be known at compile time; you are wanting to defer this determination until execution time, which cannot happen in COBOL. There are some ways to achieve the equivalent (such as writing an Assembler subprogram to handle the file operations), but using just COBOL your request is not possible.

Re: Declare a file varibile length in cobol

PostPosted: Sun Apr 06, 2014 7:11 pm
by BillyBoyo
cdavide1989,

Should I assume that RECORD CONTAINS 0 didn't set you on your way? Define your maximum length for the 01 under the FD.

Define an 01 in the WORKING-STORAGE containing an OCCURS DEPENDING ON for the relevant record-length.

READ ... INTO your-WS-record.

I think it should give you have said you want.