Easy Tri Eve

93
Using EASYTRIEVE PLUS Student Guide EAS101 1995 DPEC, Inc. DPEC, Inc. This courseware and manual are protected by the U. S. Copyright Law (Title 17 United States Code). Unauthorized reproduction and/or sales may result in imprisonment of up to one year and fines of up to $10,000 (17 USC 505). Copyright infringements may be subject to civil liability up to $50,00 (17 USC 504). 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 252.227-7013 or FAR 52.227-14. Contractor: DPEC, Inc. 11.95

Transcript of Easy Tri Eve

Page 1: Easy Tri Eve

Using EASYTRIEVE PLUS

Student Guide

EAS101

1995 DPEC, Inc.

DPEC, Inc.

This courseware and manual are protected by the U. S. Copyright Law (Title 17 United StatesCode). Unauthorized reproduction and/or sales may result in imprisonment of up to one year andfines of up to $10,000 (17 USC 505). Copyright infringements may be subject to civil liability upto $50,00 (17 USC 504).

Use, duplication or disclosure by the Government is subject to restrictions as set forth inSubparagraph (c) (1) (ii) of the Rights in Technical Data and Computer Software Clause at DFARS252.227-7013 or FAR 52.227-14. Contractor: DPEC, Inc.

11.95

Page 2: Easy Tri Eve

USING EASYTRIEVE PLUS Table of Contents

DPEC, Inc.

UNIT A EASYTRIEVE PLUS OVERVIEWObjective #1 Introduction ....................................................1Objective #2 Program Examples ................................................6

UNIT B BUILDING A SIMPLE PROGRAMObjective #1 Coding a Library Section .......................................14Objective #2 Coding a JOB Activity Section ..................................22Objective #3 Coding a REPORT Section ........................................31

UNIT C CUSTOMIZING THE REPORTObjective #1 Using REPORT Statement Parameters ..............................43Objective #2 Using Report PROCs .............................................51

UNIT D ENHANCING THE PROGRAMObjective #1 Statements and Macros ..........................................60Objective #2 File Processing ................................................76

Page 3: Easy Tri Eve

EASYTRIEVE PLUS OVERVIEW--Introduction A1

DPEC, Inc. 1

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

1. EASYTRIEVE PLUS is user-friendly, allowing you to retrieve and manage data using simple, English-like statements. It can both process data and create formatted reports without resort to complicated programming languages.

2. An EZT+ program is made up of three basic sections: • Environment • Library • Activity

3. The Environment section allows you to override system defaults. It is optional and seldom used.

4. You use the Library section to define the data your program will use. It contains two parts: • FILE statement • field definitions

5. One or more Activity sections contain the code statements which select and manipulate data and format the report.

Activity sections can be any of the following: • JOB • SORT • REPORT

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

Page 4: Easy Tri Eve

A1 EASYTRIEVE PLUS OVERVIEW--Introduction

2 DPEC, Inc.

Welcome to DPEC's course on

EASYTRIEVE PLUS.

This course explains how to create EASYTRIEVE PLUS programs to manipulate data and produce reports.

This unit introduces the EASYTRIEVE PLUS system and explains the basic rules for coding in EASYTRIEVE PLUS.

Subsequent units begin with the coding of a simple program and then proceed to explore features which allow you to write more complex programs.

EASYTRIEVE PLUS

is a system designed to let you retrieve and manage data using simple, English-like statements.

It provides the tools you need to easily produce comprehensive reports or to perform more complex programming.

NOTE: Throughout this course, to save time and space, we will often refer to EASYTRIEVE PLUS as EASYTRIEVE or EZT+.

EASYTRIEVE's processing capabilities include

• conditional logic handling • interfaces to many common databases • access to varied data formats (fixed, variable, undefined or spanned) • extraction of all types of data (sequential, ISAM, VSAM or databases) • matching and merging of unlimited number of files

EASYTRIEVE's reporting capabilities include

• automatic report formatting, easily modified by the user • multiple reports from one pass at the data • edit masks for formatting numeric data • report line and control break logic

Page 5: Easy Tri Eve

EASYTRIEVE PLUS OVERVIEW--Introduction A1

DPEC, Inc. 3

Now that you have some idea of what EASYTRIEVE has to offer, let's examine the basic sections and flow of an EASYTRIEVE program.

An EZT+ program is made up of three basic sections:

• Environment • Library • Activity

The Environment section allows you to override system defaults. It is optional and seldom used.

You use the Library section to define the data your program will use: input, output and working storage fields. It is recommended but not required.

Note: This section is not required because you have the option to define your data with the DEFINE statement in the Activity section.

One or more Activity sections make up the mandatory part of your program. They contain the code statements which select and manipulate data and format the report.

The example programs used throughout this course contain Library and Activity sections. For information on Environment section parameters, see your EASYTRIEVE PLUS documentation.

Let's take a closer look at the Library section.

The Library section contains two parts:

• FILE statement

Code the FILE statement at the beginning of the section to describe an input or output file your program will use.

• field definitions

Define the data fields within a record in an input or output file or the fields in working storage. To code the Library section, use the information in the file layout provided by your information systems department.

Page 6: Easy Tri Eve

A1 EASYTRIEVE PLUS OVERVIEW--Introduction

4 DPEC, Inc.

The following file layout is typical of what is usually available.

Filename EMPFILER Attributes Record Format = FB Record Size = 74 Blocksize = 1800

Field Content Start Location Length Type Comments SOC SEC NUMBER 1 9 N FIRST NAME 10 8 A LAST NAME 18 10 A DEPARTMENT 28 5 A JOB TITLE 33 11 A PAY GRADE 44 2 N SUPERVISOR NAME 46 10 A START DATE 56 6 N month day year SALARY 62 5 N 0 decimals TOTAL SICK DAYS 67 2 N 0 decimals USED SICK DAYS 69 2 N 0 decimals TOTAL VACATION 71 2 N 0 decimals USED VACATION 73 2 N 0 decimals

Once you've established the data you'll be working with in the Library section, you're ready to code the program activities.

ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Library ³ ³ statements ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ JOB ³ ³ SORT ³ ³ statements ³ ³ statement ³ ³ procedures ³ ³ procedures ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ ÚÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ REPORT ³ ³ statements ³ ³ procedures ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÙ

The Activity section can contain two types of activities:

JOB and SORT JOB activities begin with a JOB statement and continue with logic statements. The logic statements read, select and manipulate data, print the data to reports, or write it to an output file.

Each JOB activity can also contain user-written procedures (PROCs) and REPORT subactivities.

Page 7: Easy Tri Eve

EASYTRIEVE PLUS OVERVIEW--Introduction A1

DPEC, Inc. 5

The REPORT subsection defines formatting for your report. You can also code PROCs within a REPORT.

SORT activities reorder data to produce sequenced files. They start with a SORT statement and can also contain PROCs.

Page 8: Easy Tri Eve

A2 EASYTRIEVE PLUS OVERVIEW--Program Examples

6 DPEC, Inc.

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

1. EASYTRIEVE provides the following automatic formatting features:

• centering of report body and titles

• library field names as column headings

• column headings centered over data

• run date and page number printed at top

2. These basic rules apply to coding EZT+ statements:

• The default statement area is columns 1 to 72.

• More than one EZT+ statement can be coded on a line.

• Code a + as the final character to continue a statement with the first non-blank character on the next line.

• To code a comment, make an asterisk (*) the first non-blank character of a statement.

