Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to use ENVIRONMENT-NAME on Microfocus COBOL

1,292 views
Skip to first unread message

Joshua Hall

unread,
Mar 10, 1998, 3:00:00 AM3/10/98
to

Hi there,

I'm actually using HP-UX COBOL, But it's just a re-badging of MF COBOL
for Unix.

What I want to do is get a Unix environment variable into my COBOL
program. I stumbled across ENVIRONMENT-NAME & ENVIRONMENT-VALUE in the
manuals, but no examples!

If anyone can help me by providing an example of how to use this, I
would be most appreciative.

Oh, if possible, can you also please 'CC' me at work on ha...@anz.com

Ta muchly,

Regards, -Josh Hall-


William M. Klein

unread,
Mar 10, 1998, 3:00:00 AM3/10/98
to

The following is an example of a COBOL program using the X/Open syntax for
getting and setting environment variables. (This program uses the MF
extension that allows you to use the mnemonics in the Procedure Division.
If you don't have MF, you would need to define them in a Special-Names
paragraph.)

Identification Division.
Program-Id. CobEnv.
* This program was written to demonstrate the syntax originally
* developed by X/Open to read and set environment variables
* from a COBOL program.
Data Division.
Working-Storage Section.
01 Env-Values.
05 Env-DoW Pic X(10).
05 Env-Type Pic X(10).
Procedure Division.
Mainline.
* The following two lines read the value contained in the
* environment variable "whatday"
Display "whatday" upon environment-name
Accept Env-DoW from environment-value
Evaluate Function Upper-Case(Env-DoW)
When "MONDAY"
When "TUESDAY"
When "WEDNEDAY"
When "THURSDAY"
When "FRIDAY"
Move "WeekDay" to Env-Type
When "SATURDAY"
When "SUNDAY"
Move "WeekEnd" to Env-Type
When Other
Move "unknown" to Env-Type
End-Evaluate
* The following two lines update the environment variable
* "whattype" indicating what type of day it is.
Display "whattype" upon environment-name
Display Env-Type upon environment-value
* The following line shows the user what environment value
* was set
Display Env-Type upon console
Goback.


--
+ +
+ Bill Klein -
"C" is a nice letter to START the name of your programming language
with
but I wouldn't want to end up there.

Joshua Hall wrote in message <350500B4...@ozonline.com.au>...

Gael Wilson

unread,
Mar 10, 1998, 3:00:00 AM3/10/98
to

Joshua,

All you should need to do is

DISPLAY env-name UPON ENVIRONMENT-NAME
ACCEPT env-val FROM ENVIRONMENT-VALUE

Where env-name is the name of the environment variable you are interested
in, and env-val is a buffer to contain its value.

Hope this helps.

Joshua Hall <j...@ozonline.com.au> wrote in article

Kevin Digweed

unread,
Mar 10, 1998, 3:00:00 AM3/10/98
to j...@ozonline.com.au

Joshua Hall wrote:
> What I want to do is get a Unix environment variable into my COBOL
> program. I stumbled across ENVIRONMENT-NAME & ENVIRONMENT-VALUE in the
> manuals, but no examples!
>
> If anyone can help me by providing an example of how to use this, I
> would be most appreciative.

Hi Josh.

DISPLAY "var-name" UPON ENVIRONMENT-NAME
ACCEPT env-var-pic-x FROM ENVIRONMENT-VALUE
DISPLAY env-var-pic-x UPON ENVIRONMENT-VALUE

If you have a web browser, go to http://www.dejanews.com/home_ps.shtml
Once there, type "comp.lang.cobol" into the "newgroups" box and
"ENVIRONMENT-NAME" into the "search" box. You should be presented with
25+ articles, some of which contain the examples you were looking for.

Cheers,
Kev.

PS. I think that *everyone* who has a specific question related to a
language construct (or of the "How do I make my "Blah" database
system work with COBOL ?" variety) should first check DejaNews as
well as the FAQ.

In this case, it would have saved you waiting for a response.

Bill - could you add something along these lines to the FAQ ? I think
it's unreasonable for you to add each and every language query like
this to the FAQ (you'll end up with a Language Reference Manual
eventually :)), but they do crop up occaisionally and they are all
archived at DejaNews.

Bernd Dormann

unread,
Mar 10, 1998, 3:00:00 AM3/10/98
to

Hi Joshua,

here is a short example

Shell script:

