Inside COBOL #36
by
Shawn Gordon

In plumbing the depths of the ‘net recently, I came across an altruistic program from Curt Brimacomb of Idaho Computer Service. Basically an individual asked for a way to find a particular file equation without having to visually scan the output from the LISTEQ command. There were a number of responses in using command files and I/O redirection, but I liked Curt’s COBOL program so I asked if I could use it as the basis for this months column.

The problem we are trying to address is that the LISTEQ command basically shows you all your file equations in the order that they were issued. They are not sorted, and there is no way to limit what you are looking for. If you have a large number of file equations issued, it becomes very tedious searching to see if you have the correct one set.

Figure 1 shows an example of running the program, it’s easy to set up a command file that will take a parameter and then make a quick command of it.

Figure 2 shows the source code. Curt asked me to not change it, so I didn’t, other than taking out some references to routines that I didn’t have. First I want to talk about what I would do to make this program a little more streamlined, no offense to Curt at all, this is just a programming style thing. Then we’ll go over some of what it’s doing.

The first thing I would do is eliminate all the WORKING-STORAGE that defines the MPE commands being passed to the COMMAND intrinsic. Then I would make the call to the COMMAND intrinsic a macro. This allows us to eliminate a large
quantity of code immediatly, and actually make the program easier to read, because we don’t have to refer back to the WORKING-STORAGE section to see what is being passed to the COMMAND intrinsic.

Next I would modify the CHECK-FILE paragraph so that instead of doing an UNSTRING of the data, I would do an INSPECT..TALLYING to test for any occurance of the string. This would be more precise and allow you to look for any string in the file equation, so you could justify the file name out more if you needed to. In conjunction with this, I would upshift the users input to make sure we get a match, not everyone always types in upper case.

My next change is another topic we have talked about. Curt is making use of an 88 level field to indicate that the file EOF has been reached, but he is moving “Y” to the 01 level field, which makes it unclear what variable is being checked. So the code fragment;

READ LISTEQ-FILE AT END MOVE “Y” TO EOF-IND.
PERFORM CHECK-FILE UNTIL EOF.

would be clearer, in my opinion, with the following;

READ LISTEQ-FILE AT END SET EOF TO TRUE.
PERFORM CHECK-FILE UNTIL EOF.

Now that I have thouroughly insulted Curt even after he generously allowed me to use his code, I am going to talk about what he is doing. First we ask the user for a file name to look for. Next we make use of the COMMAND intrinsic to build a temporary file, set a file equation to point to the temporary file we just build, then issue a LISTEQ command with it’s output redirected to the temporary file we just built, making use of the file equation that was just issued.

Now that we have a data file, we read through it, unstringing each record based on delimiters into a series of variables. If the first token of the UNSTRING command matches the value entered by the user, we display the entire file equation to the screen.

This kind of logic can be extended to just about anything you care to mention. You can redirect LISTF commands, massage the output, and spew it back in any format you want. I have written many little programs to do this kind of thing with files, databases, users, groups, accounts. Virtually any MPE command you can think of. How about getting a sorted list of SHOWJOB by user or time.

We haven’t really gone over this type of technology before, and I appreciate Curt sparking off the idea, and letting me use this code. It’s short, and clearly illustrates the point. Next month I am going to show a combination of COBOL and C that will allow you to do mapped file access from COBOL.

Figure 1

SMGA.PUB% RUN EQLIST.UTIL.SYS;INFO=”TRACE”

********************
FILE TRACE.PUB.KEMP=TRACE.PUB.SMGA

Figure 2

$CONTROL USLINIT, NOSOURCE
IDENTIFICATION DIVISION.
PROGRAM-ID. EQLIST.
******************************************************************
* *
* PROGRAM SHOWS A FILE EQUATE IF FOUND *
* *
******************************************************************

AUTHOR. Curt Brimacomb.
INSTALLATION. IDAHO COMPUTER SERVICE, INC.
DATE-WRITTEN. THU, FEB 21, 1991.
DATE-COMPILED.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. HP-3000.
OBJECT-COMPUTER. HP-3000.
INPUT-OUTPUT SECTION.
FILE-CONTROL.

SELECT LISTEQ-FILE ASSIGN TO “SCJOB2FD”.

DATA DIVISION.
FILE SECTION.

FD LISTEQ-FILE LABEL RECORDS ARE STANDARD.
01 LISTEQ-REC.
03 FILLER PIC X(6).
03 FILE-EQUATION PIC X(249).

