View previous topic :: View next topic |
Author |
Message |
tarandeep_singh Beginner
Joined: 07 Mar 2005 Posts: 6 Topics: 3
|
Posted: Mon Mar 07, 2005 1:55 am Post subject: Working storage variables |
|
|
Does working storage variables in any case hold the values of the previous run of the code
actually I am facing a case where the working storage variables are retaining the values that the program had when it was called previously; this program is called several times and if not initialized retains its old values exactly
Is this possible in a general case
Thanks
Taran |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
|
Back to top |
|
|
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Mon Mar 07, 2005 12:45 pm Post subject: |
|
|
Yes, it will hold the old values if you do not meddle with PROGRAM-ID of the IDENTIFICATION DIVISION.
With
Code: |
ID DIVISION.
PROGRAM-ID. MYPGM.
|
the working storage will retain the original values.
But, with this,
Code: |
ID DIVISION.
PROGRAM-ID. MYPGM IS INITIAL.
|
the working storage will always be refreshed. _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
|
Novice Beginner
Joined: 27 Dec 2002 Posts: 46 Topics: 15
|
Posted: Mon Apr 11, 2005 1:19 am Post subject: |
|
|
Kolusu,
Does a Dynamic call always initializes working storage variables for each invocation? This is not what I got when I tried the following example. Let me know if I missed out some thing
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. CALLING.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-OTHERS.
05 WS-EYE-CATCHER PIC X(32)
VALUE' WORKING STORAGE SECTION BEGINS ' .
05 WS-PROGRAM PIC X(08) VALUE SPACES.
05 WS-SHARE-PRICE PIC 9(04).
05 WS-SHARE-PREMIUM PIC 9(04).
05 WS-TEMP PIC 9(04).
PROCEDURE DIVISION.
PERFORM B0100-INITIALIZATION THRU B0100-EXIT
GOBACK.
B0100-INITIALIZATION.
DISPLAY' ENTRY INTO MAIN:'
MOVE 'CALLED ' TO WS-PROGRAM
MOVE 1000 TO WS-SHARE-PRICE
CALL WS-PROGRAM USING WS-SHARE-PRICE WS-SHARE-PREMIUM
MOVE WS-SHARE-PREMIUM TO WS-TEMP
MOVE 1200 TO WS-SHARE-PRICE
CALL WS-PROGRAM USING WS-SHARE-PRICE WS-SHARE-PREMIUM
COMPUTE WS-SHARE-PREMIUM = WS-SHARE-PREMIUM + WS-TEMP
DISPLAY 'THE PREMIUM FOR THIS SHARE IS :' WS-SHARE-PREMIUM
.
B0100-EXIT. EXIT.
|
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. CALLED.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-OTHERS.
05 WS-EYE-CATCHER PIC X(32)
VALUE' WORKING STORAGE SECTION BEGINS ' .
05 WS-PROGRAM PIC X(08) VALUE SPACES.
05 WS-SHARE-PRICE PIC 9(04) VALUE 0.
05 WS-SHARE-PREMIUM PIC 9(04).
LINKAGE SECTION.
01 LS-SHARE-PRICE PIC 9(04).
01 LS-SHARE-PREMIUM PIC 9(04).
PROCEDURE DIVISION USING LS-SHARE-PRICE,LS-SHARE-PREMIUM.
PERFORM B0100-INITIALIZATION THRU B0100-EXIT
GOBACK.
B0100-INITIALIZATION.
DISPLAY' ENTRY INTO SUB:'
DISPLAY' WS-SHARE-PRICE:' WS-SHARE-PRICE
COMPUTE WS-SHARE-PRICE = LS-SHARE-PRICE - WS-SHARE-PRICE
IF WS-SHARE-PRICE > 999
COMPUTE WS-SHARE-PREMIUM = 0.1 * WS-SHARE-PRICE
ELSE
COMPUTE WS-SHARE-PREMIUM = 0.01 * WS-SHARE-PRICE
END-IF
MOVE WS-SHARE-PREMIUM TO LS-SHARE-PREMIUM
.
B0100-EXIT.
EXIT.
|
Quote: | The Result is
ENTRY INTO MAIN:
ENTRY INTO SUB:
WS-SHARE-PRICE:0000
ENTRY INTO SUB:
WS-SHARE-PRICE:1000
HE PREMIUM FOR THIS SHARE IS :0102
|
Is that mean that CANCEL statement or PROGRAM-ID is INITIAL is required for both STATIC CALLS and DYNAMIC calls for working storage variables initialization ?
Regards
Novice |
|
Back to top |
|
|
SureshKumar Intermediate
Joined: 23 Jan 2003 Posts: 211 Topics: 21
|
Posted: Mon Apr 11, 2005 7:42 am Post subject: |
|
|
Novice,
In a dynamic call the Working Storage is initialized once for a "Run Unit". In case of CICS it's just once, but if called in Batch more often then the WS needs to be Initialized or other methods lime "IS INITIAL". |
|
Back to top |
|
|
Novice Beginner
Joined: 27 Dec 2002 Posts: 46 Topics: 15
|
Posted: Mon Apr 11, 2005 11:33 pm Post subject: |
|
|
Thanks Suresh.
Novice |
|
Back to top |
|
|
|
|