IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to Use table value as a a variable.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Roshnii

New User


Joined: 30 Sep 2008
Posts: 45
Location: bangalore

PostPosted: Mon Mar 22, 2010 11:33 pm
Reply with quote

I have to compare the results of two variables.
The name of one of the variable will be present in a table. How can I use the variable name stored in the table for the calculation purpose?

Eg. Comarison should be done with Var A and Var B.
And the name of Var A is stored in a table. Say Var A is PHONE-NUM.

So the comaparison that I need to do is
IF PHONE-NUM = VAR B.

How can I use the value stored in the tble as the variabke name that I use for comparison?

I hope my question is clear.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Tue Mar 23, 2010 12:10 am
Reply with quote

Remember that COBOL is a compiled language. If you want a statement to read
Code:
IF  PHONE-NUM = VARB
then the compiler must compile the statement before execution of the program. If the table is not known until run time, then you are wanting to mix compile-time and run-time which is not possible in COBOL.

If the table is fixed at compile time, you could probably cobble up some reference modification to do something similar. Or you could write a COBOL program whose sole purpose is to generate the COBOL code you want, run the output of your program through the COBOL compiler, and proceed from there.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Tue Mar 23, 2010 12:19 am
Reply with quote

As I've noted before, I'm not a COBOL programmer. In PL/I, though, I'd create a table with two fields in each entry; a CHAR(n) (= PIC X(n, IIRC) for variable name, and a POINTER (not sure what the COBOL equivalent would be) set to the address of the variable. Presumably something similar can be done in contemporary COBOL.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Mar 23, 2010 12:30 am
Reply with quote

Hello,

Quote:
How can I use the variable name stored in the table for the calculation purpose?
Do you mean an array within the code or a database table?

If this is an array within the code, is it always the same or does the content change from run to run?

How does "calculation" relate?

If you post an example of what you "have" and how you want your process to work, someone may have a suggestion.
Back to top
View user's profile Send private message
Roshnii

New User


Joined: 30 Sep 2008
Posts: 45
Location: bangalore

PostPosted: Tue Mar 23, 2010 12:50 am
Reply with quote

I have to compare the two variables. And the variable that I will have to compare will be present in the table.

So the value can change from run to run.

Example: The table will contain PHONE-NUM.
So when I read the table, and get the PHONE-NUM,
I need to compare the PHONE-NUM.
I prefix some key words with the variable name present in the table like this:
OLD-PHONE-NUM = NEW-PHONE-NUM?

And the value of OLD-PHONE-NUM and NEW-PHONE-NUM will be present with me.

I hope the the queston is clear.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Mar 23, 2010 1:15 am
Reply with quote

Hello,

Quote:
I hope the the queston is clear.
Unfortunately, not yet. Keep in mind that your question is completely clear to you, but may not be clear to people who read the request.

Quote:
So when I read the table, and get the PHONE-NUM
Show the code that does this.

Quote:
I need to compare the PHONE-NUM.
Against what?

Quote:
I prefix some key words with the variable name present in the table like this:
OLD-PHONE-NUM = NEW-PHONE-NUM?
Ok, but i'm confused how this relates to the "table" and the "other variable".

Quote:
And the value of OLD-PHONE-NUM and NEW-PHONE-NUM will be present with me.
Show how this is accomplished.

It is really not clear what you "have" and how you want to work with what you have. . .
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Tue Mar 23, 2010 4:01 pm
Reply with quote

there is no such thing as "interpret" in cobol

You could try with a table with offsets of some kinds (like Robert said), but I would not recommend it, because maintaining this kind of table is hell.

Code:
01 in-Rec.
   03 name    x(30).
   03 phone   x(12).
   03 city    x(20).

01 Ws-tab-val.
   03 pic x(24) value 'NAME          0130'.
   03 pic x(24) value 'PHONE         3112'.
   03 pic x(24) value 'CITY          4320'.
01 ws-tab.
   03 ws-var occurs 3.
      05 ws-var-name pic x(20).
      05 ws-strt pic 99.
      05 ws-len  pic 99.



or some very long evaluate where you write each possible condition.
Code:
evaluate ws-var-name also ws-var-B
when 'PHONE' also PHONE
...
when 'NAME' also NAME
...
when 'CITY' also CITY
...
end-evaluate


Pointers in cobol isn't quite as good as in other languages.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Load new table with Old unload - DB2 DB2 6
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Multiple table unload using INZUTILB DB2 2
No new posts Check data with Exception Table DB2 0
Search our Forums:

Back to Top