Professional Documents
Culture Documents
Easy Tri Eve
Easy Tri Eve
Easy Tri Eve
Student Guide
EAS101
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
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.
A1
DPEC, Inc.
A1
or spanned) databases)
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.
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
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
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
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.
A1
DPEC, Inc.
A2
with the first non-blank character on the next line. non-blank character of a statement.
uppercase; decimal digits 0 through 9; all special characters except delimiters decimal digit character
DPEC, Inc.
A2
DPEC, Inc.
A2
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.
A2
DPEC, Inc.
A2
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.
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
with the first non-blank character on the next line. non-blank character of a statement. ( (left parenthesis)and : (colon).
DPEC, Inc.
11
A2
decimal digits 0 through 9; all special characters except delimiters decimal digit
must contain at least one alphabetic or special character must be unique within a file
These rules also apply to labels that identify JOBs, procedures, REPORTs and statements. Alphabetic literals (enclosed within single quotes) can contain up to 254 characters. If you need to include a single quote in the literal, code 2 quotes as shown. O'GRADY LEASING becomes 'O''GRADY LEASING'
12
DPEC, Inc.
A2
DPEC, Inc.
13
B1
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
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.
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
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
16
DPEC, Inc.
B1
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
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
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.
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
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
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.
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
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
22
DPEC, Inc.
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
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.
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
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
26
DPEC, Inc.
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
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.
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
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.
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
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.
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:
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
34
DPEC, Inc.
B3
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
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.
B3
DPEC, Inc.
37
B3
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.
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
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.
B3
DPEC, Inc.
41
B3
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
16 21 12 49 151
3 5 4 12 42
13 16 8 37 109
42
DPEC, Inc.
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
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.
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
7/15/99
NEW VACATION TOTALS AFTER BONUS DAYS AWARDED NEW TOTAL VACATION VACATION USED
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.
C1
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
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
48
DPEC, Inc.
C1
DPEC, Inc.
49
C1
6/14/99
DEPARTMENT FIN FIN FIN HRES HRES MNT MNT SALES SALES SYS SYS
50
DPEC, Inc.
C2
report processing
-- 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
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.
C2
DPEC, Inc.
53
C2
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
54
DPEC, Inc.
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
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.
C2
DPEC, Inc.
57
C2
... 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.
C2
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
DPEC, Inc.
59
D1
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.
D1
DPEC, Inc.
61
D1
62
DPEC, Inc.
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
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.
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
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.
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
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.
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
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
-----
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.
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
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
2 1
72
DPEC, Inc.
D1
2 1
MASK '99/99/99' MASK '999-99-9999' MASK '$,$$$,$$9.99' HEADING ('YEARS' 'SERVICE') HEADING 'EMPLOYEE NAME'
2 1
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
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.
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
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.
D2
DPEC, Inc.
77
D2
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.
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
DPEC, Inc.
79
D2
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.
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.
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
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.
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
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.
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
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.
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
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, 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.
D2
DPEC, Inc.
89
D2
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.
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