Skip to main content

Command Palette

Search for a command to run...

Mainframe Interview Ques

Updated
28 min readView as Markdown

1.Advantage of GDG over PS file?

ConceptGDG (Generation Data Group)PS (Physical Sequential) File
DefinitionA group of related datasets with the same base name, managed as generationsA single standalone dataset
Use CaseUsed when you need to maintain historical versions of a file (e.g., backups, logs)Used for one-time processing or temporary data

2. How do you define a VSAM file in COBOL?
Environment Division.
Input-output section.
File-control.
select VSAM-FILE assign to VSAMFL
organisation is indexed
access mode is random
record key is EMP-ID
alternate record key is EMP-NAME with duplicates
file status is ws-file-status.
Data division.
File section.

FD vsam-file
data record is vsam-record.
01 vsam-record.

3. How do you define the record structure of a VSAM file in COBOL?
For Fixed Block Size:

Data division.
File section.

FD vsam-file
block contains 0 records
recording format is F
Label records are standard
data record is vsam-record.
01 vsam-record.

For Variable Block size:
FD VB-FILE
RECORDING MODE IS V
RECORD VARYING FROM 50 TO 300 CHARACTERS
DEPENDING ON WS-REC-LENGTH.

4. How many types of VSAM files are there, and what is the difference in each?
Key Sequenced Dataset, Entry Sequenced Dataset, Relative Record Dataset, Linear Dataset.

TypeOrganizationAccess MethodKey-Based Access?Records Can Be Deleted?Use Case
KSDSIndexedSequential, Random, Dynamic✅ (Primary Key)Customer databases, inventory, employee records
ESDSSequentialSequential, Dynamic❌ (Only marked inactive)Log files, audit trails, transaction history
RRDSRelativeSequential, Random✅ (Relative Record Number)Airline seat reservation, device control
LDSByte-streamSpecial APIsDB2 tablespaces, system files

5. How do you create a KSDS VSAM file?
//STEP07 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
DELETE ECOPV.SHRCLS.FILE
SET MAXCC=0
DEFINE CLUSTER(NAME(ECOPV.SHRCLS.FILE) -
INDEXED -
KEYS(6 0) -
FSPC(10 10) -
SPEED -
SHR(3 3) -
RECSZ(26 26)) -
DATA( NAME(ECOPV.SHRCLS.FILE.DATA) -
CYL(10 10) ) -
INDEX( NAME(ECOPV.SHRCLS.FILE.INDEX) -
CYL(5 5) )

7. How do you copy data from a VSAM file to another VSAM file or a PS file?
REPRO INFILE(INPUTDD) OUTFILE(OUTPUTDD)

8. What is the VERIFY option in IDCAMS for VSAM files?
The VERIFY command in IDCAMS is used to check the integrity of a VSAM file after an abnormal termination (abend) or system failure. It ensures that the end-of-file (EOF) marker is correctly positioned and restores access to the dataset if it was left in an inconsistent state.

9. What is Control Interval and Control Area in VSAM?
In VSAM, the unit of data that is transferred in each physical I/O operation is defined as a control interval.
A Control Area (CA) is formed by putting together two or more Control Intervals.

10. What is control area split and control interval split in VSAM?
CI-SPLIT: If there isn't enough space in the control interval. VSAM performs a control interval split by moving some records to the free control intervals.
CA-SPLIT If there isn't a free control interval for split. VSAM performs a control area split by allocating a new control area and moving half of the control intervals to it.

11. How do you update a VSAM file with today’s transactions if yesterday’s transactions are in a VSAM file?
REPRO

12. How do you browse a VSAM file?
Through FILEAID and PRINT INFILE(VSAMFILE) Count(N)

13. What are file status codes 22, 23, 90, 91, and 92 in VSAM?
22 - duplicate or invalid key
23 - record not found
39 - attributes mismatch with file in cobol and jcl
90 - VSAM operations failed
91 - File not opened properly
92 - Logic error ( mismatch in file access)

13.Can you explain the differences between a COBOL copybook and a working storage section?
Stores variables local so it can only used for this program, whereas COBOL Copybook can be shared with multiple other programs.

14. Describe the purpose and usage of the FILE-CONTROL paragraph in COBOL.
File Association - Link a cobol file name to an external dataset or VSAM.
Access Control - Specifies how the program will access the file(eg: sequential, random, direct)
File Organization - defines the structure of the file

15. How do you handle VSAM file status codes in COBOL programs?
Specifies file status is ws-file-status in file-control.
Declare a file status variable in working-storage.

16. Explain the significance of DSN in DB2. How is it used?
Acts like Identifier for database subsystem. It is used to establish a connection between COBOL-DB2 program and DB2 database.

17. Discuss the significance of COMMIT and ROLLBACK statements in DB2.
COMMIT
is used to permanently save all changes made by a transaction in DB2. Once a COMMIT is issued, the changes become visible to other users and cannot be undone.

