Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

What is the benefit of using pointer?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
amiya_mf

New User


Joined: 01 Mar 2005
Posts: 19

PostPosted: Thu Apr 05, 2007 4:22 pm    Post subject: What is the benefit of using pointer?
Reply with quote

Can anybody tell the difference between calling a subprogram as usal manner and calling through pointer. What is the benefit of using pointer?

means:

call 'subprogram' using ws-data1.

AND

call 'subprogram' using ws-ptr1.

where ws-ptr1 is been mapped to ws-data1 by:

set address of ws-data1 to ws-ptr1.

i think both are same but only two different way of calling. because in both the cases the address is being passed in between called program and main program. so what is the benefit of using pointer?

--Amiya
Back to top
View user's profile Send private message

William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Thu Apr 05, 2007 5:22 pm    Post subject: Re: What is the benefit of using pointer?
Reply with quote

amiya_mf wrote:
i think both are same but only two different way of calling. because in both the cases the address is being passed in between called program and main program.
Inboth cases AN address is being passed, but a different addresses in each case. With the first, the address of the data is passed. With the second,the address of the pointer, which contains the address of the data, is passed.

As far as
Quote:
What is the benefit of using pointer?
I really can't think of one specifically......
Back to top
View user's profile Send private message
akswhy

New User


Joined: 26 Oct 2006
Posts: 3

PostPosted: Thu Apr 05, 2007 8:42 pm    Post subject: Re: What is the benefit of using pointer?
Reply with quote

Using pointers enables you to pass more than 32k in storage to subprogram by not passing actual data but just address of pointer that holds storage address of data.
If you passed data, then you can only pass up to 32k because that is system limitation.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Thu Apr 05, 2007 9:19 pm    Post subject: Re: What is the benefit of using pointer?
Reply with quote

akswhy wrote:
Using pointers enables you to pass more than 32k in storage to subprogram by not passing actual data but just address of pointer that holds storage address of data.
If you passed data, then you can only pass up to 32k because that is system limitation.
Again, there is no limitation!
Who is spreading this FUD? icon_rolleyes.gif
Back to top
View user's profile Send private message
akswhy

New User


Joined: 26 Oct 2006
Posts: 3

PostPosted: Thu Apr 05, 2007 9:52 pm    Post subject: Re: What is the benefit of using pointer?
Reply with quote

For CICS programs IBM indicates there is a 32k limit in Commarea.

http://publib.boulder.ibm.com/infocenter/cicsts/v3r1/index.jsp?topic=/com.ibm.cics.ts31.doc/dfhp3/dqx1dfhp3hb.htm
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Thu Apr 05, 2007 10:54 pm    Post subject:
Reply with quote

akswhy,
This isnt related to cics.
There is no limit on passing data through LINKAGE SECTION.
I guess you understand difference in COMMAREA and LINKAGE SECTION. icon_smile.gif
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 149
Location: Ottawa Canada

PostPosted: Fri Apr 06, 2007 12:05 am    Post subject:
Reply with quote

Scenario: Program A needs to pass 50,000 bytes of storage to Program B. How do you do this in CICS?

1. Use the CALL statement. Quite simply...

CALL WS-B USING WS-CHUNK

2. Use the LINK statement.

However, the LINK statement imposes a maximum length of 32K. So you cannot pass CHUNK directly. But you could pass it indirectly. Create a POINTER field that lives in the commarea that A passes to B. Note however that this creates an affinity between A and B. A and B must live in the same CICS region in order for this technique to work.

Note that using the CALL statement also creates an affinity between A and B. However, this affinity is far less smelly than the affinity caused by passing a POINTER via the LINK statement.

