## COBOL Interview Questions & Answers

• Question 1. Name The Divisions In A Cobol Program?

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

• Question 2. What Are The Different Data Types Available In Cobol?

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

• VSAM Interview Questions

• Question 3. What Does The Initialize Verb Do?

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

• Question 4. What Is 77 Level Used For ?

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

• VSAM Tutorial

• Question 5. What Is 88 Level Used For ?

For condition names.

• IBM – VSAM Interview Questions

• Question 6. What Is Level 66 Used For ?

For RENAMES clause.

• Question 7. What Does The Is Numeric Clause Establish ?

IS NUMERIC can be used on alphanumeric items, signed numeric & packed decimal items and usigned 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 – .

• IBM-CICS Tutorial IBM-CICS Interview Questions

• Question 8. How Do You Define A Table/array In Cobol?

01 ARRAYS.
05 ARRAY1 PIC X(9) OCCURS 10 TIMES.
05 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX.

• Question 9. Can The Occurs Clause Be At The 01 Level?

No.

• JCL Interview Questions

• Question 10. What Is The Difference Between Index And Subscript?

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.

• IBM DB2 Tutorial

• Question 11. What Is The Difference Between Search And Search All?

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.

• IBM DB2 Interview Questions

• Question 12. What Should Be The Sorting Order For Search All?

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).

• VSAM Interview Questions

• Question 13. 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.

• IBM-JCL Tutorial

• Question 14. 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.

• Question 15. 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.

• IBM-JCL Interview Questions

• Question 16. What Is The Difference Between Performing A Section And A Paragraph?

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.

• DB2 Using SQL Tutorial

• Question 17. What Is The Use Of Evaluate Statement?

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.

• DB2 Using SQL Interview Questions

• Question 18. 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.

• IBM – VSAM Interview Questions

• Question 19. How Do You Come Out Of An Evaluate Statement?

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.

• IBM Mainframe Tutorial

• Question 20. In An Evaluate Statement, Can I Give A Complex Condition On A When Clause?

Yes.

• IBM-JCL&VSAM Interview Questions

• Question 21. 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.

• Question 22. How Do You Do In-line Perform?

PERFORM … …
END PERFORM.

• IMS/DB Tutorial

• Question 23. 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 paraname rather than in-line perform.

• IBM Mainframe Interview Questions

• Question 24. What Is The Difference Between Continue & Next Sentence ?

CONTINUE is like a null statement (do nothing) , while NEXT SENTENCE transfers control to the next sentence (!!) (A sentence is terminated by a period).

• IBM-CICS Interview Questions

• Question 25. What Does Exit Do ?

Does nothing ! If used, must be the only sentence within a paragraph.

• Question 26. Can I Redefine An X(100) Field With A Field Of X(200)?

Yes. Redefines just causes both fields to start at the same location. For example:
01 WS-TOP PIC X(1)
01 WS-TOP-RED REDEFINES WS-TOP PIC X(2).
If you MOVE ’12’ to WS-TOP-RED,
DISPLAY WS-TOP will show 1 while
DISPLAY WS-TOP-RED will show 12.

• COBOL, CICS, JCL, VSAM, DB2 Interview Questions

• Question 27. Can I Redefine An X(200) Field With A Field Of X(100) ?

Yes.

• JCL Interview Questions

• Question 28. What Do You Do To Resolve Soc-7 Error?

Basically you need to correcting the offending data.

Many times the reason for SOC7 is an un-initialized numeric item. Examine that possibility first.

Many installations provide you a dump for run time abends ( it can be generated also by calling some subroutines or OS services thru assembly language). These dumps provide the offset of the last instruction at which the abend occurred. Examine the compilation output XREF listing to get the verb and the line number of the source code at this offset. Then you can look at the source code to find the bug. To get capture the runtime dumps, you will have to define some datasets (SYSABOUT etc ) in the JCL.

If none of these are helpful, use judgement and DISPLAY to localize the source of error.

Some installtion might have batch program debugging tools. Use them.

• Question 29. How Is Sign Stored In Packed Decimal Fields And Zoned Decimal Fields?

