COBOL

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/41

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

42 Terms

1
New cards

What is COBOL?

Common Business Oriented Language. Developed around 1950s. High level programming language for business applications. English like, imperative, procedural, object oriented since 2002. Around 80% of world businesses run on COBOL like govt, banks. over 60% of organizations use cobol. 60 million patient data, 95% ATM transactions, 96% vacations booking, etc.

latest release of IBM COBOL - Enterprise COBOL for z/OS - Version 6 Release 4 - 2022-05-27


latest release of COBOL : COBOL-2023

it has the following area in the pgm:

column numbers: 1 to 6 - Reserved for line numbers.

Indicator - 7 - It can have Asterisk (*) indicating comments, Hyphen (-) indicating continuation and Slash ( / ) indicating form feed.

Area A: 8 to 11 column - All COBOL divisions, sections, paragraphs and some special entries must begin in Area A.

Area B: 12 to 72 - All COBOL statements must begin in area B.

Identification area: 72 to 80 - It can be used as needed by the programmer.

2
New cards

Structure of COBOL program

  1. IDENTIFICATION DIVISION - supply info about the program such as program name, name of the programmer

  2. ENVIRONMENT DIVISION - describes the environment in which the program will run, such as the source and object computer.

  3. DATA DIVISION - provides the description of data to be processed by the program such as input and output files

  4. PROCEDURE DIVISION - code of the program.

    Each division has sections which has paragraphs which has statements

division → sections → paragraphs → statements

3
New cards

HELLO world

We have to at least give 2 divisions to execute a Hello world program. These are:

IDENTIFICATION DIVISION

PROCEDURE DIVISION

Divisions have to be given at position 8 and statements have to be given at position 12.

IDENTIFICATION DIVISION. *identifying the program

PROGRAM-ID. HELLOWORLD. *name of the program

PROCEDURE DIVISION. *real code starts from here

DISPLAY “HELLO WORLD“. *real code of the program

STOP RUN. *end the program here

4
New cards

IDENTIFICATION DIVISION.

First division. Used to identify a program. PROGRAM-ID is required.

program-id max 8 char on IBM mainframe. can be alphabets, numbers and hyphen. should not start with hyphen.

can have other optional fields like-

Author. KIRTHIKA

INSTALLATION. MTH.

REMARKS. PRACTICE CODE.

DATE-COMPILED. 12-MAY-2025.

DATE-WRITTEN. 12-MAY-2025.

SECURITY. NORMAL.

These can also be mentioned in the comments.

5
New cards

WORKING-STORAGE SECTION.

This is given in the DATA DIVISION.

Used to identify the data associated with a program such as the variables of the program.

DATA DIVISION.

WORKING-STORAGE SECTION.

01 MY_NAME PIC XXXX.

To define a variable give a 2 digit number called level number in AREA A (8 to 11), followed by the variable name in AREA B (12 to 72).

Level numbers are used to tell whether the variables are related or not. Related variables are grouped together. Unrelated variables can be given level number 77..

Variable name can be a max of 30 characters.

Variables are called Data names or data items in COBOL.

It can have alphabets, digits or hyphen.

Name should not start or end with hyphen.

PICTURE is used to tell the type of the variable.

9 means - numerical

X means alphanumeric

DATA DIVISION.

WORKING-STORAGE SECTION.

01 MY-NAME.

05 FIRST-NAME PIC X.

05 LAST-NAME PIC X.

77 AGE PICTURE 99.

6
New cards

PICTURE clause

it is used to tell whether the data item (variable) can contain numeric, alphabets etc.

It is given after the name of the data item.

item type Characters Meaning eg

Alphanumeric X Any Character PIC X.

PIC XXX.

PIC X(3).

Numeric 9 Digit PIC 99

S Sign PIC S999

V Assumed Decimal point PIC S9(5)V99

Number edited 9 Digit PIC 99

Z Zero suppressed digit PIC ZZ9

, Inserted comma PIC ZZZ,ZZZ

. Inserted decimal point PIC ZZ,ZZZ.99. don’t give zzv99 decimal will not come use “.” to insert decimal.

- Minus sign if negative PIC ZZZ,ZZZ-

Each character or digit require only one byte of storage.

7
New cards

VALUE Clause

Can be used to give a starting value to a variable. The most common way is to assign a figurative constant to a variable for example ZEROES or SPACES. Initializing the variables (data item).

DATA DIVISION.

WORKING-STORAGE SECTION.

01 INCOME PIC 9(2) VALUE ZEROES.

8
New cards

