Showing posts with label mainframe reporting. Show all posts
Showing posts with label mainframe reporting. Show all posts

Sunday, 4 August 2013

Easytrieve Macro Sample Program: Parameters, % Invocation, and Report Example

An Easytrieve report program often repeats the same control break, title, and line layout in more than one job. A macro lets you keep that repeated code in one place and pass values into it when the program is compiled. The sample below shows a small report macro that accepts a control field and builds a report around it.

Easytrieve macro sample diagram showing MACRO parameters and percent invocation
Macro code expands first.

What is an Easytrieve macro?

An Easytrieve macro is reusable source code. You define the macro once, usually in a shared macro library, and invoke it from a program with a percent sign. Broadcom notes that macros are invoked with %macroname, not with the Easytrieve CALL statement.

%CNTLRPT REGION 516

The macro is expanded before the report runs. That is why a macro is useful for repeated source patterns, such as standard file layouts, common report sections, date handling, or site-approved control-break layouts.

Macro sample: control report

This sample macro is named CNTLRPT. It accepts a control field, a starting value, an optional range word, and a high value. The ampersand prefix marks values that Easytrieve substitutes from the macro invocation.

MACRO 2 CNTL-FLD VALUE RANGE ' ' HIGH-VALUE ' '
*
IF &CNTL-FLD = &VALUE &RANGE &HIGH-VALUE
    PRINT RPT1
END-IF
*
REPORT RPT1
    SEQUENCE &CNTL-FLD NAME
    CONTROL  &CNTL-FLD NEWPAGE
    TITLE 1 'CONTROL REPORT BY &CNTL-FLD'
    LINE 1  &CNTL-FLD NAME GROSS-PAY NET-PAY

The first two values are positional in this example. CNTL-FLD receives the field name, and VALUE receives the comparison value. RANGE and HIGH-VALUE have default blank values, so the same macro can support an exact match or a range check.

Invoke the macro for one value

The simplest invocation prints a report when REGION equals 516. The source stays short, and the repeated report code remains in the macro member.

%PAYLIB
JOB INPUT PAYFILE NAME REGPROG

%CNTLRPT REGION 516

Invoke the macro for a range

If the macro supports a range, pass the range word and the high value. The expanded condition behaves like a normal Easytrieve condition after substitution.

%PAYLIB
JOB INPUT PAYFILE NAME REGPROG

%CNTLRPT REGION 516 RANGE THRU HIGH-VALUE 520

Keep range examples easy to read. A future support analyst should be able to tell whether the report is selecting one region, a range of regions, or a list handled by a different macro.

Parameter substitution rules to remember

Item Rule Example
Macro invocation Use percent sign before the macro name. %CNTLRPT REGION 516
Parameter reference Use ampersand before the parameter name inside the macro body. &CNTL-FLD
Default value Provide a default when a parameter can be omitted. RANGE ' '
Readable naming Use names that show intent. HIGH-VALUE

Where the macro library is found

At many sites, Easytrieve macro members are stored in a PDS or managed source library. Broadcom notes that the DD name can be controlled by the MACDDN option, with PANDD commonly used as the default. If a job cannot find a macro, check the macro library DD before changing the source.

//PANDD    DD DISP=SHR,DSN=PROD.EASYTRIEVE.MACLIB
//SYSIN    DD *
%CNTLRPT REGION 516

Common mistakes

Trying to CALL a macro

An Easytrieve macro is not invoked with CALL. Use %MACRONAME. The CALL statement is for invoking external programs, such as COBOL or assembler routines.

Putting ampersands in the wrong place

Use the ampersand before parameter names in the macro body. Broadcom also notes that a literal ampersand inside a macro may need special handling, so avoid clever parameter names and test expansion output when changing shared macros.

Changing a shared macro without impact review

One macro can be used by many jobs. Before editing a shared macro member, search for every program that invokes it and confirm the parameter order still matches.

Review checklist

  • Confirm the macro member name and library DD, such as PANDD.
  • Check whether the macro uses positional parameters, keyword parameters, or both.
  • Confirm every & parameter in the body is declared on the macro prototype.
  • Keep the invocation readable, especially when more than two values are passed.
  • Compile a test job and review the expanded source or compiler messages.
  • Search for other programs that invoke the same macro before changing it.

Related Mainframe Forum guides