Packed Decimal fields: Sign is stored as a hex value in the last nibble (4 bits ) of the storage.

Zoned Decimal fields: As a default, sign is over punched with the numeric value stored in the last bite.

• DB2 SQL Programming Interview Questions

• Question 30. How Is Sign Stored In A Comp-3 Field?

It is stored in the last nibble. For example if your number is +100, it stores hex 0C in the last byte, hex 1C if your number is 101, hex 2C if your number is 102, hex 1D if the number is -101, hex 2D if the number is -102 etc…

• Question 31. How Is Sign Stored In A Comp Field ?

In the most significant bit. Bit is on if -ve, off if +ve.

• Question 32. What Is The Difference Between Comp & Comp-3 ?

COMP is a binary storage format while COMP-3 is packed decimal format.

• IMS/DB Interview Questions

• Question 33. What Is Comp-1? Comp-2?

COMP-1 – Single precision floating point. Uses 4 bytes.
COMP-2 – Double precision floating point. Uses 8 bytes.

• IBM DB2 Interview Questions

• Question 34. How Do You Define A Variable Of Comp-1? Comp-2?

No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.

• Question 35. How Many Bytes Does A S9(7) Comp-3 Field Occupy ?

Will take 4 bytes. Sign is stored as hex value in the last nibble.
General formula is INT((n/2) + 1)), where n=7 in this example.

• Question 36. How Many Bytes Does A S9(7) Sign Trailing Separate Field Occupy ?

Will occupy 8 bytes (one extra byte for sign).

• IBM-JCL Interview Questions

• Question 37. How Many Bytes Will A S9(8) Comp Field Occupy ?

4 bytes.

• Question 38. What Is The Maximum Value That Can Be Stored In S9(8) Comp?

99999999.

• Question 39. What Is Comp Sync?

Causes the item to be aligned on natural boundaries. Can be SYNCHRONIZED LEFT or RIGHT.

For binary data items, the address resolution is faster if they are located at word boundaries in the memory. For example, on main frame the memory word size is 4 bytes. This means that each word will start from an address divisible by 4. If my first variable is x(3) and next one is s9(4) comp, then if you do not specify the SYNC clause, S9(4) COMP will start from byte 3 ( assuming that it starts from 0 ). If you specify SYNC, then the binary data item will start from address 4. You might see some wastage of memory, but the access to this computational field is faster.

• Question 40. What Is The Maximum Size Of A 01 Level Item In Cobol I? In Cobol Ii?

In COBOL II: 16777215.

• DB2 Using SQL Interview Questions

• Question 41. What Are Different File Open Modes Available In Cobol?

Open for INPUT, OUTPUT, I-O, EXTEND.

• Question 42. What Is The Mode In Which You Will Open A File For Writing?

OUTPUT, EXTEND.

• IBM-JCL&VSAM Interview Questions

• Question 43. In The Jcl, How Do You Define The Files Referred To In A Subroutine ?

Supply the DD cards just as you would for files referred to in the main program.

• Question 44. Can You Rewrite A Record In An Esds File? Can You Delete A Record From It?

Can rewrite(record length must be same), but not delete.

• Question 45. What Is File Status 92?

Logic error. e.g., a file is opened for input and an attempt is made to write to it.

• Question 46. What Is File Status 39 ?

Mismatch in LRECL or BLOCKSIZE or RECFM between your COBOL pgm & the JCL (or the dataset label). You will get file status 39 on an OPEN.

• Question 47. What Is Static,dynamic Linking ?

In static linking, the called subroutine is link-edited into the calling program , while in dynamic linking, the subroutine & the main program will exist as separate load modules. You choose static/dynamic linking by choosing either the DYNAM or NODYNAM link edit option. (Even if you choose NODYNAM, a CALL identifier (as opposed to a CALL literal), will translate to a DYNAMIC call).

A statically called subroutine will not be in its initial state the next time it is called unless you explicitly use INITIAL or you do a CANCEL. A dynamically called routine will always be in its initial state.

• Question 48. What Compiler Option Would You Use For Dynamic Linking?

DYNAM.

