An AFTER-BREAK procedure is invoked following the printing of summary lines for a control break. It can be used to produce special annotation on control reports.
The AFTER-BREAK procedure is invoked once for each level of break. For example, assume two control fields are specified. When the minor field causes a control break, the AFTER-BREAK procedure is invoked only once. When the major field causes a control break, AFTER-BREAK is invoked twice.
The value of LEVEL (a system-defined field) can be used to determine which control break is being processed. TALLY (a system-defined field) contains the number of records in a particular control group.
In the following example, the total line for the control field STATE receives special annotation.
Statements:
FILE FILE1
LAST-NAME 1 5 A
STATE 6 2 A
ZIP 8 5 N
PAY-NET 13 5 N 2
JOB INPUT FILE1 NAME MYPROG
PRINT REPORT1
*
REPORT REPORT1 LINESIZE 65 +
SUMMARY SUMCTL DTLCOPY
SEQUENCE STATE ZIP LAST-NAME
CONTROL STATE ZIP
LINE 01 LAST-NAME STATE ZIP PAY-NET
*
AFTER-BREAK. PROC
IF LEVEL EQ 2
DISPLAY 'END OF DETAILS FOR THE STATE OF ' STATE
END-IF
END-PROC
Data:
BROWNIL6007612345
BROWNIL6007667890
JONESIL6007709876
JONESIL6007754321
SMITHTX7521811111
SMITHTX7521866666
Results:
LAST-NAME STATE ZIP PAY-NET
BROWN IL 60076 802.35
JONES IL 60077 641.97
IL 1444.32
END OF DETAILS FOR THE STATE OF IL
SMITH TX 75218 777.77
TX 777.77
END OF DETAILS FOR THE STATE OF TX
2222.09
Similarly, a BEFORE-BREAK procedure is invoked before printing the summary lines for a control break. For example, it can be used to calculate percentages and average totals. These values must be calculated immediately before printing.
The BEFORE-BREAK procedure too is invoked once for each level of break. For example, assume two control fields are specified. When the minor field causes a control break, the BEFORE-BREAK procedure is invoked only once. When the major field causes a control break, BEFORE-BREAK is invoked twice.
The usage of LEVEL and TALLY too, are the same as in AFTER-BREAK.
Example: Consider the following percentage calculation, paying special attention to when and how PERCENT is calculated:
FILE FILE1 FB(80 8000)
LAST-NAME 1 5 A
STATE 6 2 A
ZIP 8 5 N
PAY-NET 13 5 N 2
*
PERCENT W 2 N 2
TOTAL-NET S 8 N 2
*
JOB INPUT FILE1 NAME MYPROG
*
TOTAL-NET = TOTAL-NET + PAY-NET
PRINT REPORT1
*
REPORT REPORT1 LINESIZE 80 +
SUMMARY SUMCTL DTLCOPY
SEQUENCE STATE ZIP LAST-NAME
CONTROL STATE ZIP
LINE 01 LAST-NAME STATE ZIP PAY-NET PERCENT
*
BEFORE-BREAK. PROC
PERCENT = PAY-NET * 100 / TOTAL-NET
END-PROC
Data:
BROWNIL6007612345
BROWNIL6007667890
JONESIL6007709876
JONESIL6007754321
SMITHTX7521811111
SMITHTX7521866666
Results:
LAST-NAME STATE ZIP PAY-NET PERCENT
BROWN IL 60076 802.35 36.10
JONES IL 60077 641.97 28.89
IL 1444.32 64.99
SMITH TX 75218 777.77 35.00
TX 777.77 35.00
2222.09 100.00
The BEFORE-BREAK procedure computes the percentage for each control break by multiplying the sum of PAY-NET by 100 and then dividing by TOTAL-NET.
Note: TOTAL-NET is a static (S) working storage field summed in the JOB activity processing.
The AFTER-BREAK procedure is invoked once for each level of break. For example, assume two control fields are specified. When the minor field causes a control break, the AFTER-BREAK procedure is invoked only once. When the major field causes a control break, AFTER-BREAK is invoked twice.
The value of LEVEL (a system-defined field) can be used to determine which control break is being processed. TALLY (a system-defined field) contains the number of records in a particular control group.
In the following example, the total line for the control field STATE receives special annotation.
Statements:
FILE FILE1
LAST-NAME 1 5 A
STATE 6 2 A
ZIP 8 5 N
PAY-NET 13 5 N 2
JOB INPUT FILE1 NAME MYPROG
PRINT REPORT1
*
REPORT REPORT1 LINESIZE 65 +
SUMMARY SUMCTL DTLCOPY
SEQUENCE STATE ZIP LAST-NAME
CONTROL STATE ZIP
LINE 01 LAST-NAME STATE ZIP PAY-NET
*
AFTER-BREAK. PROC
IF LEVEL EQ 2
DISPLAY 'END OF DETAILS FOR THE STATE OF ' STATE
END-IF
END-PROC
Data:
BROWNIL6007612345
BROWNIL6007667890
JONESIL6007709876
JONESIL6007754321
SMITHTX7521811111
SMITHTX7521866666
Results:
LAST-NAME STATE ZIP PAY-NET
BROWN IL 60076 802.35
JONES IL 60077 641.97
IL 1444.32
END OF DETAILS FOR THE STATE OF IL
SMITH TX 75218 777.77
TX 777.77
END OF DETAILS FOR THE STATE OF TX
2222.09
Similarly, a BEFORE-BREAK procedure is invoked before printing the summary lines for a control break. For example, it can be used to calculate percentages and average totals. These values must be calculated immediately before printing.
The BEFORE-BREAK procedure too is invoked once for each level of break. For example, assume two control fields are specified. When the minor field causes a control break, the BEFORE-BREAK procedure is invoked only once. When the major field causes a control break, BEFORE-BREAK is invoked twice.
The usage of LEVEL and TALLY too, are the same as in AFTER-BREAK.
Example: Consider the following percentage calculation, paying special attention to when and how PERCENT is calculated:
FILE FILE1 FB(80 8000)
LAST-NAME 1 5 A
STATE 6 2 A
ZIP 8 5 N
PAY-NET 13 5 N 2
*
PERCENT W 2 N 2
TOTAL-NET S 8 N 2
*
JOB INPUT FILE1 NAME MYPROG
*
TOTAL-NET = TOTAL-NET + PAY-NET
PRINT REPORT1
*
REPORT REPORT1 LINESIZE 80 +
SUMMARY SUMCTL DTLCOPY
SEQUENCE STATE ZIP LAST-NAME
CONTROL STATE ZIP
LINE 01 LAST-NAME STATE ZIP PAY-NET PERCENT
*
BEFORE-BREAK. PROC
PERCENT = PAY-NET * 100 / TOTAL-NET
END-PROC
Data:
BROWNIL6007612345
BROWNIL6007667890
JONESIL6007709876
JONESIL6007754321
SMITHTX7521811111
SMITHTX7521866666
Results:
LAST-NAME STATE ZIP PAY-NET PERCENT
BROWN IL 60076 802.35 36.10
JONES IL 60077 641.97 28.89
IL 1444.32 64.99
SMITH TX 75218 777.77 35.00
TX 777.77 35.00
2222.09 100.00
The BEFORE-BREAK procedure computes the percentage for each control break by multiplying the sum of PAY-NET by 100 and then dividing by TOTAL-NET.
Note: TOTAL-NET is a static (S) working storage field summed in the JOB activity processing.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.