Module 5: Data Division
EDITING Code characters
- While creating reports, sometimes there is necessity to edit the data before it is written on the actual report. For example, you want to add currency sign ‘$’ in salary field, you want to suppress leading zeroes from amount field etc.
- For this purpose we can use editing characters of PICTURE clause to represent data in the user expected format
- COBOL programming provides below Editing code characters:-
Code character | Description |
---|---|
Z | Used to suppress leading zeroes in numeric data item. The leading zeroes will be replace with spaces. Z character has no effect on trailing zeroes. Please refer examples in next table |
* | Similar to code character ‘Z’ except that the leading zeroes will be replaced by asterisk instead of space characters. Please refer examples in next table |
$ | A single $ character will appear on leftmost position of a numeric value. Please refer examples in next table |
- | A minus sign will appear either at the leftmost or rightmost position of numeric value. If data in negative, a minus sign will appear but if data is positive, a space will appear. Please refer examples in next table |
+ | A plus sign is similar to minus sign except that the plus sign will appear when data is positive instead of space. If data is negative a minus sign(-) will appear. Please refer examples in next table |
CR | A ‘CR’ – Credit sign will appear only at rightmost position of the numeric value. If data in negative, a ‘CR’ will appear but if data is positive, two space will appear. Please refer examples in next table |
DB | A ‘CR’ – Debit sign will appear only at rightmost position of the numeric value. If data in negative, a ‘DB’ will appear but if data is positive, two space will appear. Please refer examples in next table. Please refer examples in next table |
. | A period sign or decimal point is used to represent decimal point position in numeric value. Please refer examples in next table |
, | A comma sign is used as delimiter to represent numeric values. One or more comma allowed in picture clause of numeric data item. Please refer examples in next table |
B | Represents Blank insertion. The position where ‘B’ appears in picture clause, blank character (space) will be inserted in that position. Please refer examples in next table |
0 | Represents Zero insertion. The position where ‘0’ appears in picture clause, zero ‘0’ will be inserted in that position. Please refer examples in next table |
/ | Represents Slash insertion. The position where ‘/’ appears in picture clause, slash ‘/’ will be inserted in that position. Mostly it is used to represent date values. Please refer examples in next table |
BLANK WHEN ZERO | This will set entire data item to blanks if data item contains zero value. Please refer examples in next table |
- Important points need to remember while using Editing code characters:-
- For Alphabetic data item only editing character ‘B’ can be used
- For Numeric data item any editing character can be used
- For Alphanumeric data item only editing characters ‘B’, ‘0’ and ‘/’ can be used
- Both the period and V cannot appear in the same picture
De-editing
- Using MOVE verb, we can move numeric edited data item to the numeric data item. This is allowed in COBOL-85. Moving numeric edited item to numeric data item referred to as De-editing of the value. Let’s understand with example.
- Below declaration in done in DATA DIVISION:-
01 EDITED-DATA PIC ZZ999.999. 01 UNEDITED-DATA PIC 9(5)V99.
- In procedure division, below statement is valid in COBOL-85
MOVE 4356.12 TO EDITED-DATA. MOVE EDITED-DATA TO UNEDITED-DATA.
- Once these statements are executed, EDITED-DATA will have value ‘b4356.12’ and UNEDITED-DATA will have value ‘04356.12