You are on page 1of 18

Scenario-1 (RAHUL)

Rahul is working as a mainframe developer in ABC banking project. He received a new requirement
from client for which he must write a COBOL program to validate the input file.

Section1:
The program should read the input file and perform data validation based as per client
requirements.
The record layout of TRANS-FILE ( IDC006.EMP.DETAILS) is:

Field Name Picture clause Rule


EMP-ID 9(9) ONLY NUMERIC
EMP-NAME X(22) NON-BLANK
EMP-CODE 9(1) In the range of 1-9
MARITAL-STATUS X(1) S,M,D,W,
SALARY 9(5) In the range of 15000-
25000(includes upper and lower
boundary)
DEPT 9(2) 10,14,20 ONLY

The input record needs to be validated based on above rule and the records which pass the above
criteria are copied to another PS file ( IDC1600.EMP.FINAL) and processed further.
Record layout of IDC1600.EMP.DETAILS:
FD ETRANS.
01 TRANS-REC.
05 EMP-ID PIC 9(9)
05 EMP-NAME PIC X(22)
05 EMP-CODE PIC 9(1)
05 EMP-MARTIAL-STATUS PIC X(1)
05 EMP-SALARY PIC 9(5)
05 EMP-DEPT PIC 9(2)

Record Layout of IDC1600.EMP.FINAL:


FD EFINAL
01 EMP-REC.
05 EID PIC 9(9)
05 ENAME PIC X(22)
05 ECODE PIC 9(1)
05 E-MARITAL-STATUS PIC X(1)
05 ESALARY PIC 9(5)
05 EDEPT PIC 9(2)
Section2:
Rahul must create KSDS VSAM dataset – IDC006.EMPINFO.FILE and the valid records from
IDC006.EMP.FINAL must be copied to KSDS
The Structure of KSDS file –(Key length = 9, Offset = 0,
Max and Average Record Size = 40, Space Units = Tracks, CISZ = 512 and
Primary and Secondary Qty = 5 )
Record Layout:
FD EMPKSDS.
01 EMP-KSDS-REC.
05 EMP-ID-IN PIC 9(9).
05 EMP-DATA-IN PIC X(31).

CHOOSE

Question #1
Below are the two statement related to VSAM access mode:

1. To add records to VASAM file which is opened in output mode, use ACCESS mode as
Sequential along with the write statement to add records sequentially at the end of file.
2. To add record to VASAM file which is opened in output mode, use ACCESS mode as
Random or Dynamic along with the write statement. Here the records can be written in any
order.

ANS: 2 is Correct

Question #2
Which of the following is the correct Snippet code to validate EMP-ID field?

ANS: IF EMP-ID NOT NUMERIC


DISPLAY ’INCORRECT EMP ID’
END-IF.

Question #3
Select the most appropriate Field Control statement for VASAM KSDS file

ANS: FILE-CONTROL
SELECT EMPKSDS ASSIGN TO DD1
ORGANISATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS EMP-ID-IN
FILE STSTUS IS WS-FS1
Question #4
Which of the following is the correct Snippet code to validate EMP-NAME field?

ANS: IF EMP-NAME = SPACES


DISPLAY ‘NAME CANNOT BE BLANK’
END-IF.

Question #5
Which of the following is the correct Snippet code to validate DEPT Field?(Choose 2 correct snippet)

ANS: IF DEPT NOT = 10 AND NOT = 14 AND NOT=20


DISPLAY ‘INVALID DEPARTMENT’
ELSE
DISPLAY ‘VALID DEPARTMENT’
END-IF
&
ANS: EVALUATE DEPT
WHEN 10
WHEN 14
WHEN 20
DISPLAY ‘VALID DEPARTMENT’
WHEN OTHER
DISPLAY ‘INVALID DEPARTMENT’
END-EVALUATE

Question #6
Select the correct option to define VSAM KSDS cluster. Choose the Correct 2 options

