0% found this document useful (0 votes)
65 views

Nassau Community College: Nancy Stern Hofstra University Robert A. Stern

Uploaded by

Ask Name
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Nassau Community College: Nancy Stern Hofstra University Robert A. Stern

Uploaded by

Ask Name
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 75

Structured COBOL

Programming “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

Nancy Stern Copyright Act without the express permission of the


copyright owner is unlawful. Request for further information
should be addressed to the permissions Department , John

Hofstra University
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.”

Robert A. Stern
Nassau Community
College 9th Edition

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

Moving Data,
Printing Information, and
Displaying Output
Interactively

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
OBJECTIVES
• To familiarize you with:
1. The various options of the MOVE
statement.
2. The rules for moving fields and
literals.
3. How to print decimal points, dollar
signs, and other edit symbols.
4. How to design and print reports.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
CONTENTS
Introduction
The Instruction Formats of the MOVE
Statement
Numeric MOVE
– When Sending and Receiving Fields Have the
Same PIC Clauses
– When Sending and Receiving Fields Have
Different PIC Clauses
– Moving Numeric Literals to Numeric Fields
– Moving Signed Numbers: An Introduction
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
CONTENTS
Nonnumeric or Alphanumeric MOVE
– Basic Rules
– A Group Move Is Considered a Nonnumeric Move

Other Options of the MOVE Statement


– Qualification of Names
– Performing Multiple Moves with a Single
Statement
– Reference Modification: Accessing Segments of
a Field Using COBOL 85

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
CONTENTS
• Producing Printed Output And Screen
Displays
– Features of Printed Output
– The Editing Function
– Self-Test
– Editing Using Floating Strings
– BLANK WHEN ZERO Option
– Defining Print Records in WORKING-STORAGE

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
CONTENTS

– The WRITE. . .FROM Statement


– The JUSTIFIED RIGHT Option
– The ADVANCING Option for Spacing Forms
– Printing Page Numbers
– Printing or Displaying the Date of the Run
• Accepting DATE using compilers that are not
Y2K compliant
– Printing or Displaying Quotation Marks

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
CONTENTS

• Displaying Output Interactively Using


Screen Input and Output
– ACCEPT statement for Screen I-O
– DISPLAY statement for Screen I-O
– The SCREEN SECTION for Defining Screen
Layouts Using PCs

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
INTRODUCTION

• Every COBOL statement in the


PROCEDURE DIVISION, like every English
sentence, must contain a verb.
• A COBOL statement usually starts with a
verb.
• The MOVE statement, like all COBOL
imperative statements, appears in the
PROCEDURE DIVISION.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
The Instruction Formats of the
MOVE Statement
• The first instruction format of the MOVE
statement follows Format 1:
MOVE identifier-1 TO identifier-2
• Identifier-1 and identifier-2 are data-
names that are defined in the DATA
DIVISION.
– To obtain in identifier-2 the same contents as
in identifier-1, the PICTURE clauses of both
fields must be the same.
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
The Instruction Formats of the
MOVE Statement
• A second form of the MOVE statement is
as follows:
Format 2
MOVE literal-1 TO identifier-2

– Reminder: there are two kinds of literals:


numeric and nonnumeric.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
REVIEW OF LITERALS
• Numeric Literals
1. 1 to 18 digits.
2. Decimal point (optional).
3. Sign (optional).
• Nonnumeric or Alphanumeric Literals
1. 1 to 160 characters for COBOL 85
• 120 is the upper limit for COBOL 74.
2. Any characters may be used (except the quote
mark or apostrophe).
3. The literal is enclosed in single quotes or
apostrophes (sometimes double quotes).

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
The Instruction Formats of the
MOVE Statement
• The following are examples where a
literal is moved to a data-name or
identifier:

05 DEPT-OUT PIC 999.



MOVE 123 TO DEPT-OUT
05 CLASSIFICATION-OUT PIC 999.

