Joined: 20 Oct 2006 Posts: 6970 Location: porcelain throne
one of the formats of the READ instruction provides for a 'length ' working-storage variable which is populated with the length of the record during execution of the READ instruction. Same is available for the WRITE/REWRITE instructions.
Using "LENGTH OF" in this instance will not work because it always returns the length of the 01 level defined in the FD, not the length of the record.
The cleanest way is to define the file in the FD as "RECORD VARYING FROM x TO y DEPENDING ON WS-REC-LEN. Now, whenever a rec is read, its length is placed in WS-REC-LEN.
If he decides to WRITE a rec he must put its length in WS-REC-LEN before the WRITE, unless he hasn't changed the length of the rec just read. In that case he can use the length deposited by the preceding READ.