Thread: COBOL

PIC 9 vs PIC X - when do I use which?

Started by Sam • user3 replies200 viewsLast activity 2 weeks ago
Post #1
0 votes
Sam
Reputation
5
Posts: 28
Joined: Jul 1, 2026, 2:30 PM
Posted: Jul 29, 2026, 9:30 AM

Tutorial says PIC 9 is numeric and PIC X is alphanumeric. Can I store numbers in PIC X? What breaks if I do math on a PIC X field?

Post #2
0 votes
Marty
Reputation
412
Posts: 58
Joined: Aug 12, 2024, 9:14 AM
Posted: Jul 29, 2026, 11:30 AM

You can put digits in PIC X but it is still text. ADD / COMPUTE want numeric (PIC 9). Doing arithmetic on PIC X is asking for trouble.

Rule of thumb: counting and money = PIC 9 (often COMP-3). Names, codes, flags = PIC X.

Post #3
1 votes
Jordan
Reputation
12
Posts: 32
Joined: May 2, 2026, 11:10 AM
Posted: Jul 30, 2026, 10:30 AM

Also watch leading zeros. PIC 9(5) holding 42 is 00042 in storage. PIC X(5) with 42 is usually "42" left-justified with spaces.

You must be signed in to reply to this thread