COBOL – Common Business Oriented
Language
Ø COBOL is an
application programming language
Ø COBOL implemented
(introduced) by CODASYL in 1950’s
Ø CODASYL – Conference
On Data Systems Languages
Ø COBOL was
standardized by ANSI in 1960’s
Ø ANSI – American
National Standards Institute
Ø COBOL is structured
programming language
Ø COBOL does not
contain any graphics
Ø COBOL is an English
like language which is easily readable
Ø COBOL is easy to
understand, easy to code, easy to write also because 90% of COBOL code runs on
character based environment
Ø COBOL is commercial
programming language mainly implemented to solve business problems
Ø COBOL is very famous
in file handling
Ø COBOL is an 80 byte
record structure divided into different areas as follows…..
COBOL CODING SHEET

Column 1-6
Ø In COBOL column 1-6
defined for COBOL STANDARD NUMBERS. These are auto generated, no need to
declare
Ø COBOL STANDARD
NUMBERS will always appear in yellow color
Column 7
Ø Column 7 in COBOL is
used as continuation column
Ø The possible values
in Column 7 are
1.
/ - Specifies new line (also used for commenting COBOL
lines)
2.
* - it is used for commenting COBOL lines
3.
–(HIPHEN) – Continuation Character
4.
D – Debugging
Column 8-11
Ø It is called as
Area-A also called as Margin-A
Ø In Area-A we can
write
1.
Divisions
2.
Sections
3.
Paragraphs
4.
Level No# (01,77)
Level
No’s we have start from column 8 only
Column 12-72
Ø It is called as
Area-B also called as Margin-B
Ø In Area-B we can
write
1.
Statements
2.
Sentences
3.
Level No# (02-49, 66, 88)
Level
No’s should start from column 12(May or MayNot)
Column 73-80
Ø It is an ignored
field also called as commented field
COBOL RESERVED WORDS
Ø In COBOL programming
we are having some predefined words, they are also called as COBOL RESERVED WORDS
Ø All COBOL RESERVED WORDS are also called as
COBOL VERBS
Ø In COBOL we are
having mainly 3 types of COBOL RESERVED
WORDS. They are………….
1.
Keywords
2.
Optional Words
3.
Figurative Constants
1. KEYWORDS
Ø All Keywords are also
called as COBOL VERBS. The list of Keywords available in COBOL are as
follows…………
1.
ADD
2.
SUBTRACT
3.
DIVIDE etc..
2. OPTIONAL WORDS
Ø Optional Words does
not affect the application programming
Ø EX. GIVING, AFTER, BEFORE, ROUNDED etc…..
3. FIGURATIVE CONSTANTS
Ø All Figurative
Constants will contain a predefined value in it
Ø The list of
Figurative Constants is
EX
HIGHVALUE ZERO
SPACE LOWVALUE
HIGHVALUES ZEROES
SPACES LOWVALUES
ZEROS
Ø ZERO, ZEROS are used
to initialize Numeric Data types
Ø ZEROES is used to
initialize Alphanumeric Data types
Ø SPACE, SPACES is used
to initialize Alphabetic and Alphanumeric Data types
Ø LOWVALUE, LOWVALUES
and HIGHVALUE, HIGHVALUES are mainly used to set lowest and highest ordinal
values. We use LOWVALUE(S) in CICS to initialize the MAPS
USER DEFINED WORDS
Ø In COBOL we can also
use USER DEFINED WORDS
Ø While writing USER
DEFINED WORDS we are having some rules as follows..
1.
USER DEFINED WORDS should not be COBOL RESERVED WORDS
2.
The max length of USER DEFINED WORD is 35 characters
3.
USER DEFINED WORD should not start or end with ‘ – ‘
4.
Possible values are a-z, 0-9, and’ – ‘
5.
The names must be Alphabetic only
6.
Spaces between the characters not allowed
7.
Special characters not allowed in the name field
Ø We have several user
defined words as follows………
1. Statements – Statement is a
collection of COBOL word ending with a period (.)
Statements are two types. They
are
a.
Imperative Statement
b.
Conditional Statement
a. IMPERATIVE STATEMENT – it starts with a
verb and no conditional action is to be taken out
EX. MOVE, DISPLAY etc
b. CONDITIONAL STATEMENT – it starts with a
COBOL VERB and specifies a conditional action to be taken
EX. IF and ELSE, EVALUATE etc..
2. Sentence
Sentence is a collection of Statements
3. Paragraphs
Ø It is a collection of
Sentences
Ø PARAGRAPH must start
from Area-A
Ø PARAGRAPH name may
contain a-z, 0-9 and ‘ – ‘ combinations
Ø The max length of
PARAGRAPH name is 35 characters
Ø Spaces between the
PARAGRAPH name not allowed
4. Sections
Ø It is a collection of
PARAGRAPHS
Ø SECTION is a second
highest unit in COBOL
Ø SECTION always
contain the PARAGRAPHS
5. Divisions
Ø DIVISION is a
collection of SECTIONS
Ø Every SECTION must be
derived from DIVISION only
DIVISIONS in COBOL
Ø In COBOL we are
having 4 divisions. The DIVISION is largest unit in COBOL
Ø The 4 DIVISIONS in
COBOL are
1.
Identification Division
2.
Environment Division
3.
Data Division
4.
Procedure Division
1. IDENTIFICATION DIVISION
Ø This is the 1st
division in COBOL and also it is mandatory for every COBOL program
Ø Identification
division does not contain any Sections
Ø The list of
Paragraphs in Identification division are as follows……
PROGRAM-ID.<NAME>.
AUTHOR.<NAME>
DATE-WRITTEN.<DATE>
DATE-COMPILED.<DATE>
In all the above PARAGRAPH PROGRAM-ID.<NAME>. is mandatory
because PROGRAM-ID.<NAME>. specifies
name of a program written by the user
2. ENVIRONMENT DIVISION
Ø It specifies external
resources using in a program like files and printer etc(data base access)
Ø This is optional.
When we use files in a COBOL program then only it is mandatory
Ø In environment
division we are having mainly 2 sections
1.
Configuration Section
2.
Input – output Section
1. CONFIGURATION SECTION
It is optional. It
contain 3 paragraphs
a.
Source-Computer
b.
Object-Computer
c.
Special-names
These 3 paragraphs are not
required for every program
2. INPUT – OUTPUT SECTION
It is useful for
including the files into a COBOL program. In this we have an important
paragraph FILE-CONTROL
FILE-CONTROL
It is mainly used to
declare the files in program (logical file declaration)
3. DATA DIVISION
It specifies the data
names using in a program (variable names). In this we have 3 sections. They
are……
A.
Linkage Section
B.
File Section
C.
Working-storage Section
A. LINKAGE SECTION
Ø It is also called as
GLOBAL VARIABLE DECLARATION SECTION
Ø Mainly used for
accepting the data from outside the program into currently running application
program (sub routines)
B. FILE SECTION
It is required only when
FILE-CONTROL in ENVIRONMENT DIVISION is declared because FILE SECTION specifies
the attributes of a file
C. WORKING-STORAGE SECTION
Ø It is also called as
LOCAL VARIABLES DECLARATION SECTION
Ø In general this is
alone required for individual COBOL programs to declare a variable
4. PROCEDURE DIVISION
Ø It does not contain
SECTIONS
Ø In procedure division
user can write logic
Ø Procedure division is
also required for every program
NOTE
Ø In COBOL continuation
character is’ – ‘
Ø In COBOL each and
every statement must end with period (.)
Ø It is called as SCOPE
TERMINATOR
Ø In COBOL there are 2
types of SCOPE TERMINATORS. They are…..
1.
IMPLICIT SCOPE TERMINATOR – PERIOD (.)
2.
EXPLICIT SCOPE TERMINATOR
EXPLICIT SCOPE TERMINATOR always
start with the prefix “END-“
EX END-IF
END-EVALUATE
END-PERFORM
etc
Ø In COBOL whenever an
application programmer want to print a data in output area. We use “DISPLAY”
statement. “DISPLAY” will send the data or data of a variable on to the spool
(output section)
Ø In COBOL we can also
receive the data into a program dynamically at run-time by using ACCEPT
statement
DATA NAMES AND ITS RULES
Ø Data Name gives the
reference in the storage
Ø Data Names in general
called as Variable Names
Ø Data Name should not
start or end with ‘ - ‘
EX -AB
AB-
Ø Spaces in the data
name not allowed
EX AB is right A
B is wrong
Ø Data name should
start with alphabet only
Ø Possible values are
a-z, 0-9, and ‘ – ‘
DATA TYPES IN COBOL
In COBOL application programming
language we are having mainly 3 data types
1.
Numeric
2.
Alphabetic
3.
AlphaNumeric
NUMERIC
data types are represented with ‘9’
ALPHABETIC
data types are represented with ‘A’
ALPHANUMERIC
data types are represented with ‘X’
1. Numeric Data Types (9)
Ø The possible values
for Numeric are 0-9
Ø In numeric the
default values 0’s
Ø In numeric the
allocation will be done from right to left
Ø The maximum range is
18 digits
2. Alphabetic (A)
Ø Possible values are
a-z
Ø The default values
are Spaces
Ø Allocation will be
done from left to right
3. Alphanumeric (X)
Ø Possible values are
a-z, 0-9
Ø Default values are
Spaces
Ø Allocation is from
left to right
ALLOCATION OF DATA ITEMS
To declare any data item in COBOL
program we have to follow the structure as follows…..

