Friday, July 17, 2009

DB2 - Interview Questions with Answers

1) How would you find out the total number of rows in a table? ?
Use SELECT COUNT(*) ...

2) How do you eliminate duplicate values in SELECT? ?
Use SELECT DISTINCT ...

3) How do you select a row using indexes? ?
Specify the indexed columns in the WHERE clause.

4) What are aggregate functions?
Bulit-in mathematical functions for use in SELECT clause.

5) How do you find the maximum value in a column? ?
Use SELECT MAX(...

6) Can you use MAX on a CHAR column?
YES.

7) My SQL statement SELECT AVG(SALARY) FROM EMP yields inaccurate results. Why?
Because SALARY is not declared to have NULLs and the employees for whom the salary is not known are also counted.

8) How do you retrieve the first 5 characters of FIRSTNAME column of EMP table?
SELECT SUBSTR(FIRSTNAME,1,5) FROM EMP;

9) How do you concatenate the FIRSTNAME and LASTNAME from EMP table to give a complete name?
SELECT FIRSTNAME || ? ? || LASTNAME FROM EMP;

10) What is the use of VALUE function?
1. Avoid -ve SQLCODEs by handling nulls and zeroes in computations
2. Substitute a numeric value for any nulls used in computation

11) What is UNION,UNION ALL? ?
UNION : eliminates duplicates
UNION ALL: retains duplicates
Both these are used to combine the results of different SELECT statements.
Suppose I have five SQL SELECT statements connected by UNION/UNION ALL, how many times should I specify UNION to eliminate the duplicate rows? -
Once.

12) What is the restriction on using UNION in embedded SQL?
It has to be in a CURSOR.

13) In the WHERE clause what is BETWEEN and IN? ?
BETWEEN supplies a range of values while IN supplies a list of values.

14) Is BETWEEN inclusive of the range values specified? ?
Yes.

15) What is 'LIKE' used for in WHERE clause? What are the wildcard characters? ?
LIKE is used for partial string matches. ?%? ( for a string of any character ) and ?_? (for any single character ) are the two wild card characters.

16) When do you use a LIKE statement?
To do partial search e.g. to search employee by name, you need not specify the complete name; using LIKE, you can search for partial string matches.

17) What is the meaning of underscore ( ?_? ) in the LIKE statement? ?
Match for any single character.

18) What do you accomplish by GROUP BY ... HAVING clause? ?
GROUP BY partitions the selected rows on the distinct values of the column on which you group by.
HAVING selects GROUPs which match the criteria specified

19) Consider the employee table with column PROJECT nullable. How can you get a list of employees who are not assigned to any project?
SELECT EMPNO
FROM EMP
WHERE PROJECT IS NULL;

20) What is the result of this query if no rows are selected:
SELECT SUM(SALARY)
FROM EMP
WHERE QUAL=?MSC?;
NULL

21) Why SELECT * is not preferred in embedded SQL programs?
For three reasons:
If the table structure is changed ( a field is added ), the program will have to be modified
Program might retrieve the columns which it might not use, leading on I/O over head.
The chance of an index only scan is lost.
What are correlated subqueries? -
A subquery in which the inner ( nested ) query refers back to the table in the outer query. Correlated subqueries must be evaluated for each qualified row of the outer query that is referred to.

22) What are the issues related with correlated subqueries? ?
???

23) What is a cursor? why should it be used? ?
Cursor is a programming device that allows the SELECT to find a set of rows but return them one at a time.
Cursor should be used because the host language can deal with only one row at a time.

24) How would you retrieve rows from a DB2 table in embedded SQL? ?
Either by using the single row SELECT statements, or by using the CURSOR.
Apart from cursor, what other ways are available to you to retrieve a row from a table in embedded SQL? -
Single row SELECTs.

25) Where would you specify the DECLARE CURSOR statement? ?
See answer to next question.

26) How do you specify and use a cursor in a COBOL program? ?
Use DECLARE CURSOR statement either in working storage or in procedure division(before open cursor), to specify the SELECT statement. Then use OPEN, FETCH rows in a loop and finally CLOSE.

27) What happens when you say OPEN CURSOR?
If there is an ORDER BY clause, rows are fetched, sorted and made available for the FETCH statement. Other wise simply the cursor is placed on the first row.

28) Is DECLARE CURSOR executable?
No.

29) Can you have more than one cursor open at any one time in a program ? ?
Yes.

30) When you COMMIT, is the cursor closed?
Yes.

31) How do you leave the cursor open after issuing a COMMIT? ( for DB2 2.3 or above only )
Use WITH HOLD option in DECLARE CURSOR statement. But, it has not effect in psuedo-conversational CICS programs.

32) Give the COBOL definition of a VARCHAR field.
A VARCHAR column REMARKS would be defined as follows:
...
10 REMARKS.
49 REMARKS-LEN PIC S9(4) USAGE COMP.
49 REMARKS-TEXT PIC X(1920).

33) What is the physical storage length of each of the following DB2 data types:
DATE, TIME, TIMESTAMP?
DATE: 4bytes
TIME: 3bytes
TIMESTAMP: 10bytes

34) What is the COBOL picture clause of the following DB2 data types:
DATE, TIME, TIMESTAMP?
DATE: PIC X(10)
TIME : PIC X(08)
TIMESTAMP: PIC X(26)

35) What is the COBOL picture clause for a DB2 column defined as DECIMAL(11,2)? -
PIC S9(9)V99 COMP-3.

Note: In DECIMAL(11,2), 11 indicates the size of the data type and 2 indicates the precision.
36) What is DCLGEN ? -

DeCLarations GENerator: used to create the host language copy books for the table definitions. Also creates the DECLARE table.

37) What are the contents of a DCLGEN? -
1. EXEC SQL DECLARE TABLE statement which gives the layout of the table/view in terms of DB2 datatypes.
2. A host language copy book that gives the host variable definitions for the column names.

38) Is it mandatory to use DCLGEN? If not, why would you use it at all? -
It is not mandatory to use DCLGEN.
Using DCLGEN, helps detect wrongly spelt column names etc. during the pre-compile stage itself ( because of the DECLARE TABLE ). DCLGEN being a tool, would generate accurate host variable definitions for the table reducing chances of error.

39) Is DECLARE TABLE in DCLGEN necessary? Why it used?
It not necessary to have DECLARE TABLE statement in DCLGEN. This is used by the pre-compiler to validate the table-name, view-name, column name etc., during pre-compile.

40) Will precompile of an DB2-COBOL program bomb, if DB2 is down?
No. Because the precompiler does not refer to the DB2 catalogue tables.

41) How is a typical DB2 batch pgm executed ?
1. Use DSN utility to run a DB2 batch program from native TSO. An example is shown:
DSN SYSTEM(DSP3)
RUN PROGRAM(EDD470BD) PLAN(EDD470BD) LIB('ED 01T.OBJ.LOADLIB')
END
2. Use IKJEFT01 utility program to run the above DSN command in a JCL.
Assuming that a site?s standard is that pgm name = plan name, what is the easiest way to find out which pgms are affected by change in a table?s structure ?
Query the catalogue tables SYSPLANDEP and SYSPACKDEP.

42) Name some fields from SQLCA.
SQLCODE, SQLERRM, SQLERRD

43) How can you quickly find out the # of rows updated after an update statement?
Check the value stored in SQLERRD(3).

44) What is EXPLAIN? ?
EXPLAIN is used to display the access path as determined by the optimizer for a SQL statement. It can be used in SPUFI (for single SQL statement ) or in BIND step (for embedded SQL ).

45) What do you need to do before you do EXPLAIN?
Make sure that the PLAN_TABLE is created under the AUTHID.

46) Where is the output of EXPLAIN stored? ?
In userid.PLAN_TABLE

47) EXPLAIN has output with MATCHCOLS = 0. What does it mean? ?
a nonmatching index scan if ACCESSTYPE = I.

48) How do you do the EXPLAIN of a dynamic SQL statement?
1. Use SPUFI or QMF to EXPLAIN the dynamic SQL statement
2. Include EXPLAIN command in the embedded dynamic SQL statements

49) How do you simulate the EXPLAIN of an embedded SQL statement in SPUFI/QMF? Give an example with a host variable in WHERE clause.)
Use a question mark in place of a host variable ( or an unknown value ). e.g.
SELECT EMP_NAME
FROM EMP
WHERE EMP_SALARY > ?

50) What are the isolation levels possible ? ?
CS: Cursor Stability
RR: Repeatable Read

51) What is the difference between CS and RR isolation levels?
CS: Releases the lock on a page after use
RR: Retains all locks acquired till end of transaction

52) Where do you specify them ?
ISOLATION LEVEL is a parameter for the bind process.

53) When do you specify the isolation level? How?
During the BIND process. ISOLATION ( CS/RR )...
I use CS and update a page. Will the lock be released after I am done with that page?
No.

54) What are the various locking levels available?
PAGE, TABLE, TABLESPACE

55) How does DB2 determine what lock-size to use?
1. Based on the lock-size given while creating the tablespace
2. Programmer can direct the DB2 what lock-size to use
3. If lock-size ANY is specified, DB2 usually chooses a lock-size of PAGE

56) What are the disadvantages of PAGE level lock?
High resource utilization if large updates are to be done

57) What is lock escalation?
Promoting a PAGE lock-size to table or tablespace lock-size when a transaction has acquired more locks than specified in NUMLKTS. Locks should be taken on objects in single tablespace for escalation to occur.

58) What are the various locks available?
SHARE, EXCLUSIVE, UPDATE

59) Can I use LOCK TABLE on a view?
No. To lock a view, take lock on the underlying tables.

60) What is ALTER ? ?
SQL command used to change the definition of DB2 objects.

