Summary -

In this topic, we have explained Character Strings with detailed examples.

  • Character-string is a single character or set of adjacent characters that can create a COBOL word, literal, a PICTURE string, or a comment.
  • Separators delimit character strings.

Character-strings are used to create the below objects -

Character string types Description
COBOL Word A COBOL word is a set of characters that creates a user-defined word, a system name, or a reserved word.
Variable A Variable is an identifier used to hold the value for processing in the program.
Literal A literal is a group of characters or a group of words, or a figurative constant.
Constant A constant is a variable that contains a unique value throughout the program execution and doesn't change in the middle.
PICTURE string PICTURE clause is used to specify the type of the variable. i.e., variable type, length, etc.
Comment A comment is a group of characters used to provide the notes about the code or the information about tasks coded in the program.

Example -

Below list shows the examples for each character-string -

Type Some Examples
Words
Type Some Examples
COBOL User-defined Words
WS-VAR
VAR
PARA-ADD
PARA-SUBTRACT
...
Keywords / Reserved Words
MOVE
IF
PERFORM
...
Literals
"HELLO WORLD"
"123"
123
9
...
Variables
WS-A
VAR
A12
WRITE1
MOVE1
...
PICTURE Character String
PIC A(20).
PICTURE A(20).
PIC 9(10).
PIC X(25).
...
Comment
----+----1----+----2----+----3
      * This is a comment.
Note! The astrik (*) should be coded in the column 7 to make it as comment.

Practical Example -

Below screenshot describes how the different types of words formed using character sets in COBOL programming.

Character String Code example