16- 1 Chapter 16.  To familiarize you with  COPY statement for copying parts of a program stored in a library  CALL statement for executing called.

Slides:



Advertisements
Similar presentations
Structured COBOL Programming
Advertisements

8-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)
16-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)
2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
3-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emertius)
7-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)
The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
CHAPTER 6 FILE PROCESSING. 2 Introduction  The most convenient way to process involving large data sets is to store them into a file for later processing.
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)
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
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.
3-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emertius)
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CNG 140 C Programming (Lecture set 9) Spring Chapter 9 Character Strings.
Input, Output, and Processing
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
The DATA DIVISION Chapter 3. COBOL Data Organization Field - group of characters forming a meaningful unit or basic fact –Characters in a name or digits.
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.
3-1 The DATA DIVISION Chapter Chapter Objectives To familiarize you with Systems design considerations Ways in which data is organized Rules for.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
7-1 Chapter 7.  Basic Arithmetic Verbs  Options Available with Arithmetic Verbs  COMPUTE Statement  Signed Numbers in Arithmetic Operations  Intrinsic.
Subprograms1 THE CALL STATEMENT (chp. 16) Purpose: a calling that executes another program; allows portions of code to be treated as a “black box”. Syntax.
Indexed and Relative File Processing
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
Chapter 12: String Manipulation Introduction to Programming with C++ Fourth Edition.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
Structured Programming
12- 1 Chapter 12.  Single-Level OCCURS Clauses  Processing Data Stored in Array  Using OCCURS Clause for Table Handling  Use of SEARCH Statement 
7-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)
Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER 2 Cobol Language Fundamentals.
Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
2-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)
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
IBM-Mainframes COBOL Class-1. Background and History  COBOL is an acronym for: Common Business Oriented Language  COBOL was developed in 1959 by the.
Lecture 101 String Processing Operations on numeric edited fields i.e., view the PIC as a string of characters –Reference modification read/write substrings.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Topics Designing a Program Input, Processing, and Output
Structured Programming
The Selection Structure
Introduction to Scripting
A First Book of ANSI C Fourth Edition
Designing and Debugging Batch and Interactive COBOL Programs
Topics Introduction to File Input and Output
Machine Independent Features
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Structured COBOL Programming
Chapter 14 Sorting and Merging.
Iteration: Beyond the Basic PERFORM
Agenda Collating sequence / Sorting data
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CHAPTER 17 The Report Writer Module
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Topics Introduction to File Input and Output
Decision Making Using the IF and EVALUATE Statements
Presentation transcript:

16- 1 Chapter 16

 To familiarize you with  COPY statement for copying parts of a program stored in a library  CALL statement for executing called programs as subroutines  Text manipulation with STRING and UNSTRING statements 16- 2

 To copy prewritten COBOL entries stored in a library into a program  Often used to copy ◦ FD, 01 entries that define and describe files and records ◦ Tables ◦ SCREEN SECTIONs ◦ Standard modules used in PROCEDURE DIVISION 16- 3

 Saves programmer coding, debugging time by using code already written  Promotes program standardization - all entries copied from library are identical  Reduces time needed to modify code - changes made once to library copy  Library entries can be well-documented so meaningful to all users 16- 4

COPY test-name OF library-name. IN  Use in ENVIRONMENT, DATA, or PROCEDURE DIVISION  Library-name is external-name, 1 to 8 characters, letters and digits only  We’ll have to check to see how to create library on the alpha Format

 Suppose file called Customer, stored in library contains following entries: 01Customer-Rec. 05Cust-NoPic X(5). 05Cust-NamePic X(20). 05Cust-AddressPic X(30). 05Cust-Bal-DuePic 9(4)V

 Code COPY statement at point in program where entries should appear Data Division. File Section. FDCustFile. Copy Customer.  In source listing, copied lines are marked with a C or other designator 16- 7

…... 11FDCustFile. 12Copy Customer. 13C01Customer-Rec. 14C05Cust-NoPic X(5). 15C05Cust-NamePic X(20). 16C05Cust-AddressPic X(30). 17C05Cust-Bal-DuePic 9(4)V Line numbers followed by C are copied statements