• Question 49. What Is Ssrange, Nossrange ?

These are compiler options w.r.t subscript out of range checking. NOSSRANGE is the default and if chosen, no run time error will be flagged if your index or subscript goes out of the permissible range.

• Question 50. How Do You Set A Return Code To The Jcl From A Cobol Program?

Move a value to RETURN-CODE register. RETURN-CODE should not be declared in your program.

• Question 51. What Are The Steps You Go Through While Creating A Cobol Program Executable?

DB2 precompiler (if embedded sql used), CICS translator (if CICS pgm), Cobol compiler, Link editor.
If DB2 program, create plan by binding the DBRMs.

• Question 52. How Many Sections Are There In Data Division?

SIX SECTIONS

1. FILE SECTION
2. WORKING-STORAGE SECTION
3. LOCAL-STORAGE SECTION
4. SCREEN SECTION
5. REPORT SECTION

• Question 53. What Is Redefines Clause?

Redefines clause is used to allow the same storage allocation to be referenced by different data names.

• Question 54. What Is The Different Between Index And Subscript?

Subscript refers to the array of occurrence, where as Index represents an occurrence of a table element. An index can only modified using perform, search & set. Need to have an index for a table in order to use SEARCH and SEARCH All.

• Question 55. What Is The Difference Between Structured Cobol Programming And Object Alternatively Oriented Cobol Programming?

Structured programming is a Logical way of programming, you divide the functionalities into modules and code logically. OOP is a Natural way of programming; you identify the objects first, and then write functions, procedures around the objects. Sorry, this may not be an adequate answer, but they are two different programming paradigms, which is difficult to put in a sentence or two.

• Question 56. What Divisions, Sections And Paragraphs Are Mandatory For A Cobol Program?

IDENTIFICATION DIVISION and PROGRAM-ID paragraph are mandatory for a compilation error free COBOL program.

• Question 57. What Is The Difference Between External And Global Variables?

Global variables are accessible only to the batch program whereas external variables can be referenced from any batch program residing in the same system library.

• Question 58. What Is Difference Between Cobol And Vs Cobol Ii?

In using COBOL on PC we have only flat files and the programs can access only limited storage, whereas in VS COBOL II on M/F the programs can access up to 16MB or 2GB depending on the addressing and can use VSAM files to make I/O operations faster.

• Question 59. Difference Between Next And Continue Clause?

The difference between the next and continue verb is that in the continue verb it is used for a situation where there in no EOF condition that is the records are to be accessed again and again in an file, whereas in the next verb the indexed file is accessed sequentially, read next record command is used.

• Question 60. What Is The Importance Of Global Clause According To New Standards Of Cobol?

When any data name, file-name, Record-name, condition name or Index defined in an Including Program can be referenced by a directly or indirectly in an included program, Provided the said name has been declared to be a global name by GLOBAL Format of Global Clause is01 data-1 pic 9(5) IS GLOBAL.

• Question 61. What Is The Purpose Of Pointer Phrase In String Command?

The Purpose of POINTER phrase is to specify the leftmost position within receiving field where the first transferred character will be stored.

• Question 62. What Is The Linkage Section Used For?

The linkage section is used to pass data from one program to another program or to pass data from a PROC to a program.

• Question 63. Describe The Difference Between Subscripting And Indexing?

Indexing uses binary displacement. Subscripts use the value of the occurrence.

• Question 64. Differentiate Cobol And Cobol-ii. (most Of Our Programs Are Written In Cobolii, So, It Is Good To Know, How, This Is Different From Cobol)?

The following features are available with VS COBOL II: 1. MVS/XA and MVS/ESA support. The compiler and the object programs it produces can be run in either 24- or 31-bit addressing mode. 2. VM/XA and VM/ESA support the compiler and the object programs it produces can be run in either 24- or 31-bit addressing mode. 3. VSE/ESA supports the compiler and the object programs it produces can be run under VSE/ESA.

• Question 65. Why Do We Code S9 (4) Comp. Inspite Of Knowing Comp-3 Will Occupy Less Space ?

