COBOL & COBOL II Interview Questions With Answers

Name the divisions in a COBOL program ?.

IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION, PROCEDURE DIVISION.

 

What are the different data types available in COBOL?

Alpha-numeric (X), alphabetic (A) and numeric (9).

 

What does the INITIALIZE verb do?  - GS

Alphabetic, Alphanumeric fields & alphanumeric edited items are set to SPACES. Numeric, Numeric edited items set to ZERO. FILLER , OCCURS DEPENDING ON items left untouched.

 

What is 77 level used for ?

Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor can they be subdivided themselves.

 

What is 88 level used for ?

For condition names.

 

What is level 66 used for ?

For RENAMES clause.

 

What does the IS NUMERIC clause establish ?

IS NUMERIC can be used on alphanumeric items, signed numeric & packed decimal items and unsigned numeric & packed decimal  items. IS NUMERIC returns TRUE if the item only consists of 0-9. However, if the item being tested is a signed  item, then it may contain 0-9,  + and - .

 

How do you define a table/array in COBOL?

ARRAYS.

05  ARRAY1         PIC X(9) OCCURS 10 TIMES.

       05         ARRAY2         PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX.

 

Can the OCCURS clause be at the 01 level?

No.

 

What is the difference between index and subscript? - GS

Subscript refers to the array occurrence while index is the displacement (in no of bytes) from the beginning of the array. An index can only be modified using PERFORM, SEARCH & SET. Need to have index for a table in order to use SEARCH, SEARCH ALL.

 

What is the difference between SEARCH and SEARCH ALL? - GS

SEARCH - is a serial search.

SEARCH ALL - is a binary search & the table must be sorted ( ASCENDING/DESCENDING KEY clause to be used & data loaded in this order) before using SEARCH ALL.

 

What should be the sorting order for SEARCH ALL? - GS

It can be either ASCENDING or DESCENDING.  ASCENDING is default.  If you want the search to be done on an  array sorted in descending order, then while defining the array, you should give DESCENDING KEY clause. (You must load the table in the specified order).

What is binary search?

Search on a sorted array.  Compare the item to be searched with the item at the center.  If it matches, fine else repeat the process with the left half or the right half depending on where the item lies.

 

My program has an array defined to have 10 items.  Due to a bug, I find that even if the program access the 11th item in this array, the program does not abend.  What is wrong with it?

Must use compiler option SSRANGE if you want array bounds checking. Default is NOSSRANGE.

 

How do you sort in a COBOL program?  Give sort file definition, sort statement syntax and meaning. - GS

 Syntax: SORT file-1 ON ASCENDING/DESCENDING KEY key.... USING file-2 GIVING file-3.

 

USING can be substituted by INPUT PROCEDURE IS para-1 THRU para-2

GIVING can be substituted by OUTPUT PROCEDURE IS para-1 THRU para-2.

 

file-1 is the sort (work) file and must be described using SD entry in FILE SECTION.

file-2 is the input file for the SORT and must be described using an FD entry in FILE SECTION and SELECT

clause in FILE CONTROL.

file-3 is the out file from the SORT and must be described using an FD entry in FILE SECTION and SELECT

clause in FILE CONTROL.

file-1, file-2 & file-3 should not be opened explicitly.

 

INPUT PROCEDURE is executed before the sort and records must be RELEASEd to  the sort work file from the input procedure.

OUTPUT PROCEDURE is executed after all records have been sorted. Records from the sort work file must be RETURNed one at a time to the output procedure.

 

How do you define a sort file in JCL that runs the COBOL program?

Use the SORTWK01, SORTWK02,..... dd names in the step. Number of sort datasets depends on the volume of data being sorted, but a minimum of 3 is required.

 

What is the difference between performing a SECTION and a PARAGRAPH? - GS

Performing a SECTION will cause all the paragraphs that are part of the section, to be performed.
Performing a PARAGRAPH will cause only that paragraph to be performed.

 

What is the use of EVALUATE statement? - GS

Evaluate is like a case statement and can be used to replace nested Ifs. The difference between EVALUATE and case is that no 'break' is required for EVALUATE i.e. control comes out of the EVALUATE as soon as one match is made.

 

What are the different forms of EVALUATE statement?

 

EVALUATE                                              EVALUATE SQLCODE ALSO FILE-STATUS

       WHEN A=B AND C=D                                    WHEN 100 ALSO '00'

                    imperative stmt                                                          imperative stmt  

WHEN (D+X)/Y = 4                                                 WHEN -305 ALSO '32'

                       imperative stmt                                                       imperative stmt

WHEN OTHER                                                         WHEN OTHER

            imperative stmt                                                        imperative stmt

END-EVALUATE                                        END-EVALUATE

 

EVALUATE SQLCODE ALSO A=B         EVALUATE SQLCODE ALSO TRUE

WHEN 100 ALSO TRUE                                   WHEN 100 ALSO A=B

                     imperative stmt                                             imperative stmt

WHEN -305 ALSO FALSE                                 WHEN -305 ALSO (A/C=4)

                     imperative stmt                                             imperative stmt

END-EVALUATE                                        END-EVALUATE

 

How do you come out of an EVALUATE statement? - GS

After the execution of one of the when clauses, the control is automatically passed on to the next sentence after the EVALUATE statement.  There is no need of any extra code.

 

In an EVALUATE statement, can I give a complex condition on a when clause?

Yes.

 

What is a scope terminator?  Give examples.

Scope terminator is used to mark the end of a verb e.g. EVALUATE, END-EVALUATE; IF, END-IF.

 

How do you do in-line PERFORM? - GS

PERFORM ... <UNTIL> ...

<sentences>

END-PERFORM

 

When would you use in-line perform?

When the body of the perform will not be used in other paragraphs. If the body of the perform is a generic type of code (used from various other places in the program), it would be better to put the code in a separate Para and use

PERFORM Para name rather than in-line perform.

 

What is the difference between CONTINUE & NEXT SENTENCE ?

They appear to be similar, that is, the control goes to the next sentence in the paragraph. But, Next Sentence would take the control to the sentence after it finds a full stop (.). Check out by writing the following code example, one if sentence followed by 3 display statements (sorry they appear one line here because of formatting restrictions) If 1 > 0

then next sentence end if display 'line 1' display 'line 2'. display 'line 3'. *** Note- there is a dot (.) only at the end of

the last 2 statements, see the effect by replacing Next Sentence with Continue ***     


Comments (6)

kiran
Said this on 10-27-2007 At 02:23 pm
pls explain with more examples
khasimkhan
Said this on 11-24-2007 At 12:43 pm
very good question and easy to identified,,,, helpfull to interview
vikash kumar sharan
Said this on 12-7-2007 At 04:15 pm
good
anand
Said this on 12-16-2007 At 02:39 pm
godbless you. u do continue helping to other by sharing ur knowledge like this.i need more help from you.
vas
Said this on 2-19-2008 At 12:23 pm
very good
Madhav
Said this on 7-19-2010 At 08:06 am

Thanks. it helped me. pls do continue

Post a Comment
* Your Name:
* Your Email:
(not publicly displayed)
Reply Notification:
Approval Notification:
Website:
* Security Image:
Security Image Generate new
Copy the numbers and letters from the security image:
* Message:

Email to Friend

Fill in the form below to send this article to a friend:

Email to Friend
* Your Name:
* Your Email:
* Friend's Name:
* Friend's Email:
* Security Image:
Security Image Generate new
Copy the numbers and letters from the security image
* Message: