630 likes | 1.06k Views
CHAPTER 6 Moving Data, Printing Information, and Displaying Output Interactively. 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.
E N D
CHAPTER 6Moving Data, Printing Information, and Displaying Output Interactively Structured COBOL Programming, Stern & Stern, 9th Edition
OBJECTIVES • To familiarize you with: 1. The various options of theMOVE 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 Edition
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 Edition
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. • Identifier-1 known as Sending Field • Identifier-2 known as Receiving Field • Receiving field determines the outcome of a MOVE Structured COBOL Programming, Stern & Stern, 9th Edition
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 Edition
Sending Field • 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 Edition
Sending Field • Numeric, alphabetic, and alphanumeric sending fields can be either identifiers or literals. • Move is the same whether literal or identifier. Structured COBOL Programming, Stern & Stern, 9th Edition
Receiving Field • The receiving field determines the type of move and how the move is performed. • A literal or figurative constant cannot serve as a receiving field. • 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 Edition
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 Edition
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 X(5). … MOVE “CODE1” TO CLASSIFICATION-OUT Structured COBOL Programming, Stern & Stern, 9th Edition
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 Edition
DEBUGGING TIP 1. Nonnumeric literals, not numeric literals, should be moved to alphanumeric fields. 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 Edition
Numeric Moves • Numeric Move - Sending and receiving fields are both numeric. • Rules: • Fields are decimal aligned • Integer portion. • Movement is from right to left. • Nonfilled high-order positions are replaced with zeros. • Truncation of high-order digits occurs if the receiving field is not large enough to hold the results. • Decimal portion. • Decimal alignment is maintained. • Movement is from left to right, beginning at the decimal point. • Nonfilled low-order positions are replaced with zeros. Structured COBOL Programming, Stern & Stern, 9th Edition
SENDING FIELD RECEIVING FIELD PICTURE CONTENTS PICTURE CONTENTS (a) 9(5) 1 2 3 4 5 9(5) 1 2 3 4 5 (b) 9(5) 1 2 3 4 5 9(4) 2 3 4 5 (c) 9(5) 1 2 3 4 5 9(6) 0 1 2 3 4 5 (d) 9(3)V99 1 2 3 v 4 5 9(3) 1 2 3 (e) 9(3)V99 1 2 3 v 4 5 9V99 3 v 4 5 (f) 9(3) 1 2 3 9(3)V99 1 2 3 v 0 0 Table 5.3 Illustration of the MOVE statement: Numeric Sending Field to Numeric Receiving Field Structured COBOL Programming, Stern & Stern, 9th Edition
NONNUMERIC OR ALPHANUMERIC MOVE Structured COBOL Programming, Stern & Stern, 9th Edition
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 Edition
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 Edition
SENDING FIELD RECEIVING FIELD PICTURE CONTENTS PICTURE CONTENTS (a) X(5) A B C D E X(5) A B C D E (b) X(5) A B C D E X(4) A B C D (c) X(5) A B C D E X(6) A B C D E ¶ Table 5.2 Illustration of the MOVE statement: Alphanumeric Sending Field to Alphanumeric Receiving Field Structured COBOL Programming, Stern & Stern, 9th Edition
Different Size Fields Results Determined by Receiving Field
Receiving Field Larger than Sending • Moving Pic x(3) to recv-field Pic x(5) • Space filled in high order (leftmost positions) • Move “abc” to recv-field • Result abc__ • Moving Pic 9(3) to recv-field Pic 9(5) • Zero filled low order (rightmost positions) • Move 123 to recv-field • Result 00123 • Moving pic 9(3)v99 to recv-field Pic 9(5)v999 • Zero filled high order integer portion • Zero filled low order decimal portion • Move 123.56 to recv-field • Result 00123.560 Structured COBOL Programming, Stern & Stern, 9th Edition
Receiving Field Smaller than Sending • Moving Pic x(5) to recv-field Pic x(3) • Low order truncation • Move “abcde” to recv-field • Result abc • Moving Pic 9(5) to recv-field Pic 9(3) • High order truncation • Move 12345 to recv-field • Result 345 • Moving pic 9(5)v999 to recv-field Pic 9(3)v99 • Both high and low order truncation • Move 12345.678 to recv-field • Result 345.67 • NB: No rounding Structured COBOL Programming, Stern & Stern, 9th Edition
A Group Move is Considered a Nonnumeric Move • All group items, even those with numeric subfields, are treated as alphanumeric fields. Structured COBOL Programming, Stern & Stern, 9th Edition
Performing Multiple Moves with a Single Statement Full Format for the MOVE Instruction MOVE {identifier-1} {literal-1} TO identifier-2 . . . Example: MOVE ZEROS to Total-Gross Total-Net Total-Taxes …. Structured COBOL Programming, Stern & Stern, 9th Edition
SENDING FIELD RECEIVING FIELD ALPHABETIC ALPHANUMERIC NUMERIC NUMERIC EDITED Alphabetic Alphanumeric Numeric Numeric Edited Valid Invalid Invalid Invalid Valid Valid Integers Only Valid Invalid Invalid Valid Valid Invalid Invalid Valid Invalid Table 5.1 Rules of the MOVE Statement (Elementary Data Items) Structured COBOL Programming, Stern & Stern, 9th Edition
Qualification • When two or more data items are named the same • 01 Part-Record. 05 Part-Number pic x(12). … • 01 Detail-Line. 05 Part-Number pic x(12). … • Need some way to designate which one?? • MOVE Part-Number of (in) Part-Record to Part-Number of (in) Detail-Line Structured COBOL Programming, Stern & Stern, 9th Edition
Reference Modification • Used when you need to extract part of a data field • Example: 05 Telephone-Number Pic x(10). • If contents are 5633336173 • We can extract the various parts • Move Telephone-Number (1:3) to Area-CodeMove Telephone-Number (4:3) to ExchangeMove Telephone-Number (7:4) to Number Structured COBOL Programming, Stern & Stern, 9th Edition
Producing PRINTED OUTPUT and SCREEN DISPLAYS Structured COBOL Programming, Stern & Stern, 9th Edition
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 Edition
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 Edition
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 Edition
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 Edition
Features of Printed OutputAlignment 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 Edition
Features of Printed OutputAlignment 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 Edition
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 Edition
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 Edition
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 Edition
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 Edition
The Editing FunctionSuppressing 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 Edition
The Editing FunctionSuppressing 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 Edition
STUDENT NAME CREDITS TUITION UNION FEE ACT FEE SCHOLARSHIP TOTAL BILL SMITH JB 15 003000 025 075 00000 003100 JAMES HR 15 003000 000 075 00000 003075 BAKER SR 09 001800 000 050 00500 001350 PART-TIMER JR 03 000600 025 025 00000 000650 JONES PL 15 003000 025 075 00000 003100 HEAVYWORKER HM 18 003600 000 075 00000 003675 LEE BL 18 003600 000 075 00000 003675 CLARK JC 06 001200 000 025 00000 001225 GROSSMAN SE 07 000600 000 025 00000 001450 FRANKEL LF 10 002000 000 050 00000 002050 BENWAY CT 03 000600 000 025 00250 000375 KERBEL NB 04 000800 000 025 00000 000825 -------- ------- ------- -------- --------- 024500 0075 0625 000750 024550 (a) Without Editing Figure 7.1 Comparison of Outputs (a) Structured COBOL Programming, Stern & Stern, 9th Edition
STUDENT NAME CREDITS TUITION UNION FEE ACT FEE SCHOLARSHIP TOTAL BILL SMITH JB 15 $3,000 $25 $75 $3,100 JAMES HR 15 $3,000 $75 $3,075 BAKER SR 9 $1,800 $50 $500 $1,350 PART-TIMER JR 3 600 $25 $25 $650 JONES PL 15 $3,000 $25 $75 $3,100 HEAVYWORKER HM 18 $3,600 $75 $3,675 LEE BL 18 $3,600 $75 $3,675 CLARK JC 6 $1,200 $25 $1,225 GROSSMAN SE 7 600 $25 $1,450 FRANKEL LF 10 $2,000 $50 $2,050 BENWAY CT 3 600 $25 $250 $375 KERBEL NB 4 800 $25 $825 LUCKY ONE FR 9 $1,800 $50 $2,000 $150CR -------- ------- ------- -------- --------- $26,400 $75 $675 $2,750 $24,400 (b) With Editing Figure 7.1 Comparison of Outputs (b) Structured COBOL Programming, Stern & Stern, 9th Edition
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 Edition
Table 7.1 Editing Characters CHARACTER MEANING CHARACTER MEANING . Actual decimal point B Blank Z Zero suppression / Slash $ Dollar sign CR Credit character , Comma DB Debit character * Check protection + Plus sign 0 Zero - Minus sign Structured COBOL Programming, Stern & Stern, 9th Edition
The Editing FunctionExamples of Dollar Sign and Comma Insertion Sending-FieldReport-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 Edition
The Editing Function Examples of Zero Suppressionwith 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 Edition
The Editing Function Examples of Zero Suppressionwith Asterisk Insertion Sending-FieldReport-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 Edition
The Editing FunctionPrinting 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 Edition