Here s9(4)comp is small integer ,so two words equal to 1 byte so totally it will occupy 2 bytes(4 words).here in s9(4) comp-3 as one word is equal to 1/2 byte.4 words equal to 2 bytes and sign will occupy 1/2 byte so totally it will occupy 3 bytes.

• Question 66. What Do You Feel Makes A Good Program?

A program that follows a top down approach. It is also one that other programmers or users can follow logically and is easy to read and understand.

• Question 67. Give Some Advantages Of Redefines Clause?

1. You can REDEFINE a Variable from one PICTURE class to another PICTURE class by using the same memory location.
2. By REDEFINES we can INITIALISE the variable in WORKING-STORAGE Section itself.
3. We can REDEFINE a Single Variable into so many sub variables. (This facility is very useful in solving Y2000 Problem.)

• Question 68. How To Execute A Set Of Jcl Statements From A Cobol Program?

Using EXEC CICS SPOOL WRITE (var-name) END-EXEC command. Var-name is a COBOL host structure containing JCL statements.

• Question 69. How Do You Submit Jcl Via A Cobol Program?

Use a file //dd1 DD sysout=(*, intrdr)write your JCL to this file. Pl some on try this out.

• Question 70. What Care Has To Be Taken To Force Program To Execute Above 16 Meg Line?

Make sure that link option is AMODE=31 and RMODE=ANY. Compile option should never have SIZE (MAX). BUFSIZE can be 2K, efficient enough.

• Question 71. What Is The Difference Between Search And Search All? What Is More Efficient?

SEARCH is a sequential search from the beginning of the table. SEARCH ALL is a binary search, continually dividing the table in two halves until a match is found. SEARCH ALL is more efficient for tables larger than 70 items.

• Question 72. What Is Pic 9v99 Indicates?

PICTURE 9v99 is a three position Numeric field with an implied or assumed decimal point after the first position; the v means an implied decimal point.

• Question 73. What Is The Difference Between Pic 9.99 And 9v99?

PIC 9.99 is a FOUR-POSITION field that actually contains a decimal point where as PIC 9v99 is THREE- POSITION numeric field with implied or assumed decimal position.

• Question 74. What Is The Difference Between A Dynamic And Static Call In Cobol?

To correct an earlier answer: All called modules cannot run standalone if they require program variables passed to them via the LINKAGE section. Dynamically called modules are those that are not bound with the calling program at link edit time (IEWL for IBM) and so are loaded from the program library (joblib or steplib) associated with the job. For DYNAMIC calling of a module the DYNAM compiler option must be chosen, else the linkage editor will not generate an executable as it will expect u address resolution of all called modules. A Statically called module is one that is bound with the calling module at link edit, and therefore becomes part of the executable load module.

• Question 75. How Can I Tell If A Module Is Being Called Dynamically Or Statically?

The ONLY way is to look at the output of the linkage editor (IEWL) or the load module itself. If the module is being called DYNAMICALLY then it will not exist in the main module, if it is being called STATICALLY then it will be seen in the load module. Calling a working storage variable, containing a program name, does not make a DYNAMIC call. This type of calling is known as IMPLICITE calling as the name of the module is implied by the contents of the working storage variable. Calling a program name literal.

• Question 76. What Is The Point Of The Replacing Option Of A Copy Statement?

REPLACING allows for the same copy to be used more than once in the same code by changing the replace value.

• Question 77. What Is Length In Cobol Ii?

LENGTH acts like a special register to tell the length of a group or elementary item.

• Question 78. What Is Set To True All About, Anyway?

In COBOL II the 88 levels can be set rather than moving their associated values to the related data item. (Web note: This change is not one of COBOL IIs better specifications.)

• Question 79. What Is The Default Value(s) For An Initialize And What Keyword Allows For An Override Of The Default?

INITIALIZE moves spaces to alphabetic fields and zeros to alphanumeric fields. The REPLACING option can be used to override these defaults.

• Question 80. In An Evalute Statement Is The Order Of The When Clauses Significant?

Absolutely. Evaluation of the WHEN clauses proceeds from top to bottom and their sequence can determine results.

• Question 81. In A Cobol Ii Perform Statement, When Is The Conditional Tested, Before Or After The Perform Execution?

