Skip to main content

🚀 COBOL Statements – Part 1


📥 ACCEPT & 🖨️ DISPLAY

✅ ACCEPT

The ACCEPT statement is used to:

  • Take input from the user

  • Fetch system values like the current date or time

It reads values and stores them in specified variables. Often used for interactive programs or system timestamp capturing.

		ACCEPT WS-DATE FROM DATE.

✅ DISPLAY

The DISPLAY statement is used to output:

  • Messages

  • Variable values

  • Literals or a combination of both

It shows output on the terminal or logs (e.g., SYSOUT in mainframe environments).

		DISPLAY "The value is: " WS-VALUE.`

♻️ INITIALIZE

The INITIALIZE statement sets default values to data fields automatically, instead of using multiple MOVE statements.

What it does:

  • Sets spaces for alphanumeric fields

  • Sets zeros for numeric fields

  • Skips FILLER fields

  • Skips fields controlled by OCCURS DEPENDING ON


INITIALIZE WS-CUSTOMER-RECORD.

✅ INITIALIZE REPLACING

This variant lets you assign a custom value to fields instead of zeros or spaces.

A clean way to "reset" fields before reuse in data processing.


➡️ MOVE

The MOVE statement transfers data from a source field to one or more destination fields.

✅ Key Features:

  • Only one source allowed

  • Can have multiple destinations

  • Works on group-level or elementary data

  • Alignment depends on the JUSTIFIED clause of receiving fields

		MOVE "TINA" TO WS-NAME.

🧩 MOVE CORRESPONDING

Moves only matching fields by name between group-level items.

		MOVE CORRESPONDING GROUP-A TO GROUP-B.

✂️ Reference Modification

Allows partial move from a string or field.

		MOVE WS-NAME(1:4) TO WS-FIRST-NAME.`

🔄 De-editing

Moves data from a numeric-edited field to a pure numeric field, removing formatting.

MOVE is the most frequently used COBOL statement, ideal for data transfers and initialization.


🛑 Program Termination Statements

These statements help define program flow control, especially between main programs and sub-programs.

StatementUse InDescription
STOP RUNMain ProgramTerminates program and returns control to the OS
EXIT PROGRAMSub-programReturns control to the calling (main) program
GOBACKBothReturns to the caller or to the OS depending on context
EXITParagraphsDoes nothing functionally, used to mark end of paragraph

These ensure proper exit and control return, especially in modular, structured programs.


➗ Arithmetic Operations

COBOL provides basic and compound arithmetic statements.

✅ Standard Operations:

		ADD A TO B 
SUBTRACT A FROM B
MULTIPLY A BY B
DIVIDE A BY B

✅ Special Clauses:

  • GIVING: Stores result in a new field

  • REMAINDER: Captures leftover in division

  • ROUNDED: Rounds decimal overflow values

		ADD 10 TO 20 GIVING WS-RESULT
COMPUTE WS-AVG ROUNDED = 5.5 / 2
DIVIDE 10 BY 3 GIVING WS-QUOT REMAINDER WS-REM

✅ COMPUTE Statement

Performs compound arithmetic expressions in a single line:

		COMPUTE WS-RESULT = (WS-A + WS-B) * WS-C / WS-D.`
  • Supports parentheses and multiple operators

  • Useful for clean, mathematical expressions

Prefer COMPUTE when working with multiple operations or nested expressions.