For nearby Easytrieve topics, read Easytrieve Macros, Creating Easytrieve Macros, Easytrieve Library, Easytrieve Basic Reporting, Easytrieve Program Structure, and Easytrieve Report Calculation.

External references

Broadcom provides related support notes on how to invoke Easytrieve macros, ampersand references in macro definitions, and coding the PANDD macro library DD.

FAQ

How do you invoke an Easytrieve macro?

Invoke an Easytrieve macro with a percent sign followed by the macro name, such as %CNTLRPT REGION 516.

What does the ampersand mean in an Easytrieve macro?

The ampersand marks a parameter substitution reference inside the macro body, such as &CNTL-FLD.

Is an Easytrieve macro the same as CALL?

No. A macro expands source code before execution. CALL invokes an external program.

What should I check when Easytrieve cannot find a macro?

Check the macro name, macro library DD, MACDDN option, and whether the JCL points to the correct macro library.

Monday, 29 July 2013

Easytrieve Report Calculation: Arithmetic, Totals, and SUM

An Easytrieve report often starts with fields from an input file, then adds one or two calculated values before printing the line. A payroll report may read GROSS, subtract tax and deductions, print NET-PAY, and then total the amount by department. The calculation is small, but a wrong decimal position or missing parenthesis can make every report line wrong.

Easytrieve report calculation diagram showing input fields, work calculation, report line, CONTROL, and SUM totals
Calculate, print, total.

What Easytrieve report calculation means

Easytrieve lets you calculate values in the JOB activity and print them in a report. The common pattern is simple: define input fields, define working fields, calculate the working fields, then print them through a LINE statement.

Report totals are a separate feature. Easytrieve can total quantitative fields on control reports, and the SUM statement can limit which fields are totaled. Broadcom also documents TALLY as a count field available in report output and summary files.

Arithmetic operators

Easytrieve arithmetic uses the standard operators for multiplication, division, addition, and subtraction. Code spaces around the operators so the statement remains readable in listings and reviews.

Operator Meaning Example
* Multiplication NET = HOURS * RATE
/ Division AVG = TOTAL / COUNT
+ Addition TOTAL = BASE + BONUS
- Subtraction NET = GROSS - TAX

Order of calculation

Multiplication and division are evaluated before addition and subtraction. When the intended order is not obvious, use parentheses. Parentheses also help the next developer see the business rule without doing mental arithmetic.

RESULT = GROSS - AMT * 1.3

* Same as:
RESULT = GROSS - (AMT * 1.3)

* Different from:
RESULT = (GROSS - AMT) * 1.3

For finance reports, do not rely on readers knowing the default order. Code the parentheses that match the rule from the specification.

Define working fields for calculated values

Use working fields for values that do not come directly from the input record. Give the field a clear length, type, and decimal count. In old Easytrieve jobs, many report errors come from a receiving field that is too small or has the wrong decimal places.

FILE PERSNL FB(150 1800)
     DEPT        1   3 N
     EMPNO       9   5 N
     GROSS      94   4 P 2
     TAX        98   4 P 2

NET-PAY          W   6 P 2

The example defines NET-PAY as a working field with two decimal places. That makes it suitable for a payroll-style calculated amount.

Simple calculation example

This small report calculates net pay for each input record and prints the department, employee number, gross pay, tax, and net pay.

JOB INPUT PERSNL NAME PAY-RPT
    NET-PAY = GROSS - TAX
    PRINT PAYRPT

REPORT PAYRPT
    TITLE 1 'PAY CALCULATION REPORT'
    LINE DEPT EMPNO GROSS TAX NET-PAY

Keep calculations close to the PRINT statement when possible. That makes it easier to prove which value was printed on the report line.

Rounding calculated values

The original post mentioned a rounding factor. A common Easytrieve technique is to add a value such as .005 before assigning to a field with two decimal places. That rounds a positive amount to cents.

NET-PAY = (GROSS - TAX) + .005

Use this carefully. Confirm the rule for negative values, credits, and site-specific finance standards before applying the same rounding pattern to every amount.

Report totals with CONTROL and SUM

For control reports, Easytrieve can print totals when a control field changes. Broadcom guidance for subtotals uses SEQUENCE followed by CONTROL. Broadcom also documents that SUM can select which quantitative fields are totaled instead of totaling every eligible field on the report line.

REPORT PAYRPT
    SEQUENCE DEPT
    CONTROL DEPT
    SUM GROSS TAX NET-PAY
    TITLE 1 'PAY TOTALS BY DEPARTMENT'
    LINE DEPT EMPNO GROSS TAX NET-PAY