LEVEL NO#
Ø In COBOL level no#
specifies hierarchy of the COBOL program
Ø In COBOL all level
no’s must be written in ascending order only
Ø The available level
no# are
01
Ø Used as group item as
well as elementary data item
Ø 01 should start from
column 8
02 – it is used as
sub-groups should start in Area-B only
66 – specifies RENAMES
should start in Area-B
77
Ø Pure elementary data
item must begin from column 8
Ø It does not contain
sub-groups
88 – used for condition
checking begin in Area-B
PICTURE CLAUSE (PIC)
Ø Picture Clause
specifies the attributes of a data item
Ø It also specifies the
data types and its properties
Ø In picture clause we
are having 2 types
a.
Edited Picture Clause
b.
Non-Edited Picture Clause
VALUE CLAUSE
Ø By using value clause
we can assign a data for the data item
Ø Depends on data type
we have to write a value
Ø Value clause should
not exceed the length given for the data item
FILLER CLAUSE
Ø Filler is a
predefined word in COBOL mainly used for to allocate spaces between the data
items in group
Ø Filler also used in
files to nullify the unused fields with spaces
NOTE
In COBOL only Identification division
is mandatory and sometimes Procedure division also
PICTURE CLAUSE AND ITS TYPES
Ø Picture Clause always
specifies the attributes of a data item
Ø Picture Clause mainly
divided into 2 types
a.
Edited Picture Clause
b.
Non-Edited Picture Clause
a. Edited Picture Clause
Ø Edited picture clause
mainly used for display purpose
Ø We cant implemented
in arithmetic operations
Ø Edited picture clause
divided into 2 types
A.
Insertion
B.
Suppression
A. INSERTION
In Insertion we are having mainly 4
types
1.
Simple Insertion
2.
Special Insertion
3.
Fixed Insertion
4.
Float Insertion
1. SIMPLE INSERTION
In simple insertion we are having some
possible values
B
– Blank
/
- Inserting ‘ / ‘
0
(zero) – Inserting ‘ 0 ‘
,
- Insering ‘ , ‘
According to the picture clause the
values will be allocated
EX.1 SAMPLE COBOL PROGRAM
ID
DIVISION.
PROGRAM-ID.
PGM1.
DATA
DIVISION.
WORKING-STORAGE
SECTION.
01 A PIC A(3) VALUE 'ABC'.
01 B PIC 9(3) VALUE 456.
01 C PIC X(3) VALUE 'A3C'.
PROCEDURE
DIVISION. OUTPUT
DISPLAY ‘WELCOME TO COBOL’. WELCOME TO COBOL
DISPLAY ‘A VALUE ::’ A. A VALUE::
ABC
DISPLAY ‘B VALUE ::’ B. B VALUE::
456
DISPLAY ‘C VALUE ::’ C. C VALUE:: A3C
STOP RUN.
EX.2
ID
DIVISION.
PROGRAM-ID.
PGM1.
DATA
DIVISION.
WORKING-STORAGE
SECTION.
01 A PIC A(3).
01 B PIC 9(3).
01 C PIC X(3).
PROCEDURE
DIVISION.
DISPLAY ‘WELCOME TO COBOL’.
ACCEPT A.
ACCEPT B.
ACCEPT C.
DISPLAY A.
DISPLAY B.
DISPLAY C.
STOP RUN.
OUTPUT
WELCOME
TO COBOL
ABC
456
A3C
NOTE
Ø By using the ‘VALUE
CLAUSE’ we cant assign a value more the given ‘PICTURE CLAUSE’
Ø But in case of
‘ACCEPT’ even though the input value is greater it takes only the character
depends on ‘PICTURE CLAUSE’ length (In ACCEPT the value will be assigned to the
data item position by position)
Ø When you assign a
value using VALUE CLAUSE 1st allocation will be done depending on
PICTURE CLAUSE
PROGRAM TERMINATOR STATEMENTS
Ø Mainly used to stop
the flow of an application program
Ø We have 3 program
terminator statements. They are
1.
STOP RUN – After successful
execution of the program the control will be transferred to Operating System
2.
GO BACK – After execution of
called cursor will be sent to calling program. It also acts as ‘STOP RUN’ when
coded in calling program
3.
EXIT PROGRAM – After successful
execution of called program control will sent to calling program
EX. SIMPLE INSERTION
ID
DIVISION.
PROGRAM-ID.
PGM1.
DATA
DIVISION.
WORKING-STORAGE
SECTION.
01 VAL1 PIC 9(4) VALUE 1234.
01 A PIC 9(3)B9(1).
01 B PIC 9(2)/9(2).
01 C PIC 9(2),9(2).
01 D PIC 9(2)09(1)09.
PROCEDURE
DIVISION.
MOVE VAL1 TO A,B,C,D.
DISPLAY VAL1.
DISPLAY A.
DISPLAY B.
DISPLAY C.
DISPLAY D.
STOP RUN.
OUTPUT
A – 123
4
B –
12/34
C –
12,34
D –
120304
NOTE
Ø In insertion according
to the given picture clause the value will be allocated
Ø In general
9 = 9(1) A
= A(1) X = X(1)
99 = 9(2) AA
= A(2) XX = X(2)
999 = 9(3) AAA
= A(3) XXX = X(3)
2.
SPECIAL INSERTION
Ø In ‘special insertion’ we are having only
one value i.e., Decimal Point (.)
Ø In Decimal always
allocation will be done before Decimal Point only
Ø We cant use special
insertion in arithmetic operations
EX 01 A PIC
9(2).9(2).
|
|
.
EX
ID
DIVISION.
PROGRAM-ID.
PGM1.
DATA
DIVISION.
WORKING-STORAGE
SECTION.
01 A PIC 9(3).9(2).
01 B PIC 9(2).9(2).
01 C PIC 9.9.
01 D PIC 9(3).(5) VALUE ZEROS.
01 E PIC 9(3).
PROCEDURE
DIVISION.
MOVE 1234 TO A.
DISPLAY A.
MOVE 121.1173 TO A.
DISPLAY A.
MOVE 4567.6674 TO B.
DISPLAY B.
MOVE 1.11 TO C.
DISPLAY C.
MOVE 131415.0130 TO D.
DISPLAY D.
MOVE 4532.113 TO E.
DISPLAY E.
STOP RUN.
3. FLOAT INSERTION
In float insertion we
are having mainly 3 possible values
1.
S – Sign
2.
+ - Positive
3.
- - negative
1. S (Sign Clause)
In general, in COBOL
we cant write ‘+‘ or ‘–‘ values for the data item but by using sign clause we
can write the values because in COBOL each and every ‘+’ and ‘–‘ values are
having their own combinations in sign clause
+0 = { -0 = }
+1 = A -1
= J
+2
= B -2
= K
+3 = C -3
= L
+4 = D -4
= M
+5 = E -5
= N
+6 = F -6
= O
+7 = G -7
= P
+8 = H -8
= Q
+9 = I -9
= R
In sign clause we are having mainly 4 types. They are……..
a.
SIGN LEADING
b.
SIGN LEADING SEPERATE
c.
SIGN TRAILING
d.
SIGN TRAILING SEPARATE
a. SIGN LEADING
Ø LEADING means left
most position
Ø In SIGN LEADING the
sign will be applied to the left most position i.e., 1st character
Ø At a time only one
value will be converted
EX -123 +123
J23 A23
Because -1 = J and +1 = A
b. SIGN LEADING SEPARATE
In SIGN LEADING SEPARATE the sign will
be displayed separately from the data in leading position
EX +123 -123
+
123 - 123
c. SIGN TRAILING
Ø Trailing means right
most position
Ø In SIGN TRAILING the
sign will be applied right most positioned 1st character
Ø It is default in sign
clause
EX +123 -123
123+ 123-
12+3 12-3
d. SIGN TRAILING SEPARATE
In SIGN TRAILING
SEPARATE the sign will be displayed separately from the data in trailing
position
EX +123 -123
123+ 123-
123
+ 123 –
EX
ID
DIVISION.
PROGRAM-ID.
PGM1.
DATA
DIVISION.
WORKING-STORAGE
SECTION.
01 A PIC S9(3)VALUE +345.
01 B PIC S9(3) SIGN LEADING.
01 C PIC S9(3) SIGN LEADING SEPERATE.
01 D PIC S9(3) SIGN TRAILING.
01 E PIC S9(3) SIGN TRAILING SEPERATE.
PROCEDURE
DIVISION.
MOVE A TO B,C,D,E.
DISPLAY A.
DISPLAY B.
DISPLAY C.
DISPLAY D.
DISPLAY E.
STOP RUN.
OUTPUT
A – 34E
B – C45
C - + 345
D – 34E
E – 345 +
+, - Insertion
In sign clause we are
having predefined rules while moving the data from one sign to another sign
+ - NO SIGN
+ + +
- + -
- - -
EX
ID
DIVISION.
PROGRAM-ID.
PGM1.
DATA
DIVISION.
WORKING-STORAGE
SECTION.
01 A PIC S9(3)VALUE +345.
01 B PIC +9(3).
01 C PIC -9(3).
01 D PIC S9(3) VALUE -345.
01 E PIC +9(3).
01 F PIC -9(3).
PROCEDURE
DIVISION.
MOVE A TO B,C.
MOVE D TO E,F.
DISPLAY A. 34E
DISPLAY B. +345
DISPLAY C. 345
DISPLAY D. 34N
DISPLAY E. -345
DISPLAY F. -345
STOP RUN.
4. FIXED INSERTION
In fixed insertion we are having
mainly 3 values. They are……
1.
CR – Credit
2.
DB – Debit
3.
$ - Inserting $ symbol
CR,DB will appear only for
negative values
EX
ID
DIVISION.
PROGRAM-ID.
PGM1.
DATA
DIVISION.
WORKING-STORAGE
SECTION.
01 A PIC S9(3)VALUE -123.
01 B PIC 9(3)CR.
01 C PIC 9(3)DB.
01 D PIC S9(3) VALUE +123.
01 E PIC 9(3)CR.
01 F PIC 9(3)DB.
01 G PIC $ 9(4) VALUE ZEROS.
PROCEDURE
DIVISION.
MOVE A TO B,C.
MOVE D TO E,F.
MOVE 1234 TO G.
DISPLAY A. 123- = 12L
DISPLAY B. 123CR
DISPLAY C. 123DB
DISPLAY D. 123+ = 12C
DISPLAY E. 123
DISPLAY F. 123
DISPLAY G. $1234
STOP RUN.
In
the above example CR,DB signs will be displayed only for negative values
B.
SUPPRESSION
In suppression we are having mainly
two values. They are…
1.
Z – leading Zeros suppression
2.
* - leading Zeros replacement by’*’
According to the given picture
clause the zeros will be suppressed
EX
ID
DIVISION.
PROGRAM-ID.
PGM1.
DATA
DIVISION.
WORKING-STORAGE
SECTION.
01 A PIC 9(7)VALUE 0001234.
01 B PIC Z9(6).
01 C PIC ZZ9(5).
01 D PIC ZZZ9(4).
01 E PIC *9(6).
01 F PIC **9(5).
01 G PIC ***9(4).
PROCEDURE
DIVISION.
MOVE A TO B,C,D,E,F,G. OUTPUT
DISPLAY A. 0001234
DISPLAY B. 001234
DISPLAY C. 01234
DISPLAY D. 1234
DISPLAY E. *001234
DISPLAY F. **01234
DISPLAY G. ***1234
STOP RUN.
b.
NON-EDITED PICTURE CLAUSE
Ø Non-Edited picture
clause may be included in arithmetic operations
Ø In non-editing
picture clause we are having a value i.e.,
V – Imaginary
decimal point
EX
1.
9(2).9(2) VALUE 12.34
– wrong
2.
9(2)V9(2) VALUE 12.34
– right
1.34
internally is 1234
EX
ID
DIVISION.
PROGRAM-ID.
PGM1.
DATA
DIVISION.
WORKING-STORAGE
SECTION.
01 A PIC 9(3)V9(3) VALUE 123.456.
01 B PIC 9(3)V9(3) VALUE 111.123.
01 C PIC 9(3).9(3) VALUE ZEROS.
PROCEDURE
DIVISION.
ADD ATO B GIVING C. 123456+111123
DISPLAY ‘C VALUE IS::’ C. C VALUE IS:: 234.579
STOP RUN.
RENAMES CLAUSE
Ø In COBOL level no# 66
is used as RENAMES
Ø 66 level no# must
start in Area-B
Ø Using 66 level no# we
can re-group the data items only within a group
Ø We cant use renames
between two groups
SYNTAX
66 DATANAME RENAMES <D.NAME1> THRU <D.NAMEn>
EX
ID DIVISION.
PROGRAM-ID. PGM10.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 GRP1.
02 ENO PIC 9(4) VALUE 1001.
02 ENAME PIC A(15) VALUE 'SRI'.
02 ESAL PIC 9(5) VALUE 3000.
02 EADDR PIC X(10) VALUE 'HYD1'.
02 RES1 PIC X(55).
66 A RENAMES ENO THRU ESAL.
66 B RENAMES ENAME THRU EADDR.
66 C RENAMES ENO THRU EADDR.
66 D RENAMES ESAL THRU EADDR.
PROCEDURE DIVISION.
DISPLAY A.
DISPLAY B.
DISPLAY C.
DISPLAY D.
MOVE C TO RES1.
DISPLAY RES1.
STOP RUN.
DECLERATION
OF GROUP ITEMS
Ø In COBOL 01 level no# is used for group item
Ø Group item does not
contain picture clause because……
Sub group elements
size = group size
Ø We can use 02 – 49
level no# for sub-groups
Ø Sub-group 02 – 49
must start from Area-B (12th Column)
EX
ID DIVISION.
PROGRAM-ID. PGM11.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 GRP1.
02 ENO PIC 9(4) VALUE 1001.
02 ENAME PIC A(15) VALUE 'RAJU'.
02 ESAL PIC 9(5) VALUE 25000.
02 EADDR PIC X(10) VALUE 'HYD'.
PROCEDURE DIVISION.
DISPLAY 'GROUP ITEMS'.
DISPLAY GRP.
DISPLAY LENGTH OF GRP1.
STOP RUN.
USING
FILLER CLAUSE
By
using filler clause we can also allocate no of required spaces between the
sub-group elements existed in a group
EX
ID DIVISION.
PROGRAM-ID. PGM12.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 GRP1.
02 ENO PIC 9(4) VALUE 1001.
02 FILLER PIC X(2).
02 ENAME PIC A(4) VALUE 'RAJU'.
02
FILLER PIC X(2).
02 ESAL PIC 9(5) VALUE 25000.
02 FILLER PIC X(2).
02 EADDR PIC X(3) VALUE 'HYD'.
PROCEDURE DIVISION.
DISPLAY GRP1.
DISPLAY LENGTH OF GRP1.
STOP RUN.
LEVEL
NO# 77
Ø In COBOL level no# 77
is Pure elementary data item
Ø Under 77 we cant
write sub-group elements because in COBOL all level no’s should come in
ascending order
EX
ID DIVISION.
PROGRAM-ID. PGM13.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 X PIC 9(5) VALUE 17745.
77 Y PIC A(5) VALUE ‘SRINU’.
77 Z PIC X(3) VALUE ‘A2B’.
PROCEDURE DIVISION.
DISPLAY X.
DISPLAY Y.
DISPLAY Z.
STOP RUN.
INITIALIZE
VERB
Ø Initialize is mainly
used for initializing the data item with their default values
Ø Using ‘initialize’ we
can effectively ‘REPLACE’ ‘FIGURATIVE CONSTANTS’
SYNTAX
INITIALIZE
DATANAME
EX
ID DIVISION.
PROGRAM-ID. PGM13.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 X PIC 9(5) VALUE 17745.
77 Y PIC A(5) VALUE ‘SRINU’.
77 Z PIC X(3) VALUE ‘A2B’.
PROCEDURE DIVISION.
INITIALIZE X.
MOVE 456 TO X.
DISPLAY X.
INITIALIZE Y.
DISPLAY Y.
INITIALIZE Z.
MOVE X2Y TO Z.
INITIALIZE Z.
DISPLAY Z.
MOVE ‘ABC4’ TO Z.
DISPLAY Z.
STOP RUN.
MOVE
STATEMENT
Ø By using MOVE we can
move the data to any no of data items and also we can move the data from one
data item to any no of data items
SYNTAX
MOVE D.NAME1 TO
D.NAME2,D.NAME3,………..,D.NAMEn
MOVE VALUE TO
D.NAME1,D.NAME2,………..,D.NAMEn
Ø In MOVE we are having
two types. They are ……..
1.
Group MOVE
2.
Elementary MOVE
We
can move the data from one group to another group and also from elementary data
item to another elementary data item
EX
ID DIVISION.
PROGRAM-ID. PGM13.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 GRP1.
02 A1 PIC A(5) VALUE 'COBOL'.
02 A2 PIC 9(3) VALUE 123.
01 GRP2.
02 B1 PIC A(5) VALUE 'HELLO'.
02 B2 PIC 9(5) VALUE 45675.
77 X PIC 9(3) VALUE 177.
77 Y PIC 9(5).
77 Z PIC 9.
77 C PIC 9(2).
PROCEDURE DIVISION.
MOVE GRP1 TO GRP2.
MOVE X TO Y,Z,C.
DISPLAY GRP1.
DISPLAY GRP2.
DISPLAY X.
DISPLAY Y.
DISPLAY Z.
DISPLAY C.
STOP RUN.
Ø While moving data
from one group to another group irrespective of sub group elements data it
transpose the data from group to group
Ø In MOVE 1st
allocation will be done and then the value will be counted
REDEFINES
CLAUSE
Ø By using REDEFINES we
can use any existing group memory(size) in any sub-sequent group
Ø We can also REDEFINE
multiple items
Ø Using REDEFINES we
can request the total memory of one group into the next group
Ø For non 01 level
redefinition the redefining item size must be lesser or equal to item being
redefined
Ø For 01 level
redefinition the redefining item size must be greater or lesser or equal to
item being redefined
EX
ID DIVISION.
PROGRAM-ID. PGM14.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 GRP1.
02 A.
03 A1 PIC A(5) VALUE 'COBOL'.
03 A2 PIC 9(5) VALUE 12345.
02 B REDEFINES A.
03 B1 PIC A(2).
03 B2 PIC 9(3).
03 B3 PIC X(5).
01 GRP2 REDEFINES GRP1.
02 C PIC A(20).
PROCEDURE DIVISION.
DISPLAY GRP1.
DISPLAY A.
DISPLAY B.
DISPLAY B1.
DISPLAY GRP2.
STOP RUN.
NOTE
In REDEFINES while
redefining from one group to another group the data of redefining group will
also appear in redefining group
No comments:
Post a Comment