GROUP items

Related data items could be grouped together. Level numbers are used for this grouping. The top item is called group item and the child items are called elementary items.

Group item cannot have a picture clause.

Group item must begin in AREA A.

Level numbers from 01 to 49 can be used.

DATA DIVISION.

WORKING-STORAGE SECTION.

01 NAME.

05 FIRST-NAME PIC X(10).

05 LAST-NAME PIC X(10).

Data items unrelated to each other can be given level numbers of 77.

9
New cards

Coding the PROCEDURE division

PROCEDURE DIVISION.

000-CALC-TOTAL-MARKS.

PERFORM 100-CALCULATE-PHYSICS-MARKS

PERFORM 100-CALCULATE-BIOLOGY-MARKS

PERFORM 100-CALCULATE-MATH-MARKS

STOP RUN.

100-CALCULATE-PHYSICS-MARKS.

code

100-CALCULATE-MATH-MARKS.

code

Procedure names can have a maximum of 30 characters.

It can contain digits, alphabets and hyphen but the name should not start or end with hyphen.

Procedure names should start in Area A and the statements should be in AREA B.

10
New cards

Statements

Display statement to display data on the screen or terminal.

MOVE is used to move literal or sending field to a receiving field.

If sending field is smaller then zeroes (for numeric) and spaces (for alphanumeric) will be added.

If sending field is larger then value will be truncated. For number right to left will to taken eg: N1 PIC 99. MOVE 123 to N1. N1 will be 23 and alphanumeric left to right eg: V1 pic XX. MOVE ‘KIR’ to V1. V1 will be KI.

ACCEPT is to get input from the user.

PERFORM: Used to execute a procedure. Code can be divided into a set of paragraphs known as procedures. Control is passed to the procedure named in the PERFORM statement. After all the statements in the procedure are executed then the return comes back to the next statement after the perform.

STOP RUN: is used to end the execution of the program. It is coded only once in a program. It is generally the last statement in the main procedure.

11
New cards

Datasets needed for executing COBOL on z/os

  1. Dataset for writing COBOL program.

  2. Dataset for writing compile JCL and run JCL.

  3. Dataset for storing load module - record format - undefined, record length = 0

first 6 columns for seq numbers then divisions will come so we can give this to start every line from column 8 instead of 1 - num on std cob then F10. Sequence number will be automatically generated.

12
New cards

COBOL program compilation

2 step process:

  1. cobol program (high level language) is compiled(Uses IGYCRCTL utility) to object module (machine code and non-executable). If any copybooks are there it will be applied in this step. Error will be in compiler output in the spool.

  2. link edit- all the sub programs used by the main program will be linked to the main program and load module(executable) will be generated. Uses HEWL/ IEWL/ IEWBLINK etc - binder programs. Error will be in Link editor output in the spool.

IBM provides a cataloged procedure IGYWCL which does the whole process in one JCL. This is located at IGY*.SIGYPROC

Following DD statements are required by the procedure IGYWCL:

  1. SYSIN → Location of COBOL pgm

  2. SYSLIB → location of copybooks

  3. SYSLMOD → Output load module library

Then run execution JCL to run the code

EXEC PGM=HELLO

JOBLIB
SYSIN if any

SYSOut = *

13
New cards

ADD statement and COMPUTE statement

ADD A TO B → COMPUTE B=B+A

ADD 1 TO B → COMPUTE B=B+1

ADD A TO B GIVING C → COMPUTE C=B+A

ADD A B C TO D → COMPUTE D=A+B+C

We can use ON SIZE ERROR and ROUNDED on our results:

ADD A TO B ROUNDED → COMPUTE B ROUNDED=B+A

ADD A TO B ON SIZE ERROR DISPLAY “ERROR“ → COMPUTE B=B+A ON SIZE ERROR DISPLAY “ERROR“

14
New cards

SUBTRACT statement

SUBTRACT A FROM B → compute can be used as COMPUTE B=B-A

SUBTRACT A B C FROM D → compute can be used as COMPUTE D = D - (A + B + C) or COMPUTE D = D - A - B - C

SUBTRACT A FROM B GIVING C→ compute can be used as COMPUTE C=B-A

15
New cards

MULTIPLY statement

MULTIPLY A BY B → COMPUTE B = B * A

MULTIPLY A BY B GIVING C→ COMPUTE C = B * A

MULTIPLY A BY B ON SIZE ERROR DISPLAY “ERROR“

NOT ON SIZE ERROR DISPLAY “NO ERROR“ B.

16
New cards

