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 

usage of POINTER and ADDRESS

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


Joined: 01 Mar 2005
Posts: 105
Topics: 58

PostPosted: Tue Nov 28, 2006 3:21 pm    Post subject: usage of POINTER and ADDRESS Reply with quote

Members,

I am trying to learn usage of POINTER and ADDRESS OF parameters by looking at the link and the topic

http://www.mvsforums.com/helpboards/viewtopic.php?t=3367&highlight=address

Passing pointer to a cobol program


If this is the code for Main Program why are we using POINTER and in the called program we are using SET ADDRESS OF syntax which i am not able to understand.Called program i have not understood that is why i have not posted it.Please help me why do we need POINTER and ADDRESS of parameters.
Code:

IDENTIFICATION DIVISION.                 
PROGRAM-ID. TSTCB1.                     
ENVIRONMENT DIVISION.                   
DATA DIVISION.                           
WORKING-STORAGE SECTION.                 
01 TEST1-PTR USAGE IS POINTER.
01 TEST.
   05 TEST1-COB  PIC X(10).               
   05 TEST2-COB  PIC X(20). 
PROCEDURE DIVISION.                     
0000-MAIN.                               
     MOVE 'ABC' TO TEST1-COB             
     MOVE 'CBA' TO TEST2-COB             
     DISPLAY TEST.
     CALL 'TSTCB2' USING TEST1-PTR.         
     GOBACK                               
      .                                   
 0000-MAIN-EXIT.                           
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: Tue Nov 28, 2006 5:27 pm    Post subject: Reply with quote

mfuser,

Check this link which will answer your query

http://www.mvsforums.com/helpboards/viewtopic.php?p=30429#30429

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


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Tue Nov 28, 2006 5:46 pm    Post subject: Reply with quote

No wonder you don't understand, only one in that thread did either.

if you have a cobol module - SETPTR:
Code:

IDENTIFICATION DIVISION.
PROGRAM-ID. SETPTR.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
01  PASSED-POINTER  USAGE IS POINTER.
01  PASSED-AREA              PIC X(01).
PROCEDURE DIVISION USING PASSED-POINTER
                         PASSED-AREA.

0000-MAIN-SET-POINTER.
       SET PASSED-POINTER
        TO ADDRESS OF PASSED-AREA
       GOBACK
       .
0000-EXIT.
     EXIT.


you can
Code:

CALL SETPTR USING POINTER-A
                              AREA-A

where
POINTER-A is any working-storage or linkage POINTER
and
AREA-A is any working-storage or linkage AREA
upon return to your module, the POINTER data-item contains the address of the AREA. Thus you can get around the working-storage/linkage restriction.

why do this?

many large Batch (and ON-LINE COBOL CALLed) COBOL sub-systems - have many modules with many pass-a-long areas (USING list) that are to be shared by the sub-modules.

If your original design includes that all CALL USINGs listing every parm, any future changes - new parm - means that you have to modify the CALL USING code in every existing module (as well as the PROCEDURE DIVISION USINGs!).

But if you original design was for 1 main-program defined 'CONTROL' pass-along which contained a table of POINTER items, then your USING list would be only 1 data area. Each sub-modul would address all linkage items with the appropriate pointer.

Say MOD-A CALLs MOD-B CALLs MOD-C CALLs MOD-D.

USING list is 5 areas. New requirement, MOD-D CALLs MOD-E which needs a new area used also by MOD-D and MOD-B.

This means all the USING lists (CALLs and PROC DIV) have to be changed. MOD-C, which does not use the new area, but still must define it in linkage to pass it to MOD-D (and receive from MOD-B).

With the POINTER approach, just add the new pointer to the 'CONTROL' pass-a-long and modules that need the new area would address it, while those that did not need it would not declare it.

little wordy, hope it helps

Lot of legacy systems had upwards of 20 - 100 USING parms (limit is 256). A real pain to maintain as well as modify when something new had to be added.

to get around having to modify the USING list every time a module required yet a new area to be passed you could have a table containing thousands of POINTERs, each loaded with the address of one of 1000's areas. (thousand is a bit much but do able)

Another reason to use Pointers. Say you have a really large COBOL Table that contains items of 20,000 bytes (you have stowed a vsam file in a COBOL Table to save on I/O'S). This COBOL table is contained in sub-module TABMOD which is CALLed by other modules to get the corresponding table item (vsam record image). If every CALL to TABMOD had a USING ITEM-AREA (an item definition), TABMOD would find the item, MOVE the Table-item(xrg) to ITEM-AREA (linkage) and GOBACK. If you have a large transaction base, 2 million, and each transaction CALLed TABMOD, you would have 2 million moves of 20,000 chars.
To speed it up:
CALLing Program:
Code:

WORKING-STORAGE.
01 ITEM-POINTER USAGE IS POINTER.
01 ITEM-KEY          PIC X(20).
LINKAGE SECTION.
01 ITEM-AREA. 
(COPYBOOK definition of Table item)

CALL TABMOD USING ITEM-POINTER
                                ITEM-KEY
SET ADDRESS OF ITEM-AREA
    TO ITEM-POINTER


TABMOD:
Code:

...
WORKING-STORAGE SECTION.
01  VSAM-IMAGE-TABLE.
      05  VSAM-IMAGE      OCCURS 100000 TIMES
                                     INDEXED BY VSAM-XREG.
            10  VSAM-IMAGE-KEY          PIC X(20).
            10  FILLER                          PIC X(19980)
LINKAGE SECTION.
01  ITEM-POINTER                  USAGE IS POINTER.
01  ITEM-KEY                         PIC X(20).
PROCEDURE DIVISION USING ITEM-POINTER
                                             ITEM-KEY.

:::find item...
SET ITEM-POINTER TO ADDRESS OF VSAM-IMAGE(VSAM-XREG)
  :::: or CALL SETPTR USING ITEM-POINTER
                                          VSAM-IMAGE(VSAM-XREG)
GOBACK

_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
mfuser
Banned


Joined: 01 Mar 2005
Posts: 105
Topics: 58

PostPosted: Tue Nov 28, 2006 9:54 pm    Post subject: Reply with quote

Thanks a lot Kolusu and dbzTHEdinosauer and the info was very useful.
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