61) What is a DBRM, PLAN ?
DBRM: DataBase Request Module, has the SQL statements extracted from the host language program by the pre-compiler.
PLAN: A result of the BIND process. It has the executable code for the SQL statements in the DBRM.

62) What is ACQUIRE/RELEASE in BIND?
Determine the point at which DB2 acquires or releases locks against table and tablespaces, including intent locks.

63) What else is there in the PLAN apart from the access path? ?
PLAN has the executable code for the SQL statements in the host program

64) What happens to the PLAN if index used by it is dropped?
Plan is marked as invalid. The next time the plan is accessed, it is rebound.

65) What are PACKAGES ? ?
They contain executable code for SQL statements for one DBRM.

66) What are the advantages of using a PACKAGE?
1. Avoid having to bind a large number of DBRM members into a plan
2. Avoid cost of a large bind
3. Avoid the entire transaction being unavailable during bind and automatic rebind of a plan
4. Minimize fallback complexities if changes result in an error.
67) What is a collection?
a user defined name that is the anchor for packages. It has not physical existence. Main usage is to group packages.
In SPUFI suppose you want to select max. of 1000 rows , but the select returns only 200 rows.

68) What are the 2 sqlcodes that are returned? ?
100 ( for successful completion of the query ), 0 (for successful COMMIT if AUTOCOMMIT is set to Yes).

69) How would you print the output of an SQL statement from SPUFI? ?
Print the output dataset.

70) Lot of updates have been done on a table due to which indexes have gone haywire. What do you do? ?
Looks like index page split has occurred. DO a REORG of the indexes.

71) What is dynamic SQL? ?
Dynamic SQL is a SQL statement created at program execution time.

72) When is the access path determined for dynamic SQL? ?
At run time, when the PREPARE statement is issued.

73) Suppose I have a program which uses a dynamic SQL and it has been performing well till now. Off late, I find that the performance has deteriorated. What happened? ?
Probably RUN STATS is not done and the program is using a wrong index due to incorrect stats.
Probably RUNSTATS is done and optimizer has chosen a wrong access path based on the latest statistics.

74) How does DB2 store NULL physically?
as an extra-byte prefix to the column value. physically, the nul prefix is Hex ?00? if the value is present and Hex ?FF? if it is not.

75) How do you retrieve the data from a nullable column? ?
Use null indicators. Syntax ... INTO :HOSTVAR:NULLIND

76) What is the picture clause of the null indicator variable? ?
S9(4) COMP.

77) What does it mean if the null indicator has -1, 0, -2? ?
-1 : the field is null
0 : the field is not null
-2 : the field value is truncated

78) How do you insert a record with a nullable column?
To insert a NULL, move -1 to the null indicator
To insert a valid value, move 0 to the null indicator

79) What is RUNSTATS? ?
A DB2 utility used to collect statistics about the data values in tables which can be used by the optimizer to decide the access path. It also collects statistics used for space management. These statistics are stored in DB2 catalog tables.

80) When will you chose to run RUNSTATS?
After a load, or after mass updates, inserts, deletes, or after REORG.

81) Give some example of statistics collected during RUNSTATS?
# of rows in the table
Percent of rows in clustering sequence
# of distinct values of indexed column
# of rows moved to a nearby/farway page due to row length increase

82) What is REORG? When is it used?
REORG reorganizes data on physical storage to reclutser rows, positioning overflowed rows in their proper sequence, to reclaim space, to restore free space. It is used after heavy updates, inserts and delete activity and after segments of a segmented tablespace have become fragmented.

83) What is IMAGECOPY ? ?
It is full backup of a DB2 table which can be used in recovery.

84) When do you use the IMAGECOPY? ?
To take routine backup of tables
After a LOAD with LOG NO
After REORG with LOG NO

85) What is COPY PENDING status?
A state in which, an image copy on a table needs to be taken, In this status, the table is available only for queries. You cannot update this table. To remove the COPY PENDING status, you take an image copy or use REPAIR utility.

86) What is CHECK PENDING ?
When a table is LOADed with ENFORCE NO option, then the table is left in CHECK PENDING status. It means that the LOAD utility did not perform constraint checking.

87) What is QUIESCE?
A QUIESCE flushes all DB2 buffers on to the disk. This gives a correct snapshot of the database and should be used before and after any IMAGECOPY to maintain consistency.

88) What is a clustering index ? ?
Causes the data rows to be stored in the order specified in the index. A mandatory index defined on a partitioned table space.

89) How many clustering indexes can be defined for a table?
Only one.

90) What is the difference between primary key & unique index ?
Primary : a relational database constraint. Primary key consists of one or more columns that uniquely identify a row in the table. For a normalized relation, there is one designated primary key.
Unique index: a physical object that stores only unique values. There can be one or more unique indexes on a table.

91) What is sqlcode -922 ?
Authorization failure

92) What is sqlcode -811?
SELECT statement has resulted in retrieval of more than one row.

93) What does the sqlcode of -818 pertain to? ?
This is generated when the consistency tokens in the DBRM and the load module are different.

94) Are views updateable ?
Not all of them. Some views are updateable e.g. single table view with all the fields or mandatory fields. Examples of non-updateable views are views which are joins, views that contain aggregate functions(such as MIN), and views that have GROUP BY clause.

96) If I have a view which is a join of two or more tables, can this view be updateable? ?
No.

97) What are the 4 environments which can access DB2 ?
TSO, CICS, IMS and BATCH

98) What is an inner join, and an outer join ?
Inner Join: combine information from two or more tables by comparing all values that meet the search criteria in the designated column or columns of on e table with all the clause in corresponding columns of the other table or tables. This kind of join which involve a match in both columns are called inner joins.
Outer join is one in which you want both matching and non matching rows to be returned. DB2 has no specific operator for outer joins, it can be simulated by combining a join and a correlated sub query with a UNION.

99) What is FREEPAGE and PCTFREE in TABLESPACE creation?
PCTFREE: percentage of each page to be left free
FREEPAGE: Number of pages to be loaded with data between each free page

100) What are simple, segmented and partitioned table spaces ?
Simple Tablespace:
Can contain one or more tables
Rows from multiple tables can be interleaved on a page under the DBAs control and maintenance
Segmented Tablespace:
Can contain one or more tables
Tablespace is divided into segments of 4 to 64 pages in increments of 4 pages. Each segment is dedicated to single table. A table can occupy multiple segments
Partitioned Tablespace:
Can contain one table
Tablespace is divided into parts and each part is put in a separate VSAM dataset.

101) What is filter factor?
one divided by the number of distinct values of a column.

102) What is index cardinality? ?
The number of distinct values a column or columns contain.

103) What is a synonym ?
Synonym is an alternate name for a table or view used mainly to hide the leading qualifier of a table or view.. A synonym is accessible only by the creator.

104) What is the difference between SYNONYM and ALIAS?
SYNONYM: is dropped when the table or tablespace is dropped. Synonym is available only to the creator.
ALIAS: is retained even if table or tablespace is dropped. ALIAS can be created even if the table does not exist. It is used mainly in distributed environment to hide the location info from programs. Alias is a global object & is available to all.

105) What do you mean by NOT NULL WITH DEFAULT? When will you use it?
This column cannot have nulls and while insertion, if no value is supplied then it wil have zeroes, spaces or date/time depending on whether it is numeric, character or date/time.
Use it when you do not want to have nulls but at the same time cannot give values all the time you insert this row.

106) What do you mean by NOT NULL? When will you use it?
The column cannot have nulls. Use it for key fields.

107) When would you prefer to use VARCHAR?
When a column which contains long text, e.g. remarks, notes, may have in most cases less than 50% of the maximum length.

108) What are the disadvantages of using VARCHAR?
1. Can lead to high space utilization if most of the values are close to maximum.
2. Positioning of VARCHAR column has to be done carefully as it has performance implications.
3. Relocation of rows to different pages can lead to more I/Os on retrieval.

109) How do I create a table MANAGER ( EMP#, MANAGER) where MANAGER is a foreign key which references to EMP# in the same table? Give the exact DDL.
First CREATE MANAGER table with EMP# as the primary key. Then ALTER it to define the foreign key.
When is the authorization check on DB2 objects done - at BIND time or run time?
At run time.

110) What is auditing?
Recording SQL statements that access a table. Specified at table creation time or through alter.

Monday, July 13, 2009

Interview Questions - Cobol

COBOL & COBOL II

Q1) Name the divisions in a COBOL program ?.
A1) IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION, PROCEDURE DIVISION.

Q2) What are the different data types available in COBOL?
A2) Alpha-numeric (X), alphabetic (A) and numeric (9).

Q3) What does the INITIALIZE verb do? - GS
A3) Alphabetic, Alphanumeric fields & alphanumeric edited items are set to SPACES. Numeric, Numeric edited items set to ZERO. FILLER , OCCURS DEPENDING ON items left untouched.

Q4) What is 77 level used for ?
A4) Elementary level item. Cannot be subdivisions of other items (cannot be qualified), nor can they be subdivided themselves.

Q5) What is 88 level used for ?
A5) For condition names.

Q6) What is level 66 used for ?
A6) For RENAMES clause.

Q7) What does the IS NUMERIC clause establish ?
A7) IS NUMERIC can be used on alphanumeric items, signed numeric & packed decimal items and unsigned numeric & packed decimal items. IS NUMERIC returns TRUE if the item only consists of 0-9. However, if the item being tested is a signed item, then it may contain 0-9, + and - .

Q8) How do you define a table/array in COBOL?
A8) ARRAYS.
05 ARRAY1 PIC X(9) OCCURS 10 TIMES.
05 ARRAY2 PIC X(6) OCCURS 20 TIMES INDEXED BY WS-INDEX.

Q9) Can the OCCURS clause be at the 01 level?
A9) No.

Q10) What is the difference between index and subscript? - GS
A10) 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.