WORKING-STORAGE SECTION.
77 FILE-IN PIC X(8) VALUE SPACES.
77 WORK-FILE PIC X(8) VALUE SPACES.
77 MBUF PIC X(78).
77 PNTR PIC S9(4) COMP.
77 EDIT-ERR PIC ZZZ9.
77 RUN-PARM PIC S9(4) COMP.
77 EDIT-RUN-PARM PIC 9(5).
77 ERR-MODE PIC S9(4) COMP.
77 CMD-ERR PIC S9(4) COMP VALUE ZEROS.
77 CMD-PARM PIC S9(4) COMP VALUE ZEROS.
77 EOF-IND PIC X VALUE SPACES.
88 EOF VALUE “Y”.
77 ERR-IND PIC X VALUE SPACES.
88 ERR VALUE “Y”.
77 WS-LEN PIC S9(4) COMP VALUE 8.
77 WS-PROG PIC X(8) VALUE SPACES.

01 FILE-SCJOB2FD.
03 FILLER PIC X(20) VALUE “FILE SCJOB2FD;REC=-2”.
03 FILLER PIC X(19) VALUE “55,1,F,ASCII;NOCCTL”.
03 FILLER PIC X VALUE %015.
01 LISTEQ-SCJOB2FD.
03 FILLER PIC X(16) VALUE “LISTEQ *SCJOB2FD”.
03 FILLER PIC X VALUE %015.
03 FILLER PIC X VALUE SPACES.
01 PURGE-SCJOB2FD.
03 FILLER PIC X(19) VALUE “PURGE SCJOB2FD,TEMP”.
03 FILLER PIC X VALUE %015.
01 RESET-SCJOB2FD.
03 FILLER PIC X(14) VALUE “RESET SCJOB2FD”.
03 FILLER PIC X VALUE %015.
01 BELL PIC X VALUE %007.
******************************************************************
* *
* P R O C E D U R E D I V I S I O N *
* *
******************************************************************

PROCEDURE DIVISION.
MAIN-SECTION SECTION 01.
STREAM-MAIN.
DISPLAY ” “.
CALL INTRINSIC “GETINFO” USING WS-PROG, WS-LEN.
MOVE SPACES TO FILE-IN.
UNSTRING WS-PROG DELIMITED BY “.” OR ” ” INTO FILE-IN.

IF FILE-IN NOT > ” ”
DISPLAY “Enter File: ” NO ADVANCING
ACCEPT FILE-IN FREE.

CALL INTRINSIC “COMMAND” USING FILE-SCJOB2FD, CMD-ERR,
CMD-PARM.
IF CMD-ERR NOT = 0
DISPLAY ” ”
DISPLAY “Error when trying to set the SCJOB2FD file ”
“equation. (SC-E-0200)”
PERFORM COMMAND-FATAL.

CALL INTRINSIC “COMMAND” USING PURGE-SCJOB2FD, CMD-ERR,
CMD-PARM.

CALL INTRINSIC “COMMAND” USING LISTEQ-SCJOB2FD, CMD-ERR,
CMD-PARM.
IF CMD-ERR NOT = 0
DISPLAY ” ”
DISPLAY “Error when trying to LISTEQ to the SCJOB2FD ”
“file. (SC-E-0200)”
PERFORM COMMAND-FATAL.

OPEN INPUT LISTEQ-FILE.

MOVE “N” TO EOF-IND.

READ LISTEQ-FILE AT END MOVE “Y” TO EOF-IND.

PERFORM CHECK-FILE UNTIL EOF.

CLOSE LISTEQ-FILE.

CALL INTRINSIC “COMMAND” USING RESET-SCJOB2FD, CMD-ERR,
CMD-PARM.

CLOSE-UP.
CALL INTRINSIC “COMMAND” USING PURGE-SCJOB2FD, CMD-ERR,
CMD-PARM.

STOP RUN.

******************************************************************
* *
* W O R K I N G P R O C E D U R E S *
* *
******************************************************************

CHECK-FILE.
UNSTRING FILE-EQUATION DELIMITED BY “,” OR “;” OR “=” OR “.”
INTO WORK-FILE.

IF WORK-FILE = FILE-IN
DISPLAY ” ******************** ”
MOVE LISTEQ-REC TO MBUF
DISPLAY MBUF.

READ LISTEQ-FILE AT END MOVE “Y” TO EOF-IND.

COMMAND-FATAL.
STOP RUN.