[Access to Wang masthead]

The RUNRPT Procedure

REPORT utility heading control

From "VS Procedure",  Access 86, September 1986
  [ Prior Article ]     [ Return to the Catalog of articles ]     [ Next Article ]  

This month's procedure started as a suggestion from a regular user of Wang's REPORT utility. Why, he said, can't it be easier to change the selection criteria for a report, and how would you know what changes you made?

Let's tackle the selection problem first. Those who have been around Wang utilities for any length of time have probably used the extract option of the INQUIRY utility to create a work file, then reported on that selected file through REPORT. If you haven't, you're missing out on one of the best features within the Wang utilities. (Those not familiar with INQUIRY and its options should consult the June issue of ACCESS 86 for Pat McMonagle's discussion of it.)

You can use INQUIRY to construct a file that only contains records that meet your selection criteria. Since INQUIRY shows you the control fields for the file and checks the syntax of the query you enter, it is very simple to use. The created file is similar in organization to the input file, so the control file and REPORT will still work properly. After creating the file, you can use a standard REPORT definition (minus some of the data limits) to report on it. Voila - an ad hoc report!

So, after reading these three paragraphs you have rushed off and created two dozen "quickies" - all with unique selection criteria, all from the same data file. How do you ever tell them apart? All of REPORT's parameters are static; the title information is a permanent part of the file. Unlike the data files and control files, the titles cannot be overridden at run time.

One solution lies in creating a revised REPORT file and running that instead. This can be accomplished by using CREATE to build a new REPORT file from the existing one, replacing the title records with other information. This is how RUNRPT works.

How RUNRPT works

