Character Set


Characters are the basic unit of any programming language, and a set of valid characters createscharacter set. Characters include letters (both uppercase and lowercase), digits, and special characters.

Similarly, the COBOL language has its own set of valid characters (78) that contains alphabets(A-Z/a-z), digits(0-9), and special characters.

The list of primary COBOL characters is as follows –

CharacterMeaningUsageExample
SpaceSeparating character
01 WS-A   PIC X(10).
+Plus Arithmetic operator
COMPUTE WS-A = WS-B + WS-C.
Editing character
01 WS-A   PIC +9(3).
-Minus or hyphenArithmetic operator
COMPUTE WS-A = WS-B - WS-C.
Editing character
01 WS-A   PIC -9(3).
Continuation character
----+----1----+----2----+----3----+
       01 WS-VAR  PIC X(27) VALUE 
      -     'THIS IS MULTI-LINE'.
COBOL word element
01 WS-A   PIC 9(3).
*AsteriskArithmetic operator
COMPUTE WS-A = WS-B * WS-C.
Editing character
01 WS-A   PIC **9.
Comment character
----+----1----+----2----+----3
      * THIS IS COMMENT LINE.
/Forward slash or solidusArithmetic operator
COMPUTE WS-A = WS-B / WS-C.
Editing character
01 WS-DATE   PIC 99/99/99.
Continuation character
----+----1----+----2----+----3----+
      /01 WS-VAR  PIC X(27) VALUE 
      /     'THIS IS MULTI-LINE'.
=Equal signSeparating character
COMPUTE WS-A = WS-B / WS-C.
Relation character
IF WS-A = 10
$Currency signEditing character
01 WS-SALARY     PIC $$99.
,CommaEditing character
01 WS-SALARY   PIC 99,999.
Separating character
MOVE 10 TO WS-A, WS-B.
;SemicolonSeparating character
MOVE 10 TO WS-A; WS-B.
.Decimal point or periodEditing character
01 WS-SALARY   PIC 99,999.00.
Separating character
MOVE 10 TO WS-A.
"Quotation mark Separating character
01 WS-VAR   PIC X(5) VALUE "HELLO".
'Apostrophe Separating character
01 WS-VAR   PIC X(5) VALUE 'HELLO'.
(Left parenthesisSeparating character
IF (WS-A = 10) AND (WS-B = 5)
)Right parenthesisSeparating character
IF (WS-A = 10) AND (WS-B = 5)
>Greater than Relational character
 IF WS-A > 10
<Less thanRelational character
IF WS-A < 10
:ColonRelational character
 MOVE WS-VAR(1:10) TO WS-VAR1.
_UnderscoreUser-defined word element
 01 WS_VAR PIC X(10).
A - ZAlphabet (uppercase)Alphabetic characters
01 WS-A PIC X(10).
a - zAlphabet (lowercase)Alphabetic characters
01 ws-a pic x(10).
0 - 9Numeric charactersNumeric characters
01 WS-A PIC 9(10) VALUE 1234.
Note! Read this topic again after reading Divisions and Variable declaration topics to get a clear understanding.