COBOL KEYWORDS

1

INTRODUCTION 

Keywords are special, predefined syntactic meanings in a program  In COBOL, the keywords are reserved, and cannot be used as identifiers.

2

the value of c will be 11. 77 C PIC 99V9 VALUE IS 42. B.685.412. SUBTRACT A FROM B GIVING C ROUNDED.B GIVING C ROUNDED.861 3 .ADD & SUBTRACT statement ADD : EX: ADD A.9 instead of 11. after execution. 77 B PIC 99V999 VALUE IS 35. 77 A PIC 99V999 VALUE IS 23. SUBTRACT : SUBTRACT 10 FROM A .7 instead of 58.273. SUBTRACT A . ADD A.3.B GIVING C ROUNDED ADD statement after execution the value of c will be 58.B FROM C .

4 DIVIDE : . 77 B PIC 9(2) VALUE IS 5.MULTIPLY & DIVIDE STATEMENT MULTIPLY : MULTIPLY A BY B GIVING C. DIVIDE 5 INTO A GIVING B.Y. DIVIDE 3 INTO A GIVIING B. DIVIDE A BY 3 GIVING C. MULTIPLY 10 BY A . x would have product of 10 and A. DIVIDE 5 INTO A. 77 A PIC 9(2) VALUE IS 15. Y would have product of 10 and B. B GIVING X.C. DIVIDE C BY B GIVING A REMAINDER D. 77 C PIC 9(2) VALUE IS 34.

Example : COMPUTE A = ( ( B + C ) / ( D ± E ) ) * 100 5 . Syntax : COMPUTE Identifier-1 = Arithmetic expression.COMPUTE STATEMENT All the computations performed by the other four arithmetic statements can be done by using only the COMPUTE statement.

6 . the ON SIZE ERROR occurs. the result exceeds the largest value that can be accommodated in the result field. zero division It is an optional phrase Syntax : < Arithmetic statement > ON SIZE ERROR Imperative Statement.ON SIZE ERROR OPTION If after an arithmetic operation. Useful in detecting overflow.

[UPON mnemonic-name] [WITH NO ADVANCING] 7 .DAY. .ACCEPT & DISPLAY ACCEPT Syntax: ACCEPT identifier [ FROM {mnemonic-name / system variable}] ‡ mnemonic-name is the device identifier as defined in SPECIAL-NAMES paragraph in ENVIRONMENT DIVISION ‡ system variable may be DATE.TIME DISPLAY  Displays data on the console. {Identifier-2 / Literal-2}. .  Syntax: DISPLAY [ Identifier-1/ Literal-1] .

. or identifier to identifier ‡ DOES NOT ACTUALLY MOVE BUT COPIES ‡ Numeric data is aligned according to decimal point and receiving field is padded with zeroes ‡ Alphabetic / alphanumeric data is left justified in receiving field Syntax: MOVE Literal-1 [. 8 . Identifier-1] TO Identifier-2 [. Identifiers-3].DATA MOVEMENT ± MOVE VERB ‡ Moves data values from literal to identifier. .

DATA MOVEMENT ± MOVE VERB 9 .

YY-00 MOVE CORRESPONDING  Data items of one group are moved to data items of another group-If names of corresponding data items of both groups are identical-no use of move statements 10 .GROUP MOVE  Data items in GROUP MOVE is considered to be alphanumeric 01 DATE 05 DD 05 MM 05 YY PIC PIC PIC 99 99 99 MOVE 123 TO DATE Contents after MOVE DD-12. MM-30.

2 must refer to group items  Data items must have same data names  Corresponding items can have different locations within the group  Field size can be different MOVE CORRESPONDING Example 01 PAY-REC 01 PROFILE 02 IDNUM PIC 9(2) 02 IDNUM PIC 9(3) 02 NAME PIC X(30) 02 DEPT PIC X(3) 02 SALARY PIC 9(7)V99 02 SALARY PIC 9(6)V9 02 NAME PIC X(35)  MOVE CORRESPONDING PAY-REC TO PROFILE 11 .MOVE CORRESPONDING ID-1 TO ID-2 RULES  Identifiers 1.

PARTIAL MOVE  Partial fields can be moved in COBOL¶85 EXAMPLE 77 ABC PIC X(5) VALUE µCOBOL¶ 77 XYZ PIC X(5) MOVE ABC(3 : 3) TO XYZ µBOLbb¶ 12 .

13 .CONTINUE & EXIT  The CONTINUE statement allows to specify a no operation statement.  The EXIT statement provides a common end point for a series of programs.  CONTINUE indicates that no executable instruction is present.

GOTO STATEMENT  Unconditionally transfers control from one part of program to other part of program  Format: GO TO ± Paragraph name  Can¶t track the flow of the program 14 .

Syntax :EVALUATE Identifier-1 WHEN Identifier/Literal Imperative Statement(s) WHEN OTHER Imperative Statement(s) END-EVALUATE.EVALUATE STATEMENT Evaluate statement is used when different actions are to be specified for different values of an identifier. Example : EVALUATE MARKS WHEN 50 THRU 100 MOVE ³A´ TO GRADE WHEN 0 THRU 49 MOVE ³B´ TO GRADE WHEN OTHER MOVE WRONG TO GRADE END EVALUATE. 15 .

we need to declare the counter variables. 16 . Syntax : EXAMINE identifier TALLYING [ALL/LEADING/UNTIL FIRST] literal-1 REPLACING BY literal-2 INSPECT identifier-1 TALLYING identifier-2 FOR [ALL/LEADING] identifier -3 [BEFORE/AFTER] INITIAL identifier-4 ‡ In Examine. a counter variable tally is used as default but in inspect.EXAMINE AND INSPECT STATEMENTS ‡ EXAMINE and INSPECT are used to tally and/or replace the occurrences of a single character or a group of characters in a data field.

Example 77 A PICX(5) VALUE IS ³EERIE´ EXAMINE A TALLYING ALL ³E´ Tally Register =3 EXAMINE A TALLYING LEADING ³E´ Tally Register=2 EXAMINE A REPLACING UNTIL FIRST ³I´ BY ³P´ A=EERPE MY-STRING = ANANTA KUMAR MAITY INSPECT MY-STRING TALLYING TALLY-COUNT FOR ALL ³A´. If TALLY-1=02.´ AFTER INITIAL ³Z´. now TALLY-1=04 17 . If TALLY-COUNT=08. now TALLY-COUNT=13 MY-STRING = BACDABCZPABCABCPQ INSPECT MY-STRING TALLYING TALLY-1 FOR ALL ³ABC´ BEFORE INITIAL ³.

STRING  Concatenates two or more strings into a single data item  Syntax: STRING Identifier-1 DELIMITED BY [ ALL ] Identifier-2 DELIMITED BY [ ALL ] INTO destination-string [ WITH POINTER pointer integer ] [ ON OVERFLOW statement block ] [ NOT ON OVERFLOW statement block ] [ END-STRING ] 18 .

UNSTRING  Used to divide a string into sub strings  Syntax: UNSTRING Identifier-1 DELIMITED BY [ ALL ] Identifier-2 DELIMITED BY [ ALL ] INTO destination-string [ WITH POINTER pointer integer ] [ ON OVERFLOW statement block ] [ NOT ON OVERFLOW statement block ] [ END-UNSTRING ] 19 .

THANK YOU 20 .

Sign up to vote on this title
UsefulNot useful