Access variable named inside another variable



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Access variable named inside another variable

Postby jkush » Fri Jan 04, 2013 12:45 pm

We were looking to implement following functionality with the help of COBOL code.

Consider following variables

Var1 PIC X(5)
Var2 PIC X(5)
Var3 PIC X(5)
Var4 PIC X(5)

We have a variable name as the content of another variable. For example Var1 contains ‘Var2’.
Now using Var1 we would like to move some data in Var2. We would like to execute something like

Move ‘abcd’ to Contentof(Var1)

The variable name inside Var1 may change on the run time and will be input from the CICS terminal. We were wondering would it be possible to achieve above stated functionality with Cobol code. It seems it would not be possible to compile link such dynamic piece of code but we still wanted to take other opinions if you feel its achievable.
jkush
 
Posts: 6
Joined: Sat Nov 05, 2011 10:06 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Access variable named inside another variable

Postby BillyBoyo » Fri Jan 04, 2013 1:28 pm

EVALUATE TRUE
  WHEN VAR1 EQUAL TO "VAR2"
...
  WHEN VAR1 EQUAL TO "VAR3"
...
  WHEN VAR1 EQUAL TO "VAR4"
...
  WHEN OTHER
    send a message to the screen for failure
END-EVALUATE
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Access variable named inside another variable

Postby jkush » Mon Jan 07, 2013 5:04 pm

Thanks for the response. But above scenario with only 4 variables was just to illustrate the issue. What we are trying to implement is on a pretty large scale. There are around 100 copybooks with atleast 50 fields each. The content of var1 above can be any these 5000+ variables. Thats why we were looking for an option without hardcoding scenario of each and every possibility. Please let me know if you feel this can be achieved.
jkush
 
Posts: 6
Joined: Sat Nov 05, 2011 10:06 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Access variable named inside another variable

Postby BillyBoyo » Mon Jan 07, 2013 5:16 pm

Only by code.

You're going to have to work on the design. What is the purpose of this?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Access variable named inside another variable

Postby Robert Sample » Mon Jan 07, 2013 5:53 pm

You are confusing execution code with compile code. Other than explicitly providing data at compile time as BillyBoyo suggested, what you are wanting to do, in general, is not possible in COBOL. There is no support for indirect addressing of data in COBOL. Your options are to come up with another approach, use a different language that does support what you want to do, or accept that your design is flawed and give up on the idea. Your choice.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Access variable named inside another variable

Postby jkush » Tue Jan 08, 2013 11:33 am

I really appreciate your valuable inputs. We also felt the same way that this may not be achievable thru cobol but just wanted to get inputs from more experienced members. We just wanted to be sure that we are not missing anything. The purpose of this design is to create a new CICS transaction that will allow user to update the content of any of the fields on our database. We use VSAM file to store our data and every record and contain many fields. We were exploring the possibility of letting the user update any field on the whole record. To achieve that we are planning to take the field name and its respective value as inputs from the user and then we were trying to update the same on VSAM. But both these inputs were available to us in form of variables and thats why we were stuck with above problem. We do no use CICS maps and are trying to use CICS screens to achieve this. Please let me know if you have any other approach in mind to get this done. Thanks a ton for sparing your valauable time.
jkush
 
Posts: 6
Joined: Sat Nov 05, 2011 10:06 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Access variable named inside another variable

Postby Akatsukami » Tue Jan 08, 2013 4:50 pm

My shop has a similar tool (that I had no part in writing, so I can't assist with the details). Basically, it "maps" fields (FOO is on segment BAR, position 51, length 5, format packed decimal). Note that this solution requires at least one of:

  • A team of people technical enough to perform the mapping by hand
  • The re-creation of a portion of the compiler
  • A tool capable of extracting the necessary information from the compile listings
Think of it as reproducing the DB2 SYSCOLUMNS table.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Access variable named inside another variable

Postby Robert Sample » Tue Jan 08, 2013 8:52 pm

Depending upon the amount of effort your company is willing to invest, you could generate (from compile listing or copy book or whatever) a file that has the VSAM file name and for each variable the name, starting position, length, and type of data the variable contains. This would allow you to use reference modification to perform moves. However, the front-end work to set everything up could wind up being substantial.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Access variable named inside another variable

Postby Akatsukami » Tue Jan 08, 2013 9:44 pm

Robert Sample wrote:Depending upon the amount of effort your company is willing to invest, you could generate (from compile listing or copy book or whatever) a file that has the VSAM file name and for each variable the name, starting position, length, and type of data the variable contains. This would allow you to use reference modification to perform moves. However, the front-end work to set everything up could wind up being substantial.

Yes; creation of our tool required nearly 20,000 person-hours! (Not, to be sure, solely for coding and testing.)
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Access variable named inside another variable

Postby dick scherrer » Tue Jan 08, 2013 10:55 pm

Hello,

Is the data all stored in VSAM?

How often will this be used? Would it be acceptable if the user request was actually run in batch?

Does your system use Easytrieve?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post