| Introduction
|
Aims
| In a business-programming environment, the ability to print reports is an important property for a programming language. COBOL allows programmers to write to the printer, either directly or through an intermediate print file. But there would be little point in being able to write to the printer, if the output could not be formatted properly. COBOL allows sophisticated formatting of output through its Edited Picture clauses. This tutorial introduces the additional symbols required for edited pictures and shows how they may be used to format data for output to screen or printer.
|
Objectives
| By the end of this unit you should -
|
Prerequisites
| Introduction to COBOL Declaring data in COBOL Basic Procedure Division Commands Selection Constructs Iteration Constructs Introduction to Sequential files Processing Sequential files
|
| What is an Edited Picture?
|
Introduction
| Most users of the data produced by COBOL programs are not content with the simple raw data. They often want it presented in a particular way. Some people like to have the thousands, in numeric values, separated by commas, others may want leading zeros suppressed while still others may require that the currency symbol "floats" up against the first non-zero digit. In COBOL these things can be achieved using Edited Pictures.
|
Edit Symbols
| Edited Pictures, are PICTURE clauses that format data intended for output to screen or printer. To enable the data items to be formatted, COBOL provides additional picture symbols to supplement the basic 9, X, A, V and S. The additional symbols are referred to as "Edit Symbols," and PICTURE clauses that include edit symbols are called "Edited Pictures". The term edit is used, because the edit symbols have the effect of changing, or editing, the data inserted into the edited item. Edited items cannot be used as operands in a computation, but they may be used as the result or destination of a computation (they can be used in items placed to the right of the word GIVING).
|
Types of editing picture
| COBOL permits two basic types of editing picture:
|
Editing symbols
| COBOL permits two basic types of editing picture:>
|
| Insertion Editing
|
Introduction
| There are four types of Insertion Editing:-
Insertion Editing is so called because the edit symbol is inserted into the data item at the same position it occupies in the picture clause.
|
Simple Insertion editing
| Simple Insertion editing consists of specifying the relevant insertion character(s) in the PICTURE string. When a value is moved into the edited item, the insertion characters are inserted into the item at the position specified in the PICTURE. The comma, the B, the 0, and the slash (/) are the Simple Insertion editing symbols. All Simple Insertion symbols count toward the number of characters printed or displayed. For instance, an item described as PIC 99/99/9999 will occupy 10 character positions when printed. The comma (,) symbol If all characters to the left of the comma are zeros and zero-suppression is called for, the comma is replaced by the replacement symbol (asterisk or space). The space or blank (B) symbol The slash and zero symbols (/ and 0)
|
Simple Insertion examples |
In the examples/questions below, see if you can figure out what result will be produced when we move the value in the Sending item to the editied picture in the Receiving item. The description of the Sending item is shown in the Picture column and its current value is shown in the Data column.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Special Insertion |
The decimal point is the only Special Insertion symbol. A decimal point is inserted in the character position where the symbol occurs. Notes There may be only one decimal point in each edited picture clause. The decimal point symbol cannot be mixed with either the V (assumed decimal point) or the P (scaling position) symbol.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Special Insertion examples |
In the examples/questions below, see if you can figure out what result will be produced when the value in the Sending item is moved to the editied picture in the Receiving item. The description of the Sending item is shown in the Picture column and its current value is shown in the Data column.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Fixed Insertion |
Fixed Insertion editing inserts the symbol at the beginning or end of the edited item. The Fixed Insertion editing symbols are:
All symbols count toward the size of the printed item.
Plus and minus symbols
CR and DB The currency symbol (usually $).
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Fixed Insertion examples |
Like the previous examples/questions above, see if you can figure out what result will be produced when the value in the Sending item is moved to the editied picture in the Receiving item.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Floating Insertion |
The problem with using the fixed insertion symbols is that they can be somewhat unsightly. Values like $0045,345.56 or -0012 are more acceptablely presented as $45,345.56 and -12. What makes these formats more presentable is that the leading zeros have been suppressed and the editing symbol has been "floated" up against the first non-zero digit. In COBOL this is achieved using Floating Insertion. Floating Insertion suppresses leading zeros, and "floats" the insertion symbol up against the first non-zero digit. The Floating Insertion symbols are;
Every floating symbol counts toward the size of the printed item. Except for the left-most one, which is always printed, each Floating Insertion symbol is a placeholder that may be replaced by a digit. Accordingly, there will always be at least one symbol printed, even though this may be at the cost of truncating the number (see the fourth row in the example below.)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Floating Insertion examples |
Like the previous examples/questions above, see if you can figure out what result will be produced when the value in the Sending item is moved to the editied picture in the Receiving item.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Suppression and Replacement Editing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Introduction |
Suppression and replacement editing is used to remove leading zeroes from the value to be edited. There are two varieties of suppression and replacement editing-
Notes Using Z in an editing picture, instructs the computer to suppress a leading zero in that character position and replace it with a space. Using an * in an editing picture, instructs the computer to suppress a leading zero in that character position and replace it with an *. If all the character positions in a data item are Z editing symbols and the sending item is 0 then only spaces will be printed. If a Z or * is used, the picture clause symbol 9, cannot appear to the left of it.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Suppression and Replacement editing examples |
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Picture string restrictions |
Some combinations of picture symbols are not permitted. The table below shows the combination of symbols that is allowed.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Copyright NoticeThese COBOL course materials are the copyright property of Michael Coughlan. All rights reserved. No part of these course materials may be reproduced in any form or by any means - graphic, electronic, mechanical, photocopying, printing, recording, taping or stored in an information storage and retrieval system - without the written permission of the author. (c) Michael Coughlan Last updated : March
1999 mailto:michael.coughlan@ul.ie | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||