MOVE “CODE1” TO CLASSIFIFATION-OUT

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
The Instruction Formats of the
MOVE Statement
• The MOVE statement can also move a
figurative constant to an identifier.
– A figurative constant is a COBOL reserved
word, such as SPACE (or SPACES), or ZERO
(or ZEROS or ZEROES), that represents a
specific value.

Examples:
MOVE ZEROS TO TOTAL-OUT.
MOVE SPACES TO HEADING1.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
DEBUGGING TIP

1. Nonnumeric literals, not numeric literals,


should be moved to alphanumeric fields.
– The receiving field determines how the move
is performed.

2. As noted previously, we typically use X’s


in a PICTURE clause of nonnumeric fields
and avoid the use of A’s.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
QUESTIONS?

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST
Use the following statement for Questions 1--
5.
MOVE NAME-IN TO NAME-OUT
1. MOVE is called the ____ .
NAME-IN is called the ____ . NAME-OUT
is called the ____ .

SOLUTION: verb or operation; sending field;


receiving field

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST
2. Assume NAME-IN has contents of SAM and
NAME-OUT has contents of MAX; assume
also that the fields have the same PICTURE
clauses. At the end of the MOVE operation,
NAME-OUT will have _______ as its
contents and NAME-IN will contain ______.
SOLUTION: SAM; SAM
– (Note: The contents of a sending field remains
unchanged.)

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST

3. In a MOVE operation, the sending field


may be a(n) _______or a(n) _________
or a(n) ________.

SOLUTION: literal; identifier (data-name);


figurative constant

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST

4. What are the two kinds of literals that


may serve as a sending field in a MOVE
operation?

SOLUTION: Numeric and nonnumeric (or


alphanumeric) literals

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST

5. The receiving field in a MOVE


operation is always a(n) ____ .

SOLUTION: identifier or data-name


Structured COBOL Programming, Stern & Stern, 9th Ed
ition
SELF-TEST
Use the following statement for Questions 6
and 7.

MOVE A12 TO FIELD3


6. A12 must be a(n) _______and not a
nonnumeric literal because it is not ____ .

SOLUTION: identifier; enclosed in quotation


marks
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
SELF-TEST

7. If the identifier A12 has contents of


453, ____ will be moved to FIELD3
and A12 will have ____ as its
contents at the end of the operation.

SOLUTION: 453; 453


Structured COBOL Programming, Stern & Stern, 9th Ed
ition
SELF-TEST

Use the following statement for Questions


8--11.
MOVE 'AB1’ TO FIELD6
8. The sending field is a _______.

SOLUTION: nonnumeric literal


Structured COBOL Programming, Stern & Stern, 9th Ed
ition
SELF-TEST

9. The sending field cannot be an


identifier because it is ________.

SOLUTION: enclosed in quotation


marks

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST

10. To obtain exactly AB1 in FIELD6,


the PICTURE clause of the receiving
field should be ______.

SOLUTION: XXX or X(3)

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST

11. 'AB1' (is, is not) defined in the


DATA DIVISION.

SOLUTION: is not
– Literals appearing in the PROCEDURE
DIVISION need not be defined
elsewhere in the program.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
NONNUMERIC OR
ALPHANUMERIC MOVE

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
BASIC RULES
NONNUMERIC MOVE
1. Moving an alphanumeric or alphabetic field,
defined by a PICTURE of X's or A's, to another
alphanumeric or alphabetic field.
2. Moving a nonnumeric literal to an
alphanumeric or alphabetic field.
3. Moving a numeric field or numeric literal to
an alphanumeric field or to any group item.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
BASIC RULES

RULE FOR NONNUMERIC MOVE


