Easy Tri Eve

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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

USING EASYTRIEVE PLUS

Table of Contents

UNIT A EASYTRIEVE PLUS OVERVIEW Objective #1 Introduction .................................................... 1 Objective #2 Program Examples ................................................ 6 UNIT B BUILDING A SIMPLE PROGRAM Objective #1 Coding a Library Section ....................................... 14 Objective #2 Coding a JOB Activity Section .................................. 22 Objective #3 Coding a REPORT Section ........................................ 31 UNIT C CUSTOMIZING THE REPORT Objective #1 Using REPORT Statement Parameters .............................. 43 Objective #2 Using Report PROCs ............................................. 51 UNIT D ENHANCING THE PROGRAM Objective #1 Statements and Macros .......................................... 60 Objective #2 File Processing ................................................ 76

DPEC, Inc.

EASYTRIEVE PLUS OVERVIEW--Introduction


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

A1

DPEC, Inc.

A1

EASYTRIEVE PLUS OVERVIEW--Introduction


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 extraction of all types of data (sequential, ISAM, VSAM or matching and merging of unlimited number of files

or spanned) databases)

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

DPEC, Inc.

EASYTRIEVE PLUS OVERVIEW--Introduction


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

A1

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.

DPEC, Inc.

A1

EASYTRIEVE PLUS OVERVIEW--Introduction


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

Filename EMPFILER Attributes Record Format = FB Field Content SOC SEC NUMBER FIRST NAME LAST NAME DEPARTMENT JOB TITLE PAY GRADE SUPERVISOR NAME START DATE SALARY TOTAL SICK DAYS USED SICK DAYS TOTAL VACATION USED VACATION

Record Size = 74 Length 9 8 10 5 11 2 10 6 5 2 2 2 2

Blocksize = 1800 Comments

Start Location 1 10 18 28 33 44 46 56 62 67 69 71 73

Type N A A A A N A N N N N N N

month day year 0 decimals 0 decimals 0 decimals 0 decimals 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.

DPEC, Inc.

EASYTRIEVE PLUS OVERVIEW--Introduction


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.

A1

DPEC, Inc.

A2

EASYTRIEVE PLUS OVERVIEW--Program Examples


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. non-blank character of a statement.

To code a comment, make an asterisk (*) the first

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 decimal digit character

first character must be an alphabetic character or a

must contain at least one alphabetic or special

must be unique within a file

DPEC, Inc.

EASYTRIEVE PLUS OVERVIEW--Program Examples


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.

A2

DPEC, Inc.

A2

EASYTRIEVE PLUS OVERVIEW--Program Examples


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 DEPT FIN FIN HRES HRES MNT SALES SALES SYS SYS SYS F-NAME Sherrie Mary Letitia Yuichiro Tom Jerry Emily Jeff Linda Carmen VACATION AND SICK DAYS REPORT L-NAME TOTAL-SICK Mathers 10 Snyder 05 Washington 10 Yashiki 10 Wilson 05 Freeman 10 Vincent 10 Johnson 10 Jones 10 Saez 10 USED-SICK 02 05 02 05 03 02 04 01 04 00 TOTAL-VAC 15 15 15 15 10 10 15 15 20 10 PAGE 1 USED-VAC 06 06 04 02 04 05 03 03 05 04

DPEC, Inc.

EASYTRIEVE PLUS OVERVIEW--Program Examples


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.

A2

DPEC, Inc.

A2

EASYTRIEVE PLUS OVERVIEW--Program Examples


9/26/98 DEPT FIN FIN HRES HRES MNT SALES SALES SYS SYS SYS EMPLOYEES BY DEPARTMENT PAGE 1 F-NAME Sherrie Mary Letitia Yuichiro Tom Jerry Emily Jeff Linda Carmen L-NAME Mathers Snyder Washington Yashiki Wilson Freeman Vincent Johnson Jones Saez SSNUM 456787678 498765433 342986544 234723456 777654321 292549357 512365764 454445676 123212323 543456787