Use SUM when the report line contains numeric fields that should not be totaled, such as employee number, region code, or account code.

Using TALLY for counts

TALLY is useful when the report needs a count as well as an amount. For example, a department control report can show how many employee records were read for each department and the total net pay for that department.

REPORT PAYRPT SUMMARY
    SEQUENCE DEPT
    CONTROL DEPT
    SUM NET-PAY
    HEADING TALLY 'COUNT'
    LINE DEPT TALLY NET-PAY

This separates count from amount. Do not use an employee number or a code field as a pretend count.

Common mistakes

Forgetting decimal places

If NET-PAY is defined with no decimal places, cents can be lost or rounded in a way the report owner did not expect. Match the working field to the business value.

Totaling identifier fields

Numeric codes are not always amounts. Use SUM to keep Easytrieve from totaling fields such as employee number, department number, or account code.

Hiding calculation rules

A report line that prints NET-PAY should make the calculation visible in the job activity. Avoid spreading the same calculation across many unrelated statements.

Review checklist

  • Check every calculated field length, type, and decimal count.
  • Use parentheses where the rule has more than one operator.
  • Keep calculated work fields near the report that prints them.
  • Use SUM to total only real amount or quantity fields.
  • Use TALLY for counts instead of totaling an identifier.
  • Compare a few report lines with hand-calculated values before promotion.

Related Mainframe Forum guides

For nearby topics, read Easytrieve Basic Reporting, Easytrieve Basic Report Field Definition, Easytrieve Basic Report Edit Field Definition, Easytrieve Basic Conditions, Easytrieve Sorting, and Easytrieve VSAM File Handling.

External references

Broadcom documents subtotals and grand totals, SUMFILE fields, and HEADING usage in report definitions.

FAQ

How do I calculate a field in Easytrieve?

Define a working field, assign it in the JOB activity, and include it on the report LINE statement.

Does Easytrieve follow normal arithmetic order?

Yes. Multiplication and division are evaluated before addition and subtraction. Use parentheses when the report rule needs a different order.

How do I print subtotals in Easytrieve?

Use SEQUENCE and CONTROL for a control report. Add SUM when only selected quantitative fields should be totaled.

What is TALLY used for?

TALLY is used as a count field in reports and summary output. It is useful when the report needs record counts by control break.

Easytrieve VSAM File Handling: FILE, PUT, STATUS, and FILE-STATUS

An Easytrieve job that loads a VSAM file needs three things to be readable in production: a clear FILE definition, one obvious PUT path, and a status check after the write. If the program only says PUT OUTMAST FROM MASTER and never checks the result, a duplicate key or allocation problem can hide until the next batch step fails.

Easytrieve VSAM file handling diagram showing input file, job processing, VSAM output, and FILE-STATUS checking
Check status after each write.

What this Easytrieve file handling example covers

The original post showed a short VSAM loading example. This refreshed version keeps that search intent and expands it into a practical guide for FILE, PUT, STATUS, and FILE-STATUS. It is not a full Easytrieve course; it is a focused checklist for creating or loading a VSAM output file safely.

Easytrieve FILE statement role

The FILE statement describes an input or output file to Easytrieve. For a sequential input file, the statement gives the record format and length. For a VSAM output file, it identifies the file as VSAM and can include file handling options such as CREATE and RESET, depending on site standards and the target file.

FILE MASTER FB(150 1800)
EMPNO 9 5 N
NAME 17 16 A
GROSS 94 4 P 2
FILE OUTMAST VS(CREATE RESET)

The input definition tells Easytrieve where fields live in the record. The output definition tells Easytrieve that OUTMAST is the VSAM target. Your JCL still needs the correct DD names and data set allocation rules for the environment.

PUT statement for VSAM output

PUT writes an output record. In a load job, a common pattern is to read each input record, build or reuse an output record layout, write it to the VSAM file, and immediately test the status.

JOB INPUT MASTER NAME LOAD-VSAM
PUT OUTMAST FROM MASTER STATUS
IF OUTMAST:FILE-STATUS NE 0
DISPLAY 'VSAM LOAD ERROR. STATUS: ' +
OUTMAST:FILE-STATUS
STOP
END-IF
PRINT RPT1

The sample uses STATUS so the program can test the result of the VSAM I/O operation. Do not let a file load continue blindly after a failed write.

