System Environment Variables Get or Set using COBOL |
The SimoTime Home Page |
This document describes how to get or set a system environment variable using a COBOL program that is executing on a Linux, UNIX or Windows System. A listing of the COBOL source code is provided for viewing.
Additional information about this program may be obtained by sending an e-mail to: helpdesk@simotime.com
We have made a significant effort to ensure the documents and software technologies are correct and accurate. We reserve the right to make changes without notice at any time. The function delivered in this version is based upon the enhancement requests from a specific group of users. The intent is to provide changes as the need arises and in a timeframe that is dependent upon the availability of resources.
Copyright © 1987-2018
SimoTime Technologies and Services
All Rights Reserved
The MFENVARS routine (or callable program) will provide the capability of getting or setting and environment variable to a 256-byte value for use in a Micro Focus environment.
The following will set an environment variable named "FILENAME" to the value specified in ENV-VAR-VALUE
MOVE 'FILENAME' to ENV-VAR-NAME MOVE 'C:\MYDIR\MYFILE.DAT ' to ENV-VAR-VALUE MOVE 'SET' to ENV-VAR-REQUEST CALL 'MFENVARS' using ENV-VAR-PASSAREA
The following will get and environment variable called "FILENAME" and the value will be p/aced in ENV-VAR-VALUE. If the environment variable is missing then ENV-VAR-VALUE will be set to SPACES
MOVE 'FILENAME' to ENV-VAR-NAME MOVE 'GET' to ENV-VAR-REQUEST CALL 'MFENVARS' using ENV-VAR-PASSAREA
A copy file is provided to define the pass area to be used when calling MFENVARS. The following statement is required in the WORKING STORAGE section of the calling program.
COPY PAENVARS.
The following (cblenvs1.sh) is the Bash Script file that is used to execute the job.
#!/bin/bash # * ******************************************************************* # * cblenvs1.sh - a Bash Script File * # * This program is provided by SimoTime Technologies * # * (C) Copyright 1987-2017 All Rights Reserved * # * Web Site URL: http://www.simotime.com * # * e-mail: helpdesk@simotime.com * # * ******************************************************************* # * # * Text - Accessing Environment Variables # * Author - SimoTime Technologies # * Date - November 11, 2003 # * Version - 06.07.16 # * # * This job will access System Environment Variables and display # * the content or value on the screen. # * # * Th COBOL programs have been compiled and will execute using # * GnuCOBOL 2.0.0. # * # * ************ # * * cblenvs1 * # * *********sh* # * * # * * # * ************ ************ ************ # * * cobcrun ******* CBLENVC1 ******* SYSOUT * # * ************ ********cbl* ************ # * * * # * * * # * * ************ # * * * MFENVARS * # * * ********cbl* # * ************ # * * EOJ * # * ************ # * # * ******************************************************************** # * Step 1 of 2, Set the environment variables... # * JOBNAME=cblenvs1 export BASESYS1=/home/larry/SIMOSY76 export COB_LIBS=$BASESYS1/SIMOSAM1/DEVL/LOADLIB:$BASESYS1/SIMOLIBR export COB_LIBRARY_PATH=$BASESYS1/SIMOSAM1/DEVL/LOADLIB:$BASESYS1/SIMOLIBR export SIMONOTE=$BASESYS1/LOGS/SYSOUT_BASHUSER_$JOBNAME.txt simonote.sh "Starting Job Name is $JOBNAME" # * # * ******************************************************************** # * Step 2 of 2, Run the programs, Display a message... # * export USER0039=....:....1....:....2....:....3....:.... export USER0096=....:....1....:....2....:....3....:....4....:....5....:....6....:....7....:....8....:....9....:. export USER0100=....:....1....:....2....:....3....:....4....:....5....:....6....:....7....:....8....:....9....:...10 export USER0137=$USER0100....:....1....:....2....:....3....:.. export USER0296=$USER0100$USER0096..20$USER0096 cobcrun CBLENVC1 # * simonote.sh "Finished Job Name is $JOBNAME"
This job requires three COBOL Members. The 1st member is a mainline driver program. The 2nd member is a callable program. The 3rd member is a COBOL Copy File that defines the pass area that is used when the 1st program calls the 2nd program.
The following (CBLENVC1.cbl) is the COBOL Source Code for the Mainline Driver program.
IDENTIFICATION DIVISION. PROGRAM-ID. CBLENVC1. *AUTHOR. SIMOTIME TECHNOLOGIES. ***************************************************************** * This program was created by Larry Simmons * * A Test Driver for a Call to DTTESTC1 * * Creation Date: 2012/08/21 * ***************************************************************** *ENVIRONMENT DIVISION. *CONFIGURATION SECTION. *special-names. * ENVIRONMENT-NAME is env-name * ENVIRONMENT-VALUE is env-value. DATA DIVISION. WORKING-STORAGE SECTION. 01 SIM-TITLE. 05 T1 pic X(11) value '* CBLENVC1 '. 05 T2 pic X(34) value 'Test a call to the DTSYSCON Member'. 05 T3 pic X(10) value ' v12.09.26'. 05 T4 pic X(24) value ' helpdesk@simotime.com'. 01 SIM-COPYRIGHT. 05 C1 pic X(11) value '* CBLENVC1 '. 05 C2 pic X(32) value 'This Data File Convert Member wa'. 05 C3 pic X(32) value 's generated by SimoTime Technolo'. 05 C4 pic X(04) value 'gies'. 01 ENV-VAR-VALUE-LSB pic 9(5) value 0. ***************************************************************** * * When ENV-VAR-REQUEST is 'GET' then * the ENV-VAR-NAME is used to get ENV-VAR-VALUE * if the environment variable specified in ENV-VAR-NAME is * missing then ENV-VAR-VALUE is set to SPACES. * * When ENV-VAR-REQUEST is 'SET' then * the environment variable specified in ENV-VAR-NAME is * set to the value specified in ENV-VAR-VALUE. * 01 ENV-VAR-PASSAREA. 05 ENV-VAR-REQUEST pic X(3). 05 ENV-VAR-RESPOND pic X(4). 05 ENV-VAR-NAME pic X(16). 05 ENV-VAR-VALUE pic X(1024). ***************************************************************** PROCEDURE DIVISION. perform ACTION-USER0096 perform ACTION-USER0039 perform ACTION-USER0137 perform ACTION-USER0296 perform ACTION-USERTEST GOBACK. ***************************************************************** ACTION-USER0039. move ZERO to RETURN-CODE move SPACES to ENV-VAR-NAME move SPACES to ENV-VAR-VALUE move '0000' to ENV-VAR-RESPOND move 'USER0039 ' to ENV-VAR-NAME move 'GET' to ENV-VAR-REQUEST CALL 'MFENVARS' using ENV-VAR-PASSAREA perform CALCULATE-ENV-VAR-VALUE-LSB display 'Return..... ' ENV-VAR-RESPOND upon console display 'Expected... 00039' upon console display 'Size....... ' ENV-VAR-VALUE-LSB upon console display ENV-VAR-VALUE(1:ENV-VAR-VALUE-LSB) upon console exit. ***************************************************************** ACTION-USER0096. move ZERO to RETURN-CODE move SPACES to ENV-VAR-NAME move SPACES to ENV-VAR-VALUE move '0000' to ENV-VAR-RESPOND move 'USER0096 ' to ENV-VAR-NAME move 'GET' to ENV-VAR-REQUEST CALL 'MFENVARS' using ENV-VAR-PASSAREA perform CALCULATE-ENV-VAR-VALUE-LSB display 'Return..... ' ENV-VAR-RESPOND upon console display 'Expected... 00096' upon console display 'Size....... ' ENV-VAR-VALUE-LSB upon console display ENV-VAR-VALUE(1:ENV-VAR-VALUE-LSB) upon console exit. ***************************************************************** ACTION-USER0137. move ZERO to RETURN-CODE move SPACES to ENV-VAR-NAME move SPACES to ENV-VAR-VALUE move '0000' to ENV-VAR-RESPOND move 'USER0137 ' to ENV-VAR-NAME move 'GET' to ENV-VAR-REQUEST CALL 'MFENVARS' using ENV-VAR-PASSAREA perform CALCULATE-ENV-VAR-VALUE-LSB display 'Return..... ' ENV-VAR-RESPOND upon console display 'Expected... 00137' upon console display 'Size....... ' ENV-VAR-VALUE-LSB upon console display ENV-VAR-VALUE(1:ENV-VAR-VALUE-LSB) upon console exit. ***************************************************************** ACTION-USER0296. move ZERO to RETURN-CODE move SPACES to ENV-VAR-NAME move SPACES to ENV-VAR-VALUE move '0000' to ENV-VAR-RESPOND move 'USER0296 ' to ENV-VAR-NAME move 'GET' to ENV-VAR-REQUEST CALL 'MFENVARS' using ENV-VAR-PASSAREA perform CALCULATE-ENV-VAR-VALUE-LSB display 'Return..... ' ENV-VAR-RESPOND upon console display 'Expected... 00296' upon console display 'Size....... ' ENV-VAR-VALUE-LSB upon console display ENV-VAR-VALUE(1:ENV-VAR-VALUE-LSB) upon console exit. ***************************************************************** ACTION-USERTEST. ACCEPT ENV-VAR-VALUE FROM ENVIRONMENT ENV-VAR-NAME END-ACCEPT perform CALCULATE-ENV-VAR-VALUE-LSB display 'Expected... ?????' upon console display 'Size....... ' ENV-VAR-VALUE-LSB upon console display ENV-VAR-VALUE(1:ENV-VAR-VALUE-LSB) upon console exit. ***************************************************************** CALCULATE-ENV-VAR-VALUE-LSB. add 1024 to ZERO giving ENV-VAR-VALUE-LSB if ENV-VAR-VALUE = SPACES move ZERO to ENV-VAR-VALUE-LSB else if ENV-VAR-VALUE(513:512) = SPACES add 512 to ZERO giving ENV-VAR-VALUE-LSB if ENV-VAR-VALUE(257:256) = SPACES add 256 to ZERO giving ENV-VAR-VALUE-LSB end-if else if ENV-VAR-VALUE(769:256) = SPACES add 768 to ZERO giving ENV-VAR-VALUE-LSB end-if end-if perform until ENV-VAR-VALUE-LSB < 2 or ENV-VAR-VALUE(ENV-VAR-VALUE-LSB:1) not = SPACE if ENV-VAR-VALUE(ENV-VAR-VALUE-LSB:1) = SPACE subtract 1 from ENV-VAR-VALUE-LSB end-if end-perform end-if exit. ***************************************************************** * This program was created by Larry Simmons * * A Test Driver for a Call to DTSYSCON * * Creation Date: 2012/08/21 * *****************************************************************
The following (MFENVARS.cbl) is the COBOL Source Code for the callable routine.
IDENTIFICATION DIVISION. PROGRAM-ID. MFENVARS. AUTHOR. SIMOTIME TECHNOLOGIES. ***************************************************************** * Copyright (C) 1987-2018 SimoTime Technologies. * * * * All rights reserved. Unpublished, all rights reserved under * * copyright law and international treaty. Use of a copyright * * notice is precautionary only does not imply publication or * * disclosure. This software contains confidential information * * and trade secrets of SimoTime Technologies. No part of this * * program or publication may be reproduced, transmitted, * * transcribed, stored in a retrieval system, or translated into * * any language or computer language, in any form or by any * * means, electronic, mechanical, magnetic, optical, chemical, * * manual or otherwise, without the prior written permission of: * * * * SimoTime Technologies * * 15 Carnoustie Drive * * Novato, CA 94949-5849 * * 415.883.6565 * * * * RESTRICTED RIGHTS LEGEND * * Use, duplication, or disclosure by the Government is subject * * to restrictions as set forth in subparagraph (c)(1)(ii) of * * the Rights in Technical Data and Computer Software clause at * * DFARS 52.227-7013 or subparagraphs (c)(1) and (2) of * * Commercial Computer Software - Restricted Rights at 48 * * CFR 52.227-19, as applicable. Contact SimoTime Technologies, * * 15 Carnoustie Drive, Novato, CA 94949-5849. * * * ***************************************************************** * This program is provided by SimoTime Technologies * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * * * ***************************************************************** * * MAINTENANCE * ----------- * 1989/02/27 Simmons, Created program. * ***************************************************************** * Source Member: MFENVARS.CBL * Copy Files: None * Calls to: None ***************************************************************** * This program will use an environment variable to map the file * name on the SELECT statement to a fully qualified PC file name. * To do this mapping this program must be compiled with the * assign(EXTERNAL) directive. * The program will read the file and display the records to the * screen. If this program is compiled with the sequential(LINE) * directive then the input file may be an ASCII/Text file. * ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. ***************************************************************** * Data-structure for Title and Copyright... * ------------------------------------------------------------ 01 SIM-TITLE. 05 T1 pic X(11) value '* MFENVARS '. 05 T2 pic X(34) value 'Get an Environment Variable Value '. 05 T3 pic X(10) value ' v17.04.21'. 05 T4 pic X(24) value ' http://www.simotime.com'. 01 SIM-COPYRIGHT. 05 C1 pic X(11) value '* MFENVARS '. 05 C2 pic X(20) value 'Copyright 1987-2018 '. 05 C3 pic X(28) value ' SimoTime Technologies '. 05 C4 pic X(20) value ' All Rights Reserved'. 01 SIM-THANKS-01. 05 C1 pic X(11) value '* MFENVARS '. 05 C2 pic X(32) value 'Thank you for using this program'. 05 C3 pic X(32) value ' provided from SimoTime Technolo'. 05 C4 pic X(04) value 'gies'. 01 SIM-THANKS-02. 05 C1 pic X(11) value '* MFENVARS '. 05 C2 pic X(32) value 'Please send all inquires or sugg'. 05 C3 pic X(32) value 'estions to the helpdesk@simotime'. 05 C4 pic X(04) value '.com'. ***************************************************************** * Buffer used for posting messages to the console. * ------------------------------------------------------------ 01 MESSAGE-BUFFER. 05 MESSAGE-HEADER pic X(11) value '* MFENVARS '. 05 MESSAGE-TEXT pic X(68). ***************************************************************** LINKAGE SECTION. COPY PAENVARS. ***************************************************************** PROCEDURE DIVISION using ENV-VAR-PASSAREA. move ZERO to RETURN-CODE evaluate ENV-VAR-REQUEST when 'GET' perform GET-ENVIRONMENT-VARIABLE when 'SET' perform SET-ENVIRONMENT-VARIABLE when other add 16 to ZERO giving RETURN-CODE move SPACES to ENV-VAR-VALUE end-evaluate move RETURN-CODE to ENV-VAR-RESPOND GOBACK. ***************************************************************** * Get an environment variable. *----------------------------. GET-ENVIRONMENT-VARIABLE. move SPACES to ENV-VAR-VALUE accept ENV-VAR-VALUE from ENVIRONMENT ENV-VAR-NAME on exception add 8 to ZERO giving RETURN-CODE end-accept if RETURN-CODE not = 0 move SPACES to ENV-VAR-VALUE end-if exit. ***************************************************************** * Set an environment variable. *----------------------------. SET-ENVIRONMENT-VARIABLE. display ENV-VAR-NAME upon ENVIRONMENT-NAME on exception add 4 to ZERO giving RETURN-CODE end-display if RETURN-CODE = ZERO display ENV-VAR-VALUE upon ENVIRONMENT-VALUE on exception add 4 to ZERO giving RETURN-CODE end-display end-if exit. ***************************************************************** * ABEND the program, post a message to the console and issue * * a STOP RUN. * ***************************************************************** Z-ABEND-PROGRAM. if MESSAGE-TEXT not = SPACES perform Z-DISPLAY-MESSAGE-TEXT end-if move 'PROGRAM-IS-ABENDING...' to MESSAGE-TEXT perform Z-DISPLAY-MESSAGE-TEXT add 12 to ZERO giving RETURN-CODE GOBACK. ***************************************************************** Z-POST-COPYRIGHT. display SIM-TITLE upon console display SIM-COPYRIGHT upon console exit. ***************************************************************** Z-DISPLAY-MESSAGE-TEXT. display MESSAGE-BUFFER upon console move SPACES to MESSAGE-TEXT exit. ***************************************************************** Z-THANK-YOU. display SIM-THANKS-01 upon console display SIM-THANKS-02 upon console exit. ***************************************************************** * This example is provided by SimoTime Technologies * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * *****************************************************************
The following (PAENVARS.cpy) is the COBOL copy file that may be used when calling the MFENVARS program.
***************************************************************** * PAENVARS is a COBOL Copy File * * Data Structure or Pass Area used for calling MFENVARS. * * Copyright (C) 1987-2018 SimoTime Technologies * * All Rights Reserved * ***************************************************************** * Provided by SimoTime Technologies * * Our e-mail address is: helpdesk@simotime.com * * Also, visit our Web Site at http://www.simotime.com * ***************************************************************** * * When ENV-VAR-REQUEST is 'GET' then * the ENV-VAR-NAME is used to get ENV-VAR-VALUE * if the environment variable specified in ENV-VAR-NAME is * missing then ENV-VAR-VALUE is set to SPACES. * * When ENV-VAR-REQUEST is 'SET' then * the environment variable specified in ENV-VAR-NAME is * set to the value specified in ENV-VAR-VALUE. * 01 ENV-VAR-PASSAREA. 05 ENV-VAR-REQUEST pic X(3). 05 ENV-VAR-RESPOND pic X(4). 05 ENV-VAR-NAME pic X(16). 05 ENV-VAR-VALUE pic X(1024). *** PAENVARS - End-of-Copy File - - - - - - - - - - - PAENVARS * ***************************************************************** *
This section will describe some of the additional jobs or processes that are required to build and execute this test case.
The following describes the hardware and software system configurations used at SIMOTIME.
Our Windows development system of choice is a DELL Latitude E6520 with 8GB RAM and a 128GB SSD and a 300GB HDD. Our Linux development system of choice is a System/76 (Serval WS)
Our Windows Operating System is Windows/7 Ultimate with Microsoft Office 2010. Windows will no longer be our only development choice. Since we have a large number of Windows Users we plan to continue using Windows as one of multiple development choices.
Our Linux Operating System is Ubuntu 16.04 LTS. Ubuntu is a complete desktop Linux operating system, freely available with both community and professional support. This is our Linux operating system of choice. We are currently running Ubuntu 16.04.1 LTS (64-bit). Ubuntu 14.04.5 was originally installed by System/76.
The SIMOTIME users have a wide variety of applications written in a number of different languages and executing on systems of varying architectures.
For COBOL programs we use Micro Focus Enterprise Developer for the Windows Environment. We use GnuCOBOL for the Linux environment.
The following describes a Bash Script file that will post a user message to the System Console and to a Log file.
#!/bin/bash # * ******************************************************************* # * simonote.sh - a Bash Script File * # * This program is provided by SimoTime Technologies * # * (C) Copyright 1987-2018 All Rights Reserved * # * Web Site URL: http://www.simotime.com * # * e-mail: helpdesk@simotime.com * # * ******************************************************************* # * # * Text - Display message on screen and write to a log file. # * Author - SimoTime Technologies # * # * This script may be called from other scripts and expects a single # * parameter enclosed in double quotes. The double quotes will be # * removed. Before writing to the log file a date and time stamp # * will be inserted in front of the message text. # * # * Note: The tilde (~) removes leading/trailing double-quotes. # * # * "$simonote" == "" export SimoNOTE=/SIMOLIBR/LOGS/JESLOG_BASHUSER.txt if [ "$SIMONOTE" = "" ] then export SIMONOTE=SIMONOTE_JOBLOG_BASHUSER.txt fi echo $(date +'%Y/%m/%d') - $(date +'%r') $1>> $SIMONOTE echo $1
The following link provides additional detail about the simonote.sh Bash Script file.
Explore How to Post a Message to a log file and to the System Console.
We used the following command to compile the driver program for this test case.
cobc -fixed -std=ibm MFENVARS.cbl -o MFENVARS.so -I SIMOSAM1/DEVL/COBCPY1 -t MFENVARS.prn
We used the following command to compile the Get/Set Routine for this test case.
cobc -fixed -std=ibm CBLENVARS.cbl -o CBLENVARS.so -I SIMOSAM1/DEVL/COBCPY1 -t CBKENVC1.prn
This document describes how to get or set a system environment variable using a COBOL program that is executing on a Linux, UNIX or Windows System. This document may be used as a tutorial for new programmers or as a quick reference for experienced programmers.
In the world of programming there are many ways to solve a problem. This document and the links to other documents are intended to provide a greater awareness of the Data Management and Application Processing alternatives.
The documentation and software were developed and tested on systems that are configured for a SIMOTIME environment based on the hardware, operating systems, user requirements and security requirements. Therefore, adjustments may be needed to execute the jobs and programs when transferred to a system of a different architecture or configuration.
SIMOTIME Services has experience in moving or sharing data or application processing across a variety of systems. For additional information about SIMOTIME Services or Technologies please send an e-mail to: helpdesk@simotime.com or call 415 883-6565. We appreciate hearing from you.
Permission to use, copy, modify and distribute this software, documentation or training material for any purpose requires a fee to be paid to SimoTime Technologies. Once the fee is received by SimoTime the latest version of the software, documentation or training material will be delivered and a license will be granted for use within an enterprise, provided the SimoTime copyright notice appear on all copies of the software. The SimoTime name or Logo may not be used in any advertising or publicity pertaining to the use of the software without the written permission of SimoTime Technologies.
SimoTime Technologies makes no warranty or representations about the suitability of the software, documentation or learning material for any purpose. It is provided "AS IS" without any expressed or implied warranty, including the implied warranties of merchantability, fitness for a particular purpose and non-infringement. SimoTime Technologies shall not be liable for any direct, indirect, special or consequential damages resulting from the loss of use, data or projects, whether in an action of contract or tort, arising out of or in connection with the use or performance of this software, documentation or training material.
This section includes links to documents with additional information that are beyond the scope and purpose of this document. The first group of documents may be available from a local system or via an internet connection, the second group of documents will require an internet connection.
Note: A SimoTime License is required for the items to be made available on a local system or server.
The following links may be to the current server or to the Internet.
Explore a complete list of the SimoTime Callable Routines or Utility Programs. This includes the callable routines and utility programs for the Micro Focus environment.
Explore the COBOL Connection for more examples of COBOL programming techniques and sample code.
Explore an Extended List of Software Technologies that are available for review and evaluation. The software technologies (or Z-Packs) provide individual programming examples, documentation and test data files in a single package. The Z-Packs are usually in zip format to reduce the amount of time to download.
Explore The ASCII and EBCDIC Translation Tables. These tables are provided for individuals that need to better understand the bit structures and differences of the encoding formats.
Explore The File Status Return Codes to interpret the results of accessing VSAM data sets and/or QSAM files.
The following links will require an internet connect.
A good place to start is The SimoTime Home Page for access to white papers, program examples and product information. This link requires an Internet Connection
Explore The Micro Focus Web Site for more information about products and services available from Micro Focus. This link requires an Internet Connection.
Explore the Glossary of Terms for a list of terms and definitions used in this suite of documents and white papers.
This document was created and is copyrighted and maintained by SimoTime Technologies.
If you have any questions, suggestions, comments or feedback please call or send an e-mail to: helpdesk@simotime.com
We appreciate hearing from you.
SIMOTIME Technologies was founded in 1987 and is a privately owned company. We specialize in the creation and deployment of business applications using new or existing technologies and services. We have a team of individuals that understand the broad range of technologies being used in today's environments. Our customers include small businesses using Internet technologies to corporations using very large mainframe systems.
Quite often, to reach larger markets or provide a higher level of service to existing customers it requires the newer Internet technologies to work in a complementary manner with existing corporate mainframe systems. We specialize in preparing applications and the associated data that are currently residing on a single platform to be distributed across a variety of platforms.
Preparing the application programs will require the transfer of source members that will be compiled and deployed on the target platform. The data will need to be transferred between the systems and may need to be converted and validated at various stages within the process. SIMOTIME has the technology, services and experience to assist in the application and data management tasks involved with doing business in a multi-system environment.
Whether you want to use the Internet to expand into new market segments or as a delivery vehicle for existing business functions or need assistance with converting non-relational data structures simply give us a call at 415 883-6565 or check the web site at http://www.simotime.com
Return-to-Top |
GET or SET an Environment Variable using a COBOL Program |
Copyright © 1987-2018 SimoTime Technologies and Services All Rights Reserved |
When technology complements business |
http://www.simotime.com |