HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to COBOLVariablesArithmeticConditions (IF)Loops (PERFORM)
REFERENCE
📖 Overview
🖥️ Structure & Output
📦 Variables
🔢 Arithmetic
COMPUTE / ADDFUNCTION MOD
🔀 Condition
🔁 Loop
COBOL›REFERENCE›Arithmetic
🔢

Arithmetic

COMPUTE, ADD, and FUNCTION MOD.

CommandDescription
COMPUTE / ADDPerforms calculations.
FUNCTION MODReturns the remainder of a division.

COMPUTE / ADD

Try it yourself →

Performs calculations.

Syntax

COMPUTE R = a + b.   ·   ADD a TO b.

Description

COMPUTE calculates with formulas (* / + - ** ). ADD/SUBTRACT/MULTIPLY/DIVIDE are separate statements. The result is written to a variable.

Example

       IDENTIFICATION DIVISION.
       PROGRAM-ID. H.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 R PIC 9.
       PROCEDURE DIVISION.
           COMPUTE R = 3 + 4.
           DISPLAY R.
           STOP RUN.

Expected output

7

When to use?

Calculations.

FUNCTION MOD

Try it yourself →

Returns the remainder of a division.

Syntax

COMPUTE R = FUNCTION MOD(a b).

Description

FUNCTION MOD(a b) returns the remainder of a divided by b.

Example

       IDENTIFICATION DIVISION.
       PROGRAM-ID. H.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 R PIC 9.
       PROCEDURE DIVISION.
           COMPUTE R = FUNCTION MOD(23 4).
           DISPLAY R.
           STOP RUN.

Expected output

3

When to use?

Even/odd, periodic calculation.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code