Are you a candidate? Complete list of COBOL interview questions 👇
- What will happen if you code GO BACK instead of STOP RUN in a stand alone COBOL program?
- What is the IS NUMERIC clause?
- What is the difference between Call and a Link?
- What are literals?
- Can you call an OS VS COBOL pgm from a VS COBOL II pgm?
- How can arrays be defined in COBOL?
- Explain the terms Static Linking and Dynamic Linking.
- What do you do to resolve SOC-7 error?
- What Is An In Line Perform? When Would You Use It?
- What is the difference between Global and External Variables?
- What is the Purpose of Pointer in the string?
- What is the function of REPLACING in a COPY statement?
- What is the use of the IS NUMERIC clause?
- What Is The Difference Between Pic 9.99 And 9v99?
- How can you differentiate between a binary search and a sequential search?
- What Is The Difference Between Index And Subscript?
- Explain the function of EVALUATE statement in COBOL.
- What Is Redefines Clause?
- What do you understand by index and subscript?
- What Divisions, Sections And Paragraphs Are Mandatory For A Cobol Program?
- How Is Sign Stored In A Comp-3 Field?
- Why does the file always need to be opened in I-O mode for REWRITE purposes?
- A table has two indexes defined. Which one will be used by the SEARCH?
- How can you tell if a module is being called Dynamically or Statically?
- What are some characteristics of COBOL as means of business language?
- What are the data types that COBOL supports?
- Our program has an array defined to have 10 items. Due to a bug, We find that even if the program access the 11th item in this array, the program does not abend. What is wrong?
- What do you understand by PSB and ACB?
- Explain the difference between Subscript and Index.
- Which type of error is trapped by ON SIZE ERROR option?
- Can you REWRITE a record in an ESDS file? Can you DELETE a record from it?
- What are divisions in a COBOL program?
- What are the different rules of SORT operation?
- What is the difference between SSRANGE and NOSSRANGE?
- What is the difference between Perform With Test After and Perform With Test Before?
- What do you understand by passing by reference and passing by content?
- What is the difference between CONTINUE & NEXT SENTENCE?
- When Would You Use In-line Perform?
- What Is File Status 39?
- What do you do to resolve SOC-7 error?
- What are Advantages Of Redefines Clause?
- In An Evalute Statement Is The Order Of The When Clauses Significant?
- Which mode is used to operate the sequential file?
- Where can we specify OCCURS clause?
- Explain what you understand by passing BY VALUE.
- What is the difference between NEXT SENTENCE & CONTINUE?
- What Is The Importance Of Global Clause According To New Standards Of Cobol?
- What is the point of the REPLACING option of a copy statement?
- What should be the sorting order for SEARCH ALL?
- What are the guidelines to write a structured COBOL program?
- If You Were Passing A Table Via Linkage, Which Is Preferable - A Subscript Or An Index?
- What is the role of ACCEPT?
- What are the differences between Structured COBOL Programming and Object-Oriented COBOL programming?
- What are the modes of File opening in COBOL?
- Explain an in-line PERFORM?
- When is a scope terminator mandatory?
- What is length in COBOL?
- In The Jcl, How Do You Define The Files Referred To In A Subroutine?
- How to remove the spaces at the end of each record in the output file of variable length, via COBOL program?
A Stop run ends the unit of work and returns control to the operating system whereas GOBACK returns control to calling program. So if we code GO BACK instead of Stop Run, it will go in infinite loop.
The IS NUMERIC clause is used to check if an item is numeric or not. The value returned will be TRUE if the item that is checked for contains only numbers whether positive or negative.
A call is an actual COBOL command, which initiates an external program and returns. While Link is the same as Call but the only difference is that it does not belong to a COBOL verb.
A literal is a data item which consists value by itself. It cannot be referred by a name. They are constant data items. There are two types of literals:
- String / Alphanumeric Literals
- Numeric Literals
In non-CICS environment, it is possible. In CICS, this is not possible.
Arrays can be defined as:
- 05 Array2 PIC X(9) which occurs 20 times
- 05 Array 1 PIC X(9) which occurs 10 times
In Static linking, the subroutine links into the calling program whereas in Dynamic linking, the key program and subroutine will remain as separate modules. Static linking and Dynamic linking can be attained by link edit options- DYNAM or NODYNAM.
- Offending data need to be corrected
- The main cause for SOC-7 error is un-initialized numeric item. Focus on examining on this.
- Lot of installations provide a dump for run time abends, and these abends provide the offset which is returned by the last instruction where the abend occurred.
- Focus on examining the compilation output XREF listing to find the verb and the line number within the source code at this offset.
- Later investigate the source code for finding the bug
- Define certain datasets(SYSABOUT etc) in JCL, for capturing runtime dumps
- At times few installations might have batch program debugging tool. Utilize them to resolve the issue.
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.
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.
The Purpose of Pointer is to specify the leftmost position within receiving field where the first transferred character will be stored.
REPLACING allows for the same copy to be repeated more than once in the same code just by replacing the value.
IS NUMERIC is used on alphanumeric items, signed numeric & packed decimal items. It is also used for unsigned numeric & packed decimal items. IS NUMERIC returns TRUE if the item only comprises of 0-9. However, if the item being tested is a signed item, then it may contain 0-9, + and -.
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.
In the case of a binary search, the table element key values will be in ascending or descending order. The table is ‘halved’ to search for equal to, greater than or less than conditions until the element is found.
In case of a sequential search, the table is searched from top to bottom. For this, the elements do not have to be in a specific sequence.
The binary search is much faster for more tables, while sequential Search works very well with lesser tables. SEARCH ALL is used for binary search, while SEARCH is used for sequential search.
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.
EVALUATE statement does the same job of a CASE statement or a nested-IF statement. The main difference between EVALUATE and nested-IF is that “break” is not needed for the former and the control leaves the EVALUATE statement once a match is found.
Redefines clause is used to allow the same storage allocation to be referenced by different data names.
Subscript means the array occurrence, while the index is the displacement (in bytes) from the start of the array. An index can only be modified using PERFORM, SEARCH & SET.
Programmers need to have an index for a table in order to use SEARCH, SEARCH ALL.
IDENTIFICATION DIVISION and PROGRAM-ID paragraph are mandatory for a compilation error free COBOL program.
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.
Even before the REWRITE is performed, the record must be opened and read from the file. For the same purpose, the file must be opened in I-O mode for REWRITE functionality.
The index named first can be used by search.
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.
COBOL is a dominant programing language that has aided business users for a few decades. Following are the features of COBOL as a means of business language:
- It can be compiled, executed and brought together on various machines.
- It can handle large volumes of data and it is a business-oriented application.
- It offers several debugging and testing tools for business users as it has several versions that make it easy to debug.
- It is a structured language.
COBOL supports 3 different data types- Alphanumeric (X), Alphabetic(A) and Numeric(9).
Must use compiler option SSRANGE if you want array bounds checking. Default is NOSSRANGE.
- PSB stands for Program specification block.
- This block is used to define how any program is to access an IMS DB. The PSB comprises of the PCB (Program Communication Block).
- Each PSB must contain at least one PCB. These contain information such as which segment in DB can be accessed, what the program can do and how the DB can be accessed.
- ASB stands for Access control blocks.
- Basically they are a block of memory with information stored in them. These are generated by IMS.
- They serve the purpose of being an expansion of the information contained in the PSB
s. By doing so they speed up the access to the applicable DSDs. IMS builds the ACB with the ACBGEN utility by merginf info from PSB and the DBD.
- They can be built either dynamically or can be prebuilt.
Subscript refers to the occurrence in an array whereas Index refers to the number of bytes or displacement from the beginning of the array.
An Index can be modified only with PERFORM, SEARCH and SET commands.
The index is needed to perform SEARCH or SEARCH ALL in a Table.
ON SIZE ERROR option is raised when there is:
- Division by 0
- Zero raised to a negative number
- A negative number raised to a fractional power
- Fixed point overflow
- Zero raised to zero power
Can rewrite(record length must be same), but not delete.
There are around four divisions in a COBOL program. These are known as identification, environment, data and procedure. The identification is the most important division as it identifies the program. The environment division is divided into two sections, configuration and input-output. It defines the environment of the written program. The data division is used to identify data items, allocate memories, and define names within the program. It has a file, working storage and linkage section. The procedure division supports the logic behind the program. It must have at least one statement for using variables defined by the user.
SORT can be performed when
- Input and Output files must remain closed
- Working file must have a select clause
- Input and Output files have FD entries
- Work file should have short description in File Section
Both SSRANGE and NOSSRANGE are options for a compiler to find the out-of-range subscript. NOSSRANGE is the default option wherein there will not be any run-time error if the index or subscript went out of a range.
If TEST BEFORE is specified, the condition is tested at the beginning of each repeated execution of the specified PERFORM range. If TEST AFTER is specified, the condition is tested at the end of each repeated execution of the PERFORM range. The range is executed at least once in TEST AFTER.
Passing by reference:
- When between programs data is shared or passed the subprogram always refers and processes the data items within the calling programs storage.
- It does not work on the copy of the data. Whenever a call by reference identifier is used the caller and the called share the same memory.
Passing by content:
- In this case the calling program only passes the contents of the identifier or the literal.
- When this is used the called program is unable to change the value of the identifier or the literal in the program being called. Further it cannot change the value even if it has modified the variable through which it received its literal.
CONTINUE is like a null statement (do nothing) , while NEXT SENTENCE transfers control to the next sentence (!!) (A sentence is terminated by a period)
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.
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.
Basically you need to correct 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 installation might have batch program debugging tools. Use them.
- You can REDEFINE a Variable from one PICTURE class to another PICTURE class by using the same memory location.
- By REDEFINES we can INITIALISE the variable in WORKING-STORAGE Section itself.
- We can REDEFINE a Single Variable into so many sub variables. (This facility is very useful in solving Y2000 Problem.)
Yes. Evaluation of the WHEN clauses proceeds from top to bottom and their sequence can determine results.
An O-I mode (Output/Input mode) is used for starting and initiation of processing files. Processing of files is determined by successful execution of an OPEN statement.
In array declaration, we can specify occurs clause on Elementary item as well as on Group item also.
It means that the program/method passes the value of the identifier or literal. It does not imply a reference to the sending data item. The program/method called has the capability to change the parameter in the called/invoked program/method. But there is no effect on the argument value in the calling program as the subprogram/method has access to a temporary copy of the sent data item. The parameters used should always be of a particular defined data type in case the data is to be passed somewhere else. This is different as compared to BY CONTENT as it does not passes only the contents of the identifier.
NEXT SENTENCE is used for transferring control to the next sentence. CONTINUE acts like a null statement, and it continues execution.
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.
REPLACING allows for the same copy to be used more than once in the same code by changing the replace value.
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).
There is a format that has to be taken care of while writing a structured COBOL program. One has to work within these guidelines to make a structured COBOL-
- In order to construct a case, one has to use EQUIVALENT statements every time.
- Scope terminators are used for nesting.
- IN-LINE PERFORM statements are used for writing ‘do’ constructions. Also, use Tests before and Test after in performing statements while writing do-while statements.
It is not possible to pass an index via linkage. The index is not part of the calling programs working storage.
The ACCEPT verb is a basic statement used in COBOL for retrieving data like time, date and day from the user or program. In the educational data, ACCEPT verb and DISPLAY are used to receive information for a student record.
Structured programming can be defined as a logical way of programming. In this, the functionalities are divided into modules and help the programmer to write the code logically.
Object-Oriented COBOL is a natural way of programming. In this, programmers identify the objects and then write functions and procedures around that object.
The modes of opening a file in COBOL are OUTPUT, INPUT, I/O and EXTEND.
What is the extreme size of a mimetic field that can be defined in COBOL?
The maximum size of a numeric field that can be defined in COBOL is PIC 9(18).
Through an IN-LINE PERFORM statement, the routine is being performed to be nested within the perform statement instead of being a separate paragraph.
While the PERFORM and END-PERFORM statements are used to block the COBOL statements between them, in line PERFORM work as long as there are no internal GO TOs, not even to an exit.
Scope terminators are mandatory in COBOL in in-line PERFORMS and EVALUATE statements. For ease of reading, it is suggested coding practice to always make scope terminators explicit.
Length is like a particular record to have the extent of a group or a simple item.
Supply the DD cards just as you would for files referred to in the main program.
Spaces at the end of the record are called trailing spaces. There are no functions to trim the trailing space. It can be done by altering the RECORD-LENGTH.
The following is the accomplish this task:
- Assuming that a variable length file has maximum record length as 4000.
- Move the original record length value to RECORD-LENGTH. This process enables the trimming off the entire record that is beyond the length.
- In case the data is populated only up to 3000 bytes. Then move 3000 to RECORD-LENGTH.
- By implementing the above process, the record would trim off the trailing 1000 bytes.