View previous topic :: View next topic
|
Author |
Message |
SathyaS
New User
Joined: 20 Sep 2005 Posts: 11
|
|
|
|
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 |
|
|
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
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 |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi Prav06,
But the picture clause of these variable are different |
|
Back to top |
|
|
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
Oops!!!! ... My mistake |
|
Back to top |
|
|
prav_06 Warnings : 1 Active User
Joined: 13 Dec 2005 Posts: 154 Location: The Netherlands
|
|
|
|
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 |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
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 |
|
|
nileshp
New User
Joined: 25 Feb 2006 Posts: 31
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
jasorn Warnings : 1 Active User
Joined: 12 Jul 2006 Posts: 191 Location: USA
|
|
|
|
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 |
|
|
|