+ All Categories
Home > Documents > Cobol Day 3and4

Cobol Day 3and4

Date post: 11-Apr-2015
Category:
Upload: api-3838727
View: 946 times
Download: 0 times
Share this document with a friend
84
COBOL (COMMON BUSINESS ORIENTED LANGUAGE) Overview
Transcript
Page 1: Cobol Day 3and4

COBOL (COMMON BUSINESS ORIENTED

LANGUAGE)

Overview

Page 2: Cobol Day 3and4

COBOL Fundamentals

DAY3

Page 3: Cobol Day 3and4

SEQUENCE CONTROL verbs

GO TO

IF . . . THEN . . .

PERFORM

EVALUATE

STOP RUN

Page 4: Cobol Day 3and4

GO TO Verb

Syntax-1

GO TO paragraph-name.

Example

GO TO 400-READ-PARA.

Page 5: Cobol Day 3and4

GO TO . .

Syntax-2

GO TO paragraph-name-1 [paragraph-name-2

]Example

GO TO 500-INSERT-PARA, 600-UPDATE-PARA, 700-DELETE-PARA DEPENDING ON TRANS-CODE.

Page 6: Cobol Day 3and4

IF statement

Syntax-1

IF condition [ THEN ] {statement-1, NEXT SENTENCE}

[ELSE {statement-2, NEXT SENTENCE}]

[ END-IF ].

Examples

(1) IF MARKS >= 80 THEN MOVE ‘A’ TO GRADEELSE MOVE ‘B’ TO GRADE

END-IF.

(2) IF NOT OK-BALANCE THEN MOVE 2 TO BALANCE-CODE ELSE NEXT-SENTENCE END-IF

Page 7: Cobol Day 3and4

Relation Conditions

Identifier

Literal

ArithmeticExpression

Identifier

Literal

ArithmeticExpression

IS

NOT GREATER THAN

NOT >

NOT LESS THAN

NOT <

NOT EQUAL TO

NOT =

GREATER THAN OR EQUAL TO

>=

LESS THAN OR EQUAL TO

<=

Page 8: Cobol Day 3and4

IF statement

Syntax-2 ( Nested IF )

IF condition-1 [ THEN ] statement-1ELSE

IF condition-2 [ THEN ] statement-2

ELSE statement-3 END-IF

END-IF.

Example

IF ( Var1 < 10 ) THEN DISPLAY “Zero” ELSE

IF Var2 = 14 THEN DISPLAY “First” ELSE DISPLAY “Second” END-IF

END-IF.

Page 9: Cobol Day 3and4

Sign condition

Syntax

ZERO

NEGATIVE