Q11) What is the difference between SEARCH and SEARCH ALL? - GS
A11) 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.

Q12) What should be the sorting order for SEARCH ALL? - GS
A12) 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).

Q13) What is binary search?
A13) Search on a sorted array. Compare the item to be searched with the item at the center. If it matches, fine else repeat the process with the left half or the right half depending on where the item lies.

Q14) My program has an array defined to have 10 items. Due to a bug, I find that even if the program access the
11th item in this array, the program does not abend. What is wrong with it?
A14) Must use compiler option SSRANGE if you want array bounds checking. Default is NOSSRANGE.

Q15) How do you sort in a COBOL program? Give sort file definition, sort statement syntax and meaning. - GS
A15) Syntax: SORT file-1 ON ASCENDING/DESCENDING KEY key.... USING file-2 GIVING file-3.

USING can be substituted by INPUT PROCEDURE IS para-1 THRU para-2
GIVING can be substituted by OUTPUT PROCEDURE IS para-1 THRU para-2.

file-1 is the sort (work) file and must be described using SD entry in FILE SECTION.
file-2 is the input file for the SORT and must be described using an FD entry in FILE SECTION and SELECT
clause in FILE CONTROL.
file-3 is the out file from the SORT and must be described using an FD entry in FILE SECTION and SELECT
clause in FILE CONTROL.
file-1, file-2 & file-3 should not be opened explicitly.

INPUT PROCEDURE is executed before the sort and records must be RELEASEd to the sort work file from the input procedure.
OUTPUT PROCEDURE is executed after all records have been sorted. Records from the sort work file must be RETURNed one at a time to the output procedure.

Q16) How do you define a sort file in JCL that runs the COBOL program?
A16) Use the SORTWK01, SORTWK02,..... dd names in the step. Number of sort datasets depends on the volume of data
being sorted, but a minimum of 3 is required.

Q17) What is the difference between performing a SECTION and a PARAGRAPH? - GS
A17) Performing a SECTION will cause all the paragraphs that are part of the section, to be performed.
Performing a PARAGRAPH will cause only that paragraph to be performed.

Q18) What is the use of EVALUATE statement? - GS
A18) Evaluate is like a case statement and can be used to replace nested Ifs. The difference between EVALUATE and
case is that no 'break' is required for EVALUATE i.e. control comes out of the EVALUATE as soon as one match is
made.

Q19) What are the different forms of EVALUATE statement?
A19)
EVALUATE EVALUATE SQLCODE ALSO FILE-STATUS
WHEN A=B AND C=D WHEN 100 ALSO '00'
imperative stmt imperative stmt
WHEN (D+X)/Y = 4 WHEN -305 ALSO '32'
imperative stmt imperative stmt
WHEN OTHER WHEN OTHER
imperative stmt imperative stmt
END-EVALUATE END-EVALUATE

EVALUATE SQLCODE ALSO A=B EVALUATE SQLCODE ALSO TRUE
WHEN 100 ALSO TRUE WHEN 100 ALSO A=B
imperative stmt imperative stmt
WHEN -305 ALSO FALSE WHEN -305 ALSO (A/C=4)
imperative stmt imperative stmt
END-EVALUATE END-EVALUATE

Q20) How do you come out of an EVALUATE statement? - GS
A20) After the execution of one of the when clauses, the control is automatically passed on to the next sentence after the
EVALUATE statement. There is no need of any extra code.

Q21) In an EVALUATE statement, can I give a complex condition on a when clause?
A21) Yes.

Q22) What is a scope terminator? Give examples.
A22) Scope terminator is used to mark the end of a verb e.g. EVALUATE, END-EVALUATE; IF, END-IF.

Q23) How do you do in-line PERFORM? - GS
A23) PERFORM ... ...

END-PERFORM

Q24) When would you use in-line perform?
A24) 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 Para name rather than in-line perform.

Q25) What is the difference between CONTINUE & NEXT SENTENCE ?
A25) They appear to be similar, that is, the control goes to the next sentence in the paragraph. But, Next Sentence would
take the control to the sentence after it finds a full stop (.). Check out by writing the following code example, one if
sentence followed by 3 display statements (sorry they appear one line here because of formatting restrictions) If 1 > 0
then next sentence end if display 'line 1' display 'line 2'. display 'line 3'. *** Note- there is a dot (.) only at the end of
the last 2 statements, see the effect by replacing Next Sentence with Continue ***

Q26) What does EXIT do ?
A26) Does nothing ! If used, must be the only sentence within a paragraph.

Q27) Can I redefine an X(100) field with a field of X(200)?
A27) Yes. Redefines just causes both fields to start at the same location. For example:

01 WS-TOP PIC X(1)
01 WS-TOP-RED REDEFINES WS-TOP PIC X(2).
If you MOVE '12' to WS-TOP-RED,
DISPLAY WS-TOP will show 1 while
DISPLAY WS-TOP-RED will show 12.

A28) Can I redefine an X(200) field with a field of X(100) ?
Q31)1 Yes.

Q31)2 What do you do to resolve SOC-7 error? - GS
Q31) Basically you need to correcting the offending data. Many times the reason for SOC7 is an un-initialized numeric item.
Examine that possibility first. Many installations provide you a dump for run time abend’s ( 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.

Q32) How is sign stored in Packed Decimal fields and Zoned Decimal fields?
Q32) Packed Decimal fields: Sign is stored as a hex value in the last nibble (4 bits ) of the storage.
Zoned Decimal fields: As a default, sign is over punched with the numeric value stored in the last bite.

Q33) How is sign stored in a comp-3 field? - GS
Q33) 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...

Q34) How is sign stored in a COMP field ? - GS
Q34) In the most significant bit. Bit is ON if -ve, OFF if +ve.

Q35) What is the difference between COMP & COMP-3 ?
Q35) COMP is a binary storage format while COMP-3 is packed decimal format.

Q36) What is COMP-1? COMP-2?
Q36) COMP-1 - Single precision floating point. Uses 4 bytes.
COMP-2 - Double precision floating point. Uses 8 bytes.

Q37) How do you define a variable of COMP-1? COMP-2?
Q37) No picture clause to be given. Example 01 WS-VAR USAGE COMP-1.

Q38) How many bytes does a S9(7) COMP-3 field occupy ?
Q38) Will take 4 bytes. Sign is stored as hex value in the last nibble. General formula is INT((n/2) + 1)), where n=7 in this
example.

Q39) How many bytes does a S9(7) SIGN TRAILING SEPARATE field occupy ?
Q39) Will occupy 8 bytes (one extra byte for sign).

Q40) How many bytes will a S9(8) COMP field occupy ?
Q40) 4 bytes.

Q41) What is the maximum value that can be stored in S9(8) COMP?
Q41) 99999999

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

Q43) What is the maximum size of a 01 level item in COBOL I? in COBOL II?
Q43) In COBOL II: 16777215

Q44) How do you reference the following file formats from COBOL programs:
Q44)
Fixed Block File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS F,
BLOCK CONTAINS 0 .
Fixed Unblocked - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS F,
do not use BLOCK CONTAINS
Variable Block File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS V, BLOCK
CONTAINS 0. Do not code the 4 bytes for record length in FD ie JCL rec length will be max rec length in pgm + 4
Variable Unblocked - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS V, do not use
BLOCK CONTAINS. Do not code 4 bytes for record length in FD ie JCL rec length will
be max rec length in pgm + 4.
ESDS VSAM file - Use ORGANISATION IS SEQUENTIAL.
KSDS VSAM file - Use ORGANISATION IS INDEXED, RECORD KEY IS, ALTERNATE RECORD KEY IS RRDS File - Use ORGANISATION IS RELATIVE, RELATIVE KEY IS
Printer File - Use ORGANISATION IS SEQUENTIAL. Use RECORDING MODE IS F, BLOCK
CONTAINS 0. (Use RECFM=FBA in JCL DCB).

Q45) What are different file OPEN modes available in COBOL?
Q45) Open for INPUT, OUTPUT, I-O, EXTEND.

Q46) What is the mode in which you will OPEN a file for writing? - GS
Q46) OUTPUT, EXTEND

Q47) In the JCL, how do you define the files referred to in a subroutine ?
Q47) Supply the DD cards just as you would for files referred to in the main program.

Q48) Can you REWRITE a record in an ESDS file? Can you DELETE a record from it?
Q48) Can rewrite (record length must be same), but not delete.

Q49) What is file status 92? - GS
Q49) Logic error. e.g., a file is opened for input and an attempt is made to write to it.

Q50) What is file status 39 ?
Q50) 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.

Q51) What is Static and Dynamic linking ?
Q51) In static linking, the called subroutine is link-edited into the calling program , while in dynamic linking, the subroutine & the main program will exist as separate load modules. You choose static/dynamic linking by choosing either the DYNAM or NODYNAM link edit option. (Even if you choose NODYNAM, a CALL identifier (as opposed to a CALL literal), will translate to a DYNAMIC call).A statically called subroutine will not be in its initial state the next time it is called unless you explicitly use INITIAL or you do a CANCEL. A dynamically called routine will always be in its initial state.


Q52) What is AMODE(24), AMODE(31), RMODE(24) and RMODE(ANY)? (applicable to only MVS/ESA
Enterprise Server).
Q52) These are compile/link edit options. Basically AMODE stands for Addressing mode and RMODE for Residency
mode.
AMODE(24) - 24 bit addressing;
AMODE(31) - 31 bit addressing
AMODE(ANY) - Either 24 bit or 31 bit addressing depending on RMODE.
RMODE(24) - Resides in virtual storage below 16 Meg line. Use this for 31 bit programs that call 24 bit programs.
(OS/VS Cobol pgms use 24 bit addresses only).
RMODE(ANY) - Can reside above or below 16 Meg line.