• Leave at least one space after all delimiters except for ( (left parenthesis)and : (colon).

3. The following rules apply to field names and other labels:

• can contain up to 40 characters

• can contain any alphabetic character, lower or uppercase; decimal digits 0 through 9; all special characters except delimiters

• first character must be an alphabetic character or a decimal digit

• must contain at least one alphabetic or special character

• must be unique within a file

Page 9: Easy Tri Eve

EASYTRIEVE PLUS OVERVIEW--Program Examples A2

DPEC, Inc. 7

∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points (cont.) ∞∞∞∞∞∞∞∞∞∞∞∞∞

4. Alphabetic literals can contain up to 254 characters. To include a single quote in the literal, code 2 quotes.

5. Numeric literals can contain up to 18 decimal digits and a single decimal point. Use a + or - as a prefix to indicate the algebraic sign.

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

Page 10: Easy Tri Eve

A2 EASYTRIEVE PLUS OVERVIEW--Program Examples

8 DPEC, Inc.

This objective describes some EASYTRIEVE PLUS programs and the reports they produce.

It also explains some of the basic rules for coding in EZT+.

This simple EASYTRIEVE PLUS program contains many of the sections and subsections described earlier.

FILE EMPFILER F-NAME 10 8 A L-NAME 18 10 A DEPT 28 5 A TOTAL-SICK 67 2 N 0 USED-SICK 69 2 N 0 TOTAL-VAC 71 2 N 0 USED-VAC 73 2 N 0 JOB INPUT EMPFILER NAME DAYSOFF PRINT REPT1 REPORT REPT1 SEQUENCE DEPT L-NAME TITLE 01 'VACATION AND SICK DAYS REPORT' LINE 01 DEPT F-NAME L-NAME TOTAL-SICK USED-SICK TOTAL-VAC USED-VAC

The Library section contains the FILE statement and the field definitions for the input file EMPFILER.

The JOB activity section contains the JOB statement and a statement which tells EZT+ to print data to a report.

The REPORT subactivity specifies how REPT1 displays.

Here is the report this program produces.

9/08/99 VACATION AND SICK DAYS REPORT PAGE 1

DEPT F-NAME L-NAME TOTAL-SICK USED-SICK TOTAL-VAC USED-VAC FIN Sherrie Mathers 10 02 15 06 FIN Mary Snyder 05 05 15 06 HRES Letitia Washington 10 02 15 04 HRES Yuichiro Yashiki 10 05 15 02 MNT Tom Wilson 05 03 10 04 SALES Jerry Freeman 10 02 10 05 SALES Emily Vincent 10 04 15 03 SYS Jeff Johnson 10 01 15 03 SYS Linda Jones 10 04 20 05 SYS Carmen Saez 10 00 10 04

Page 11: Easy Tri Eve

EASYTRIEVE PLUS OVERVIEW--Program Examples A2

DPEC, Inc. 9

In the report below, the Library section defines both the input file (EMPFILER) and an output file for the sort (SALSORT).

FILE EMPFILER SSNUM 1 9 N F-NAME 10 8 A L-NAME 18 10 A DEPT 28 5 A SALARY 62 5 N 0 FILE SALSORT COPY EMPFILER SORT EMPFILER TO SALSORT + USING (DEPT SALARY D) JOB INPUT SALSORT NAME SALARY PRINT RPT1-SALARY PRINT RPT2-SALARY REPORT RPT1-SALARY TITLE 'EMPLOYEE SALARIES BY NAME WITHIN DEPARTMENT' LINE 01 DEPT F-NAME L-NAME SALARY REPORT RPT2-SALARY TITLE 'EMPLOYEE SALARIES BY SS NUMBER WITHIN DEPARTMENT' LINE 01 DEPT SSNUM SALARY

The SORT activity creates an output file (SALSORT) which then is printed by the JOB activity.

The REPORT section specifies the report title and the fields to include.

Note that EASYTRIEVE can produce multiple reports from one pass through a file. Next, look at the reports you can produce from some fairly simple code.

EASYTRIEVE provides the following automatic formatting features: • centering of report body and titles • library field names as column headings • column headings centered over data • run date and page number printed at top

In the example below, we have also specified that the list of employees be ordered by last name within departments.

Page 12: Easy Tri Eve

A2 EASYTRIEVE PLUS OVERVIEW--Program Examples

10 DPEC, Inc.

FILE EMPFILER º 9/26/98 EMPLOYEES BY DEPARTMENT PAGE 1 SSNUM 1 9 N º F-NAME 10 8 A º DEPT F-NAME L-NAME SSNUM L-NAME 18 10 A º FIN Sherrie Mathers 456787678 DEPT 28 5 A º FIN Mary Snyder 498765433 JOB INPUT EMPFILER NAME ROSTER º HRES Letitia Washington 342986544 PRINT RPT1-ROSTER º HRES Yuichiro Yashiki 234723456 REPORT RPT1-ROSTER º MNT Tom Wilson 777654321 SEQUENCE DEPT L-NAME º SALES Jerry Freeman 292549357 TITLE 'EMPLOYEES BY DEPARTMENT' º SALES Emily Vincent 512365764 LINE 01 DEPT F-NAME L-NAME SSNUM º SYS Jeff Johnson 454445676 º SYS Linda Jones 123212323 º SYS Carmen Saez 543456787

You'll see later how to customize a report by adding other statements and parameters.

Now that you've seen some sample EASYTRIEVE programs, let's take a quick look at some rules for coding in EZT+.

This course uses the following notation conventions whenever you see the syntax of a statement or a sample of EASYTRIEVE code:

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ SYMBOL ³ MEANING ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ UPPERCASE ³ Keywords or options. You must spell these ³ ³ ³ exactly as shown, though they can be in ³ ³ ³ lowercase. ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ lowercase ³ Values that you supply. ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ < > ³ Optional entry or choice of entry. ³ ³ angle brackets ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ³ ³ You must choose at least one value from ³ ³ vertical bar ³ a group. ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ... ³ The parameters preceding the ellipsis can be ³ ³ in syntax ³ repeated any number of times ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ... in code ³ Code is omitted ³ ³ ... in output ³ Output lines are omitted ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

Page 13: Easy Tri Eve

EASYTRIEVE PLUS OVERVIEW--Program Examples A2

DPEC, Inc. 11

Due to space constraints, this course often displays only that part of a program currently under discussion. Output data lines, blank lines and spaces in a report may be omitted, even though the defaults or coded formats may call for blank lines or different column spacing.

Note: You will find that the syntax for EASYTRIEVE PLUS statements presented in this course does not cover all optional parameters.

Please refer to your EASYTRIEVE PLUS documentation for the complete syntax.

Here are some rules for coding EZT+ statements.

• The default statement area is columns 1 to 72, but your systems staff may establish another area (e.g., 7 to 72) to allow for entry of optional data that EZT+ ignores.

• More than one EZT+ statement can be coded on a line. Use a period (.) to separate these statements.

• Code a + as the final character to continue a statement with the first non-blank character on the next line.

• To code a comment, make an asterisk (*) the first non-blank character of a statement.

• Leave at least one space after all delimiters except for ( (left parenthesis)and : (colon).

Page 14: Easy Tri Eve

A2 EASYTRIEVE PLUS OVERVIEW--Program Examples

12 DPEC, Inc.

The following characters are EASYTRIEVE PLUS delimiters:

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ Character ³ Function ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ . period ³ ends a statement ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ blank ³ separates the parts of a statement ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ () parentheses ³ enclose multiple subparameters ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ , comma ³ separates for readability (optional) ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ : colon ³ delimits file, record and field ³ ³ ³ qualifications ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ ' ' single quotes ³ enclose alphabetic literals ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

The following rules apply to field names:

• can contain up to 40 characters

• can contain any alphabetic character, lower or uppercase; decimal digits 0 through 9; all special characters except delimiters

• first character must be an alphabetic character or a decimal digit

• must contain at least one alphabetic or special character

• must be unique within a file

These rules also apply to labels that identify JOBs, procedures, REPORTs and statements.

Alphabetic literals (enclosed within single quotes) can contain up to 254 characters. If you need to include a single quote in the literal, code 2 quotes as shown.

O'GRADY LEASING becomes 'O''GRADY LEASING'

Page 15: Easy Tri Eve

EASYTRIEVE PLUS OVERVIEW--Program Examples A2

DPEC, Inc. 13

Numeric literals can contain up to 18 decimal digits and a single decimal point. You can also use a + or - as a prefix to indicate the algebraic sign. For example

78306 -78306 -78306.245

The rules presented here are some of the most basic coding rules. For more detail and a complete listing, see your EZT+ documentation.

Page 16: Easy Tri Eve

B1 BUILDING A SIMPLE PROGRAM--Coding a Library Section

14 DPEC, Inc.

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

1. The FILE statement begins the Library section. You use it to define both input and output files.

Syntax: FILE file-name <attributes>

A filename can be 1 to 8 characters (up to 7 in DOS.)

2. The remainder of the Library section defines fields used in the program. The syntax is

field-name start-location field-length data-type + <decimal-positions> <HEADING 'literal'> + <MASK (letter³BWZ³'literal')>

3. Specifying the number of decimal positions for a non-alphanumeric field tells EASYTRIEVE

• that this is a quantitative field • to automatically total this field in a control report • where to place commas and decimals and to suppress leading zeros when the field data prints

4. The HEADING parameter lets you supply more descriptive names for column headings. To stack parts of a heading, enter the parts as separate literals.

5. An edit mask lets you define a pattern of characters for printing numeric data. You create a mask using the following characters:

9 prints a digit Z prints a digit, or if a leading zero, a blank * prints a digit, or if a leading zero, an * - prints a minus sign before the first non-zero digit of a negative number $ prints a currency symbol ($) before the first non-zero digit and suppresses leading zeros

Page 17: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a Library Section B1

DPEC, Inc. 15

∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points (cont.) ∞∞∞∞∞∞∞∞∞∞∞∞∞

6. If the exact data you need for a report is included as part of another field, you can break the field apart by redefining it. For example,

BIRTH-DATE 72 6 MASK 'Z9/99/99' BIRTH-MTH 72 2 BIRTH-DAY 74 2 BIRTH-YR 76 2

7. Define working storage fields as either W or S, using the letter as the start-location for the field:

W values associated with each individual record S values not associated with a record

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

Page 18: Easy Tri Eve

B1 BUILDING A SIMPLE PROGRAM--Coding a Library Section

16 DPEC, Inc.

In this unit we build a simple EASYTRIEVE program.

We start, in this objective, with learning to code the Library section.

The FILE statement normally begins the Library section. You use it to define both input and output files.

Syntax: FILE file-name <attributes>

Example: FILE INVNTRY

A file-name can be 1 to 8 characters (up to 7 in DOS.)

File attributes vary depending on the file you are using. They can specify file type, device type and record format.

Often they don't have to be included in your EZT+ program because they're in the JCL statements. Check with your systems department to see what is required.

Next come the field definitions.

Syntax: field-name start-location field-length data-type + <decimal-positions> <HEADING 'literal'> + <MASK (letter³BWZ³'literal')>

Example: L-NAME 18 10 A SALARY 50 5 N 0

Page 19: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a Library Section B1

DPEC, Inc. 17

As you can see, the required parameters are

field-name use the field name from the record layout or create a new one for the program

start-location define based on position 1 of the record

field-length specify in bytes (characters/spaces)

data-type code the appropriate letter:

TYPE MAX. LENGTH (BYTES) A Alphanumeric 32,767 N Numeric 18 P Packed 10 U Unsigned Packed 9 B Binary 4

The top three data-types are the most commonly used. For all except alphanumeric, EASYTRIEVE can perform calculations on the data in that field.

The first optional parameter is decimal-positions.

You can specify the number of decimal positions for any non-alphanumeric field. This tells EASYTRIEVE

• that this is a quantitative field • to automatically total this field in a control report • where to place commas and decimals and to suppress leading zeros when the field data prints

Example: BIWEEKLY-GROSS 84 4 P 2

As you saw earlier, EZT+ automatically uses field names for report column headings, but sometimes these are not the heading you want on the report. You can instead use the HEADING parameter to specify headings for any or all columns when you define the fields.

Example: L-NAME 18 10 A HEADING 'LAST NAME'

To keep columns with long names from being too wide on the report, stack the headings by making each word a literal.

Example: L-NAME 18 10 A HEADING ('LAST' 'NAME')

Page 20: Easy Tri Eve

B1 BUILDING A SIMPLE PROGRAM--Coding a Library Section

18 DPEC, Inc.

The final optional parameter we consider at this time is MASK.

An edit mask lets you define a pattern or format for printing numeric data. For example,

Field data Mask Result 323456765 '999-99-9999' 323-45-6765 035467 '$$$,$$9' $35,467

You create a mask using the following characters:

9 prints a digit Z prints a digit, or if a leading zero, a blank * prints a digit, or if a leading zero, an * - prints a minus sign before the first non-zero digit of a negative number $ prints a currency symbol ($) before the first non-zero digit and suppresses leading zeros

In the mask, you must designate each digit in the field. You can also add common characters, such as

. place a decimal point ( ) insert parentheses (phone numbers) , separate long numbers - break up numbers (phone, social security) / format dates

After the MASK keyword, you enter at least one of this group of parameters: letter name for the edit mask in the following literal or one already defined literal the mask format you are defining BWZ used when a field should not be printed if it contains all zeros

Example: SSNUM 1 9 N MASK (S '999-99-9999')

This defines a mask for a social security number and names it S.

If you define a mask using the letter parameter, you can specify that mask for another field by using just the letter.

Page 21: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a Library Section B1

DPEC, Inc. 19

In the examples below, M is a mask for money and P is a phone mask.

BIWEEKLY-GROSS 84 4 P 2 MASK (M '$$$,$$9.99') MONTHLY-GROSS 88 4 P 2 MASK (M) PHONE 25 10 N MASK (P '(999)999-9999')

If you do not specify a mask, the system default for numeric fields depends on the number of decimal positions specified:

SALARY 50 5 N '99999' SALARY 50 5 N 0 'ZZ,ZZZ-' SALARY 50 5 N 2 'ZZZ.99-'

Note: Remember to include a negative sign (-) in the mask for fields that may be negative.

At times, the exact data you need for a report is included as part of another field. In that case, you can break the field apart by redefining it, as shown here:

BIRTH-DATE 72 6 MASK 'Z9/99/99' BIRTH-MTH 72 2 BIRTH-DAY 74 2 BIRTH-YR 76 2

With this redefinition, you can access birth month, day and year separately.

You can also define working storage fields in the Library section.

Working storage is an area set aside to keep results of calculations or other information created as the EASYTRIEVE program runs.

Define working storage as either W or S, using the letter as the start-location for the field:

W values associated with each individual record S values not associated with a record

Page 22: Easy Tri Eve

B1 BUILDING A SIMPLE PROGRAM--Coding a Library Section

20 DPEC, Inc.

W values allow you to create new temporary fields for each record. For example,

calculate each employee's deductions by subtracting net pay from gross pay.

BIWEEKLY-GROSS 84 4 P 2 BIWEEKLY-NET 88 4 P 2 DEDUCTIONS W 4 P 2

S values cannot be printed and are used mainly for totaling, percentages and counting. For example,

Use TOTAL-GROSS to store the total of all employees' gross salaries.

TOTAL-GROSS S 6 P 2

Or store a count of the number of employees selected for a report.

TOTAL-EMP S 2 P

With working storage fields, you can use the VALUE option to assign initial values to fields.

PROPOSED-RAISE-PERCENT W 2 N VALUE 05

If you don't assign a value, the defaults are zeros for numeric and blanks for alphanumeric fields.

Now that we've covered all the statements and parameters, let's build the Library section of our example program.

The purpose of the example program is to report on vacation days allotted and remaining to employees.

These are all the fields from the input file that we need to define.

FILE EMPFILER F-NAME 10 8 A L-NAME 18 10 A DEPT 28 5 A PAY-GRADE 44 2 N TOTAL-VAC 71 2 N 0 USED-VAC 73 2 N 0

Page 23: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a Library Section B1

DPEC, Inc. 21

We also need two working storage fields for some calculations we'll be doing later in the JOB activity section.

FILE EMPFILER F-NAME 10 8 A L-NAME 18 10 A DEPT 28 5 A PAY-GRADE 44 2 N TOTAL-VAC 71 2 N 0 USED-VAC 73 2 N 0 NEW-VAC W 2 N 0 VAC-REMAIN W 2 N 0

The working storage field NEW-VAC will hold the new total amount of vacation days for each employee.

Note that it has the same field-length, data-type and decimal positions as the other two vacation fields.

The last file definition for a working storage field is called VAC-REMAIN and will hold the amount of vacation days remaining for each employee.

We'll see later how these working storage fields will be used.

OK. These are the basic definitions we need. Let's do one more thing in the Library section to specify how the report will look -- add more descriptive headings to our course example fields.

FILE EMPFILER F-NAME 10 8 A HEADING 'FIRST NAME' L-NAME 18 10 A HEADING 'LAST NAME' DEPT 28 5 A HEADING 'DEPARTMENT' PAY-GRADE 44 2 N TOTAL-VAC 71 2 N 0 USED-VAC 73 2 N 0 HEADING ('VACATION' 'USED') NEW-VAC W 2 N 0 HEADING ('NEW' 'TOTAL' 'VACATION') VAC-REMAIN W 2 N 0 HEADING ('VACATION' 'REMAINING')

That completes the Library section for our course example.

In case you're wondering ...

... we don't need alternate headings for PAY-GRADE and TOTAL-VAC because they don't appear in the report.

Page 24: Easy Tri Eve

B2 BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section

22 DPEC, Inc.

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

1. The JOB statement begins JOB activity. Use it to initiate processing and to identify the automatic input file.

Syntax: JOB <INPUT file-name> <NAME job-name>

2. IF statements follow the JOB statement.

Syntax: IF field-1 relational-operator object statements to execute for true IF END-IF

3. EZT+ follows the standard order of operations for arithmetic expressions: multiplication and division are evaluated before addition and subtraction, in order from left to right.

Use parentheses to change the order of evaluation -- EZT+ evaluates expressions within parentheses first.

4. Use an ELSE statement to specify statements to execute when the condition is false.

Syntax: IF field-1 relational-operator object statements to execute for true IF ELSE statements to execute for false IF END-IF

5. Use AND and OR to combine conditional expressions.

Page 25: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section B2

DPEC, Inc. 23

∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points (cont.) ∞∞∞∞∞∞∞∞∞∞∞∞∞

6. Use an assignment statement to establish a value in a field. Copy data from another field, use a literal or an arithmetic expression.

Syntax: field-name-1 = field-name-2³literal³expression

7. Use the INTEGER and ROUNDED parameters in assignment statements to assure that the fractional portion of a value is handled the way you want it to be.

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

Page 26: Easy Tri Eve

B2 BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section

24 DPEC, Inc.

In the prior objective, you started to build a simple EASYTRIEVE program by coding the Library section.

In this objective, you learn how to code a JOB Activity section.

The JOB statement begins JOB activity. You use it to initiate processing and to identify the automatic input file.

Syntax: JOB <INPUT file-name> <NAME job-name>

Example: JOB INPUT INVFILE NAME MONTHLY

If you don't specify an input file, EZT+ supplies one based on your program: - If you have a SORT activity right before the JOB activity, it uses the SORT output file. - Otherwise, it uses the first file defined in the Library section.

The optional NAME parameter is used only for documentation. We use it consistently in this course to help you keep track of the various example jobs.

After the JOB statement, you code any logic statements necessary for processing the data. Look first at the IF statement.

Syntax: IF field-1 relational-operator object statements to execute for true IF END-IF

Example: IF DEPT = 'SYS' PRINT REPT1 END-IF

Example: IF SALARY > 30000 NEWSAL = SALARY * 1.1 END-IF

Page 27: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section B2

DPEC, Inc. 25

Each record read from the input file is processed against the condition established by the IF statement.

If the condition is true, EZT+ executes the statements which follow.

If the condition is false, EZT+ does not execute the statements and control passes to the statement following the END-IF.

Every IF statement must end with an END-IF statement.

relational-operator can be one of the following:

= or EQ equal to ª= or NE not equal to (see NOTE) > or GT greater than < or LT less than >= or GE greater than or equal to <= or LE less than or equal to

NOTE: Depending on your terminal, the caret, tilde and not sign (ª) all can indicate a logical not.

object can be a literal, a field or an arithmetic expression:

literal IF USED-SICK LT 3 field IF USED-SICK = TOTAL-SICK arithmetic expression IF USED-SICK > (TOTAL-SICK / 2)

Let's look at literals and arithmetic expressions in more detail.

Literals can be alphanumeric or numeric. Alphanumerics must be enclosed in single quotes.

You can also specify a series or range of literals.

IF DEPT = 'SYS' 'FIN' 'HRES' IF VAC-REMAIN = 5 THRU 10

The condition is true if field-1 is equal to any of the values in the series or is within the range.

Page 28: Easy Tri Eve

B2 BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section

26 DPEC, Inc.

Valid operators in arithmetic expressions are + addition - subtraction * multiplication / division

EZT+ follows the standard order of operations for arithmetic expressions: multiplication and division are evaluated before addition and subtraction, in order from left to right.

Use parentheses to change the order of evaluation -- EZT+ evaluates expressions within parentheses first.

A variation on the standard IF statement evaluates the class of data in a field. Use this when you need to test a field to make sure the data is valid.

Syntax: IF field-1 <NOT> object statements if true END-IF

object in this case is a class condition such as ALPHABETIC NUMERIC ZERO SPACE

Example: IF SSNUM NOT NUMERIC PERFORM ERR-REPT

Use the NOT parameter to reverse the condition test.

You can optionally use an ELSE statement to specify statements to execute when the condition is false.

Syntax: IF field-1 relational-operator object statements to execute for true IF ELSE statements to execute for false IF END-IF

Example: IF DEPT = 'SYS' PRINT REPT1 ELSE PRINT REPT2 END-IF

Page 29: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section B2

DPEC, Inc. 27

You can also combine conditional expressions.

Example: IF DEPT = 'SYS' AND SALARY > 40000

In this case the IF statement is true if both conditions are true for the record being evaluated.

Example: IF USED-VAC > 10 OR USED-SICK > 4

In this case, if either condition is true, the IF statement is true.

IF you use both AND and OR in the same IF statement, EASYTRIEVE evaluates ANDs before ORs. For example,

IF SALARY > 50000 OR IF SALARY > 30000 AND START-YEAR < 90

This statement will select records that test true for either of the following conditions:

IF SALARY > 50000 IF SALARY > 30000 AND START-YEAR < 90

You can change the default order by using parentheses to designate the expression to be evaluated first.

You can use an assignment statement to establish a value in a field. Copy data from another field, or use a literal or an arithmetic expression.

Syntax: field-name-1 = field-name-2³literal³expression

Example: PHONE = HOME-PHONE

Example: INCREASE-A = 4.5

Example: TOTAL-DAYS = TOTAL-VAC + TOTAL-SICK

When you use an arithmetic expression that results in fractional values, you may need to consider how you want EZT+ to handle them.

Example: NEWSAL = BI-WEEKLY-SALARY * 1.07

Without additional parameters, the value in NEWSAL depends on the number of decimal places you defined for the field.

Page 30: Easy Tri Eve

B2 BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section

28 DPEC, Inc.

EASYTRIEVE's default action is to truncate the result of the expression moved to the receiving field if the number of decimal places exceeds the number defined.

The following syntax allows you some options:

field-name-1 = <INTEGER> <ROUNDED³TRUNCATED> expression

INTEGER causes EZT+ to ignore the fractional portion of the resulting value. In other words, only numerics to the left of the decimal point are transferred.

ROUNDED causes EZT+ to round off the fractional portion based on the number of decimal places in the value and in the receiving field. It follows the standard rounding rule of increasing the value of the least significant digit by 1 if the rounding digit is greater than or equal to 5.

TRUNCATED is the default action.

Let's apply these parameters to our earlier example.

Assume that these fields are defined:

BI-WEEKLY-SALARY 85 6 N 2 NEWSAL W 7 N 2

Example: NEWSAL = BI-WEEKLY-SALARY * 1.07

If the value of BI-WEEKLY-SALARY is 1873.95, the result of the expression is 2005.1265. With no parameters specified, the final two decimal digits are truncated and the value placed in NEWSAL is 2005.12

If instead you code the ROUNDED parameter,

Example: NEWSAL ROUNDED = BI-WEEKLY-SALARY * 1.07

the value placed in NEWSAL is 2005.13.

You can use INTEGER with ROUNDED to first round the result and then transfer only the numerics to the receiving field. Assume that these fields are defined:

SALARY 62 5 N 0 INCREASE W 4 N 0

Page 31: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section B2

DPEC, Inc. 29

Example: INCREASE INTEGER = SALARY * .05

With just the INTEGER parameter, if the value of SALARY is 36,459, the result of the expression is 1822.95. The value placed in INCREASE is 1822.

If however, you also use the ROUNDED parameter,

Example: INCREASE INTEGER ROUNDED = SALARY * .05

the value placed in INCREASE is 1823.

Once you've coded all your logic, you need to make whatever data is selected available for output to a report. Use the PRINT statement to do this:

Syntax: PRINT report-name

Example: PRINT SALES-RPT

Example: IF SALARY < 25000 PRINT SAL-RPT-A END-IF

Now that we've covered all the statements and parameters, let's build the JOB section of our example program.

Here's the Library section where we defined the fields. The purpose of the example program is to report on vacation days allotted and remaining to employees.

FILE EMPFILER F-NAME 10 8 A HEADING 'FIRST NAME' L-NAME 18 10 A HEADING 'LAST NAME' DEPT 28 5 A HEADING 'DEPARTMENT' PAY-GRADE 44 2 N TOTAL-VAC 71 2 N 0 USED-VAC 73 2 N 0 HEADING ('VACATION' 'USED') NEW-VAC W 2 N 0 HEADING ('NEW' 'TOTAL' 'VACATION') VAC-REMAIN W 2 N 0 HEADING ('VACATION' 'REMAINING')

Normally, this would be a simple matter of outputting the contents of the TOTAL-VAC and VAC-REMAIN fields. In this case, the company is awarding bonus vacation days to employees, with the number of days based on pay grade.

Because there are some decisions involved, we'll need to code some logic statements.

Page 32: Easy Tri Eve

B2 BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section

30 DPEC, Inc.

FILE EMPFILER... field definition statements ... JOB INPUT EMPFILER NAME COURSE-EXAMPLE IF PAY-GRADE > 3 NEW-VAC = TOTAL-VAC + 2 ELSE NEW-VAC = TOTAL-VAC + 1 END-IF VAC-REMAIN = NEW-VAC - USED-VAC PRINT REPT1

The JOB statement specifies EMPFILER as the input file.

The IF statement selects records with a PAY-GRADE value higher than 3. The following assignment statement defines NEW-VAC as the value of TOTAL-VAC plus 2.

If the IF statement is not true, the ELSE statement allows you to offer an alternative action. The assignment statement sets the value of NEW-VAC for all other pay grades to one more than TOTAL-VAC.

The last logic statement calculates a value for VAC-REMAIN that is the amount of vacation each employee still has for the year.

And finally, the PRINT statement makes the data selected available to a report named REPT1.

That completes the JOB activity section of our example program.

All that remains is to add a REPORT subsection to display output. We'll do that in the next objective.

Page 33: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section B3

DPEC, Inc. 31

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

1. Each REPORT section begins with a REPORT statement.

Syntax: REPORT report-name

You can add spacing control, testing aid, format determination and file directing parameters to tailor the report to your requirements.

2. Code report definition statements after the REPORT statement in the following order: • SEQUENCE • CONTROL • SUM • TITLE • HEADING • LINE

3. Use the SEQUENCE statement to specify the order data prints to the report.

Syntax: SEQUENCE field-name-1 <D> field-name-2 <D> ...

4. Use the CONTROL statement to have the report accumulate totals and print them at control breaks.

Syntax: CONTROL field-name³FINAL <NEWPAGE³RENUM>+ <NOPRINT> ...

5. Use the SUM statement to specify which fields you want totaled for control breaks.

Syntax: SUM field-name-1 field-name-2 ...

6. Use TITLE statements to define one or more titles for a report, with up to 99 allowed.

Syntax: TITLE <nn> <+n³-n³COL nn> field-name³'literal' ...

Page 34: Easy Tri Eve

B3 BUILDING A SIMPLE PROGRAM--Coding a REPORT Section

32 DPEC, Inc.

∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points (cont.) ∞∞∞∞∞∞∞∞∞∞∞∞∞

7. Use the HEADING statement to define alternate column headings for any fields in the report. These definitions override any you specified in the Library section.

Syntax: HEADING field-name 'literal'

8. Use LINE statements to define the content of report lines.

Syntax: LINE <nn> <+n³-n³COL nn³POS nn>+ field-name³'literal' ...

9. EASYTRIEVE stores a count of the number of records in a control group in the TALLY field. To display the count, add TALLY to the LINE statement.

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

Page 35: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section B3

DPEC, Inc. 33

In prior objectives, you started to build a simple EASYTRIEVE program by coding the Library section and the JOB section.

In this objective, you learn how to code a REPORT section.

Each REPORT section begins with a REPORT statement.

Syntax: REPORT report-name

Example: REPORT INV-REPT

Beyond this basic syntax, there are parameters you can add to tailor the report to your requirements. These parameters fall into four categories:

• spacing control • testing aid • format determination • file directing

In this objective we'll look at some spacing and testing parameters. You'll see the others later in the course.

Page 36: Easy Tri Eve

B3 BUILDING A SIMPLE PROGRAM--Coding a REPORT Section

34 DPEC, Inc.

This table displays each spacing control parameter, its description and its default EZT+ value.

ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄ¿ ³ PARAMETER ³ DESCRIPTION ³ DEFAULT ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´ ³ PAGESIZE ³ number of lines per page ³ 58 ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´ ³ LINESIZE ³ length per line ³ 132 ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´ ³ SKIP ³ blank lines between line groups ³ 0 ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´ ³ SPACE ³ blanks between field columns and ³ ³ ³ ³ between fields and literals in titles ³ 3 ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´ ³ TITLESKIP ³ blank lines after title line(s) ³ ³ ³ ³ before heading or detail lines begin ³ 3 ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´ ³ SPREAD ³ spreads data evenly over entire line; ³ NOSPREAD ³ ³ ³ overrides SPACE ³ ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´ ³ NOADJUST ³ left-justifies title lines and body ³ centered ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´ ³ NODATE ³ suppresses date on first title line ³ prints ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´ ³ NOPAGE ³ suppresses page number on title line ³ prints ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄ´ ³ NOHEADING ³ suppresses column headings ³ prints ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÙ

To summarize ...

PAGESIZE and LINESIZE let you allow for variations in the length and width of your report.

Example: REPORT REPT1 PAGESIZE 40 LINESIZE 80

SKIP, SPACE and TITLESKIP allow you to add extra blank lines and spaces to make your report more attractive.

Example: REPORT RPT2 SKIP 1 TITLESKIP 4

SPREAD and NOADJUST give you different options from the standard centering. They are mutually exclusive.

Example: REPORT REPT-INV LINESIZE 80 NOADJUST

Page 37: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section B3

DPEC, Inc. 35

NODATE, NOPAGE and NOHEADING allow you to suppress printing some standard top-of-report information.

Example: REPORT NEWRPT NODATE NOPAGE

The testing aid parameters let you control the amount of data output to a report, which can be pretty important when you are testing a program.

Use the LIMIT parameter to specify the number of records printed on the report.

Use the EVERY parameter to specify that only every nth line is printed on the report.

Example: REPORT REPT1 LIMIT 50

Example: REPORT INV-RPT EVERY 5

After the REPORT statement, you code report definition statements to define the report content. Code them in the following order:

• SEQUENCE • CONTROL • SUM • TITLE • HEADING • LINE

Use the SEQUENCE statement to specify the order data prints to the report.

Syntax: SEQUENCE field-name-1 <D> field-name-2 <D> ...

Example: SEQUENCE DEPT SALARY D L-NAME

This example sequences the report data by department, then by salary within the department, then by last name within a salary. Coding D after SALARY sequences that field in descending order.

You can specify as many fields as your system sort allows, using any field from any input file or any W working storage field. The fields you sequence on DO NOT have to appear in the printed report.

Page 38: Easy Tri Eve

B3 BUILDING A SIMPLE PROGRAM--Coding a REPORT Section

36 DPEC, Inc.

Use the CONTROL statement to have the report accumulate totals and print them at control breaks.

Whenever the value of a control field changes, or at the end of the report, a control break occurs and EASYTRIEVE prints totals for all quantitative fields in the report.

Syntax: CONTROL field-name³FINAL <NEWPAGE³RENUM> <NOPRINT> ...

field-name can be any nonquantitative field from any input file or any W working storage field.

FINAL lets you specify options for the end-of-report control break.

NEWPAGE starts the report on a new page following the printing of the control break totals. Page numbers continue in sequence.

RENUM also starts a new page, but restarts the numbering at PAGE 1.

NOPRINT suppresses the printing of accumulated totals at that control break. Final totals print automatically unless you code FINAL NOPRINT.

Example: CONTROL FINAL NOPRINT DEPT NEWPAGE SUPERVISOR

This example causes totals to accumulate and be printed by department, with each department starting on a new page. Totals also print when the supervisor changes. No final totals will print.

Use the SUM statement to specify which fields you want totaled for control breaks. By default, EZT+ totals all quantitative fields included in the report, but you can override this with SUM.

Syntax: SUM field-name-1 field-name-2 ...

Example: SUM SALARY BONUS NEW-SAL

Use the TITLE statement to define one or more titles for a report, with up to 99 allowed.

Syntax: TITLE <nn> <+n³-n³COL nn> field-name³'literal' ...

nn is the number of the title line. After 1, which is the default, number in ascending order with no duplicates.

Page 39: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section B3

DPEC, Inc. 37

+n and -n modify the normal spacing between literals or fields on the title line by adding to or subtracting from the SPACE parameter. Unless modified on the REPORT statement, the SPACE value is 3.

COL nn indicates the column number where the next literal or field-name should begin. You must also specify NOADJUST on the REPORT statement.

field-name can be any field from any input file, any W working storage field or a system-defined field. Use only in control reports because EZT+ determines its value based on the current control group.

literal is a character string that you want as part of the title.

The report title area below is the result of the following statements:

CONTROL DEPT TITLE 'NEW SALARY AND BONUS FIGURES' TITLE 3 'FOR THE' -2 DEPT 'DEPARTMENT'

4/12/99 New Salary and Bonus Figures PAGE 1

For the Finance Department

Coding the title number on the first TITLE line is optional. Since no title was coded for TITLE 2, the line is blank.

You must code at least one field-name or literal on each TITLE statement. By default, EASYTRIEVE prints the data and page number on title line 1. If no titles are coded, however, no date or page number display.

Use the HEADING statement to define alternate column headings for any fields in the report. These definitions override any you specified in the Library section.

Syntax: HEADING field-name 'literal'

Example: HEADING DEPT 'DEPARTMENT'

Page 40: Easy Tri Eve

B3 BUILDING A SIMPLE PROGRAM--Coding a REPORT Section

38 DPEC, Inc.

Use one HEADING statement for each field. If you want to stack words in the heading to save space, group them within parentheses, as you learned earlier.

Example: HEADING INCREASE ('PROPOSED' 'SALARY' 'HIKE')

Use the LINE statement to define the detail lines of a report. Fields listed on LINE 1 determine the column headings: either the field-name itself or an alternate name specified by the HEADING parameter or HEADING statement.

You can optionally use other LINE statements to position a record's data on multiple report lines.

Syntax: LINE <nn> <+n³-n³COL nn³POS nn> field-name³'literal' ...

nn is the position of the line within the line group. Specify in ascending order with no duplicates. The default is 1.

+n and -n modify spacing between items on the line as they did in the title line.

COL nn works the same here as it did for title lines.

POS nn specifies which LINE 1 column heading position to align this field with.

literal is a static alphanumeric value, that is, it is the same for every record. It never has a heading.

field-name can be any field from any input file or any working storage field.

Example: LINE SSNUM F-NAME L-NAME DEPT SALARY

Example: LINE DEPT L-NAME LINE 2 POS 2 WORK-PHONE LINE 3 POS 2 MAIL-STOP

Note: Any fields already specified on the SUM statement DO NOT have to be specified on the LINE statement.

All the reports you've seen so far in this course have been regular reports with just one LINE statement. The example below shows the program and output for a multiple line report.

Page 41: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section B3

DPEC, Inc. 39

FILE EMPFILER º 6/4/99 EMPLOYEE LOCATION/PHONE L-NAME 18 10 A º DEPT 28 5 A º DEPT L-NAME WORK-PHONE 74 4 N º MAIL-STOP 96 4 A º FIN MATHERS JOB INPUT EMPFILER NAME CONTACT º 9654 PRINT CONTACT-RPT º B234 REPORT CONTACT-RPT NOPAGE º SEQUENCE DEPT º FIN SNYDER TITLE 'EMPLOYEE LOCATION/PHONE' º 4532 LINE DEPT L-NAME º B236 LINE 2 POS 2 WORK-PHONE º ... LINE 3 POS 2 MAIL-STOP º º

When you use the CONTROL statement to create control reports, you can use a system-defined field called TALLY.

EASYTRIEVE accumulates in TALLY the number of detail records within each control break. Its value appears on total lines.

List TALLY on the LINE statement just like any other field. Use a HEADING statement to give the value a more descriptive name.

Below is an example of a control report with a TALLY field.

Page 42: Easy Tri Eve

B3 BUILDING A SIMPLE PROGRAM--Coding a REPORT Section

40 DPEC, Inc.

REPORT ROSTER º9/26/98 EMPLOYEES BY DEPARTMENT PAGE 1 SEQUENCE DEPT L-NAME º CONTROL DEPT º DEPARTMENT TITLE 'EMPLOYEES BY DEPT' º DEPT F-NAME L-NAME TOTAL HEADING TALLY ('DEPARTMENT' 'TOTAL')º LINE DEPT F-NAME L-NAME TALLY º FIN Sherrie Mathers º FIN Mary Snyder º FIN 2 º HRES Letitia Washington º HRES Yuichiro Yashiki º HRES 2 º MNT Tom Wilson º MNT 1 º SALES Jerry Freeman º SALES Emily Vincent º SALES 2 º SYS Jeff Johnson º SYS Linda Jones º SYS Carmen Saez º SYS 3 º º 10 º º

Now it's time to complete our course example program by entering the code for the REPORT section.

FILE EMPFILER... field definition statements ... JOB INPUT EMPFILER NAME COURSE-EXAMPLE IF PAY-GRADE > 3 NEW-VAC = TOTAL-VAC + 2 ELSE NEW-VAC = TOTAL-VAC + 1 END-IF VAC-REMAIN = NEW-VAC - USED-VAC PRINT REPT1

We need to define REPT1 to produce a report that displays total, used and remaining vacation.

Page 43: Easy Tri Eve

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section B3

DPEC, Inc. 41

FILE EMPFILER... field definition statements ... JOB INPUT EMPFILER NAME COURSE-EXAMPLE logic statements PRINT REPT1 REPORT REPT1 SEQUENCE DEPT L-NAME CONTROL DEPT TITLE 'NEW VACATION TOTALS AFTER BONUS DAYS AWARDED' DEPT F-NAME L-NAME NEW-VAC USED-VAC VAC-REMAIN LINE DEPT F-NAME L-NAME NEW-VAC USED-VAC VAC-REMAIN

The REPORT statement begins the report activity.

The SEQUENCE statement orders the data by last name (L-NAME) within each department (DEPT), with both fields in ascending order.

The CONTROL statement totals the quantitative fields for each department.

The TITLE statement adds a title to the report.

The LINE statement specifies the fields to appear in the report.

Here's our complete course example program.

FILE EMPFILER F-NAME 10 8 A HEADING 'FIRST NAME' L-NAME 18 10 A HEADING 'LAST NAME' DEPT 28 5 A HEADING 'DEPARTMENT' PAY-GRADE 44 2 N TOTAL-VAC 71 2 N 0 USED-VAC 73 2 N 0 HEADING ('VACATION' 'USED') NEW-VAC W 2 N 0 HEADING ('NEW' 'TOTAL' 'VACATION') VAC-REMAIN W 2 N 0 HEADING ('VACATION' 'REMAINING') JOB INPUT EMPFILER NAME COURSE-EXAMPLE IF PAY-GRADE > 3 NEW-VAC = TOTAL-VAC + 2 ELSE NEW-VAC = TOTAL-VAC + 1 END-IF VAC-REMAIN = NEW-VAC - USED-VAC PRINT REPT1 REPORT REPT1 SEQUENCE DEPT L-NAME CONTROL DEPT TITLE 'NEW VACATION TOTALS AFTER BONUS DAYS AWARDED' LINE DEPT F-NAME L-NAME NEW-VAC USED-VAC VAC-REMAIN

Page 44: Easy Tri Eve

B3 BUILDING A SIMPLE PROGRAM--Coding a REPORT Section

42 DPEC, Inc.

The report displays below.

7/15/99 NEW VACATION TOTALS AFTER BONUS DAYS AWARDED PAGE 1

NEW TOTAL VACATION VACATION DEPARTMENT FIRST NAME LAST NAME VACATION USED REMAINING

FIN Sherrie Mathers 16 6 10 Mary Snyder 16 6 10 FIN 32 12 20

HRES Letitia Washington 16 4 12 Yuichiro Yashiki 16 2 14 HRES 32 6 26

...

SYS Jeff Johnson 16 3 13 Linda Jones 21 5 16 Carmen Saez 12 4 8 SYS 49 12 37 151 42 109

Page 45: Easy Tri Eve

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters C1

DPEC, Inc. 43

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

1. DTLCTL determines how control field values print on detail lines. Its subparameters are

FIRST -- prints the value of all control fields on the first detail line on a page and after a control break (Default)

EVERY -- prints the value of all control fields on every detail line

NONE -- prints no control field values on detail lines

2. SUMCTL determines how control field values print on total lines. Its subparameters are

HIAR -- prints all control field values in hierarchical order (Default)

TAG -- prints the control field name and the word TOTAL on the left side of each total line

DTLCOPY -- prints values from detail lines onto total lines

NONE -- prints no control field values on total lines

3. Some other REPORT statement parameters that determine formatting are

SUMMARY -- prints a summary report containing only total lines

SUMSPACE -- increases the print size of total line fields in case the length of the total is greater than the defined field size

TALLYSIZE -- sets the print size of the TALLY field

Page 46: Easy Tri Eve

C1 CUSTOMIZING THE REPORT--Using REPORT Statement Parameters

44 DPEC, Inc.

∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points (cont.) ∞∞∞∞∞∞∞∞∞∞∞∞∞

4. The SUMFILE parameter produces a summary file containing values for all control and summed fields at every minor control break.

Syntax: REPORT report-name SUMFILE file-name

5. The LABELS parameter creates a report you can use for mailing labels and for printing on forms. Use the following subparameters with LABELS:

ACROSS -- number of labels printed across. The default is 4. DOWN -- number of lines in a label. The default is 6. SIZE -- length of the label in print positions. The default is 30.

6. Use the PRINTER parameter to identify an alternate printer.

Syntax: REPORT report-name PRINTER file-name

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

Page 47: Easy Tri Eve

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters C1

DPEC, Inc. 45

In the last unit you learned how to code Library, JOB and REPORT sections to generate a fairly basic EASYTRIEVE report.

This unit explains some additional ways to customize your reports using other REPORT statement parameters and report PROCs.

Earlier you learned about some spacing control and testing aid parameters that you can add to the REPORT statement.

This objective covers other parameters that determine which data is included and how it prints on a control report.

The first group of parameters specifies how control field values print, either on detail or summary lines.

DTLCTL determines how control field values print on detail lines. Its subparameters are

FIRST -- by default, prints the value of all control fields on the first detail line on a page and on the first detail line after a control break

EVERY -- prints the value of all control fields on every detail line

NONE -- prints no control field values on detail lines

Example: REPORT REPT-B DTLCTL NONE

SUMCTL determines how control field values print on total lines. Its subparameters are

HIAR -- by default, prints all control field values for the level of the current group and higher in hierarchical order

TAG -- prints the control field name and the word TOTAL on the left side of each total line

DTLCOPY -- prints values from detail lines onto total lines

NONE -- prints no control field values on total lines

Page 48: Easy Tri Eve

C1 CUSTOMIZING THE REPORT--Using REPORT Statement Parameters

46 DPEC, Inc.

We use the default values for DTLCTL and SUMCTL in our example program. Look again at that output.

7/15/99 NEW VACATION TOTALS AFTER BONUS DAYS AWARDED PAGE 1

NEW TOTAL VACATION VACATION DEPARTMENT FIRST NAME LAST NAME VACATION USED REMAINING

FIN Sherrie Mathers 16 6 10 Mary Snyder 16 6 10 FIN 32 12 20 ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ HRES Letitia Washington³ The value of the control field ³ Yuichiro Yashiki ³ DEPT is printed only on the ³ HRES ³ first line of a control group ³ ³ and on the total line. ³ ... ³ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ SYS Jeff Johnson 16 3 13 Linda Jones 21 5 16 Carmen Saez 12 4 8 SYS 49 12 37 151 42 109

Adding SUMCTL TAG to the REPORT statement produces the following output, with the words DEPT TOTAL appearing on each total line.

Page 49: Easy Tri Eve

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters C1

DPEC, Inc. 47

7/15/99 NEW VACATION TOTALS AFTER BONUS DAYS AWARDED PAGE 1

NEW TOTAL VACATION VACATION DEPARTMENT FIRST NAME LAST NAME VACATION USED REMAINING

FIN Sherrie Mathers 16 6 10 Mary Snyder 16 6 10 DEPT TOTAL 32 12 20

HRES Letitia Washington 16 4 12 Yuichiro Yashiki 16 2 14 DEPT TOTAL 32 6 26

...

SYS Jeff Johnson 16 3 13 Linda Jones 21 5 16 Carmen Saez 12 4 8 DEPT TOTAL 49 12 37 FINAL TOTAL 151 42 109

Some other REPORT statement parameters that determine formatting are

SUMMARY -- prints a summary report containing only total lines.

SUMSPACE -- increases the print size of total line fields in case the length of the total is greater than the defined field size. By default, a value of 3 is added to the length of the field.

TALLYSIZE -- sets the print size of the TALLY field. The default value is 2. When a TALLY value appear on a total line, its size is a total of SUMSPACE and TALLYSIZE.

The SUMFILE parameter lets you separate the totals from the rest of the report so you can use them in other JOB activities. It produces a summary file containing values for all control and summed fields at every minor control break.

Page 50: Easy Tri Eve

C1 CUSTOMIZING THE REPORT--Using REPORT Statement Parameters

48 DPEC, Inc.

This file consists of the following parts:

control fields -- the fields appearing on the CONTROL statement. Define them with the same attributes as the input file.

TALLY -- defined as 10 P 0.

summed fields -- fields that are totaled. Define them as 10 P.

You first define the file in the Library section and then create it with the REPORT section.

Syntax: REPORT report-name SUMFILE file-name

Example: REPORT REPT-2 SUMFILE OUTFILE

The final format determination parameter to look at is a departure from the standard report format.

LABELS creates a report you can use for mailing labels and for printing on forms. This type of report differs from a standard report in the following ways:

• no titles or headings • can print multiple labels side-by-side • allows for control breaks but doesn't automatically total quantitative fields

Use the following subparameters with LABELS:

ACROSS -- number of labels printed across. The default is 4.

DOWN -- number of lines in a label. The default is 6.

SIZE -- length of the label in print positions. The default is 30.

This program illustrates the coding for a LABELS report.

Page 51: Easy Tri Eve

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters C1

DPEC, Inc. 49

FILE EMPFILER F-NAME 10 8 A L-NAME 18 10 A DEPT 28 5 A WORK-PHONE 74 4 N MAIL-STOP 96 4 A JOB INPUT EMPFILER NAME CONTACT PRINT CONTACT-LABELS REPORT CONTACT-LABELS LABELS (ACROSS 2 DOWN 4 SIZE 35) SPACE 1 SEQUENCE DEPT L-NAME LINE 1 COL 5 F-NAME L-NAME LINE 2 COL 5 WORK-PHONE LINE 3 COL 5 MAIL-STOP

Note that you can sequence the output of this type of report just as you can a standard report.

Talking about LABEL reports leads us to a discussion of a parameter that lets you direct the report's printed output to a different printer file.

It's possible that the printer that prints to forms or labels using a LABEL format could be different from the default printer (SYSPRINT) that most of your EASYTRIEVE jobs go to.

In that case, use the PRINTER parameter to identify the alternate printer.

Syntax: REPORT report-name PRINTER file-name Example: REPORT REPT-2 PRINTER PRFORM

You must also define the printer file in the library section with a FILE statement: FILE PRFORM PRINTER

The following code produces a summary report that displays only those fields which have values on total lines: control fields and quantitative fields.

REPORT REPT1 SUMMARY SEQUENCE DEPT SUPERVISOR CONTROL DEPT SUPERVISOR TITLE 01 'NEW VACATION TOTALS AFTER BONUS DAYS AWARDED' LINE 01 DEPT SUPERVISOR F-NAME L-NAME NEW-VAC USED-VAC VAC-REMAIN

The report displays below.

Page 52: Easy Tri Eve

C1 CUSTOMIZING THE REPORT--Using REPORT Statement Parameters

50 DPEC, Inc.

6/14/99 NEW VACATION TOTALS AFTER BONUS DAYS AWARDED PAGE 1

NEW TOTAL VACATION VACATION DEPARTMENT SUPERVISOR VACATION USED REMAINING

FIN Anderson 16 6 10 FIN Mathers 16 6 10 FIN 32 12 20

HRES Liam 32 6 26 HRES 32 6 26

MNT Holmes 11 4 7 MNT 11 4 7

SALES Zetsky 27 8 19 SALES 27 8 19

SYS Matsko 49 12 37 SYS 49 12 39

151 42 109

Page 53: Easy Tri Eve

CUSTOMIZING THE REPORT--Using REPORT PROCs C2

DPEC, Inc. 51

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

1. EASYTRIEVE provides seven procedures (PROCs) which perform special data manipulation tasks for a report:

• REPORT-INPUT -- selects and modifies data prior to report processing

• BEFORE-BREAK -- modifies totals and adds notes before control break total lines print

• AFTER-BREAK -- adds a note after a total line prints

• BEFORE-LINE -- adds a note before a detail line prints

• AFTER-LINE -- adds a note after a detail line prints

• ENDPAGE -- produces page footer information

• TERMINATION -- produces end of report information

2. The syntax for PROCs is

proc-name. PROC proc-name logic statements (OR) PROC END-PROC logic statements END-PROC

3. When it's important to know the control break level, you can code testing logic using LEVEL, a system-defined field which holds the value of the current control break.

Start with Level = 1 for the lowest level (most minor) break and go up to the number of CONTROL fields (N). Final totals have a value of N + 1.

4. To print special annotation to a report, use the DISPLAY statement. The syntax is

DISPLAY 'literal'³field-name

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

Page 54: Easy Tri Eve

C2 CUSTOMIZING THE REPORT--Using REPORT PROCs

52 DPEC, Inc.

For most of your reports, the combination of EASYTRIEVE's automatic reporting features and the REPORT statement parameters you just learned will meet your reporting needs.

However, some reports may benefit from the special logic provided by EASYTRIEVE's report procedures.

This objective describes these procedures and provides some examples of their use.

EASYTRIEVE provides seven procedures (PROCs) which perform special data manipulation tasks for a report:

• REPORT-INPUT • BEFORE-BREAK • AFTER-BREAK • BEFORE-LINE • AFTER-LINE • ENDPAGE • TERMINATION

Code one or more PROCs right after a REPORT section LINE statement. Each of these PROCs can be used only once in a given report.

Syntax: proc-name. PROC proc-name logic statements (OR) PROC END-PROC logic statements END-PROC

There are two ways to start a PROC. Either code the keyword PROC on the same line with the proc-name, or put the keyword on the next line. Note that in the first method, a period and a space follow the proc-name before the keyword is coded. This course uses the first method.

Code logic statements the same way you do in a JOB activity, except that no input/output is allowed. Complete the PROC by coding an END-PROC.

We'll look at each report PROC in turn.

The REPORT-INPUT procedure provides a way to screen and/or modify the data sent to the report.

When you code this PROC, EZT+ executes it on each record sent to the report by the PRINT statement, prior to report processing. In order for data to continue to the report, you must code a SELECT statement in the PROC.

Page 55: Easy Tri Eve

CUSTOMIZING THE REPORT--Using REPORT PROCs C2

DPEC, Inc. 53

Let's look at an example program to see how you might use this PROC.

FILE EMPFILER L-NAME 18 10 A HEADING 'LAST NAME' DEPT 28 5 A ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ SALARY 62 5 N 0 ³ The logic in the JOB section ³ INCREASE W 3 N 2 ³ calculates a new salary for ³ NEW-SAL W 6 N 0 HEAD³ each employee and stores the ³ TOTAL-SAL S 7 N 0 ³ total salary amount in an S ³ PCT-SAL-TO-TOT W 4 N 2 HEAD³ working storage field. ³ JOB INPUT EMPFILER NAME NEW-SALARY ³ ³ INCREASE = 1.03 ³ In the REPORT section we want ³ NEW-SAL = SALARY * INCREASE ³ to show the new salary for ³ TOT-SAL = TOT-SAL + NEW-SAL ³ each employee and also what ³ PRINT RPT-SAL ³ percent that salary is of the ³ REPORT RPT-SAL ³ total company salary amount. ³ SEQUENCE DEPT SALARY ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ CONTROL DEPT TITLE 'NEW SALARIES AFTER INCREASE' LINE DEPT L-NAME NEW-SAL PCT-SAL-TO-TOT

Here's the assignment statement needed to calculate the percentage:

PCT-SAL-TO-TOT ROUNDED = NEW-SAL / TOT-SAL * 100

At the time of this calculation, EZT+ must have a total salary amount.

Page 56: Easy Tri Eve

C2 CUSTOMIZING THE REPORT--Using REPORT PROCs

54 DPEC, Inc.

FILE EMPFILER L-NAME 18 10 A HEADING 'LAST NAME' DEPT 28 5 A ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ SALARY 62 5 N 0 ³ The REPORT-INPUT procedure ³ INCREASE W 3 N 2 ³ performs the calculation for ³ NEW-SAL W 6 N 0 HEAD³ each record input to the ³ TOTAL-SAL S 7 N 0 ³ report. ³ PCT-SAL-TO-TOT W 4 N 2 HEAD³ ³ JOB INPUT EMPFILER NAME NEW-SALARY ³ At the time the PROC executes, ³ INCREASE = 1.03 ³ the TOT-SAL field contains the ³ NEW-SAL = SALARY * INCREASE ³ total of all new salaries. ³ TOT-SAL = TOT-SAL + NEW-SAL ³ ³ PRINT RPT-SAL ³ Note the use of the SELECT ³ REPORT RPT-SAL ³ statement to pass the record ³ SEQUENCE DEPT SALARY ³ on to the report. ³ CONTROL DEPT ³ ³ TITLE 'NEW SALARIES AFTER INCREAS³ ³ LINE DEPT L-NAME NEW-SAL PCT-SALÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ REPORT-INPUT. PROC PCT-SAL-TO-TOT ROUNDED = NEW-SAL / TOT-SAL * 100 SELECT END-PROC

Here's the output using REPORT-INPUT.

NEW SALARIES AFTER INCREASE

% OF TOTAL DEPT LAST NAME NEW SALARY SALARY FIN Snyder 29,252 7.58 Mathers 40,067 10.38 FIN 69,319 17.96 HRES Yashiki 33,475 8.67 Washington 46,659 12.09 HRES 80,134 20.76 MNT Wilson 26,574 6.88 MNT 26,574 6.88 SALES Freeman 41,200 10.68 Vincent 41,200 10.68 SALES 82,400 21.36 SYS Jones 31,930 8.27 Johnson 42,539 11.02 Saez 52,839 13.69 SYS 127,308 32.98 385,735 99.94

Look now at another example.

Page 57: Easy Tri Eve

CUSTOMIZING THE REPORT--Using REPORT PROCs C2

DPEC, Inc. 55

This example will show why at times you may need to modify totals that appear on total lines produced by the CONTROL statement. Examine the program below and then take a look at the output that follows.

FILE EMPFILER ... PCT-OF-SALARY W 4 N 2 BONUS-AMT W 4 N 0 JOB INPUT EMPFILER NAME PROJECTION BONUS-AMT = 2000 PCT-OF-SALARY ROUNDED = (BONUS-AMT / SALARY) * 100 PRINT RPT1 REPORT RPT1 SEQUENCE DEPT L-NAME CONTROL DEPT TITLE 'IMPACT OF PROJECTED $2000 BONUS' LINE DEPT F-NAME L-NAME SALARY BONUS-AMT PCT-OF-SALARY

Take a good look at the last column of data, particularly on the total lines. PCT-OF-SALARY is calculated in the program using a fixed amount of 2000 for BONUS-AMT.

IMPACT OF PROJECTED $2000 BONUS

DEPT F-NAME L-NAME SALARY BONUS-AMT PCT-OF-SALARY FIN Sherrie Mathers 38,900 2,000 5.14 Mary Snyder 28,400 2,000 7.04 FIN 67,300 4,000 2.97 ... SALES Jerry Freeman 40,000 2,000 5.00 Emily Vincent 40,000 2,000 5.00 SALES 80,000 4,000 2.50 SYS Jeff Johnson 41,300 2,000 4.84 Linda Jones 31,000 2,000 6.45 Carmen Saez 51,300 2,000 3.89 SYS 123,600 6,000 1.61 374,500 20,000 .53

When a total line for DEPT prints, it continues to use 2000 for BONUS-AMT instead of the total DEPT bonus amount. And this isn't what we want, is it?

The BEFORE-BREAK procedure lets you modify totals and add special annotation before the total lines print. By coding the assignment statement in this report PROC, the PCT-OF-SALARY totals are based on total amounts.

Page 58: Easy Tri Eve

C2 CUSTOMIZING THE REPORT--Using REPORT PROCs

56 DPEC, Inc.

FILE EMPFILER ... PCT-OF-SALARY W 4 N 2 BONUS-AMT W 4 N 0 JOB INPUT EMPFILER NAME PROJECTION BONUS-AMT = 2000 PCT-OF-SALARY ROUNDED = (BONUS-AMT / SALARY) * 100 PRINT RPT1 REPORT RPT1 SEQUENCE DEPT L-NAME CONTROL DEPT TITLE 'IMPACT OF PROJECTED $2000 BONUS' LINE DEPT F-NAME L-NAME SALARY BONUS-AMT PCT-OF-SALARY BEFORE-BREAK. PROC PCT-OF-SALARY ROUNDED = (BONUS-AMT / SALARY) * 100 END-PROC

This output looks a bit more realistic, doesn't it?

IMPACT OF PROJECTED $2000 BONUS

DEPT F-NAME L-NAME SALARY BONUS-AMT PCT-OF-SALARY FIN Sherrie Mathers 38,900 2,000 5.14 Mary Snyder 28,400 2,000 7.04 FIN 67,300 4,000 5.94 HRES Letitia Washington 45,300 2,000 4.41 Yuichiro Yashiki 32,500 2,000 6.15 HRES 77,800 4,000 5.14 MNT Tom Wilson 25,800 2,000 7.75 MNT 25,800 2,000 7.75 SALES Jerry Freeman 40,000 2,000 5.00 Emily Vincent 40,000 2,000 5.00 SALES 80,000 4,000 5.00 SYS Jeff Johnson 41,300 2,000 4.84 Linda Jones 31,000 2,000 6.45 Carmen Saez 51,300 2,000 3.89 SYS 123,600 6,000 4.85 374,500 20,000 5.34

The example below had control breaks on only one field (DEPT) and at the end (FINAL). One way to describe this is to say that there are two levels of breaks.

Page 59: Easy Tri Eve

CUSTOMIZING THE REPORT--Using REPORT PROCs C2

DPEC, Inc. 57

FILE EMPFILER F-NAME 10 8 A ... PCT-OF-SALARY W 4 N 2 BONUS-AMT W 4 N 0 JOB INPUT EMPFILER NAME PROJECTION BONUS-AMT = 2000 PCT-OF-SALARY ROUNDED = (BONUS-AMT / SALARY) * 100 PRINT RPT1 REPORT RPT1 SEQUENCE DEPT L-NAME CONTROL DEPT TITLE 'IMPACT OF PROJECTED $2000 BONUS' LINE DEPT F-NAME L-NAME SALARY BONUS-AMT PCT-OF-SALARY BEFORE-BREAK. PROC PCT-OF-SALARY ROUNDED = (BONUS-AMT / SALARY) * 100 END-PROC

Since we wanted to affect the totals on both levels in the same way, there was no need to know which break was which. But, say we wanted to add some special wording which applies to the DEPT level but not the FINAL level?

FILE EMPFILER F-NAME 10 8 A ... PCT-OF-SALARY W 4 N 2 BONUS-AMT W 4 N 0 JOB INPUT EMPFILER NAME PROJECTION BONUS-AMT = 2000 PCT-OF-SALARY ROUNDED = (BONUS-AMT / SALARY) * 100 PRINT RPT1 REPORT RPT1 SEQUENCE DEPT L-NAME CONTROL DEPT TITLE 'IMPACT OF PROJECTED $2000 BONUS' LINE DEPT F-NAME L-NAME SALARY BONUS-AMT PCT-OF-SALARY BEFORE-BREAK. PROC PCT-OF-SALARY ROUNDED = (BONUS-AMT / SALARY) * 100 END-PROC

When it's important to know the control break level, you can code testing logic using LEVEL, a system-defined field which holds the value of the current control break.

Start with Level = 1 for the lowest level (most minor) break and go up to the number of CONTROL fields (N). Final totals have a value of N + 1.

Page 60: Easy Tri Eve

C2 CUSTOMIZING THE REPORT--Using REPORT PROCs

58 DPEC, Inc.

In the following example, the DEPT level has a value of '1' and the FINAL level, '2'. If we wanted to do something different at the DEPT level, we could add the coding shown.

... REPORT RPT1 SEQUENCE DEPT L-NAME CONTROL DEPT TITLE 'IMPACT OF PROJECTED $2000 BONUS' LINE DEPT F-NAME L-NAME SALARY BONUS-AMT PCT-OF-SALARY BEFORE-BREAK. PROC PCT-OF-SALARY ROUNDED = (BONUS-AMT / SALARY) * 100 IF LEVEL = 1 logic statements END-IF END-PROC

Similar to BEFORE-BREAK, the AFTER-BREAK procedure lets you display special annotation after the control break lines print.

To print special annotation to a report, use the DISPLAY statement.

Syntax: DISPLAY 'literal'³field-name

Example: AFTER-BREAK. PROC IF LEVEL = 1 DISPLAY 'TOTAL EMPLOYEES IN ' DEPT + 'DEPARTMENT: ' TALLY END-IF END-PROC

The BEFORE-LINE and AFTER-LINE procedures let you specify special annotation before or after each detail line prints.

Although you cannot modify the contents of the line, you can code logic to determine its contents and select an appropriate message to print.

Example: AFTER-LINE. PROC IF VAC-REMAIN > 10 DISPLAY 'NOTE TOTAL -- ONLY 5 DAYS CAN BE + CARRIED OVER TO NEXT YEAR!!' END-PROC

Page 61: Easy Tri Eve

CUSTOMIZING THE REPORT--Using REPORT PROCs C2

DPEC, Inc. 59

The ENDPAGE and TERMINATION procedures are used to add footing-type information at the end of a page or report.

Typical uses include such things as totals, banners and routing lists.

Let's now add two report PROCs to our example program.

The AFTER-LINE procedure lets you add a special note after a detail line when the IF condition is true.

The TERMINATION procedure puts a message at the end of the report.

Here's the report.

7/15/99 NEW VACATION TOTALS AFTER BONUS DAYS AWARDED PAGE 1

NEW TOTAL VACATION VACATION DEPARTMENT LAST NAME FIRST NAME VACATION USED REMAINING FIN Sherrie Mathers 16 06 10 Mary Snyder 16 06 10 FIN 32 12 20

HRES Letitia Washington 16 04 12 NOTE TOTAL -- ONLY 5 DAYS CAN BE CARRIED OVER TO NEXT YEAR!! Yuichiro Yashiki 16 02 14 NOTE TOTAL -- ONLY 5 DAYS CAN BE CARRIED OVER TO NEXT YEAR!! HRES 32 06 26 ... SYS Jeff Johnson 16 03 13 NOTE TOTAL -- ONLY 5 DAYS CAN BE CARRIED OVER TO NEXT YEAR!! Linda Jones 21 05 16 NOTE TOTAL -- ONLY 5 DAYS CAN BE CARRIED OVER TO NEXT YEAR!! Carmen Saez 12 04 08 SYS 49 12 37 151 42 109

ROUTE TO PERSONNEL AND EACH SUPERVISOR TO SHARE WITH ALL EMPLOYEES

Page 62: Easy Tri Eve

D1 ENHANCING THE PROGRAM--Statements and Macros

60 DPEC, Inc.

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

1. Virtual File Manager (VFM) dynamically allocates space in memory for program work files.

FILE file-name F(lrecl) VIRTUAL <RETAIN>

2. Use the COPY statement to copy field definitions from one file to another.

COPY file-name

3. Use the CALL statement to invoke an external subprogram.

CALL program-name <USING (field-name³'literal' ...)>

4. Use MOVE to transfer data from one place to another.

MOVE sending data TO receiving data <FILL>

A related statement, MOVE LIKE moves the contents of identically-named fields from one file to another.

MOVE LIKE file-name-1 TO file-name-2

5. You can write your own procedures to accomplish specific objectives. The syntax for user procedures is

proc-name. PROC proc-name logic statements (OR) PROC END-PROC logic statements END-PROC

You can use the PERFORM statement or the START and FINISH parameters of the JOB statement to invoke a user procedure.

PERFORM proc-name

JOB INPUT file-name <NAME job-name> + <START proc-name> <FINISH proc-name>

Page 63: Easy Tri Eve

ENHANCING THE PROGRAM--Statements and Macros D1

DPEC, Inc. 61

∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points (cont.) ∞∞∞∞∞∞∞∞∞∞∞∞∞

6. A SORT activity creates a sequenced file containing all or some of the records from another file. Begin the activity with the SORT statement:

SORT file-name-1 TO file-name-2 + USING (field-name-1 <D> ...) <NAME sort-name>+ <BEFORE proc-name>

To select only certain records for a sort or even modify the contents of the records before a sort, use a SORT procedure.

Code the procedure the same way you do any other user procedure, but be sure to execute a SELECT statement for records you want to go to the output file.

7. Use the GOTO statement to modify this usual top-down logic flow of an EZT+ program.

GOTO label³JOB

8. Another way to modify program flow is to set up a controlled loop for repetitive logic. Use the DO WHILE, DO UNTIL and END-DO statements to delimit the logic statements.

DO WHILE³UNTIL conditional expression logic statements END-DO

Page 64: Easy Tri Eve

D1 ENHANCING THE PROGRAM--Statements and Macros

62 DPEC, Inc.

∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points (cont.) ∞∞∞∞∞∞∞∞∞∞∞∞∞

9. To invoke a macro, use a macro invocation statement anywhere in an EASYTRIEVE program.

%macro-name <macro-parameters>

The syntax for coding a prototype statement is

MACRO <n> <positional-parameters> <keyword-parameters>

10. Code parameters to allow for substitution values:

You can combine keyword and positional parameters. Code all positional parameters before any keyword parameters.

MACRO n pos1 pos2 ... key1 value1 key2 value2 ...

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

Page 65: Easy Tri Eve

ENHANCING THE PROGRAM--Statements and Macros D1

DPEC, Inc. 63

This unit covers a variety of programming methods that let you go beyond the basic examples presented thus far.

This objective looks at additional statements and parameters, user procedures and macros that can enhance your programs.

The next objective describes the different types of file processing you can do.

In this objective, you'll see information on the following:

• virtual files • COPY statement • CALL statement • MOVE and MOVE LIKE statements • user procedures • SORT activity • GOTO, DO WHILE and DO UNTIL statements • macros

Let's start with some additions to the Library section.

It's very typical for programs of any complexity to need temporary work files for such uses as sequencing data or producing multiple reports.

One method for handling this is to use JCL statements to define temporary files and reserve disk space for them.

EASYTRIEVE provides an easier method as a standard feature. Virtual File Manager (VFM) dynamically allocates space in memory for program work files.

Use the FILE statement to set up the virtual file. ...

You've already seen examples using the FILE statement to describe standard input and output files. By coding different parameters, you can set up a temporary work file to which your program has sequential access.

Syntax: FILE file-name F(lrecl) VIRTUAL <RETAIN> Example: FILE SALSORT F(80) VIRTUAL

F(lrecl) specifies the record length.

VIRTUAL causes VFM to create and maintain the file.

Page 66: Easy Tri Eve

D1 ENHANCING THE PROGRAM--Statements and Macros

64 DPEC, Inc.

RETAIN causes VFM to retain the file for the duration of EZT+ program execution. By default, the file is deleted once it is processed as an input file, so the space can be reused. If you plan to use the file for more than one activity in your program, code RETAIN.

The program first sorts EMPFILER and puts the output of the sort into SALSORT. Then SALSORT becomes the input file in the JOB activity.

FILE EMPFILER SSNUM 1 9 N F-NAME 10 8 A L-NAME 18 10 A DEPT 28 5 A SALARY 62 5 N 0 FILE SALSORT F(80) VIRTUAL COPY EMPFILER SORT EMPFILER SALSORT + USING (DEPT SALARY D) JOB INPUT SALSORT NAME SALARY PRINT RPT1-SALARY PRINT RPT2-SALARY ...

The program above also shows the use of another statement you can use in the Library section -- COPY.

Use the COPY statement to copy field definitions from one file to another.

Syntax: COPY file-name

Example: FILE SORTFILE COPY EMPFILER

If your program uses the same field names in two files in the same activity, you must qualify the field names by adding the filename as a prefix. Use a colon (:) as the delimiter.

In the program below, we qualify the field name DEPT because both EMPFILER and TRANS will be used in the JOB activity.

Page 67: Easy Tri Eve

ENHANCING THE PROGRAM--Statements and Macros D1

DPEC, Inc. 65

FILE EMPFILER SSNUM 1 9 N F-NAME 10 8 A L-NAME 18 10 A DEPT 28 5 A SALARY 62 5 N 0 FILE TRANS COPY EMPFILER JOB INPUT TRANS NAME SALARY IF TRANS:DEPT = 'SYS' ... logic statements ... END-IF ...

Use the CALL statement to invoke an external subprogram.

Your company probably has existing programs in other languages (such as COBOL) that perform functions unavailable in EASYTRIEVE.

Syntax: CALL program-name <USING (field-name³'literal' ...)> Example: CALL DUMP USING ABEND-CODE

Code USING to specify parameters to pass to the subprogram.

Use MOVE to transfer data from one place to another.

You can move the contents of a file to another file or the contents of a field or a literal to a field. You can also move spaces or zeros to a field to initialize it.

Syntax: MOVE sending data TO receiving data <FILL 'literal'>

Example: MOVE SALARY TO OUT-SALARY Example: MOVE 'NO DATA' TO COMMENTS FILL '*' Example: MOVE ZERO TO TOTAL

Values for sending data include file-name, field-name, 'literal', SPACE or ZERO.

Values for receiving data include file-name or field-name.

You can move spaces or zeros to multiple files at once.

If a sending field is longer than a receiving field, the data is truncated on the right. If a receiving field is longer, it is padded on the right with spaces. Alternately, you can use the FILL parameter to place characters in those unused spaces.

Page 68: Easy Tri Eve

D1 ENHANCING THE PROGRAM--Statements and Macros

66 DPEC, Inc.

A related statement, MOVE LIKE moves the contents of identically-named fields from one file to another.

Syntax: MOVE LIKE file-name-1 TO file-name-2 Example: MOVE LIKE MASTER TO NEWFILE

Let's look at an example of this.

MOVE LIKE generates assignment statements to assign values to identical fields.

FILE EMPFILER F-NAME 10 8 A L-NAME 18 10 A DEPT 28 5 A FILE DEPTLST COPY EMPFILER JOB INPUT EMPFILER MOVE LIKE EMPFILER TO DEPTLST ...

In this case

DEPTLST:F-NAME = EMPFILER:F-NAME DEPTLST:L-NAME = EMPFILER:L-NAME DEPTLST:DEPT = EMPFILER:DEPT

Next we'll look at user procedures and SORTs.

In the last unit you learned about report PROCs that perform special tasks within a REPORT subactivity.

You can also write your own procedures to accomplish specific objectives. These user PROCs are identified by the following syntax:

proc-name. PROC proc-name logic statements (OR) PROC END-PROC logic statements END-PROC

Code the PROC at the end of the activity where you will invoke it, just as you coded report PROCs at the end of a REPORT activity.

Page 69: Easy Tri Eve

ENHANCING THE PROGRAM--Statements and Macros D1

DPEC, Inc. 67

Use the PERFORM statement to invoke a user procedure. You can code it after the JOB statement or from within another procedure.

Syntax: PERFORM proc-name Example: PERFORM MYPROC

Let's look at a rewrite of our original course example program, using PROCs.

JOB INPUT EMPFILER NAME COURSE-EXAMPLE º JOB INPUT EMPFILER NAME PROC-EXAMPLE IF PAY-GRADE > 3 º IF PAY-GRADE > 3 NEW-VAC = TOTAL-VAC + 2 º PERFORM VAC-A ELSE º ELSE NEW-VAC = TOTAL-VAC + 1 º PERFORM VAC-B END-IF º END-IF <ÄÄÄÄÄÄÄÄÄÄÄ¿ VAC-REMAIN = NEW-VAC - USED-VAC º VAC-REMAIN = NEW-VAC - USED-VAC ³ PRINT REPT1 º PRINT REPT1 ³ º VAC-A. PROC ³ º NEW-VAC = TOTAL-VAC + 2 ³ º END-PROC ³ º VAC-B. PROC ³ º NEW-VAC = TOTAL-VAC + 1 ³ º END-PROC ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ

When EZT+ reaches an END-PROC, it returns to the statement following the PERFORM that invoked the PROC.

In such a simple program, there's no real advantage in using the PROCs; in fact, it's a little more coding.

However, when you have situations where the same statements must be performed multiple times in an activity, using PROCs eliminates repeating code.

In addition to the PERFORM statement, there are other ways to invoke a user PROC.

One way is to use the START and FINISH parameters of the JOB statement.

Syntax: JOB INPUT file-name <NAME job-name> + <START proc-name> <FINISH proc-name> Example: JOB INPUT EMPFILER NAME BONUS START INITIAL

A START procedure executes automatically before reading the first input record. A typical task is to initialize working storage fields.

Page 70: Easy Tri Eve

D1 ENHANCING THE PROGRAM--Statements and Macros

68 DPEC, Inc.

A FINISH procedure executes immediately after the last input record is processed. It is invoked by a STOP, but not by a STOP EXECUTE. A typical task is to display information accumulated during the JOB activity.

You can also invoke a user PROC from a SORT activity.

You've seen some example programs containing SORTs, but we haven't really worked with them yet. Let's do so now.

A SORT activity creates a sequenced file containing all or some of the records from another file.

Your installation's sort program does the actual sort, so you can sort on as many fields as your system allows.

Begin the activity with the SORT statement:

Syntax: SORT file-name-1 TO file-name-2 + USING (field-name-1 <D> ...) <NAME sort-name>

Example: SORT EMPFILER TO SALSORT USING (DEPT SALARY D)

USING identifies fields from file-name-1 to use as sort keys. Use D to sort in descending order.

If you want to select only certain records for a sort or even modify the contents of the records before a sort, use a SORT procedure.

Code the procedure the same way you do any other user procedure, but be sure to execute a SELECT statement for records you want to go to the output file.

SEL-DEPT. PROC IF DEPT = 'SYS' 'FIN' SELECT END-IF END-PROC

You may recall that we coded SELECT when using the REPORT-INPUT procedure, which also screens data prior to input.

Page 71: Easy Tri Eve

ENHANCING THE PROGRAM--Statements and Macros D1

DPEC, Inc. 69

Invoke the PROC by adding the BEFORE parameter to the SORT statement.

Syntax: SORT file-name-1 TO file-name-2 + USING (field-name-1 <D> ...) <NAME sort-name> + BEFORE proc-name

Example: SORT INVENTRY TO SORTFILE USING QUANTITY D + BEFORE PARTS-SELECT

If you don't code BEFORE, all records in file-name-1 are sorted to file-name-2.

We'll finish this list of topics with a look at statements that control program logic flow ...

... and also see how to use macros for greater programming efficiency.

By default, EASYTRIEVE statements execute from the top of a program to the bottom. Use the GOTO statement to modify this usual logic flow.

Syntax: GOTO label³JOB Example: GOTO JOB Example: GOTO MY-ROUTINE

EZT+ accepts GO TO as well as GOTO.

label specifies a statement label, which is a complete EZT+ statement consisting only of a name.

GOTO JOB branches immediately to the top of the current JOB activity. GOTO label transfers control to the first statement after the label statement, which must be in the same activity or procedure. Processing continues from that point in a top-down sequence.

Coding a GOTO statement is similar to coding a PERFORM. The major difference is that after a PERFORM, EASYTRIEVE returns automatically to the natural top-down flow of the program. With GOTO, any returns must be coded as a GOTO to a JOB or label statement.

Another way to modify program flow is to set up a controlled loop for repetitive logic.

Page 72: Easy Tri Eve

D1 ENHANCING THE PROGRAM--Statements and Macros

70 DPEC, Inc.

Use the DO WHILE, DO UNTIL and END-DO statements to delimit the logic statements.

Syntax: DO WHILE³UNTIL conditional expression logic statements END-DO

Example: DO WHILE COUNT < 15 logic statements END-DO

With DO WHILE, the conditional expression is checked first. If it's true, the statements execute and then the program branches back to test the expression again. The program continues to loop until the conditional expression is false.

Example: DO UNTIL COUNT = 15 logic statements END-DO

With DO UNTIL, the statements execute at least once and then the conditional expression is checked. If the expression is false, the statements execute again. Once the condition becomes true, the program leaves the loop.

We'll finish this objective with an introduction to macros.

EASYTRIEVE's macro facility lets you easily duplicate often-used source statements for your programs.

Macros are basically just lines of code that you and other EZT+ programmers are likely to use again and again in your programs. These macros are stored in a library defined to EASYTRIEVE. In some companies they are called copy code.

Your installation's macro library probably contains numerous macros that you may be able to use. Some common types of macros are

• data dictionary -- file and field definitions • user PROCs -- commonly used routines • report templates -- regularly generated reports • queries -- entire EZT+ programs (so a user can code one line to produce a report)

Page 73: Easy Tri Eve

ENHANCING THE PROGRAM--Statements and Macros D1

DPEC, Inc. 71

To invoke a macro, use a macro invocation statement anywhere in an EASYTRIEVE program.

Syntax: %macro-name <macro-parameters> Example: %CUSTLIB

% tells EZT+ to retrieve a macro with the specified name.

macro-name is the same as the member name in the macro storage library.

Optionally, you can specify parameters to substitute in the macro. You'll see more about this shortly.

Each macro in the storage library is made up of three parts:

• prototype statement -- defines macro parameters • body -- contains the EZT+ statements to be generated • termination command -- ends the macro (optional)

Let's see how to actually create a macro for the library.

Start with a prototype statement.

Syntax: MACRO <n> <positional-parameters> <keyword-parameters>

If you are not specifying substitution parameters, you need only code the keyword MACRO.

Follow with the EASYTRIEVE statements you want to execute as the macro. If you wish, end with the command MEND.

Example: MACRO FILE INVENTRY PART-NUM 1 6 N PART-NAME 7 20 A INSTOCK 27 5 N 2 PRICE 32 6 N 2 MEND

Code parameters to allow for substitution values:

Positional parameters are identified by their order on the prototype statement.

Page 74: Easy Tri Eve

D1 ENHANCING THE PROGRAM--Statements and Macros

72 DPEC, Inc.

Syntax: MACRO pos1-parameter pos2-parameter ... Example: MACRO RAISE-PCT

Use positional parameters when the value is required each time the macro is invoked.

You cannot specify a default value, so if you don't supply a substitution value when invoking the macro, the parameter will be treated as nonexistent.

Keyword parameters are defined by a keyword and a default value.

Syntax: MACRO <n> key1 value1 key2 value2 Example: MACRO 0 LGTH-OF-SVC '1'

n specifies the number of positional parameters. It is required only when you code keyword parameters. If you use only keyword parameters, you must code it as 0.

You can optionally delimit the parameter value with single quotes -- the quotes are not passed.

Use keyword parameters to keep track of multiple parameters or when their use is optional. Also use to specify a default value for parameters.

You can, of course, combine keyword and positional parameters. Code all positional parameters before any keyword parameters.

Syntax: MACRO n pos1 pos2 ... key1 value1 key2 value2 ... Example: MACRO 1 RAISE-PCT LGTH-OF-SVC 1

An example of a data dictionary macro displays below.

MACRO SUFX NAME&SUFX 1 25 A HEADING 'EMPLOYEE NAME' ADDRESS&SUFX 26 25 A CITY&SUFX 51 15 A STATE&SUFX 66 10 A BIRTH-DATE&SUFX 76 6 N MASK '99/99/99' SOC-SEC-NUM&SUFX 82 9 N MASK '999-99-9999' SALARY&SUFX 91 9 N 2 MASK '$,$$$,$$9.99' LGTH-OF-SVC&SUFX 100 3 N 1 HEADING ('YEARS' 'SERVICE')

Page 75: Easy Tri Eve

ENHANCING THE PROGRAM--Statements and Macros D1

DPEC, Inc. 73

This macro uses a parameter called SUFX to add a suffix to each field name. The ampersand (&) tells EZT+ where to substitute the value of SUFX in the macro. In this case the SUFX word is delimited at the end by a space.

If you want to concatenate the substituted value with another word, use a period as the delimiter.

MACRO NEW &NEW.NAME &NEW.ADDRESS

In our actual source code, we code the Library section as

FILE MSTRIN %EMPEZT -01 FILE MSTROUT %EMPEZT -02

The resulting EASYTRIEVE file definition displays below. This is a quick and easy way to duplicate file definitions while providing unique filenames.

FILE MSTRIN NAME-01 1 25 A HEADING 'EMPLOYEE NAME' ADDRESS-01 26 25 A CITY-01 51 15 A STATE-01 66 10 A BIRTH-DATE-01 76 6 N MASK '99/99/99' SOC-SEC-NUM-01 82 9 N MASK '999-99-9999' SALARY-01 91 9 N 2 MASK '$,$$$,$$9.99' LGTH-OF-SVC-01 100 3 N 1 HEADING ('YEARS' 'SERVICE') FILE MSTROUT NAME-02 1 25 A HEADING 'EMPLOYEE NAME' ADDRESS-02 26 25 A CITY-02 51 15 A STATE-02 66 10 A BIRTH-DATE-02 76 6 N MASK '99/99/99' SOC-SEC-NUM-02 82 9 N MASK '999-99-9999' SALARY-02 91 9 N 2 MASK '$,$$$,$$9.99' LGTH-OF-SVC-02 100 3 N 1 HEADING ('YEARS' 'SERVICE')

These are the file definitions for a master employee file. We'd like to place these in a macro, but specify a substitution parameter that will let us use them for a variety of input and output files.

Page 76: Easy Tri Eve

D1 ENHANCING THE PROGRAM--Statements and Macros

74 DPEC, Inc.

EMP-NUM 1 5 A L-NAME 6 10 A F-NAME 16 10 A ADDR-1 26 15 A ADDR-2 41 15 A CITY 56 10 A STATE 66 2 A ZIP 68 5 A FILLER-A 73 7 A

After coding the macro prototype statement and modifying the field names, we store the macro with the name EMPLIB. Now it's ready to be invoked in a program.

MACRO PREFIX &PREFIX.EMP-NUM 1 5 A &PREFIX.L-NAME 6 10 A &PREFIX.F-NAME 16 10 A &PREFIX.ADDR-1 26 15 A &PREFIX.ADDR-2 41 15 A &PREFIX.CITY 56 10 A &PREFIX.STATE 66 2 A &PREFIX.ZIP 68 5 A &PREFIX.FILLER-A 73 7 A

The following statements invoke macros for both the master and transaction files.

FILE OLDMSTR VS %EMPLIB MST- FILE TRANS %EMPLIB TRN-

You can see below what we coded for an earlier program before we set up the macro.

Page 77: Easy Tri Eve

ENHANCING THE PROGRAM--Statements and Macros D1

DPEC, Inc. 75

FILE OLDMSTR VS FILE OLDMSTR VS %EMPLIB MST- MST-EMP-NUM 1 5 A FILE TRANS MST-L-NAME 6 10 A %EMPLIB TRN- MST-F-NAME 16 10 A MST-ADDR-1 26 15 A ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ MST-ADDR-2 41 15 A ³ The small amount of code ³ MST-CITY 56 10 A ³ on the left produces all ³ MST-STATE 66 2 A ³ the EZT+ statements on ³ MST-ZIP 68 5 A ³ the right. ³ MST-FILLER-A 73 7 A ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ FILE TRANS TRN-EMP-NUM 1 5 A TRN-L-NAME 6 10 A TRN-F-NAME 16 10 A TRN-ADDR-1 26 15 A TRN-ADDR-2 41 15 A TRN-CITY 56 10 A TRN-STATE 66 2 A TRN-ZIP 68 5 A TRN-FILLER-A 73 7 A

Using macros helps you and other users standardize and streamline your EASYTRIEVE programs.

You can share common code and modify it with substitution values as needed.

That concludes our look at macros. We showed you only a few basic examples. If you want to do more, see your EASYTRIEVE manuals for more guidelines and suggestions.

Page 78: Easy Tri Eve

D2 ENHANCING THE PROGRAM--File Processing

76 DPEC, Inc.

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

1. Use the GET statement to control input for sequential processing.

GET file-name <STATUS>

2. To move data to an output file, use a PUT statement.

PUT file-name <FROM file-name-2>

3. Another way to control input is to code the CARD option on the FILE statement to retrieve instream data.

FILE file-name CARD

4. To describe a VSAM file as input, use the following syntax for the FILE statement:

FILE file-name VS <(F UPDATE)>

5. To randomly access a VSAM file, use the READ statement:

READ file-name KEY field-name STATUS

6. Use STATUS to test whether or not a record is present in the file. Some common examples of FILE-STATUS values are

0 operation performed successfully 4 end-of-file during a GET 16 record not found during a READ

7. The POINT statement allows you to set a position within a VSAM file where you want sequential processing to begin.

POINT file-name operator <field-name³literal> <STATUS >

Page 79: Easy Tri Eve

ENHANCING THE PROGRAM--File Processing D2

DPEC, Inc. 77

∞∞∞∞∞∞∞∞∞∞∞∞∞ Review Points (cont.) ∞∞∞∞∞∞∞∞∞∞∞∞∞

8. Use the WRITE statement to update a VSAM file.

WRITE file-name-1 <UPDATE³ADD³DELETE> + <FROM file-name-2> STATUS

9. Use the INPUT parameter on the JOB statement to designate files and their keys for synchronized file input.

JOB INPUT (file-1 KEY (field-1 field-2 ...) + file-2 KEY (field-1 field-2 ...) ...)+ <NAME jobname>

10. Use a MATCHED test to see if keys on all current records match.

IF <NOT> MATCHED (file-name-1 file-name-2 ...)

11. Use a file presence test to see if there's a record available for processing from a certain file or if EZT+ has reached the end of the file.

IF <NOT> <EOF> file-name

12. You can check for duplicate records with the following syntax:

IF <NOT> DUPLICATE³FIRST-DUP³LAST-DUP file-name

∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞

Page 80: Easy Tri Eve

D2 ENHANCING THE PROGRAM--File Processing

78 DPEC, Inc.

This objective looks at some of the statements related to sequential file processing, VSAM processing and synchronized processing.

Let's start by looking at some general information about file processing.

EASYTRIEVE can process all sorts of files and data bases, including

• sequential • VSAM • IMS/DLI • IDMS • SQL

Processing can be either automatic or controlled.

automatic -- EZT+ controls input through the JOB and SORT statements and output through the SORT and REPORT SUMFILE parameter.

controlled -- the programmer (you) codes input/output statements such as GET, PUT, POINT, READ and WRITE.

Much of the time, especially for sequential access of files, you can just let EASYTRIEVE handle the processing chores.

There are situations, though, when the ability to control input, output or both come in handy. For example,

• to access data from more than one input file • to randomly access VSAM or data base files

Look at the following example.

In the Library section we define an input file with customer information (INFILE) and two other input VSAM files which contain price information we need for our report (PRICE-FILE-1 and PRICE-FILE-2).

Page 81: Easy Tri Eve

ENHANCING THE PROGRAM--File Processing D2

DPEC, Inc. 79

FILE INFILE CUST-NAME 1 35 A CUST-NO 36 7 N 0 PRICE-CODE 43 1 A INF-ITEM 44 9 N 0 ITEM-NAME 54 40 A OUT-PRICE W 6 N 2 FILE PRICE-FILE-1 VS PF1-ITEM 1 9 N 0 PF1-PRICE 10 6 N 2 FILE PRICE-FILE-2 VS PF2-ITEM 1 9 N 0 PF2-PRICE 10 6 N 2

The JOB statement automatically inputs records from INFILE. Then EASYTRIEVE READs a corresponding record in either PRICE-FILE-1 or PRICE-FILE-2.

It then MOVEs a price value (PF1-PRICE or PF2-PRICE) to the OUT-PRICE field.

JOB INPUT INFILE NAME ITEM-PRICES IF PRICE-CODE = 'A' THRU 'C' READ PRICE-FILE-1 KEY INF-ITEM MOVE PF1-PRICE TO OUT-PRICE ELSE READ PRICE-FILE-2 KEY INF-ITEM MOVE PF2-PRICE TO OUT-PRICE END-IF PRINT PRICE-REPT REPORT PRICE-REPT TITLE 'ITEM PRICES BASED ON CUSTOMER PRICE CODE' LINE CUST-NO CUST-NAME ITEM-NAME OUT-PRICE

The following restrictions apply to combining automatic and controlled processing:

• No controlled statements are permitted in SORT or REPORT procedures

• Controlled processing is not allowed for an input file that has already been defined as an automatic input file.

Page 82: Easy Tri Eve

D2 ENHANCING THE PROGRAM--File Processing

80 DPEC, Inc.

The following error conditions can arise during file processing:

• File OPEN errors are usually caused by faulty JCL. The operating system terminates EZT+ processing.

• Invalid file reference errors occur when a statement refers to data in a file with no current record (e.g., after end-of-file). EASYTRIEVE generates a message if the FLDCHK option is in effect.

• Improper handling of nonzero STATUS conditions. Statements such as READ return input/output STATUS codes which you are responsible for handling in your code. You'll see examples of this in the section on VSAM processing.

EASYTRIEVE handles the opening and closing of files used in activities. It performs several tasks as needed, including

- validates block length - allocates buffer areas - allocates work areas - loads user exit programs - closes files at the end of each activity

Sequential processing is what we've been letting EZT+ do automatically so far.

The JOB section of our course example defines EMPFILER as the automatic input file for sequential processing.

JOB INPUT EMPFILER NAME COURSE-EXAMPLE IF PAY-GRADE > 3 NEW-VAC = TOTAL-VAC + 2 ELSE NEW-VAC = TOTAL-VAC + 1 END-IF VAC-REMAIN = NEW-VAC - USED-VAC PRINT REPT1

If you decide to control the input, use the GET statement.

Syntax: GET file-name <STATUS> Example: GET EMPFILER STATUS

Page 83: Easy Tri Eve

ENHANCING THE PROGRAM--File Processing D2

DPEC, Inc. 81

Optionally use STATUS to check if the input operation was successful. You can test the return code in the system-defined FILE-STATUS field and specify different actions based on its value. You'll see examples of this as we proceed.

If we decide to take control of the input, we use a GET statement and add some logic.

Note the use of NULL in the JOB statement. This inhibits automatic input so the GET statement can take control.

JOB INPUT NULL NAME CONTROL-INPUT GET EMPFILER IF EOF EMPFILER STOP END-IF IF PAY-GRADE > 3 NEW-VAC = TOTAL-VAC + 2 ELSE NEW-VAC = TOTAL-VAC + 1 END-IF VAC-REMAIN = NEW-VAC - USED-VAC PRINT REPT1

You must also test for end-of-file (EOF) and code the STOP statement, otherwise your program will execute forever. STOP ends the current activity and goes on to the next, if there are any.

Syntax: STOP <EXECUTE>

Code the EXECUTE parameter to terminate all EZT+ execution.

In our course example, the output is defined as a report.

JOB INPUT EMPFILER NAME COURSE-EXAMPLE IF PAY-GRADE > 3 NEW-VAC = TOTAL-VAC + 2 ELSE NEW-VAC = TOTAL-VAC + 1 END-IF VAC-REMAIN = NEW-VAC - USED-VAC PRINT REPT1

Page 84: Easy Tri Eve

D2 ENHANCING THE PROGRAM--File Processing

82 DPEC, Inc.

If we would also like to have an output file, we can add a PUT statement.

Syntax: PUT file-name <FROM file-name-2> Example: PUT OUTFILE FROM INFILE

Using the FROM parameter is equivalent to coding a MOVE statement prior to a PUT statement.

Let's create an output file.

First we define a new output file with just the fields we want.

FILE NEW-VAC F-NAME 1 8 A L-NAME 9 10 A DEPT 19 5 A NEW-VAC 24 2 N 0 USED-VAC 26 2 N 0 VAC-REMAIN 28 2 N 0

Then we add a PUT statement to write out the current EMPFILER record to the file NEW-VAC.

JOB INPUT EMPFILER NAME CONTROL-OUTPUT IF PAY-GRADE > 3 NEW-VAC = TOTAL-VAC + 2 ELSE NEW-VAC = TOTAL-VAC + 1 END-IF VAC-REMAIN = NEW-VAC - USED-VAC PUT NEW-VAC FROM EMPFILER PRINT REPT1

Another way to control input is to code the CARD option on the FILE statement to retrieve instream data.

Syntax: FILE file-name CARD Example: FILE INDATA CARD

Look at an example of this.

Page 85: Easy Tri Eve

ENHANCING THE PROGRAM--File Processing D2

DPEC, Inc. 83

FILE TESTDATA CARD SSNUM-TST 1 9 N ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ FILE MASTER VS ³ Note that an END statement must ³ SSNUM 1 9 N ³ be coded between the EZT+ ³ L-NAME 18 10 N ³ statements and the card data. ³ USED-SICK 69 2 N 0 ³ ³ USED-VAC 73 2 N 0 ³ This example actually involves ³ JOB INPUT TESTDATA NAME MYTEST ³ both sequential and random ³ READ MASTER KEY SSNUM-TST STATUS ³ processing, so let's consider ³ IF FILE-STATUS = 0 ³ VSAM files next. ³ PRINT DAYS-USED ³ ³ ELSE ³ ³ PERFORM ABEND. PROC ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ REPORT DAYS-USED ... ABEND. PROC ... END 345235678 143576987 543769504

To describe a VSAM file as input, use the following syntax for the FILE statement:

Syntax: FILE file-name VS <(F UPDATE)> Example: FILE MASTER VS

Coding F tells EZT+ that all the records in the file are the same length, which results in greater efficiency for any SORTs.

Code UPDATE if you want to use PUT or WRITE to update the file. We'll see an example of this soon.

VSAM files can be processed either sequentially or randomly. Only sequential processing is automatic.

To control sequential processing of a VSAM file, use the GET statement.

To randomly access a VSAM file, use the READ statement:

Syntax: READ file-name KEY field-name STATUS Example: READ MASTER KEY SSNUM-TST

The KEY parameter tells EZT+ the field-name (or literal) to use when searching for a corresponding record.

Page 86: Easy Tri Eve

D2 ENHANCING THE PROGRAM--File Processing

84 DPEC, Inc.

As with the GET statement, use STATUS to test whether or not a record is present in the file. Some common examples of FILE-STATUS values are

0 operation performed successfully 4 end-of-file during a GET 16 record not found during a READ

FILE TESTDATA CARD SSNUM-TST 1 9 N ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ FILE MASTER VS ³ If the value of FILE-STATUS ³ SSNUM 1 9 N ³ is anything but 0, EASYTRIEVE ³ L-NAME 18 10 N ³ will perform an error routine ³ USED-SICK 69 2 N 0 ³ called ABEND. ³ USED-VAC 73 2 N 0 ³ ³ JOB INPUT TESTDATA NAME MYTEST ³ This program demonstrates how ³ READ MASTER KEY SSNUM-TST STATUS ³ to check for valid input and ³ IF FILE-STATUS = 0 ³ specify an error routine if ³ PRINT DAYS-USED ³ the data is not valid. ³ ELSE ³ ³ PERFORM ABEND. PROC ³ ³ REPORT DAYS-USED ³ ³ ... ³ Let's look at two more ³ ABEND. PROC ³ statements used to control ³ ... ³ random processing. ³ END ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ 345235678 143576987 543769504

The POINT statement allows you to set a position within a VSAM file where you want sequential processing to begin. Data can be retrieved either via automatic file input or with a GET statement.

Syntax: POINT file-name operator <field-name³literal> <STATUS> Example: POINT INFILE >= 34567 STATUS

file-name must be on a FILE statement describing a VSAM file.

The relational operator can specify an exact match with an equal operator (EQ or =) or use a 'greater than or equal to' operator (GE or >=).

The object of the operator can be any valid field-name or literal.

Optionally use STATUS to check on input processing.

Page 87: Easy Tri Eve

ENHANCING THE PROGRAM--File Processing D2

DPEC, Inc. 85

Use the WRITE statement to update a VSAM file.

Syntax: WRITE file-name-1 <UPDATE³ADD³DELETE> + <FROM file-name-2> STATUS

Example: WRITE MASTER-FILE UPDATE FROM TRANS-FILE

A typical scenario is to update a master file with the values in a transaction file. We're going to see an example of this next.

Note: At many sites, although many users can read VSAM files, only certain programmers are authorized to modify the files. If you are going to be modifying VSAM files, see the EASYTRIEVE PLUS manual for more details on WRITE.

We'll now present a VSAM processing example. It incorporates many of the EASYTRIEVE statements you've learned.

The purpose of the program is to update employee performance review dates in the master file. Personnel has just received a listing of 10 employees who had their reviews last month.

The Library section defines the transaction file (EMPIN) and the master file (EMPVSAM), as well as several working storage fields. WORK-DATE will be used to display the date of an employee's last review on a report. WS-MONTH and WS-YEAR are initialized to a value for last month. ABEND-CODE is used in an error routine.

FILE EMPIN EMP-REC-IN 1 80 A EMP-L-NAME 1 20 A HEADING 'LAST NAME' EMP-F-NAME 21 10 A HEADING 'FIRST NAME' FILE EMPVSAM VS (F UPDATE) EMPVSAM-KEY 1 20 A EMPVSAM-F-NAME 21 10 A REVIEW-DATE 31 4 N REV-MONTH 31 2 N REV-YEAR 33 2 N WORK-DATE W 4 N HEADING ('PRIOR' 'REVIEW' 'DATE') + MASK (BWZ 'ZZ/ZZ') WS-MONTH W 2 N VALUE 06 WS-YEAR W 2 N VALUE 97 ABEND-CODE W 2 B 0

Page 88: Easy Tri Eve

D2 ENHANCING THE PROGRAM--File Processing

86 DPEC, Inc.

The JOB activity section sets up EMPIN as the automatic input file. It then assigns the value of EMP-L-NAME to the VSAM file key field. Using the value of EMPVSAM-KEY, EASYTRIEVE reads EMPVSAM randomly, inputting each record that matches a key value in EMPIN.

JOB INPUT EMPIN EMPVSAM-KEY = EMP-L-NAME READ EMPVSAM KEY EMPVSAM-KEY STATUS IF FILE-STATUS = 16 PERFORM ADD-NEW-EMPLOYEE ELSE IF FILE-STATUS = 0 PERFORM UPDATE-EMPLOYEE ELSE DISPLAY 'VSAM READ FILE STATUS = ' FILE-STATUS ABEND-CODE = +1562 PERFORM ABEND END-IF END-IF PRINT MONTHLY-REVIEWS ADD-NEW-EMPLOYEE. PROC WORK-DATE = 0 EMPVSAM-F-NAME = EMP-F-NAME REV-MONTH = WS-MONTH REV-YEAR = WS-YEAR WRITE EMPVSAM ADD END-PROC UPDATE-EMPLOYEE. PROC WORK-DATE = REVIEW-DATE REV-MONTH = WS-MONTH REV-YEAR = WS-YEAR WRITE EMPVSAM UPDATE END-PROC ABEND. PROC CALL DUMP USING ABEND-CODE END-PROC REPORT MONTHLY-REVIEWS TITLE 'EMPLOYEE PERFORMANCE REVIEWS' TITLE 2 'FOR JUNE' LINE EMP-L-NAME EMP-F-NAME WORK-DATE

Look now at the PROC that is performed to add a new employee. It assigns values to the remaining fields needed for the master file and also the working storage field WORK-DATE, used in the report.

It then writes the record to the master file.

Page 89: Easy Tri Eve

ENHANCING THE PROGRAM--File Processing D2

DPEC, Inc. 87

The UPDATE-EMPLOYEE procedure is similar. The UPDATE parameter is used on the WRITE statement.

The listings below show you the contents of the EMPVSAM file before and after the update process. Note that two new records are added and all REVIEW-DATEs are 0697, which is last month's date.

BEFORE UPDATE AFTER UPDATE

BARTH SUE 0896 BARTH SUE 0697 CARLSON DAVE 0696 CARLSON DAVE 0697 CARNAGEY BOB 0796 CARNAGEY BOB 0697 FERNANDEZ EVETTE 0197 DUGAS WENDY 0697 FREY RICH 0396 FERNANDEZ EVETTE 0697 KY TANYA 0297 FREY RICH 0697 STUBENRAUCH DUANE 0696 KY TANYA 0697 TRIEU JASON 0197 SMITH DON 0697 STUBENRAUCH DUANE 0697 TRIEU JASON 0697

If neither an ADD or an UPDATE are performed, EZT+ displays an error message and performs an error routine which calls an external program based on the value of ABEND-CODE.

Following the file processing, EASYTRIEVE sends all records to a report, which displays below.

7/7/97 EMPLOYEE PERFORMANCE REVIEWS PAGE 1 FOR JUNE

PRIOR REVIEW LAST NAME FIRST NAME DATE

BARTH SUE 8/96 CARLSON DAVE 6/96 CARNAGEY BOB 7/96 DUGAS WENDY FERNANDEZ EVETTE 1/97 FREY RICH 3/96 KY TANYA 2/97 SMITH DON STUBENRAUCH DUANE 6/96 TRIEU JASON 1/97

Page 90: Easy Tri Eve

D2 ENHANCING THE PROGRAM--File Processing

88 DPEC, Inc.

Thus far, we've explored both sequential and random (VSAM) processing.

Next we'll look at synchronized processing.

EASYTRIEVE's Synchronized File Processing facility (SFP) coordinates the input of multiple files.

Instead of coding complex logic to handle match/merge operations, you can let EZT+ perform input automatically with its universally adaptable match/merge algorithm.

EASYTRIEVE also has special conditional expressions that help you determine file relationships.

The following assumptions and rules apply to the SFP match/merge algorithm:

• EASYTRIEVE can access two or more files capable of being processed sequentially.

• All files must be in ascending order by key values.

• All files must have the same number of keys.

• Corresponding keys must be either alphanumeric or numeric. If alphanumeric, lengths can be different. If numeric, data types and lengths can be different.

• Processing continues until EASYTRIEVE encounters end-of-file on all files.

• VSAM files cannot be updated during synchronized processing, because of the way the algorithm 'reads ahead' to perform a match/merge.

Use the INPUT parameter on the JOB statement to designate files and their keys for synchronized file input.

Syntax: JOB INPUT (file-1 KEY (field-1 field-2 ...) + file-2 KEY (field-1 field-2 ...) ...)+ <NAME jobname>

Example: JOB INPUT (MASTER KEY M-SSNO TRANS KEY T-SSNO) + NAME OVERTIME

Page 91: Easy Tri Eve

ENHANCING THE PROGRAM--File Processing D2

DPEC, Inc. 89

Let's look at some conditional statements you can code to determine the relationships between records in multiple files.

Use a MATCHED test to see if keys on all current records match.

Syntax: IF <NOT> MATCHED (file-name-1 file-name-2 ...) Example: IF MATCHED (MASTER TRANS)

You can code the NOT parameter to specify action when records don't match.

Use a file presence test to see if there's a record available for processing from a certain file or if EZT+ has reached the end of the file.

Syntax: IF <NOT> <EOF> file-name Example: IF MASTER Example: IF EOF TRANS

Look now at an example program that uses both these tests.

FILE OLDMSTR VS MST-EMP-NUM 1 5 A ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ MST-L-NAME 6 10 A ³ The Library section defines ³ MST-F-NAME 16 10 A ³ a current master file (OLDMSTR), ³ MST-ADDR-1 26 15 A ³ a transaction file (TRANS) and ³ MST-ADDR-2 41 15 A ³ a new master file (NEWMSTR). ³ MST-CITY 56 10 A ³ ³ MST-STATE 66 2 A ³ The information in the ³ MST-ZIP 68 5 A ³ transaction file is used to ³ MST-FILLER-A 73 7 A ³ update general employee data. ³ FILE TRANS ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ TRN-EMP-NUM 1 5 A TRN-L-NAME 6 10 A TRN-F-NAME 16 10 A TRN-ADDR-1 26 15 A TRN-ADDR-2 41 15 A TRN-CITY 56 10 A TRN-STATE 66 2 A TRN-ZIP 68 5 A TRN-FILLER-A 73 7 A FILE NEWMSTR FB(0,0)

Page 92: Easy Tri Eve

D2 ENHANCING THE PROGRAM--File Processing

90 DPEC, Inc.

This JOB section sets up the synchronized processing and codes the statements to check on record relationships.

If a match is found between the master file and the transaction file, the transaction record is written out to the new master file.

JOB INPUT (OLDMSTR KEY MST-EMP-NUM + TRANS KEY TRN-EMP-NUM) IF MATCHED PUT NEWMSTR FROM TRANS ELSE IF OLDMSTR PUT NEWMSTR FROM OLDMSTR END-IF END-IF

Sometimes you have the situation where the transaction file has multiple records that match the master file. You can handle this by checking for duplicate records.

Syntax: IF <NOT> DUPLICATE³FIRST-DUP³LAST-DUP file-name Example: IF DUPLICATE TRANS

DUPLICATE tests whether a duplicate record exists on the same file.

FIRST-DUP tests whether the record is the first in a series of duplicate records.

LAST-DUP tests whether the record is the last in a series of duplicate records.

The next program updates the total overtime hours on the employee master file.

If a match is found between the master file and the transaction file, the overtime hours from the transaction file record are added to the hours on the master file record. Otherwise, the master file record is written out with no changes.

The program handles multiple updates on the transaction file.

Page 93: Easy Tri Eve

ENHANCING THE PROGRAM--File Processing D2

DPEC, Inc. 91

FILE OLDMSTR MST-RECORD 1 80 A ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ MST-EMP-NUM 1 5 A ³ Once again, there are three ³ MST-L-NAME 6 10 A ³ files defined. ³ MST-F-NAME 16 10 A ³ ³ MST-ADDR-1 26 15 A ³ TRANS can contain one or more ³ MST-ADDR-2 41 15 A ³ records with the same employee ³ MST-CITY 56 10 A ³ number. ³ MST-STATE 66 2 A ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ MST-ZIP 68 5 A MST-OT-HRS 73 8 N 0 FILE TRANS TRN-EMP-NUM 1 5 A TRN-OT-HRS 6 8 N 0 FILE NEWMSTR FB(0,0) NEW-RECORD 1 80 A

Here's the JOB section. If keys on current records match, EASYTRIEVE will add the transaction file overtime hours to the master file hours.

JOB INPUT (OLDMSTR KEY MST-EMP-NUM + TRANS KEY TRN-EMP-NUM) IF MATCHED MST-OT-HRS = MST-OT-HRS + TRN-OT-HRS IF DUPLICATE TRANS IF LAST-DUP TRANS PUT NEWMSTR FROM OLDMSTR END-IF ELSE PUT NEWMSTR FROM OLDMSTR END-IF ELSE IF OLDMSTR PUT NEWMSTR FROM OLDMSTR END-IF END-IF

The next two statements determine if the current TRANS record is a duplicate, and if it is, if it is the last duplicate.

If this is the last duplicate, then write the record to the new master file. If not, continue processing.

If there are no duplicates on TRANS, write the updated old master record to the new master file.

For when there is no match, write the current unaltered old master record to the new master file. r