Below, frequently asked Top COBOL Interview Questions and Answers for freshers and experienced.
What do you know about COBOL?
COBOL, which stands for Common Business Oriented Language, is one of the oldest high-level programming languages still in use today. It was designed specifically for business, finance, and administrative systems in large organizations. COBOL is known for its readability, English-like syntax, and ability to handle massive amounts of data processing. It is widely used in industries where legacy systems and mainframe computers are prevalent, such as banking, insurance, and government sectors. COBOL programs are used to develop application software that handles complex business operations and transactions.
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 name entry
What is 66 level used for?
For Renames clause items
What is PIC 9.99?
PIC 9.99 is a four-position field that actually contains a decimal point
What is the maximum value that can be stored in S9(8) COMP?
The maximum value is 99999999.
What are the different data types in COBOL?
In COBOL, there are five main data types:
- Alphanumeric (X): This data type is used to represent alphanumeric characters, including letters, numbers, and special characters. It is declared using the “PIC X” clause.
- Alphabetic (A): This data type is specifically used to represent alphabetic characters. It is declared using the “PIC A” clause.
- Numeric (9): The numeric data type is used to represent numeric values, such as integers or decimal numbers. It is declared using the “PIC 9” clause.
- Sign (S): The sign data type is used to represent signed numeric values. It allows both positive and negative numbers. It is declared using the “PIC S9” clause.
- Assumed decimal point (P/V): This data type is used to represent numeric values with an assumed decimal point. The position of the decimal point is determined by the program logic. It is declared using the “PIC 9V9” or “PIC 9P9” clause.
What is the difference between a subscript and an index in programming?
In programming, a subscript and an index are terms used to access elements within an array or a collection. While they are often used interchangeably, there is a slight difference in their meaning and usage.
A subscript refers to the position or occurrence of an element within an array. It is typically an integer value that represents the relative position of the element in the array. Subscripts are commonly used in languages like FORTRAN and BASIC.
What is the difference between a static call and a dynamic call in programming?
In programming, a static call and a dynamic call are two different ways of invoking or executing a subroutine or a program. Here’s the difference between them:
Static Call: A static call refers to a call to a subroutine or program where the called program is a stand-alone executable program. It is typically a separate module or program unit that can be compiled and linked independently. During the compilation and linking process, the calling program is statically linked with the called program. The address or entry point of the called program is known at compile time, and the call is resolved and validated during the compilation process. Static calls are commonly used when the called program remains constant throughout the execution.
Dynamic Call: A dynamic call refers to a call to a subroutine or program where the called program is not an executable program by itself. Instead, it is a program that can be dynamically loaded and executed at runtime. The address or entry point of the called program is determined during runtime, based on the conditions or parameters specified by the calling program. Dynamic calls provide flexibility in program execution as the called program can be determined and changed dynamically based on the program’s logic or user input.
What is the difference between the CONTINUE statement and the NEXT SENTENCE statement in programming?
In programming languages like COBOL, the CONTINUE statement and the NEXT SENTENCE statement serve different purposes and have distinct effects on the program flow.
CONTINUE Statement: The CONTINUE statement is a placeholder or null statement that has no effect on program execution. It is used when a statement is required syntactically but no specific action needs to be performed at that point in the program. The CONTINUE statement is typically used for readability or as a placeholder to be replaced with actual code in the future. It allows the program to continue execution without performing any specific operation.
NEXT SENTENCE Statement: The NEXT SENTENCE statement is used to transfer control to the next executable statement following the current statement. It is often used within the conditional statements (IF, EVALUATE) to skip the remaining part of the current sentence and proceed to the next one. The NEXT SENTENCE statement effectively skips over the subsequent statements within the current sentence and continues program execution from the next executable statement.
What is the difference between structured COBOL programming and object-oriented COBOL programming?
Structured COBOL programming and object-oriented COBOL programming are two different paradigms used in COBOL programming. Here’s the difference between them:
Structured COBOL Programming: Structured programming is a logical approach to programming where the code is organized into modular and manageable units called modules or procedures. It emphasizes the use of structured control flow constructs such as sequence, selection (IF-THEN-ELSE), and iteration (PERFORM, DO) to improve program clarity, maintainability, and reusability. In structured COBOL programming, the focus is on breaking down the program into smaller, self-contained modules that perform specific tasks.
Object-Oriented COBOL Programming: Object-oriented COBOL programming is a natural extension of structured programming that introduces the concept of objects and classes. It allows the programmer to define objects, which encapsulate data and the procedures or methods that operate on that data. Object-oriented COBOL programming emphasizes the concepts of inheritance, polymorphism, and encapsulation. It enables the creation of reusable and extensible code by modeling real-world entities as objects and leveraging the interactions between them.
What is the purpose of the LOCAL-STORAGE section in COBOL?
The LOCAL-STORAGE section in COBOL is a division within the DATA DIVISION that is used to define data items that are specific to a particular program execution. It provides a temporary storage area for variables and data that are required during the execution of a program but do not need to persist between program invocations.
What is file status 92?
Logic error. e.g., a file is opened for input and an attempt is made to write to it.
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.
What is the purpose of the INPUT PROCEDURE and OUTPUT PROCEDURE in COBOL?
In COBOL, the INPUT PROCEDURE and OUTPUT PROCEDURE are sections within the SORT verb that define the logic for processing input records and output records during a sorting operation.
INPUT PROCEDURE: The INPUT PROCEDURE is responsible for handling the input records that are read from an input file. Within the INPUT PROCEDURE, you can perform tasks such as opening the input file, reading and editing the input records, and preparing the data for sorting. You have the flexibility to perform any necessary data manipulations, validations, or calculations on the input records before releasing them for sorting. Finally, the input file is closed, completing the input processing phase.
OUTPUT PROCEDURE: The OUTPUT PROCEDURE is responsible for handling the output records that result from the sorting operation. Within the OUTPUT PROCEDURE, you can perform tasks such as writing the sorted records to an output file or performing further processing on the sorted data. You have the flexibility to define any additional data manipulations, formatting, or calculations on the output records as needed. Once the output records are processed, the output file is closed, completing the output processing phase.
What are the file opening modes in COBOL?
File opening modes in COBOL include:
INPUT,
OUTPUT,
I-O, and EXTEND.
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.
What is the difference between static linking and dynamic linking in programming?
Static linking and dynamic linking are two different methods of connecting or integrating subroutines or modules within a program. Here’s the difference between them:
Static Linking: Static linking refers to the process of combining the called subroutine or module into the calling program at compile time or link time. In static linking, the code of the called subroutine is physically inserted into the main program, and the resulting executable file contains all the necessary code. During program execution, there is no need to locate or load external libraries or modules as everything is self-contained within the executable. Static linking provides a standalone executable file that can be run independently.
Dynamic Linking: Dynamic linking, on the other hand, involves keeping the called subroutine or module separate from the main program at compile or link time. During program execution, the main program and the called subroutine exist as separate entities. The linking or connection between them occurs dynamically at runtime when the subroutine is needed. The main program references and loads the required subroutine or module from external libraries or shared libraries on-demand. Dynamic linking allows for modularity and flexibility as multiple programs can share and utilize the same external libraries.
What is the purpose of the EVALUATE statement in programming?
The EVALUATE statement is used for conditional branching and decision-making in programming languages like COBOL. It provides a structured and efficient way to perform multiple comparisons and execute corresponding actions based on the evaluated conditions.
The EVALUATE statement is similar to a case statement or nested IF statements found in other programming languages. It allows the program to compare a given value or expression against multiple conditions, known as WHEN clauses, and perform specific actions associated with the matched condition.
What is the purpose of the REPLACING option in the COPY statement?
The REPLACING option in the COPY statement is used to modify or replace specific text within a copybook when it is included in a program. It allows for the reuse of the same copybook in multiple places within the code while making selective changes to certain portions of the copybook.
What type of error is caught by the ON SIZE ERROR option in programming?
Answer: The ON SIZE ERROR option is used to handle arithmetic errors related to the size or range of numeric values in programming languages like COBOL. It primarily captures errors such as fixed-point overflow, division by zero, and certain power or exponentiation calculations.
The specific errors trapped by the ON SIZE ERROR option include:
- Fixed-point overflow: This occurs when a computation or operation results in a value that exceeds the maximum representable size for the given data type.
- Division by zero: This occurs when attempting to divide a number by zero, which is mathematically undefined.
- Exponentiation errors: These include situations such as zero raised to the zero power, zero raised to a negative number, or a negative number raised to a fractional power.
Which divisions and paragraphs are required in a COBOL program?
In a COBOL program, there are certain divisions and paragraphs that are mandatory and must be included. These are:
- Identification Division: The Identification Division is a mandatory division in a COBOL program. It contains information about the program, such as the program name, author, date, and other descriptive details. The Program ID paragraph within the Identification Division is also mandatory and specifies the unique identifier for the program.
- Environment Division: The Environment Division is another mandatory division in a COBOL program. It contains the CONFIGURATION SECTION and INPUT-OUTPUT SECTION, which define the environment and the files used by the program.
- Data Division: The Data Division is a mandatory division in a COBOL program as it defines the data structures used by the program. It includes the FILE SECTION, WORKING-STORAGE SECTION, and LINKAGE SECTION. At least one of these sections must be present in the Data Division.
- Procedure Division: The Procedure Division is the main section of a COBOL program where the actual program logic is written. It contains the executable statements and procedural logic to perform the desired tasks. The Procedure Division is mandatory and must be present in every COBOL program.
What is the difference between global variables and external variables in COBOL?
Global variables and external variables are two types of data variables used in COBOL programs. Here’s the difference between them:
Global Variables: Global variables are data variables that are accessible and visible only within the scope of a specific program or module. They are declared and defined within the program itself and can be accessed by any subroutine, paragraph, or section within that program. Global variables are limited to the scope of the program and cannot be accessed from other programs or modules.
External Variables: External variables, also known as external data items, are data variables that can be referenced from multiple programs residing in the same system library. They are declared and defined in a separate copybook or program that is shared by multiple programs. External variables allow for data sharing and communication between different programs within the same library.
What does the PIC 9V99 notation indicate in COBOL?
In COBOL, the PIC 9V99 notation is used to define a numeric field with a specific format and implied decimal point. Here’s what it signifies:
The “PIC 9V99” notation indicates a three-position numeric field where the first position is for a whole number digit, and the following two positions represent decimal places. The “V” character is used as an implied or assumed decimal point. This format allows for the representation of decimal numbers with two decimal places.
What are the guidelines for writing a structured COBOL program?
When writing a structured COBOL program, it is important to follow certain guidelines to ensure readability, maintainability, and efficiency. Here are some guidelines to consider:
- Use Divisions and Sections: Organize your program into logical divisions such as Identification, Environment, Data, Procedure, and possibly others. Within each division, use sections to further structure and group related code.
- Modularize with Paragraphs and Sections: Break down your procedures into smaller, manageable pieces using paragraphs and sections. Each paragraph should perform a specific task, and sections can be used to group related paragraphs.
- Use Meaningful Names: Give meaningful and descriptive names to variables, paragraphs, and sections. This enhances the readability and understanding of your program’s logic.
- Follow a Logical Flow: Write your code in a structured and sequential manner, following a logical flow from the start to the end of your program. Use conditionals (IF, ELSE, etc.) and iterative statements (PERFORM, EVALUATE, etc.) to control the flow of execution.
- Avoid GOTO Statements: Minimize the use of GOTO statements as they can make the program difficult to understand and maintain. Instead, use structured control statements like IF-ELSE, PERFORM, and EVALUATE for better program control.
- Use Comments: Include comments throughout your code to provide explanations, describe the purpose of sections or paragraphs, and make the program more understandable to other developers.
- Limit Paragraph Length: Keep your paragraphs concise and focused. Avoid creating excessively long paragraphs that perform multiple tasks. Breaking them down into smaller paragraphs improves readability.
- Use Proper Indentation: Indent your code consistently to improve readability and clearly show the program’s structure. Proper indentation helps identify nested sections, loops, and conditional statements.
- Limit Use of Global Variables: Minimize the use of global variables and prefer local variables within the scope of specific paragraphs or sections. This helps prevent unintended side effects and enhances program maintainability.
- Error Handling: Implement proper error handling techniques, including the use of exception handling routines, to handle exceptions and error conditions gracefully.
What are the divisions of a COBOL program?
A COBOL program is typically divided into four divisions:
- Identification Division: This division contains information about the program, such as the program name, author, date of creation, and other relevant identification details.
- Environment Division: The Environment Division defines the configuration and characteristics of the system on which the program will execute. It includes sections such as Configuration Section, Input-Output Section, and File Section.
- Data Division: The Data Division defines the data structures and variables used in the program. It includes sections such as File Section, Working-Storage Section, Local-Storage Section, and Linkage Section.
- Procedure Division: The Procedure Division contains the actual procedural logic of the program. It includes sections, paragraphs, and sentences that define the sequence of actions to be performed. This division is where the main execution flow of the program is coded.
What is the difference between COMP-1 and COMP-2 ?
COMP-1 and COMP-2 are data types used in COBOL for representing floating-point numbers with different levels of precision. Here’s a more detailed explanation of each:
- COMP-1: It is a single-precision floating-point data type in COBOL. It is used to represent floating-point numbers with a precision of 4 bytes or 32 bits. COMP-1 numbers use the IEEE floating-point format and can store decimal numbers with a range and precision suitable for most general calculations.
- COMP-2: It is a double-precision floating-point data type in COBOL. It is used to represent floating-point numbers with a higher level of precision compared to COMP-1. COMP-2 numbers require 8 bytes or 64 bits of storage. They also use the IEEE floating-point format but provide increased precision, allowing for more accurate calculations and representation of decimal numbers.
Could you please provide me with information about the different rules to perform a SEARCH?
In COBOL, the SEARCH operation allows for searching within a table. Here are the rules associated with performing a search in COBOL:
- Table with OCCURS Clause: The search operation can be applied to a table that is defined using the OCCURS clause. The OCCURS clause specifies the number of occurrences or elements in the table.
- INDEXED BY Phrase: To perform a search, the table must be indexed using the INDEXED BY phrase. This phrase associates an index name with the table, allowing you to reference specific elements within the table during the search.
- Initial Value for Search Index: Before performing the search, the search index (associated with the table using the INDEXED BY phrase) must have some initial value. This value determines the starting point for the search within the table.
- Setting the Index Value: Prior to initiating the search, it is common practice to set the value of the search index to 1. This ensures that the search starts from the first element of the table.
Could you please provide me with information about the different rules for the SORT operation in COBOL?
In COBOL, the SORT operation is performed using the SORT verb. Here are the basic rules and requirements for using the SORT operation:
- Input and Output files must remain closed: Before executing the SORT verb, the input and output files must be closed. This means that the files should not be open for reading or writing by any other program or process.
- Working file must have a SELECT clause: The working file used for sorting must be defined in the File Section of the program using the SELECT clause. The SELECT clause specifies the file’s organization, access mode, and other attributes.
- Input and Output files have FD entries: The input and output files used in the SORT operation must be defined in the File Section using the FILE-CONTROL paragraph. The FILE-CONTROL paragraph contains the File Description (FD) entries for each file, which provide information about the file’s layout and characteristics.
- Work file should have a short description in the File Section: The working file used for sorting should have a short description in the File Section. This description typically includes the file name, organization, access mode, and record length.
These rules ensure that the SORT operation can be performed correctly and efficiently in a COBOL program.
What is REDEFINES?
The REDEFINES clause allows you to use different data description entries to describe the same computer storage area. OR The REDEFINES clause allows the same memory area to be described by different data items
Why is it necessary to open a file in I-O (Input-Output) mode for the REWRITE operation in COBOL?
When performing the REWRITE operation in COBOL, it is necessary to have the file opened in I-O mode. This is because the REWRITE operation requires reading the existing record from the file before updating it.
The REWRITE operation is used to modify or update an existing record in a file without changing its position. Before performing the REWRITE, the program needs to locate the specific record within the file by performing a prior READ operation. This read operation fetches the desired record from the file and makes it available for modification.
When is INSPECT verb is used in COBOL?
INSPECT is used to know number of times a specific character occurs or to replace some portion of data.
How many sections are there in the Data Division of COBOL?
The Data Division in COBOL is divided into six sections that serve specific purposes in defining and organizing data within a program. These sections are as follows:
- File Section: The File Section is used to describe the files that the program will read from or write to. It includes file descriptions, record layouts, and access modes for sequential, indexed, or relative files.
- Working Storage Section: The Working Storage Section is used to define data items that are needed during program execution but do not require persistence between program runs. It typically includes variables, counters, flags, and other temporary data used for calculations or intermediate storage.
- Local Storage Section: The Local Storage Section is used to define data items that are specific to a particular program execution. It is allocated and deallocated each time the program is called and provides a temporary storage area for program-specific data.
- Screen Section: The Screen Section is used to define the layout and characteristics of screens or display panels used in interactive or online programs. It includes screen descriptions, field definitions, and attributes such as colors and positions.
- Report Section: The Report Section is used to define the layout and formatting of reports generated by the program. It includes report descriptions, record layouts, and report control statements for page breaks, headings, footings, and other formatting options.
- Linkage Section: The Linkage Section is used for defining data items that are passed between programs or modules through parameters or communication areas. It provides a way to share data between different program units.
How to display COMP-3 variable in Cobol?
Cobol does not allow you to directly display COMP-3. The only way you can display it is by moving the value into a variable.
What is the difference between a CALL statement and a LINK statement in COBOL?
Both the CALL statement and the LINK statement are used to invoke external programs or subroutines in COBOL. However, there is a difference in the way they are used and their relationship to COBOL.
CALL Statement: The CALL statement is a COBOL verb that is used to invoke an external program or subroutine and transfer control to it. It is a standard COBOL command that allows one program to call another program or subroutine. When a CALL statement is executed, control is transferred to the called program, and after the called program completes its execution, control returns to the next statement following the CALL statement in the calling program.
LINK Statement: The LINK statement, on the other hand, is not a COBOL verb but rather a facility provided by the underlying operating system or runtime environment. It is used to invoke an external program or routine, similar to the CALL statement. However, the LINK statement is typically used when interacting with programs written in other languages or when invoking system-level functions. The LINK statement transfers control to the external program, and control may or may not return to the calling program.
What is the Difference between GOBACK, STOP RUN and EXIT PROGRAM in COBOL?
GOBACK returns control to the calling program
STOP RUN stops the current work unit and returns control to OS
EXIT PROGRAM is used to come out of a program that has been called by another program
COBOL Interview Questions for Experienced Candidates
What are the different ways to handle date arithmetic in COBOL?
You can use intrinsic functions like DATE-OF-INTEGER, INTEGER-OF-DATE, and FUNCTION CURRENT-DATE to perform calculations on dates.
You can also manipulate date fields by splitting them into individual components (year, month, day) and perform arithmetic operations on these components.
Can you Explain the differences between CALL and LINK statements in COBOL?
CALL statement is used to transfer control to a subroutine or a separate COBOL program. It establishes a new level of the calling program hierarchy and returns control back to the caller upon completion.
LINK statement is used for dynamic program linking. It transfers control to a specified program or routine and transfers control back to the calling program upon completion. It allows the called program to directly access data and variables of the calling program.
How can you handle file status codes in COBOL programs?
COBOL provides a predefined set of file status codes that indicate the status of file operations (such as OPEN, READ, WRITE, CLOSE). These codes are stored in a special 2-byte field called FILE-STATUS.
You can check the value of the FILE-STATUS field after file operations and take appropriate actions based on the returned status code. For example, you can handle errors, retry operations, or display error messages.
What is the purpose of the REDEFINES clause in COBOL, and how is it used?
The REDEFINES clause is used to define two or more data items that occupy the same storage area. It allows different interpretations or representations of the same memory location.
It is primarily used for data item overlaying, where a single memory location can be used to store different types of data depending on the program logic or processing requirements.
How do you handle decimal arithmetic in COBOL, and what are the considerations for precision and scale?
COBOL provides built-in support for decimal arithmetic through the USAGE clause. You can declare numeric fields with USAGE IS COMPUTATIONAL or COMPUTATIONAL-3 to ensure decimal arithmetic precision and rounding.
Considerations for precision and scale involve defining appropriate PIC (Picture) clauses, including the PICTURE and SCALE attributes, based on the decimal requirements of the data.
Can you explain the differences between static and dynamic linking in COBOL?
Static linking is done at compile time, where all the necessary subprograms or libraries are resolved and bound to the main program. The resulting executable contains all the required code.
Dynamic linking occurs at runtime, where the program references external subprograms or libraries. The linkage is resolved dynamically during program execution, allowing for flexibility and modularity.
What is the significance of the INITIALIZE verb in COBOL, and how is it used?
The INITIALIZE verb is used to initialize a group or elementary data item to its default initial values. It sets the value of each data item within the group to the predefined initial value defined by the USAGE clause.
How do you handle exceptions and abnormal termination in COBOL programs?
COBOL provides several error-handling techniques, including the use of condition-names, the ON EXCEPTION phrase, and the declarative section, to handle exceptions and abnormal termination.
By defining condition-names and associating them with specific exception conditions, you can handle errors or exceptional situations gracefully and take appropriate actions.
Explain the concept of file organization in COBOL, such as sequential, indexed, and relative?
Sequential file organization is used when records are accessed and processed in the order they appear in the file, from start to end.
Indexed file organization involves the use of an index to allow direct access to records based on a key value.
Relative file organization provides direct access to records using relative record numbers.
How can you handle table processing in COBOL, including search and sort operations?
– COBOL provides various table-handling capabilities like SEARCH, SEARCH ALL, SORT, and MERGE.
– SEARCH and SEARCH ALL are used to search for specific values in a table, while SORT and MERGE are used for sorting and merging table elements based on specified criteria.
What are the differences between level numbers 66 and 88 in COBOL?
Level number 66 is used for a renaming entry. It allows a data item to be renamed without allocating additional storage. It is often used to provide a more descriptive name for an existing data item.
Level number 88 is used for condition-names. It represents a condition or a flag that can be tested for true or false. Condition-names are associated with data items and are primarily used for decision-making or branching logic.
Can you explain the purpose and usage of the INSPECT verb in COBOL?
The INSPECT verb in COBOL is used for string manipulation and data manipulation tasks. It allows you to search, replace, and modify characters or substrings within a data item.
INSPECT can be used to perform operations like counting occurrences, replacing characters, removing leading or trailing spaces, validating data formats, and more.
How can you handle sequential and indexed file processing in COBOL?
For sequential file processing, you can use the READ, WRITE, and REWRITE statements to read records sequentially from an input file or write records sequentially to an output file.
For indexed file processing, COBOL supports indexed file organizations like QSAM, VSAM, and ISAM. You can use the START, READ, WRITE, and REWRITE statements with associated file-control clauses to access and process indexed files.
What is the difference between CALL and CICS commands in COBOL programs?
CALL statement is a COBOL language construct used for program-to-program communication within a batch environment.
CICS commands, such as EXEC CICS READ or EXEC CICS WRITE, are used in COBOL programs running under the CICS (Customer Information Control System) transaction processing environment. They provide access to CICS services and resources.
Can you explain the differences between USING and GIVING phrases in COBOL programs?
The USING phrase is used in the PROCEDURE DIVISION to pass data from the calling program to the called program or subroutine.
The GIVING phrase is used to return results from the called program or subroutine to the calling program.
These answers should provide you with a good understanding of the topics. However, it’s always recommended to study further and refer to COBOL language documentation for more detailed information and examples.