Summary -

In this topic, we have explained User-defined Words with detailed examples.

A User-defined word is a COBOL word supplied by the user to fulfill the clause or statement construction. The user-defined word maximum length is 30 bytes except for level-numbers and priority-numbers.

Rules -

  • User-defined word should be on and only one and unique within the type to which it belongs to(that might be a program, paragraph etc).
    Example -
    01 WS-VAR1 PIC X(05).
    WS-VAR1 should be unique in the program where it is declared.
  • Level number and segment number may not be unique.
    Example -
    01 WS-VAR1 PIC X(05).
    05 WS-VAR2  PIC X(05).
  • User-defined word can be duplicated when the reference can be maintained in condition-names, data-names, record-names, paragraph-names and text-names.
    Example -
    01 WS-GRP1.
    	05 WS-VAR1 PIC X(05).
    01 WS-GRP-BACKUP.
    	05 WS-VAR1 PIC X(05).
    The above declaration is valid as it has a reference and should be represented as -
    WS-VAR1 OF WS-GRP1
    WS-VAR1 OF WS-GRP-BACKUP
    In this case, the two representations consider as two different variables.

The below list specifies some types of user-defined names –

User-defined name types Rules
Alphabet-name
Condition-name
Constant-name
Data-item-name
File-name
Index-name
Mnemonic-name
Program-name (Using in PROCEDURE linkage)
Record-name
Routine-name
Each word atleast have one letter.
Library-name
Program-name(using PROGRAM linkage)
Text-name
Each word atleast have one letter.
First 10 character should be unique word.
Paragraph-name
Section-name
Word may need not contain alphabetic character.
Level-numbers Each word may contain 1 or 2 digits.
It does not have to be unique.

Example -

The below list shows the examples for each type of user-defined name -

User-defined name Some Examples
Alphabet-name
SPECIAL-NAMES. 
    ALPHABET SORT-SEQ IS "A" THROUGH "Z"
                         "a" THROUGH "z".
SORT-SEQ is the alphabet-name.
Condition-name
05 STD-GENDER PIC A(06).
	88 STD-MALE VALUE "MALE".
	88 STD-FEMALE VALUE "FEMALE".
STD-MALE, STD-FEMALE are the condition-names.
Constant-name
01 WS-PI      PIC 9.99 VALUE 3.14.
WS-PI is the constant-name.
Data-item-name
05 WS-VAR     PIC X(05).
WS-VAR is the data-item-name.
File-name
FILE-CONTROL.
	SELECT INPUT-FILE ASSIGN TO DISK01.
INPUT-FILE is the file-name.
Index-name
01 BTECH-1ST-YEAR.
    03 SUBJECT-MARKS    PIC 9(03) OCCURES 6 TIMES
				INDEXED BY MARKS-INDEX.
MARKS-INDEX is the index-name.
Mnemonic-name
SPECIAL-NAMES.
    SRW IS SORT-SWITCH ON STATUS IS SORT-ON.
SRW is the mnemonic-name.
Paragraph-name
	PERFORM PARA-DISPLAY 10 TIMES.
	.
	.
PARA-DISPLAY.
	.
PARA-DISPLAY is the paragraph-name.
Program-name
PROGRAM-ID. MTHPROG1.
MTHPROG1 is the program-name.
Record-name
01 WS-REC.
	05 WS-REC-KEY PIC X(10).
	05 FIELD1     PIC X(10).
	.
	.
WS-REC is the record-name.
Routine-name
CALL ROUTINE1 USING variable-1, variable-2.
ROUTINE1 is the routine-name.
Section-name
SEC-ADDITION SECTION.
SEC-ADDITION is the section-name.
Key-name
FILE-CONTROL.
	SELECT INPUT-FILE ASSIGN TO DISK01.
		.
		.
	RECORD KEY IS WS-REC-KEY.

	01 WS-REC.
		05 WS-REC-KEY PIC X(10).
		05 FIELD1     PIC X(10).
		.
		.
WS-REC-KEY is the key-name.
Symbolic-character
SYMBOLIC CHARACTERS BACKSPACE IS 23.
BACKSPACE is the symbolic-character.
Text-name
05 WS-MTH PIC X(20) VALUE "MAINFRAMESTECHHELP".
WS-MTH is the text-name.