REPLACING ==pseudo-text-1== ==pseudo-text-2== identifier-1BY identifier-2... literal-1 literal-2 word-1 word-2  Add REPLACING clause to COPY to make changes to copied entries Format

Copy Customer Replacing Cust-No By Cust-Number, ==X(5)== By ==X(6)==.  Changes copied line 14C ◦ From: 14C05Cust-No Pic X(5). ◦ To:14C05Cust-Number Pic X(6) Example

 Used in PROCEDURE DIVISION to CALL or reference independent subprograms stored in library  Calling program - main program that calls or references subprogram  Called program - subprogram stored in separate file that is linked and executed within main program

 Compiled, debugged, stored in library to be called when needed  Typical subprograms include: ◦ Edit routines ◦ Error control checks ◦ Standard calculations ◦ Summary, total printing

 Avoids duplication of effort  Improves programmer productivity  Provides greater flexibility  Changes to called program can be made without modifying calling program  Results in greater standardization

 COPY brings entries into program as is  CALL causes an entire program (the called program) to be executed ◦ Data passed from calling to called program ◦ Entire called program (subprogram) executed ◦ Data passed back from called program ◦ Control returns to calling program  COPY is like include in C  CALL is like a function

 Typically, COPY ENVIROMENT, DATA DIVISION entries into source program  CALL subprograms in PROCEDURE DIVISION rather than COPY them

CALL literal-1 [USING identifier-1 …]  To call subprogram into main program  literal-1 is PROGRAM-ID name in called program  Enclose in quotes Format

Calling and Called Programs Identification Division.... Procedure Division.... Call 'Sub1'... Call 'Sub2'... Identification Division. Program-ID. Sub1. … Procedure Division. Exit Program Identification Division. Program-ID. Sub2. … Procedure Division. Exit Program

1.Subprogram Sub1 called and executed in its entirety 2.Control returns to calling program 3.Subprogram Sub2 called and executed in its entirety 4.Control returns to calling program Same as other languages

 USING clause required if data passed between calling and called program  Fields passed are called parameters  Parameter passed in several ways: ◦ Value of parameter may be passed to and used by subprogram but not changed ◦ Value for parameter may be calculated by instructions in subprogram and passed back to main program

 Suppose a main program ◦ Reads in employee records ◦ Produces report showing employee salary, Social Security tax and Medicaid tax (taxes referred to as FICA taxes)  Subprogram is to calculate amount of each tax based on the salary field ◦ Assume PROGRAM-ID is FICAProg

 Parameters needed ◦ Salary (WS-Ann-Sal)  Passed to subprogram, used to calculate taxes but not changed by subprogram ◦ Tax fields Soc-Sec and Med-Tax  Subprogram calculates values for these parameters and passes them back to main program

 CALL statement with: ◦ Literal same as PROGRAM-ID of called program ◦ List of parameters in USING clause Call 'FICAProg' Using WS-Ann-Sal, Soc-Sec, Med-Tax Example

 PROGRAM-ID identifier is literal used in CALL in main program  LINKAGE SECTION must be defined in DATA DIVISION ◦ Follows FILE and WORKING-STORAGE SECTIONs ◦ Describes all items passed between main and subprogram ◦ Format same as WORKING-STORAGE

 PROCEDURE DIVISION header must include USING clause ◦ Lists all parameters or fields defined in LINKAGE SECTION  EXIT PROGRAM ◦ Last executed statement in called program ◦ Returns control back to calling program

Identification Division. Program-ID. FICAProg. Data Division. Linkage Section. 01WS-Ann-SalPic 9(6). 01Soc-SecPic 9(4)V99. 01Med-TaxPic 9(5)V