ROLLBACK is used to undo all changes made by a transaction since the last COMMIT. It is useful when an error occurs or if the transaction needs to be canceled.

18. How would you optimize a COBOL program for performance in a mainframe environment?
1. Optimize File Handling Efficient file access is crucial for performance.

✅ Use the Right File Organization: VSAM KSDS for indexed access ESDS for sequential processing RRDS for random access
✅ Reduce I/O Operations: Use BLOCK CONTAINS and RECORD CONTAINS clauses in the FD section to increase block size, reducing I/O. MULTIPLE RECORDS PER BLOCK improves efficiency.
✅ Use Efficient Access Methods: Use SEQUENTIAL access for batch processing when reading large files. Use DYNAMIC access only when necessary, as it requires additional processing.
✅ Avoid Excessive OPEN and CLOSE Statements: Keep files open for the entire transaction whenever possible.
2. Optimize Database Access (DB2 & VSAM) Database interactions often impact COBOL program performance.
✅ Use Efficient SQL Queries (For DB2 Programs): Use OPTIMIZE FOR n ROWS to limit the result set. Use INDEXES to speed up searches. Avoid SELECT * and fetch only the required columns.
✅ Use CURSOR Efficiently: Use FOR UPDATE OF to avoid unnecessary locking. Use FETCH FIRST n ROWS ONLY for limited data retrieval.
✅ Minimize I/O in VSAM Files: Use START and READ NEXT for sequential reads instead of multiple READ RANDOM calls. Avoid frequent REWRITE or DELETE operations within loops.
3. Optimize CPU Usage Reducing unnecessary processing can improve execution speed.
✅ Use COMP or COMP-3 for Numeric Data: Binary computations are faster than display format (PIC 9(n)). Use COMP for calculations, COMP-3 for packed decimal storage.
✅ Avoid Unnecessary Data Movements: Minimize MOVE statements. Store frequently used values in WORKING-STORAGE instead of re-reading files.
✅ Reduce Condition Checking: Arrange EVALUATE conditions from most to least likely to reduce checks. Use PERFORM WITH TEST AFTER instead of unnecessary condition checks.
4. Optimize Program Logic Refactoring code for efficiency can improve execution time.
✅ Use Efficient Looping Mechanisms: Use PERFORM UNTIL instead of GO TO for better readability and performance. Avoid deeply nested loops; consider restructuring logic.
✅ Use SEARCH Instead of Sequential IF Conditions: For large OCCURS tables, use SEARCH ALL (binary search) instead of sequential SEARCH.
✅ Minimize Unnecessary COMPUTE Statements: Avoid unnecessary COMPUTE operations in loops. Pre-calculate values outside of loops where possible.
5. Reduce Memory Usage Efficient memory management prevents excessive resource consumption.
✅ Use the OCCURS Clause Wisely: Use OCCURS DEPENDING ON to dynamically allocate storage. Avoid defining large tables if only a small portion is needed.
✅ Use WORKING-STORAGE Efficiently: Avoid declaring large unused variables. Use LINKAGE SECTION for passing large data between programs.
6. Use Compiler Optimization Options COBOL compilers offer various optimization techniques.
✅ Enable Compiler Optimization Flags: Use OPT(2) or OPT(3) for better performance in Enterprise COBOL. Use SSRANGE OFF to disable subscript range checking in production.
✅ Use Compiler Directives: FASTSRT for improving SORT performance. BUFSIZE to adjust buffer sizes for better efficiency.
7. Optimize SORT and MERGE Operations Sorting can be resource-intensive, so optimizing it is crucial.
✅ Use COBOL SORT Instead of External SORT Utilities When Possible.
✅ Use Input and Output Procedures in SORT Statements to minimize unnecessary file reads.
✅ Ensure the SORT Work Area (STORAGE) is Large Enough to prevent excessive I/O.

19. What are the various types of joins in DB2, and when would you use each one?
Inner Join :-
Retrieves only matching rows from both tables.
Use When: You need records that exist in both tables and satisfy the join condition.
Left Join or Left Outer Join:-
Returns all records from the left table and matching records from the right table.
If no match is found, NULL values are returned from the right table.
Use When: You need all records from the left table, even if there’s no matching data in the right table.
Right Join or Right Outer Join:-
Returns all records from the right table and matching records from the left table.
If no match is found, NULL values are returned from the left table.
Use When: You need all records from the right table, even if no matching data exists in the left table.
Full Outer Join :-
Returns all records from both tables.
If a match exists, it is returned; otherwise, NULL values are shown where there is no match.
Use When: You need to retrieve all records from both tables, whether or not they have matching entries.
Cross Join:
Returns a Cartesian product of both tables (i.e., every row of the first table is combined with every row of the second table).
Use When: You need all possible combinations of records from both tables.
🚨 Be careful! It can generate huge result sets.
Self Join:
Joins a table with itself.
Use When: You need to compare rows within the same table, like finding employees who report to the same manager.

