State of WORKING-STORAGE in Statically-Called Subroutines

docdwarf_at_panix.com
Date: 12/16/03


Date: 16 Dec 2003 12:50:10 -0500


All righty... ran across this one today and wanted to make sure mine eyes
did not deceive me.

(Architecture is IBM mainframe, compiler is IGYCRCTL,
PARM='SIZE(MAX),LIB,NUMPROC(MIG),OFF,MAP,
      XREF,OPT,FLAG(I,I),NOSEQ,TEST(NONE,SYM),NOADV' )

There is a chain of three programs, A, B and C. B contains a static call
to C (CALL 'C' USING...), A contains static calls to both B and C.

A reads the files and does... stuff. If records are rejected a block of
them gets passed to B which does some formatting and then passes the
records one-at-a-time to C. C, in essence, is composed of the following
Olde-Stylee Codee:

--begin quoted text:

   01 OUTPUT-SW VALUE SPACE PIC X.
       88 FIRST-BATCH VALUE SPACE.
       88 REJECT-FILE-OPEN VALUE 'O'.
   LINKAGE SECTION.
   01 REJ-IO-SW PIC X.
       88 LAST-REC VALUE 'E'.
       COPY TAREJECT.
   PROCEDURE DIVISION USING REJ-IO-SW
                             TA-REJECT-RECORD.
   0000-WRITE-TA-REJECT-RECORD.
       IF FIRST-BATCH AND NOT LAST-REC
           OPEN EXTEND TA-REJECT-FILE
           MOVE 'O' TO OUTPUT-SW.
       IF LAST-REC
           IF REJECT-FILE-OPEN
               CLOSE TA-REJECT-FILE
               MOVE 'C' TO OUTPUT-SW
           ELSE
               NEXT SENTENCE
       ELSE
           WRITE TAREJECT-RECORD FROM TA-REJECT-RECORD.
   0000-END-OF-WRITE.
       EXIT PROGRAM.
 
--end quoted text

So... the first time B calls C the WORKING-STORAGE field OUTPUT-SW
contains SPACES; condition FIRST-BATCH is met so the file is OPENed and an
O is MOVEd to OUTPUT-SW.

Subsequent times that B calls C condition FIRST-BATCH is *not* met (as
verified by copious DISPLAYs) so it appears that the value set in that
first time through is persistent.

First question: is this so, that a value set in the WORKING-STORAGE
SECTION of a staticaly-called subroutine persists in subsequent calls by
the same program?

Anyhow... A gets done processing and as part of 9999-EOJ checks another
flag; based on this flag A will call C directly (remember, static
linkage) USING a REJ-IO-SW of 'E'.

Second question: will A's call to the subroutine demonstrate the
persistence of value in C which B has set?

I think not, based on the behavior I have seen and a fix which allows for
the 'self-documenting syntax' of:

IF FIRST-BATCH AND NOT LAST-REC

... but I'd be interested in hearing what others might have experienced
along these lines.

(Hint: the error-symptom was that even though C had written output it hit
the OPEN EXTEND statement when called from A... thus wiping out everything
that had been written by being passed from B.)

DD