Procedure Division Using WS-Ann-Sal, Soc-Sec, Med-Tax. If WS-Ann-Sal <= Compute Soc-Sec =.062 * WS-Ann-Sal Else Compute Soc-Sec =.062 * End-If Compute Med-Tax =.0145 * WS-Ann-Sal Exit Program

 When FICAProg is called ◦ Value of WS-Ann-Sal passed to subprogram ◦ Value of Soc-Sec and Med-Tax undefined  When FICAProg finished ◦ Values calculated for Soc-Sec and Med-Tax passed back to main program

 Parameters passed in sequence ◦ First parameter in CALL … USING passed to first parameter in PROCEDURE DIVISION USING clause and so on  Number of parameters in both USING clause should be the same  PIC clauses for corresponding parameters must be same

 Data-names of corresponding parameters may be same or different  Parameters paired by sequence, not by data- name (same as C)  List parameters in same order in both USING clauses

 Assume USING clauses are: Call 'FICAProg' Using Soc-Sec, Med-Tax, WS-Ann-Sal Procedure Division Using WS-Ann-Sal, Soc-Sec, Med-Tax. ◦ Soc-Sec passed as value for WS-Ann-Sal ◦ Calculations in subprogram will be incorrect, values passed back incorrect

 To combine or concatenate several fields into one  Consider following entries: 05Name. 10Last-NamePic X(10). 10First-NamePic X(10). 10Middle-NamePic X(6)

 Suppose name fields have values below  Print name with single blank between parts: THOMAS ALVA EDISON

STRINGidentifier-1... literal-1 identifier-2 DELIMITED BYliteral-2... SIZE INTO identifier-3 [END-STRING]

 identifier-1 or literal-1 is field or value to be combined  identifier-3 is field in which all identifiers or literals are combined  DELIMITED BY clause ◦ Transmitting of characters ends when value of identifier-2 or literal-2 encountered ◦ SIZE means entire contents to be copied

String First-Name Delimited By ' ' Middle-Name Delimited By ' ' Last-Name Delimited By ' ' Into Name-Out  Copies characters from named fields to Name-Out up to first blank in field  Name-Out is THOMASALVAEDISON

 To insert a blank between parts of name String First-Name Delimited By ' ' ' ' Delimited By Size Middle-Name Delimited By ' ' ' ' Delimited By Size Last-Name Delimited By ' ' Into Name-Out Places blank after each field

 Specifies operation(s) to be performed if receiving field not large enough to accommodate result  NOT ON OVERFLOW option may also be used  END-STRING scope terminator also available

 To count number of characters moved in STRING statement  Increments specified field by one for every character moved  If you need to know how may characters were concatenated

Move 1 To WS-Count String First-Name Delimited By ' ' Into Name-Out With Pointer WS-Count  If First-Name is 'Paul', WS-Count is five after STRING  Subtract one from WS-Count to get length of actual move (4)  Initialize WS-Count to 1 or

 Also used to move data to receiving field beginning at some point other than first position  If WS-Count initialized to 15 before STRING, First-Name moved to Name-Out beginning with fifteenth position of Name-Out

 DELIMITED BY clause required  Receiving field must be elementary data item - no editing symbols or JUSTIFIED RIGHT clause  All literals must be nonnumeric  Identifier with POINTER clause must be elementary  Moves data left to right but does not pad with low-order blanks

 To separate a field into its components  Suppose Name-In equals TAFT, WILLIAM, H  The last name, first name and middle initial can be stored in separate fields without commas with the following UNSTRING statement

Unstring Name-In Delimited By ',' Into Last-Name First-Name Middle-Initial  TAFT will be stored in Last-Name, William in First-Name and H in Middle-Initial

UNSTRING identifier-1 DELIMITED BY [ALL] identifier-2 literal-1 OR [ALL] identifier-3 literal-2… INTO identifier-4 … [END-UNSTRING]

 Sending field, as well as literal, must be nonnumeric  Receiving fields may be numeric or nonnumeric  ALL phrase means one or more occurrences of literal or identifier treated as one  POINTER and OVERFLOW clauses may also be used

COPY Statement  To copy entries stored in a library to a user program  Entries for ENVIRONMENT, DATA, and PROCEDURE DIVISIONs may be copied

COPY statement most often used for  Copying standard file and record description entries  Modules used in PROCEDURE DIVISION

CALL Statement  To call or reference entire programs stored in a library  Calling program is user program  Called program (subprogram) is program accessed from library

To pass data between calling program and called program  CALL statement must include USING clause listing name of fields being passed  PROCEDURE DIVISION statement of called program must also have USING clause  Called program must have LINKAGE SECTION defining fields passed  Identifiers in calling and called program may be same or different

 STRING statement joins or concatenates fields or portions of fields into one field  UNSTRING statement breaks a long string into parts and thus enables processing of portion of sending field