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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Environmental Variables or Command Line Arguments

Status
Not open for further replies.

bojo

Programmer
Apr 3, 2001
2
US
I need to write a COBOL program to execute other programs or batch files. I need to
either get the filenames from a command line argument or an evironmental variable.

How do I one access an evironmental variable within Micro Focus COBOL, and TWO
How do I execute or start another program within Micro Focus COBOL, so that I can
check the return code, for successful competion?

I would also like to know the name of a good book/books or a website to obtain the
under the cover knowledge of Micro Focus COBOL.

Thanx
BoJo
 
Hi,

I would like to help you but Microfocus is probably much different from CA-REALIA which has a DOS interface to do this.

I give you the example to get all the environment variables and also the commandline.

If Microfocus is mainframe-look-alike, you can have a procedure division using command-line.

The command-line should be defined in the linkage-section and looks like this:

01 COMMAND-LINE.
03 LENGTH-OF-COMMAND PIC S9(4) COMP.
03 COMMAND-ITSELF.
05 FILLER OCCURS 1 TO 120 DEPENING ON LENGTH-OF-COMMAND PIC X.

The CA-REALIA possibility comes here after.

If you can execute a command-line you can also do something like this:

SET > SET.OUT

You can read the SET.OUT text file and do something with it.

Hope this helps.
000100*$CALL
000200 IDENTIFICATION DIVISION.
000300 PROGRAM-ID. TTEST003.
000400* COPYRIGHT (C) R.G. WOUTERSON
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 SOURCE-COMPUTER. IBM-PC.
000800 OBJECT-COMPUTER. IBM-PC.
000900 SPECIAL-NAMES.
001000 DECIMAL-POINT IS COMMA.
001100 INPUT-OUTPUT SECTION.
001200 FILE-CONTROL.
001300 DATA DIVISION.
001400 FILE SECTION.
001500 WORKING-STORAGE SECTION.
001600 01 SUB-ENVIRONMENT-BYTE VALUE +1 PIC S9(4) COMP-5.
001700 01 SUB-ENVIRONMENT-FIRST VALUE +1 PIC S9(4) COMP-5.
001800 01 SUB-ENVIRONMENT-LENGTH VALUE +1 PIC S9(4) COMP-5.
001900 01 ENV-POINTER POINTER.
002000 01 MACHINE-ADDRESS REDEFINES ENV-POINTER.
002100 05 ADDRESS-OFFSET PIC S9(4) COMP-5.
002200 05 ADDRESS-SEGMENT PIC S9(4) COMP-5.
002300 01 FILLER REDEFINES ENV-POINTER.
002400 05 DISP-ADDRESS-OFFSET PIC 9(4) COMP-5.
002500 05 DISP-ADDRESS-SEGMENT PIC 9(4) COMP-5.
002600
002700 LINKAGE SECTION.
002800 01 ENVIRONMENT-GEBIED.
002900 03 ENVIRONMENT-BYTE OCCURS 32767 PIC X.
003000
003100 PROCEDURE DIVISION.
003200 MAIN-SECTION.
003300 0000.
003310******************************************************************
003320* *
003321* OPHALEN ENVIRONMENT INFORMATIE *
003323* *
003330******************************************************************
003400 CALL 'DOS_GET_ENV_ADDRESS' USING ENV-POINTER.
003500 SET ADDRESS OF ENVIRONMENT-GEBIED TO ENV-POINTER.
003600* EXHIBIT NAMED ADDRESS-OFFSET ADDRESS-SEGMENT.
003700* EXHIBIT NAMED DISP-ADDRESS-OFFSET DISP-ADDRESS-SEGMENT.
003800 PERFORM UNTIL ENVIRONMENT-BYTE (SUB-ENVIRONMENT-BYTE) =
003900 LOW-VALUE
004000 MOVE SUB-ENVIRONMENT-BYTE TO SUB-ENVIRONMENT-FIRST
004100 PERFORM UNTIL ENVIRONMENT-BYTE (SUB-ENVIRONMENT-BYTE) =
004200 LOW-VALUE
004300 ADD +1 TO SUB-ENVIRONMENT-BYTE
004400 END-PERFORM
004500 COMPUTE SUB-ENVIRONMENT-LENGTH =
004600 SUB-ENVIRONMENT-BYTE -
004700 SUB-ENVIRONMENT-FIRST
004800 DISPLAY ENVIRONMENT-GEBIED (SUB-ENVIRONMENT-FIRST:
004900 SUB-ENVIRONMENT-LENGTH)
005000 ADD +1 TO SUB-ENVIRONMENT-BYTE
005100 END-PERFORM.
005110******************************************************************
005120* *
005130* OPHALEN COMMAND LINE INFO *
005140* *
005150******************************************************************
005200 DISPLAY 'COMMAND LINE INFO: ' WITH NO ADVANCING.
005400 ADD +3 TO SUB-ENVIRONMENT-BYTE.
005410 MOVE SUB-ENVIRONMENT-BYTE TO SUB-ENVIRONMENT-FIRST.
005500 PERFORM UNTIL ENVIRONMENT-BYTE (SUB-ENVIRONMENT-BYTE) =
005600 LOW-VALUE
005700 ADD +1 TO SUB-ENVIRONMENT-BYTE
005800 END-PERFORM.
005900 COMPUTE SUB-ENVIRONMENT-LENGTH =
006000 SUB-ENVIRONMENT-BYTE -
006100 SUB-ENVIRONMENT-FIRST
006200 DISPLAY ENVIRONMENT-GEBIED (SUB-ENVIRONMENT-FIRST:
006300 SUB-ENVIRONMENT-LENGTH).
006400 9999.
006500 GOBACK.
006600 DUMMY SECTION.
006700 ENTRY 'DUMMY' USING ENVIRONMENT-GEBIED.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top