What FILE-STATUS tells you

FILE-STATUS is a system-defined status field associated with the file. After a VSAM operation, test it before assuming the record was written. A zero status normally means the operation completed successfully. Non-zero status needs handling, logging, or a controlled stop.

Check Why it matters
OUTMAST:FILE-STATUS = 0 The write completed successfully and the job can continue.
OUTMAST:FILE-STATUS NE 0 The program should display or report the status and stop or route the record to error handling.
Status not checked The next step may fail with poor evidence, making production support slower.

Complete Easytrieve VSAM load example

This example keeps the program small. It reads MASTER, writes the record to OUTMAST, checks status, and prints a simple report line.

FILE MASTER FB(150 1800)
EMPNO 9 5 N
NAME 17 16 A
GROSS 94 4 P 2
FILE OUTMAST VS(CREATE RESET)
JOB INPUT MASTER NAME LOAD-VSAM
PUT OUTMAST FROM MASTER STATUS
IF OUTMAST:FILE-STATUS NE 0
DISPLAY 'LOAD ERROR. FILE STATUS: ' +
OUTMAST:FILE-STATUS
STOP
END-IF
PRINT RPT1
REPORT RPT1
LINE 1 EMPNO NAME GROSS

Use the exact file names, field names, and VSAM options used at your site. The pattern is more important than the sample names: define, write, check, report.

CREATE and RESET in a load job

CREATE and RESET are often seen in examples that load or recreate output. Before using them, confirm whether the VSAM cluster is newly allocated, reusable, or managed by a delete/define step in JCL. A production load should not accidentally replace a file that another application expects to keep.

If the cluster is created with IDCAMS before the Easytrieve step, keep the JCL and Easytrieve file options consistent. For VSAM definition examples, see the Mainframe Forum DEFINE CLUSTER guide.

Empty input and empty output handling

An empty input file should still produce predictable job behavior. Broadcom notes that automatic input processing can handle open, end-of-file, and read logic for the input activity. For output-only or empty-output cases, the file may need an explicit CLOSE pattern depending on platform and file definition.

JOB INPUT NULL NAME CLOSE-OUTPUT
CLOSE OUTMAST
STOP

Do not rely on accidental file creation behavior. If an empty output file must exist for the next job step, test that case in lower environments.

Report work files and large reports

File handling also matters when Easytrieve creates large reports. Broadcom documents REPORT work files for large sequenced or multiple reports. Those work files are separate from ordinary input and output business files. If a report step spills to work files, make sure the JCL or site options provide enough space.

Common mistakes

Skipping STATUS on the PUT

A failed VSAM write should be visible in the same step. Use STATUS and test file-name:FILE-STATUS after the operation.

Using unclear file names

Names such as INFILE and OUTFILE are fine in a small example, but production jobs are easier to support when names show business meaning: CUSTIN, PAYMST, or ERRRPT.

Not testing duplicate-key cases

A VSAM load can fail because the target key already exists or the file definition is wrong. Test duplicate, missing, and maximum-value records before moving the job to production.

Quick checklist before running the job

  • Confirm the input DD name matches the Easytrieve FILE name.
  • Confirm the VSAM output file exists or is created by the planned step.
  • Check record length and field positions before the first load run.
  • Use STATUS on the write and test FILE-STATUS.
  • Keep a report or display message that shows the failing status value.
  • Test empty input, duplicate key, and normal load paths.

Related Mainframe Forum guides

For the surrounding topics, read Easytrieve introduction, Easytrieve program structure, Easytrieve basic reporting, VSAM IDCAMS guide, and JCL DD statement examples.

External references

Broadcom support notes describe Easytrieve FILE statement and empty output handling, REPORT work files, and Virtual File Manager usage.

FAQ

How do you write to a VSAM file in Easytrieve?

Define the VSAM output with a FILE statement, write records with PUT, use STATUS, and test file-name:FILE-STATUS after the write.

What does FILE-STATUS mean in Easytrieve?

FILE-STATUS is the status value returned for a file operation. A zero value normally means success; a non-zero value should be handled or reported.

Should an Easytrieve load job use CREATE RESET?

Use CREATE or RESET only when it matches the site file handling standard and the VSAM cluster lifecycle. Confirm this before replacing production data.

What should I test before a VSAM load job goes live?

Test normal records, empty input, duplicate keys, bad field positions, and non-zero file status handling.

New In-feed ads