Home About the Ghast

Cobol tutorial for Beginners

Author Title Year
Miss Google. Cobol tutorial for Beginners | Cobol Essential Training,3H49 2022.

Are you ready to get started?

COBOL is a procedural language.

What is JCL?

JCL, Job Control Language- the scripting language for running COBOL programs

Obtain input from the user

COBOL naming standards

How to define types of data

Variables are defined in cobol in the following way:

Level Numbers

Comp-3 data types

comp-3 in cobol is a "packed decimal". This compresses numbers to half their size.

This tells computers to use decimal arithmatic and not floating point.

comp-3 is declared immediately after the pic clause

Literal and figurative constants

Numeric literal can have 18 digits

figurative constants can be things like "high-values", "zeroes", etc.

Editing characters for writing reports

Introducing to verbs

some verbs have ending verbs: read/end-read, if/end-if

Computational verbs

Verbs that perform calculations

ADD add digits

Suppose A is 5, B is 7, C is 1

SUBTRACT performs subtraction

A 5, B 7, C 20, D 10

MULTIPLY

A 5, B 7, C 20

DIVIDE

A 5, B 7, C 20

COMPUTE

Allows you to do math using operators

classic method

  1. MULTIPLY A * A GIVING A-SQUARED
  2. MULTIPLY B * B GIVING B-SQUARED
  3. ADD A-SQUARED TO B-SQUARED GIVING C-SQUARED
  4. COMPUTE C = (C-SQUARED)**.5

pure compute method

  1. COMPUTE C = (A * A + B * B)**.5

compute statements always begin with the resulting variable set equal to the desired equation.

Conditional expressions

IF, END-IF

IF, ELSE, END-IF

Nested IF statements

can test for things:

COMPARE

EVALUATE

Perform statement

Cobol is sequential. It starts at the beginning and executes commands until told otherwise.

The GO TO command has a limited use case, generally only for error handling, to close the files and end the program.

Perform times

"PERFORM __ UNTIL __" lets you define loops.

Challenge: Process payroll

START HERE

Solution: Sample program to process payroll

Inserting records in a master data file

Updating records in a master file

Sorting records in COBOL

Merging records in COBOL

Challenge: Merge two employee files

Solution: Create a master employee file

Direct access files in COBOL

Relative files in COBOL

Indexed files in COBOL

Challenge: Create an indexed file

Solution: Solution for creating an indexed file

Using tables in COBOL

Creating tables from an input file

Searching tables in COBOL

Challenge: Create table of weather data

Solution: Search table of weather data

Inspecting strings in COBOL

Using the string command in COBOL

Using the unstring command in COBOL

Watch for numeric overflow in variables

How to read and find logic errors

Finding answers to your COBOL questions