Page 1 of 2

Access variable named inside another variable

PostPosted: Fri Jan 04, 2013 12:45 pm
by jkush
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.

Re: Access variable named inside another variable

PostPosted: Fri Jan 04, 2013 1:28 pm
by BillyBoyo
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

Re: Access variable named inside another variable

PostPosted: Mon Jan 07, 2013 5:04 pm
by jkush
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.

Re: Access variable named inside another variable

PostPosted: Mon Jan 07, 2013 5:16 pm
by BillyBoyo
Only by code.

You're going to have to work on the design. What is the purpose of this?

Re: Access variable named inside another variable

PostPosted: Mon Jan 07, 2013 5:53 pm
by Robert Sample
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.

Re: Access variable named inside another variable

PostPosted: Tue Jan 08, 2013 11:33 am
by jkush
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.

Re: Access variable named inside another variable

PostPosted: Tue Jan 08, 2013 4:50 pm
by Akatsukami
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.

Re: Access variable named inside another variable

PostPosted: Tue Jan 08, 2013 8:52 pm
by Robert Sample
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.

Re: Access variable named inside another variable

PostPosted: Tue Jan 08, 2013 9:44 pm
by Akatsukami
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.)

Re: Access variable named inside another variable

PostPosted: Tue Jan 08, 2013 10:55 pm
by dick scherrer
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?