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

Dynamically change VARIABLE name


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Tue Apr 12, 2011 9:32 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Apr 12, 2011 9:36 pm
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Apr 12, 2011 10:20 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts 3270 personal communications. Can't c... TSO/ISPF 2
No new posts SELECT from data change table DB2 5
Search our Forums:

Back to Top