Community Sites
Create your own community website and start earning today !
It's Free !
 
Communities Members BookmarksPolls Fresher Jobs Strange Photos Academic Projects New Member FAQ  



My Profile
Active Members
TodayLast 7 Days more...



Awards & Gifts
Online Exams

Fresher Jobs


Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian cities including Bangalore, Chennai, Hyderabad, Pune or Kochi

Resources


Find educational articles, blogs, discussion threads and other resources.

Colleges


Find details about any college in India or search for courses.

website counter




FUNDAMENTALS OF COMPUTER & COBOL(CONDITIONAL AND SEQUENCE CONTROL VERBS):-


Posted Date: 06 Feb 2008    Resource Type: Articles/Knowledge Sharing    Category: Computer & Technology

Posted By: prakash       Member Level: Silver
Rating:     Points: 5



. CONDITIONAL AND SEQUENCE CONTROL VERBS
10.1.CONDITION
A condition is an entity that at one point of time an have only one of the two values- true or false. As already pointed out, the IF Verb makes use of conditions. We shall also see in the next chapter that some forms of the PERFORM and SEARCH verbs also make use of the conditions. In COBOL a condition can be any one of the following.
(i) Relational Condition
(ii) Sign Condition
(iii) Class condition
(iv) Condition-name condition
(v) Negated simple condition and
(vi) Compound condition

10.1.1 RELATIONAL CONDITION
The relational condition has been briefly discussed earlier. We known that a relational condition indicates a comparison between two operands and has the form
Operand-1 relational-operator operand-2

Where the relational-operator can be any one of the following
IS [ NOT ] GREATER THAN
IS [NOT] >
IS [NOT] LESS THAN
IS [NOT] <
IS [NOT] EQUAL TO
IS [NOT] =

10.1.2 SIGN CONDITION
The Sign condition determines whether or not the algebraic value of an operand is positive., negative or Zero. The operand can be either a numeric identifier or an arithmetic expression. The format of this condition is as follows :
Identifier
Arithmetic-expression is [NOT] POSITIVE
NEGATIVE
ZERO
10.1.3 CLASS CONDITION
The Class Condition determines whether or not the value of an operand is numeric or alphabetic. An operand is numeric if it contains only the digits) to 9 with or with our operational sign. An operand is alphabetic if it contains only the letters A to Z and space. The format of the class condition is as follows :

Identifier IS [ NOT ] NUMERIC
ALPHABETIC

10.1.4 CONDITION-NAME CONDITION
Condition name is an entity which itself is a condition and as such can have either a true or false value. It must always associated to a data name called conditional variable. It can be defined in any section in DATA DIVISION, and must be immediately after the entry that defines the conditional variable.

88 condition-name VALUE IS literal-1 THRU literal-2
VLAUES ARE THROUGH

,literal-3 THRU literal-3 ….
THROUGH



10.1.5 Negated simple condition
Any of the simple condition ca be preceded by the logical operator NOT. The effect of placing the operator NOT before a simple condition is to reverse the value of the condition.

10.1.6 Compound condition
The simple condition can be connected by the logical operators AND or OR to form a compound condition (also known as combined condition).
Format:
Condition-1 AND condition-2
OR
EXAMPLE:
IF AGE IS LESS THAN 30 AND (HIGH-EDU OR HIGH-EXP)
MOVE 3 TO BONUS-CODE

10.2.1 NESTED IF SENTENCE
The then and else parts of an IF statement an contain other IF statements the included IF statements in their turn may also contain other IF statements. Such inclusion of one or more IF statements within the scope of an IF Statement if called nesting. Note that the most inclusive IF statement must have a terminating period and thus this statement along with all the included statements is often called a nested IF Sentence.
Example
Consider the following Sentence
IF AMOUNT –CODE IS EQUAL TO OLD – CODE
2) ADD TRNS-VALUE TO TRANS- TOTAL
IF TRANS-VALUE > 1000
1) Add 1 to HIGH-COUNT
ELSE
ADD 1 TO LOW-COUNT

10.4 ALTER STATEMENT
The Alter Statement can be used to modify the targets of Go TO Statements written elsewhere in the PROCEDURE DIVISION. The Syntax of the statement is as follows :
ALTER Procedure-name-1 TO [PROCEED TO] Procedure-name-2
[,proedure-name-3 TO [ PROCEED To] Procedure –name-4]

