slides cobol la01 lc 01 [compatibility mode]
DESCRIPTION
cobol powerpointTRANSCRIPT
Education and ResearchWe enable you to leverage knowledge anytime, anywhere!
COBOL Programming COBOL Programming
Day 1Day 1
ER/CORP/CRS/LA1010/003ER/CORP/CRS/LA1010/003 Ver. No.: 4.0Ver. No.: 4.0 Copyright © 2008, Infosys Technologies Ltd.Copyright © 2008, Infosys Technologies Ltd.
Course ObjectivesCourse Objectives
�Evolution, Features & Language Fundamentals
�Programming in COBOL
Copyright © 2008, Infosys Technologies Ltd. 22
Course AgendaCourse Agenda
� Day 1: Introduction to COBOL
� Day 2: Cobol Language constructs and miscellaneous verbs
� Day 3: Sequential File Handling
� Day 4: Indexed File Handling, COPY and CALL Verbs
Copyright © 2008, Infosys Technologies Ltd. 33
� Day 4: Indexed File Handling, COPY and CALL Verbs
� Day 5: Table Handling and String Handling
� Day 6: Working on project
� Day 7: Project Evaluation
COBOL in IndustryCOBOL in Industry
�All the batch applications like report processing, payroll processing pertaining to finance, insurance and banking are developed in COBOL
�COBOL with the Customer Information Customer System (CICS) makes the batch operating
Copyright © 2008, Infosys Technologies Ltd. 44
System (CICS) makes the batch operating environment interactive through online systems
�Huge systems like railway reservation and airline reservation systems use COBOL with CICS to perform customer services effectively
Pre-requisitesPre-requisites
�Programming Fundamentals
�MVS Operating system and its subsystem TSO
� Job Control Language to submit jobs to MVS
Copyright © 2008, Infosys Technologies Ltd. 55
� Job Control Language to submit jobs to MVS
�Navigating through ISPF
Topics beyond the scopeTopics beyond the scope
�Report writer feature of COBOL
�SORT and MERGE
�Relative Files
Copyright © 2008, Infosys Technologies Ltd. 66
�Relative Files
Component Marks Schedule
Module Test(All topics)
70 Day 8
Project 30 Day 7
Evaluation MechanismsEvaluation Mechanisms
Copyright © 2008, Infosys Technologies Ltd. 77
Project 30 Day 7
Session Plan - Day1Session Plan - Day1
� Evolution and Features of COBOL
� General Coding and Format rules
� Language Fundamentals
Copyright © 2008, Infosys Technologies Ltd. 88
� Input and Output verbs
� Data Movement Verbs
� Arithmetic Verbs
� Design and development of simple COBOL programs
ReferencesReferences
� FAQs on COBOL � http://172.25.103.176/Extl_FAQ/xfaq_10099/xfaq_10099.htm
� Edited Picture Clauses in COBOL� http://172.25.103.176/InternalTutorial/itut_87190/itut_87190.doc
� How Edited Picture Clauses Work ?� http://172.25.103.176/Bok/bok_84310/bok_84310.DOC
Copyright © 2008, Infosys Technologies Ltd. 99
� M.K.Roy and D. Ghosh Dastidar, COBOL Programming, Tata McGraw� Hill, New York, 1973.
� Nancy Stern and Robert Stern, COBOL Programming, John Wiley &� Sons, New York, 1973.
� Newcomer and Lawrence, Programming with Structured COBOL,� McGraw Hill Books, New York, 1973.
Education and ResearchWe enable you to leverage knowledge anytime, anywhere!
Features of COBOLFeatures of COBOL
ER/CORP/CRS/LA1010/003ER/CORP/CRS/LA1010/003 Ver. No.: 4.0Ver. No.: 4.0 Copyright © 2008, Infosys Technologies Ltd.Copyright © 2008, Infosys Technologies Ltd.
History of COBOLHistory of COBOL
YEAR VERSION FEATURES
May 1958 Initial Stage US Dept. Of Defense set up COD ASYL(Conference on Data Systems Language) to develop a language to cater the busine ss data processing needs.
Sept. 1959 Initial Stage CODASYL developed COBOL.
April 1960 First Version CODASYL officially released COBOL with its initial specifications
Copyright © 2008, Infosys Technologies Ltd. 1111
May 1961 COBOL-61 Published with more revisions which provided the foundation for later versions.
1965 COBOL-64 Re-revised version of COBOL was release d with a number of additional features.
1968 COBOL-68 �ANSI approved COBOL as a standard language for comm ercial use.�Standardized form of COBOL�Attempted to overcome the incompatibilities of diff erent versions
History of COBOLHistory of COBOL
YEAR VERSION FEATURES
1974 COBOL-74 ANSI published the revised version of C OBOL with string operations added to it.
1985 COBOL-85 �Another revised version of COBOL�Designed to take advantage of structured programming languages.�Logic errors reduced with END statements
Copyright © 2008, Infosys Technologies Ltd. 1212
�Case statements reduced nested Ifs�Less English-like�Maintained readability and business orientation�Compatible with previous versions�Today most COBOL compilers adhere to this standard
Latest COBOL 9x(or) Object Oriented COBOL
It allows the flexibility to use encapsulated objec ts as a normal part of COBOL programming.
Features of COBOLFeatures of COBOL
�Business Oriented & Robust Language (good file handling methods)
�Excellent self-documenting capabilities
Copyright © 2008, Infosys Technologies Ltd. 1313
�Structured Programming Language
�English-like Language
Education and ResearchWe enable you to leverage knowledge anytime, anywhere!
Language BasicsLanguage Basics
ER/CORP/CRS/LA1010/003ER/CORP/CRS/LA1010/003 Ver. No.: 4.0Ver. No.: 4.0 Copyright © 2008, Infosys Technologies Ltd.Copyright © 2008, Infosys Technologies Ltd.
Structure of a COBOL programStructure of a COBOL programPROGRAM
DIVISIONS
SECTIONS
PARAGRAPHS
Principal portions of a program. There are 4 divisions a) Identification (Required)b) Environment (Optional)c) Data (Optional)d) Procedure (Required)
User defined chunk of code which consists of one/more paragraphs.
e.g. a) U000-CHECK-LOG SECTION.User defined chunk of code which
A STATEMENT consists of a COBOL verb and an operand or operands.
e.g. SUBTRACT T-TAX FROM GROSS-PAY
GIVING NET-PAY
Copyright © 2008, Infosys Technologies Ltd. 1515
SENTENCES
STATEMENTS
RESERVED WORDSUSER-DEFINED
WORDS
CHARACTERS
a) U000-CHECK-LOG SECTION.b) FILE SECTION.
User defined chunk of code which consists of one/more sentences.
e.g. a) P000-PRINT-FINAL-TOTALS.
b) PROGRAM-ID.A SENTENCE consists of one or more statements and is terminated by a full stop.
e.g. a) MOVE .21 TO VAT-RATE
b) COMPUTE VAT-AMOUNT =
PRODUCT-COST * VAT-RATE.
COBOL – Character SetCOBOL – Character Set
Character Meaning
Space
+ Plus sign
- Minus sign or hyphen
* Asterisk
/ Forward slash or solidus
= Equal sign
$ Currency sign1
, Comma
Copyright © 2008, Infosys Technologies Ltd. 1616
; Semicolon
. Decimal point or period
" Quotation mark2
( Left parenthesis
) Right parenthesis
> Greater than
< Less than
: Colon
' Apostrophe
A-Z Alphabet (uppercase)
a-z Alphabet (lowercase)
0-9 Numeric characters
IDENTIFICATION DIVISIONIDENTIFICATION DIVISION
IDENTIFICATION DIVISION.
PROGRAM-ID. PGM-NAME.
[AUTHOR. Comment Entry]
[INSTALLATION . Comment Entry]
[DATE-WRITTEN. Comment Entry]
[DATE-COMPILED. Comment
SYNTAX
Copyright © 2008, Infosys Technologies Ltd. 1717
Entry]
IDENTIFICATION DIVISION.
PROGRAM-ID. FIRSTPGM.
AUTHOR.ENR, MYSORE.
INSTALLATION. GEC, MYSORE.
DATE-WRITTEN. 26 JULY 206.
DATE-COMPILED. 27 JULY 2006.
ExampleProgram Name
ENVIRONMENT DIVISION
ENVIRONMENT DIVISION
Copyright © 2008, Infosys Technologies Ltd. 1818
CONFIGURATION SECTION INPUT-OUTPUT SECTION
Identifies the computer used for compiling of programs
Identifies the files and the input-output resources used by the program
ENVIRONMENT DIVISIONENVIRONMENT DIVISION
SYNTAXENVIRONMENT DIVISION.
CONFIGURATION SECTION.
[SOURCE-COMPUTER.Comment Entry.]
[ OBJECT- COMPUTER.Comment Entry.]
Copyright © 2008, Infosys Technologies Ltd. 1919
[ OBJECT- COMPUTER.Comment Entry.]
INPUT-OUTPUT SECTION.
[FILE-CONTROL.]
[File control entries]
[I-O CONTROL.]
[I-O control entries]
DATA DIVISIONDATA DIVISION
� DATA DIVISION has following sections :
� FILE SECTION - describes most of the data that is sent to, or coming from, the computer’s peripherals
� WORKING-STORAGE SECTION - describes the general variables used in the program
Copyright © 2008, Infosys Technologies Ltd. 2020
used in the program
� LINKAGE SECTION - establishes link between two programs
� DATA DIVISION is optional unless the program manipulates any constant and user-defined data
PROCEDURE DIVISION
� Includes statements and sentences necessary for reading input,processing it and writing the output
� Contains instructions that are executed by the computer at the RUN TIME
� All the data described in the DATA DIVISION are processed here anddesired results are produced
Copyright © 2008, Infosys Technologies Ltd. 2121
� Programmer describes his algorithm in PD
� Its hierarchical in structure consists of Sections, Paragraphs, Sentencesand Statements
� Only the Section is optional
� Should contain at least one paragraph, sentence and statement
Sections
� A SECTION is a block of code made up of one or more paragraphs
� A SECTION begins with the section-name and ends where next section name is encountered or where the program text ends
Copyright © 2008, Infosys Technologies Ltd. 2222
� A SECTION name consists of a name devised by the programmer or defined by the language followed by the word SECTION followed by a full stop
– U0000-SELECT-USER-RECORDS SECTION.– FILE SECTION.
Paragraphs
� Each section consists of one or more paragraphs
� A PARAGRAPH is a block of code made up of one or more sentences
� A PARAGRAPH begins with the paragraph -name and ends with the next
Copyright © 2008, Infosys Technologies Ltd. 2323
� A PARAGRAPH begins with the paragraph -name and ends with the next paragraph or section name or the end of the program text
� The paragraph-name consists of a name devised by the programmer or defined by the language followed by a full stop � P0000-PRINT-FINAL-TOTALS.� PROGRAM-ID.
Sentences and Statements
� A PARAGRAPH consists of one or more sentences
� A SENTENCE consists of one or more statements and is terminated by a full stop
– MOVE 21 TO VAT-RATECOMPUTE VAT-AMOUNT = PRODUCT-COST * VAT-RATE.
– DISPLAY "Enter Name "
Copyright © 2008, Infosys Technologies Ltd. 2424
– DISPLAY "Enter Name " ACCEPT STUDENT-NAMEDISPLAY "Name Entered was “ STUDENT-NAME.
� A STATEMENT consists of a COBOL verb and an operand or operands
– SUBTRACT T-TAX FROM GROSS-PAY GIVING NET-PAY.– READ STUDENT-FILE
AT END SET END-OF-FILE TO TRUEEND-READ.
COBOL coding sheetCOBOL coding sheet
Column numbers
1 2 3 4 5 6 7 8 9 10 11 12 72 80
Column numbers
* Area A Area B IDENTI-
Copyright © 2008, Infosys Technologies Ltd. 2525
IFICATION
AREA
-
/
Cols 1-6
Column Numbers
Col 7
* - > Comment
- -> Continuation
/ -> Form Feed
Area A - Cols 8-11
Division Name
Section Name
Paragraph Name
FD entries
Area B - Cols 12 - 72
All Procedure Division Statements & Sentences
Copyright © 2008, Infosys Technologies Ltd. 2626
Column Numbers01 Entries
The minimum COBOL program
IDENTIFICATION DIVISION.PROGRAM-ID. SMALLPGM.
PROCEDURE DIVISION.A0000-DISPLAY-PARA.
DISPLAY “Welcome to MF training“.
Copyright © 2008, Infosys Technologies Ltd. 2727
DISPLAY “Welcome to MF training“.STOP RUN..
What is the model we have used to describe the COBOL program structure?
TOP-DOWN
Can You Answer?Can You Answer?
�Area A entries begin in ______________________
�PROGRAM-ID is a paragraph name appearing in
Columns 8, 9, 10 & 11
Copyright © 2008, Infosys Technologies Ltd. 2828
�PROGRAM-ID is a paragraph name appearing in ____________________IDENTIFICATION DIVISION
Education and ResearchWe enable you to leverage knowledge anytime, anywhere!
Data Types in COBOLData Types in COBOL
ER/CORP/CRS/LA1010/003ER/CORP/CRS/LA1010/003 Ver. No.: 4.0Ver. No.: 4.0 Copyright © 2008, Infosys Technologies Ltd.Copyright © 2008, Infosys Technologies Ltd.
Basic data typesBasic data types
�Alphabetic
� Numeric
� Alphanumeric
Copyright © 2008, Infosys Technologies Ltd. 3030
� Alphanumeric
� Edited numeric
� Edited alphanumeric
Literals
� Analogous to “constants” in any other language
� Literals are symbols whose value does not change in a program
� There are 3 types of literals namely
Copyright © 2008, Infosys Technologies Ltd. 3131
� There are 3 types of literals namely
(1) Numeric literals.
(2) Non-numeric literals.
(3) Figurative constants.
Numeric literalsNumeric literals
� Are formed using digits only
� There must not be any blank between the sign and the first digit
� May include a decimal point which cannot be the right most character
� Can have at most 18 digits
Copyright © 2008, Infosys Technologies Ltd. 3232
Can have
Valid Literals Invalid Literals777 666,66,7 (Comma appears)-1234 -0 .888 (Blank appears)123456789126789092 +765. (Decimal in rightmost position)
Non-numeric literalsNon-numeric literals
� Are used to display headings or messages
� Are a sequence of characters (except quotes) from the COBOL character set enclosed within quotes
� May contain up to 160 characters including spaces
Copyright © 2008, Infosys Technologies Ltd. 3333
Valid Literals Invalid Literals‘DATE-OF-BIRTH’ ‘NEW BILL (Right Quote missing)‘7788990’ ‘PAUL’S FATHER’ (Quotes appear
inbetween)‘EXERCISE-I’ ‘’ (No character between quotes)‘ / ‘
Figurative constantsFigurative constants
Figurative constants Meaning
ZERO(S) or ZEROES Represents the value 0, one or mor e depending on the context
SPACE(S) Represents one or more spaces
HIGH-VALUE(S) Represents the highest value
Copyright © 2008, Infosys Technologies Ltd. 3434
HIGH-VALUE(S) Represents the highest value
LOW-VALUE(S) Represents the lowest value
QUOTE(S) Represents single or double quotes
ALL ALL literalliteral Fill With Literal
Data NamesData Names
� These are analogous to “Variables” in any other programming languages
� Are named memory locations
� Must be described in the DATA DIVISION before they can be used in thePROCEDURE DIVISION
Copyright © 2008, Infosys Technologies Ltd. 3535
� Can be of elementary or group type
� Can be subscripted
� Are user defined words
� Are used to form section, paragraph and data names
Rules for forming User-Defined WordsRules for forming User-Defined Words
� Can be at most 30 characters in length
� Only alphabets, digits and hyphen are allowed
� Blanks are not allowed
� May not begin or end with a hyphen
Copyright © 2008, Infosys Technologies Ltd. 3636
� Should not be a COBOL reserved word
ExampleValid Invalid
777-VALUE -WS-VALUE (starts with hyphen)WS-Y-ITEM-DATA INPUT-OUTPUT (reserved word)WS-X104 WS-DATA RES (blank appears)
Description of data namesDescription of data names
The description of a data name is done with the aid of
(1) Level number – expresses data hierarchy
(2) PICTURE clause – specifies data type and storage
(3) VALUE clause – initializes the data names
01 WS-NUMBER PICTURE 9999.
Copyright © 2008, Infosys Technologies Ltd. 3737
01 WS-NUMBER PICTURE 9999.
Level Number Identifier PICTURE Clause
Level number and RulesLevel number and Rules
LEVEL NUMBER
Description Coding Rules
01 Record Description for files and independent data items
Must begin in Area A
02 – 49 Fields within records and sub-items Can begin in Area A or Area B
Copyright © 2008, Infosys Technologies Ltd. 3838
66 RENAMES Clause Must begin in Area A
77 Independent elementary items Must begin in Area A
88 Condition Names Can begin in Area A or Area B
� Is used to specify the following
(1) The data type
(2) The storage requirement
� Can be abbreviated as PIC
� It is used only for describing elementary items
PICTURE clause
Copyright © 2008, Infosys Technologies Ltd. 3939
PICTURE Symbol Meaning
9 Numeric
A Alphabetic
X Alphanumeric
V Implied Decimal Point
S Sign bit
ExamplesExamples
� Numeric Data item
01 WS-NUMBER PIC 9(3).01 WS-GROSS PIC 9(2)V9(2).01 WS-SNUMBER PIC S9(2).
� Alphabetic Data-item
Copyright © 2008, Infosys Technologies Ltd. 4040
01 WS-NAME PIC A(30).01 WS-TITLE PIC A(25).
� Alphanumeric Data-item
01 WS-REGNO PIC X(4).01 WS-PANN PIC X(6).
Group and elementary items
� GROUP ITEM – describes a data item that can be further subdivided
– Declared using a level number and a data name
– Cannot have a picture clause
– Group item is the highest in the data hierarchy with level number 01and it is referred to as “record”
Copyright © 2008, Infosys Technologies Ltd. 4141
and it is referred to as “record”
� ELEMENTARY ITEM - describes data items which are atomic, thatcannot be further subdivided
– An elementary item must have a picture clause
� Every group or elementary item declaration must be followed by a fullstop
Group ItemsGroup Items
01 WS-ADDRESS.05 WS-HOUSENO PIC 9(2).05 WS-STREET PIC A(15).05 WS-ROAD PIC A(20).05 WS-DISTRICT PIC A(25).05 WS-STATER PIC A(20).
Copyright © 2008, Infosys Technologies Ltd. 4242
05 WS-STATER PIC A(20).
01 WS-DATE-OF-BIRTH.05 WS-DATE PIC 9(2).05 WS-MON PIC A(3).05 WS-YEAR PIC 9(4).
Edited picture symbols (1/4)
Edited Symbol Meaning Data Type supported
Z Zero Suppression
* Check Protection
, Comma Insertion
- Minus sign Insertion
+ Plus sign Insertion
CR Credit Symbol Insertion
Copyright © 2008, Infosys Technologies Ltd. 4343
NUMERICCR Credit Symbol Insertion
DB Debit Symbol Insertion
. Decimal Point Insertion
B Blank Insertion
/ Slash Insertion
BLANK WHEN ZERO Blank Insertion when the value is zero
$ Dollar sign Insertion
Edited picture symbols (2/4)Edited picture symbols (2/4)
Edited Symbol Meaning Data Type supported
B Blank InsertionAlphabetic,
Copyright © 2008, Infosys Technologies Ltd. 4444
Alphabetic, Alphanumeric
& Numeric/ Slash Insertion
0 Zero Insertion
Edited picture symbols (3/4)Edited picture symbols (3/4)
Source PICTURE
Value Destination PICTURE
Edited Value
9(5) 00077 ZZ999 077
9(2) 20 ***9(2) ***20
9(3) 124 $9(4) $0124
S9(4) -4256 -9999 -4256
Copyright © 2008, Infosys Technologies Ltd. 4545
S9(4) -1256 +9999 -1256
S9(2) -12 999CR 012CR
S9(2) 24 999CR 024
9(2)V9(2) 12.34 9(3).9 012.3
9(4) 3456 99,999 03,456
9(4) 3489 9(4)B99 0034 89
X(9) BFSKINNER XBXBX(7) B F SKINNER
Edited picture symbols (4/4)Edited picture symbols (4/4)
Edited Symbol Methods
ZSuppression And Replacement(leading zeroes are suppressed and replaced with blanks or ‘*’)
*
,
Copyright © 2008, Infosys Technologies Ltd. 4646
Insertion
-
+
CR
DB
.
B
$
/
Can You Answer?Can You Answer?
� Level numbers are used for _____________
� Picture class is used for _________ & ________________
Data Hierarchy
Data Type Storage Requirement
Copyright © 2008, Infosys Technologies Ltd. 4747
� A Non-numeric literal can have maximum of ______________
� A numeric literal can have at most _______________
160 characters
18 digits
Education and ResearchWe enable you to leverage knowledge anytime, anywhere!
PROCEDURE DIVISION VERBSPROCEDURE DIVISION VERBS
ER/CORP/CRS/LA1010/003ER/CORP/CRS/LA1010/003 Ver. No.: 4.0Ver. No.: 4.0 Copyright © 2008, Infosys Technologies Ltd.Copyright © 2008, Infosys Technologies Ltd.
� Data movement Verb
� Arithmetic Verbs
� Input / Output Verbs
PROCEDURE DIVISION Verbs
Copyright © 2008, Infosys Technologies Ltd. 4949
� Input / Output Verbs
� Sequence control Verbs
� File handling Verbs
ACCEPT Verb
Syntax
Input -Output VERBS (1/2)Input -Output VERBS (1/2)
ACCEPT identifier [ FROM { DATE, DAY, TIME, mnemonic-name }].
Copyright © 2008, Infosys Technologies Ltd. 5050
Examples
(1) ACCEPT WS-NUMBER-1.(2) ACCEPT WS-TODAY-DATE FROM DATE.
Copyright © 2008, Infosys Technologies Ltd. 5252
The ‘SYSIN’ statement from the JCL passes data into the COBOL program which can be stored in a variable using
the ACCEPT statement
DISPLAY Verb
Syntax
Input -Output VERBS (2/2)Input -Output VERBS (2/2)
DISPLAY { identifier-1, literal-1 } , . . .
Copyright © 2008, Infosys Technologies Ltd. 5353
Examples
(1) DISPLAY WS-VARIABLE-PAY(2) DISPLAY ‘The sum is : ’ WS-SUM
Data Movement Verb - MOVE VerbData Movement Verb - MOVE Verb
Move copies data from the source identifier or literal to oneor more destination identifiers
SYNTAX
Copyright © 2008, Infosys Technologies Ltd. 5454
MOVE { identifier, literal } TO { identifier } ………………
MOVE verb ExampleMOVE verb Example
01 SUR-NAME PIC X(008).
R Y A NF I T Z P A T R I C K
Copyright © 2008, Infosys Technologies Ltd. 5555
MOVE “RYAN” TO SUR-NAME.
MOVE “FITZPATRICK” TO SURMOVE “FITZPATRICK” TO SUR--NAME.NAME.
Before
WS00-OUT1 BEST
WS00-OUT2 1234
After
WS00-OUT1 ‘ ’
WS00-OUT2 0
Before
WS00-OUT3 0786
Copyright © 2008, Infosys Technologies Ltd. 5656
WS00-OUT3 0786
After
WS00-OUT3 2345
Before
WS00-OUT4 ‘PAYAL PAREKH’
After
WS00-OUT4 ‘SHUTI DEY’
MOVE to a numeric item
� When the destination item is numeric, or edited numeric, then data is
aligned along the decimal point with zero filling or truncation as necessary
Copyright © 2008, Infosys Technologies Ltd. 5757
� When the decimal point is not explicitly specified in either the source or
destination items, the item is treated as if it had an assumed decimal point
immediately after its rightmost character
MOVE ZEROS TO GROSS-PAY.
MOVE 12.4 TO GROSS- PAY.
01 GROSS-PAY PIC 9(004)V99.
�����
����
GROSS-PAY
GROSS-PAY
0 0 0 0 0 00 0 0 0 0 0
0 0 1 2 4 0
MOVE – Example (1/2)
Copyright © 2008, Infosys Technologies Ltd. 5858
MOVE 12.4 TO GROSS- PAY.
MOVE 123.456 TO GROSS-PAY .
MOVE 12345.757 TO GROSS-PAY.
�����
�����
�����
GROSS-PAY
GROSS-PAY
1 2 4
0 1 2 3 4 5
2 3 4 5 7 5
MOVE 1234 TO COUNTRY-POP.
01 COUNTRY-POP PIC 999.01 PRICE-RS PIC 999V99.
1 2 3 4
1 5 4 0 0PRICE-RS
COUNTRY-POP
�����
MOVE – Example (2/2)
Copyright © 2008, Infosys Technologies Ltd. 5959
MOVE 154 TO PRICE-RS.
MOVE 3552.75 TO PRICE-RS.
1 5 4 0 0
3 5 5 2 7 5
�����
PRICE-RS
�����
�����
Before
WS00-OUT1 0000
WS00-OUT2 000000
After
WS00-OUT1 3456
WS00-OUT2 345678
Before
WS00-OUT3 000000
Copyright © 2008, Infosys Technologies Ltd. 6060
WS00-OUT3 000000
After
WS00-OUT3 123456
Before
WS00-OUT4 00000000
After
WS00-OUT4 12345678
JUSTIFIED RIGHT Clause
Is used to change the default type movement of alphabetic and alphanumeric data
Examples
01 NAME PIC X(10) JUSTIFIED RIGHT.
Copyright © 2008, Infosys Technologies Ltd. 6161
01 NAME PIC X(10) JUSTIFIED RIGHT.
MOVE “INFY” TO NAME.
Contents of NAME field is bbbbbbINFY.
JUSTIFIED RIGHT clause .. exampleJUSTIFIED RIGHT clause .. example
Copyright © 2008, Infosys Technologies Ltd. 6262
*********************************************
WS00-OUT1 : ABCDEFGHIJKLMNOPQRSTUVWXYZ
WS00-OUT2 : ABCDEFGHIJKLMNOPQRSTUVWXYZ
*********************************************
Output SPOOL
MOVE CORRESPONDING (1/2)
•It’s a group move
•Group move is one in which one or both of the sending and receiving fields are groupitems
•This is treated exactly as though it were an alphanumeric elementary move, except thatthere is no conversion of data from one form of internal representation to another
Copyright © 2008, Infosys Technologies Ltd. 6363
SYNTAX
�where identifier-1 and identifier-2 are group items.
MOVE { CORRESPONDING, CORR } identifier-1 TO identifier-2
01 WS-STUREC.
05 WS- NAME PIC A(20).
05 WS-AGE PIC 9(2).
05 WS-SEX PIC A(6).
05 WS- GRADE PIC A(1).
01 WS-STUDCOPYREC.
05 WS-NAME PIC A(15).
05 WS - AGE PIC 9(2).
WS-STUREC :
WS- NAME –KUMAR
WS-AGE –23
WS-SEX –MALEWS-GRADE –A
WS-STUDCOPYREC :WS-NAME – GUPTAWS-AGE – 24
MOVE CORRESPONDING(2/2)
Copyright © 2008, Infosys Technologies Ltd. 6464
05 WS - AGE PIC 9(2).
05 WS-DOB PIC X(10).
PROCEDURE DIVISION.
A0000-FIRST-PARA.
MOVE CORRESPONDING WS-STUREC TO WS-STUDCOPYREC.
DISPLAY WS-STUDCOPYREC.
WS-AGE – 24WS-DOB –15/02/1980
WS-STUDCOPYREC :WS-NAME – KUMARWS-AGE –23WS-DOB –15/02/1980
MOVE CORRESPONDING .. exampleMOVE CORRESPONDING .. example
Copyright © 2008, Infosys Technologies Ltd. 6565
****************************
WS00-GR2 : NISHANT 00000
****************************Output SPOOL
MOVE . . . OF . . . TO . . . OF (1/2)
Facilitates the movement of a particular field of a record to a particular field of another record
Example:
Copyright © 2008, Infosys Technologies Ltd. 6666
MOVE NAME OF STUD-REC TO WS-NAME OF WS-STUD-REC.
01 STUREC.
05 NAME PIC A(20).
05 AGE PIC 9(2).
05 SEX PIC A(6).
05 GRADE PIC A(1).
01 WS-STUDREC.
05 WS-NAME PIC A(15).
STUREC :
NAME – KUMAR
AGE –23
SEX –MALE
GRADE –A
WS-STUDREC :WS-NAME – GUPTA
MOVE . . . OF . . . TO . . . OF (2/2)
Copyright © 2008, Infosys Technologies Ltd. 6767
05 WS-AGE PIC 9(2).
05 WS-DOB PIC X(10).
PROCEDURE DIVISION.
A0000-FIRST-PARA.
MOVE NAME OF STUREC TO WS-NAME OF WS- STUDREC.
DISPLAY WS-STUDREC.
WS-NAME – GUPTAWS-AGE –24WS-DOB –15/02/1980
WS-STUDREC :WS-NAME – KUMARWS-AGE –24WS-DOB –15/02/1980
Legal MOVE(s)
Certain combinations of sending and receiving data types are not permitted.
Alphabetic Alphanumeric Edited Alphanumeric
Numeric Numeric non integer
Edited numeric
Alphabetic Y Y Y N N N
Receiving field
Sen
ding
fiel
d
Copyright © 2008, Infosys Technologies Ltd. 6868
Alphabetic Y Y Y N N N
Alphanumeric Y Y Y Y* N N
Edited Alphanumeric
Y Y Y N N N
Numeric N Y Y Y Y Y
Numeric non integer
N N N Y Y Y
Edited numeric N Y Y Y Y Y
Sen
ding
fiel
d
� ADD
� SUBTRACT
� MULTIPLY
� DIVIDE
Arithmetic VERBS
Copyright © 2008, Infosys Technologies Ltd. 6969
� DIVIDE
� COMPUTE
ADD Verb (1/2)
SYNTAX -1
ADD { identifier-1, literal-1 }[ , identifier-2, literal-2 ] . . . TO identifier-3 [ , identifier-4
] . . .
Copyright © 2008, Infosys Technologies Ltd. 7070
SYNTAX-2
ADD { identifier-1, literal-1 }{ identifier-2, literal-2 } [ identifier-3, literal-3 ] GIVING
identifier-4 . . .
ADD Verb (2/2)ADD Verb (2/2)
Contents BeforeA B C D
COBOL Statement Contents AfterA B C D
2 ADD 10 TO A 12
2 4 ADD A TO B 2 6
2 4 25 ADD A TO B GIVING C 2 4 6
Copyright © 2008, Infosys Technologies Ltd. 7171
2 4 25 ADD A TO B GIVING C 2 4 6
2 4 25 ADD A, B, 6 TO C(C=A+B+6+C)
2 4 37
2 4 25 30 ADD A,B,6 TO C GIVING D(D=A+B+6+C)
2 4 25 37
2 4 25 30 ADD A, B TO C,D(C=A+B+C)(D=A+B+D)
2 4 31 36
Before
WS00-IN1 123WS00-OUT1 0000
After
WS00-IN1 123WS00-OUT1 0123
Before
ADD
Copyright © 2008, Infosys Technologies Ltd. 7272
WS00-IN1 123WS00-OUT2 0000
After
WS00-IN1 123WS00-OUT2 0223
Before
WS00-IN1 123WS00-IN2 456WS00-OUT3 0000
After
WS00-IN1 123WS00-IN2 456WS00-OUT3 0579
SUBTRACT Verb (1/2)
SYNTAX
SUBTRACT {identifier-1, literal-1} [ identifier-2, literal-2]…FROM identifier-3
[identifier-4] [, GIVING identifier-5 [,identifier-6]…]
Copyright © 2008, Infosys Technologies Ltd. 7373
2
Contents BeforeA B C D
COBOL Statement Contents AfterA B C D
21 SUBTRACT 10 FROM A 11
2 4 SUBTRACT A FROM B 2 2
2 4 25 SUBTRACT A FROM B GIVING C(C=A-B)
2 4 2
SUBTRACT Verb (2/2)
Copyright © 2008, Infosys Technologies Ltd. 7474
(C=A-B)
2 4 25 SUBTRACT A,B,6 FROM C(C=C-(A+B+6))
2 4 13
2 4 25 30 SUBTRACT A,B,6 FROM C GIVING D(D=C-(A+B+6))
2 4 25 13
2 4 25 30 SUBTRACT A,B FROM C ,D(C=C-(A+B))(D=D-(A+B))
2 4 19 24
Before
WS00-IN1 111WS00-OUT1 1111
After
WS00-IN1 111WS00-OUT1 1000
Before
WS00-IN1 111WS00-OUT2 2222
SUBTRACT
Copyright © 2008, Infosys Technologies Ltd. 7575
WS00-OUT2 2222
After
WS00-IN1 111WS00-OUT2 2000
Before
WS00-IN1 111WS00-IN2 555WS00-OUT3 6666WS00-OUT4 9666
After
WS00-IN1 111WS00-IN2 555WS00-OUT3 6666WS00-OUT4 6000
MULTIPLY Verb (1/2)
SYNTAX
MULTIPLY {identifier-1, literal-1} BY identifier-2 [ identifier-3 ] . . . [ , GIVING identifier-4 [ , identifier-5 ] . . . ]
Copyright © 2008, Infosys Technologies Ltd. 7676
MULTIPLY Verb (2/2)MULTIPLY Verb (2/2)
Contents BeforeA B C D
COBOL Statement Contents AfterA B C D
2 MULTIPLY 10 BY A 20
2 4 MULTIPLY 10 BY A GIVING B 2 20
2
Copyright © 2008, Infosys Technologies Ltd. 7777
2 4 MULTIPLY A BY B 2 8
2 4 25 MULTIPLY A BY B GIVING C 2 4 8
2 4 25 30 MULTIPLY A BY B GIVING C, D
2 4 8 8
Before
WS00-IN1 100WS00-OUT1 1111
After
MULTIPLY
Copyright © 2008, Infosys Technologies Ltd. 7878
WS00-IN1 100WS00-OUT1 1000
Before
WS00-IN1 100WS00-OUT2 0222WS00-OUT3 0666
After
WS00-IN2 100WS00-OUT2 2200WS00-OUT3 6600
DIVIDE Verb (1/2)
SYNTAX-1
SYNTAX-2
DIVIDE { identifier-1, literal-1 } INTOidentifier-2 [, identifier-3]…..[ GIVINGidentifier-4 [ , identifier-5]…..].
Copyright © 2008, Infosys Technologies Ltd. 7979
SYNTAX-2
SYNTAX-3
DIVIDE { identifier-1, literal-1 } BY {identifier-2, literal-2} GIVING identifier-3 [ , identifier-4].
DIVIDE { identifier-1, literal-1 } { INTO , BY } { identifier-2, literal-2 } GIVING identifier-3 REMAINDER identifer-4.
2
DIVIDE Verb (2/2)DIVIDE Verb (2/2)
Contents BeforeA B C D
COBOL Statement Contents AfterA B C D
21 3 DIVIDE A BY B 21 7
21 3 DIVIDE B INTO A 7 3
21 DIVIDE 7 INTO A 3
Copyright © 2008, Infosys Technologies Ltd. 8080
21 DIVIDE 7 INTO A 3
21 3 25 DIVIDE B INTO A GIVING C 21 3 7
21 8 3 1 DIVIDE A BY B GIVING C REMAINDER D
21 8 2 5
21 8 3 1 DIVIDE B INTO A GIVING C REMAINDER D
21 8 2 5
Before
WS00-IN1 100WS00-OUT1 1000
After
DIVIDE
Copyright © 2008, Infosys Technologies Ltd. 8181
WS00-IN1 100WS00-OUT1 0010
Before
WS00-IN2 1000WS00-OUT2 2000WS00-OUT3 00
After
WS00-IN2 1000WS00-OUT2 0008WS00-OUT3 16
STOP RUNSTOP RUN
SYNTAX
STOP RUN
Copyright © 2008, Infosys Technologies Ltd. 8282
� Instructs the computer to terminate the program.
� Closes all the files that were opened for file operations.
� The STOP RUN is usually the last statement in the main paragraph .
SummarySummary
� History of COBOL� Features of COBOL� Structure of COBOL Program� COBOL Coding Rules� Data Types in COBOL� Declaration of Data Items using Level Numbers and
Copyright © 2008, Infosys Technologies Ltd. 8383
� Declaration of Data Items using Level Numbers and PICTURE Clause
� Elementary and Group Items� Data Movement Verbs� Input/Output Verbs� Arithmetic Verbs� STOP RUN
Copyright © 2008, Infosys Technologies Ltd. 84848484
Thank You
“The contents of this document are proprietary and confidential to Infosys Technologies Ltd. and may not be disclosed in whole or in part at any time, t o any third party without the prior written consent of Infosys Technologies Ltd.”
“© 2008 Infosys Technologies Ltd. All rights reserv ed. Copyright in the whole and any part of this document belongs to Infosys Technologies Ltd. This work may not be used, sold, transferred, adapted, abridged, copied or reproduced in whole or in part, in any manner or form, or in any media, without th e prior written consent of Infosys Technologies Ltd.”