Q53) What compiler option would you use for dynamic linking?
Q53) DYNAM.

Q54) What is SSRANGE, NOSSRANGE ?
Q54) These are compiler options with respect to subscript out of range checking. NOSSRANGE is the default and if chosen,
no run time error will be flagged if your index or subscript goes out of the permissible range.

Q55) How do you set a return code to the JCL from a COBOL program?
Q55) Move a value to RETURN-CODE register. RETURN-CODE should not be declared in your program.

Q56) How can you submit a job from COBOL programs?
Q56) Write JCL cards to a dataset with //xxxxxxx SYSOUT= (A,INTRDR) where 'A' is output class, and dataset should be
opened for output in the program. Define a 80 byte record layout for the file.

Q57) What are the differences between OS VS COBOL and VS COBOL II?
Q57) OS/VS Cobol pgms can only run in 24 bit addressing mode, VS Cobol II pgms can run either in 24 bit or 31 bit
addressing modes.

I. Report writer is supported only in OS/VS Cobol.
II. USAGE IS POINTER is supported only in VS COBOL II.
III. Reference modification e.g.: WS-VAR(1:2) is supported only in VS COBOL II.
IV. EVALUATE is supported only in VS COBOL II.
V. Scope terminators are supported only in VS COBOL II.
VI. OS/VS Cobol follows ANSI 74 stds while VS COBOL II follows ANSI 85 stds.
VII. Under CICS Calls between VS COBOL II programs are supported.

Q58) What are the steps you go through while creating a COBOL program executable?
Q58) DB2 precompiler (if embedded SQL used), CICS translator (if CICS pgm), Cobol compiler, Link editor. If DB2
program, create plan by binding the DBRMs.

Q59) Can you call an OS VS COBOL pgm from a VS COBOL II pgm ?
Q59) In non-CICS environment, it is possible. In CICS, this is not possible.

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

Q61) What is an explicit scope terminator?
A61) A scope terminator brackets its preceding verb, e.g. IF .. END-IF, so that all statements between the verb and its scope terminator are grouped together. Other common COBOL II verbs are READ, PERFORM, EVALUATE, SEARCH and STRING.

Q62) What is an in line PERFORM? When would you use it? Anything else to say about it?
A62) 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.

Q63) What is the difference between NEXT SENTENCE and CONTINUE?
A63) NEXT SENTENCE gives control to the verb following the next period. CONTINUE gives control to the next verb after the explicit scope terminator. (This is not one of COBOL II's finer implementations). It's safest to use CONTINUE rather than NEXT SENTENCE in COBOL II.

Q64) What COBOL construct is the COBOL II EVALUATE meant to replace?
A64) EVALUATE can be used in place of the nested IF THEN ELSE statements.

Q65) What is the significance of 'above the line' and 'below the line'?
A65) Before IBM introduced MVS/XA architecture in the 1980's a program's virtual storage was limited to 16 megs. Programs compiled with a 24 bit mode can only address 16 Mb of space, as though they were kept under an imaginary storage line. With COBOL II a program compiled with a 31 bit mode can be 'above the 16 Mb line. (This 'below the line', 'above the line' imagery confuses most mainframe programmers, who tend to be a literal minded group.)

Q66) What was removed from COBOL in the COBOL II implementation?
A66) Partial list: REMARKS, NOMINAL KEY, PAGE-COUNTER, CURRENT-DAY, TIME-OF-DAY, STATE, FLOW, COUNT, EXAMINE, EXHIBIT, READY TRACE and RESET TRACE.

Q67) Explain call by context by comparing it to other calls.
A67) The parameters passed in a call by context are protected from modification by the called program. In a normal call they are able to be modified.

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

Q69) What is the difference between a subscript and an index in a table definition?
A69) A subscript is a working storage data definition item, typically a PIC (999) where a value must be moved to the subscript and then incremented or decrements by ADD TO and SUBTRACT FROM statements. An index is a register item that exists outside the program's working storage. You SET an index to a value and SET it UP BY value and DOWN BY value.

Q70) If you were passing a table via linkage, which is preferable - a subscript or an index?
A70) Wake up - you haven't been paying attention! It's not possible to pass an index via linkage. The index is not part of the calling programs working storage. Those of us who've made this mistake, appreciate the lesson more than others.

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

Q72) What is the difference between comp and comp-3 usage? Explain other COBOL usage’s.
A72) Comp is a binary usage, while comp-3 indicates packed decimal. The other common usage’s are binary and display. Display is the default.

Q73) When is a scope terminator mandatory?
A73) Scope terminators are mandatory for in-line PERFORMS and EVALUATE statements. For readability, it's recommended coding practice to always make scope terminators explicit.

Q74) In a COBOL II PERFORM statement, when is the conditional tested, before or after the perform execution?
A74) In COBOL II the optional clause WITH TEST BEFORE or WITH TEST AFTER can be added to all perform statements. By default the test is performed before the perform.

Q75) In an EVALUTE statement is the order of the WHEN clauses significant?
A75) Absolutely. Evaluation of the WHEN clauses proceeds from top to bottom and their sequence can determine results.

Q76) What is the default value(s) for an INITIALIZE and what keyword allows for an override of the default.
A76) INITIALIZE moves spaces to alphabetic fields and zeros to alphanumeric fields. The REPLACING option can be used to override these defaults.

Q77) What is SET TO TRUE all about, anyway?
A77) In COBOL II the 88 levels can be set rather than moving their associated values to the related data item. (Web note: This change is not one of COBOL II's better specifications.)

Q78) What is LENGTH in COBOL II?
A78) LENGTH acts like a special register to tell the length of a group or elementary item.

Q79) What is the difference between a binary search and a sequential search? What are the pertinent COBOL
commands?
A79) In a binary search the table element key values must be in ascending or descending sequence. The table is 'halved' to search for equal to, greater than or less than conditions until the element is found. In a sequential search the table is searched from top to bottom, so (ironically) the elements do not have to be in a specific sequence. The binary search is much faster for larger tables, while sequential works well with smaller ones. SEARCH ALL is used for binary searches; SEARCH for sequential.

Q80) What is the point of the REPLACING option of a copy statement?
A80) REPLACING allows for the same copy to be used more than once in the same code by changing the replace value.

Q81) What will happen if you code GO BACK instead of STOP RUN in a stand alone COBOL program i.e. a
program which is not calling any other program.
A81) The program will go in an infinite loop.

Q82) How can I tell if a module is being called DYNAMICALLY or STATICALLY?
A82) 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 (CALL

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

Q84) How may divisions are there in JCL-COBOL?
A84) Four

Q85) What is the purpose of Identification Division?
A85) Documentation.

Q86) What is the difference between PIC 9.99 and 9v99?
A86) 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.

Q87) what is Pic 9v99 Indicates?
A87) PICTURE 9v99 is a three position Numeric field with an implied or assumed decimal point after the first position; the v means an implied decimal point.

Q88) What guidelines should be followed to write a structured Cobol prg'm?
A88)
1) use 'evaluate' stmt for constructing cases.
2) use scope terminators for nesting.
3) use in line perform stmt for writing 'do ' constructions.
4) use test before and test after in the perform stmt for writing do-while constructions.

Q89) Read the following code. 01 ws-n pic 9(2) value zero. a-para move 5 to ws-n. perform b-para ws-n times. b-para.
move 10 to ws-n. how many times will b-para be executed ?
A89) 5 times only. it will not take the value 10 that is initialized in the loop.

Q90) What is the difference between SEARCH and SEARCH ALL? What is more efficient?
A90) SEARCH is a sequential search from the beginning of the table. SEARCH ALL is a binary search, continually dividing the table in two halves until a match is found. SEARCH ALL is more efficient for tables larger than 70 items.

Q91) What are some examples of command terminators?
A91) END-IF, END-EVALUATE

Q92) What care has to be taken to force program to execute above 16 Meg line?
A92) Make sure that link option is AMODE=31 and RMODE=ANY. Compile option should never have SIZE(MAX). BUFSIZE can be 2K, efficient enough.
Q93) How do you submit JCL via a Cobol program?
A93) Use a file //dd1 DD sysout=(*, intrdr)write your JCL to this file. Pl some on try this out.

Q94) How to execute a set of JCL statements from a COBOL program
A94) Using EXEC CICS SPOOL WRITE(var-name) END-EXEC command. var-name is a COBOL host structure containing JCL statements.

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

Q96) What is the difference between static call & Dynamic call
A96) In the case of Static call, the called program is a stand-alone program, it is an executable program. During run time we can call it in our called program. As about Dynamic call, the called program is not an executable program it can executed through the called program

Q97) What do you feel makes a good program?
A97) A program that follows a top down approach. It is also one that other programmers or users can follow logically and is easy to read and understand.

Q98) How do you code Cobol to access a parameter that has been defined in JCL? And do you code the PARM
parameter on the EXEC line in JCL?
A98)
1) using JCL with sysin. //sysin dd *here u code the parameters(value) to pass in to cobol program /* and in program
you use accept variable name(one accept will read one row)/.another way.
2) in jcl using parm statement ex: in exec statement parm='john','david' in cobol pgm u have to code linkage section in that for first value you code length variable and variable name say, abc pic x(4).it will take john inside to read next value u have to code another variable in the same way above mentioned.

Q99) Why do we code S9(4) comp. Inspite of knowing comp-3 will occupy less space.
A99) Here s9(4)comp is small integer ,so two words equal to 1 byte so totally it will occupy 2 bytes(4 words).here in s9(4) comp-3 as one word is equal to 1/2 byte.4 words equal to 2 bytes and sign will occupy 1/2 byte so totally it will occupy 3 bytes.

Q100) The maximum number of dimensions that an array can have in COBOL-85 is ----------- ?
A100) SEVEN in COBOL - 85 and THREE in COBOL - 84

