powerpoint presentation: richard h. baum, ph.d. devry institute of technology 9th edition nancy...

57
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community College “Copyright @ 2000 John Wiley & Sons, In. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976 United States Copyright Act without the express permission of the copyright owner is unlawful. Request for further information should be addressed to the permissions Department , John Wily & Sons, Inc. The purchaser may make back- up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages, caused by the use of these programs or from the use of the information contained herein.” Structured COBOL Programming

Upload: johan-watkinson

Post on 11-Dec-2015

221 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

PowerPoint Presentation:Richard H. Baum, Ph.D.DeVry Institute of Technology

9th Edition

Nancy Stern Hofstra University

Robert A. Stern

Nassau Community College

“Copyright @ 2000 John Wiley & Sons, In. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976 United States Copyright Act without the express permission of the copyright owner is unlawful. Request for further information should be addressed to the permissions Department , John Wily & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages, caused by the use of these programs or from the use of the information contained herein.”

Structured COBOL Programming

Page 2: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

CHAPTER 16Improving Program Performance UsingThe COPY, CALL, and Other Statements

Page 3: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

OBJECTIVES

• To familiarize you with:

1. The COPY statement for copying parts of a program that are stored in a library.

2. The CALL statement for executing called programs as subroutines.

3. Text manipulation with the STRING and UNSTRING statements.

Page 4: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

CONTENTS• COPY STATEMENT

– Introduction

– Entries that Can be Copied

– An Example

– The Full Format for the COPY Statement

– Self-Test

• CALL STATEMENT– Why Use a CALL Statement?

– Format of the CALL Statement•Called Program Requirements•Calling Program Requirements

Page 5: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

CONTENTS

• Text Manipulation with the STRING and UNSTRING Statements – The STRING Statement

•The Basic Format

• OVERFLOW Option

•POINTER Option

•General Rules for Using the STRING

– The UNSTRING Statement•The Basic Format

•General Rules for Using the UNSTRING

Page 6: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

COPY STATEMENT

• A COPY statement is used to bring into a program a series of prewritten COBOL entries that have been stored in a library.

• Benefits of copy libraries include:

(1) Saving the programmer a considerable amount of coding and debugging time;

(2) Promoting program standardization since all programs that copy entries from a library will be using common data-names and/or procedures;

Page 7: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

COPY STATEMENT

(3) Reducing the time it takes to make modifications and reducing duplication of effort; • if a change needs to be made to a data

entry, it can be made just once in the library without the need to alter individual programs;

(4) Providing extensively annotated library entries that they are meaningful to all users; this annotation results in better-documented programs and systems.

Page 8: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

COPY STATEMENT

• Most often, the COPY statement is used to copy FD and 01 entries that define and describe files and records.

• In addition, standard modules to be used in the PROCEDURE DIVISION of several programs may also be stored in a library and copied as needed.

Page 9: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

COPY STATEMENT

• An Example:--Creating a library entry called CUSTOMER

To copy CUSTOMER into a source program code the following :

COPY CUSTOMER

Page 10: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

COPY STATEMENT• The source listing might appear as

follows(lower case is the copied library; the numbers are source line numbers; the lines that include a C after the line number are the copied statements):

1 IDENTIFICATION DIVISION.

2 PROGRAM-ID. CUST01.. . .10 DATA DIVISION.11 FD CUSTFILE LABEL RECORDS ARE STANDARD.12 COPY CUSTOMER.13 c 01 customer-rec.14 c 05 cust-no pic x(5).15 c 05 cust-name pic x(20).16 c 05 cust-address pic x(30).17 c 05 cust-bal-due pic 9(4)v99.

Page 11: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The Full Format for the COPY StatementCOPY text-name-1 [{OF}{IN} library-name-1]