10.5 PERFORM STATEMENT
The perform Statement can be used to execute a group of consecutive statements written elsewhere in the program. We shall refer to this group of Statements as the range of the PERFORM Statement. During execution, when a PERFORM Statement is encountered, a temporary departure form the normal sequential execution takes place and the statements contained in the specified range are executed.
The format of a simple PERFORM statement is as follows:
PERFORM Procedure-name –1 THRU
THROUGH Procedure-name-2 ]
Example
PERFORM CALCULATE-TAXS
10.6. EXIT STATEMENT
The EXIT verb indicates a no operation, and when executed, no action takes place. The syntax is
EXIT
And this must be the only statement in the paragraph in which it is used. The real use of an EXIT paragraph is in the last paragraph in a PERFORM. Range so that all routes leading to the return mechanism may be gathered here.

8. MORE ABOUT DATA DIVISION
Important data-description clauses, such as PICTURE and VALUE have been described earlier. However, a DATA DIVISION entry can have other clauses as well. Some of these clauses can be effectively used to achieve improvements in the object program; others can be used for convenience in programming.

8.1. USAGE CLAUSE
Normally, a computer can store data in more than one internal form. In COBOL, a programmer is allowed to specify the internal form of the data item so as to facilitate the use of the data item more efficiently.

USAGE IS COMPUTATIONAL {integer}
COMP
DISPLAY


DISPLAY USAGE
This is the most common form of internal data. Each character of the data is represented in one byte and a data-item is stored in a couple of contiguous.
COMPUTATIONAL (COMP) USAGE
When usage is specified as COMP, the numeric data item is represented in pure binary. The Item must be an integer (no assumed decimal point is allowed). Such data items are often used as subscripts (See chapter 11 for he meaning of subscript).
PICTURE S9 (5) v9(3) USAGE IS COMPUTATIONAL-3

8.2 SYNCHRONIZED CLAUSE
The COBOL compiler normally allocates contiguous storage spaces. Thus a data item specified as COMP-1 will be allocated 4 contiguous bytes, which is equivalent to one word. However, the first byte starts immediately after the byte which was allocates for the previous data item.

SYNCHRONIZED
SYNC

01 MY DATA
02 DATE-ONE PIC X(10).
02 DATA-TWO PIC 9(6) COMP SYNC
02 DATA-THREE PIC S9(4)V99 COM-3
8.3 JUSTIFIED CLAUSE
In the case of alphanumeric or alphabetic data movement, the receiving field usually receives data starting from the left-hand side. If this clause is used, the data will be aligned at the rightmost character position.

JUSTIFIED RIGHT
JUST

8.3 REDEFINES CLAUSE
Sometimes it may be found that two or more storage areas defined in the DATA DIVISION are not in use simultaneously. In such cases only one storage area can serve the purpose of two or more areas if the area is redefined.
The REDEFINES clause used for the purpose allows the said area to be referred to by more than one data name with different sizes and pictures.

Example:
01 SALES-REC.
02 SALES-TYPE PIC X(2).
02 SALES-BY-UNIT.
03 QTY PIC 9(4).
03 UNIT-PRICE PIC 9(8)V99.
02 TOTAL-SALES REDEFINES SALES-BY-UNIT.
03 AMOUNT PIC 9(10)V99.
03 F PIC X(2).

8.5 RENAMES CLAUSE
Sometimes a re-grouping of elementary data items in a record may be necessary so that they can belong to the original as well as to the new group.
Example:
01 AY-REC.
03 FIXED-PAY.
05 BASIC–PAY PIC 9(6)V99.
05 D-ALLOW PIC 9(6)V99.
03 ADD-PAY.
05 H-RENT PIC 9(4)V99.
05 M-INCEN PIC 9(3)V99.
03 DED.
05 PF PIC 9(3)V99.
05 IT PIC 9(4)V99.
05 OTHER PIC 9(3)V99.
66 PAY-BASIC RENAMES D-ALLOW THRU M-INCEN
66 IT-AND-PF RENAMES PF THRU IT.
SYNTAX:
66 dataname-1 RENAMES dataname-2 THRU dataname-3

8.6 QUALIFICATION OF DATA NAMES
The data names within a COBOL program need not be unique. When duplicate data names are used, each time such a data name is referred to in the PROCEDURE DIVISION, the programmer must qualify the data name to make it unique.
Format 1:

Dataname-1 OF dataname-2 OF dataname-3 ...
IN IN
Format 2:

dataname-4 OF file-name
IN

