MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Working storage variables

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
tarandeep_singh
Beginner


Joined: 07 Mar 2005
Posts: 6
Topics: 3

PostPosted: Mon Mar 07, 2005 1:55 am    Post subject: Working storage variables Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Mar 07, 2005 9:48 am    Post subject: Reply with quote

tarandeep_singh,

How are you calling the subroutine? Is it statically or dynamically? If you are calling statically , then you can issue a CANCEL statement before returning to the main program.

Or call the subroutine dynamically , so that your subroutine is always in the initial state for every call.

Check this link for cancelling a sub program

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGY3PG10/4.1.3.2.1?SHELF=&DT=20020923143836&CASE=

Check this link for cancel command

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGY3LR10/6.2.5?DT=20020920180651

Hope this helps...

Cheers

kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Cogito-Ergo-Sum
Advanced


Joined: 15 Dec 2002
Posts: 637
Topics: 43
Location: Bengaluru, INDIA

PostPosted: Mon Mar 07, 2005 12:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
Novice
Beginner


Joined: 27 Dec 2002
Posts: 46
Topics: 15

PostPosted: Mon Apr 11, 2005 1:19 am    Post subject: Reply with quote

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
View user's profile Send private message
SureshKumar
Intermediate


Joined: 23 Jan 2003
Posts: 211
Topics: 21

PostPosted: Mon Apr 11, 2005 7:42 am    Post subject: Reply with quote

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
View user's profile Send private message
Novice
Beginner


Joined: 27 Dec 2002
Posts: 46
Topics: 15

PostPosted: Mon Apr 11, 2005 11:33 pm    Post subject: Reply with quote

Thanks Suresh.

Novice
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group