Hi,
As part of the creation of a COBOL framework to speed up developments, we are looking for a solution to fix the size of an elementary data-item at the time of compilation because it cannot be determined at the time of writing the code.
Sample use case:
*> from ZCOMMON COPYBOOK
01 ZCOMMON.
05 ZCOMMON-HEADER.
10 ZCOMMON-KEY1 PIC X(10).
10 ZCOMMON-KEY2 PIC X(5).
05 ZCOMMON-DATA.
10 ZCOMMON-ITEMS PIC X(max length of ZREC*-ITEMS).
*> from ZREC01 COPYBOOK
01 ZREC01 REDEFINES ZCOMMON.
05 ZREC01-HEADER.
ZREC01-KEYS PIC X(length of ZCOMMON-HEADER).
05 ZREC01-DATA.
10 ZREC01-ITEMS.
15 ZREC01-ITEM1 PIC X(5).
15 ZREC01-ITEM2 PIC X(3).
10 ZREC01-COMPL PIC X(length of ZCOMMON-ITEMS - length of ZREC01-ITEMS).
*> from ZREC02 COPYBOOK
01 ZREC02 REDEFINES ZCOMMON.
05 ZREC02-HEADER.
ZREC02-KEYS PIC X(length of ZCOMMON-HEADER).
05 ZREC02-DATA.
10 ZREC02-ITEMS.
15 ZREC02-ITEM1 PIC X(30).
10 ZREC01-COMPL PIC X(length of ZCOMMON-ITEMS - length of ZREC02-ITEMS).
At compile time:
length of ZCOMMON-HEADER = 15
length of ZREC01-ITEMS = 8
length of ZREC02-ITEMS = 30
length of ZCOMMON-ITEM = max(8,30) = 30
length of ZREC01-COMPL = 30 - 8 = 22
length of ZREC02-COMPL = 30 - 30 = 0
It should be noted that the determination of a value may be dependent on another value that is defined downstream in the source code flow, and that some calculations may provide a value 0 (possibly negative) and in this case the elementary data-item should have a size of 0, and should not be considered as an error.
The result obtained would therefore be:
*> from ZCOMMON COPYBOOK
01 ZCOMMON.
05 ZCOMMON-HEADER.
10 ZCOMMON-KEY1 PIC X(10).
10 ZCOMMON-KEY2 PIC X(5).
05 ZCOMMON-DATA.
10 ZCOMMON-ITEMS PIC X(30).
*> from ZREC01 COPYBOOK
01 ZREC01 REDEFINES ZCOMMON.
05 ZREC01-HEADER.
ZREC01-KEYS PIC X(15).
05 ZREC01-DATA.
10 ZREC01-ITEMS.
15 ZREC01-ITEM1 PIC X(5).
15 ZREC01-ITEM2 PIC X(3).
10 ZREC01-COMPL PIC X(22).
*> from ZREC02 COPYBOOK
01 ZREC02 REDEFINES ZCOMMON.
05 ZREC02-HEADER.
ZREC02-KEYS PIC X(15).
05 ZREC02-DATA.
10 ZREC02-ITEMS.
15 ZREC02-ITEM1 PIC X(30).
10 ZREC01-COMPL PIC X(0).
This process of calculating the length of zones can only be performed at compile time: using conditional compilation does not seem to meet this need.
This need mainly concerns declarations of areas in REDEFINES.
The compiler already does some calculations internally since it allows REDEFINES with longer (and shorter) descriptions and in this case reserves memory for the longer description.
Perhaps part of the solution could be achieved by a mechanism that automatically calculates the lengths:
*> from ZCOMMON COPYBOOK
01 ZCOMMON.
05 ZCOMMON-HEADER.
10 ZCOMMON-KEY1 PIC X(10).
10 ZCOMMON-KEY2 PIC X(5).
05 ZCOMMON-DATA.
10 ZCOMMON-ITEMS PIC X(*).
*> from ZREC01 COPYBOOK
01 ZREC01 REDEFINES ZCOMMON.
05 ZREC01-HEADER.
ZREC01-KEYS PIC X(15).
05 ZREC01-DATA.
10 ZREC01-ITEMS.
15 ZREC01-ITEM1 PIC X(5).
15 ZREC01-ITEM2 PIC X(3).
10 ZREC01-COMPL PIC X(*).
*> from ZREC02 COPYBOOK
01 ZREC02 REDEFINES ZCOMMON.
05 ZREC02-HEADER.
ZREC02-KEYS PIC X(15).
05 ZREC02-DATA.
10 ZREC02-ITEMS.
15 ZREC02-ITEM1 PIC X(30).
10 ZREC01-COMPL PIC X(*).
The last area of a description (in a group), with a PICTURE X(*) adjusts its length relative to the other descriptions in REDEFINES.
This idea is being accepted and will be updated once put into plan.
This idea is being discussed further.