Variable names in text strings 
Author Message
 Variable names in text strings

Hello Everyone,

I am using Micro Focus COBOL in SCO OpenServer.
If I have the name of a variable in a text string (the value
of another variable), is there any way to then get or use its value?
I have a paragraph that needs to be used the same way
on several different variables, and there is not an opportunity
to move anything to a work variable for that function before
performing it.  I do have a way while in the paragraph to
get the names of those variables as text strings.

Thanks.



Fri, 06 Jun 2003 23:09:00 GMT  
 Variable names in text strings
This is DEFINITELY not a direct answer to the coding issue that you ask
about, but it *might* provide a way to do what you want.

Have you looked at "nested programs"?  If you pass the "relevant" variables
from each location to the nested program, it could do the "common" action.
If there is a "medium small" number of fields that might need this action,
you could code something like:

  Evaluate Variable-name
   When "field1"
      Call Nested-Pgm Using Field1
    When "field2"
       Call Nested-Pgm Using Field2
         ...
     When Other
        Display "unknown field"
   End-Evaluate

--
Bill Klein
 wmklein <at> ix.netcom.com

Quote:
> Hello Everyone,

> I am using Micro Focus COBOL in SCO OpenServer.
> If I have the name of a variable in a text string (the value
> of another variable), is there any way to then get or use its value?
> I have a paragraph that needs to be used the same way
> on several different variables, and there is not an opportunity
> to move anything to a work variable for that function before
> performing it.  I do have a way while in the paragraph to
> get the names of those variables as text strings.

> Thanks.



Sat, 07 Jun 2003 01:58:41 GMT  
 Variable names in text strings
Thanks, but calling a subprogram will not work in this case.
This might seem a little strange, but in this case I need to
use a "PERFORM" for this routine and not a "CALL".

---Hillel



Sat, 07 Jun 2003 03:06:43 GMT  
 Variable names in text strings
My next suggestion is even MORE of a stretch.  Partially, I don't fully
understand why you don't move the "relevant" fields to a working-copy,
Perform the "logic" and then move the working copy back to the original.
However, if there is a reason for avoiding this, let me try another (fairly
obscure) method - that relies on an extension that your compiler PROBABLY
has.

1) Define a field in Linkage Section (but don't put it in your Procedure
Division USING statement) that can "hold" the actual data to be processed.

2) Where (in your logic) you want to perform the "common logic" - place a
    Set Address of Linkage-Section-Item to Address of Real-Item (using an
EVALUATE as in my first example to figure out which data-item to use)
    Perform logic-routine (working on the Linkage Section "copy" of the
data)

     ***

After this is performed the "original" item will already be "modified" to
the new value.

--
Bill Klein
 wmklein <at> ix.netcom.com

Quote:
> Thanks, but calling a subprogram will not work in this case.
> This might seem a little strange, but in this case I need to
> use a "PERFORM" for this routine and not a "CALL".

> ---Hillel



Sat, 07 Jun 2003 03:24:13 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Using a variable name for a variable name??

2. Procedure name in a string variable

3. Using variable names as strings

4. treating variable names as strings (NEWBIE)

5. String to Variable Name Mapping

6. Appending text to a variable name

7. Variable name -> string

8. creating variable names by adding 2 strings?

9. how to convert variable name to a string?

10. string to variable name

11. More About Array Names In String Variables

12. TEXT entry field for String variable

 

 
Powered by phpBB® Forum Software