[Access to Wang masthead]

Shifting the Burden

Downloading VS files to PCs lets users run their own reports

From "VS Workshop",  Access to Wang, September 1992
  [ Prior Article ]     [ Return to the Catalog of articles ]     [ Next Article ]  

It's inevitable; as soon as you sit down with a complex chore and little time to do it, someone approaches you for a favor. A report, an inquiry, a reordering of information for a meeting - it could be anything, and it's probably too difficult for the Wang INQUIRY or REPORT utilities. If only you could get the data into Lotus or Excel format and let the end users report on it as they wish. . .with a sigh, you turn to the EDITOR and start coding.

As regular readers of this column know, the subject of downloading - extracting information from the VS and loading it into PC applications - has been covered here before. The extract process described this month is perhaps the most practical yet listed for those with a COBOL compiler; it also would make an ideal project for someone new to COBOL, those unfamiliar with programming tools on the VS, or simply for you harried programmers out there trying to give their end users more self-sufficiency.

For this project you will need a COBOL compiler, the Wang COBGEN utility, a CONTROL file or COBOL FD (File Descriptor) for a file you wish to extract, a means of transferring VS consecutive files to the PC, and some familiarity with the Wang EDITOR. Note that the compiler must be functional; this seems an obvious point, but a surprising number of VS shops have old versions that do not function in current operating systems. The version of COBGEN is not important; either the current Wang-supported or an earlier USERAID version is sufficient.

The process

I will use the FILEINFO utility - a VSAID - as an example. FILEINFO is a simple tool that extracts a variety of information on files and produces a consecutive file. The information can be reported using the REPORT or INQUIRY utilities or other means. The fields include the name and location, file size, organization, key locations, modification history, and record count. For this project we will extract the file name, library, volume, record count, and record size using FILEINFO and a CONTROL file that describes the data file created by it.

Here's the problem: you're tracking disk usage over time to try to predict when there is no more disk space available. You have gathered data for this process by taking "snapshots" of file statistics at fixed times in the month. You would like to get this information into your PC so that you can use a spreadsheet product to produce eye-popping charts so management will allow you to spend more money on computer equipment. Experiments using text files from the VS have been unsuccessful because all of the information ends up in one column of the worksheet. The task is to create a simple program that will perform that extract better. The task should take no more than a lunch hour. Ready?

Step one: create a shell program

Run COBGEN, the COBOL generator, and specify the location of a source file to be created at the COBOLSRC screen. The name and location are not important but should be consistent with your shop's practice.

The program then asks for the file control information. Specify two disk files: the input file (the file to be extracted; e.g. FILEINFO) and a file called TEXTOUT. The open mode for the input file should be INPUT or SHARED, depending on its use by others on your system; TEXTOUT should be opened OUTPUT. COBGEN will not allow you to use a data file name that is the same as the name of the source file you are creating, so you may have to make up a new name for your input file. Note that no workstation or printer files are necessary.

The next screen to appear allows you to select some program options, such as code for GETPARMs, PUTPARMs, links to other programs, sorts, and other options. Nothing is needed here, so press ENTER to continue.

COBGEN then prompts you for information on the two files to be used in the program; this information is supplied by specifying CONTROL files. At the first screen (FILEINFO), enter the name and location of a valid CONTROL file. Opps - you haven't created a CONTROL file yet for the second file (TEXTOUT); COBGEN allows you to do so by entering the file name and location and pressing PF2.

You are now in the CONTROL utility, ready to create TEXTOUT. Set up the file with the following specifications:

File characteristics

Item Value
Organization Consecutive
Type Compressed
File size 250 characters

Data elements

Field Name Type Size
FIELD1 Character 125
FIELD2 Character 125

A strange file format, no? It is intended to be a 250-character open record area, but CONTROL limits the number of characters in a character field, so two fields were created to cover the area. It won't matter, as we'll see.

All of the necessary information has been entered now, and COBGEN goes about the task of creating a program from it. If you have never used COBGEN before, it is worth looking over the generated source file carefully to see what has been done. COBGEN's mission is to create the file description and input and output statements, leaving you to write the PROCEDURE DIVISION - the heart of any COBOL program. (The generated program may also look familiar; an embarrassing amount of commercial VS software began with this utility!)

Step two: Modify the program

Now for some fun. Edit the program and make the following changes:

1. Comments: add some description of the program and its purpose below DATE-WRITTEN in the IDENTIFICATION DIVISION, using an asterisk (*) in column one so the compiler ignores it.

2. Special character: add the following statement below the OBJECT-COMPUTER paragraph:


FIGURATIVE-CONSTANTS.
     HEX-09      "09".

This creates the special character HEX-09, which contains the value of a tab character - the character that will separate fields in our output file.

3. Change main paragraph control logic: our program is designed to be run until the end of the input file is reached; change the START-PROGRAM paragraph to something like this:


 PERFORM MAIN-PROCESS
   UNTIL NO-MORE-FILEINFO.

(Note that FILEINFO is the name of the input file in my example; change this name to your file name if different.)

4. Build output record format: find the last paragraph in the file (WRITE-A-REC-TO-TEXTOUT) and add logic to build the output record area by merging data fields with tab characters (HEX-09). This can be performed by creating a fixed output record area, but we're using a large record with no fields; how can we assemble the information in the right form? Through the STRING command, like this:


 MOVE SPACES                 TO TEXTOUT-RECORD.

 STRING  FFIL         DELIMITED BY " "
         HEX-09       DELIMITED BY SIZE
         FLIB         DELIMITED BY " "
         HEX-09       DELIMITED BY SIZE
         FVOL         DELIMITED BY " "
         HEX-09       DELIMITED BY SIZE
         RECCOUNT     DELIMITED BY SIZE
         HEX-09       DELIMITED BY SIZE
         RECSIZE      DELIMITED BY SIZE
 INTO    TEXTOUT-RECORD.

 WRITE   TEXTOUT-RECORD.

Translated, this means "stick these five variables together with tabs between them, using the record area for TEXTOUT as your work space." There is also a trick here to make the output fields vary according to their length: the DELIMITED BY " " statements for variables FFIL, FLIB, and FVOL means that STRING will stop reading that field when the first space character is reached. The other variables will be their full size as defined by the FD for the file. The delimiter (character that divides the fields) is the special tab character defined in FIGURATIVE-CONSTANTS.

5. Compile and run: you should be able to compile the program now and run it. No subroutines are called, so specify NO to LINKS. The program will prompt for the input and output file names and locations.

Done already?

That's it - at least most of the time. Note that STRING must work with normal text characters such as numbers and letters; packed fields must be moved to an intermediary field. For example, if PFIELD is defined as PIC S9(5) COMP, it must be unpacked by moving it into another field (e.g. DFIELD, defined as PIC S9(5)) and using that in the STRING statement.

The output file can now be transferred to the PC and moved directly into spreadsheets, data base programs, and word processors.

Extra credit

  • Write an extract that combines two files. Add logic to select specific records from the input file.

  • Write a procedure that extracts records with the EXTRACT option of INQUIRY, then feeds that file into your extract program for processing. Make it simple to run so end users can write the query and generate the PC file.

  • Instead of a CONTROL file, specify your input file's data format using an FD from other production programs.

There you have it - a worthwhile use of an hour because it can free your end users to select and report on information as they wish, using powerful tools within their reach.


  [ Prior Article ]     [ Return to the Catalog of articles ]     [ Next Article ]  


Copyright © 1992 Dennis S. Barnes
Reprints of this article are permitted without notification if the source of the information is clearly identified