In COBOL II the optional clause WITH TEST BEFORE or WITH TEST AFTER can be added to all perform statements. By default the test is performed before the perform.

• Question 82. When Is A Scope Terminator Mandatory?

Scope terminators are mandatory for in-line PERFORMS and EVALUATE statements. For readability, it is recommended coding practice to always make scope terminators explicit.

• Question 83. Explain The Difference Between An Internal And An External Sort, The Pros And Cons, Internal Sort Syntax Etc?

An external sort is not COBOL; it is performed through JCL and PGM=SORT. It is understandable without any code reference. An internal sort can use two different syntaxs: 1.) USING, GIVING sorts are comparable to external sorts with no extra file processing; 2) INPUT PROCEDURE, OUTPUT PROCEDURE sorts allow for data manipulation before and/or after the sort.

• Question 84. If You Were Passing A Table Via Linkage, Which Is Preferable – A Subscript Or An Index?

Wake up – you haven’t been paying attention! It is not possible to pass an index via linkage. The index is not part of the calling programs working storage. Those of us, who’ve made this mistake, appreciate the lesson more than others.

• Question 85. What Is The Difference Between A Subscript And An Index In A Table Definition?

A subscript is a working storage data definition item, typically a PIC (999) where a value must be moved to the subscript and then incremented or decrements by ADD TO and SUBTRACT FROM statements. An index is a register item that exists outside the programs working storage. You SET an index to a value and SET it UP BY value and DOWN BY value.

• Question 86. What Is The Linkage Section?

The linkage section is part of a called program that links or maps to data items in the calling program are working storage. It is the part of the called program where these share items are defined.

• Question 87. Explain Call By Context By Comparing It To Other Calls?

The parameters passed in a call by context are protect
ed from modification by the called program. In a normal call they are able to be modified.

• Question 88. What Was Removed From Cobol In The Cobol Ii Implementation?

Partial list: REMARKS, NOMINAL KEY, PAGE-COUNTER, CURRENT-DAY, TIME-OF-DAY, STATE, FLOW, COUNT, EXAMINE, EXHIBIT, READY TRACE and RESET TRACE.

• Question 89. What Is The Difference Between Next Sentence And Continue?

NEXT SENTENCE gives control to the verb following the next period. CONTINUE gives control to the next verb after the explicit scope terminator. (This is not one of COBOL IIs finer implementations). It is safest to use CONTINUE rather than NEXT SENTENCE in COBOL II.

• Question 90. What Is An In Line Perform? When Would You Use It? Anything Else You Wish To Say About It?

The PERFORM and END-PERFORM statements bracket all COBOL II statements between them. The COBOL equivalent is to PERFORM or PERFORM THRU a paragraph. In line PERFORMs work as long as there are no internal GO TOs, not even to an exit. The in line PERFORM for readability should not exceed a page length – often it will reference other PERFORM paragraphs.

• Question 91. What Is An Explicit Scope Terminator?

A scope terminator brackets its preceding verb, e.g. IF… END-IF, so that all statements between the verb and its scope terminator are grouped together. Other common COBOL II verbs are READ, PERFORM, and EVALUATE, SEARCH and STRING.

• Question 92. What Are The Differences Between Cobol And Cobol Ii?

There are at least five differences: COBOL II supports structured programming by using in line Performs and explicit scope terminators, It introduces new features (EVALUATE, SET. TO TRUE, CALL. BY CONTEXT, etc) It permits programs to be loaded and addressed above the 16-megabyte line It does not support many old features (READY TRACE, REPORT-WRITER, ISAM, Etc.), and It offers enhanced CICS support.

• Question 93. How Many Bytes Do A S9 (7) Comp-3 Field Occupy?

It will take 4 bytes to occupy. Sign is stored as hex value in the last nibble. General formula is INT((n/2) + 1)), where n=7 in this example.

• Question 94. How Is Sign Stored In A Comp Field?

It is stored in the most significant bit. Bit is ON if -ve, OFF if +ve.

• Question 95. What Is The Difference Between Comp And Comp-3?