I believe that “1467” is your logical record length (LRECL). I can duplicate your results if I read a file of blank records; I suggest that you check your JCL, especially the DD for CMWKF01. Also, try changing your DISPLAY statement to
Now I understand your problem. But this seems to me like mainframe-specific stuff. Because your code doesn’t run on my testing system (Windows).
Sorry, I hope Ralph Zbrog can help you…
As noted by Ralph, GIVING LENGTH is pretty silly unless you have TYPE UNFORMATTED, which is basically just a character string. Otherwise, you just get the lrecl.
As to why *length is zero… that is another matter. Are you sure you have the workfile defined correctly?
Sanjay, what results do you receive, if you change from dynamic to fixed length #RECORD (e.g. (A10)). If the record read is longer, it does not matter for this testing, if the record is smaller, ir does not matter for this testing, too.
What is displayed in #RECORD then? All blanks or reliable value? If all blanks, check your jcl, if reliable value: I don’t know :?
"[i]Large and Dynamic Variables can be written into work files or read from work files using the two work file types PORTABLE and UNFORMATTED. For these types, there is no size restriction for dynamic variables. However, large variables may not exceed a maximum field/record length of 32766 bytes.
Reading a dynamic variable from a PORTABLE work file leads to resizing to the stored length.[/i]"
This one is kinda hard to work out from the documentation…the dynamic variable has to be set BEFORE the read. This trick works well with any FB input - the first read figures out the LRECL, then allocates the dynamic variable it needs. If you were using a VB file, you might need to read the whole file to determine the longest record and allocate the dynamic accordingly.
DEFINE DATA
LOCAL
1 #RECORD (A) DYNAMIC
1 #LENGTH (I4)
END-DEFINE
*
READ WORK FILE 1 ONCE #RECORD GIVING LENGTH #LENGTH
EXPAND DYNAMIC #RECORD TO #LENGTH
MOVE ALL ' ' TO #RECORD UNTIL #LENGTH
CLOSE WORK FILE 1
*
READ WORK FILE 1 RECORD #RECORD GIVING LENGTH #LENGTH
DISPLAY #LENGTH *LENGTH(#RECORD)
END-WORK
END
If you are leaning towards Douglas’ solution for a recfm=VB dataset and if the number of records in the file may be too many, you also have the option of reading the dataset’s DCB (using IKJEFTSR and LISTDS) and pass on the LRECL which should be the largest record for that dataset to initialize your dynamic alpha variable upon start of the program.