Consider what would happen if the CICS Configuration people decided to configure A and B in different CICS regions. (Maybe they did this for a valid reason... maybe they made a mistake. It doesn't really matter...)

An attempt by A to CALL B would result in an abend - and that is exactly how I want this event handled. Perfect.

However, an attempt by A to LINK to B will succeed BUT the pointer that A passes to B will become an invalid pointer in the remote CICS region. As they say, unpredictable results. Much more difficult to diagnose.

In other words, if you are going to pass POINTERs around using LINK you've got to take care. One idea is, when setting a pointer, to bundle it with the SYSID of the region it points to. This allows for a check to occur by whoever wants to use the pointer - they can ask "Is this pointer pointing to the CICS region I am running in".

So the best option is use CALL. CALL clearly establishes the affinity between A and B whereas the LINK/POINTER approach can be a time-bomb.

Where I work we have strict rules about avoiding the creation of affinities between certain programs.

Whenever possible avoid the use of POINTERs. Are there legitimate scenarios where POINTERS make sense? Yes. One example: consider a table that typically contains no more than 15 entries for 99% of transactions, but may contain 1000 entries for your big customers. Instead of defining this table in your working storage as OCCURS 1200 you could define it in your LINKAGE SECTION as OCCURS 1 to 1200 and allocate storage dynamically - only as much as you need. To do this you must use pointers.
Back to top
View user's profile Send private message
akswhy

New User


Joined: 26 Oct 2006
Posts: 3

PostPosted: Fri Apr 06, 2007 12:36 am    Post subject: Re: What is the benefit of using pointer?
Reply with quote

It seems to me the 32k limitation is there for transferring to CICS programs using LINK or XCTL. Otherwise there is no limitation.
Back to top
View user's profile Send private message
jinal_mca

New User


Joined: 05 Jan 2007
Posts: 23
Location: Pune, India

PostPosted: Fri Apr 06, 2007 2:18 pm    Post subject: hi
Reply with quote

in case if u r sending parameter by reference u dont need to return it back to
called program ...

in case of pointer the changes will get reflected in the variable bcaz it always works on memory addresses.
Back to top
View user's profile Send private message
amiya_mf

New User


Joined: 01 Mar 2005
Posts: 19

PostPosted: Mon Apr 09, 2007 6:04 pm    Post subject: Thanks for your valuable reply
Reply with quote

but i have one more question like... in general call also i.e. without using pointer both calling program and called program is shariing the same memory address as it is call by reference. but in case of call by value different address is being maintained.

so what i am worring like in both the case ( in using pointer and not using) the interfacing is by address only.

so how it is different. or both are same but just two different form.

TG Murphy wrote:
Scenario: Program A needs to pass 50,000 bytes of storage to Program B. How do you do this in CICS?

1. Use the CALL statement. Quite simply...

CALL WS-B USING WS-CHUNK

2. Use the LINK statement.

However, the LINK statement imposes a maximum length of 32K. So you cannot pass CHUNK directly. But you could pass it indirectly. Create a POINTER field that lives in the commarea that A passes to B. Note however that this creates an affinity between A and B. A and B must live in the same CICS region in order for this technique to work.

Note that using the CALL statement also creates an affinity between A and B. However, this affinity is far less smelly than the affinity caused by passing a POINTER via the LINK statement.

Consider what would happen if the CICS Configuration people decided to configure A and B in different CICS regions. (Maybe they did this for a valid reason... maybe they made a mistake. It doesn't really matter...)

An attempt by A to CALL B would result in an abend - and that is exactly how I want this event handled. Perfect.

However, an attempt by A to LINK to B will succeed BUT the pointer that A passes to B will become an invalid pointer in the remote CICS region. As they say, unpredictable results. Much more difficult to diagnose.

In other words, if you are going to pass POINTERs around using LINK you've got to take care. One idea is, when setting a pointer, to bundle it with the SYSID of the region it points to. This allows for a check to occur by whoever wants to use the pointer - they can ask "Is this pointer pointing to the CICS region I am running in".

So the best option is use CALL. CALL clearly establishes the affinity between A and B whereas the LINK/POINTER approach can be a time-bomb.

Where I work we have strict rules about avoiding the creation of affinities between certain programs.

Whenever possible avoid the use of POINTERs. Are there legitimate scenarios where POINTERS make sense? Yes. One example: consider a table that typically contains no more than 15 entries for 99% of transactions, but may contain 1000 entries for your big customers. Instead of defining this table in your working storage as OCCURS 1200 you could define it in your LINKAGE SECTION as OCCURS 1 to 1200 and allocate storage dynamically - only as much as you need. To do this you must use pointers.
Back to top
View user's profile Send private message
amiya_mf

New User


Joined: 01 Mar 2005
Posts: 19

PostPosted: Mon Apr 09, 2007 6:09 pm    Post subject: Re: What is the benefit of using pointer?
Reply with quote

Hi,
Can you suggest me what exactly the differce is? in what case pointer is beneficial? as i am not finding any difference.

any reply would be appreciated..

Thanks.

William Thompson wrote:
akswhy wrote:
Using pointers enables you to pass more than 32k in storage to subprogram by not passing actual data but just address of pointer that holds storage address of data.
If you passed data, then you can only pass up to 32k because that is system limitation.
Again, there is no limitation!
Who is spreading this FUD? :roll:
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Mon Apr 09, 2007 6:36 pm    Post subject: Re: What is the benefit of using pointer?
Reply with quote

amiya_mf wrote:
Can you suggest me what exactly the differce is? in what case pointer is beneficial? as i am not finding any difference.
In both cases AN address is being passed, but a different addresses in each case. With the first, the address of the data is passed. With the second,the address of the pointer, which contains the address of the data, is passed.

As far as
Quote:
What is the benefit of using pointer?
I really can't think of one specifically......
Back to top
View user's profile Send private message
amiya_mf

New User


Joined: 01 Mar 2005
Posts: 19

PostPosted: Tue Apr 10, 2007 5:04 pm    Post subject: Re: What is the benefit of using pointer?
Reply with quote

I am agree this works on two different addresses but both are working on addresses. generally work on addres is better then work on direct value. i am not finding any difference either it is address of pointer or address of data. am i right? what do u suggest?



William Thompson wrote:
amiya_mf wrote:
Can you suggest me what exactly the differce is? in what case pointer is beneficial? as i am not finding any difference.
In both cases AN address is being passed, but a different addresses in each case. With the first, the address of the data is passed. With the second,the address of the pointer, which contains the address of the data, is passed.

As far as
Quote:
What is the benefit of using pointer?
I really can't think of one specifically......
Back to top
View user's profile Send private message
piportill4

New User


Joined: 09 Apr 2007
Posts: 4
Location: Buenos Aires

PostPosted: Fri Apr 13, 2007 10:46 am    Post subject:
Reply with quote

I never could find ver much benefit of using pointer, but that's just me.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Fri Apr 13, 2007 7:33 pm    Post subject:
Reply with quote

I had asked a similar question before, it was promptly moved to 'Off topics' . icon_sad.gif
I have observed some programs which call 100s of subprograms dynamically.
Now it is quite obvious that they pass huge number variables/structures to other subprograms.
We have to take care while 'aligning' passed parameters in the subprogram.
They should be declared in same order in the subprogram in linkage section.
This becomes cumbersome when there are large number of subprograms.

So by using pointers we pass all variables to every subprogram, now subprogram has the freedom to use it or not.
This appears very appealing when we consider maintainance of the programs in long term.
No problem in adding more subprograms with different data passed.

example 1:

Code:
WORKING-STORAGE SECTION.
01 A PIC X(100).
01 B PIC X(200).
01 c PIC x(300).

PROCEDURE DIVISION.
..
..
..
CALL 'PROGA' USING A C.
CALL 'PROGB' USING B C.
CALL 'PROGC' USING A.
PROGA:
 
PROCEDURE DIVISION USING A C (we need to take care in each program)

PROGB

PROCEDURE DIVISION USING B C

PROGC

PROCEDURE DIVISION USING a


EXAMPLE 2 WITH POINTERS

Code:
WORKING-STORAGE SECTION.
01 A PIC X(100).
01 B PIC X(200).
01 c PIC x(300).
01 POINTER-ST.
  05 POINTERA
  05 POINTERB
  05 POINTERC

CALL 'PROGA' USING POINTER-ST.
CALL 'PROGB' USING POINTER-ST.
CALL 'PROGC' USING POINTER-ST.

PROGA:
LINKAGE-SECTION.
01 POINTER-ST..
  ..

01 A  ONLY DECLARE WHATEVER YOU NEED OUT OF ALL
01 B
 
PROCEDURE DIVISION USING POINTER-ST
SET ADDRESS OF A TO POINTERA
SET ADDRESS OF B TO POINTERB


There is a lot more 'relief' and less possibility of misalignment in the second method. icon_smile.gif
You have access to all data from main program but use what all you need!
But this is all IMHO. (Copyright Dick icon_lol.gif )

Please let me know if you think this as an advantage of pointers.
Sorry for lengthy post, but thought it was needed here. icon_smile.gif
Back to top
View user's profile Send private message
amiya_mf

New User


Joined: 01 Mar 2005
Posts: 19

PostPosted: Mon Apr 16, 2007 4:16 pm    Post subject: Your are right
Reply with quote

Hi Abhijit,

You are right. In my work area i am also finding the same type of programs. The main benefit here is that you can pass all but use as much you want thats right. but if we will see the address wise processing with pointer or without pointer the address of the data item is being passed between the programs..... am i correct ?



agkshirsagar wrote:
I had asked a similar question before, it was promptly moved to 'Off topics' . :(
I have observed some programs which call 100s of subprograms dynamically.
Now it is quite obvious that they pass huge number variables/structures to other subprograms.
We have to take care while 'aligning' passed parameters in the subprogram.
They should be declared in same order in the subprogram in linkage section.
This becomes cumbersome when there are large number of subprograms.

So by using pointers we pass all variables to every subprogram, now subprogram has the freedom to use it or not.
This appears very appealing when we consider maintainance of the programs in long term.
No problem in adding more subprograms with different data passed.

example 1:

Code:
WORKING-STORAGE SECTION.
01 A PIC X(100).
01 B PIC X(200).
01 c PIC x(300).

PROCEDURE DIVISION.
..
..
..
CALL 'PROGA' USING A C.
CALL 'PROGB' USING B C.
CALL 'PROGC' USING A.
PROGA:
 
PROCEDURE DIVISION USING A C (we need to take care in each program)

PROGB

PROCEDURE DIVISION USING B C

PROGC

PROCEDURE DIVISION USING a


EXAMPLE 2 WITH POINTERS

Code:
WORKING-STORAGE SECTION.
01 A PIC X(100).
01 B PIC X(200).
01 c PIC x(300).
01 POINTER-ST.
  05 POINTERA
  05 POINTERB
  05 POINTERC

CALL 'PROGA' USING POINTER-ST.
CALL 'PROGB' USING POINTER-ST.
CALL 'PROGC' USING POINTER-ST.

PROGA:
LINKAGE-SECTION.
01 POINTER-ST..
  ..

01 A  ONLY DECLARE WHATEVER YOU NEED OUT OF ALL
01 B
 
PROCEDURE DIVISION USING POINTER-ST
SET ADDRESS OF A TO POINTERA
SET ADDRESS OF B TO POINTERB


There is a lot more 'relief' and less possibility of misalignment in the second method. :)
You have access to all data from main program but use what all you need!
But this is all IMHO. (Copyright Dick :lol: )

Please let me know if you think this as an advantage of pointers.
Sorry for lengthy post, but thought it was needed here. :)
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 685
Location: Earth

PostPosted: Mon Apr 16, 2007 5:03 pm    Post subject:
Reply with quote

Quote:
You are right. In my work area i am also finding the same type of programs. The main benefit here is that you can pass all but use as much you want thats right. but if we will see the address wise processing with pointer or without pointer the address of the data item is being passed between the programs..... am i correct ?

yes! In both cases address is getting passed through the linkage section.
later approach passes pointer to these pointers. Only one pointer is getting passed (POINTER-ST is a pointer which points to set of pointers under it.)
Suppose
Address(A) = 1000
Now this address of A is stored in PointerA
Therefore content(PointerA) = 1000
and let Address(PointerA) = 4000
Now this 4000 will be passed to the linkage section.

If it creates lot of confusion for it then just leave it. You dont have to bother about the insides about how it works to use it ! icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts READQ TS returning inconsistent addre... moezbud CICS 14 Wed May 04, 2016 1:09 am
No new posts Display the hexadecimal address of a ... M_Kaiser COBOL Programming 12 Thu May 28, 2015 5:50 pm
No new posts Usage of pointer nilaksh92 COBOL Programming 2 Mon Mar 16, 2015 12:53 pm
No new posts Obtaining the address of Pointer in C... oerdgie COBOL Programming 7 Thu Oct 23, 2014 2:57 pm
No new posts Move Cursor position to the place bas... sakrat TSO/ISPF 4 Wed Feb 19, 2014 6:13 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us