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
 

 

Dynamically change VARIABLE name

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

New User


Joined: 03 Dec 2010
Posts: 87
Location: India

PostPosted: Tue Apr 12, 2011 9:29 pm    Post subject: Dynamically change VARIABLE name
Reply with quote

Hi

Let's say I have following variable names :
Code:

VARIABLE-1,
VARIABLE-2,
VARIABLE-3,
VARIABLE-4

Now within the COBOL program I want to do something like this :

A variable 'X' is defined with value equal to 1
And,
I perform this :
Code:

MOVE VARIABLE-X = TEMP-VAR

Here X must be replaced with the value of X(that is, 1), so that value of VARIABLE-1 will be moved to TEMP-VAR.
Then I will increment the value of X by 1 and continue.

Can this be achieved using COBOL ?

Please guide me.

Any help is highly appreciated.
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7254

PostPosted: Tue Apr 12, 2011 9:32 pm    Post subject:
Reply with quote

First, look up the MOVE statement in the Cobol manual (see link at the top). Then look up OCCURS, subscripts and indexes. If you get stuck, there is a begginers forum available.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10211
Location: italy

PostPosted: Tue Apr 12, 2011 9:36 pm    Post subject: Reply to: Dynamically change VARIABLE name
Reply with quote

Quote:
Can this be achieved using COBOL ?

Please guide me.

Any help is highly appreciated.

NO! ( not at least the way You asked )

unless ( I do not speak cobolese ) You can redefine the variables over an array

so that VAR1 corresponds to ARRAY(1)
VAR2 to ARRAY(2) and so on
at this point when You assign something to ARRAY(i) the You can also retrieve the value using VARi

but the whole thing does not make much sense.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7935
Location: Bellevue, IA

PostPosted: Tue Apr 12, 2011 10:20 pm    Post subject:
Reply with quote

You need to learn that COBOL is a compiled language. As such, all variable references are fixed at compile time. There is no way, at run time, to modify COBOL code that has been compiled. You can use arrays as suggested by others to accomplish something similar to what you ask, but the direct answer to your question is that no, once the program has been compiled there is no way to change any source statements in any way, shape, style, or form.
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 Fail to change physical VSAM filename... jacobdng CICS 7 Fri Jan 20, 2017 12:36 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
No new posts Change date (DD/MM/YY) in 2nd record ... uday kiran DFSORT/ICETOOL 12 Wed Sep 07, 2016 10:57 pm
No new posts how to DYNAMICALLY write sort cond to... mohamedmubee COBOL Programming 13 Fri Aug 26, 2016 11:46 pm
No new posts PL/I: opening file w/ dynamically det... Sam Dodgers PL/I & Assembler 6 Wed Jul 27, 2016 4:05 pm


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