• In a nonnumeric move, data is
transmitted from the sending field to the
receiving field from left to right.
• Low-order or rightmost positions of the
receiving field that are not replaced with
sending field characters are filled with
spaces.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
A Group Move is Considered a
Nonnumeric Move
• All group items, even those with numeric
subfields, are treated as alphanumeric fields.
• Sending fields are of six types:
– numeric
– alphabetic
– alphanumeric
– the figurative constant ZEROS
– the figurative constant SPACES
– and group item.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
A Group Move is Considered a
Nonnumeric Move
• Numeric, alphabetic, and alphanumeric
sending fields can be either identifiers
or literals.
• A numeric field is moved in the same
manner as a numeric literal.
• A literal or figurative constant cannot
serve as a receiving field.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
A Group Move is Considered a
Nonnumeric Move
• The receiving fields refer only to
identifiers that can be numeric,
alphabetic, alphanumeric, and group
fields.
• Note that when mixed data types appear,
the MOVE operation is always performed
in the format of the receiving field.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
MORE QUESTIONS!

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST

1. In a nonnumeric move, data is


transmitted from (left, right) to
(left, right).

SOLUTION: left; right

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST

2. In a nonnumeric move, if the


receiving field is larger than the
sending field, (right-, left-) most
positions are replaced with ______.

SOLUTION: right-; spaces or blanks


Structured COBOL Programming, Stern & Stern, 9th Ed
ition
SELF-TEST
 Use the following statement for Questions 3--
5.
 MOVE CODE-IN TO CODE-OUT
 CODE-IN CODE-OUT
PICTURE / Contents / PICTURE / Contents
(after MOVE)

 3. X(4) AB12 X(6) _______

 SOLUTION: AB12bb (b denotes a blank)

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST

4. X(4) AB12 X(3) _______

SOLUTION: AB1

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST

5. XXX ABC _______ AB

SOLUTION: XX

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
SELF-TEST

6. Suppose TOTAL-OUT has a PIC of X(5)


and we code MOVE '0' TO TOTAL-OUT.
What would the contents of TOTAL-OUT be
at the end of the MOVE? Would this be
the same as moving ZEROS to TOTAL-
OUT?

SOLUTION: 0bbbb; no
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
Performing Multiple Moves
with a Single Statement
Full Format for the MOVE Instruction
MOVE {identifier-1}
{literal-1} TO identifier-2 . . .

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
A Review of Instruction
Format Rules
• The braces { } mean that either of the
two elements may be used as a
sending field.
• The receiving field must be a data-
name or identifier.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
A Review of Instruction
Format Rules
• Uppercase words like MOVE and TO are
reserved words.
• When these words are underlined, they
are required in the statement.
• The ellipses or dots at the end of the
statement mean that one sending field
can be moved to numerous receiving
fields.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
Producing PRINTED
OUTPUT and SCREEN
DISPLAYS

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
Features of Printed Output and
Screen Displays

• Computer maintained files must be


printed or displayed in order to be
accessed by users.
• Output that is displayed on a screen is
useful for answering inquiries about
the status of a file or for quick,
interactive results.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
Features of Printed Output and
Screen Displays
• Printed reports are typically formal
documents that provide users with the
information they need to perform their
jobs effectively.
• Because computer-produced displays
and reports are to be read by people,
they must be clear, neat, and easy to
understand.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
Features of Printed Output
Spacing of Forms
• The lines on printed output must
be properly spaced for ease of
reading.
• Some lines might be single-
spaced, others double-spaced,
and so on.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
Features of Printed Output
Spacing of Forms
• Printed output must have margins
at both the top and bottom of each
page.
– This requires the computer to be
programmed to sense the end of a
page and then to transmit the next
line of information to a new page.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
Features of Printed Output
Alignment of Information
• Reports do not have fields of
information adjacent to one
another as is the practice with disk
files.
• Printed and displayed output are
more easily interpreted when
fields are spaced evenly across the
page or screen.
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
Features of Printed Output
Alignment of Information

• The Printer Spacing Chart is used for