DIVIDE STATEMENT

DIVIDE A INTO B → COMPUTE B=B/A

DIVIDE A BY B GIVING C → COMPUTE C=A/B

DIVIDE A BY B GIVING C REMAINDER D → NO CORRESPONDING COMPUTE

17
New cards

COMPUTE STATEMENT

USED TO DO ARITHMETIC OPERATIONS IN COBOL PGM:

COMPUTE B = B + A

COMPUTE B = B - A

COMPUTE B = B * A

COMPUTE B = B / A

COMPUTE B = B ** A

COMPUTE B ROUNDED = B + A

COMPUTE B = B + A ON SIZE ERROR DISPLAY “ERROR“

18
New cards

ORDER OF PRECEDENCE OF MATHEMATICAL STATEMENTS

EXPONENTIAL (**) DONE FROM LEFT TO RIGHT

MULTIPLICATION (*) AND DIVISION (/) DONE FROM LEFT TO RIGHT

ADDITION(+) AND SUBTRACTION(-) DONE FROM LEFT TO RIGHT

IF PARENTHESIS EXISTS THEN EVERYTHING IN THE BRACKET IS SOLVED FIRST.

19
New cards

FUNCTIONS IN COBOL

There are over 42 inbuilt functions in COBOL.

they are also called intrinsic functions

These were added in 1989 to the COBOL-85 standard. These are of 6 types.

SYNTAX: FUNCTION function-name(arguments)

Mathematical such as SUM, SQRT → eg: FUNCTION SUM(13,22) or FUNCTION SUM(13 22)

Statistical → MEAN, MAX, MIN
Character → REVERSE, LENGTH eg: FUNCTION LENGTH(‘abcdef’) → 6

Date → CURRENT-DATE

Financial → PRESENT-VALUE

Trigonometric → SIN, COS

Functions can be used within a COMPUTE statement:

COMPUTE C = FUNCTION MAX(13,22,89) + FUNCTION SUM(29 22) / 2

20
New cards

MATHEMATICAL FUNCTIONS

SUM → FUNCTION SUM(13 22 89) O/P:

SQRT → FUNCTION SQRT(9) O/P: 3

REM → FUNCTION REM(12 2) O/P: 0 REMAINDER - WE CAN GIVE DECIMAL

MOD → FUNCTION MOD(12 2) O/P: 0 HERE ALSO WE CAN GIVE DECIMAL BUT REM IS USED FOR THAT

FACTORIAL → FUNCTION FACTORIAL(5) O/P: 120

LOG → FUNCTION LOG(1) O/P: 0

LOG10 → FUNCTION LOG10(1) O/P: 0

INTEGER → FUNCTION INTEGER(4.5) O/P: 4 IT WILL TAKE LESSER VALUE

FUNCTION INTEGER(-4.2) O/P: -5

INTERGER-PART FUNCTION INTEGER-PART(4.5) O/P: 4 IT WILL IGNORE ANYTHING AFTER DECIMAL AND DISPLAY

FUNCTION INTEGER-PART(-4.2) O/P: -4

NUMVAL → FUNCTION NUMVAL(" 10 ") O/P: 000000010 - WILL REMOVE SAPCES AND GIVE THE NUMERICAL VALUE WILL NOT REMOVE $

NUMVAL-C → FUNCTION NUMVAL-C("$ 10 "). O/P: 000000010 - WILL REMOVE SAPCES AND GIVE THE NUMERICAL VALUE WILL ALSO REMOVE $

RANDOM → FUNCTION RANDOM(5) O/P: 0.2747455962350339 - WILL GENERATE RANDOM VALUE IN DECIMAL ALWAYS

21
New cards

STATISTICAL FUNCTIONS

MEAN

MEDIAN

STANDARD-DEVIATION

VARIANCE

RANGE

MID-RANGE

MAX

MIN

ORD-MAX

ORD-MIN

22
New cards

CHARACTER FUNCTIONS

LENGTH

REVERSE

UPPER-CASE

LOWER-CASE

ORD - finds the ordinal position of the collating sequence

CHAR - finds the character based on the ordinal position

23
New cards

FINANCIAL FUNCTIONS

ANNUITY: FUNCTION ANNUITY(INTEREST-RATE NUMBER-OF-PERIODS)

used to find the installment value for the loan

PRESENT-VALUE: FUNCTION PRESENT-VALUE(INTEREST-RATE PAYMENT-VALUE1 PAYMENT-VALUE2..)

used to find the present value for the series of future payments

24
New cards

