Data Items

D
Data Items:

Using PIC clause we define the size and type of the data item.

Data item types and meaning:

Char Type Meaning
9 Numeric This Char represents numeric value.
V Numeric This Char represents Assumed decimal point.
S Numeric This Char represents Sign of numeric value.it should be left most character if used.it can be – or +.Numeric data items are right justified.
X Alphanumeric This Char represents with characters all numeric alphabetic (A-Z), Space, special characters.
A Alphabetic This Char represents only Alphabetic values and spaces are left justified.

Examples:

IDENTIFICATION DIVISION.

PROGRAM-ID. HELLOCOBOL.

DATA DIVISION.

WORKING-STORAGE SECTION.

01 WS-A PIC 9(3).                                                          –> 000

01 WS-B PIC 9(3) VALUE 1234.                                 –> 123

01 WS-C PIC S9(3)V9(2).                                             –>+000.00

01 WS-D PIC S9(3) VALUE 1234.                               –>+234

01 WS-E PIC A(5) VALUE ‘ABCDEF’.                        –>ABCDE

01 WS-F PIC X(4) VALUE ‘A1211’.                            –>A121

PROCEDURE DIVISION.

DISPLAY “WS-A : “WS-A.

DISPLAY “WS-B : “WS-B.

DISPLAY “WS-C : “WS-C.

DISPLAY “WS-D : “WS-D.

DISPLAY “WS-E : “WS-E.

DISPLAY “WS-F : “WS-F.

STOP RUN.

 

Editing Characters for data items:

These characters are used to edit the numeric data before printing in the reports.

Char Meaning
.(Period) This Char represents decimal position in the numeric value. Ex-PIC 9(3).9(2)
,(comma) This Char is used to represent amount values. Ex-PIC 99,999,99
+(plus) This Char represents positive sign.it will represent + when the value is positive. Ex-PIC 999+ or PIC +999
-(minus) This Char represents negative sign.it will represent – when the value is negative. Ex-PIC 999- or PIC -999
*(asterisk) This Char replace leading zeroes with “*”. Ex-PIC ***99
$(Dollar) This Char represents one “$” appear to the left most position of PIC clause. Ex- PIC $999
Z This Char replace all leading zeroes with spaces. Ex-PIC ZZ999
/(Slash) This Char used in the date values. Ex- Pic 99/99/9999
B(Blank) This Char insert a space in that position. Ex-PIC 99B9.99
0(Zero) This Char insert “0” in that position. Ex-PIC 990099.
Blank when zero This Clause is used with the PIC clause is the value in the data item is zero and display blanks. Ex- PIC 999 BLANK WHEN ZERO.

 

 

About the author

Add comment

By neelam

Find us

Address
Chennai ,Tamil Nadu,603103

Hours
Monday—Friday: 9:00AM–5:00PM
Saturday & Sunday: 11:00AM–3:00PM

About This Site

This site is to help the beginners in COBOL.

Categories