planning the output design so that
detail lines and heading lines are
properly spaced for readability.
– There is a set of Printer Spacing Charts
at the back of the book that you can
use to plan your output.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
Printing Headings, Total Lines,
and Footings
• We typically establish a print area as
80, 100, or 132 characters per line
depending on the printer used.
• Displayed output typically has 80
characters for line.
• Three types of headings may appear on
each page of a report:

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
Printing Headings, Total Lines,
and Footings
1. Report heading - includes a title for
the report, date, etc. This heading may
appear once at the beginning of the
report or on each page.
2. Page heading - appears on each page
and may include page numbers,
distribution list, etc.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
Printing Headings, Total Lines,
and Footings
• Often a single heading on each page
serves both as a report and page
heading.
3. Column heading - identifies the
fields that will print on subsequent
lines.
• Total lines and footings may also appear
at the end of a page or report.
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
The Printer Spacing Chart
• The Printer Spacing Chart is used to assist
programmers in the preparation of reports,
it helps to insure that:
(1) headings appear properly spaced across the
page and
(2) fields are properly aligned under column
headings and are evenly spaced across the page.
• A screen layout form is used in a similar way to
plan the formatting for displayed output. This is
discussed in a later section

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
The Editing Function
Suppressing Leading Zeros
• Nonsignificant or leading zeros are zeros
appearing in the leftmost positions of a field
and having no significant value.
– For example, 00387 has two leading zeros.

• Nonsignificant zeros should generally be


omitted when printing.
– That is, 00387 should print as bb387, since the
two numbers are numerically equivalent and the
latter is easier to read.
**The b represents a blank.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
The Editing Function
Suppressing Leading Zeros
• The operation to perform this type of
editing is called suppression of leading
zeros.
• The edit symbol Z is used to suppress
leading zeros and to replace them with
blanks or spaces.
WS-TOTAL, with a PICTURE of 999, might be
edited by moving it to TOTAL-OUT, with a
PICTURE of ZZZ.
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
The Editing Function: Printing
Dollar Signs and Commas
• Dollar signs and commas are editing
symbols frequently used in conjunction
with the suppression of leading zeros and
the printing of decimal points, since many
numeric quantities often appear on printed
reports as dollars and cents figures.
• The dollar sign and comma are placed in
the positions in which they are desired, as
in the case with decimal points.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
The Editing Function
Examples of Dollar Sign and
Comma Insertion
Sending-Field Report-Item
PICTURE Contents PICTURE Edited Results
1. 9(4)V99 3812^34 $9,999.99 $3,812.34
2. 99V99 05^00 $ZZ.99 $5.00
3. 999V99 000^05 $ZZZ.99 $ .05
4. 9(4)V99 0003^82 $Z,ZZZ.99 $ 3.82

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
The Editing Function
Examples of Zero Suppression
with Asterisk Insertion
• The asterisk is used most often for
the printing of checks or when there
is some concern that the resultant
amount fields might be tampered
with.
• Under other conditions, the use of
Z's for normal zero suppression is
sufficient.
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
The Editing Function
Examples of Zero Suppression
with Asterisk Insertion
Sending-Field Report-Item
PICTURE / Contents/ PICTURE/Edited Results

1. 9(3)V99 123^45 $***.99 $123.45


2. 9(3)V99 012^34 $***.99 $*12.34
3. 9(5)V99 00234^56 $**,***.99 $***234.56

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
The Editing Function
Printing Debit and Credit
Symbols
for Accounting Applications
• For most applications, a plus or minus
sign to indicate positive or negative
quantities is sufficient.
• For accounting applications, however, a
minus sign often indicates either a debit
or a credit to a particular account.
• The edit symbols DB , for debit, or CR , for
credit, may be used in place of the minus
sign.
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
The Editing Function
Examples of CR or DB Insertion
Sending-Field Report-Item
PICTURE / Contents / PICTURE / Contents
1. S999 123 - 999CR 123CR
2. S999 123 - 999DB 123DB
3. S999 123 + 999CR 123bb
4. S999 123 + 999DB 123bb

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
BLANK WHEN ZERO Option
• At times, we may want to print, or
display, spaces rather than zeros when
a sending field consists entirely of
zeros.
• Or, with the use of complex editing,
you may find that $.00, - 0, or a + or -
sign by itself will print or display.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
BLANK WHEN ZERO Option