8.7 SIGN CLAUSE
A numeric data item when described with S in its picture character string indicates a singed field. The sign is stored in the zone part of the units positions (When the usages is DISPLAY). However, this causes certain difficulties. For example, suppose the record description associated with a card file is as follows :
05 SIGNED-FIELD PIC S9(3)

SIGN IS LEADING
TRAILING [SEPARATE CHARACTER]
Example
77 XYZ PICTURE S9(3) SING TRAILING SEPARATE VALUE-135.
The value is stored internally in four characters as

1 3 5 -


9.MORE ABOUT DATA MOVEMENT VERB AND ARITHMETIC VERBS
9.1. ELEMENTARY AND GROUP MOVES
The receiving or sending field of a MOVE Statement an be either an elementary item or a group item. When both the fields are elementary item, the data movement is known as an elementary move, When at least one of the fields is a group item, it is called a group move, Let us first consider the elementary move.
For example, let FIELD-1 and FIELD-2 be defined as
77 FIELD-2 PIC 9(5) COMP
77 FIELD-2 PIC 9(5).

9.2.1 MOVE CORRESPONDING
Quite often it is required to move some of the data items of one group to some other data items in another group.
MOVE CORRESPONDING PAY-REC TO PRINT –REC.

MOVE CORRESPONDING identifier-1 TO identifier-2
CORR

9.2.2. ADD AND SUBTRACT CORRESPONDING
The CORRESPONDING option can also be used with the ADD and SUBTRACT Verbs. The following are the formants of these verbs with the CORRESPONDING option.

ADD CORRESPONDING identifier-1 To identifier-2
CORR


SUBTRACT CORRESPONDING identifer-1 FROM identifier-2
CORR

9.3 ROUNDED OPTION
Let us consider the following DATA DIVISION entries.
77 A PIC 99V999 VALUE IS 23.412
77 B PIC 99V999 VALUE IS 35.273
77 C PIC 99V9 VALUE IS 41.5.
C=23.412+35.273
=58.685
ADD A B GIVING C ROUNDED
After execution C value is 58.7
9.4. ON SIZE ERROR OPTION
If after an arithmetic operation, the result exceeds the largest value that can be accommodated in the result field, the error is called a Size error.
; ON SIZE ERROR imperative-Statement
When this phrase is specified the imperative statement gets executed, if an ON SIZE ERROR Occurs. Thus a statement.

ADD A TO B ON SIZE ERROR GO TO ERROR- PARA.

9.5 COMPUTE VERB
So far we have discussed only four arithmetic verbs, namely, ADD, SUBTRACT, MULTIPLY and DIVIDE. In COBOL there is another arithmetic verb called.
COMPUTER identifier-1 [ ROUNDED ] [ , identifier-2 ROUNDED ] …
= Arithmetic –expression [ ; ON SIZE ERROR imperative-statement]
Example
COMPUTE F = 1.8 * + 32.

11.TABLE HANDLING

Sometimes, it becomes necessary to handle a group of data consisting of similar items. Such a group is called a table. For example, let us consider the price list. Suppose that each item in this list consists of three fields product code, product name and unit price. Such price list can be viewed as a table because it consists of similar elements.
A table must consist of homogenous elements. Moreover, the element of a table must be ordered in a way such that there is a first element, second element, and so on. This kind of table is known as one dimensional table.

OCCURS CLAUSE AND SUBSCRIPTING

Let us introduce the table with the help of an example. Suppose there are five different direct tax rates which are to be stored in the form of a table named DIRECT-TAX-RATE. One way of describing the said table could be as follows:
01 DIRECT-TAX-RATE.
02 TAX-RATE-1 PIC 99.
02 TAX-RATE-2 PIC 99.
02 TAX-RATE-3 PIC 99.
02 TAX-RATE-4 PIC 99.
02 TAX-RATE-5 PIC 99.
Since each element of this table has identical description, an alternative method for describing the table is to describe the typical element and then to specify that the description is to be repeated five times. This is accomplished by OCCURS clause.

