000100 Identification Division. 000200 Program-ID. VIDEOSR2. 000300 000400 Environment Division. 000500 Configuration Section. 000600 Special-Names. 000700 Decimal-Point is Comma. 000800 000900 Input-Output Section. 001000 File-Control. 001100 001200 Select Video-Titles-File Assign to VIDETIT 001300 Organization is Indexed 001400* File Status is VTF-Status 001500 Access Mode is Dynamic 001600 Record Key is VTF-Video-Code 001700 Alternate Record key is VTF-Supplier-code 001800 with Duplicates 001900 . 002000 Select Video-Rentals-File Assign to VIDEREN 002100 Organization is Indexed 002200 File Status is VRF-Status 002300 Access Mode is Dynamic 002400 Record Key is VRF-Video-Num 002500 Alternate Record Key is VRF-Video-Code 002600 with Duplicates 002700 . 002800 002900 Select Video-Supplier-File Assign to VIDESUP 003000 Organization is Relative 003100* File Status is VSF-Status 003200 Access Mode is Random 003300 Relative Key is Supplier-Key 003400 . 003500 003600 Select Video-Report-File Assign to VIDERPT 003700 . 003800 Data Division. 003900 File Section. 004000 004100 FD Video-Titles-File. 004200 01 VTF-Record. 004300 05 VTF-Video-Code Pic X(05). 004400 05 VTF-Video-Title Pic X(30). 004500 05 VTF-Supplier-Code Pic X(02). 004600 05 Pic X(43). 004700 004800 FD Video-Rentals-File. 004900 01 VRF-Record. 005000 05 VRF-Video-Num Pic X(05). 005100 05 VRF-Video-Code Pic X(05). 005200 05 VRF-Rental-Earnings Pic 9(04)V99. 005300 05 VRF-Purchase-Earnings Pic 9(03)V99. 005400 05 Pic X(59). 005500 005600 FD Video-Supplier-File. 005700 01 VSF-Record. 005800 05 VSF-Supplier-Code Pic X(02). 005900 05 VSF-Supplier-Name Pic X(20). 006000 05 VSF-Supplier-Address Pic X(58). 006100 006200 FD Video-Report-File. 006300 01 VRF-Print-Line Pic X(80). 006400 006500 006600 Working-Storage Section. 006700 01 File-Status-Fields. 006800 05 VRF-Status Pic X(02). 006900 05 VTF-Status Pic X(02). 007000 05 VSF-Status Pic X(02). 007100 007200 01 End-Of-File-Flags. 007300 05 Filler Pic 9(01) Value 0. 007400 88 VTF-EOF Value 1. 007500 05 Filler Pic 9(01) Value 0. 007600 88 Not-VRF-EOF Value 0. 007700 88 VRF-EOF Value 1. 007800 007900 01 Top-Suppliers. 008000 05 Top-Supplier Occurs 4 Times. 008100 10 Top-Supp-Code Pic 9(02). 008200 10 Top-Supp-Earnings Pic 9(06)V99. 008300 10 Top-Video-Code Pic 9(05). 008400 10 Top-Video-Title Pic X(30). 008500 10 Top-Video-Earnings Pic 9(04)V99. 008600 008700 01 Hold-Supp-Rec. 008800 05 Hold-Supp-Code Pic 9(02) Value 0. 008900 05 Hold-Supp-Earnings Pic 9(06)V99 Value 0. 009000 05 Hold-Video-Code Pic 9(05) Value 0. 009100 05 Hold-Video-Title Pic X(30). 009200 05 Hold-Video-Earnings Pic 9(04)V99 Value 0. 009300 009400 01 Counters. 009500 05 Total-Video-Earnings Pic 9(05)V99. 009600 05 Average-Video-Earnings Pic 9(04)V99. 009700 05 Video-Count Pic 9(03) Value 0. 009800 05 Supp-Rank Pic 9(01). 009900 05 Supplier-Key Pic 9(02) Value 0. 010000 05 Filler Pic 9(01). 010100 88 Continue-Checking Value 0. 010200 88 Stop-Checking Value 1. 010300 010400 01 Report-Heading1. 010500 05 Pic X(20) Value Space. 010600 05 Pic X(25) Value 'Top 3 Suppliers Report'. 010700 010800 01 Report-Heading2. 010900 05 Pic X(20) Value Space. 011000 05 Pic X(23) Value All '-'. 011100 011200 01 Report-Trailer. 011300 05 Pic X(20) Value Space. 011400 05 Pic X(25) Value '*** End of Report ***'. 011500 011600 01 Detail-Heading1. 011700 05 Pic X(20) Value 'Supplier'. 011800 05 Pic X(10) Value 'Total'. 011900 05 Pic X(05) Value Space. 012000 05 Pic X(30) Value 'Best'. 012100 05 Pic X(15) Value 'Average'. 012200 012300 01 Detail-Heading2. 012400 05 Pic X(20) Value 'Name'. 012500 05 Pic X(10) Value 'Earnings'. 012600 05 Pic X(05) Value Space. 012700 05 Pic X(30) Value 'Video Title'. 012800 05 Pic X(15) Value 'Earnings'. 012900 013000 01 Detail-Print-Line. 013100 05 DPR-Supp-Name Pic X(20). 013200 05 DPR-Supp-Earnings Pic Z(02).9(03),99. 013300 05 Pic X(06) Value Space. 013400 05 DPR-Video-Title Pic X(30). 013500 05 DPR-Video-Earnings Pic Z.9(03),99. 013600 013700 Procedure Division. 013800 Perform Open-All-Files 013900 Move Zeros to VTF-Supplier-Code 014000 Start Video-Titles-File 014100 Key Is Greater Than VTF-Supplier-Code 014200 Invalid Key 014300 Display 'Error on START VTF, status: ' VTF-Status 014400 Move 99 to Return-Code 014500 GoBack 014600 Not Invalid Key 014700 Read Video-Titles-File NEXT Record 014800 At End 014900 Set VTF-EOF to True 015000 Not At End 015100 Perform Read-Video-Rentals-File 015200 Until VTF-EOF 015300 End-Read 015400 End-Start 015500 015600 Perform Print-Headings 015700 Perform Print-Details 015800 Perform Print-Trailer 015900 016000 GoBack 016100 . 016200 016300 Read-Video-Rentals-File. 016400 Move VTF-Supplier-Code to Hold-Supp-Code 016500 Move VTF-Video-Code to VRF-Video-Code, Hold-Video-Code 016600 Move Zero to Total-Video-Earnings 016700 016800 Read Video-Rentals-File Key is VRF-Video-Code 016900 Invalid Key 017000 Display '*** No Rentals for: ' VTF-Video-Code 017100 Not Invalid Key 017200 Add 1 to Video-Count 017300 Add VRF-Rental-Earnings to 017400 Total-Video-Earnings 017500 End-Read 017600 Set Not-VRF-EOF to True 017700 017800 Perform Until VRF-Video-Code Not Equal VTF-Video-Code 017900 Or VRF-EOF 018000 Read Video-Rentals-File Next Record 018100 At End 018200 Set VRF-EOF to True 018300 Not AT End 018400 If VRF-Video-Code = VTF-Video-Code 018500 Add 1 to Video-Count 018600 Add VRF-Rental-Earnings to 018700 Total-Video-Earnings 018800 End-If 018900 End-Read 019000 End-Perform 019100 019200 Perform Sum-Title-Earnings 019300 019400 Read Video-Titles-File Next Record 019500 At End 019600 Set VTF-EOF to True 019700 Perform Sum-Supplier-Earnings 019800 Not At End 019900 If VTF-Supplier-Code Not Equal Hold-Supp-Code 020000 Perform Sum-Supplier-Earnings 020100 Move VTF-Supplier-Code to Hold-Supp-Code 020200 End-If 020300 End-Read 020400 . 020500 Sum-Title-Earnings. 020600 Divide Total-Video-Earnings by Video-Count 020700 Giving Average-Video-Earnings 020800 If Average-Video-Earnings Greater Than 020900 Hold-Video-Earnings 021000 Move Average-Video-Earnings to Hold-Video-Earnings 021100 Move VTF-Video-Title to Hold-Video-Title 021200 Move VTF-Video-Code to Hold-Video-Code 021300 End-If 021400 021500 Add Total-Video-Earnings to Hold-Supp-Earnings 021600 Move Zero to Total-Video-Earnings 021700 Move Zero to Video-Count 021800 . 021900 Sum-Supplier-Earnings. 022000 Set Continue-Checking to True 022100 Perform Varying Supp-Rank from 3 by -1 022200 Until Supp-Rank = 0 Or Stop-Checking 022300 If Hold-Supp-Earnings is Greater Than 022400 Top-Supp-Earnings(Supp-Rank) 022500 Move Top-Supplier(Supp-Rank) to 022600 Top-Supplier(Supp-Rank + 1) 022700 Move Hold-Supp-Rec to Top-Supplier(Supp-Rank) 022800 Else 022900 Set Stop-Checking to True 023000 End-IF 023100 End-Perform 023200 Move Zero to Hold-Supp-Rec 023300 . 023400 Print-Headings. 023500 Write VRF-Print-Line from Report-Heading1 023600 Write VRF-Print-Line from Report-Heading2 023700 Move Space to VRF-Print-Line 023800 Write VRF-Print-Line 023900 Write VRF-Print-Line from Detail-Heading1 024000 Write VRF-Print-Line from Detail-Heading2 024100 Move Space to VRF-Print-Line 024200 Write VRF-Print-Line 024300 . 024400 Print-Details. 024500 Perform Varying Supp-Rank from 1 by 1 024600 Until Supp-Rank > 3 024700 Move Top-Supp-Code(Supp-Rank) to Supplier-Key 024800 Read Video-Supplier-File 024900 Invalid Key 025000 Move 'N/A' to DPR-Supp-Name 025100 Not Invalid Key 025200 Move VSF-Supplier-Name to DPR-Supp-Name 025300 End-Read 025400 025500 Move Top-Supp-Earnings(Supp-Rank) to DPR-Supp-Earnings 025600 Move Top-Video-Title(Supp-Rank) to DPR-Video-Title 025700 Move Top-Video-Earnings(Supp-Rank) to DPR-Video-Earnings 025800 025900 Write VRF-Print-Line from Detail-Print-Line 026000 Move Space to VRF-Print-Line 026100 Write VRF-Print-Line 026200 End-Perform 026300 . 026400 Print-Trailer. 026500 Move Space to VRF-Print-Line 026600 Write VRF-Print-Line 026700 Write VRF-Print-Line from Report-Trailer 026800 . 026900 Open-All-Files. 027000 Open Input Video-Rentals-File 027100 Open Input Video-Titles-File 027200 Open Input Video-Supplier-File 027300 Open Output Video-Report-File 027400 . 027500 Close-All-Files. 027600 Close Video-Rentals-File, 027700 Video-Titles-File, 027800 Video-Supplier-File, 027900 Video-Report-File 028000 . 028100 End Program VIDEOSR2.