Q101) How do you declare a host variable (in COBOL) for an attribute named Emp-Name of type VARCHAR(25) ?
A101)
01 EMP-GRP.
49 E-LEN PIC S9(4) COMP.
49 E-NAME PIC X(25).

Q102) What is Comm?
A102) COMM - HALF WORD BINARY

Q103) Differentiate COBOL and COBOL-II. (Most of our programs are written in COBOLII, so, it is good to know,
how, this is different from COBOL)
A103) The following features are available with VS COBOL II:
1. MVS/XA and MVS/ESA support The compiler and the object programs it produces can be run in either
24- or 31-bit addressing mode.
2. VM/XA and VM/ESA support The compiler and the object programs it produces can be run in either
24- or 31-bit addressing mode.
3. VSE/ESA support The compiler and the object programs it produces can be run under VSE/ESA.

Q104) What is PERFORM ? What is VARYING ? (More details about these clauses)
A104) The PERFORM statement is a PROCEDURE DIVISION statement which transfers control to one or more specified procedures and controls as specified the number of times the procedures are executed. After execution of the specified procedures is completed (i.e., for the appropriate number of times or until some specified condition is met), control is transferred to the next executable statement following the PERFORM statement. There are 5 types of PERFORM statements:

a) Basic PERFORM
b) PERFORM TIMES
c) PERFORM UNTIL
d) PERFORM VARYING
e) IN-LINE PERFORM

Q105) How many sections are there in data division?.
A105) SIX SECTIONS 1.FILE SECTION 2.WORKING-STORAGE SECTION 3. LOCAL-STORAGE SECTION 4.SCREEN SECTION 5.REPORT SECTION 6. LINKAGE SECTION

Q106) What is Redefines clause?
A106) Redefines clause is used to allow the same storage allocation to be referenced by different data names .

Q107) How many bytes does a s9(4)comp-3 field occupy?
A107) 3Bytes (formula : n/2 + 1))

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

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

Q110) What divisions, sections and paragraphs are mandatory for a COBOL program?
A110) IDENTIFICATION DIVISION and PROGRAM-ID paragraph are mandatory for a compilation error free COBOL
program.

Q111) Can JUSTIFIED be used for all the data types?
A111) No, it can be used only with alphabetic and alphanumeric data types.

Q112) What happens when we move a comp-3 field to an edited (say z (9). ZZ-)
A112) the editing characters r to be used with data items with usage clause as display which is the default. When u tries displaying a data item with usage as computational it does not give the desired display format because the data item is stored as packed decimal. So if u want this particular data item to be edited u have to move it into a data item whose usage is display and then have that particular data item edited in the format desired.

Q113) What will happen if you code GO BACK instead of STOP RUN in a stand-alone COBOL program i.e. a program which is not calling any other program ?
A113) Both give the same results when a program is not calling any other program. GO BACK will give the control to the system even though it is a single program.

Q114) what is the difference between external and global variables?
A114) 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.

Q115) You are writing report program with 4 levels of totals: city, state, region and country. The codes being used can be the same over the different levels, meaning a city code of 01 can be in any number of states, and the same applies to state and region code so how do you do your checking for breaks and how do you do add to each level?
A115) Always compare on the highest-level first, because if you have a break at a highest level, each level beneath it must also break. Add to the lowest level for each record but add to the higher level only on a break.

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

Q117) Why occurs can not be used in 01 level ?
A117) Because, Occurs clause is there to repeat fields with same format, not the records.

Q118) What is report-item?
A118) A Report-Item Is A Field To Be Printed That Contains Edit Symbols

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

Q120) What is the Importance of GLOBAL clause According to new standards of COBOL
A120) 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.

Q121) What is the Purpose of POINTER Phrase in STRING command
A121) The Purpose of POINTER phrase is to specify the leftmost position within receiving field where the first transferred character will be stored

Q122) How do we get current date from system with century?
A122) By using Intrinsic function, FUNCTION CURRENT-DATE

Q123) What is the maximum length of a field you can define using COMP-3?
A123) 10 Bytes (S9(18) COMP-3).

Q124) Why do we code s9 (4) comp? In spite of knowing comp-3 will occupy less space?
A124) Here s9(4)comp is small integer, so two words equal to 1 byte so totally it will occupy 2 bytes(4 words).here in s9(4) comp-3 as one word is equal to 1/2 byte.4 words equal to 2 bytes and sign will occupy 1/2 byte so totally it will occupy 3 bytes.

Q125) What is the LINKAGE SECTION used for?
A125) The linkage section is used to pass data from one program to another program or to pass data from a PROC to a program.

Q126) Describe the difference between subscripting and indexing ?
A126) Indexing uses binary displacement. Subscripts use the value of the occurrence.

Some More Questions to refer:
1. What R 2 of the common forms of the EVALUATE STATEMENT ?
2. What does the initialize statement do ?
3. What is the reference modification.
4. Name some of the examples of COBOl 11?
5. What are VS COBOL 11 special features?
6. What are options have been removed in COBOL 11?
7. What is the file organization clause ?
8. What is a subscript ?
9. What is an index for tables?
10. What are the two search techniques ?
11. What is an in-line perform ?
12. What is CALL statement in COBOL?
13. When can the USING phrase be included in the call statement ?
14. In EBCDIC, how would the number 1234 be stored?
15. How would the number +1234 be stored if a PIC clause of PICTUREs9(4) comp-3 were used?16. What is Alternate Index ? How is it different from regular index ?

Thanks for Reading.

A brief COBOL (COmmon Business Oriented Language) Introduction

History.
Developed by 1959 by a group called COnference on Data Systems Language (CODASYL). First COBOL compiler was released by December 1959.
First ANSI approved version – 1968
Modified ANSI approved version – 1974 (OS/VS COBOL)Modified ANSI approved version – 1985 (VS COBOL 2).

Speciality.
First language developed for commercial application development, which can efficiently handle millions of data.
Procedure Oriented Language - Problem is segmented into several tasks. Each task is written as a Paragraph in Procedure Division and executed in a logical sequence as mentioned.
English Like language – Easy to learn, code and maintain.

Coding Sheet.
7 12 72 80
COL-A COLUMN-B
1-6 Page/line numbers – Optional (automatically assigned by compiler)
7 Continuity (-), Comment (*), Starting a new page (/)Debugging lines (D)
8-11 Column A –Division, Section, Paragraph, 01,77 declarations must begin here.
12-72 Column B –All the other declarations/statements begin here.
73-80 Identification field. It will be ignored by the compiler but visible in the source listing.

Divisions in COBOL.
There are four divisions in a COBOL program and Data division is optional.
1.Identification Division.
2.Environment Division.
3.Data Division.
4.Procedure Division.

Identification Division.
This is the first division and the program is identified here. Paragraph PROGRAM-ID followed by user-defined name is mandatory. All other paragraphs are optional and used for documentation. The length of user-defined name for IBM COBOL is EIGHT.

IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM NAME.
AUTHOR. COMMENT ENTRY.
INSTALLATION. COMMENT ENTRY.
DATE-WRITTEN. COMMENT ENTRY.
DATE-COMPILED. COMMENT ENTRY.
SECURITY. COMMENT ENTRY.
Environment Division.
Only machine dependant division of COBOL program. It supplies information about the hardware or computer equipment to be used on the program. When your program moves from one computer to another computer, the only section that may need to be changed is
ENVIRONMENT division.

Configuration Section.
It supplies information concerning the computer on which the program will be compiled (SOURCE-COMPUTER) and executed (OBJECT-COMPUTER). It consists of three paragraphs – SOURCE COMPUTER, OBJECT-COMPUTER and SPECIAL-NAMES.
This is OPTIONAL section from COBOL 85.