01 DIRECT-TAX-RATE.
02 TAX-RATE PIC 99 OCCURS 5 TIMES.
Here the elements can be referred by means of a technique known as subscripting. For example, the first element is referred to as TAX-RATE(1), the second one as TAX-RATE(2) and so on. The format of OCCURS clause is:
OCCURS integer TIMES.
The following rules apply for the OCCURS clause and subscript.
1. The integer must be positive.
2. The OCCURS clause can be specified for an elementary item or for a group item. The clause causes contiguous area holding the elements to be set up internally. The number of elements is equal to the integer in OCCURS clause.
3. When a data name is described with the OCCURS clause, the data and as well as any of its subordinate items cannot be referred to in the PROCEDURE DIVISION without a subscript.
4. A data name used as a subscript cannot be another subscripted data name.
5. When an entry is defines with OCCURS clause, the value clause cannot be specified for the associated data name or any data name subordinate to it.
6. The OCCURS clause can appear in the data description entry in any position after the level number and the data name.
Consider the following table:
02 AMOUNT-TABLE OCCURS 20 TIMES.
03 AMOUNT PIC 9(6)V99.
03 AMOUNT-CODE PIC X.


PARA1.
IF AMOUNT-CODE(I) IS EQUAL TO “1”
ADD AMOUNT(I) TO TOTAL.

ASSIGNING VALUES TO TABLE ELEMENTS

There are two different ways for storing values in a table. The first method is to store the values by writing necessary statements in the PROCEDURE DIVISION. The values that are to be stored may be obtained from a file or these may be the results of certain computations.
01 PRICE-LIST.
05 LIST-ITEM OCCURS 50 TIMES.
10 PROD-CODE PIC X(5).
10 PROD-PRICE PIC 9(6)V99.
The values are available in a file named PRICE-FILE whose FD entry and record description are shown below.
FD PRICE-FILE.
01 PRICE-REC.
05 ITEM-CODE PIC X(5).
05 ITEM-PRICE PIC 9(6)V99.
The PROCEDURE DIVISION statements to store the values of table from the file may be written as follows:
MOVE 1 TO I.
READ-PARA.
READ PRICE-FILE AT END GO TO END-OF-STORE.
MOVE ITEM-CODE TO PROD-CODE (I).
MOVE ITEM-PRICE TO PROD-PRICE (I).
ADD 1 TO I.
IF I NOT > 50 GO TO READ-PARA.
END-OF-STORE.

The above code stores the values of the table from the first 50 records of PRICE-FILE. In case the file has fewer records, the values are stored for as many table elements as there are records.

MULTI-DIMENSIONAL TABLES

In one-dimensional table, each of its elements in turn is a table of one dimension, it is called a two-dimensional table.
Example
01 ALES-TABLE.
02 BRANCH-FIGURES OCCURS 18 TIMES.
03 MONTHLY-SALES PIC 9(6) OCCURS 12 TIMES
The table is assumed to store monthly sales figures for 12 months for each of the 18 branches of an organization. Note that this is a two dimensional table because each of the 18 BRANCH-FIGURES is itself a table having 12 elements. A reference to an element of a two-dimensional table requires two subscripts. We must specify the branch as well as the month so that the desired element is identified.
Thus MONTHLY-SALES(3,5) means the sales figure for the fifth month of the third branch.

PERFORM with TIMES option
Format is
THRU
PERFORM procedure-name-1 THROUGH procedure-name-2

Identifier
Integer TIMES


The range is repetitively executed for the number of times specified through the identifier or the integer and after that the control goes to the next statement following the PERFORM statement. Thus the statement
PERFORM PROCESS-TO-BE-PERFORMED 5 TIMES.
Means that the section or paragraph indicated by the name PROCESS-TO-BE-PERFORMED will be repetitively executed 5 times.

PERFORM with UNTIL option
The format is

THRU
PERFORM procedure-name-1 THROUGH procedure-name-2

UNTIL condition
The range is executed repetitively until the specified condition becomes true. Consider an example.
MOVE ZERO TO SUM, NUMB.
PERFORM ADD-PARA UNTIL NUMB=50.
ADD-PARA.
ADD 1 TO NUMB , ADD NUMB TO SUM.

PERFORM with VARYING option

The format is
THRU
PERFORM procedure-name-1 THROUGH procedure-name-2

Identifier-1 identifier-2
VARYING Index-name-1 FROM index-name-2
Literal-1
BY identifier-3
Literal-2 UNTIL condition.
This is similar to the UNTIL option in the sense that the specified range is executed repetitively until the condition becomes true. In addition, identifier-1 is set to some initial value and it is incremented each time the range is executed.

Example
MOVE ZERO TO TOTAL.
PERFORM PARA1 VARYING I FROM 1 BY UNTIL I > 20
PERFORM with VARYING-AFTER option
This option has the following format:


THRU
PERFORM procedure-name-1 THROUGH procedure-name-2

