Chapter 7 – Editing and Coding Standards • Numeric field types – Numeric – Numeric-edited • Use these only for the fields you define for printing purposes Figure 7.1 Comparison of Outputs (a) STUDENT NAME SMITH JAMES BAKER PART-TIMER JONES HEAVYWORKER LEE CLARK GROSSMAN FRANKEL BENWAY KERBEL CREDITS JB HR SR JR PL HM BL JC SE LF CT NB 15 15 09 03 15 18 18 06 07 10 03 04 TUITION 003000 003000 001800 000600 003000 003600 003600 001200 000600 002000 000600 000800 -------024500 UNION FEE ACT FEE 025 000 000 025 025 000 000 000 000 000 000 000 ------0075 075 075 050 025 075 075 075 025 025 050 025 025 ------0625 (a) Without Editing SCHOLARSHIP 00000 00000 00500 00000 00000 00000 00000 00000 00000 00000 00250 00000 -------000750 TOTAL BILL 003100 003075 001350 000650 003100 003675 003675 001225 001450 002050 000375 000825 --------024550 Figure 7.1 Comparison of Outputs (b) STUDENT NAME SMITH JAMES BAKER PART-TIMER JONES HEAVYWORKER LEE CLARK GROSSMAN FRANKEL BENWAY KERBEL LUCKY ONE CREDITS JB HR SR JR PL HM BL JC SE LF CT NB FR 15 15 9 3 15 18 18 6 7 10 3 4 9 TUITION $3,000 $3,000 $1,800 600 $3,000 $3,600 $3,600 $1,200 600 $2,000 600 800 $1,800 -------$26,400 UNION FEE ACT FEE $25 $25 $25 ------$75 $75 $75 $50 $25 $75 $75 $75 $25 $25 $50 $25 $25 $50 ------$675 (b) With Editing SCHOLARSHIP $500 $250 $2,000 -------$2,750 TOTAL BILL $3,100 $3,075 $1,350 $650 $3,100 $3,675 $3,675 $1,225 $1,450 $2,050 $375 $825 $150CR --------$24,400 • Editing characters – Decimal point • • • • Actual decimal point Implied decimal point 05 Field-A PIC 9v99. 05 Field-A-Edited PIC 9.99. – Zero suppression • Gets rid of the left side zeros • 05 FIELD-B PIC 9(5). • 05 FIELD-B-EDITED PIC ZZZZ9. – Dollar sign • Fixed – 05 FIELD-D PIC 9(4). – 05 FIELD-D-EDITED PIC $ZZZ9. • Floating – 05 FIELD-D-EDITED PIC $$$$9. – Receiving field must be one character bigger than the sending field – Comma • 05 FIELD-E PIC 9(4). • 05 FIELD-E-EDITED PIC $$,$$9. • In this example 2 extra spaces needed – Check protection • Used when printing a check to avoid blank spaces between a fixed dollar sign and first digit. • 05 FIELD-G-EDITED PIC $**,**9. – Insertion characters • • • • /, BLANK (B), 0 Printed exactly where they appear in the PIC statement 05 FIELD-H PIC 9(6). 05 FIELD-H-EDITED PIC 99/99/99. • Signed numbers – Require a ‘S’ in the PIC clause – signed field • FIELD-A PIC S99 VALUE - 20 – Default is positive if no ‘S’ even if the result of a calculation is negative. – CR and DB symbols • Credit and debit • Treats them identically • Only shows CR or DB if value is negative – Plus and minus signs • BLANK WHEN ZERO clause – Use after a PIC clause • 05 UNION-FEE PIC $$$9.99 BLANK WHEN ZERO. 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 Table 7.3 CR and DB Editing Characters SOURCE FIELD PICTURE a. b. c. d. S9(5) S9(5) S9(5) S9(5) VALUE 98765 -98765 98765 -98765 RECEIVING FIELD PICTURE VALUE $$$,999CR $$$,999CR $$$,999DB $$$,999DB $98,765 $98,765CR $98,765 $98,765DB Table 7.4 Floating Plus and Minus Sign SOURCE FIELD PICTURE a. b. c. d. e. f. g. h. S9(4) S9(4) S9(4) S9(4) S9(4) S9(4) S9(4) S9(4) VALUE 1234 0123 -1234 1234 0123 -1234 1234 -1234 RECEIVING FIELD PICTURE VALUE ++,+++ ++,+++ ++,+++ --,----,----,--ZZ,ZZ9+ ZZ,ZZ9- +1,234 +123 -1,234 1,234 123 -1,234 1,234+ 1,234- • Coding standards – If someone else must edit your program – Data division • Meaningful data names – X or IN-EMPLOYEE-NAME • Consistent data name prefixes – Within the same record (01) or File Descriptor (FD) – IN-… WS-… • Column alignment of picture clauses – This helps check that the PIC clause is correct • Standard format for picture clause – PIC, PICTURE, PIC IS use only one • Consistent indentation of level numbers • Avoidance of 77-level entries • Procedure division – Development of functional paragraphs • Useful names, READ-FILE, WRITE-HEADING – Sequencing of paragraph names • 100-WRITE-HEADER, 200-READ-FILE • Used to locate paragraph header quickly – Avoidance of commas – Use scope terminators • Ex, END-IF, END-READ – Consistent indentation • Readability – Use of Spaces – Avoidance of literals or constants in the procedure division – Don’t over comment • Use care when commenting • Make the PIC clause: Page 191 – 1.a Floating $, omission of cents, printing of commas, max value of $9,999,999 – c. fixed dollar sign, zero suppression of insignificant leading zeros, no commas, max value of $99,999.99 – d. floating $, use of commas, max value of $9,999.00 and trailing CR if negative. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 9(6) 9(6) 9(6) 9(4)V99 9(4)V99 9(4)V99 9(4)V99 9(6) 9(6) 9(4)V99 123456 123456 123456 123456 123456 123456 123456 123456 123456 123456 9(6) 9(8) 9(6).99 9(6) 9(4) $$$$$9.99 $$$,$$9.99 $$$$,$$9.99 Z(8) $ZZZ,ZZZ.99 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. S9(4)V99 S9(4)V99 S9(4) S9(6) S9(6) S9(6) S9(6) S9(6) 9(4)V99 9(4)V99 9(4)V99 45600 $$$$$.99CR 45600 $$,$$$.99DB 4567 $$,$$$.00 122577 99B99B99 123456 ++++,+++ -123456 ++++,+++ 123456 ----,---123456 ----,--567890 $$$$,$$$.99 567890 $ZZZ,ZZZ.99 567890 $***,***.99