SOURCE-COMPUTER. IBM-4381 (Computer and model # supplied by manufacturer)
WITH DEBUGGING MODE clause specifies that the debugging lines in the program (statements coded with ‘D’ in column 7) are compiled.

OBJECT-COMPUTER. IBM-4381 (Usually same as source computer)

SPECIAL-NAMES. This paragraph is used to relate hardware names to user-specified mnemonic names.
1. Substitute character for currency sign. (CURRENCY SIGN IS litearal-1)
2. Comma can be used as decimal point. (DECIMAL-POINT IS COMMA)
3. Default collating sequence can be changed. It will be explained later.
4. New class can be defined using CLASS keyword. (CLASS DIGIT is “0” thru “9”)

Input-Output Section.
It contains information regarding the files to be used in the program and it consists of two paragraphs FILE-CONTROL & I-O CONTROL.
FILE CONTROL. Files used in the program are identified in this paragraph.
I-O CONTROL. It specifies when check points to be taken and storage areas that are shared by different files.

Data Division.
Data division is used to define the data that need to be accessed by the program. It has three sections.
FILE SECTION describes the record structure of the files.
WORKING-STORAGE SECTION is used to for define intermediate variables.
LINKAGE SECTION is used to access the external data.
Ex: Data passed from other programs or from PARM of JCL.

Literals, Constants, Identifier,
1. Literal is a constant and it can be numeric or non-numeric.
2. Numeric literal can hold 18 digits and non-numeric literal can hold 160 characters in it. (COBOL74 supports 120 characters only)
3. Literal stored in a named memory location is called as variable or identifier.
4. Figurative Constant is a COBOL reserved word representing frequently used constants. They are ZERO/ZEROS/ZEROES, QUOTE/QUOTES, SPACE/SPACES, ALL, HIGH-VALUE/HIGH-VALUES, LOW-VALUE/LOW-VALUES.

Example: 01 WS-VAR1 PIC X(04) VALUE ‘MUSA’.
‘MUSA ‘ is a non-numeric literal. WS-VAR1 is a identifier or variable.

Declaration of variable
Level# $ Variable $ Picture clause $ Value clause $ Usage Clause $ Sync clause.
Level# It specifies the hierarchy of data within a record. It can take a value from the set of integers between 01-49 or from one of the special level-numbers 66 77 88
01 level. Specifies the record itself. It may be either a group item or an
Elementary item. It must begin in Area A.
02-49 levels. Specify group or elementary items within a record. Group level items
must not have picture clause.
66 level. Identify the items that contain the RENAMES clause.
77 level. Identify independent data item.
88 level. Condition names.

Variable name and Qualifier
Variable name can have 1-30 characters with at least one alphabet in it.
Hyphen is the only allowed special character but it cannot be first or last letter of the name. Name should be unique within the record. If two variables with same name are there, then use OF qualifier of high level grouping to refer a variable uniquely.
Ex: MOVE balance OF record-1 TO balance OF record-2.

FILLER
When the program is not intended to use selected fields in a record structure, define them as FILLER. FILLER items cannot be initialized or used in any operation of the procedure division.
PICTURE Clause
It Describes the attributes of variable.
Numeric: 9 (Digit), V (Implied decimal point), S (Sign)
Numeric Edited : + (Plus Sign), - (Minus Sign), CR DB (Credit Debit Sign) . (Period), b (Blank), ‘,’(comma), 0 (Zero), / (Slash)
BLANK WHEN ZERO (Insert blank when data value is 0), Z (ZERO suppression), * (ASTERISK), $(Currency Sign)
Non Numeric A (alphabet), B (Blank insertion Character), X(Alpha numeric), G(DBCS)
Exclusive sets + - CR,DB,V ‘.’,$ + - Z * (But $ Can appear as first place and * as floating. $***.**)
DBCS (Double Byte Character Set) is used in the applications that support large character sets. 16 bits are used for one character. Ex: Japanese language applications.
Refreshing Basics
Nibble. 4 Bits is one nibble. In packed decimal, each nibble stores one digit.
Byte. 8 Bits is one byte. By default, every character is stored in one byte.
Half word. 16 bits or 2 bytes is one half word. (MVS)
Full word. 32 bits or 4 bytes is one full word. (MVS)
Double word. 64 bits or 8 bytes is one double word. (MVS)
Usage Clause
DISPLAY Default. Number of bytes required equals to the size of the data item.
COMP Binary representation of data item.
PIC clause can contain S and 9 only.
S9(01) – S9(04) Half word.
S9(05) – S9(09) Full word.
S9(10) - S9(18) Double word.
Most significant bit is ON if the number is negative.
COMP-1 Single word floating point item. PIC Clause should not be specified.
COMP-2 Double word floating-point item. PIC Clause should not be specified.
COMP-3 Packed Decimal representation. Two digits are stored in each byte.
Last nibble is for sign. (F for unsigned positive, C for signed positive
and D for signed negative)
Formula for Bytes: Integer ((n/2) + 1)) => n is number of 9s.
INDEX It is used for preserve the index value of an array. PIC Clause should
not be specified.
VALUE Clause It is used for initializing data items in the working storage section. Value of item must not exceed picture size. It cannot be specified for the items whose size is variable.
Syntax:
VALUE IS literal.
VALUES ARE literal-1 THRU THROUGH literal-2
VALUES ARE literal-1, literal-2
Literal can be numeric without quotes OR non-numeric within quotes OR figurative constant.

SIGN Clause
Syntax SIGN IS (LEADING) SEPARATE CHARACTER (TRAILING).
It is applicable when the picture string contain ‘S’. Default is TRAILING WITH NO SEPARATE CHARACTER. So ‘S’ doesn’t take any space. It is stored along with last digit.
REDEFINES
The REDEFINES clause allows you to use different data description entries to describe the same computer storage area. Redefining declaration should immediately follow the redefined item and should be done at the same level. Multiple redefinitions are possible. Size of redefined and redefining need not be the same.

Example:
01 WS-DATE PIC 9(06).
01 WS-REDEF-DATE REDEFINES WS-DATE.
05 WS-YEAR PIC 9(02).
05 WS-MON PIC 9(02).
05 WS-DAY PIC 9(02).

RENAMES
It is used for regrouping of elementary data items in a record. It should be declared at 66 level. It need not immediately follows the data item, which is being renamed. But all RENAMES entries associated with one logical record must immediately follow that record's last data description entry. RENAMES cannot be done for a 01, 77, 88 or another 66 entry.
01 WS-REPSONSE.
05 WS-CHAR143 PIC X(03).
05 WS-CHAR4 PIC X(04).
66 ADD-REPSONSE RENAMES WS-CHAR143.

CONDITION name
It is identified with special level ‘88’. A condition name specifies the value that a field can contain and used as abbreviation in condition checking.
01 SEX PIC X.
88 MALE VALUE ‘1’
88 FEMALE VALUE ‘2’ ‘3’.
IF SEX=1 can also be coded as IF MALE in Procedure division.
‘SET FEMALE TO TRUE ‘ moves value 2 to SEX. If multiple values are coded on VALUE clause, the first value will be moved when it is set to true.

JUSTIFIED RIGHT
This clause can be specified with alphanumeric and alphabetic items for right justification. It cannot be used with 66 and 88 level items.

OCCURS Clause
OCCURS Clause is used to allocate physically contiguous memory locations to store the table values and access them with subscript or index. Detail explanation is given in Table Handling section.

LINKAGE SECTION
It is used to access the data that are external to the program. JCL can send maximum 100 characters to a program thru PARM. Linkage section MUST be coded with a half word binary field, prior to actual field. If length field is not coded, the first two bytes of the field coded in the linkage section will be filled with length and so there are chances of 2 bytes data truncation in the actual field.
01 LK-DATA.
05 LK-LENGTH PIC S9(04) COMP.
05 LK-VARIABLE PIC X(08).
Procedure Division.
This is the last division and business logic is coded here. It has user-defined sections and paragraphs. Section name should be unique within the program and paragraph name should be unique within the section.
Procedure division statements are broadly classified into following categories.
Statement Type - Meaning
Imperative - Direct the program to take a specific action. Ex: MOVE ADD EXIT GOTO Conditional - Decide the truth or false of relational condition and based on it, execute different paths. Ex: IF, EVALUATE
Compiler Directive - Directs the compiler to take specific action during compilation.
Ex: COPY SKIP EJECT
Explicit Scope terminator - Terminate the scope of conditional and imperative statements.
Ex: END-ADD END-IF END-EVALUATE
Implicit Scope terminator- The period at the end of any sentence, terminates the scope of
all previous statements not yet terminated.
MOVE Statement
It is used to transfer data between internal storage areas defined in either file section or working storage section.