FILE EMPFILER SSNUM 1 9 N F-NAME 10 8 A L-NAME 18 10 A DEPT 28 5 A JOB INPUT EMPFILER NAME ROSTER PRINT RPT1-ROSTER REPORT RPT1-ROSTER SEQUENCE DEPT L-NAME TITLE 'EMPLOYEES BY DEPARTMENT' LINE 01 DEPT F-NAME L-NAME SSNUM

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

10

DPEC, Inc.

EASYTRIEVE PLUS OVERVIEW--Program Examples


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

A2

systems staff may establish another area (e.g., 7 to 72) to allow for entry of optional data that EZT+ ignores. a period (.) to separate these statements. Use

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. non-blank character of a statement. ( (left parenthesis)and : (colon).

To code a comment, make an asterisk (*) the first

Leave at least one space after all delimiters except for

DPEC, Inc.

11

A2

EASYTRIEVE PLUS OVERVIEW--Program Examples


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 decimal digit

first character must be an alphabetic character or a

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'

12

DPEC, Inc.

EASYTRIEVE PLUS OVERVIEW--Program Examples


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.

A2

DPEC, Inc.

13

B1

BUILDING A SIMPLE PROGRAM--Coding a Library Section


Review Points 1. The FILE statement begins the Library section. it to define both input and output files. Syntax: FILE file-name <attributes> You use

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 (letterBWZ'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 Z * $ prints a prints a prints a prints a digit of prints a non-zero digit digit, or if a leading zero, a blank digit, or if a leading zero, an * minus sign before the first non-zero a negative number currency symbol ($) before the first digit and suppresses leading zeros

14

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a Library Section


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 BIRTH-MTH BIRTH-DAY BIRTH-YR 72 72 74 76 6 2 2 2 MASK 'Z9/99/99'

B1

7. Define working storage fields as either W or S, using the letter as the start-location for the field: W S values associated with each individual record values not associated with a record

DPEC, Inc.

15

B1

BUILDING A SIMPLE PROGRAM--Coding a Library Section


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. use it to define both input and output files. Syntax: FILE file-name <attributes> You

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 (letterBWZ'literal')> 18 50 10 5 A N 0

Example: L-NAME SALARY

16

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a Library Section


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 define based on position 1 of the record specify in bytes (characters/spaces) code the appropriate letter: MAX. LENGTH (BYTES) 32,767 18 10 9 4

B1

start-location field-length data-type A N P U B

TYPE Alphanumeric Numeric Packed Unsigned Packed Binary

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 84 4 P 2

Example: BIWEEKLY-GROSS

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')

DPEC, Inc.

17

B1

BUILDING A SIMPLE PROGRAM--Coding a Library Section


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 323456765 035467 Mask '999-99-9999' '$$$,$$9' Result 323-45-6765 $35,467

You create a mask using the following characters: 9 Z * $ prints a prints a prints a prints a digit of prints a non-zero digit digit, or if a leading zero, a blank digit, or if a leading zero, an * minus sign before the first non-zero a negative number currency symbol ($) before the first 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.

18

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a Library Section


In the examples below, M is a mask for money and P is a phone mask. BIWEEKLY-GROSS MONTHLY-GROSS PHONE 84 88 25 4 P 4 P 10 N 2 2 MASK (M '$$$,$$9.99') MASK (M) MASK (P '(999)999-9999')

B1

If you do not specify a mask, the system default for numeric fields depends on the number of decimal positions specified: SALARY SALARY SALARY 50 50 50 5 5 5 N N 0 N 2 '99999' 'ZZ,ZZZ-' '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 BIRTH-MTH BIRTH-DAY BIRTH-YR 72 72 74 76 6 2 2 2 MASK 'Z9/99/99'

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 S values associated with each individual record values not associated with a record

DPEC, Inc.

19

B1

BUILDING A SIMPLE PROGRAM--Coding a Library Section


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 BIWEEKLY-NET DEDUCTIONS 84 88 W 4 4 4 P P P 2 2 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 L-NAME DEPT PAY-GRADE TOTAL-VAC USED-VAC 10 18 28 44 71 73 8 10 5 2 2 2 A A A N N 0 N 0

20

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a Library Section


We also need two working storage fields for some calculations we'll be doing later in the JOB activity section. FILE EMPFILER F-NAME L-NAME DEPT PAY-GRADE TOTAL-VAC USED-VAC NEW-VAC VAC-REMAIN 10 18 28 44 71 73 W W 8 10 5 2 2 2 2 2 A A A N N N N N

B1

0 0 0 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 L-NAME DEPT PAY-GRADE TOTAL-VAC USED-VAC NEW-VAC VAC-REMAIN 10 18 28 44 71 73 W W 8 10 5 2 2 2 2 2 A A A N N N N N HEADING 'FIRST NAME' HEADING 'LAST NAME' HEADING 'DEPARTMENT' 0 0 0 0 HEADING ('VACATION' 'USED') HEADING ('NEW' 'TOTAL' 'VACATION') 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.

DPEC, Inc.

21

B2

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section


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.

22

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section


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-2literalexpression

B2

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.

DPEC, Inc.

23

B2

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section


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

24

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section


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 or or or or or EQ NE GT LT GE LE equal to not equal to (see NOTE) greater than less than greater than or equal to less than or equal to

B2

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 field arithmetic expression IF USED-SICK LT 3 IF USED-SICK = TOTAL-SICK IF USED-SICK > (TOTAL-SICK / 2)

Let's look at literals and arithmetic expressions in more detail. Literals can be alphanumeric or numeric. must be enclosed in single quotes. Alphanumerics

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.

DPEC, Inc.

25

B2

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section


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

26

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section


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-2literalexpression

B2

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.

DPEC, Inc.

27

B2

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section


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> <ROUNDEDTRUNCATED> 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 NEWSAL 85 W 6 7 N N 2 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 INCREASE W 5 4 N N 0 0

28

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity Section


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

B2

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 L-NAME DEPT PAY-GRADE TOTAL-VAC USED-VAC NEW-VAC VAC-REMAIN 10 18 28 44 71 73 W W 8 10 5 2 2 2 2 2 A A A N N N N N HEADING 'FIRST NAME' HEADING 'LAST NAME' HEADING 'DEPARTMENT' 0 0 0 0 HEADING ('VACATION' 'USED') HEADING ('NEW' 'TOTAL' 'VACATION') 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.

DPEC, Inc.

29

B2

BUILDING A SIMPLE PROGRAM--Coding a JOB Activity 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 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.

30

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


Review Points 1. Each REPORT section begins with a REPORT statement. Syntax: REPORT report-name

B3

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-nameFINAL <NEWPAGERENUM>+ <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-nCOL nn> field-name'literal' ...

DPEC, Inc.

31

B3

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


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-nCOL nnPOS 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.

32

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


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

B3

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.

DPEC, Inc.

33

B3

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


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

34

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


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:

B3

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.

DPEC, Inc.

35

B3

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


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-nameFINAL <NEWPAGERENUM> <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-nCOL 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.

36

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


+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 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' PAGE 1

B3

Example: HEADING DEPT 'DEPARTMENT'

DPEC, Inc.

37

B3

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


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-nCOL nnPOS 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.

38

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


FILE EMPFILER 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-RPT REPORT CONTACT-RPT NOPAGE SEQUENCE DEPT TITLE 'EMPLOYEE LOCATION/PHONE' LINE DEPT L-NAME LINE 2 POS 2 WORK-PHONE LINE 3 POS 2 MAIL-STOP 6/4/99 EMPLOYEE LOCATION/PHONE DEPT FIN L-NAME MATHERS 9654 B234 SNYDER 4532 B236

B3

FIN ...

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.

DPEC, Inc.

39

B3

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


EMPLOYEES BY DEPARTMENT PAGE 1 F-NAME Sherrie Mary Letitia Yuichiro Tom Jerry Emily Jeff Linda Carmen L-NAME Mathers Snyder Washington Yashiki Wilson Freeman Vincent Johnson Jones Saez DEPARTMENT TOTAL

REPORT ROSTER 9/26/98 SEQUENCE DEPT L-NAME CONTROL DEPT TITLE 'EMPLOYEES BY DEPT' DEPT HEADING TALLY ('DEPARTMENT' 'TOTAL') LINE DEPT F-NAME L-NAME TALLY FIN FIN FIN HRES HRES HRES MNT MNT SALES SALES SALES SYS SYS SYS SYS

2 2 1 2

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.

40

DPEC, Inc.

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


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

B3

DPEC, Inc.

41

B3

BUILDING A SIMPLE PROGRAM--Coding a REPORT Section


The report displays below.

7/15/99

NEW VACATION TOTALS AFTER BONUS DAYS AWARDED NEW TOTAL VACATION 16 16 32 16 16 32 VACATION USED 6 6 12 4 2 6

PAGE 1 VACATION REMAINING 10 10 20 12 14 26

DEPARTMENT FIN FIN HRES HRES ... SYS SYS

FIRST NAME Sherrie Mary Letitia Yuichiro

LAST NAME Mathers Snyder Washington Yashiki

Jeff Linda Carmen

Johnson Jones Saez

16 21 12 49 151

3 5 4 12 42

13 16 8 37 109

42

DPEC, Inc.

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters


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

C1

2. SUMCTL determines how control field values print on total lines. Its subparameters are HIAR TAG -- prints all control field values in hierarchical order (Default) -- 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 SUMSPACE -- prints a summary report containing only total lines -- increases the print size of total line fields in case the length of the total is greater than the defined field size -- sets the print size of the TALLY field

TALLYSIZE

DPEC, Inc.

43

C1

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters


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 DOWN SIZE -- number of labels printed across. The default is 4. -- number of lines in a label. The default is 6. -- 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

44

DPEC, Inc.

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters


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

C1

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 -- prints the control field name and the word TOTAL on the left side of each total line

TAG

DTLCOPY -- prints values from detail lines onto total lines NONE -- prints no control field values on total lines

DPEC, Inc.

45

C1

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters


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 NEW TOTAL VACATION VACATION USED

PAGE 1 VACATION REMAINING

DEPARTMENT FIN FIN HRES HRES ... SYS SYS

FIRST NAME Sherrie Mary Letitia Yuichiro

LAST NAME Mathers Snyder

Jeff Linda Carmen

16 6 10 16 6 10 32 12 20 Washington The value of the control field Yashiki DEPT is printed only on the first line of a control group and on the total line. Johnson 16 3 13 Jones 21 5 16 Saez 12 4 8 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.

46

DPEC, Inc.

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters


7/15/99 NEW VACATION TOTALS AFTER BONUS DAYS AWARDED NEW TOTAL VACATION 16 16 32 16 16 32 VACATION USED 6 6 12 4 2 6 PAGE 1 VACATION REMAINING 10 10 20 12 14 26

C1

DEPARTMENT FIN DEPT TOTAL HRES DEPT TOTAL ... SYS

FIRST NAME Sherrie Mary Letitia Yuichiro

LAST NAME Mathers Snyder Washington Yashiki

DEPT TOTAL FINAL TOTAL

Jeff Linda Carmen

Johnson Jones Saez

16 21 12 49 151

3 5 4 12 42

13 16 8 37 109

Some other REPORT statement parameters that determine formatting are SUMMARY SUMSPACE -- prints a summary report containing only total lines. -- 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. -- 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.

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.

DPEC, Inc.

47

C1

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters


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. -- defined as 10 P 0. -- fields that are totaled. them as 10 P. Define

TALLY summed fields

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 DOWN SIZE -- number of labels printed across. default is 4. -- number of lines in a label. is 6. The

The default

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

This program illustrates the coding for a LABELS report.

48

DPEC, Inc.

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters


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.

C1

DPEC, Inc.

49

C1
6/14/99

CUSTOMIZING THE REPORT--Using REPORT Statement Parameters


NEW VACATION TOTALS AFTER BONUS DAYS AWARDED NEW TOTAL VACATION 16 16 32 32 32 11 11 27 27 49 49 151 VACATION USED 6 6 12 6 6 4 4 8 8 12 12 42 PAGE 1 VACATION REMAINING 10 10 20 26 26 7 7 19 19 37 39 109

DEPARTMENT FIN FIN FIN HRES HRES MNT MNT SALES SALES SYS SYS

SUPERVISOR Anderson Mathers Liam Holmes Zetsky Matsko

50

DPEC, Inc.

CUSTOMIZING THE REPORT--Using REPORT PROCs


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

C2

report processing

BEFORE-BREAK -- modifies totals and adds notes before

control break total lines print

AFTER-BREAK BEFORE-LINE AFTER-LINE ENDPAGE TERMINATION

-- adds a note after a total line prints -- adds a note before a detail line prints -- adds a note after a detail line prints -- produces page footer information -- produces end of report information

2. The syntax for PROCs is proc-name. PROC logic statements END-PROC (OR) proc-name 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

DPEC, Inc.

51

C2

CUSTOMIZING THE REPORT--Using REPORT PROCs


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 logic statements END-PROC (OR) proc-name 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.

52

DPEC, Inc.

CUSTOMIZING THE REPORT--Using REPORT PROCs


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.

C2

DPEC, Inc.

53

C2

CUSTOMIZING THE REPORT--Using REPORT PROCs

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 SALARY 7.58 10.38 17.96 8.67 12.09 20.76 6.88 6.88 10.68 10.68 21.36 8.27 11.02 13.69 32.98 99.94

DEPT FIN FIN HRES HRES MNT MNT SALES SALES SYS SYS

LAST NAME Snyder Mathers Yashiki Washington Wilson Freeman Vincent Jones Johnson Saez

NEW SALARY 29,252 40,067 69,319 33,475 46,659 80,134 26,574 26,574 41,200 41,200 82,400 31,930 42,539 52,839 127,308 385,735

Look now at another example.

54

DPEC, Inc.

CUSTOMIZING THE REPORT--Using REPORT PROCs


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

C2

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.

DPEC, Inc.

55

C2

CUSTOMIZING THE REPORT--Using REPORT PROCs

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

56

DPEC, Inc.

CUSTOMIZING THE REPORT--Using REPORT PROCs


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.

C2

DPEC, Inc.

57

C2

CUSTOMIZING THE REPORT--Using REPORT PROCs


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

58

DPEC, Inc.

CUSTOMIZING THE REPORT--Using REPORT PROCs


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 NEW TOTAL VACATION 16 16 32 VACATION USED 06 06 12 PAGE 1 VACATION REMAINING 10 10 20 12 14 26 13 16 08 37 109

C2

DEPARTMENT FIN FIN

LAST NAME Sherrie Mary

FIRST NAME Mathers Snyder

HRES Letitia NOTE TOTAL -- ONLY 5 DAYS Yuichiro NOTE TOTAL -- ONLY 5 DAYS HRES ... SYS Jeff NOTE TOTAL -- ONLY 5 DAYS Linda NOTE TOTAL -- ONLY 5 DAYS Carmen SYS

Washington 16 04 CAN BE CARRIED OVER TO NEXT YEAR!! Yashiki 16 02 CAN BE CARRIED OVER TO NEXT YEAR!! 32 06 Johnson 16 03 CAN BE CARRIED OVER TO NEXT YEAR!! Jones 21 05 CAN BE CARRIED OVER TO NEXT YEAR!! Saez 12 04 49 12 151 42

ROUTE TO PERSONNEL AND EACH SUPERVISOR TO SHARE WITH ALL EMPLOYEES

DPEC, Inc.

59

D1

ENHANCING THE PROGRAM--Statements and Macros


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 logic statements END-PROC (OR) proc-name 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>

60

DPEC, Inc.

ENHANCING THE PROGRAM--Statements and Macros


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 labelJOB 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 WHILEUNTIL conditional expression logic statements END-DO

D1

DPEC, Inc.

61

D1

ENHANCING THE PROGRAM--Statements and Macros


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 ...

62

DPEC, Inc.

ENHANCING THE PROGRAM--Statements and Macros


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:

D1

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.

DPEC, Inc.

63

D1

ENHANCING THE PROGRAM--Statements and Macros


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.

64

DPEC, Inc.

ENHANCING THE PROGRAM--Statements and Macros


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'>

D1

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.

DPEC, Inc.

65

D1

ENHANCING THE PROGRAM--Statements and Macros


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 logic statements END-PROC (OR) proc-name 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.

66

DPEC, Inc.

ENHANCING THE PROGRAM--Statements and Macros


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 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 JOB INPUT EMPFILER NAME PROC-EXAMPLE IF PAY-GRADE > 3 PERFORM VAC-A ELSE PERFORM VAC-B END-IF < VAC-REMAIN = NEW-VAC - USED-VAC PRINT REPT1 VAC-A. PROC NEW-VAC = TOTAL-VAC + 2 END-PROC VAC-B. PROC NEW-VAC = TOTAL-VAC + 1 END-PROC

D1

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.

DPEC, Inc.

67

D1

ENHANCING THE PROGRAM--Statements and Macros


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.

68

DPEC, Inc.

ENHANCING THE PROGRAM--Statements and Macros


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

D1

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 labelJOB 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.

DPEC, Inc.

69

D1

ENHANCING THE PROGRAM--Statements and Macros


Use the DO WHILE, DO UNTIL and END-DO statements to delimit the logic statements. Syntax: DO WHILEUNTIL 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 user PROCs report templates queries

-----

file and field definitions commonly used routines regularly generated reports entire EZT+ programs (so a user can code one line to produce a report)

70

DPEC, Inc.

ENHANCING THE PROGRAM--Statements and Macros


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 termination command -- ends the macro (optional)

D1

to be generated

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 PART-NAME INSTOCK PRICE MEND

1 7 27 32

6 20 5 6

N A N 2 N 2

Code parameters to allow for substitution values: Positional parameters are identified by their order on the prototype statement.

DPEC, Inc.

71

D1

ENHANCING THE PROGRAM--Statements and Macros


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 ADDRESS&SUFX CITY&SUFX STATE&SUFX BIRTH-DATE&SUFX SOC-SEC-NUM&SUFX SALARY&SUFX LGTH-OF-SVC&SUFX

1 26 51 66 76 82 91 100

25 25 15 10 6 9 9 3

A A A A N N N N

HEADING 'EMPLOYEE NAME'

2 1

MASK '99/99/99' MASK '999-99-9999' MASK '$,$$$,$$9.99' HEADING ('YEARS' 'SERVICE')

72

DPEC, Inc.

ENHANCING THE PROGRAM--Statements and Macros


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 ADDRESS-01 CITY-01 STATE-01 BIRTH-DATE-01 SOC-SEC-NUM-01 SALARY-01 LGTH-OF-SVC-01 FILE MSTROUT NAME-02 ADDRESS-02 CITY-02 STATE-02 BIRTH-DATE-02 SOC-SEC-NUM-02 SALARY-02 LGTH-OF-SVC-02 1 26 51 66 76 82 91 100 1 26 51 66 76 82 91 100 25 25 15 10 6 9 9 3 25 25 15 10 6 9 9 3 A A A A N N N N A A A A N N N N HEADING 'EMPLOYEE NAME'

D1

2 1

MASK '99/99/99' MASK '999-99-9999' MASK '$,$$$,$$9.99' HEADING ('YEARS' 'SERVICE') HEADING 'EMPLOYEE NAME'

2 1

MASK '99/99/99' MASK '999-99-9999' MASK '$,$$$,$$9.99' 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.

DPEC, Inc.

73

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

ENHANCING THE PROGRAM--Statements and Macros

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 &PREFIX.L-NAME &PREFIX.F-NAME &PREFIX.ADDR-1 &PREFIX.ADDR-2 &PREFIX.CITY &PREFIX.STATE &PREFIX.ZIP &PREFIX.FILLER-A 1 6 16 26 41 56 66 68 73 5 10 10 15 15 10 2 5 7 A A A A A A A A A

The following statements invoke macros for both the master and transaction files. FILE OLDMSTR VS %EMPLIB MSTFILE TRANS %EMPLIB TRNYou can see below what we coded for an earlier program before we set up the macro.

74

DPEC, Inc.

ENHANCING THE PROGRAM--Statements and Macros


FILE OLDMSTR VS %EMPLIB MSTFILE TRANS %EMPLIB TRN The small amount of code on the left produces all the EZT+ statements on the right. FILE OLDMSTR VS MST-EMP-NUM MST-L-NAME MST-F-NAME MST-ADDR-1 MST-ADDR-2 MST-CITY MST-STATE MST-ZIP MST-FILLER-A FILE TRANS TRN-EMP-NUM TRN-L-NAME TRN-F-NAME TRN-ADDR-1 TRN-ADDR-2 TRN-CITY TRN-STATE TRN-ZIP TRN-FILLER-A

D1

1 6 16 26 41 56 66 68 73 1 6 16 26 41 56 66 68 73

5 10 10 15 15 10 2 5 7 5 10 10 15 15 10 2 5 7

A A A A A A A A A A A A A A A A A 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.

DPEC, Inc.

75

D2

ENHANCING THE PROGRAM--File Processing


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 4 16 operation performed successfully end-of-file during a GET 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-nameliteral> <STATUS >

76

DPEC, Inc.

ENHANCING THE PROGRAM--File Processing


Review Points (cont.) 8. Use the WRITE statement to update a VSAM file. WRITE file-name-1 <UPDATEADDDELETE> + <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> DUPLICATEFIRST-DUPLAST-DUP file-name

D2

DPEC, Inc.

77

D2

ENHANCING THE PROGRAM--File Processing


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).

78

DPEC, Inc.

ENHANCING THE PROGRAM--File Processing


FILE INFILE CUST-NAME 1 CUST-NO 36 PRICE-CODE 43 INF-ITEM 44 ITEM-NAME 54 OUT-PRICE W FILE PRICE-FILE-1 PF1-ITEM 1 PF1-PRICE 10 FILE PRICE-FILE-2 PF2-ITEM 1 PF2-PRICE 10

D2

35 7 1 9 40 6 VS 9 6 VS 9 6

A N A N A N N N N N

0 0 2 0 2 0 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.

DPEC, Inc.

79

D2

ENHANCING THE PROGRAM--File Processing


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. 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.

Improper handling of nonzero STATUS conditions.

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

80

DPEC, Inc.

ENHANCING THE PROGRAM--File Processing


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>

D2

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

DPEC, Inc.

81

D2

ENHANCING THE PROGRAM--File Processing


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 L-NAME DEPT NEW-VAC USED-VAC VAC-REMAIN

1 9 19 24 26 28

8 10 5 2 2 2

A A A N 0 N 0 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.

82

DPEC, Inc.

ENHANCING THE PROGRAM--File Processing


FILE TESTDATA CARD SSNUM-TST 1 9 N FILE MASTER VS SSNUM 1 9 N L-NAME 18 10 N USED-SICK 69 2 N 0 USED-VAC 73 2 N 0 JOB INPUT TESTDATA NAME MYTEST READ MASTER KEY SSNUM-TST STATUS IF FILE-STATUS = 0 PRINT DAYS-USED ELSE PERFORM ABEND. PROC REPORT DAYS-USED ... ABEND. PROC ... END 345235678 143576987 543769504

D2

Note that an END statement must be coded between the EZT+ statements and the card data. This example actually involves both sequential and random processing, so let's consider VSAM files next.

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.

DPEC, Inc.

83

D2

ENHANCING THE PROGRAM--File Processing


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 4 16 operation performed successfully end-of-file during a GET record not found during a READ If the value of FILE-STATUS is anything but 0, EASYTRIEVE will perform an error routine called ABEND. This program demonstrates how to check for valid input and specify an error routine if the data is not valid. Let's look at two more statements used to control random processing.

FILE TESTDATA CARD SSNUM-TST 1 9 N FILE MASTER VS SSNUM 1 9 N L-NAME 18 10 N USED-SICK 69 2 N 0 USED-VAC 73 2 N 0 JOB INPUT TESTDATA NAME MYTEST READ MASTER KEY SSNUM-TST STATUS IF FILE-STATUS = 0 PRINT DAYS-USED ELSE PERFORM ABEND. PROC REPORT DAYS-USED ... ABEND. PROC ... 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-nameliteral> <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.

84

DPEC, Inc.

ENHANCING THE PROGRAM--File Processing


Use the WRITE statement to update a VSAM file. Syntax: WRITE file-name-1 <UPDATEADDDELETE> + <FROM file-name-2> STATUS

D2

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

DPEC, Inc.

85

D2

ENHANCING THE PROGRAM--File Processing


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.

86

DPEC, Inc.

ENHANCING THE PROGRAM--File Processing


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

D2

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 BARTH CARLSON CARNAGEY FERNANDEZ FREY KY STUBENRAUCH TRIEU SUE DAVE BOB EVETTE RICH TANYA DUANE JASON 0896 0696 0796 0197 0396 0297 0696 0197 AFTER UPDATE BARTH CARLSON CARNAGEY DUGAS FERNANDEZ FREY KY SMITH STUBENRAUCH TRIEU SUE DAVE BOB WENDY EVETTE RICH TANYA DON DUANE JASON 0697 0697 0697 0697 0697 0697 0697 0697 0697 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 FOR JUNE PRIOR REVIEW DATE 8/96 6/96 7/96 1/97 3/96 2/97 6/96 1/97 PAGE 1

LAST NAME BARTH CARLSON CARNAGEY DUGAS FERNANDEZ FREY KY SMITH STUBENRAUCH TRIEU

FIRST NAME SUE DAVE BOB WENDY EVETTE RICH TANYA DON DUANE JASON

DPEC, Inc.

87

D2

ENHANCING THE PROGRAM--File Processing


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. end-of-file on all files.

Processing continues until EASYTRIEVE encounters

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

88

DPEC, Inc.

ENHANCING THE PROGRAM--File Processing


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

D2

DPEC, Inc.

89

D2

ENHANCING THE PROGRAM--File Processing


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> DUPLICATEFIRST-DUPLAST-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.

90

DPEC, Inc.

ENHANCING THE PROGRAM--File Processing


FILE OLDMSTR MST-RECORD 1 MST-EMP-NUM 1 MST-L-NAME 6 MST-F-NAME 16 MST-ADDR-1 26 MST-ADDR-2 41 MST-CITY 56 MST-STATE 66 MST-ZIP 68 MST-OT-HRS 73 FILE TRANS TRN-EMP-NUM 1 TRN-OT-HRS 6 FILE NEWMSTR FB(0,0) NEW-RECORD 1

D2

80 5 10 10 15 15 10 2 5 8 5 8 80

A A A A A A A A A N 0 A N 0 A

Once again, there are three files defined. TRANS can contain one or more records with the same employee number.

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

DPEC, Inc.

91

You might also like