Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading environment variables 3

Status
Not open for further replies.

butler

MIS
Oct 12, 1998
88
US
Hi all,

This seems like it should be easy, but I just can't get anything to work. How do you read operating system (AIX) environment variables in a Cobol (micro focus) program? Passing them as arguments at startup is not an option. I have been playing with the special names section and accept statement but am getting nowhere.

Help!
bill [sig][/sig]
 
Hi,

I don't know anything about AIX but in DOS you can before startup put the data into a file with:

SET > SET.OUT

and then all the environvariables are in the file SET.OUT which can be read in the COBOL program.

You mentioned the special-names. Micro Focus uses things like SWITCH-0 SWITCH-1 .... SWITCH-8.

Don't you have some examples from Micro Focus? They deliver always some programs with their system with for sure also something with accept and a screen section...

Sorry if this isn't any help!

[sig][/sig]
 
Thanks for the reply,

I was using the SYSTEM command to echo the environment variable into a file, and then read in the file. But this just didn't sit right with me. I was hoping for something a little cleaner.

I guess I'll just write a sub-program that accepts a variable name and returns the value, as stated above. Then I guess I could live with it - I guess. Out of sight, out of mind? ;)

Thanks again
bill [sig][/sig]
 
Got it!!!!!!!!

SPECIAL-NAMES.
ENVIRONMENT-NAME IS COMMAND
ENVIRONMENT-VALUE IS DIRECTORY
CONSOLE IS CRT.

(these need be set in the special names. It will give an error if you use ENVIRONMENT-NAME OR ENVIRONMENT-VALUE directly)

MOVE "TERM" TO MY-DIR-NAME.
DISPLAY MY-DIR-NAME UPON COMMAND.
ACCEPT MY-DIR-NAME FROM DIRECTORY.
DISPLAY MY-DIR-NAME.

This is backed by the X/Open standard and available across environments such as UNIX, DOS, OS/2 and Windows!!!

Thanks again!
bill


[sig][/sig]
 
Call me stupid but can you explain this a little more for me?

If I have an environment variable called $USER how do I pull this into the program using your solution.

Thanks,
Mark. [sig][/sig]
 
Try...

SPECIAL-NAMES.
ENVIRONMENT-NAME IS MY-ENV-NAME
ENVIRONMENT-VALUE IS MY-ENV-VALUE
CONSOLE IS CRT.
(note that the special names MY-ENV-NAME and MY-ENV-VALUE can be anything you want as long as it's not a reserved word. They do not need to be defined in working storage.)

WORKING-STORAGE SECTION.
01 MY-USER-NAME-VARIABLE PIC X(30).
01 MY-USER-NAME-VALUE PIC X(30).

PROCEDURE DIVISION.
MOVE "$USER" TO MY-USER-NAME-VARIABLE.
DISPLAY MY-USER-NAME-VARIABLE UPON MY-ENV-NAME.
ACCEPT MY-USER-NAME-VALUE FROM MY-ENV-VALUE.
(my-user-name-value will now hold the value of $USER)

Good luck!


[sig][/sig]
 
Okay, that's cool..

Is possible then, using the above concept, to then update the value of the environment variable?

cheers,
mark. [sig][/sig]
 
To set a variable...

MOVE "ANYVARNAME" TO MY-USER-NAME-VARIABLE.
DISPLAY MY-USER-NAME-VARIABLE UPON MY-ENV-NAME.
MOVE "any value" TO MY-USER-NAME-VALUE.
DISPLAY MY-USER-NAME-VALUE UPON MY-ENV-VALUE.

bill [sig][/sig]
 
I know it is years since this thread was current, but I have the same problem though with IBM cobol on AIX (not MicroFocus).
The solution proposed:

SPECIAL-NAMES.
ENVIRONMENT-NAME IS ENV-NAME
ENVIRONMENT-VALUE IS ENV-VALUE
CONSOLE IS CRT.

gives errors:
25 IGYDS1325-E The "ALPHABET" clause did not start with the "ALPHABET"
keyword. The clause was accepted.
Same message on line: 26
25 IGYDS1254-S "ENV-NAME" was found in the "ALPHABET" clause but was not
recognized as an implementor-name. The associated
alphabet-name was discarded.
26 IGYDS1254-S "ENV-VALUE" was found in the "ALPHABET" clause but was
not recognized as an implementor-name. The associated
alphabet-name was discarded.
etc etc etc

Does this mean that I have to import environment variables via a piped file, or is there another direct way?

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top