IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

What is the benefit of using pointer?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
amiya_mf

New User


Joined: 01 Mar 2005
Posts: 18

PostPosted: Thu Apr 05, 2007 4:22 pm
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: 3156
Location: Tucson AZ

PostPosted: Thu Apr 05, 2007 5:22 pm
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
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: 3156
Location: Tucson AZ

PostPosted: Thu Apr 05, 2007 9:19 pm
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
Reply with quote

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

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: 691
Location: Earth

PostPosted: Thu Apr 05, 2007 10:54 pm
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: 148
Location: Ottawa Canada

PostPosted: Fri Apr 06, 2007 12:05 am
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
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: 22
Location: Pune, India

PostPosted: Fri Apr 06, 2007 2:18 pm
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: 18

PostPosted: Mon Apr 09, 2007 6:04 pm
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: 18

PostPosted: Mon Apr 09, 2007 6:09 pm
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: 3156
Location: Tucson AZ

PostPosted: Mon Apr 09, 2007 6:36 pm
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: 18

PostPosted: Tue Apr 10, 2007 5:04 pm
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
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: 691
Location: Earth

PostPosted: Fri Apr 13, 2007 7:33 pm
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: 18

PostPosted: Mon Apr 16, 2007 4:16 pm
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: 691
Location: Earth

PostPosted: Mon Apr 16, 2007 5:03 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
No new posts Can we pass cobol pointer to cobol-db... DB2 4
No new posts READQ TS returning inconsistent addre... CICS 14
No new posts Display the hexadecimal address of a ... COBOL Programming 12
No new posts Usage of pointer COBOL Programming 2
Search our Forums:

Back to Top