For Defining numeric data :
-Use the PICTURE clause .
➢ The Picture clause is used to specify the type and size of an elementary data item.
➢ It consists of the word PIC or PICTURE followed by the actual picture clause, where the
type and size are specified
Example1 :
01 EMP-Salary Pic 9(5) Value 25000.
05 EMP-Name Pic X(20) Value "James".
Arithmetic positioning character:
Example2:
01 PRODUCT-PRICE PIC $999V99.
SIGN Clause :
SIGN clause allow us to store the sign separately for the signed numeric data items. This can
be coded only for numeric data items that contains 'S' in PIC clause.
Syntax :
SIGN IS (LEADING) SEPARATE CHARACTER (TRAILING).
➢ Default is TRAILING WITH NO SEPARATE CHARACTER.
➢ So 'S' doesn't take any space for TRAILING and LEADING
➢ It is stored along with the last digit.
EXAMPLE :-
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-SIGN-LS-P PIC $999 VALUE +123
SIGN IS LEADING SEPARATE CHARACTER.
01 WS-SIGN-TS-P PIC $999 VALUE +123
SIGN IS TRAILING SEPARATE CHARACTER.
01 WS-SIGN-P PIC 5999 VALUE +123. 01 WS-SIGN-LS-N PIC $999 VALUE-123
SIGN IS LEADING SEPARATE CHARACTER.
01 WS-SIGN-TS-N PIC $999 VALUE-123
SIGN IS TRAILING SEPARATE CHARACTER.
01 WS-SIGN-N PIC $999 VALUE-123.
PROCDURE DIVISION.
DISPLAY "SIGN POSITIVE LEADING SEPERATE: WS-SIGN-LS-P.
DISPLAY "SIGN POSITIVE TRAILING SEPERATE: WS-SIGN-TS-P
DISPLAY "SIGN POSITIVE NO SEPERATE: WS-SIGN-P.
DISPLAY "SIGN NEGATIVE LEADING SEPERATE: WS-SIGN LS-N.
DISPLAY "SIGN NEGATIVE TRAILING SEPERATE: WS-SIGN-TS-N.
DISPLAY "SIGN NEGATIVE NO SEPERATE: WS-SIGN-N.
OUTPUT:
SIGN POSITIVE LEADING SEPERATE: +123
SIGN POSITIVE TRAILING SEPERATE: 123+
SIGN POSITIVE NO SEPERATE: 12C
SIGN NEGATIVE LEADING SEPERATE: -123
SIGN NEGATIVE NO SEPERATE: 12L
SIGN NEGATIVE TRAILING SEPERATE: 123
ROUNDED & ON SIZE ERROR :
ROUNDED option used to round the fraction result of the compute statement exceeds the
length of the target data item fractional places.
If the ROUNDED option is not specified and the target decimal fraction exceeds, the result
gets truncated.
ON SIZE ERROR
The ON SIZE ERROR phrase can be used to define special processing that is to take place when
a size error occurs for a data item used to store the results of a mathematical operation.
Because COBOL continues execution even if a size error occurs, a size error can cause a loop
or processing result error at execution
Representing Zero Suppression:
• In a PICTURE character-string, there are two ways to represent zero suppression, and two
ways in which editing is performed:
• Any or all of the leading numeric character positions to the left of the decimal point are
represented by suppression symbols. When editing is performed, the replacement character
replaces any leading zero in the data that appears in the same character pos ition as a
suppression symbol.
Suppression stops at the leftmost character:
• That does not correspond to a suppression symbol
• That contains nonzero data
• That is the decimal point
All the numeric character positions in the PICTURE character-string are represented by the
suppression symbols. When editing is performed and the value of the data is nonzero, the result is the
same as in the preceding rule. If the value of the data is zero, then:
If Z has been specified, the entire data item will contain spaces.
If * has been specified, the entire data item except the actual decimal point will contain asterisks.
For example:
Displaying Numeric Data :
Numeric data items with editing
DATA DIVISION
01 PRODUCT-PRICE PIC 9(5)V99.
01 EDITED-PRODUCT-PRICE PIC $ZZ,ZZ9.99.
Symbols
Decimal points (.)
Commas (,)
Dollar signs ($)
PROCEDURE DIVISION.
ACCEPT PRODUCT-PRICE.
Debit (DR)
MOVE PRODUCT-PRICE TO EDITED-PRODUCT PRICE
Credit (CR)
DISPLAY EDITED-PRODUCT-PRICE.
SAMPLE INPUT: 0170099
SAMPLE OUTPUT: $1,700.99