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 Use table value as a a variable.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to Use table value as a a variable.
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: 7936
Location: Bellevue, IA

PostPosted: Tue Mar 23, 2010 12:10 am    Post subject:
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: 1746
Location: Bloomington, IL

PostPosted: Tue Mar 23, 2010 12:19 am    Post subject:
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

Site Director


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

PostPosted: Tue Mar 23, 2010 12:30 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue Mar 23, 2010 1:15 am    Post subject:
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: 1278
Location: Belgium

PostPosted: Tue Mar 23, 2010 4:01 pm    Post subject:
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    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 SQL query to run through list of valu... Ni3-db2 DB2 14 Wed Dec 14, 2016 9:52 am
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
No new posts Command UNIQUE CONSTRAINT on any tabl... rohanthengal DB2 2 Thu Aug 18, 2016 3:48 pm
No new posts Updating online Db2 table kishpra DB2 3 Fri Aug 12, 2016 2:44 pm


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