I want to share data between 2 modules. Most of the data is constant so I would prefer to have it initialized by the runtime system:
01 MY-EXTERNAL-DATA EXTERNAL.
05 DATA-AAA PIC X(12) VALUE ALL "AAAx".
...
05 DATA-ZZZ PIC X(12) VALUE ALL "ZZZx".
This gives me the error: *1018-E* VALUE clause not allowed here. Clause processed as comment.
So I understand I cannot have EXTERNAL data initialized right from the beginning and I have to do it all by myself.
So I have made an init section that I only call once and that should do the work:
INITIALIZE MY-EXTERNAL-DATA EXTERNAL ALL TO VALUE
Unfortunately the error message is unpleasantly accurate. The compiler does not only ignore the VALUE clause when it is setting up the memory at program start-up, but it totally ignores it for the whole of the program. Thus, the INITIALIZE statement has no choice than to simply fill up the record with SPACES.
Question: What is the intended way to initialize an EXTERNAL record?
What have I tried so far?
1. REDEFINITIONs
Neither this
01 MY-EXTERNAL-DATA EXTERNAL.
05 DATA-AAA PIC X(12).
01 MY-NOT-EXTERNAL-DATA REDEFINES MY-EXTERNAL-DATA.
05 DATA-AAA PIC X(12) VALUE ALL "AAAx".
*1018-E***************************************
** VALUE clause not allowed here. Clause processed as comment.
nor that
01 MY-NOT-EXTERNAL-DATA.
05 DATA-AAA PIC X(12) VALUE ALL "AAAx".
01 MY-EXTERNAL-DATA REDEFINES MY-NOT-EXTERNAL-DATA EXTERNAL.
* 229-S*******************************************************
** Incompatible qualifiers
05 DATA-AAA PIC X(12).
did work.
For the second one I think that's OK, because it would have to initialize the EXTERNAL record right from the beginning.
But why is the first one not OK. Everything you write in a redefinition is normally irrelevant regarding memory content.
2. CONDITION names
01 MY-EXTERNAL-DATA EXTERNAL.
88 MY-EXTERNAL-DATA-INIT VALUE "AAAxAAAxAAAx".
05 DATA-AAA PIC X(12).
...
SET MY-EXTERNAL-DATA-INIT TO TRUE
will work, but for the sake of coding explicitly every data byte in the record. And all in one literal. Isn't there a limit?
3. passing the record from one module to the other
CALL "module_2" USING MY-NOT-EXTERNAL-DATA
will also work for the sake of every time passing the same address.
And it will not work, if for some reason then owner of the record ist the second module.
4. let only one module own the record, the other has to ask the address.
CALL "module_2__get_address" USING ADDRESS-OF-MY-NOT-EXTERNAL-DATA
This does work, especially in case that the second module owns the record. But for the sake of an extra "get_address" call before module 1 can start its work.