Thread: COBOL

How do I define a variable in COBOL?

Started by Alex • user4 replies314 viewsLast activity 2 weeks ago
Post #1
1 votes
Alex
Reputation
8
Posts: 35
Joined: Jun 15, 2026, 9:20 AM
Posted: Jul 31, 2026, 8:44 AM

Sorry if this is dumb. Coming from Python where you just write x = 5.

Where do variables go in COBOL and what is PIC supposed to mean? I keep seeing stuff like:

01 WS-COUNT PIC 9(3).

Do I put that in WORKING-STORAGE? And what is the 01 for?

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

Yes, WORKING-STORAGE SECTION under DATA DIVISION.

PIC (PICTURE) describes the shape: 9 = digit, X = any character. 9(3) means three digits. 01 is the level number for a top-level item.

Example:
01 WS-NAME PIC X(20).
01 WS-COUNT PIC 9(3) VALUE 0.

Post #3
0 votes
Tyler
Reputation
34
Posts: 19
Joined: Nov 8, 2025, 1:44 PM
Posted: Jul 31, 2026, 12:44 PM

I had the same confusion week one. Think of PIC as the type + length stuck together. Not separate like int count = 0.

Post #4
1 votes
Alex
Reputation
8
Posts: 35
Joined: Jun 15, 2026, 9:20 AM
Posted: Jul 31, 2026, 4:44 PM

Ok that clicked. So PIC X(10) is basically a 10-char string. Thanks.

You must be signed in to reply to this thread