[REPLACING {{==pseudo-text-1==}

{identifier-1}{literal-1} {word-1}

BY{==pseudo-text-2}

{identifier-2}{literal-2}{word-2}. . . ]– If the REPLACING clause is omitted from the

COPY statement, the library text is copied unchanged.

– The REPLACING option allows virtually any library entry to be changed when it is being copied into the user's source program.

Page 12: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The Full Format for the COPY Statement• The REPLACING clause does not alter

the prewritten entries in the library. That is, the changes are made to the user's source program only.

• Typically, FDs with long or complex record descriptions are copied into programs, as are SCREEN SECTIONs and even modules or paragraphs that are common to more than one program.

• Tables are also often copied.

Page 13: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

QUESTIONS?

Page 14: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST

1. A single series of file or record description entries may be used in several different programs by placing it in a _____ and _____ it when needed.

Solution: library; copying

Page 15: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST

2. With the statement _______you can include prewritten entries in your program.

Solution: COPY

Page 16: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST

3. (T or F) A user or source program can copy library routines and make changes to the field-names initially specified in the library.

Solution: T

Page 17: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST

4. (T or F) Using the REPLACING option of the COPY statement, it is possible to alter the field-names stored in the library itself.

Solution: F--This option only alters library functions for the user program

Page 18: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

SELF-TEST

5. Two purposes of using library functions are to _____ and to ____ .

Solution: make coding and debugging easier; increase standardization

Page 19: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

CALL STATEMENTWhy Use the CALL Statement?

• Structured programs should consist of a series of independent modules that are executed from the main module.– Modules within a program can be viewed as

subroutines that are called or executed from the main module.

• But a program may also CALL or reference independent subprograms stored in a library that are entirely separate from the main program.

Page 20: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

CALL STATEMENT

• The program that references--or calls--a subprogram is referred to as the calling program.

• The subprogram that is linked and executed within the calling program is the called program.

Page 21: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

WHY USE A CALL STATEMENT?

• The called program would need to be compiled, debugged, and catalogued or stored in a library so that it may be called when needed.

• Typical subprograms that may be used by numerous calling programs include edit routines, error control checks, standard calculations, and summary and total printing.

Page 22: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

ADVANTAGES OF CALLING SUBPROGRAMS

1. Avoids duplication of effort. – When modules need to be included in

more than one program, it is best to write them separately and call them into each program as needed.

2. Improves programmer productivity.– Programmers can specialize or code

modules that make use of their specific talents or skills.

Page 23: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

ADVANTAGES OF CALLING SUBPROGRAMS

3. Provides greater flexibility.– Subprograms may be written in any

programming language, but are typically written in a language best suited to the specific task required.

4. Allows changes to the called program to be made without needing to modify the calling program.

5. Results in greater standardization.

Page 24: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

Differences between CALL and COPY• The COPY brings into a user program

separate ENVIRONMENT, DATA, or PROCEDURE DIVISION segments as is. – The copied entries are compiled and executed

together with the source program.

• The CALL causes an entire program, which is already in machine language, to be executed. – The calling and called programs are separate,

but data may be passed from the called program to the calling program or from the calling program to the called program.

Page 25: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

Differences between CALL and COPY• When the CALL is performed, data is

passed from the calling to the called program. – The entire called program is executed,

data is passed from the called program back to the calling program, and control returns to the calling program.

• Typically, we COPY ENVIRONMENT and DATA DIVISION entries into a source program and we CALL programs from a library rather than COPY them.

Page 26: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

Format of the CALL Statement• Format:

CALL literal-1

[USING identifier-1....]– Literal-1 is the name of the called program as

specified in its PROGRAM-ID statement; it is enclosed in quotes like a nonnumeric literal.

– The USING clause of the CALL statement is required if the subprogram performs any operations in which data is to be passed from one program to another.

Page 27: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

Format of the CALL Statement• The CALL ... USING identifies fields in

the main or calling program that will be either passed to the called program before it is executed, or passed back to the calling program after the called program has been executed.– Since the purpose of calling a subprogram

is to perform operations or calculations on data, we almost always employ the USING option.

Page 28: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

Called Program RequirementsPROGRAM-ID.

• The literal used in the CALL statement of the main program to extract a subprogram or routine from a library and execute it must be identical to the called program's PROGRAM-ID. – In the calling program, we code

CALL 'literal-1' USING ... .

– In the called program, we code PROGRAM-ID. literal-1.

Page 29: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

Called Program RequirementsLINKAGE SECTION.

• A LINKAGE SECTION must be defined in the called program for identifying those items that:(1) will be passed to the called program from

the calling program and

(2) passed back from the called program to the calling program.

• The LINKAGE SECTION of the called program, then, describes all items to be passed between the two programs.

Page 30: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

Called Program RequirementsPROCEDURE DIVISION USING.

• The identifiers specified in the USING clause in the PROCEDURE DIVISION entry include all fields defined in the LINKAGE SECTION;

– these identifiers will be passed from one program to the other.

– They are passed to and from corresponding identifiers in the CALL ... USING of the main program.

Page 31: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

Called Program Requirements

EXIT PROGRAM.

• The last executed statement in the called program must be the EXIT PROGRAM.– It signals the computer to return control

back to the calling program.

Page 32: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

Calling Program Requirements• To execute a subprogram stored in a

library, the only statement required in the calling program is the

CALL 'literal-1' USING . . .

• The literal specified in the CALL statement of the main program should be the same as in the PROGRAM-ID of the called program, but it is enclosed in quotes in the CALL.

Page 33: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

COBOL 85

• With COBOL 74, you pass 01-level items.

• With COBOL 85 you can pass parameters at any level as long as they are elementary items.

Page 34: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

TEXT MANIPULATION WITH THE STRING AND UNSTRING STATEMENTS

Page 35: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

Interactive Processing

• When data is entered interactively, we sometimes need to convert it into a more concise form for processing purposes or for storing it on disk.

• Similarly, when data is to be displayed, we sometimes need to convert it from a concise form to a more readable form.

• We can use the STRING and UNSTRING for these purposes.

Page 36: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The STRING Statement

The Basic Format

• A STRING statement may be used to combine several fields to form one concise field.

• This process is called concatenation.

Page 37: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The STRING Statement

• A simplified format of the STRING statement is:

STRING {{identifier-1}{literal-1} . . .

DELIMITED BY {identifier-2} {literal-2}{SIZE}} . . .

INTO identifier-3

[END-STRING]

Page 38: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The STRING Statement• For example, we can instruct the computer

to transmit only significant or nonblank characters in FIRST-NAME, MIDDLE-NAME, and LAST-NAME. Once a blank is reached, we stop transmitting that field:

STRING FIRST-NAME DELIMITED BY ' '

MIDDLE-NAME DELIMITED BY ' ' LAST-NAME DELIMITED BY ' ' INTO NAME-OUT– The delimiter itself would not be placed in the receiving

field.

Page 39: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The STRING Statement• We can also use literals between clauses, to

insert blanks between significant characters as follows:

STRINGFIRST-NAME DELIMITED BY ‘ ‘‘ ‘ DELIMITED BY SIZEMIDDLE-NAME DELIMITED BY ‘ ‘‘ ‘ DELIMITED BY SIZELAST-NAME DELIMITED BY ‘ ‘‘ ‘ DELIMITED BY SIZEINTO NAME

– In this instance the NAME would be displayed as: THOMAS ALVA EDISON

Page 40: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The STRING Statement

• The delimiter SIZE means that the entire content of the specified literal is transmitted (it could have been a field as well).

• Each time ' ' DELIMITED BY SIZE is executed, a one-position blank is transmitted.

Page 41: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The STRING Statement• As noted, the delimiter SIZE means that

the entire content of the field is transmitted.

• The delimiter for STATE and ZIP can also be SIZE because we will always print two characters for STATE and five characters for ZIP.

• Note that this coding would not be correct if city consisted of more than 1 word ( NEW ORLEANS).

Page 42: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The STRING Statement• There are numerous additional options

available with the STRING, only some of which we will discuss.

OVERFLOW Option

STRING...

[ON OVERFLOW imperative-statement-1]

– The OVERFLOW option specifies the operation(s) to be performed if the receiving field is not large enough to accommodate the result.

Page 43: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The STRING Statement

POINTER Option

• We may also count the number of characters actually moved in a STRING statement:

STRING ...

[WITH POINTER identifier- 1]

[ON OVERFLOW ...]

– The identifier will specify the number of nonblank characters moved to the receiving field if it is initialized at one.

Page 44: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The STRING Statement• RULES FOR USING THE STRING

STATEMENT

1. The DELIMITED BY clause is required. It can indicate:

– SIZE: The entire sending field is transmitted.

– Literal: The transfer of data is terminated when the specified literal is encountered; the literal itself is not moved.

– Identifier: The transfer of data is terminated when the contents of the identifier is encountered.

Page 45: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The STRING Statement

2. The receiving field must be an elementary data item with no editing symbols or JUSTIFIED RIGHT clause.

3. All literals must be described as nonnumeric.

Page 46: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

The STRING Statement

4. The identifier specified with the POINTER clause must be an elementary numeric item.

5. The STRING statement moves data from left to right just like alphanumeric fields are moved, but a STRING does not pad with low-order blanks, unlike an alphanumeric MOVE.

Page 47: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

THE UNSTRING STATEMENTThe Basic Format

• The UNSTRING statement may be used to convert keyed data to a more appropriate form for storing it on disk. – For example, a program may include a statement

that causes the following to be displayed on a screen:

ENTER NAME: LAST, FIRST, MIDDLE INITIAL : USE COMMAS TO SEPARATE ENTRIES – The message to the operator is fairly clear. When

the name is entered, is stored in an alphanumeric field called NAME- IN.

Page 48: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

THE UNSTRING STATEMENT

• Suppose we wish to store the name in an output disk record as follows:

01 PAYROLL-REC.

05 NAME-OUT.

10 LAST-NAME PIC X(20).

10 FIRST-NAME PIC X(15).

10 MIDDLE-INITIAL PIC X.

Page 49: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

THE UNSTRING STATEMENT

• With an UNSTRING statement, we can instruct the computer to separate the NAME-IN into its components and store them without the commas:

UNSTRING NAME-IN

DELIMITED BY ‘,’INTO LAST-NAME

FIRST-NAME MIDDLE-INITIAL

Page 50: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

THE UNSTRING STATEMENT

UNSTRING Format

UNSTRING identifier-1

[DELIMITED BY [ALL]{identifier-2}{literal-1}

[OR [ALL] {identifier-3}{literal-2}]...]

INTO identifier-4...

[END-UNSTRING]

Page 51: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

THE UNSTRING STATEMENT• We may use any literal, even a blank, as

a delimiter. – We may also ACCEPT a name from a

keyboard and UNSTRING it so that we can use just the last name for looking up a corresponding disk record with last name as a RECORD KEY or ALTERNATE RECORD KEY.

• When the ALL phrase is included, one or more occurrences of the literal or identifier are treated as just one occurrence.

Page 52: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

THE UNSTRING STATEMENT• SUMMARY RULES FOR USING THE

UNSTRING STATEMENT

1. The sending field must be nonnumeric. The receiving fields may be numeric or nonnumeric.

2. Each literal must be nonnumeric.

3. The [WITH POINTER identifier] and [ON OVERFLOW imperative-statement] clauses may be used in the same way as with the STRING.

Page 53: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

CHAPTER SLIDES END HERE

CHAPTER SUMMARY COMES NEXT

Page 54: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

CHAPTER SUMMARY

A. COPY Statement

1. To copy entries stored in a library to a user program.

2. ENVIRONMENT, DATA, and PROCEDURE DIVISION entries may be copied.

3. Most often used for copying standard file and record description entries or modules to be used in the PROCEDURE DIVISION.

4. The format is: COPY text-name {OF}{IN} library-name.

Page 55: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

CHAPTER SUMMARYB. CALL Statement

1. To call or reference entire programs stored in a library.

2. The user program is referred to as the calling program; the program accessed from the library will serve as a subprogram and is referred to as the called program.

3. To pass data from the called program to the calling program. a. The CALL statement can include a USING clause

that lists the names of the fields in the calling program that are passed to the called program and fields that will be passed back from the called program.

Page 56: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

CHAPTER SUMMARY

b. The PROCEDURE DIVISION statement of the called program also includes a USING clause to indicate identifiers specified in this subprogram that will correspond to identifiers in the calling program.

c. Identifiers in the called and calling program may be the same or they may be different, but their picture clauses should match.

d. The called program must have a LINKAGE SECTION in which fields to be passed to and from the calling program are defined. This is the last section of the DATA DIVISION.

Page 57: PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Nancy Stern Hofstra University Robert A. Stern Nassau Community

Structured COBOL Programming, Stern & Stern, 9th Edition

CHAPTER SUMMARYe. The called program must end with an

EXIT PROGRAM statement. This must be in a separate paragraph only for COBOL 74.

C. The STRING statement joins or concatenates fields or portions of fields into one field.

• The UNSTRING statement enables processing of a portion of a sending field.