Skip to main content

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.

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.

Hi marcus1,

First, my apologies for the delay in responding.

As you've found, you can't use INITIALIZE on external data items, and you can't specify VALUE clauses for them. I don't believe getting the external items initialized automatically is possible. You'll need something in the programs (at least one of them) to do this.  The options you mentioned are valid, or variations on them. 

Your idea of using the SET statement to set a value for the external item seems like it might require less coding and complexity that some of the others. If setting up the value clauses becomes onerous because of their size, you could split up the area and have multiple conditional clauses.

You can have all of the programs specify the same value in the condition, or not. In my testing, you can have the same external item defined in different programs with different values on the conditional variables, for example:

In program 1:

       01 ext-item    pic x(10) is external.
           88 ext-init-value value "maininit".

In program 2:

       01 ext-item    pic x(10) is external.
           88 ext-init-value value "subinit".

Then, each program could examine the value of ext-item, figure out that it needs to be initialized, and use a set statement to initialize it to the respective "template" value for that program.

           set ext-init-value to true

 

Hope this helps.