20. Explain Isolation levels in DB2?
ISOLATION LEVEL:- Degree to which db2 data which is being accessed with cobol-db2 program is isolated with another parallely executing cobol-db2 program.
Cursor stability (CS) - The cursor stability isolation level locks only the current row which the program is accessing. As soon as the program shifts to the next row, the lock in the previous row gets released. The cursor stability fetches only committed rows for the program to access. This is a default isolation level.
Read stability (RS) - This isolation level places a lock on all the rows which qualifies the SQL statement’s predicate (eg: WHERE clause). The lock is retained until the entire processing is completed.
Uncommitted read (UR) - The uncommitted read isolation level is used in the SQL statements meant for read-only purpose. There is no lock placed on a row/record and it fetches the committed as well as uncommitted rows (from the other programs/transactions).
Repeatable read (RR) - This holds page and row locks until a COMMIT point is reached. No other program can modify the data. If the data is accessed twice during the unit of work, the same exact data will be returned.

20. Explain how you would handle GDG (Generation Data Group) in JCL.
Define GDG using IDCAMS, Create, Read latest, Read previous, Delete using IDCAMS.

21. Describe the purpose and usage of EXEC statement in JCL.
EXEC used to Execute the cobol programs & Procedures.

22. Explain Proc in jcl?
A procedure (PROC) in JCL is a reusable set of JCL statements that can be called from multiple jobs. It helps in reducing redundancy, improving maintainability, and simplifying complex JCL scripts.

22. How do you handle concurrency issues in a DB2 environment?
Use of isolation Levels.

23. Can you explain the role of a plan and a package in DB2?
Package:- Compiled form of sql statements in a DBRM.
Plan:- A collection of packages needed to execute a program.

24. Discuss the significance of primary and secondary allocation in VSAM datasets.
Primary Allocation:- Initial amount of space allocated when the VSAM first allocated.
Secondary Allocation:- If the dataset grows beyond primary allocation, VSAM attempts to allocate additional space.

25. How do you debug COBOL programs in a mainframe environment?
Using Xpeditor or adding displays.

26. Explain the importance of the SQLCODE and SQLSTATE variables in DB2 programming.
SQLCODE:- A numerical code that indicating the execution of the SQL Statement.
SQLSTATE:- A standardized 5-character string providing additional error classification

27. Describe the process of error handling in COBOL programs using CICS (Customer Information Control System).
Always check EIBRESP or RESP variables after every CICS command.
✔ Use HANDLE CONDITION for controlled error recovery.
✔ Use HANDLE ABEND to redirect the program flow in case of an unexpected failure.
✔ Log errors in a separate file or table for debugging and troubleshooting.
✔ Ensure transaction rollback using SYNCPOINT and ROLLBACK when needed.

28. How to read the VSAM file if you don't know the full key?
START: Position the file pointer at the first record that matches the known part of the key.
READ NEXT: Read subsequent records sequentially until the key no longer matches the partial key.

29. what is MSG Level =(1,1) in JCL?
Controls the printing of job statements in the spool. MSGLEVEL=(M1,M2), MSGLEVEL=(1,1) means print all job statements and print allocation and termination message when job ended normally or abnormally.

31. How do we handle -911 SQL abend in the Cobol db2 program?
Dead Lock or Time Out. need to run repair job.

32. what will happen when open the cursor?
SQL statement inside the cursor is executed, No data is retrieved the program must use fetch to retrieve data from one by one.

33. what is the main difference when declaring the cursor in the working-storage section and procedure division?
Declaring Cursor in the Working-Storage Section (Static SQL)
The cursor is hardcoded with a predefined SQL query.
The query structure remains fixed at compile time.
Performance is better because DB2 optimizes access paths during pre-compilation.
More secure since SQL statements are not modified at runtime.
Declaring Cursor in the Procedure Division (Dynamic SQL)
The cursor is declared within the PROCEDURE DIVISION using a PREPARED STATEMENT.
The SQL query is built at runtime, allowing for more flexibility.
Performance overhead exists due to query parsing and optimization at runtime.
Useful when query conditions or tables change dynamically.

34. what are 'for update of' and 'where current of 'in cursor?
FOR UPDATE OF :- It locks the rows for update, preventing from other transactions to modify until the cursor is closed.
WHERE CURRENT OF:- It allows you to modify or delete the row currently being processed by the cursor.

35. what is SOC4 and SOC7 abend?
SOC4 :- Protection exception error.
An Invalid address referenced due to subscript error
In a group Move the length of the receiving field was defined incorrectly
Moving variable length record which is larger than the receiving field’s length.
Read/Write a file which has not been opened in the program.
Read/Write a file after EOF.
Invalid parms passed through linkage section.
Used DD dummy with logic that moves high values to FD at end of read.
Tried to use CALL within COBOL SORT Input output procedure
Using GOBACK in COBOL SORT output procedure