POSITIVE

]NOT[ IS Expression Arithmetic

Example

IF DISCRIMINANT IS NEGATIVE THEN DISPLAY “The roots are imaginary”.

Page 10: Cobol Day 3and4

Class condition

Syntax

Identifier IS [NOT]

NUMERIC

ALPHABETIC

ALPHABETIC - LOWER

ALPHABETIC - UPPER

UserDefinedClassName

Example

IF REGNO IS NOT NUMERIC

THEN DISPLAY “Records will not be sorted”.

Page 11: Cobol Day 3and4

Compound Condition

Syntax

Condition-1 { AND, OR } Condition-2

Examples

(1) IF PERCENT > 80 AND TOTAL > 480

THEN MOVE ‘A’ TO GRADE.

(2) IF ROW-NUMBER > 24 OR COLUMN > 80

THEN DISPLAY “Page Error ! “.

Page 12: Cobol Day 3and4

Defining Condition Names.

Condition Names are defined using the special level number 88 in the DATA DIVISION of a COBOL program.

They are defined immediately after the definition of the data item with which they are associated with.

We can use Condition Names for a group as well as an elementary item.

A condition name takes the value TRUE or FALSE depending on the value of the data item with which it is associated. The VALUE clause of the associated data item is used to identify the values which make the Condition Name TRUE.

88 ConditionName VALUE

VALUES

Literal

LowValue THROUGH

THRU HighValue

Page 13: Cobol Day 3and4

Condition Names

Are essentially boolean variables.

Are always associated with data names called condition variables.

Is defined in the DATA DIVISION with levelnumber 88.

Syntax

88 condition-name {VALUE IS, VALUES ARE } literal-1 [ { THRU, THROUGH } literal-2 ].

Page 14: Cobol Day 3and4

Condition-Names .. example

01 MARITAL-STATUS PIC 9.

88 SINGLE VALUE IS ZERO. 88 MARRIED VALUE IS 1. 88 WIDOWED VALUE IS 2. 88 DIVORCED VALUE IS 3. 88 ONCE-MARRIED VALUES ARE 1, 2, 3. 88 VALID-STATUS VALUES ARE 0 THRU 3.

PROCEDURE DIVISION Statements.DISPLAY ‘ENTER MARTIAL STATUS.:’.ACCEPT MARITAL-STATUS.IF SINGLE SUBTRACT 125 FROM DEDUCTIONS.IF ONCE-MARRIED ADD 300 TO SPECIAL-PAY.IF MARRIED PERFORM B000-MARRIAGE-GIFT.

Condition Names

Martial-status = 0

Martial-status = 2

Martial-status = 1

Page 15: Cobol Day 3and4

Before

WS00-MARKS 000

WS00-DISP

After

WS00-MARKS 050

WS00-DISP NOT CLEARED COMPRE

Before

WS00-MARKS 000

WS00-DISP

After

WS00-MARKS 081

WS00-DISP PASSED COMPRE

JCL000100 //ER4857C JOB ,,NOTIFY=&SYSUID,CLASS=B

000500 //STEP1 EXEC PGM=COND88

000700 //STEPLIB DD DSN=OPERN.CICS3.LOADLIB,DISP=SHR

000800 //SYSIN DD *

000900 050

001000 081

001100 /*

Page 16: Cobol Day 3and4

The PERFORM Verb

Iteration constructs are used when we need to repeat the same instructions over and over again in our programs.

Other programming languages have a variety of iteration / looping constructs (e.g. WHILE, FOR, REPEAT). Each of these in turn facilitate the creation of different ‘types’ of iteration structure.

In COBOL we have ‘PERFORM’ verb which is used to create these looping constructs. The PERFORM has several variations each of which simulates different looping constructs of other programming languages.

Page 17: Cobol Day 3and4

Paragraphs - Revisited

A PARAGRAPH comprises of one or more sentences.

The paragraph-name indicates the start of a paragraph. The next paragraph or section name or the end of the program text terminates the paragraph.

Paragraph names are either user defined or language enforced. They are followed by a full stop.

B0000-PERF-PARA.

PROGRAM-ID.

Page 18: Cobol Day 3and4

PERFORM Verb - variations

Simple PERFORM

In-line PERFORM

Nested PERFORM

PERFORM . . . THRU

PERFORM . . . UNTIL

PERFORM . . . TIMES

PERFORM . . . VARYING

Page 19: Cobol Day 3and4

PERFORM Verb - Simple PERFORM

Syntax

PERFORM Paragraph-Name.

Example

PERFORM 500-PROCESS-PARA.

This is not iterative but instructs the computer to execute the chunk of code inside the mentioned paragraph before reverting back to the sentence following the PERFORM coded.

Page 20: Cobol Day 3and4

PERFORM Verb – Simple PERFORM example

****************************************

WE ARE INSIDE B000-LAST-PARA

WE ARE INSIDE B001-FIRST-PARA

WE ARE INSIDE B002-MIDDLE-PARA

****************************************

Output SPOOL

Page 21: Cobol Day 3and4

PERFORM Verb - In-line PERFORM

Syntax

PERFORM imperative-statements.

Example

PERFORM MOVE NUM-1 TO MAXIF NUM-2 > MAX THEN MOVE NUM-2 TO

MAXDISPLAY “Maximum is ” MAX.

END-PERFORM

Page 22: Cobol Day 3and4

INLINE PERFORM PROGRAM

Page 23: Cobol Day 3and4

JCL FOR THE INLINE PERFORM PROGRAM

Page 24: Cobol Day 3and4

When SYSIN data satisfies the condition WS-STRING = ‘KARINA’ the scope of the INLINE PERFORM gets

terminated

Page 25: Cobol Day 3and4

PERFORM Verb – Nested PERFORM

Syntax

Paragraph-Name-1. PERFORM Paragraph-Name-2. . . . . . . . . . .Paragraph-Name-2. PERFORM Paragraph-Name-3.

. . . . . . . . . .Paragraph-Name-3. MOVE A TO B.

. . . . . . . . . .

Page 26: Cobol Day 3and4

PERFORM Verb – Nested PERFORM

****************************************

WE ARE INSIDE B000-LAST-PARA

WE ARE INSIDE B001-FIRST-PARA

WE ARE INSIDE B002-MIDDLE-PARA

****************************************

Output SPOOL

Page 27: Cobol Day 3and4

PERFORM Verb – PERFORM … THRU …

Syntax

PERFORM Paragraph-Name-1 [ { THRU, THROUGH }

Paragraph-Name-2 ].

Example

PERFORM 300-READ-PARA THRU 600-UPDATE-PARA.

Page 28: Cobol Day 3and4

PERFORM … THRU … - example

****************************

WE ARE INSIDE B000-DISP-PARA

WE ARE INSIDE B001-DISP-PARA

WE ARE INSIDE B002-DISP-PARA

****************************

Output SPOOL

Page 29: Cobol Day 3and4

PERFORM Verb – PERFORM .. UNTIL ..

Syntax

PERFORM Paragraph-Name-1 [ { THRU, THROUGH }

Paragraph-Name-2 ] UNTIL condition.

Example

PERFORM 300-READ-PARA UNTIL EOF = ‘N’.

Page 30: Cobol Day 3and4

PERFORM Verb – PERFORM . . UNTIL .. WITH TEST AFTER OPTION

Syntax

PERFORM Paragraph-Name-1 [ { THRU, THROUGH }

Paragraph-Name-2 ]

[WITH TEST {BEFORE, AFTER}]

UNTIL condition.

ExamplePERFORM 300-PROCESS-PARA WITH TEST AFTER

UNTIL VALUE NOT = 0.

Page 31: Cobol Day 3and4

PERFORM Verb …PERFORM . . UNTIL .. WITH TEST AFTER OPTION

This format is used where the WHILE or REPEAT constructs are used in other languages.

If the WITH TEST BEFORE phrase is used the PERFORM behaves like a WHILE loop and the condition is tested before the loop body is entered.

If the WITH TEST AFTER phrase is used the PERFORM behaves like a REPEAT loop and the condition is tested after the loop body is entered.

The WITH TEST BEFORE phrase is the default and so is rarely explicitly stated.

Page 32: Cobol Day 3and4

PERFORM Verb – PERFORM . . UNTIL .. WITH TEST BEFORE

****************************

****************************Output SPOOL

Page 33: Cobol Day 3and4

PERFORM Verb – PERFORM . . UNTIL .. WITH TEST AFTER

****************************

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

WE ARE INSIDE B000-PERF-PARA

****************************

Output SPOOL

10 Times!! Why?

Page 34: Cobol Day 3and4

PERFORM Verb – PERFORM .. TIMES

Syntax

PERFORM Paragraph-Name-1 [ { THRU, THROUGH }

Paragraph-Name-2 ] { integer, identifier } TIMES.

Example

PERFORM 500-PROCESS-PARA THRU 800-END-PARA 8 TIMES.

Page 35: Cobol Day 3and4

PERFORM Verb – PERFORM .. TIMES …… Example

****************************

HELLO GUEST. WELCOME TO E&R TRAINING

HELLO GUEST. WELCOME TO E&R TRAINING

HELLO GUEST. WELCOME TO E&R TRAINING

HELLO GUEST. WELCOME TO E&R TRAINING

HELLO GUEST. WELCOME TO E&R TRAINING

****************************

Output SPOOL

Page 36: Cobol Day 3and4

PERFORM Verb - PERFORM . . . VARYING

Syntax

PERFORM Paragraph-Name-1 [ { THRU, THROUGH }Paragraph-Name-2 ] VARYING identifier-1 FROM{identifier-2, integer-1} BY { identifier-3, integer-2 }

UNTIL condition.

Example

PERFORM 500-WRITE-PARA

VARYING I FROM 1 BY 1

UNTIL I > 5.

Page 37: Cobol Day 3and4

PERFORM Verb - PERFORM . . . VARYING

****************************

HELLO GUEST. WISH YOU ALL THE BEST

HELLO GUEST. WISH YOU ALL THE BEST

HELLO GUEST. WISH YOU ALL THE BEST

HELLO GUEST. WISH YOU ALL THE BEST

****************************

Output SPOOL

Page 38: Cobol Day 3and4

PERFORM ...VARYING Syntax

PERFORM-ENDlock StatementB

Condition2 UNTIL Literal

6Identifier BY

4

5

FROM IndexName3

4Identifier AFTER

Condition1 UNTIL Literal

3Identifier BY

2

2

FROM IndexName1

Identifer1 VARYING

AFTER

BEFORE TEST WITH EndProc

THROUGH

THRU 1stProc PERFORM

Literal

IndexName

Identifier

Literal

IndexName

Identifier

Page 39: Cobol Day 3and4

PERFORM .. VARYING Example

Page 40: Cobol Day 3and4

PERFORM .. VARYING Example

Gives the IX1th occurrence of the array

Page 41: Cobol Day 3and4

PERFORM .. VARYING Example

OUTPUT SPOOL

Page 42: Cobol Day 3and4

EVALUATE Verb

The EVALUATE verb provides a very powerful construct to carry out DATA validation. It is similar to the SWITCH statement in C programs.

It assists us in implementing decision table logic.

Syntax

EVALUATE subject-1 [ ALSO subject-2 ] . . .

{ { WHEN object-1 [ ALSO object-2 ] . . . } . . . }

imperative-statement-1 } . . .

WHEN subject = { identifier, expression, TRUE, FALSE }

and object = { condition, TRUE, FALSE }.

Page 43: Cobol Day 3and4

The Evaluate

EVALUATE

Identifier

Literal

CondExpression

ArithExpression

TRUE

FALSE

WHEN

ANY

Condition

TRUE

FALSE

NOT

Identifier

Literal

ArithExpression

THRU

THROUGH

Identifier

Literal

ArithExpression

StatementBlock

WHEN OTHER StatementBlock

END - EVALUATE

Page 44: Cobol Day 3and4

EVALUATE Verb .. example

There are two valid ranges

which the logic checks for –

1) Marks > 79

2) Marks > 64 & <= 79

*************************************

YOU HAVE CLEARED EXAM WITH A GRADE

*************************************Output SPOOL

Page 45: Cobol Day 3and4

STOP RUN statement

Syntax : STOP RUN.

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.

Page 46: Cobol Day 3and4

COBOL DAY 4

Overview

Page 47: Cobol Day 3and4

Array

An array is a Linear data structure and is a collection of homogenous data items that can be referred by a single data name.

The data items contained in an array are called its elements.

The elements of an array are internally stored in contiguous memory locations.

The elements of an array may be elementary or group items.

An array can have dimension up to 7 in COBOL-85.

Page 48: Cobol Day 3and4

ARRAY – Defining an Array

Similar to any other data item an array is defined in the DATA DIVISION.

To specify the repeated occurrence of data items with the same format, the OCCURS clause is used.

The OCCURS clause specifies the maximum number of elements that can be stored in the array.

The OCCURS clause can be used only with level numbers 02 to 49.

Page 49: Cobol Day 3and4

ARRAY – Single dimensional Array

Array Declaration

Page 50: Cobol Day 3and4

ARRAY – Multi dimensional Array

Array Declaration

For Output spool display

Output Spool of the

Job

Page 51: Cobol Day 3and4

Defining an Array – Using Indexed clause

INDEXED ARRAY

Page 52: Cobol Day 3and4

Defining an Array – Using Indexed clause

Output Spool of the

Job

Page 53: Cobol Day 3and4

Declaring Tables – An examplePROJECT EMP# EMPNAME

BANKS 11111 SRINI

BANKS 22222 JYOTI

MKTNG 33333 VINAY

MKTNG 44444 SARMA

Page 54: Cobol Day 3and4

Declaring Tables – An example

Page 55: Cobol Day 3and4

Declaring Tables – An example

DISPLAY '**************************************************'

DISPLAY 'WS00-ORG : ' WS00-ORG

DISPLAY 'WS00-IBU FIRST OCCUR : ' WS00-IBU(1)

DISPLAY 'WS00-PROJ FIRST OCCUR : ' WS00-PROJ(1,1)

DISPLAY 'WS00-EMP : ' WS00-EMP(1,1)

DISPLAY 'WS00-EMPNAME : ' WS00-EMPNAME(1,1)

DISPLAY '**************************************************'

PROJECT EMP# EMPNAME

BANKS 11111 SRINI

BANKS 22222 JYOTI

MKTNG 33333 VINAY

MKTNG 44444 SARMA

Page 56: Cobol Day 3and4

Accessing the elements of an array

Can be done using the data-name that is lowest in the hierarchy with subscript .

The subscript is a positive integer

The subscript must be enclosed within a pair of parenthesis.

The highest value that the subscript can take is the integer value specified in the OCCURS clause.

The elements of an array can be used for arithmetic and logical operations similar to any ordinary data-items.

Page 57: Cobol Day 3and4

SET statement

Is used to modify the index value.

Syntax-1

SET index-1 , . . . TO { index-2, identifier-2, integer-1 }.

Syntax-2

SET index-1, . . . { UP BY, DOWN BY } { integer, identifier }.

Page 58: Cobol Day 3and4

SUBSCRIPT Vs INDEX

Subscript Index

(1) Is a WORKING-STORAGESECTION variable defined by the user.

Is a special subscript created

and maintained by the operating System.

(2) Represents an occurrence of array element

Represents a displacement from

the address of the first element

(3) To modify the value of a

subscript, the MOVE or

Arithmetic verbs are used.

To modify the value of an index,

the SET verb is used.

Page 59: Cobol Day 3and4

SEARCH Statement

Syntax

SEARCH table-name [ VARYING index ]

[ AT END imperative statement-1 ]

{ WHEN condition-1 { statement-2, NEXT SENTENCE }} . . .

[ END-SEARCH ].

Page 60: Cobol Day 3and4

Searching in a table

Looking forward to locate the presence of ‘Z’ in the given

string/array

Page 61: Cobol Day 3and4

Searching in a table

JCL

Output Spool

Page 62: Cobol Day 3and4

SEARCH ALL

Syntax

SEARCH ALL Table-Name [AT END imperative-statement-1]

WHEN { identifier-1 { IS EQUAL TO, IS = } {identifier-2,

literal-1, arithmetic-expression-1 }

imperative-statement-2.

Page 63: Cobol Day 3and4

SEARCH ALL

Limitations of SEARCH ALL compared SEARCH

The condition following the word WHEN can test only for equality.

If the condition following the word WHEN is a compound condition then it can use only AND but not OR.

Multiple WHENs can not be used.

The VARYING option can not be used.

The item defined with OCCURS clause with its index must appear to the left of equal to sign.

Page 64: Cobol Day 3and4

SEARCH vs. SEARCH ALL SEARCH SEARCH ALL

(1) Table entries need not be in Table entries must be sequence. any sequence.

(2) Requires SET statement Does not need a SET prior to prior to SEARCH statement. SEARCH ALL statement.

(3) Can include any relational Can only have a single = condition with WHEN clause. condition with WHEN clause. (4) May include multiple WHEN May include only one WHEN

clause. clause.(5) Linear Search Binary Search

Page 65: Cobol Day 3and4

STRING HANDLING VERBS

Inspect

String

Unstring

Page 66: Cobol Day 3and4

INSPECT statement

The INSPECT statement can be used to

1. Count the number of occurrences of a given character in a field.

2. Replace specific occurrences of a given character with another character.

Page 67: Cobol Day 3and4

INSPECT statement

Syntax

INSPECT identifier-1 TALLYING { counter-1 FOR { {ALL, LEADING } , CHARACTERS , { char-1, literal-1 } } [ { BEFORE, AFTER } INITIAL { delimiter-4, literal-2 } ] }. . .

Page 68: Cobol Day 3and4

INSPECT – How does it work

a) The INSPECT scans the Source String from left to right counting and/or replacing characters under the control of the TALLYING, REPLACING or CONVERTING phrases.

b) The behavior of the INSPECT is modified by using the LEADING, FIRST, BEFORE and AFTER phrases.

c) An ALL, LEADING, CHARACTERS, FIRST or CONVERTING phrase may only be followed by one BEFORE and one AFTER phrase.

Page 69: Cobol Day 3and4

INSPECT – Modifying phrases

1) LEADINGThe LEADING phrase causes counting/replacement of all

Compare$il characters from the first valid one encountered to the first invalid one.

2) FIRSTThe FIRST phrase causes only the first valid character to be

replaced.

3) BEFOREThe BEFORE phrase designates as valid those characters to

the left of the delimiter associated with it.

4) AFTERThe AFTER phrase designates as valid those characters to

the right of the delimiter associated with it.

Page 70: Cobol Day 3and4

INSPECT – Example (finding occurrences)

INSPECT statement for finding the number of times a given character comes in a given name

Display messages to come in sysout

Page 71: Cobol Day 3and4

INSPECT – Example (finding occurrences)

JCL for executing program INSPEC

Name & Character passed to program by SYSIN in JCL

OUTPUT SPOOL

Page 72: Cobol Day 3and4

STRING statement

The STRING statement may be used to combine several fields to form one concise field. This process is called concatenation.

Example:

Suppose the structure of NAME field is

01 NAME. 05 F-NAME PIC A(10). 05 M-NAME PIC A(10). 05 L-NAME PIC A(10).

Let us say that the value of NAME field is THOMASALVAEDISON. We may wish to print the name with only a single blank between each component as THOMAS ALVA EDISON. We can use the STRING statement.

Page 73: Cobol Day 3and4

STRING statementSyntax

STRING

{ { identifier-1, literal } DELIMITED BY { identifier-2, literal-2, SIZE }} { { identifier-3, literal } DELIMITED BY { identifier-4, literal-2, SIZE }} INTO identifier-5

END-STRING.

ExampleSTRING

F-NAME DELIMITED BY ‘ ‘‘ ‘ DELIMITED BY SIZE M-NAME DELIMITED BY SIZE‘ ‘ DELIMITED BY SIZEL-NAME DELIMITED BY SIZE

INTO NAME.

Page 74: Cobol Day 3and4

STRING statement

Rules for using the STRING statement

1) The DELIMITED BY clause is required. It can indicate a) SIZE : The entire sending field is transmitted.

b) Literal : The transfer of data is terminated when the specified literal is encountered; the literal is not moved.

c) Identifier : The transfer of data is terminated when the contents of the identifier is encountered.

2) The receiving field must be an elementary data item with no editing symbols is JUSTIFIED RGHT.

3) All literals must be described as nonnumeric.

Page 75: Cobol Day 3and4

STRING statement

Rules for using the STRING statement

4) The identifier specified with the POINTER clause must be an elementary numeric item.

5) The STRING statement moves data left to right just like alphabetic fields are moved, but a STRING does not pad with low ordered, unlike an alphanumeric MOVE.

Page 76: Cobol Day 3and4

STRING statement

OVERFLOW Option

STRING . . . [ ON OVERFLOW imperative-statement ].

POINTER Option

STRING . . . [ WITH POINTER identifier ] [ ON OVERFLOW . . . ].

Page 77: Cobol Day 3and4

STRING - Example

Display in the spool

STRING statement

Page 78: Cobol Day 3and4

STRING - Example

JCL for executing program STRNG

Display in the Output spool

Page 79: Cobol Day 3and4

UNSTRING statement

The UNSTRING statement may be used to convert keyed data to a more compact form for storing it on disk.

For example, a program may include a statement that causes the following to be displaced on a screen.

ENTER NAME: LAST, FIRST, MIDDLE INITIAL

: USE COMMAS TO SEPARATE ENTRIES

Since each name has a variable number of characters, there is no way of knowing how large each individual last name and first name is. With the UNSTRING statement, we can instruct the computer to separate the NAME-IN into its components and store them without the commas.

Page 80: Cobol Day 3and4

UNSTRING statement

Syntax

UNSTRING identifier-1 [ DELIMITED BY [ ALL ] { identifier-2, literal-1 } [ OR [ ALL] { identifier-3, literal-2 }] . . .]

INTO identifier-4 . . . [ END-UNSTRING ].

Page 81: Cobol Day 3and4

UNSTRING statement

Rules for using the unstring statement

1. The sending field must be nonnumeric. The receiving fields numeric or nonnumeric.

2. Each literal must be nonnumeric.

3. The WITH POINTER and ON OVERFLOW clauses can be used in the same way as with the STRING statement.

Page 82: Cobol Day 3and4

UNSTRING - Example

Page 83: Cobol Day 3and4

UNSTRING - Example

JCL for executing program

UNSTRNG

Display in the Output spool

Page 84: Cobol Day 3and4

Some Common programming problems

• DATA EXCEPTIONPerforming arithmetic operation or comparison on afield containing BLANKS or non-numeric data

• DIVIDE EXCEPTIONAttempting to divide by ZERO

• ADDRESSING ERRORWhen we have Invalid value placed in a sub-script or index.This might lead to addressing beyond the table boundaries.

• OPERATION ERRORAttempting to access file before opening it.

Some common abend codes are –S0C4 : Protection exception (Unable to convert virtual to real address)S0C7 : Data Exception (Bad data in decimal field)S322 : Job/Program exceeded time limit. Program is loopingS222 : Job was cancelled by operator or JES


Recommended