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

Data Moving by using COBOL pointer variables


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

New User


Joined: 02 Aug 2011
Posts: 17
Location: India

PostPosted: Wed Sep 14, 2011 2:18 pm
Reply with quote

Hi All,

I have two variables with data as below.

01 WS-AB PIC X(02) VALUE 'AB'.
01 WS-CD PIC X(02) VALUE 'CD'.
I like to refer data 'CD' to variable WS-AB by using cobol pointers.

Please let me know how can I achieve this.

Thanks
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Sep 14, 2011 2:31 pm
Reply with quote

It is unclear from your description what it is that you want.

Why do you want to do it?

What do you want to achieve?

What is wrong with MOVE?
Back to top
View user's profile Send private message
Eshwar CICS

New User


Joined: 18 May 2011
Posts: 47
Location: India

PostPosted: Wed Sep 14, 2011 2:36 pm
Reply with quote

Are the variables which you have mentioned reside in working storage?
Back to top
View user's profile Send private message
satishboddu

New User


Joined: 02 Aug 2011
Posts: 17
Location: India

PostPosted: Wed Sep 14, 2011 3:02 pm
Reply with quote

Hi All,

I have two variables with data as below.

01 WS-AB PIC X(02) VALUE ‘123’.
01 WS-CD PICX(02) VALUE ‘345’
01 WS-F PIC X(08) VALUE.

MOVE “WS-AB” to WS-F, is populated in another program.

Based on variable name that’s in WS-F, we want to retrieve the value of that variable.
Suppose, we have WS-AB as variable in WS-F, we need 123 and if WS-CD in the variable, we are looking for 345.

I have heard pointers can be used to do this.

Please suggest ..
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10833
Location: italy

PostPosted: Wed Sep 14, 2011 3:17 pm
Reply with quote

since in any case You have to use an if to <load> the pointer with the proper address why bother
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Sep 14, 2011 3:27 pm
Reply with quote

There is no fancy way to dynamically obtain the address/contents of a Cobol data-name from a piece of text.

Test the value of the text, and code out the MOVEs for the appropriate value.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Sep 14, 2011 4:26 pm
Reply with quote

another case of pc language skills - not able to read the manual.

cobol resolves the contents of areas indirectly addressed by use of pointers.

cobol always treats the contents of a variable as the contents of a variable.

cobol treats the contents of a pointer as the address of a variable.

that is the way that it is done.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Sep 14, 2011 4:38 pm
Reply with quote

Using POINTER's to address WS fields was not introduced until OS/390 COBOL 2.2.1, about 10-12 years ago.

If your COBOL version/release is less than the above, then you're out of luck.

Mr. Bill
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Sep 14, 2011 5:29 pm
Reply with quote

Bill,
you are correct.

COBOL 2 still disallows SETing a POINTER TO ADDRESS OF Variable in W-S.

but, you can CALL a module with two parms in the using list:
W-S
POINTER

and the CALLed module simply SETs the POINTER in linkage TO ADDRESS OF Variable in linkage,
and returns.
Back to top
View user's profile Send private message
Eshwar CICS

New User


Joined: 18 May 2011
Posts: 47
Location: India

PostPosted: Wed Sep 14, 2011 5:37 pm
Reply with quote

Satish,

My opinion is that compiler has no role to play in this context.Basically get clarity on how working storage gets allocated and understand how pointers can be used in COBOL w.r.t linkage variables.Then you can decide on the feasibility of implementing your requirement. Thanks.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Sep 14, 2011 7:38 pm
Reply with quote

Dick,

Yes, you're right.

Many moons ago, had both an Assembler sub-program and COBOL sub-program which did this.

But to tell you the truth, I still don't know what the OP is trying to accomplish.

If the concept of obtaining addresses and traversing control blocks is foreign to the OP, my suggestion is to stay away from this and KISS.

As Bill W. expressed, what's wrong with a MOVE?

Mr. Bill
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Sep 14, 2011 8:01 pm
Reply with quote

you can do that kind of silliness in java, c, c+, vb.
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 Cobol prog to put an indicator on the... JCL & VSAM 1
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
No new posts COBOL program logic for comparisipn o... COBOL Programming 2
No new posts Split a record with data in a differe... DFSORT/ICETOOL 8
No new posts COBOL - create and write to output fi... COBOL Programming 0
Search our Forums:

Back to Top