Sort and Merge.  The StudentFile is a sequential file sequenced upon ascending StudentId.  Write a program to display the number of students taking.

Slides:



Advertisements
Similar presentations
DT266/2 Information Systems COBOL Revision. Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment.
Advertisements

2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
Cobol application using ODBC or File processing Vandana Janeja CIS 365 With COBOL OR PowerCobol.
Module 7 Sorting.  The StudentFile is a sequential file sequenced upon ascending StudentId.  How to sort the file by StudentId? DATA DIVISION. FILE.
MVC, Model, View and Controller ISYS 475. The three components in a database application 1. Presentation – user interface Menus, forms, reports, etc 2.
Files  File organisation and usage A record is a group of logically related fields A file is a group of logically related records Files are used to store.
- Kav Shrestha.  Introduction  History  Features  COBOL Usage  Characteristics  Structure of COBOL Programs  COBOL Divisions  Data Items  Variable.
Conditions.. IF Syntax.   Simple Conditions l Relation Conditions l Class Conditions l Sign Conditions   Complex Conditions   Condition Names 
BY: JOSHUA THOMAS IGNATIUS TOWERS COBOL. Overview What is COBOL History Design Implementations What did it do Program structure Data types Syntax Sample.
Chapter 15 Indexed Sequential Files. Disk File Organization File is collection of records Three major ways records stored or organized on disk - Sequential.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
14-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
Structured COBOL Programming, Stern & Stern, 9th Edition
VSAM KSDS and COBOL Department of Computer Science Northern Illinois University August 2005 Some of the illustrations are from VSAM: Access Method Services.
Advanced Sequential Files 1.. Single Record Type Files  In a file which contains only one record type (the kind we have examined so far) the record structure.
Relative Files.. Creating a Relative File $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. CreateRelativeFromSeq. * Creates a Relative file.
Structured COBOL Programming, Stern & Stern, 9th edition
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
4-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Programming in COBOL-85 For IBM Mainframe System 390
4-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
1 Chapter 4. To familiarize you with methods used to 1. Access input and output files 2. Read data from an input file 3. Perform simple move operations.
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
Introduction to COBOL. COBOL  COBOL is an acronym which stands for Common Business Oriented Language.  The name indicates the target area of COBOL applications.
History COBOL (Common Business Oriented Language) was one of the earliest high-level programming languages. COBOL was first proposed in 1959 by the Conference.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Programming in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: Phone:
Totals on the Screen Please use speaker notes for additional information!
1 Chapter 14 - Sorting System Concepts –Sort key Major Key (Primary) Minor Key (Secondary) –Sort sequence Ascending - Low to high Descending – High to.
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
3-1 Chapter 3. To familiarize you with  Ways in which data is organized in COBOL  Rules for forming data-names  Defining input and output files in.
Module 4 Constants Copy Statement Perform Verb Part 1.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File.
COBOL Basics 2. H E N N E S S Y R M L M F Group Items/Records StudentDetails WORKING-STORAGE SECTION. 01StudentDetailsPIC X(26).
14- 1 Chapter 14.  To familiarize you with ◦ How files may be sorted ◦ How to process file during SORT procedure  Before it is sorted  After it is.
Chapter 7 File I/O 1. File, Record & Field 2 The file is just a chunk of disk space set aside for data and given a name. The computer has no idea what.
Indexed and Relative File Processing
1 Chapter – 12 Table Lookups Table Codes –Expanded Values –Types of Codes Numeric Alphabetic Alphanumeric.
COBOL (Common Business Oriented Language). 1. Introduction to COBOL History of COBOL Coding rules Program Structure Data names and Identifiers Figurative.
1 The Procedure Division Chapter 4. 2 Main Two Sections File Section –Used to define files and record formats –Field names within records Working Storage.
Statement Syntax1 THE SELECT STATEMENT Purpose: designates a file and points to its physical location Syntax Definition : SELECT file-name-1 ASSIGN TO.
CPSC3111/CISM3111 COBOL Structured COBOL Programming Text: murach’s structured COBOL Authors: Murach, Prince, Menendez.
9-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
9-1 Iteration: Beyond the Basic PERFORM Chapter 9.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
Opening Input/Output Files void openFiles ( ifstream& infile, ofstream& outfile) { char inFileName[40]; char outFileName[40]; cout
Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.
COBOL Screens Please use speaker notes for additional information!
Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER 2 Cobol Language Fundamentals.
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
One & Two dimensional Tables Cont.. Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
Indexed Files.. Creating an Indexed File $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. CreateIndexedFromSeq. * Creates an indexed file.
Chapter 4 PROCEDURE DIVISION. Paragraphs PROCEDURE DIVISION divided into paragraphs Each is independent module or routine Made up of series of instructions.
Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads.
The PERFORM. The PERFORM Verb  Iteration is an important programming construct. We use iteration when we need to repeat the same instructions over and.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
Introduction to Sequential Files. COBOL's forte  COBOL is generally used in situations where the volume of data to be processed is large.  These systems.
General Introduction Algorithms. Let’s write a program  A program is a collection of statements written in a language the computer understands.  A computer.
Sorting in COBOL M. M. Pickard.
THE SORT STATEMENT for files (chp. 14)
Designing and Debugging Batch and Interactive COBOL Programs
Chapter 3 The DATA DIVISION.
Chapter 14 Sorting and Merging.
Programming in COBOL-85 For IBM Mainframe System 390
Presentation transcript:

Sort and Merge

 The StudentFile is a sequential file sequenced upon ascending StudentId.  Write a program to display the number of students taking each course. How? DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails. 02 StudentId PIC 9(7). 02 StudentName. 03 Surname PIC X(8). 03 Initials PIC XX. 02 DateOfBirth. 03 YOBirth PIC 9(2). 03 MOBirth PIC 9(2). 03 DOBirth PIC 9(2). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X.

Simplified Sort Syntax.  The WorkFileName identifies a temporary work file that the SORT process uses for the sort. It is defined in the FILE SECTION using an SD entry.  Each SortKeyIdentifier identifies a field in the record of the work file upon which the file will be sequenced.  When more than one SortKeyIdentifier is specified, the keys decrease in significance from left to right (leftmost key is most significant, rightmost is least significant).  InFileName and OutFileName, are the names of the input and output files. These files are automatically opened by the SORT. When the SORT executes they must not be already open.

FD SalesFile. 01 SalesRec. 02 FILLERPIC X(10). WorkFile WSalesmanNum SD WorkFile. 01 WorkRec. 02 WSalesmanNumPIC 9(5). 02 FILLER PIC X(5). FD SortedSalesFile. 01 SortedSalesRec. 02 SalesmanNumPIC 9(5). 02 ItemTypePIC X. 02 QtySoldPIC 9(4). WorkFileWSalesmanNum PROCEDURE DIVISION. Begin. SORT WorkFile ON ASCENDING KEY WSalesmanNum USING SalesFile GIVING SortedSalesFile. OPEN INPUT SortedSalesFile. Sort Example.

ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT WorkFile ASSIGN TO "WORK.TMP". SD WorkFile. 01 WorkRecord. 02 ProvinceCode PIC SalesmanCode PIC 9(5). 02 FILLER PIC X(19). PROCEDURE DIVISION. Begin. SORT WorkFile ON ASCENDING KEY ProvinceCode DESCENDING KEY SalesmanCode USING UnsortedSales GIVING SortedSales. OPEN INPUT SortedSales. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT WorkFile ASSIGN TO "WORK.TMP". SD WorkFile. 01 WorkRecord. 02 ProvinceCode PIC SalesmanCode PIC 9(5). 02 FILLER PIC X(19). PROCEDURE DIVISION. Begin. SORT WorkFile ON ASCENDING KEY ProvinceCode DESCENDING KEY SalesmanCode USING UnsortedSales GIVING SortedSales. OPEN INPUT SortedSales.

SORTProcess WorkFile How the SORT works. SORT WorkFile ON ASCENDING KEY WSalesmanNum USING SalesFile GIVING SortedSalesFile. SalesFileSortedSalesFile Unsorted Records Sorted Records

SORTProcess How the INPUT PROCEDURE works. SORT WorkFile ON ASCENDING KEY WSalesmanNum INPUT PROCEDURE IS SelectHatSales GIVING SortedSalesFile. WorkFile SalesFileSortedSalesFile Sorted Records SelectHatSales Unsorted Hat Records Unsorted Records

OPEN INPUT InFileName READ InFileName RECORD PERFORM UNTIL Condition RELEASE SDWorkRec READ InFileName RECORD END-PERFORM CLOSE InFile OPEN INPUT InFileName READ InFileName RECORD PERFORM UNTIL Condition RELEASE SDWorkRec READ InFileName RECORD END-PERFORM CLOSE InFile INPUT PROCEDURE Template

FD SalesFile. 01 SalesRec. 88 EndOfSales VALUE HIGH-VALUES. 02 FILLERPIC 9(5). 02 FILLERPIC X. 88 HatRecord VALUE "H". 02 FILLERPIC X(4). SD WorkFile. 01 WorkRec. 02 WSalesmanNumPIC 9(5). 02 FILLERPIC X(5). FD SortedSalesFile. 01 SortedSalesRec. 02 SalesmanNumPIC 9(5). 02 ItemTypePIC X. 02 QtySoldPIC 9(4). SelectHatSales PROCEDURE DIVISION. Begin. SORT WorkFile ON ASCENDING KEY WSalesmanNum INPUT PROCEDURE IS SelectHatSales GIVING SortedSalesFile. FD SalesFile. 01 SalesRec. 88 EndOfSales VALUE HIGH-VALUES. 02 FILLERPIC 9(5). 02 FILLERPIC X. 88 HatRecord VALUE "H". 02 FILLERPIC X(4). SD WorkFile. 01 WorkRec. 02 WSalesmanNumPIC 9(5). 02 FILLERPIC X(5). FD SortedSalesFile. 01 SortedSalesRec. 02 SalesmanNumPIC 9(5). 02 ItemTypePIC X. 02 QtySoldPIC 9(4). SelectHatSales PROCEDURE DIVISION. Begin. SORT WorkFile ON ASCENDING KEY WSalesmanNum INPUT PROCEDURE IS SelectHatSales GIVING SortedSalesFile. INPUT PROCEDURE - Example

New Version SelectHatSales. OPEN INPUT SalesFile READ SalesFile AT END SET EndOfSales TO TRUE END-READ PERFORM UNTIL EndOfSales IF HatRecord RELEASE WorkRec FROM SalesRec END-IF READ SalesFile AT END SET EndOfSales TO TRUE END-READ END-PERFORM CLOSE SalesFile. SelectHatSales. OPEN INPUT SalesFile READ SalesFile AT END SET EndOfSales TO TRUE END-READ PERFORM UNTIL EndOfSales IF HatRecord RELEASE WorkRec FROM SalesRec END-IF READ SalesFile AT END SET EndOfSales TO TRUE END-READ END-PERFORM CLOSE SalesFile.

Old Version SelectHatSales SECTION. BeginHatSales. OPEN INPUT SalesFile READ SalesFile AT END SET EndOfSales TO TRUE END-READ PERFORM GetHatSales UNTIL EndOfSales CLOSE SalesFile GO TO SelectHatSalesExit. GetHatSales. IF HatRecord RELEASE WorkRec FROM SalesRec END-IF READ SalesFile AT END SET EndOfSales TO TRUE END-READ. SelectHatSalesExit EXIT. SelectHatSales SECTION. BeginHatSales. OPEN INPUT SalesFile READ SalesFile AT END SET EndOfSales TO TRUE END-READ PERFORM GetHatSales UNTIL EndOfSales CLOSE SalesFile GO TO SelectHatSalesExit. GetHatSales. IF HatRecord RELEASE WorkRec FROM SalesRec END-IF READ SalesFile AT END SET EndOfSales TO TRUE END-READ. SelectHatSalesExit EXIT.

ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT WorkFile ASSIGN TO "WORK.TMP". SD WorkFile. 01 WorkRecord. 88 EndOfWorkFile VALUE HIGH-VALUES. 02 ProvinceCode PIC ProvinceIsUlster VALUE SalesmanCode PIC 9(5). 02 FILLER PIC X(19). FD UnsortedSales. 01 FILLER PIC X(25). FD SortedSales. 01 SortedRec. 88 EndOfSalesFile VALUE HIGH-VALUES. 02 ProvinceCode PIC SalesmanCode PIC 9(5). 02 ItemCode PIC 9(7). 02 ItemCost PIC 9(3)V QtySold PIC 9(7). ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT WorkFile ASSIGN TO "WORK.TMP". SD WorkFile. 01 WorkRecord. 88 EndOfWorkFile VALUE HIGH-VALUES. 02 ProvinceCode PIC ProvinceIsUlster VALUE SalesmanCode PIC 9(5). 02 FILLER PIC X(19). FD UnsortedSales. 01 FILLER PIC X(25). FD SortedSales. 01 SortedRec. 88 EndOfSalesFile VALUE HIGH-VALUES. 02 ProvinceCode PIC SalesmanCode PIC 9(5). 02 ItemCode PIC 9(7). 02 ItemCost PIC 9(3)V QtySold PIC 9(7).

PROCEDURE DIVISION. Begin. SORT WorkFile ON ASCENDING KEY ProvinceCode SalesmanCode INPUT PROCEDURE IS SelectUlsterRecs GIVING SortedSales. OPEN INPUT SortedSales. SelectUlsterRecs. OPEN INPUT UnsortedSales READ UnsortedSales INTO WorkRec AT END SET EndOfSalesFile TO TRUE END-READ PERFORM UNTIL EndOfSalesFile IF ProvinceIsUlster RELEASE WorkRec END-IF READ UnsortedSales INTO WorkRec AT END SET EndOfSalesFile TO TRUE END-READ END-PERFORM CLOSE UnsortedSales PROCEDURE DIVISION. Begin. SORT WorkFile ON ASCENDING KEY ProvinceCode SalesmanCode INPUT PROCEDURE IS SelectUlsterRecs GIVING SortedSales. OPEN INPUT SortedSales. SelectUlsterRecs. OPEN INPUT UnsortedSales READ UnsortedSales INTO WorkRec AT END SET EndOfSalesFile TO TRUE END-READ PERFORM UNTIL EndOfSalesFile IF ProvinceIsUlster RELEASE WorkRec END-IF READ UnsortedSales INTO WorkRec AT END SET EndOfSalesFile TO TRUE END-READ END-PERFORM CLOSE UnsortedSales

Full Sort Syntax.  ProcedureName is the name of a section or paragraph.

SummariseSales SORTProcess WorkFile How the OUTPUT PROCEDURE works. SORT WorkFile ON ASCENDING KEY WSalesmanNum USING SalesFile OUTPUT PROCEDURE IS SummariseSales. SalesFile SalesSummaryFile Unsorted Records Salesman Summary Record Sorted Records

OPEN OUTPUT OutFile RETURN SDWorkFile RECORD PERFORM UNTIL Condition WRITE OutRec RETURN SDWorkFile RECORD END-PERFORM CLOSE OutFile OUTPUT PROCEDURE Template

FD SalesFile. 01 SalesRec PIC X(10). SD WorkFile. 01 WorkRec. 88 EndOfWorkFile VALUE HIGH-VALUES. 02 WSalesmanNumPIC 9(5). 02 FILLERPIC X. 02 WQtySold PIC X(4). FD SalesSummaryFile. 01 SummaryRec. 02 SalesmanNumPIC 9(5). 02 TotalQtySoldPIC 9(6). SummariseSales PROCEDURE DIVISION. Begin. SORT WorkFile ON ASCENDING KEY WSalesmanNum USING SalesFile OUTPUT PROCEDURE IS SummariseSales. OPEN INPUT SalesSummaryFile. PERFORM PrintSummaryReport. FD SalesFile. 01 SalesRec PIC X(10). SD WorkFile. 01 WorkRec. 88 EndOfWorkFile VALUE HIGH-VALUES. 02 WSalesmanNumPIC 9(5). 02 FILLERPIC X. 02 WQtySold PIC X(4). FD SalesSummaryFile. 01 SummaryRec. 02 SalesmanNumPIC 9(5). 02 TotalQtySoldPIC 9(6). SummariseSales PROCEDURE DIVISION. Begin. SORT WorkFile ON ASCENDING KEY WSalesmanNum USING SalesFile OUTPUT PROCEDURE IS SummariseSales. OPEN INPUT SalesSummaryFile. PERFORM PrintSummaryReport. Output PROCEDURE - Example

SummariseSales. OPEN OUTPUT SalesSummaryFile RETURN WorkFile AT END SET EndOfWorkFile TO TRUE END-RETURN PERFORM UNTIL EndOfWorkFile MOVE WSalesmanNum TO SalesmanNum MOVE ZEROS TO TotalQtySold PERFORM UNTIL WSalesManNum NOT = SalesmanNum OR EndOfWorkFile ADD WQtySold TO TotalQtySold RETURN WorkFile AT END SET EndOfWorkFile TO TRUE END-RETURN END-PERFORM WRITE SummaryRec END-PERFORM CLOSE SalesSummaryFile. SummariseSales. OPEN OUTPUT SalesSummaryFile RETURN WorkFile AT END SET EndOfWorkFile TO TRUE END-RETURN PERFORM UNTIL EndOfWorkFile MOVE WSalesmanNum TO SalesmanNum MOVE ZEROS TO TotalQtySold PERFORM UNTIL WSalesManNum NOT = SalesmanNum OR EndOfWorkFile ADD WQtySold TO TotalQtySold RETURN WorkFile AT END SET EndOfWorkFile TO TRUE END-RETURN END-PERFORM WRITE SummaryRec END-PERFORM CLOSE SalesSummaryFile.

RELEASE and RETURN Syntax WriteRead

Feeding the SORT from the keyboard. SORT WorkFile ON ASCENDING KEY WStudentId INPUT PROCEDURE IS GetStudentDetails GIVING StudentFile. WorkFile StudentFile Sorted Student Records SORTProcess GetStudentDetails Unsorted Student Records COUGHLAN

ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT StudentFile ASSIGN TO "SORTSTUD.DAT" ORGANIZATION IS LINE SEQUENTIAL. SELECT WorkFile ASSIGN TO "WORK.TMP". DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails PIC X(32). SD WorkFile. 01 WorkRec. 02 WStudentId PIC 9(7). 02 FILLER PIC X(25). PROCEDURE DIVISION. Begin. SORT WorkFile ON ASCENDING KEY WStudentId INPUT PROCEDURE IS GetStudentDetails GIVING StudentFile. STOP RUN. GetStudentDetails. DISPLAY "Enter student details using template below." DISPLAY "Enter no data to end.". DISPLAY "NNNNNNNSSSSSSSSIIYYMMDDCCCCGGGGS". ACCEPT WorkRec. PERFORM UNTIL WorkRec = SPACES RELEASE WorkRec ACCEPT WorkRec END-PERFORM. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT StudentFile ASSIGN TO "SORTSTUD.DAT" ORGANIZATION IS LINE SEQUENTIAL. SELECT WorkFile ASSIGN TO "WORK.TMP". DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentDetails PIC X(32). SD WorkFile. 01 WorkRec. 02 WStudentId PIC 9(7). 02 FILLER PIC X(25). PROCEDURE DIVISION. Begin. SORT WorkFile ON ASCENDING KEY WStudentId INPUT PROCEDURE IS GetStudentDetails GIVING StudentFile. STOP RUN. GetStudentDetails. DISPLAY "Enter student details using template below." DISPLAY "Enter no data to end.". DISPLAY "NNNNNNNSSSSSSSSIIYYMMDDCCCCGGGGS". ACCEPT WorkRec. PERFORM UNTIL WorkRec = SPACES RELEASE WorkRec ACCEPT WorkRec END-PERFORM.

MERGE Syntax.  The Merge takes two or more identically sequenced files and combines them, according to the key values specified, to produce a combined file which is then output to an output file or OUTPUT PROCEDURE.  e.g. MERGE WorkFile ON ASCENDING KEY StudentId USING InsertionsFile, StudentFile GIVING NewStudentFile.

ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT StudentFile ASSIGN TO "STUDENTS.DAT" ORGANIZATION IS LINE SEQUENTIAL. SELECT InsertionsFile ASSIGN TO "TRANSINS.DAT" ORGANIZATION IS LINE SEQUENTIAL. SELECT NewStudentFile ASSIGN TO "STUDENTS.NEW" ORGANIZATION IS LINE SEQUENTIAL. SELECT WorkFile ASSIGN TO "WORK.TMP". DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentRec PIC X(32). FD InsertionsFile. 01 InsertionRec PIC X(32). FD NewStudentFile. 01 NewStudentRec PIC X(32). SD WorkFile. 01 WorkRec. 02 WStudentId PIC 9(7). 02 FILLER PIC X(25). PROCEDURE DIVISION. Begin. MERGE WorkFile ON ASCENDING KEY WStudentId USING InsertionsFile, StudentFile GIVING NewStudentFile. STOP RUN. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT StudentFile ASSIGN TO "STUDENTS.DAT" ORGANIZATION IS LINE SEQUENTIAL. SELECT InsertionsFile ASSIGN TO "TRANSINS.DAT" ORGANIZATION IS LINE SEQUENTIAL. SELECT NewStudentFile ASSIGN TO "STUDENTS.NEW" ORGANIZATION IS LINE SEQUENTIAL. SELECT WorkFile ASSIGN TO "WORK.TMP". DATA DIVISION. FILE SECTION. FD StudentFile. 01 StudentRec PIC X(32). FD InsertionsFile. 01 InsertionRec PIC X(32). FD NewStudentFile. 01 NewStudentRec PIC X(32). SD WorkFile. 01 WorkRec. 02 WStudentId PIC 9(7). 02 FILLER PIC X(25). PROCEDURE DIVISION. Begin. MERGE WorkFile ON ASCENDING KEY WStudentId USING InsertionsFile, StudentFile GIVING NewStudentFile. STOP RUN.