ANS: //SYSIN DD *
DEFINE CLUSTER (NAME(IDC006.EMINFO.FILE) –
TRACKS(5 5) -
VOLUMES(USER01) -
CONTROLINTERVALSIZE(512) -
KEYS(9 0) -
RECORDSIZE(40 40) -
INDEXED) -
DATA (NAME(IDC006.EMPINFO.FILE.DATA))-
INDEX (NAME(IDC006.EMPINFO.FILE.INDEX))
/*
&
ANS: //SYSIN DD *
CREATE CLUSTER (NAME(IDC006.EMPINFO.FILE) -
TRACKS(5 5) -
VOLUMES(USER01) -
CONTROLINTERVALSIZE(512) -
KEYS(9 0) -
INDEXED -
RECORDSIZE(40 40)) -
DATA (NAME(IDC006.EMPINFO.FILE.DATA))-
INDEX (NAME(IDC006.EMPINFO.FILE.INDEX))
/*

Question #7
Rahul has decided to copy record from PS to VSAM KSDS File using IDCAMS utility. Select the most
appropriate option.

ANS://IDC006J JOB NOTIFY=&SYSUID


//STEP01 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//DD1 DD DSN=IDC006.EMPFINAL.DISP=SHR
//DD2 DD DSN=IDC006.EMPINFO.FIELD.DISP=OLD
//SYSIN DD *
REPRO.
INFILE(DD1).
OUTFILE(DD2)
/*

Question #8
Assume EMPKSDS VSAM file has 100 records.
Select the correct code to read last 50 records from the EMPKSDS VSAM file in dynamic mode
By accepting the key. Choose the most appropriate option.
ANS: C000-PROCESS-PARA.
ACCEPT EMP-ID-IN.
START EMPKSDS KEY IS EQUAL TO EMP-ID-IN.
IF WS-FS1 = 00 THEN
PERFORM E000-READ-FILE UNTIL WS EDF= ‘Y’
ELSE
DISPLAY ‘THE STATUS OF FILE IS’ WS-FS1
END-IF
E000-READ-FILE
READ EMPKSDS NEXT RECORD
AT END
MOVE ‘Y’ TO WS-EOF
NOT AT END
PERFORM F000-PROCESS-PARA
END-READ
Question #9
Select the correct snippet to delete record from EMPKSDS VSAM file.

ANS: DELETE-PARA.
MOVE 990009900 TO EMP-ID-IN
READ EMPKSDS
INVALID KEY
PERFORM ERROR-ROUTINE
NOT INVALID KEY
DELETE EMP-KSDS-REC
END-READ.

Question #10
Which of the following is the correct Snippet code to validate SALARY field?
Select two correct options.

ANS: EVALUATE SALARY


WHEN 15000 THRU 25000
PERFORM PROCESS-PARA
WHEN OTHER
DISPLAY “INCORRECT SALARY”
END-EVALUATE

&

ANS: IF SALARY >= 15000 AND SALARY <=25000


PERFORM PROCESS-PARA
ELSE
DISPLAY “INCORRECT SALARY”
END-IF.

*************************COMPLETED***********************************
Scenario-2 (DAVID)
Section 1

Question # 1

David is working on Mainframe migration project and below are the requirement details.

File details:

File name structure: <MFID> CUSTOMER.DATA

File structure:

Field name CNO CNAME CADD CBAL CDOB


Data type of X(5) A(20) X(20) 9(8) COMP-3 X(8) Format
the field DDMMYYYY

CDOB format: DDMMYYYY

The file (<MFID>.CUSTOMER.DATA) has 20 records

Requirements:

Table needs to be created as per the file structure and data types
Table name: TBCUST

Program needs to be developed as per the below instructions


Read the data from sequential file(<MFID> CUSTOMER DATA) and
them into DB2 table as per the below conditions

· Check CNO, CNAME, CBAL fields are blank or not if any field in blank, then don't insert the record
into table
· If CADD field is blank, then insert NULL value into corresponding column

CHOOSE

Question #1
DCLGEN copybook is part of ________ SECTION? Choose the best option
ANS: WORKING-STORAGE

Question #2
What in the record length David have to mention during MFID CUSTOMER DATA file creation?
Choose the best option
ANS: 58
Question # 3
What is valid programming logic to process at the records from sequential file as per the
requirement
ANS: Write a loop to read all the record until file status is equal to 10

Question #4
Assume that the client asked David to create a table with Primary key(TCNO). In this scenario, how
to create unique index after creating table with Primary key?
ANS: CREATE UNIQUE INDEX IX_TECUST ON TBCUST(TCNO);
Question #5
How do you declare record structure in DATA DIVISION as per the requirement if you are the
developer?
ANS: DATA DIVISION.
FILE SECTION
FD CUSTFILE.
01 FS-CUSTREC.
05 FS-CNO PIC X(5).
05 FS-CNAME PIC A(20).
05 FS-CADD PIC X(20).
05 FS-CBAL PIC 9(8) COMP-3.
05 FS-CDOB PIC X(8).

Question #6
What is valid table structure as per the requirement?
ANS: CREATE TABLE TBCUST(
TCNO CHAR(5),
TCNAME CHAR(20),
TCADD CHAR(20),
TCBAL DECIMAL(8),
TCDOB DATE ) IN DATABASENAME TABLESPACENAME;

Question # 7
Choose appropriate COBOL logic to check FS-CNO, FS-CNAME fie fields are blanks or not?
ANS: IF FS-CNO =’ ‘
IF FS-CNAME =’ ‘
DISPLAY ‘CUSTOMER NUMBER & NAME FIELDS ARE BLANK’
ELSE
DISPLAY ‘CUSTOMER NAME IS NOT BLANK’
END-IF
ELSE
DISPLAY ‘CUSTOMER NUMBER IS NOT BLANK.
END-IF.
Question #8
How do you handle Nut indicator in COBOL program when you are moving sequential Ble to 082
table if CADD feld is blank in sequential file?
ANS: Declare WS-ADD-NULL variable in working storage section with S9(4)
Type
Move-1 to WS-ADO-NULLI CADD is blank
Move 0 to WS-ADD-NULL if CADD is not blank
Mention WS-ADD-NULL field in insert command

Question #9
What is the vald SQL command to insert the data into TOCUST table?
Assume following details:
Column names: TCNO,TCNAME,TCADO TCBAL,TCDOB
Host variables for the mentioned columns HV-TCNO, HV-TCNAME,HV-TCADD,HV-
TCBAL,HV-TCDOB
Indicator Variable for the column TCADD is IV-TCADO
Insert NULL value for the column TCADD.
ANS: EXEC SOL
INSERT INTO TBCUST
VALUE(:HV-TCNAME,:HV-TCADD:IV-TCADD,:HV-TCBAL
END-EXEC

Question #10
How do you define the file in environment division as per the given business requirement?
ANS: ENVIRONMENT DIVISION
INPUT-OUTPUT SECTION
FILE-CONTROL
SELECT CUSTFILE ASSIGN TO DD1
ORGAN7IZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL
FILE STATUS IS STATUS-VARIABLE

*************************COMPLETED***********************************
Scenario-3 (BILLING)

Section 1

Question # 1

Display the BILL in the following format along with the details of usage as follows:
*********************************************************************
ABC BROADBAND SERVICES CUSTOMER DETAILS:
*********************************************************************
CUSTOMER DETAILS:

CUSTOMER ID: <CUSTOMERID>


CUSTOMER NAME: <CUSTOMERNAME>
PHONE NUMBER: <PHONENUMBER>
*********************************************************************
PLAN DETAILS:
PLAN NAME: <PLANNAME>

TOTAL USAGE: <TOTALUSAGE>


*********************************************************************
TOTAL AMOUNT PAYABLE: <BILLAMOUNT>

Validation:

1. If CUSTOMERID is not numeric, display "CUSTOMER ID MUST BE NUMERIC".

2. The CUSTOMERID must be existing in VSAM file. Else display an error message "CUSTOMER DOES
NOT EXISTS" 3. If the total usage is zero display "CUSTOMER CANNOT BE BILLED FOR THE GIVEN
DURATION" and end the program.

Where Plan name can be “Home-Deluxe" or “Corporate-plan"


The details of usage of a customer are stored in below table USAGE
Column Name Datatype Constraint
USAGEID NUMERIC (5) NOT NULL PRIMARY KEY
CUSTID NUMERIC (6) NOT NULL
USAGEDATE DATE NOT NULL
USAGEINGB NUMERIC (5,3) NOT NULL

Joe is developing a batch program which will perform the following business logic:

1.Accept the CUSTOMER ID, FROM-DATE and TO-DATE of bill generation from the user
2. Fetch the details of the Customer from the VSAM file, corresponding to the accepted
CUSTOMERID

3. Compute the TOTALUSAGE in GB for the accepted CUSTOMERID within the duration of FROM-
DATE and TO-DATE (inclusive of both dates)

4. If the total usage is not zero, calculate the total BILLAMOUNT payable using the following
specification.

ABC Broadband services provide services at the rate


a. Home-Deluxe: Rs. 0.15 per MB.
b. Corporate-Plan: Rs. 0.20 per MB.

(1 GB = 1024 MB)

CHOOSE

Question #1
Choose the right host variable for the column USAGEINGB?
ANS: S9(02)V9(03) COMP-3

Question #2
How Joe will implement the second validation written in the scenario in his program? Choose the
best right approach
ANS: He reads all the records from VSAM ksds file sequentially and compare the data from the file
with accepted customer id

Question # 3
Joe is going to create VSAM KSDS file using ISPF 3.2 option to store customer details. Can you
suggest appropriate file attributes for creating VSAM KSDS file?
ANS: Record Size Average :56
Record Size Maximum : 56
Key Length: :6
Offset :0

Question # 4
How Joe will implement the validation-1(CUSTOMER ID MUST BE NUMERIC) in the Cobol code?
ANS: Using Class condition

Question # 5
Choose the right statements written in file control para of cobol program for the VSAM KSDS file
ANS: SELECT CUST ASSIGN TO DD1
ORGANIZATION IS INDEXED
ACCESS MODE IS SEQUENTIAL
RECORD KEY IS FS-CUST-ID
FILE STATUS IS WS-FS1.
Question # 6
Choose the 2 right approach for calculating total bill amount as per the plan from the total usage
Name of the plan is stored in a data name WS-PNAME
Total bill amount will be stored in a data name WS-COST

ANS: EVALUATE WS-PNAME


WHEN "HOME-DELUXE”
COMPUTE WS-COST WS-TOTAL 0.15 1024
WHEN "CORPORATE-PLAN"
COMPUTE WS-COST = WS-TOTAL 0.20 1024
END-EVALUTE.
&
ANS: EVALUATE TRUE
WHEN WS-PNAME = "HOME-DELUXE”
COMPUTE WS-COST WS-TOTAL *0.15* 1024
WHEN WS-PNAME="CORPORATE-PLAN"
COMPUTE WS-COST WS-TOTAL* 020* 102
END-EVALUATE.

Question # 7
Joe would like to add below sample data in USAGE table using SPUFI USAGEID: 12000 CUSTID:
112233 USAGEDATE: 12th May 2020 USAGEINGB: 12.123

ANS: INSERT INTO USAGE VALUES(12000, 112233, ‘2020-05-12’ 12 123);

Question # 8
Joe created table USAGE successfully. But he could not insert data into the table. His insert scripts
are failed with -540 sqlcode.
How to resolve above issue?

ANS: By creating a unique index using below query CREATE UNIQUE INDEX IDIDX ON
USAGE(USAGEID)

Question # 9
How Joe will calculate the TOTALUSAGE as per the business logic given in the scenario? Choose 2
right approach.

ANS: By coding following singleton SELECT query

EXEC SQL
SELECT SUM(USAGEINGB) FROM USAGE
WHERE CUSTID=HV-CUSTID AND USAGEDATE BETWEEN
:WS-FROM-DATE AND :WS-TO-DATE
END-EXEC.
&
ANS: By declaring the following cursor

EXEC SQL
DECLARE CURSOR C1 WITH HOLD FOR
SELECT USAGEINGB FROM
USAGE WHERE CUSTID=:HV-CUSTID
AND USAGEDATE BETWEEN :WS-FROM-DATE AND :WS-TO-DATE
END-EXEC.

Question # 10
Choose the right table script for the table mentioned in the scenario to store usage details of
customer. Choose 2 right choice

ANS: CREATE TABLE USAGE(USAGEID NUMERIC(5) NOT NULL PRIMARY KEY,


CUSTID NUMERIC(6) NOT NULL,
USAGEDATE DATE NOT NULL,
USAGEINGB NUMERIC(5,3) NOT NULL)
IN DBNAME TSNAME
&

ANS: CREATE TABLE USAGE USAGEID NUMERIC(5) NOT NULL,


CUSTID NUMERIC(6) NOT NULL,
USAGEDATE DATE NOT NULL,
USAGEINGB NUMERIC(5,3) NOT NULL, ,
PRIMARY KEY(USAGEID))
IN DBNAME TSNAME;

*************************COMPLETED***********************************
Scenario-4 (JOHN)
John is a mainframe developer who is coding a batch program for the below requirements to
fetch the details of books sold in normal price at xyz pvt ltd.

The DB2 table "BOOK_MASTER" consists of below attributes

Attributes Datatype Constraints


BOOK_NO INTEGER PRIMARY KEY
BOOK_NAME VARCHAR(50) NOT NULL
AUTHOR VARCHAR(50) NOT NULL

Below records are added to the BOOK MASTER table

10001 The mortals of meluha Amish


10002 The secret of the nagas Amish
10003 #girl boss Sophia Amoruso
10004 Grandma's bag of stories Sudha Murtty
10005 The Blue umbrella Ruskin bond

The DB2 table BOOK SALES consists of below attributes

Attributes Datatype Constraint


SALE_ID CHAR(5) PRIMARY KEY
BOOK_NO INTEGER NOT NULL

FOREIGN KEY REFERENCE


BOOK
NO OF COPIES INTEGER NOT NULL
SALE STATUS CHAR(1) NOT NULL

N- NORMAL PRICE R-

REDUCED PRICE

F- Free
Below records are added to the BOOK_SALES table

S 1001 10002 4 N
S 1002 10001 2 N
S 1003 10002 2 N
S 1004 10005 4 R
S 1005 10005 2 R
S 1006 10002 2 N
S 1007 10003 1 F
S 1008 10004 1 R

The batch program to be coded by John must perform the following

1. Accept book number via SYSIN

2. Check whether the accepted book number is present in the BOOK MASTER table. If not
display "BOOK details not present in the records".

3. Find the total number of copies of the same book sold in 'normal' price, display "THIS
BOOK HAS NOT BEEN SOLD ON NORMAL PRICE"

4. Display the details in the given format in SPOOL

5. If accepted book number is blank(spaces), display the details of all the books sold in
normal price.

Report Format:

**********************************************************************
BOOK SALE REPORT

**********************************************************************
BOOK NUMBER : <book number>

BOOK NAME. : <book name>

AUTHOR. : <author name>

**********************************************************************
NO OF COPIES SOLD IN NORMAL PRICE : <no of copies>

*********************************************************************
Question # 1
Choose the right host variable for the column BOOK_NAME. If the host variable prefix is BK
Choose the most appropriate option

Ans :
01 BK-BOOK-NAME
49 BK-BOOK-NAME-LEN PIC 59(4) COMP
49 BK-BOOK-NAME-TEXT PIC X(50)

Question # 2
What is the output generated for input Book number 10005 as per given table data in scenario?

Ans : The message "THIS BOOK HAS NOT BEEN SOLD ON NORMAL PRICE" will be displayed in
SPOOL
Question # 3
What is the most variable PICTURE clause of the table column BOOK_NO?

Ans : S9(9) COMP


Question # 4
What is the pre-requisite for the below insert to be successful?
INSERT INTO BOOK_SALES VALUES ('S1001',10002,4,'N'),
Choose the most inappropriate option

Ans : No pre-requisite. Record will be successfully added to the sales table


Question # 5
Which of the following statement is/are true. While using cursor for fetching all the books
details sold in normal price? Choose 2 correct options

Ans :
* Cursor must be declared in working storage section or procedure division as first step
* One FETCH statement is enough to display all the book details
Question # 6
Display the number of copies sold without leading zeroes. What is the best approach? Provided,
SL-NO-OF-COPIES is the host variable used for the table column NO_OF_COPIES.
Ans :
Declare below dataname in the Working Storage Section,
01 COPIES-ED PIC Z(2)9(7),
Before displaying, do the below move,
MOVE SL-NO-OF-COPIES TO COPIES-ED
DISPLAY COPIES-ED.

Question # 7
Choose the right statements that identify SALE_ID as primary key and BOOK_ID as foreign key
in the BOOK_SALES table, such that subsequent inserts in the table will be successful.
Ans :
CREATE TABLE BOOK_SALES (
SALE_ID CHAR(5) NOT NULL PRIMARY KEY,
BOOK_NO INTEGER NOT NULL REFERENCES BOOK_MASTER(BOOK_NO),
NO_OF_COPIES INTEGER NOT NULL
SALE_STATUS CHAR(1) NOT NULL) IN DBNAME,TSNAME.

CREATE UNIQUE INDEX SALEIDX ON BOOK_SALES(SALE_ID).

Question # 9
Check whether the accepted Book Number is present in the BOOK_MASTER table. If not, display
'BOOK DETAILS NOT PRESENT IN THE RECORDS'

Choose 2 right approach to implement the validation.


Ans :
EXEC-SQL
SELECT COUNT(BOOK_NO)
INTO WS-COUNT
FROM BOOK_MASTER
WHERE BOOK_NO = BK-BOOK-NO
END-EXEC.
EVALUATE SQLCODE
WHEN 0
IF WS-COUNT = 1
PERFORM PROCESS-PARA!
ELSE IF WS-COUNT = 0
DISPLAY 'BOOK DETAILS NOT PRESENT IN THE RECORDS'
END-IF
END-IF
WHEN OTHER
PERFORM ERROR-PARA
END EVALUATE.

&

EXEC-SQL
SELECT COUNT(BOOK_NO)
INTO WS-COUNT
FROM BOOK_MASTER
WHERE BOOK_NO = BK-BOOK-END-EXEC.

EVALUATE SQLCODE
WHEN 0
PERFORM PROCESS-PARA!
WHEN +100
DISPLAY 'BOOK DETAILS NOT PRESENT IN THE RECORDS'
WHEN OTHER
PERFORM ERROR-PARA
END-EVALUATE.

Question # 10
What is the correct cursor declaration to fetch the details of books sold in normal price, if the
input Book number is blank/spaces?

Ans :
EXEC SQL
DECLARE C1 CURSOR FOR
SELECT BOOK_NO,BOOK_NAME,AUTHOR,SUM(NO_OF_COPIES)
FROM BOOK_MASTER
GROUP BY BOOK_NO,BOOK_NAME,AUTHOR
HAVING SALE_STATUS ='N'

END-EXEC.

*******************************COMPLETED*************************************

You might also like