DD_PRTF02=$MRS_ROOT/log/$JOB/$TIMESTAMP/ERROR.dat; export DD_PRTF02

Program:

SELECT PROTOKOLL ASSIGN TO "PRTF02"

I hope this helps

Bye
Bernd

Joshua Hall <j...@ozonline.com.au> schrieb im Beitrag


<350500B4...@ozonline.com.au>...
> Hi there,
>
> I'm actually using HP-UX COBOL, But it's just a re-badging of MF COBOL
> for Unix.
>

> What I want to do is get a Unix environment variable into my COBOL
> program. I stumbled across ENVIRONMENT-NAME & ENVIRONMENT-VALUE in the
> manuals, but no examples!
>
> If anyone can help me by providing an example of how to use this, I
> would be most appreciative.
>

francis...@ag.be

unread,
Mar 17, 1998, 3:00:00 AM3/17/98
to

In article <350500B4...@ozonline.com.au>, j...@ozonline.com.au wrote:
> > Hi there, > > I'm actually using HP-UX COBOL, But it's just a
re-badging of MF COBOL > for Unix. > > What I want to do is get a Unix
environment variable into my COBOL > program. I stumbled across
ENVIRONMENT-NAME & ENVIRONMENT-VALUE in the > manuals, but no examples! > >
If anyone can help me by providing an example of how to use this, I > would
be most appreciative. > > Oh, if possible, can you also please 'CC' me at
work on ha...@anz.com > > Ta muchly, > > Regards, -Josh Hall- > > Find
here a sample of production code I use under DOS and Win95.
*---------------------------------------------- * POUR VARIABLES
D'ENVIRONNEMENT *---------------------------------------------- 01
IW-LEVTVAR PIC X(256). 01 IW-COBCPY-OLD PIC X(256). 01 IW-COBCPY-NEW
PIC X(256). 01 IW-PATH-RTSWB PIC X(256). This code is reading the
variable COBCPY SAUVER-ANCIEN-COBCPY. *
-------------------------------------------------- * ADAPTATION DE LA
VARIABLE D'ENVIRONNEMENT COBCPY * CAR LE SIGLE APPLICATION EST VARIABLE
* -------------------------------------------------- DISPLAY "COBCPY" UPON
ENVIRONMENT-NAME ACCEPT IW-LEVTVAR FROM ENVIRONMENT-VALUE MOVE IW-LEVTVAR
TO IW-COBCPY-OLD . This code is writting the variable COBCPY
POSITIONNER-COBCPY. MOVE SPACE TO IW-COBCPY-NEW STRING "C:\CWB\CPY;"
IW-DRIVE-APPLICATION ":\" IW-APPLICATION "\T000\COPY;" DELIMITED BY SIZE
INTO IW-COBCPY-NEW DISPLAY "COBCPY" UPON ENVIRONMENT-NAME DISPLAY
IW-COBCPY-NEW UPON ENVIRONMENT-VALUE I hope it 'll help you ! Have a nice
day. Francis...@AG.BE

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading

Ferhat Hajdarpasic

unread,
Mar 18, 1998, 3:00:00 AM3/18/98
to

Try this
000000 working-storage section.
000000 01 env pic x(40).
000000 procedure division.
000000 call "mfextmap"
000000 display "PATH" upon environment-name
000000 accept env from environment-value
000000 display "linciidir=" env
000000 exit program
000000 stop run.

With MF COBOL V 4.0.32

Paddy Coleman

unread,
Mar 18, 1998, 3:00:00 AM3/18/98
to

Folks,

The call to mfextmap is only required if you want to 'set' an environment
variable. Basically the syntax is:

To read:

display "<environment variable name>" upon environment-name.
accept ws-envvar-value from environment-value.

To set:

display "<environment variable name>" upon environment-name.
display ws-envvar-value upon environment-value.

Hope this helps.

Paddy Coleman
Team Leader, Distributed Computing Support (WinTel)
Micro Focus UK.

Ferhat Hajdarpasic wrote in message <6enjro$oaj$1...@ernie.rsvl.unisys.com>...

Ferhat Hajdarpasic

unread,
Mar 19, 1998, 3:00:00 AM3/19/98
to

Sorry, line 7 should be changed!
_________________________

000000 working-storage section.
000000 01 env pic x(40).
000000 procedure division.
000000 call "mfextmap"
000000 display "PATH" upon environment-name
000000 accept env from environment-value
000000 display "path=" env

000000 exit program
000000 stop run.
___________________________

0 new messages