TRIGONOMETRIC FUNCTIONS

SIN

COS

TAN

ASIN

ACOS

ATAN

25
New cards

IF STATEMENT

IF CONDITION

……………….

……………….

ELSE

……………….

……………….

END-IF.

26
New cards

NESTED IF

IF CONDITION

……………….

……………….

ELSE IF CONDITION

……………….

……………….

ELSE

IF CONDTION

……………….

ELSE

……………….

END-IF.

27
New cards

PERFORM UNTIL STATEMENT

PERFORM PROCEDURE-NAME UNTIL CONDITION

……………….

……………….

STOP RUN.

Used to execute a procedure in a loop.

Control is passed to the procedure named in the PERFORM statement.

After all the statements in the PROCEDURE are executed then the condition is checked again.

The procedure keeps on executing until the condition becomes true.

28
New cards

PERFORM WITH TEST AFTER

PERFORM DISPLAY-PARA

WITH TEST AFTER

UNTIL I > 5

DISPLAY-PARA.

DISPLAY “HELLO WORLD“

COMPUTE I = I +1

The default option is WITH TEST BEFORE.

TEST AFTER: execute the code first then check condition

TEST BEFORE: check the condition first then execute the code

29
New cards

PERFORM with VARYING clause

PERFORM COMPOUND-INTEREST-CAL

VARYING YEARS FROM 1 BY 1

UNTIL YEARS > 5

30
New cards

PERFORM WITH TIMES CLAUSE

To execute multiple times:

PERFORM COMPUND-INTEREST-CALCULATION 5 TIMES

PERFORM COMPOUND-INTEREST-CALC NO-OF-YEARS TIMES

31
New cards

EVALUATE statement

The conditions are checked in sequence. Once the conditions becomes true the EVALUATE is exited.

EVALUATE AGE

WHEN 15 DISPLAY “YOU ARE 15“

WHEN 13 DISPLAY “YOU ARE 13“

WHEN 22 DISPLAY “YOU ARE 22“

WHEN 29 DISPLAY “YOU ARE 29“

WHEN OTHER DISPLAY “YOU ARE NON OF THE ABOVE“

END-EVALUATE.

EVALUATE TRUE

WHEN AGE > 18 DISPLAY “YOU ARE AN ADULT“

END-EVALUATE.

EVALUATE GENDER ALSO AGE > 18

WHEN “FEMALE” ALSO TRUE DISPLAY “YOU ARE ELIGIBLE“

END-EVALUATE.

More than 2 conditions check:
EVALUATE GENDER ALSO AGE-GROUP ALSO CITIZENSHIP

WHEN "FEMALE" ALSO "ADULT" ALSO "USA"

DISPLAY "You are eligible"

WHEN OTHER

DISPLAY "Not eligible"

END-EVALUATE.

AND cannot be used ALSO is the syntax.

  • Make sure the number of ALSOs match between EVALUATE and the corresponding WHEN.

  • All conditions are checked side by side — it’s like comparing rows in a table.

32
New cards

REFERENCE MODIFICATION

MOVE FULL-DATE(3:2) TO MONTH

MOVE FULL-DATE(5:4) TO MONTH

Reference modification can be used to refer a portion of a field.

Syntax:

FIeldname(offset:Length)

If length is omitted then all the characters after offset are selected.

33
New cards

STRING STATEMENT

Used to concatenate two or more fields together.

Delimit by size will send the whole field.

Pointer clause determines the starting position on the receiving field.

Overflow clause will get executed when more characters are sent to the receiving field than it can hold.

STRING FIRST-NAME DELIMITED BY SIZE

LAST-NAME DELIMITED BY SIZE

“ABC” DELIMITED BY SIZE

INTO FULL-NAME

WITH POINTER POINTER-FIELD

ON OVERFLOW DISPLAY “OVERFLOW IS THERE”

NOT ON OVERFLOW DISPLAY “NO OVERFLOW IS THERE”

SIZE will copy whole field with the allocated space. we can delimit it by “ “ or “ “ or till any char “A“ or “$” etc.

If the sting in which we are placing the concatenated string is smaller size than the concatenated string then overflow will occur and the message will be displayed.

Pointer will determine the place from where the copied string will be placed in th output string. pointer pic 9(2) value 4 will point to position 4 of the output field and the strings will be copied in that position.

34
New cards

UNSTRING STATEMENT

UNSTRING FULL-NAME DELIMITED BY “ “

INTO FIRST-NAME MIDDLE-NAME LAST-NAME

TALLYING IN COUNTER1