Syntax:
MOVE identifier1/literal1/figurative-constant TO identifier2 (identifier3)Multiple move statements can be separated using comma, semicolons, blanks or the keyword THEN.
Numeric move rules:
A numeric or numeric-edited item receives data in such a way that the decimal point is aligned first and then filling of the receiving field takes place.
Unfilled positions are filled with zero. Zero suppression or insertion of editing symbols takes places according to the rules of editing pictures.
If the receiving field width is smaller than sending field then excess digits, to the left and/or to the right of the decimal point are truncated.
Alphanumeric Move Rules:
Alphabetic, alphanumeric or alphanumeric-edited data field receives the data from left to right. Any unfilled field of the receiving filed is filled with spaces.
When the length of receiving field is shorter than that of sending field, then receiving field accepts characters from left to right until it is filled. The unaccomodated characters on the right of the sending field are truncated.
When an alphanumeric field is moved to a numeric or numeric-edited field, the item is moved as if it were in an unsigned numeric integer mode.
CORRESPONDING can be used to transfer data between items of the same names belonging to different group-items by specifying the names of group-items to which they belong.
ROUNDED option
With ROUNDED option, the computer will always round the result to the PICTURE clause specification of the receiving field. It is usually coded after the field to be rounded. It is prefixed with REMAINDER keyword ONLY in DIVIDE operation. ADD A B GIVING C ROUNDED.
ON SIZE ERROR
If A=20 (PIC 9(02)) and B=90 (PIC 9(02)), ADD A TO B will result 10 in B where the expected value in B is 110. ON SIZE ERROR clause is coded to trap such size errors in arithmetic operation.
If this is coded with arithmetic statement, any operation that ended with SIZE error will not be carried out but the statement follows ON SIZE ERROR will be executed.
ADD A TO B ON SIZE ERROR DISPLAY ‘ERROR!’.
COMPUTE
Complex arithmetic operations can be carried out using COMPUTE statement. We can use arithmetic symbols than keywords and so it is simple and easy to code.
+ For ADD, - for SUBTRACT, * for MULTIPLY, / for DIVIDE and ** for exponentiation.
Rule: Left to right – 1.Parentheses
2.Exponentiation
3.Multiplication and Division
4.Addition and Subtraction
Caution: When ROUNDED is coded with COMPUTE, some compiler will do rounding for every arithmetic operation and so the final result would not be precise.
77 A PIC 999 VALUE 10
COMPUTE A ROUNDED = (A+2.95) *10.99
Result: (ROUNDED(ROUNDED(12.95) * ROUNDED(10.99)) =120 or
ROUNDED(142.3205) = 142
So the result can be 120 or 142.Be cautious when using ROUNDED keyword with COMPUTE statement.

All arithmetic operators have their own explicit scope terminators. (END-ADD, END-SUBTRACT, END-MULTIPLY, END-DIVIDE, END-COMPUTE). It is suggested to use them.
CORRESPONDING is available for ADD and SUBTRACT only.
INITIALIZE
VALUE clause is used to initialize the data items in the working storage section whereas INITIALIZE is used to initialize the data items in the procedure division.
INITIALIZE sets the alphabetic, alphanumeric and alphanumeric-edited items to SPACES and numeric and numeric-edited items to ZERO. This can be overridden by REPLACING option of INITIALIZE. FILLER, OCCURS DEPENDING ON items are not affected.
Syntax: INITIALIZE identifier-1
REPLACING (ALPHABETIC/ALPHANUMERIC/ALPHA-NUMERIC-EDITED
NUMERIC/NUMERIC-EDITED)
DATA BY (identifier-2 /Literal-2)
ACCEPT
ACCEPT can transfer data from input device or system information contain in the reserved data items like DATE, TIME, DAY.
ACCEPT WS-VAR1 (FROM DATE/TIME/DAY/OTHER SYSTEM VARS).
If FROM Clause is not coded, then the data is read from terminal. At the time of execution, batch program will ABEND if there is no in-stream data from JCL and there is no FROM clause in the ACCEPT clause.

DATE option returns six digit current date in YYYYMMDD
DAY returns 5 digit current date in YYDDD
TIME returns 8 digit RUN TIME in HHMMSSTT
DAY-OF-WEEK returns single digit whose value can be 1-7 (Monday-Sunday respectively)

DISPLAY
It is used to display data. By default display messages are routed to SYSOUT.
Syntax: DISPLAY identifier1 literal1 (UPON mnemonic name)

STOP RUN, EXIT PROGRAM & GO BACK
STOP RUN is the last executable statement of the main program. It returns control back to OS.
EXIT PROGRAM is the last executable statement of sub-program. It returns control back to main program.
GOBACK can be coded in main program as well as sub-program as the last statement. It just gives the control back from where it received the control.
PERFORM STATEMENTSPERFORM will be useful when you want to execute a set of statements in multiple places of the program. Write all the statements in one paragraph and invoke it using PERFORM wherever needed. Once the paragraph is executed, the control comes back to next statement following the PERFORM
1.SIMPLE PERFORM.
PERFORM PARA-1.
DISPLAY ‘PARA-1 executed’
STOP RUN.
PARA-1.
Statement1
Statement2.
It executes all the instructions coded in PARA-1 and then transfers the control to the next instruction in sequence.

2.INLINE PERFORM.
When sets of statements are used only in one place then we can group all of them within PERFORM END-PERFORM structure. This is called INLINE PERFORM.
This is equal to DO..END structure of other languages.
PERFORM
ADD A TO B
MULTIPLE B BY C
DISPLAY ‘VALUE OF A+B*C ‘ C
END-PERFORM

3. PERFORM PARA-1 THRU PARA-N.
All the paragraphs between PARA-1 and PARA-N are executed once.

4. PERFORM PARA-1 THRU PARA-N UNTIL condition(s).
The identifiers used in the UNTIL condition(s) must be altered within the paragraph(s) being performed; otherwise the paragraphs will be performed indefinitely. If the condition in the UNTIL clause is met at first time of execution, then named paragraph(s) will not be executed at all.

5. PERFORM PARA-1 THRU PARA-N N TIMES.
N can be literal defined as numeric item in working storage or hard coded constant.

6. PERFORM PARA-1 THRU PARA-N VARYING identifier1
FROM identifier 2 BY identifier3 UNTIL condition(s)
Initialize identifier1 with identifier2 and test the condition(s). If the condition is false execute the statements in PARA-1 thru PARA-N and increment identifier1 BY identifier3 and check the condition(s) again. If the condition is again false, repeat this process till the condition is satisfied.

7.PERFORM PARA-1 WITH TEST BEFORE/AFTER UNTIL condition(s).
With TEST BEFORE, Condition is checked first and if it found false, then PARA-1 is executed and this is the default. (Functions like DO- WHILE)
With TEST AFTER, PARA-1 is executed once and then the condition is checked. (Functions like DO-UNTIL)
EXIT statement.
COBOL reserved word that performs NOTHING. It is used as a single statement in a paragraph that indicate the end of paragraph(s) execution.
EXIT must be the only statement in a paragraph in COBOL74 whereas it can be used with other statements in COBOL85.
GO TO Usage:
In a structured top-down programming GO TO is not preferable. It offers permanent control transfer to another paragraph and the chances of logic errors is much greater with GO TO than PERFORM. The readability of the program will also be badly affected.
But still GO TO can be used within the paragraphs being performed. i.e. When using the THRU option of PERFORM statement, branches or GO TO statements, are permitted as long as they are within the range of named paragraphs.
PERFORM 100-STEP1 THRU STEP-4
..
100-STEP-1.
ADD A TO B GIVING C.
IF D = ZERO DISPLAY ‘MULTIPLICATION NOT DONE’
GO TO 300-STEP3
END-IF.
200-STEP-2.
MULTIPLY C BY D.
300-STEP-3.
DISPLAY ‘VALUE OF C:’ C.
Here GO TO used within the range of PERFORM. This kind of Controlled GO TO is fine with structured programming also!
CALL statement (Sub-Programs)
When a specific functionality need to be performed in more than one program, it is best to write them separately and call them into each program. Sub Programs can be written in any programming language. They are typically written in a language best suited to the specific task required and thus provide greater flexibility.

Main Program Changes:
CALL statement is used for executing the sub-program from the main program. A sample of CALL statement is given below:
CALL ‘PGM2’ USING BY REFERENCE WS-VAR1, BY CONTENT WS-VAR2.
PGM2 is called here. WS-VAR1 and WS-VAR2 are working storage items.
WS-VAR1 is passed by reference. WS-VAR2 is passed by Content. BY REFERENCE is default in COBOL and need not be coded. BY CONTENT LENGTH phrase permits the length of data item to be passed to a called program.

Sub-Program Changes:
WS-VAR1 and WS-VAR2 are working storage items of main program.
As we have already mentioned, the linkage section is used for accessing external elements. As these working storage items are owned by main program, to access them in the sub-program, we need to define them in the linkage section.

LINKAGE SECTION.
01 LINKAGE SECTION.
05 LK-VAR1 PIC 9(04).
05 LK-VAR2 PIC 9(04).

In addition to define them in linkage section, the procedure division should be coded with these data items for address-ability.

PROCEDURE DIVISION USING LK-VAR1,LK-VAR2

There is a one-one correspondence between passed elements and received elements (Call using, linkage and procedure division using) BY POSITION. This implies that the name of the identifiers in the called and calling program need not be the same (WS-VAR1 & LK-VAR1) but the number of elements and picture clause should be same.

The last statement of your sub-program should be EXIT PROGRAM. This returns the control back to main program. GOBACK can also be coded instead of EXIT PROGRAM but not STOP RUN. EXIT PROGRAM should be the only statement in a paragraph in COBOL74 whereas it can be coded along with other statements in a paragraph in COBOL85.

PROGRAM-ID. IS INITIAL PROGRAM.
If IS INITIAL PROGRAM is coded along with program-id of sub program, then the program will be in initial stage every time it is called (COBOL85 feature).
Alternatively CANCEL issued after CALL, will set the sub-program to initial state.
If the sub program is modified then it needs to be recompiled. The need for main program recompilation is decided by the compiler option used for the main program. If the DYNAM compiler is used, then there is no need to recompile the main program. The modified subroutine will be in effect during the run. NODYNAM is default that expects the main program recompilation.
COBOL COMPILATION
COMPILATION JCL:
//SMSXL86B JOB ,'COMPILATION JCL', MSGCLASS=Q,MSGLEVEL=(1,1),CLASS=C
//COMPILE1 EXEC PGM=IGYCRCTL, PARM=’XREF,APO,ADV,MAP,LIST),REGION=0M
//STEPLIB DD DSN=SYS1.COB2LIB,DISP=SHR
//SYSIN DD DSN=SMSXL86.TEST.COBOL(SAMPGM01),DISP=SHR
//SYSLIB DD DSN=SMSXL86.COPYLIB,DISP=SHR
//SYSPRINT DD SYSOUT=*
//SYSLIN DD DSN=&&LOADSET, DCB=(RECFM=FB,LRECL=80,BLKSIZE=3200),
// DISP=(NEW,PASS),UNIT=SYSDA,SPACE=(CYL,(5,10),RLSE),
//SYSUT1 DD UNIT=&SYSDA,SPACE=(CYL,(1,10)) => Code SYSUT2 to UT7
//LINKEDT1 EXEC PGM=IEWL,COND=(4,LT)
//SYSLIN DD DSN=&&LOADSET, DISP=(OLD,DELETE)
//SYSLMOD DD DSN=&&GOSET(SAMPGM01),DISP=(NEW,PASS),UNIT=SYSDA
// SPACE=(CYL,1,1,1))
//SYSLIB DD DSN=SMSXL86.LOADLIB,DISP=SHR
//SYSUT1 DD UNIT=SYSDA,SPACE=(CYL,(1,10))
//SYSPRINT DD SYSOUT=*

//*** EXECUTE THE PROGRAM ***
//EXECUTE1 EXEC PGM=*.LINKEDT1.SYSLMOD,COND=(4,LT),REGION=0M
//STEPLIB DD DSN=SMSXL86.LOADLIB,DISP=SHR
// DD DSN=SYS1.SCEERUN,DISP=SHR
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
Compiler Options
The default options that were set up when your compiler was installed are in effect for your program unless you override them with other options. To check the default compiler options of your installation, do a compile and check in the compilation listing.

Ways of overriding the default options

1.Compiler options can be passed to COBOL Compiler Program (IGYCRCTL) through the PARM in JCL.

2.PROCESS or CBL statement with compiler options, can be placed before the identification division.
3.If the organization uses any third party product or its own utility then these options can be coded in the pre-defined line of the utility panel.

Precedence of Compiler Options
(Highest precedence). Installation defaults, fixed by the installation.
Options coded on PROCESS /CBL statement
Options coded on JCL PARM parameters
(Lowest Precedence). Installation defaults, but not fixed.
Here i have posted most importance concepts that i feel a beginner should know. There is lot to understand in COBOL. Please let me the topic that you want to understand. I will soon post it. Thanks for reading.

Friday, July 10, 2009

JCL Interview Questions

1. What is primary allocation for a dataset?
The space allocated when the dataset is first created.
2. What is the difference between primary and secondary allocations for a dataset?
Secondary allocation is done when more space is required than what has already been allocated.
3. How many extents are possible for a sequential file ? For a VSAM file?
16 extents on a volume for a sequential file and 123 for a VSAM file.
4. What does a disposition of (NEW,CATLG,DELETE) mean?
That this is a new dataset and needs to be allocated, to CATLG the dataset if the step is successful and to delete the dataset if the step abends.
5. What does a disposition of (NEW,CATLG,KEEP) mean?
That this is a new dataset and needs to be allocated, to CATLG the dataset if the step is successful and to KEEP but not CATLG the dataset if the step abends. Thus if the step abends, the dataset would not be catalogued and we would need to supply the vol. ser the next time we refer to it.
6. How do you access a file that had a disposition of KEEP?
Need to supply volume serial no. VOL=SER=xxxx.
7. What does a disposition of (MOD,DELETE,DELETE) mean ?
The MOD will cause the dataset to be created (if it does not exist), and then the two DELETEs will cause the dataset to be deleted whether the step abends or not. This disposition is used to clear out a dataset at the beginning of a job.
8. What is the DD statement for a output file?
Unless allocated earlier, will have the foll parameters: DISP=(NEW,CATLG,DELETE), UNIT , SPACE & DCB .
9. What do you do if you do not want to keep all the space allocated to a dataset?
Specify the parameter RLSE ( release ) in the SPACE e.g. SPACE=(CYL,(50,50),RLSE)
10. What is DISP=(NEW,PASS,DELETE)?
This is a new file and create it, if the step terminates normally, pass it to the subsequent steps and if step abends, delete it. This dataset will not exist beyond the JCL.
11. How do you create a temporary dataset? Where will you use them?1
Temporary datasets can be created either by not specifying any DSNAME or by specifying the temporary file indicator as in DSN=&&TEMP.
We use them to carry the output of one step to another step in the same job. The dataset will not be retained once the job completes.
12. How do you restart a proc from a particular step?
In job card, specify RESTART=procstep.stepname

where procstep = name of the jcl step that invoked the proc
and stepname = name of the proc step where you want execution to start
13. How do you skip a particular step in a proc/JOB?
Can use either condition codes or use the jcl control statement IF (only in ESA JCL)
14. A PROC has five steps. Step 3 has a condition code. How can you override/nullify this condition code?
Provide the override on the EXEC stmt in the JCL as follows:
//STEP001 EXEC procname,COND.stepname=value

All parameters on an EXEC stmt in the proc such as COND, PARM have to be overridden like this.
15. How do you override a specific DDNAME/SYSIN in PROC from a JCL?
// DSN=...
16. What is NOTCAT ?
This is an MVS message indicating that a duplicate catalog entry exists. E.g., if you already have a dataset with dsn = 'xxxx.yyyy' and u try to create one with disp new,catlg, you would get this error. the program open and write would go through and at the end of the step the system would try to put it in the system catalog. at this point since an entry already exists the catlg would fail and give this message. you can fix the problem by deleting/uncataloging the first data set and going to the volume where the new dataset exists(this info is in the msglog of the job) and cataloging it.
17. What is 'S0C7' abend?
Caused by invalid data in a numeric field.
18. What is a S0C4 error?
Storage violation error - can be due to various reasons. e.g.: READING a file that is not open, invalid address referenced due to subscript error.
19. What are SD37, SB37, SE37 abends?
All indicate dataset out of space. SD37 - no secondary allocation was specified. SB37 - end of vol. and no further volumes specified. SE37 - Max. of 16 extents already allocated.
20.What is S322 abend ?
Indicates a time out abend. Your program has taken more CPU time than the default limit for the job class. Could indicate an infinite loop.
21. Why do you want to specify the REGION parameter in a JCL step?
To override the REGION defined at the JOB card level.

REGION specifies the max region size. REGION=0K or 0M or omitting REGION means no limit will be applied.
22. What does the TIME parameter signify ? What does TIME=1440 mean ?
TIME parameter can be used to overcome S322 abends for programs that genuinely need more CPU time. TIME=1440 means no CPU time limit is to be applied to this step.
23. What is COND=EVEN ?
Means execute this step even if any of the previous steps, terminated abnormally.
24. What is COND=ONLY ?
Means execute this step only if any of the previous steps, terminated abnormally.
25. How do you check the syntax of a JCL without running it?
TYPERUN=SCAN on the JOB card or use JSCAN.
26. What does IEBGENER do?
Used to copy one QSAM file to another. Source dataset should be described using SYSUT1 ddname. Destination dataset should be decribed using SYSUT2. IEBGENR can also do some reformatting of data by supplying control cards via SYSIN.
27. How do you send the output of a COBOL program to a member of a PDS?
Code the DSN as pds(member) with a DISP of SHR. The disp applies to the pds and not to a specific member.
28. I have multiple jobs ( JCLs with several JOB cards ) in a member. What happens if I submit it?
Multiple jobs are submitted (as many jobs as the number of JOB cards).
29. I have a COBOL program that ACCEPTs some input data. How do you code the JCL statment for this? ( How do you code instream data in a JCL? )
//SYSIN DD*
input data
input data
/*
30. Can you code instream data in a PROC ?
No.
31. How do you overcome this limitation?
One way is to code SYSIN DD DUMMY in the PROC, and then override this from the JCL with instream data.
32. How do you run a COBOL batch program from a JCL? How do you run a COBOL/DB2 program?
To run a non DB2 program,

//STEP001 EXEC PGM=MYPROG

To run a DB2 program,

//STEP001 EXEC PGM=IKJEFT01
//SYSTSIN DD *
DSN SYSTEM(....)
RUN PROGRAM(MYPROG)
PLAN(.....) LIB(....) PARMS(...)
/*
33. What is STEPLIB, JOBLIB? What is it used for?
Specifies that the private l ibrary (or libraries) specified should be searched before the default system libraries in order to locate a program to be executed.
STEPLIB applies only to the particular step, JOBLIB to all steps in the job.
34. What is order of searching of the libraries in a JCL?
First any private libraries as specified in the STEPLIB or JOBLIB, then the system libraries such as SYS1.LINKLIB. The system libraries are specified in the linklist.
35.What happens if both JOBLIB & STEPLIB is specified ?
JOBLIB is ignored.
36. When you specify mutiple datasets in a JOBLIB or STEPLIB, what factor determines the order?
The library with the largest block size should be the first one.
37. How to change default proclib ?
//ABCD JCLLIB ORDER=(ME.MYPROCLIB,SYS1.PROCLIB)
38. The disp in the JCL is MOD and the program opens the file in OUTPUT mode. What happens ? The disp in the JCL is SHR and the pgm opens the file in EXTEND mode. What happens ?
Records will be written to end of file (append) when a WRITE is done in both cases.
39. What are the valid DSORG values ?
PS - QSAM, PO - Partitioned, IS - ISAM
40. What are the differences between JES2 & JES3 ?
JES3 allocates datasets for all the steps before the job is scheduled. In JES2, allocation of datasets required by a step are done only just before the step executes.

Thursday, July 9, 2009

What is Mainframes??

The term ‘MainFrame’ brings to mind a giant room of electronic parts that is a computer, referring to the original CPU cabinet in a computer of the mid-1960’s. Today, Mainframe refers to a class of ultra-reliable large and medium-scale servers designed for carrier-class and enterprise-class systems operations. Mainframes are costly, due to the support of symmetric multiprocessing (SMP) and dozens of central processors existing within in a single system. Mainframes are highly scalable. Through the addition of clusters, high-speed caches and volumes of memory, they connect to terabyte holding data subsystems.
The first mainframe vendors were GE, Control Data, IBM, NCR, RCA, Burroughs, Honeywell and Univac. Collectively known as “IBM and the Seven Dwarfs”. Through mergers, these vendors shifted within the industry, becoming “IBM and the BUNCH”. Running a version of Unix or Linux, these vendors led by IBM now include Amdahl (Fujitsu), Unisys and Sun among others.
Online training includes the History of Mainframes, Job Control Language (JCL) and thorough tutorials on the components, transactions and functions of the Customer Information Control System (CICS). Mainframe professionals can find well-paid work in highly respected and breakthrough technology companies throughout the world as Mainframe Systems Programmers and Project Managers.

History and Evolution of Mainframes:
Some of the early mainframes which were developed starting from the year of 1942 are ENIAC, MARK1, BINAC, UNIVAC. ENIAC is also called as electronic numerical integrator and calculator was developed in the year 1942. This mainframe machine weighed in tones and consumed enormous electric power. It had thousands of vacuum tubes, relays resistors, capacitors, and inductors inside it.In the year 1951, UNIVAC-I was developed specially for the US Census Bureau. The major difference between UNIVAC and ENIAC was the processing of digits. IBM was producing and releasing mainframes in the market at all periods from past till present with the successive development of IBM Series starting with System/360.
Mainframe Channel:
A mainframe channel connect to one or more controllers via either pairs of large "bus and tag" cables or, fiber optic ESCON (Enterprise System CONnection) cables and FICON, which has the ability controlling one or more devices. This is one of the important term in mainframe technology since it has the ability of take care of huge input and output functions.
DASD:
DASD stands for Direct Access Storage Device. This indicates to any type of storage that was directly (randomly) addressable.
LPAR:
LPAR stands for Logical Partition and is a powerful hardware or firmware feature implemented in all mainframe systems. By this feature it is possible to create partitions and by which CPUs and I/O sub-systems can be shared between logical partitions.