SOC7:- Data exception error. (index out of bounds)
An uninitialized index or subscript
An invalid sign bit in the last byte
Incorrect overlapping of fields in arithmetic packed decimal
Trying to read a table when the subscript is larger than the array size
Comparing a PACKED-DECIMAL or USAGE DISPLAY data item to another numeric data item when the PACKED-DECIMAL or USAGE DISPLAY data item contains invalid digits or an invalid sign code

SE37:- Dataset out of space.
S106: Region Not enough.
S806: Load module not found.
SB37: Primary or secondary extends not enough for PS.
SD37: Secondary Space is not soecified.
S222: operator cancelled the job.
S013: Member not found.
S322:- Allocated cpu time exceeded, time abend.
S722:- SYSOUT linit has been reached

36. write a query to find the 3rd highest salary from table?
SELECT DISTINCT SALARY FROM EMPLOYEE ORDER BY SALARY DESC FETCH FIRST 1 ROW ONLY OFFSET 2 ROWS;
SELECT SALARY FROM ( SELECT SALARY, ROW_NUMBER() OVER (ORDER BY SALARY DESC) AS RN FROM EMPLOYEE ) WHERE RN = 3;
SELECT SALARY FROM ( SELECT SALARY, DENSE_RANK() OVER (ORDER BY SALARY DESC) AS RN FROM EMPLOYEE ) WHERE RN = 3;

37. what is class and msgclass in jcl?**
CLASS Parameter used to classify the job, to how much time there are running.
MSGCLASS parameter is used to specify the output device to where the system or jcl messages are routed(written & printed). It’s used to hold the job log messages - JESMSGLG
Default value is ‘A’ (spool).