• This may detract from the clarity of a


report.
• In such cases, the COBOL expression
BLANK WHEN ZERO may be used along
with the PIC clause for the report-item.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
The WRITE ... FROM Statement

• As noted, the WORKING-STORAGE


SECTION stores records to be printed.
– Because a separate area is established for
each record and all constants and blanks may
be preassigned with VALUE clauses.

• The data stored in WORKING-STORAGE


must, however, be transmitted to the
print area and then printed.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
The WRITE ... FROM Statement

• We use a WRITE (FILE SECTION record)


FROM (WORKING-STORAGE record) to
accomplish this instead of a MOVE and
WRITE.
Example:
WRITE PRINT-REC FROM HEADING-1 instead
of
MOVE HEADING-1 TO PRINT-REC
WRITE PRINT-REC
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
CHAPTER SLIDES END HERE

CHAPTER SUMMARY COMES NEXT

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
CHAPTER SUMMARY

A. Numeric Move - Sending and receiving


fields are both numeric.
Rules:
1. Integer portion.
a. Movement is from right to left.
b. Nonfilled high-order positions are replaced
with zeros.
c. Truncation of high-order digits occurs if the
receiving field is not large enough to hold the
results.
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
CHAPTER SUMMARY

Numeric Move Rules (continued)


2. Decimal portion.
a. Decimal alignment is maintained.
b. Movement is from left to right, beginning at
the decimal point.
c. Nonfilled low-order positions are replaced
with zeros.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
CHAPTER SUMMARY

B. Nonnumeric Move - Receiving field is


nonnumeric.
Rules
1. Movement is from left to right.
2. Low-order nonfilled positions are replaced
with spaces.
3. Truncation of low-order characters occurs if
the receiving field is not large enough to hold
the results.
Structured COBOL Programming, Stern & Stern, 9th Ed
ition
CHAPTER SUMMARY
C. The format of the receiving field
determines the type of MOVE operation that
is performed - either numeric or
nonnumeric.
D. A field-name may be qualified by using OF
or IN with the name of a record or group
item of which the field is a part.
E. Editing. Table 6.3 (see last slides) reviews
edit symbols used in a PICTURE clause.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
CHAPTER SUMMARY

F. Rules for printing output.


1. The AFTER or BEFORE ADVANCING option
should be used with each WRITE instruction
to indicate the spacing of the form.
– AFTER ADVANCING 1, 2, or 3 lines, for
example, will cause zero, one, or two blank
lines, respectively, to appear before the next
record is written.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
CHAPTER SUMMARY
F. Rules for printing output.
2. Records defining all printed output including
heading and detail lines should be established in
WORKING-STORAGE so that VALUE clauses can
be used.
– These records must be moved to the print area
defined in the FILE SECTION.
• A WRITE ... FROM instruction may be used in place
of a MOVE and a WRITE to print these lines
3. Use a Printer Spacing Chart to determine the
print positions to be used.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
CHAPTER SUMMARY

F. Rules for printing output.


4. After each record is printed, a test for the
end of a form should be performed.
– If the desired number of lines have been
printed, code WRITE (print record) FROM
(heading record) AFTER ADVANCING PAGE.
5. The appropriate editing symbols should be
specified in the PICTURE clauses of report-
items within the detail record.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition
CHAPTER SUMMARY

G. Output can be displayed in exact screen


positions.
– Using the SCREEN SECTION, and
enhancements to the ACCEPT and
DISPLAY verbs, screen displays can be
made more user-friendly.

Structured COBOL Programming, Stern & Stern, 9th Ed


ition

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy