Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
techslam

New User

Joined: 03 Dec 2010
Posts: 87
Location: India

Posted: Tue Apr 12, 2011 9:29 pm    Post subject: Dynamically change VARIABLE name

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 ?

Any help is highly appreciated.

Bill Woodger

DFSORT Moderator

Joined: 09 Mar 2011
Posts: 7314

 Posted: Tue Apr 12, 2011 9:32 pm    Post subject: 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.
enrico-sorichetti

Global Moderator

Joined: 14 Mar 2007
Posts: 10457
Location: italy

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

 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.
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8280
Location: Dubuque, Iowa, USA

 Posted: Tue Apr 12, 2011 10:20 pm    Post subject: 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.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Repeat Sequence Number Until change i... rahulabvp DFSORT/ICETOOL 6 Thu Mar 29, 2018 12:51 pm Creation of Datasets dynamically on t... Raghu M N DFSORT/ICETOOL 8 Fri Mar 16, 2018 12:56 am How to change the logon screen info o... sakthikumarT TSO/ISPF 4 Fri Dec 29, 2017 6:44 pm Change NULL indicator in UNLOAD utility Khadhar Basha DB2 2 Fri Dec 15, 2017 3:01 pm Moving a COMP-3 Variable to a Numeric... ajayachander COBOL Programming 2 Thu Dec 14, 2017 5:46 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us