RUNRPT (see Figure 1) consists of five main parts. From the start through step S00 variables are declared and values assigned to literals. (The procedure assumes control and REPORT files are in the user's personal libraries, and that the data files are found within the current INLIB and INVOL defaults.) Step S01 prompts the user for the data file, the control file, and the REPORT file to be used, and also accepts the TITLE information and selection option (yes/no). As a convenience, this screen also allows access to the DISPRINT utility to review the user's print files.

Step S02 runs INQUIRY, building a work file from the original data file; this step is bypassed should the user opt for NO selection. Steps S03 and S04 center the title, if entered, and create a working copy of the REPORT file containing this new title; again, this step is bypassed if no title is entered. Finally, step S05 runs REPORT, then returns control to initialization and the entry screen (steps S00 and S01).

Some of the finer points of the procedure include the declaration of several variables that accept the value of INVOL from the user's defaults and the use of STEP LABELS and BACKWARD REFERENCES for the output files. For example, look at the ENTER OUTPUT statement within INQUIRY; a step label of O1 has been assigned, and the file name is four characters preceded by "##"; this will result in a work file in the user's work library with the first four characters followed by a system-assigned number. Temporary work files such as these exist until the user logs off the system or exits to the command processor level (e.g., cancels the menu or other application they normally run).

Another point not yet explained is the use of " H1-TITLE " as a key value for the header information. This is simply the key naming convention Wang uses for REPORT files. If you are interested, a complete listing of the file layouts for REPORT and CONTROL files can be found in the back of the Wang File Management Utilities Reference (Publication 800-1308FM).

Using RUNRPT

RUNRPT can be used for virtually any REPORT. If no title is entered and the selection option is not taken, the procedure runs the REPORT utility just like it would normally, with the exception that you will have direct control over the data file to be used. With the addition of title or selection criteria, you can customize a stock report to fit a variety of circumstances.

While the procedure will work for most situations, there are several limitations. The first is the fact that only the first line of title information can be used. This can be changed by adding variables to the DECLARE and screen display sections (steps S00 through S01) and making two more copies of the logic within CREATE to create the header records.

Due to the complexity of the procedure and space considerations, I have purposely left out much of the error-checking logic I would normally have included. This involves the existence of the data, control, and REPORT files prior to processing. It is also quite possible that the selection from INQUIRY will yield zero records; at present, the procedure would continue into REPORT, then blow up due to a lack of data. Of course, if this procedure will be used infrequently, there is little need to cover all possible problems such as these.

Variations

As always, I have several suggestions for possible changes:

1. Change other information within the REPORT file. For example, change the sort order, the fields to be displayed, etc.

2. Add variables and screen logic to handle the secondary file in those REPORT files that use them.

3. Change the references to personal control and REPORT libraries to the defaults that best meet your needs.

4. Capture the actual query information within INQUIRY by specifying that the QUERY lines funnel into procedure variables.

I hope that you find this procedure as useful as I have. See you next month.


Figure 1: The RUNRPT Procedure


     PROCEDURE RUNRPT

**********************************************************************
*
*                  RUNRPT - Runs the REPORT Utility
*
*    This procedure was featured in the September 1986 ACCESS 86.  It
*    provides a means of controlling the headers and data selection
*    of an existing REPORT definition file.
*
*    This procedure accepts a user-entered REPORT file, the associated
*    CONTROL file, and a data file to be reported on.  The user can
*    change the three titles of the report, and use the EXTRACT option
*    of INQUIRY to select records.
*
*    Written by Dennis S. Barnes
*
*    MODIFICATION HISTORY
*
*    Version 1.0   06/24/86   Initial version.
*
**********************************************************************


     DECLARE &KEY        INTEGER
     DECLARE &MSG        STRING (60)
     DECLARE &OPTION     STRING (01) INITIAL "Y"
     DECLARE &ID         STRING (03)

     DECLARE &FUNC       STRING (02) INITIAL "CT"
     DECLARE &LEN        INTEGER     INITIAL 60

     DECLARE &TITL1      STRING (60)
     DECLARE &TITL2      STRING (60)
     DECLARE &TITL3      STRING (60)

     DECLARE &CTLFIL     STRING (08)
     DECLARE &CTLLIB     STRING (08)
     DECLARE &CTLVOL     STRING (06)

     DECLARE &INFIL      STRING (08)
     DECLARE &INLIB      STRING (08)
     DECLARE &INVOL      STRING (06)

     DECLARE &WINFIL     STRING (08)
     DECLARE &WINLIB     STRING (08)
     DECLARE &WINVOL     STRING (06)

     DECLARE &RPTFIL     STRING (08)
     DECLARE &RPTLIB     STRING (08)
     DECLARE &RPTVOL     STRING (06)

     DECLARE &WRPTFIL    STRING (08)
     DECLARE &WRPTLIB    STRING (08)
     DECLARE &WRPTVOL    STRING (06)

     DECLARE &WRKLIB     STRING (08)
     DECLARE &WRKVOL     STRING (06)

S00: EXTRACT             &ID       = USERID, &RPTVOL   = INVOL,
                         &INLIB    = INLIB,  &INVOL    = INVOL,
                         &CTLVOL   = INVOL,  &WRKLIB   = WORKLIB,
                         &WRKVOL   = WORKVOL

     ASSIGN &RPTLIB      = &ID(1,*) !! "RPT"
     ASSIGN &CTLLIB      = &ID(1,*) !! "CTL"
     ASSIGN &RPTFIL      = " "
     ASSIGN &INFIL       = " "
     ASSIGN &TITL1       = " "
     ASSIGN &TITL2       = " "
     ASSIGN &TITL3       = " "

S01: PROMPT              PFKEY     = &KEY
     CENTER BRIGHT LINE  "REPORT Utility Run Control";;

     CENTER              "Please enter the following:";;

     CENTER              " REPORT FILE   ", UPPER &RPTFIL;
     CENTER              "        LIBRARY", UPPER &RPTLIB;
     CENTER              "        VOLUME ", UPPER &RPTVOL, " ";;

     CENTER              "  INPUT FILE   ", UPPER &INFIL;
     CENTER              "        LIBRARY", UPPER &INLIB;
     CENTER              "        VOLUME ", UPPER &INVOL, " ";;

     CENTER              "  CONTROL FILE ", UPPER &CTLFIL;
     CENTER              "        LIBRARY", UPPER &CTLLIB;
     CENTER              "        VOLUME ", UPPER &CTLVOL, " ";;

     CENTER              "Do you wish to select data (Y/N)?",
                         UPPER &OPTION;;

     CENTER              "Report title 1", UPLOW &TITL1;
     CENTER              "       title 2", UPLOW &TITL2;
     CENTER              "       title 3", UPLOW &TITL3;;

     CENTER              &MSG;
     CENTER              "PF13=Display print files  PF16=EXIT"

     IF &KEY = 16        GOTO S99
     IF &KEY = 13        GOTO @13
     IF &KEY NE 00       GOTO S01

     IF NOT EXISTS FILE &RPTFIL IN &RPTLIB ON &RPTVOL  GOTO S01
     IF NOT EXISTS FILE &INFIL  IN &INLIB  ON &INVOL   GOTO S01
     IF NOT EXISTS FILE &CTLFIL IN &CTLLIB ON &CTLVOL  GOTO S01

     IF &OPTION = "N"    GOTO S03

*-----* Extract records from data file (optional)

S02: RUN INQUIRY
     ENTER INPUT         FILE      = &INFIL,
                         LIBRARY   = &INLIB,
                         VOLUME    = &INVOL,
                         CHANGE    = "YES",
                         OPTION    = "EXTRACT"
     ENTER CONTROL       FILE      = &CTLFIL,
                         LIBRARY   = &CTLLIB,
                         VOLUME    = &CTLVOL
O1:  ENTER OUTPUT        FILE      = "##WORK",
                         LIBRARY   = &WRKLIB,
                         VOLUME    = &WRKVOL
     ENTER EOJ           16

     ASSIGN &WINFIL      = (O1.FILE)
     ASSIGN &WINLIB      = (O1.LIBRARY)
     ASSIGN &WINVOL      = (O1.VOLUME)

*-----* Center the title

S03: IF &TITL1 = " "     GOTO S05

     RUN STRING IN USERSUBS        USING &FUNC, &TITL1, &LEN
     RUN STRING IN USERSUBS        USING &FUNC, &TITL2, &LEN
     RUN STRING IN USERSUBS        USING &FUNC, &TITL3, &LEN

*-----* Make a new copy of the REPORT file; create H1-TITLE record

S04: RUN CREATE
O2:  ENTER OUTPUT        FILE      = "##WRPT",
                         TYPE      = "I",
                         RECSIZE   = "0087",
                         RECORDS   = "0000100",
                         KEYPOS    = "0001",
                         KEYLEN    = "013"

*-----* Recreate first records of REPORT file

     ENTER INPUT         FILE      = &RPTFIL,
                         LIBRARY   = &RPTLIB,
                         VOLUME    = &RPTVOL
     ENTER FILE          END       = " H1-        "
     ENTER INPUT         16

*-----* Recreate first title

     ENTER INPUT         01
     ENTER LITERAL       STRING    = " H1-TITLE   ",
                         POSITION  = "0001",
                         LENGTH    = "13"
     ENTER INPUT         01
     ENTER LITERAL       STRING    = &TITL1,
                         POSITION  = "0014",
                         LENGTH    = "60"
     ENTER INPUT         02
     ENTER PAD           POSITION  = "0074",
                         LENGTH    = "0014"
     ENTER INPUT         16
     ENTER COUNT         RECORDS   = "0000001"

*-----* Recreate second title

     ENTER INPUT         01
     ENTER LITERAL       STRING    = " H2-TITLE   ",
                         POSITION  = "0001",
                         LENGTH    = "13"
     ENTER INPUT         01
     ENTER LITERAL       STRING    = &TITL2,
                         POSITION  = "0014",
                         LENGTH    = "60"
     ENTER INPUT         02
     ENTER PAD           POSITION  = "0074",
                         LENGTH    = "0014"
     ENTER INPUT         16
     ENTER COUNT         RECORDS   = "0000001"

*-----* Recreate third title

     ENTER INPUT         01
     ENTER LITERAL       STRING    = " H3-TITLE   ",
                         POSITION  = "0001",
                         LENGTH    = "13"
     ENTER INPUT         01
     ENTER LITERAL       STRING    = &TITL3,
                         POSITION  = "0014",
                         LENGTH    = "60"
     ENTER INPUT         02
     ENTER PAD           POSITION  = "0074",
                         LENGTH    = "0014"
     ENTER INPUT         16
     ENTER COUNT         RECORDS   = "0000001"

*-----* Recreate remainder of REPORT file

     ENTER INPUT         FILE      = &RPTFIL,
                         LIBRARY   = &RPTLIB,
                         VOLUME    = &RPTVOL
     ENTER FILE          START     = " H3-zzzzzzzz"
     ENTER INPUT         16

     ENTER INPUT         16
     ENTER EOJ           16

     ASSIGN &WRPTFIL     = (O2.FILE)
     ASSIGN &WRPTLIB     = (O2.LIBRARY)
     ASSIGN &WRPTVOL     = (O2.VOLUME)

*-----* Run REPORT with modified report format and/or data file

S05: RUN REPORT
     ENTER FUNCTION      04
     ENTER OPTIONS       ID        = &RPTFIL,
                         PAGE      = "55"
     ENTER RPTDEF        FILE      = &RPTFIL,
                         LIBRARY   = &RPTLIB,
                         VOLUME    = &RPTVOL
     ENTER INPUT1        FILE      = &WINFIL,
                         LIBRARY   = &WINLIB,
                         VOLUME    = &WINVOL
     ENTER CONTROL       FILE      = &CTLFIL,
                         LIBRARY   = &CTLLIB,
                         VOLUME    = &CTLVOL
     ENTER FUNCTION      16

     GOTO S01

@13: RUN DISPRINT IN USERAID

     GOTO S01

S99: RETURN

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


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