WITH POINTER POINTER-FIELD

ON OVERFLOW DISPLAY “OVERFLOW IS THERE”

NOT ON OVERFLOW DISPLAY “NO OVERFLOW IS THERE”

END_UNSTRING.

Used to divide a field into two or more fields

Pointer clause determines the starting position in the sending field- if we give pointer-field as 5 then the unstring will happen from position 5.

Overflow clause will get executed when more characters are sent to the receiving field than it can hold.

TALLYING counts the number of receiving fields: means in how many variables was the data copied.

35
New cards

INSPECT STATEMENT

INSPECT can be used to count, replace and convert characters in a string.

FULL-NAME= “KIRTHIKA“

INSPECT FULL-NAME

TALLYING COUNTER1 FOR CHARACTERS BEFORE SPACES. o/p:8

INSPECT FULL-NAME

TALLYING COUNTER1 FOR CHARACTERS AFTER “H“. o/p: 4

INSPECT FULL-NAME

TALLYING COUNTER1 FOR ALL “,”.

EXAM-NAME = “***TAY****SWIFT”

INSPECT EXAM-NAME

TALLYING COUNTER1 FOR LEADING “*”. o/p: 3

INSPECT FULL-NAME

TALLYING COUNTER1 FOR ALL “I” BEFORE “T”. o/p: 1 - how many I are there before T.

TALLYING COUNTER1 FOR ALL “I” AFTER “T”. o/p: 1 - how many I are there AFTER T.

36
New cards

INSPECT STATEMENT with REPLACE clause

Replace can replace characters in a string.

INSPECT FULL-NAME

REPLACING ALL “,” BY “ “.

INSPECT FULL-NAME

REPLACING CHARACTERS BY “0“ AFTER “.”.
INSPECT FULL-NAME

REPLACING LEADING “*” BY ZERO.
INSPECT FULL-NAME

REPLACING ALL “CR” BY “ “.

INSPECT FULL-NAME

TALLYING COUNTER1 FOR LEADING “0”

REPLACING LEADING “0” BY “*”. → this will counter the leading 0 and replace it by *.

37
New cards

INSPECT with CONVERTING clause

INSPECT FULL-NAME
CONVERTING “,” TO “ “.

INSPECT FULL-NAME
CONVERTING “ABCDEFGHIJKLMNOPQRSTUVWXYZ” TO “abcdefghijklmnopqrstuvwxyz“. → will convert all upper case to lower case

similar to replace but no need for all keyword.

38
New cards

TABLE in COBOL

An array in Cobol is called as table. Index starts from 1.

01 WEEK-TABLE.

02 DAY-NAME PIC X(10) OCCURS 7 TIMES. → starts from 1 to 7

MOVE ‘MONDAY’ TO DAY-NAME(1).

MOVE ‘TUESDAY’ TO DAY-NAME(2).

MOVE ‘WEDNESDAY’ TO DAY-NAME(3).

01 WEEK-TABLE VALUE “MONDAY TUESDAY WEDNESDAY “. → this will assign values to DAY-NAME based on length- first 10 will go to DAY-NAME(1) and so on.

02 DAY-NAME PIC X(10) OCCURS 7 TIMES.

Display full table:

PERFORM VARYING I FROM 1 BY 1 UNTIL I >7

DISPLAY DAY-NAME(I)

END-PERFORM.

39
New cards

MULTI LEVEL TABLE

01 STUDENT-TABLE.

05 STUDENTS OCCURS 30 TIMES.

10 STUDENT-NAME PIC X(15).

10 SUBJECTS PIC 9(3) OCCURS 3 TIMES.

Moving values:

MOVE “TAYLOR 13 22 89“ TO STUDENT-TABLE.

or

MOVE “TAYLOR 13 22 89“ TO STUDENTS(1).

DISPLAY STUDENT-TABLE.

DISPLAY STUDENTS(1).

DISPLAY SUBJECTS(1 1). → student 1’s first subject

DISPLAY SUBJECTS(1 2). → student 1’s second subject

40
New cards

Search a TABLE using PERFORM

01 WEEK-TABLE.

05 DAY-NAME PIC X(10) OCCURS 7 TIMES.

01 TO-BE-FOUND PIC X(10) VALUE “FRIDAY“

PERFORM VARYING I FROM 1 BY 1 UNTIL I >7

IF DAY-NAME(I) = TO-BE-FOUND

DISPLAY DAY-NAME(I)

END-IF

END-PERFORM.

41
New cards

Reading a line from Sequential file

42
New cards