38. How to create a map and map set in cics?
Write the BMS map (BMS macros).
Assemble and link the map.
Use the map in a COBOL-CICS program.
Define and install the map in CICS.
Run the transaction to display the screen.

  1. what is DB2 runstat utility?
    Used to gather and update statistics about tables and index.

  2. How many ways pass the data from jcl to cobol?
    InStream, File, PARM parameter.

  3. what is search and searchall in cobol?
    Search is a sequential search (one by one).
    SearchAll is Binary search (divide & conquer).

  4. what are utilities used for the cobol db2 precompile process?
    1️⃣ Precompile (DSNHPC) → Converts SQL to CALL statements, generates DBRM.
    2️⃣ Compile (IGYCRCTL) → Converts COBOL source to an object module.
    3️⃣ Bind (DSN) → Binds the DBRM to a PLAN.
    4️⃣ Link (IEWL) → Creates a load module.
    5️⃣ Execute (IKJEFT01) → Runs the program.

  5. what is the importance of SQLCA in the cobol db2 program?
    SQLCA (SQL Communication Area) is a data structure that stores information about the execution of SQL statements in a COBOL-DB2 program. It helps in error handling, debugging, and performance monitoring.

  6. matched and unmatched logic using the cobol program?
    OPEN INPUT FILE-A, FILE-B.
    OPEN OUTPUT MATCHED-FILE, UNMATCHED-A-FILE, UNMATCHED-B-FILE.
    PERFORM READ-FILE-A.
    PERFORM READ-FILE-B.
    PERFORM UNTIL EOF-FLAG-A = 'Y' AND EOF-FLAG-B = 'Y'
    IF EMP-ID-A = EMP-ID-B
    MOVE EMP-ID-A TO EMP-ID-MATCH
    MOVE EMP-NAME-A TO EMP-NAME-MATCH
    WRITE MATCHED-REC
    PERFORM READ-FILE-A
    PERFORM READ-FILE-B
    ELSE IF EMP-ID-A < EMP-ID-B
    MOVE EMP-ID-A TO EMP-ID-UA
    MOVE EMP-NAME-A TO EMP-NAME-UA
    WRITE UNMATCHED-A-REC
    PERFORM READ-FILE-A
    ELSE
    MOVE EMP-ID-B TO EMP-ID-UB
    MOVE EMP-NAME-B TO EMP-NAME-UB
    WRITE UNMATCHED-B-REC
    PERFORM READ-FILE-B
    END-IF
    END-PERFORM.

    CLOSE FILE-A, FILE-B, MATCHED-FILE, UNMATCHED-A-FILE, UNMATCHED-B-FILE.
    STOP RUN.
    READ-FILE-A.
    READ FILE-A INTO REC-A AT END
    MOVE 'Y' TO EOF-FLAG-A.
    READ-FILE-B.
    READ FILE-B INTO REC-B AT END
    MOVE 'Y' TO EOF-FLAG-B.

  7. how to find the unique values in the table?
    DISTINCT

  8. How many types of VSAM files do we have? what is main difference between KSDS and ESDS?
    4 Types, Key Sequenced Dataset, Entry Sequenced Dataset.

    | Feature | KSDS (Key-Sequenced Data Set) | ESDS (Entry-Sequenced Data Set) | | --- | --- | --- | | Storage Method | Records are stored in sorted order based on a unique key. | Records are stored in the order they are inserted. | | Access Method | Supports both direct and sequential access using the key. | Supports sequential and direct access using RBA (Relative Byte Address). | | Indexing | Has an index component to locate records using keys. | No index; records are accessed by their physical position (RBA). | | Record Update | Can be updated in place as records are indexed. | Cannot be updated in place; a new record is appended. | | Deletion | Records can be deleted logically, leaving space for reuse. | Records cannot be deleted, only marked for future use. | | Best Used For | Applications requiring fast lookup via keys (e.g., Customer DB, Employee DB). | Applications where records are written once and retrieved sequentially (e.g., Log files, Transaction history). |

  9. what is an alternate index ?
    Secondary index used to retrieve the data from vsam file.

  10. how to convert VB to FB by using JCL?
    In JCL, you can use SORT utility to convert a Variable Block (VB) file to a Fixed Block (FB) file. The key difference is that VB records have a 4-byte RDW (Record Descriptor Word) at the beginning of each record, which needs to be removed.
    //STEP1 EXEC PGM=SORT
    //SYSOUT DD SYSOUT=*
    //SORTIN DD DSN=YOUR.INPUT.VB.FILE,DISP=SHR
    //SORTOUT DD DSN=YOUR.OUTPUT.FB.FILE,
    // DISP=(NEW,CATLG,DELETE),
    // RECFM=FB,LRECL=80,
    // SPACE=(CYL,(5,5),RLSE)
    //SYSIN DD*
    OPTION COPY
    OUTREC BUILD=(5,80) /* Remove first 4 bytes of RDW / /

  11. what is -911 and -913 SQL Abend?

    | Feature | SQLCODE -911 | SQLCODE -913 | | --- | --- | --- | | Cause | Deadlock or Timeout | Deadlock or Timeout | | Transaction Rolled Back? | ✅ Yes (Automatic Rollback) | ❌ No (Program must handle it) | | Action Needed? | Retry transaction | Explicitly issue COMMIT or ROLLBACK |

  12. what are static and dynamic calls in cobol?
    Static call: (Call by value) A static call is when the called program is linked into the main program at compile time. The called program’s object code is included in the main program’s load module.
    Key Features of Static Call
    ✅ Faster execution because the called program is already loaded in memory.
    ✅ Uses less CPU overhead since no dynamic loading is required.
    ✅ Suitable for frequently used subprograms.
    ✅ The called program does not require separate deployment.
    🚨 Limitations:
    ❌ Requires recompilation and re-linking if the subprogram changes.
    ❌ Increases the size of the main program’s load module.
    When to Use Static Call?
    🔹 When the subprogram is frequently used and performance is a priority.
    🔹 When the subprogram is not expected to change often.
    🔹 When the application does not require runtime flexibility.

    Dynamic call: (Call by reference)A dynamic call occurs when the program name is determined at runtime. The called program is loaded into memory dynamically when invoked.
    Key Features of Dynamic Call
    ✅ More flexibility, as the subprogram can be changed without recompiling the main program.
    Reduces the size of the main program’s load module.
    ✅ Ideal for applications where subprograms are used occasionally or change frequently.
    🚨 Limitations:
    ❌ Slightly slower execution due to the overhead of dynamically loading the subprogram.
    ❌ Requires the subprogram’s load module to be available in the library at runtime.
    When to Use Dynamic Call?
    🔹 When the subprogram is rarely used, avoiding unnecessary memory usage.
    🔹 When the subprogram is updated frequently without recompiling the main program.
    🔹 When the program needs runtime flexibility (e.g., choosing a different subprogram at runtime).

  13. how many ways pass data from one application to another application in CICS?

  14. what is the linkage-section in cobol?
    The LINKAGE SECTION in COBOL is used to define variables that are passed from one program to another or from JCL to a COBOL program. It is commonly used in subprograms, called programs, and CICS programs.

  15. Difference between CALL and LINK?

    | Feature | CALL (COBOL) | LINK (CICS) | | --- | --- | --- | | Used In | Batch (JCL, COBOL programs) | Online (CICS transactions) | | Passing Data | USING clause | COMMAREA | | Control Flow | Returns to the main program | Returns to the calling CICS program | | Subprogram Type | Can be batch or CICS | Only for CICS programs | | Resource Management | Subprogram runs in the same memory space | Called program gets a new task storage | | Overhead | Lower (direct memory access) | Higher (CICS resource allocation) |

    1)How do u handle dynamic memory allocations in cobol?
    2)how do you perform sorting in cobol without using the sort verb?
    3)how to load data into array in cobol?
    Perform until ws-eof=’y’
    Read file at end move ‘y’ to ws-eof
    not at end move values to array(counter)
    add 1 to counter
    end-perform

    4. how to search a particular record in cobol?
    5. What kind of analysis we need if we are modifying a copybook?
    6. What will happen if you use redefines with overlapping data items?
    Redefines clause is used to define a storage with different data description. If one or more data items are not used simultaneously, then the same storage can be utilized for another data item. So the same storage can be referred with different data items.
    REDEFINES is useful for memory optimization.
    Overlapping data items share the same memory, so changes in one affect the other.
    Mixing numeric and character data can lead to garbage values or program failures.
    ✅ Avoid redefining COMP, COMP-3, and COMP-1/COMP-2 fields as character fields unless necessary.

    7. Explain Renames clause?
    Renames clause is used to give different names to existing data items. It is used to re-group the data names and give a new name to them. The new data names can rename across groups or elementary items. Level number 66 is reserved for renames.

    8. Difference between REDEFINES and RENAMES?
    RENAMES clause is used for regrouping elementary data items and gives one name to it. REDEFINES clause allow you to use different data descriptions entries to describe same memory area.

    7. What is internal sort in cobol?

    8. How to check the key is present in Ksds file?
    READ VSAM-FILE KEY IS SEARCH-KEY
    INVALID KEY DISPLAY "Key Not Found"
    NOT INVALID KEY DISPLAY "Key Found: " FILE-DATA.

    9. Why should the occurs not be defined at 01 level!
    01 represents an entire record structure, and COBOL does not allow repeating an entire record within a file structure.

    10. How do u optimise a cobol program for performance,particularly when dealing with large datasets?
    11. How does cobol handle memory management,particularly with the use of working storage and linkage section?

    12. Explain the process of handling a file with variable length records in cobol?
    ✔ Use RECORDING MODE IS V to define variable-length files.
    ✔ First two bytes (RDW) store the actual record length.
    ✔ Use READ ... INTO to dynamically adjust the record size.
    ✔ Use RECORD IS VARYING ... DEPENDING ON to handle variable-size records.

    14. The system library from where the executable form of idcams is fetched?
    SYS1.PROCLIB
    SYS1.LINKLIB

    15. An error in Jcl in stream data will be captured as a Jcl error?
    No

    16. How do u delete a record from indexed file?
    Open the file in I-O mode (to allow both reading and deleting).
    Read the record using its primary key.
    If the record exists, use the DELETE statement to remove it.
    Handle possible file status codes properly.
    Close the file after deletion.

    17. What happens if the file is not found at runtime?how would you debug this?

    FILE STATUS IS WS-FILE-STATUS in input-output section in file control will gives file status 35 means file not found. When opening the file.

    18. explain comp, comp-1,comp-2,comp-2?

    | Type | Storage Type | Size | Use Case | | --- | --- | --- | --- | | COMP | Binary (Integer) | 2, 4, or 8 Bytes | Fast arithmetic calculations | | COMP-1 | Single-Precision Float | 4 Bytes | Scientific calculations | | COMP-2 | Double-Precision Float | 8 Bytes | High-precision scientific computations | | COMP-3 | Packed Decimal (BCD) | Varies | Financial applications |

    19. DB2 error codes:
    0 - successful execution
    -100 - record not found
    -180 - date error
    -181- date value exceeds it’s maximum
    -305 - null data exception (cursor/select/update)
    -502 - cursor not opened
    -503 - cursor already opened.
    -803 - duplicate records found while insert
    -805 - Plan not found, bind error
    -811 - multiple records found for select
    -904 - resource unavailable
    -911 - dead lock with timeout
    -913 - dead lock with rollback
    -922 - authorization failed

    20. SQL Statement Types:
    DDL:- Data Definition Language - Define and manage the structure of database objects like index, tables & views ( create, Alter, Drop).
    DQL:- Data Query Language - Used to retrieve data from database. (Select)
    DML:- Data Manipulation Language - Manipulate and manage data within database.(Insert, Update, Delete).
    DCL:- Data Control Language - Manage access and permission for database access.(Grant, Revoke).
    TCL:- Transaction Control Language - Control the transaction performed on database. (Commit, Rollback)

    21. Cursor with HOLD:-
    Cursor should not close until close cursor execution. however executing commit or syncpoint command will close all opened cursors. So to resolve this we use cursor with hold.
    EXEC SQL
    DECLARE CUR_NAME CURSOR WITH HOLD FOR
    SELECT * FROM TBL_NAME
    END-EXEC

    22. Explain VIEW in db2?
    A view in DB2 is a virtual table that does not store data itself but provides a customized way to access data from one or more base tables. It simplifies complex queries, enhances security, and helps in abstraction.

    23. SYNONYM vs ALIAS in db2?
    SYNONYM: A private, user-specific shortcut for a table or view that simplifies queries but is automatically dropped if the base object is dropped.
    ALIAS: A global, persistent reference to a table or view that remains even if the base object is dropped, allowing cross-subsystem access in DB2.

    24. How to handle Null Value Exception in COBOL-DB2 program?
    DB2 provides a NULL indicator variable to track NULL values.
    If a column is NULL:
    NULL Indicator = -1 → The column contains NULL
    NULL Indicator = 0 → The column has a valid value
    NULL Indicator > 0 → The column has a valid but truncated value
    WORKING-STORAGE SECTION.
    01 WS-EMP-ID PIC 9(5).
    01 WS-EMP-NAME PIC X(30).
    01 WS-SALARY PIC 9(7)V99 COMP-3.
    01 WS-SALARY-NULL-IND PIC S9(4) COMP. *> NULL Indicator Variable
    EXEC SQL
    SELECT EMP_ID, EMP_NAME, SALARY
    INTO :WS-EMP-ID, :WS-EMP-NAME, :WS-SALARY :WS-SALARY-NULL-IND
    FROM EMPLOYEE_TABLE WHERE EMP_ID = 1001
    END-EXEC.

    IF SQLCODE = -305 THEN
    DISPLAY 'Error -305: NULL Value Found in SALARY'
    MOVE ZERO TO WS-SALARY > Assigning Default Value
    ELSE
    IF WS-SALARY-NULL-IND = -1 THEN
    MOVE ZERO TO WS-SALARY > Handling NULL after fetching
    END-IF
    END-IF.

    25. what are db2 data types and equivalent cobol datatypes?

    | DB2 Data Type | Description | COBOL Equivalent | | --- | --- | --- | | SMALLINT | Integer (2 bytes) | PIC S9(4) COMP | | INTEGER (INT) | Integer (4 bytes) | PIC S9(9) COMP | | BIGINT | Large Integer (8 bytes) | PIC S9(18) COMP | | DECIMAL (DEC, NUMERIC) | Fixed-point decimal | PIC S9(n)V9(d) COMP-3 | | FLOAT (REAL, DOUBLE) | Floating-point numbers | COMP-1 (Single precision) or COMP-2 (Double precision) | | CHAR(n) | Fixed-length character string | PIC X(n) | | VARCHAR(n) | Variable-length character string | PIC X(n) with null indicator | | CLOB (Character Large Object) | Large text storage | PIC X(n) (handled as multiple segments) | | BLOB (Binary Large Object) | Binary data | PIC X(n) | | DATE | Stores a date (YYYY-MM-DD) | PIC X(10) (formatted as YYYY-MM-DD) | | TIME | Stores time (HH:MM:SS) | PIC X(8) (formatted as HH:MM:SS) | | TIMESTAMP | Date + Time + Fractional seconds | PIC X(26) (formatted as YYYY-MM-DD-HH.MM.SS.ffffff) |

    DB2 Table Definition:
    CREATE TABLE EMPLOYEE (
    EMP_ID INTEGER,
    EMP_NAME VARCHAR(30),
    SALARY DECIMAL(7,2),
    HIRE_DATE DATE
    );
    Cobol Equivalent data structures:
    01 EMPLOYEE-RECORD.
    05 EMP-ID PIC S9(9) COMP. »»»»INTEGER
    05 EMP-NAME PIC X(30). »»»»» VARCHAR
    05 SALARY PIC S9(7)V99 COMP-3. »»»»»» DECIMAL(7,2)
    05 HIRE-DATE PIC X(10). »»»»»»» DATE as STRING "YYYY-MM-DD"

    26. Explain the difference between INDEX and SUBSCRIPT?
    Subscript (Position-Based Access)

    • A subscript is a numeric variable that holds the position number of an element in the array.

    • It starts from 1 for the first element.

    • It is stored in memory as a normal variable, so accessing elements using subscripts is slower than using an index.
      01 ws-sub 9(1) value 1.
      move 100 to ws-table(ws-sub).

  1. It requires multiplication at runtime to find the elements memory location.2) To access ws-table(ws-sub), the system calculates base address+(ws-sub-1)*element size.

  2. This calculation adds extra cpu processing overhead, making it less efficient than index.

Index (Faster Address-Based Access)

  • An index is a special pointer that stores the memory address of an element, not its position.

  • Indexing makes accessing elements faster than using subscripts.

  • It must be defined using INDEXED BY and manipulated with SET and PERFORM VARYING.

    01 WS-ARRAY.
    05 WS-NUMBERS PIC 9(3) OCCURS 10 TIMES INDEXED BY WS-IDX.
    SET WS-IDX TO 1.
    MOVE 100 TO WS-NUMBERS(WS-IDX).
    A index stores the memory address offset of the element, not a numeric value.
    Index are faster than subscripts, no addition calculations are required.

27. DB2 Datatype and bytes stored?
INTEGER => 4 Bytes
DECIMAL(P,N) => (P/2)+1 Bytes
CHAR(n) => n bytes
VARCHAR(n) => n+2 bytes
DATE => 4 Bytes
TIME => 3 Bytes
TIMESTAMP => 10 Bytes

28. DECLARE vs DCLGEN
DCLGEN only provides table structure and host variable declarations.
DECLARE is necessary for cursors and dynamic SQL processing.
Even when using DCLGEN, you must explicitly declare cursors in the program.

29. Difference of COND Parameter in STEP and JOBCARD?

FeatureJOB COND (Job-Level)STEP COND (Step-Level)

Scope

Affects the entire job

Affects only the step

Evaluation

Checked before any step runs

Checked before the step runs

Effect

If met, job terminates

If met, step is skipped

Use Case

To control job-wide execution

To conditionally run steps

30.Explain JOBGROUP, CONCURRENT, GJOB, JOBSET, AFTER?

JCL StatementMatching Description

JOBGROUP

Used to identify the name and attributes of the group of jobs

CONCURRENT

Identifies jobs that can be run at the same time

GJOB

All jobs in a job group must be defined with one of these

JOBSET

A method used to define jobs with the same set of dependencies

AFTER

Defines prerequisites that must be met before a job or set of jobs is run

31.Explain DATACLAS parameter?
The DATACLAS parameter in JCL allows you to assign a predefined data class to a data set. A data class is a set of storage attributes that control how the data set is allocated and managed.

32. Explain EJECT and SKIP statements in COBOL?
In COBOL, EJECT and SKIP are pseudo-statements primarily used in the source code — they are not executable COBOL statements and are used for formatting when printing program listings during compilation.


🔸 EJECT

  • Purpose: Forces a page break in the program listing during compilation.

  • Use Case: Helps organize source code by starting a new page in printed listings.

  • Effect: No effect on program execution.

📌 Example:

           PROCEDURE DIVISION.
           DISPLAY "STARTING PROGRAM".

           EJECT

           PERFORM MAIN-LOGIC.

🔹 This causes the listing to jump to a new page before PERFORM MAIN-LOGIC. when printed or viewed in a full listing output.


🔸 SKIP (aka SKIP1, SKIP2, SKIP3)

  • Purpose: Inserts blank lines in the source listing.

  • Types:

    • SKIP1 – Skips 1 line

    • SKIP2 – Skips 2 lines

    • SKIP3 – Skips 3 lines

  • Use Case: Visually separates sections of code for readability in listings.

  • Effect: No runtime effect.

📌 Example:

           DISPLAY "VALIDATION COMPLETE".

           SKIP2

           DISPLAY "PROCESSING NEXT RECORD".

🔹 This will add two blank lines between the display statements in the listing only.


⚠️ Important Notes:

  • These are compiler directives or listing formatters.

  • They do not affect the compiled executable or logic of your COBOL program.

  • Mostly used in legacy systems when printed listings were common.


33. EXTEND statement in COBOL?
The EXTEND statement in COBOL is used when you're working with a sequential file and want to add new records at the end of an existing file.
syntax: OPEN EXTEND file-name

34.Create GDG Base and mention the parameters?
Create a GDG base (using IDCAMS utility – Access method service utility

//Step01 exec PROG=IDCAMS
//sysprint dd sysout=a
//sysin dd *

define gdg - (name(sample.test) -
limit(10) -
Noempty -
scratch)
List of PARAMETERS used to create GDG:

NAME– Name of the GDG Base.

LIMIT– To limit the maximum number of generations.

EMPTY/NOEMPTY:

NOEMPTY– Uncatalog only the oldest generation in GDG when the limit is reached.
EMPTY– Uncatalog all the generations when a limit is reached.

SCRATCH/NOSCRATCH:

SCRATCH-Physically delete the dataset(generation) which is uncataloged.
NOSCRATCH– Don’t Physically delete the dataset(generation) which is uncataloged

  1. 🔍 Difference Between Transaction and Task in CICS


    🔸 Basic Definitions

    | Concept | Definition | | --- | --- | | Transaction | A 4-character identifier used by a user or program to invoke a CICS application. Think of it like a command that tells CICS what operation to perform. | | Task | The unit of work that CICS creates when a transaction is initiated. A task is the execution instance of a transaction. |


    🔄 How They Work Together

    • When a user types a transaction ID (e.g., INQ1) and presses Enter in a CICS terminal:

      1. CICS starts a task.

      2. The task loads the associated COBOL program.

      3. The task performs the defined logic (e.g., retrieve data, update a file).

      4. After execution, the task ends.

More from this blog

Mainframes

15 posts