Identifier-1 identifier-2
VARYING Index-name-1 FROM index-name-2
Literal-1
BY identifier-3
Literal-2 UNTIL condition-1

Identifier-4 identifier-5
AFTER Index-name-3 FROM index-name-4
Literal-3

BY identifier-6
Literal-4 UNTIL condition-2


Identifier-7 identifier-8
AFTER Index-name-5 FROM index-name-6
Literal-5

BY identifier-9
Literal-6 UNTIL condition-3


This form is used when a nested repetition of the range is required while varying more than one identifier. For example,
PERFORM RANGE-TO-BE-EXECUTED
VARYING I FROM 1 BY 1 UNTIL I>50
AFTER J FROM 1 BY 1 UBTIL J >10.
Here, RANGE-TO-BE-EXECUTED will be performed 500 times- first with I as 1 and varying J from 1 to 10 in step of 1, then I as 2 and again J varying from 1 to 10 and so on. Every time I changes value, J must vary from 1 to 10.


INDEXED TABLES AND INDEXING

An index as data item which is associated with a table or a particular dimension of a table through the use of INDEXED BY phrase of an OCCURS clause. The syntax is:
OCCURS integer TIMES
[INDEXED BY index-name-1 [, index-name-2]……]
Example
01 ENROLL-TABLE.
02 FACULTY OCCURS 3 TIMES INDEXED BY F1.
03 DEPARTMENT OCCURS 6 TIMES INDEXED BY D1.
04 YEAR PIC 9(4) OCCURS 5 TIMES INDEXED BY Y1.

Here F1, D1, Y1 are index names associated with this table. An index is similar to a subscript but the internal value of an index is quite different from that of a subscript. A subscript is any integer data item and its value denotes the position or occurrence number of the element within a table.

SET VERB

The SET verb is used to increase or decrease the value of the indexes. For example,
SET F1 TO 4
Will set the value of the index F1 to 4. There are several forms of the SET verb:
a. To set one particular value to one or more index names we can use the following form
SET index-name-1 [, index-name-2]…..TO identifier-1
Integer-1
Index-data-item
Index-name-3
For example,
SET F1, Y1 TO 3.
Only positive integral values can be set to an index.
b. To move the current value of an index to one or more identifiers, the following form of the SET verb can be used.

SET identifier-2 [, identifier-3] ….. TO index-name-4

If A and B are data names and F1 is an index name, the statement,
SET A, B TO F1.
Indicates that the current value of F1 will be stored in both the data names A and B.

SEARCH VERB

The SEARCH verb is used to locate elements in one-dimensional tables. Format is



SEARCH identifier-1 VARYING identifier-2
Index-name-1

[ ; AT END imperative-statement1]

; WHEN condition-1 imperative-statement-2
NEXT SENTENCE

; WHEN condition-2 imperative-statement-3
NEXT SENTENCE
For example,
Suppose each element of a table consists of three fields, namely, the account number of a person, the name of that person and the amount that he has deposited. We would like to display the name as well as the corresponding account number and amount.
77 NAME PIC X(20).
01 SAVINGS-BANK-ACCOUNT.
02 ACCOUNT-TABLE OCCURS 400 TIMES INDEXED BY A1.
03 ACCOUNT-NUMBER PIC 9(6).
03 NAME-OF-THE-PERSON PIC X(2).
03 AMOUNT PIC 9(6).99.
PROCEDURE DIVISION.
SET A1 TO 1.
SEARCH ACCOUNT-TABLE
AT END DISPLAY “NAME NOT FOUND”
WHEN NAME = NAME-OF-THE-PERSON (A1)
DISPLAY ACCOUNT-NUMBER (A1), NAME AMOUNT (A1).

If the condition is satisfied for some value of the index name A1, the statement DISPLAY ACCOUNT-NUMBER(A1) , NAME, AMOUNT (A1) is executed. AT END part is executed only when the entire table is searched and the condition is not satisfied for any value of A1. The increment of A1 is taken care of by the SEARCH verb.




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: FUNDAMENTALS OF COMPUTER & COBOL(FILE ORGANIZATION):-
Previous Resource: Introduction to computers:-
Return to Discussion Resource Index
Post New Resource
Category: Computer & Technology


Post resources and earn money!
 
Related Resources

Watch TV Channels



Contact Us    Editors    Privacy Policy    Terms Of Use   

SpiderWorks Technologies Pvt Ltd. 2006 - 2007 All Rights Reserved.