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
 

 

How to get the value of a variable-the name is in a variable

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

New User


Joined: 20 Sep 2005
Posts: 11

PostPosted: Wed Feb 14, 2007 4:54 pm    Post subject: How to get the value of a variable-the name is in a variable
Reply with quote

Hi,
We have a COBOL code with variables declared as:

WS-TEST1 PIC X(5)
WS-TEST2 PIC X(8)
WS-TEST3 PIC X(4)
.
.
.
WS-TEST100 PIC X(2)

The code has logic to populate all of these 100 variables (say it gets them from a file).

REQUIREMENT:
We want some mechanism by which if we pass the SYSIN as WS-TEST1 the code should display the value stored in WS-TEST1 variable alone.

SOLUTION?
One way to achieve this is:
ACCEPT WS-INPUT
IF WS-INPUT = ?WS-TEST1?
DISPLAY WS-TEST1
IF WS-INPUT = ?WS-TEST2?
DISPLAY WS-TEST2
and so on?

But this means we have to hardcode 100 conditions; and if the copybook for the file changes then we have to change the IF conditions.

Is there any other way to get the value displayed without hardcoding??
Back to top
View user's profile Send private message

prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Wed Feb 14, 2007 5:21 pm    Post subject:
Reply with quote

Hi Sathya,
U can use a table in order to do this, only if your variables are in a sequnce like u have mentioned
Code:
WS-TEST1 PIC X(5)
WS-TEST2 PIC X(8)
WS-TEST3 PIC X(4)
.
.
.
WS-TEST100 PIC X(2)

u can subscript the variable names as ws-test is 1 and ws-test2 is 2, so if ya give the subscript value inside your sysin dd * statement it would display the content of the same, I think this logic is better than hard coding all the 100 variable names.

Cheer's,

Thamilzan.
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Wed Feb 14, 2007 5:23 pm    Post subject:
Reply with quote

Hi Prav06,

But the picture clause of these variable are different
Back to top
View user's profile Send private message
prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Wed Feb 14, 2007 5:29 pm    Post subject:
Reply with quote

Oops!!!! icon_rolleyes.gif ... My mistake
Back to top
View user's profile Send private message
prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Wed Feb 14, 2007 5:36 pm    Post subject:
Reply with quote

guptae,
How about implementing the same logic that i had told, by defining the array of uniform size say x(8) which is the max. that has been posted in the variables
WS-TEST1 PIC X(5)
WS-TEST2 PIC X(8)
WS-TEST3 PIC X(4)
.
.
.
WS-TEST100 PIC X(2)

and moving the values of the variable to the elements of the array and then going thro.



Cheer's,

Thamilzan.
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Wed Feb 14, 2007 5:43 pm    Post subject:
Reply with quote

Hi Thamilzan,

This way it can be done ...by taking max size...

but again he need to load value of the variables individually bcoz they are coming from file
Back to top
View user's profile Send private message
nileshp

New User


Joined: 25 Feb 2006
Posts: 31

PostPosted: Mon Feb 26, 2007 6:00 pm    Post subject: Re: How to get the value of a variable-the name is in a vari
Reply with quote

Hi,
I this we can use "EVALUATE" to fulfill your need.
Lets consider following assumption

1)you r passing variable "WS-INPUT" from your JCL.
2) Accept it in the dataitem WS-INPUT
3) Use EVALUATE verb as follow

EVALUATE WS-INPUT
WHEN "WS-TEST1"
Display "WS-TEST1" WS-TEST1
.
.
.
.
WHEN OTHER
CALL error-proc
END-EVALUATE;


Regards
Nilesh Padwal
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Feb 26, 2007 9:56 pm    Post subject:
Reply with quote

Hello,

How does data get into the variables?

If this same code "reads" something to load the variables, creating the variables the "max" length and redefining them as an array may work well. When the variables are loaded with data any issues of leading/trailing spaces/zeros could be dealt with as well as left/right justification.

Once the variables are built, they could be retrieved by using the input "field-name" as a "pointer". This will only work if the field-names always end with the relative field number.

Another approach would be to build variables in an array with 3 fields - one for field-name, one for actual data length, and one for the data (all of the data would be fixed at the longest valid length). You could then accept the "runtime field name" and look for it in the table. Once found, you could use the length of that field in a reference-modified move to move the data to "display" the data. To use this approach, i'd recommend making sure that all of the variables were loaded into the table left-justified and blank filled.
Back to top
View user's profile Send private message
jasorn

Active User


Joined: 12 Jul 2006
Posts: 153
Location: USA

PostPosted: Wed May 09, 2007 7:54 am    Post subject:
Reply with quote

I've been doing this kind of thing for years. Here's how I do it.
1. I wrote a program that reads a copybook and creates a different kind of copybook (meta data is the word I suppose). It has things like field name, start and stop positions, data type, etc.

2. Then I read that into an array in the program and use it instead of the copybook. Then you can use the field name in the logic. If you couple this with logic that lets you read different lrecls(i.e. record contains 0) you can have a nice utility that will work for all sorts of files as long as the field name in the metadata file matches.

You don't need the program in 1 if you don't mind creating the meta data file by hand.
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 Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 11 Tue May 16, 2017 2:20 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Writing on to GSAM variable length rohanthengal JCL & VSAM 6 Fri Mar 03, 2017 7:46 pm
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm


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