MAINFRAME MATERIAL - COBOL, DB2, AND CICS

AUTHOR - K PHANI KUMAR,

Contents
Contents...................................................................................................................................................................1 COBOL - COMMON BUSINESS ORIENTED LANGUAGE ..............................................................................3 DIVISIONS........................................................................................................................................................3 COBOL CODING SHEET..................................................................................................................................5 DATA TYPES....................................................................................................................................................6 LEVEL NUMBERS ...........................................................................................................................................6 SPECIAL LEVEL NUMBERS ...........................................................................................................................7 MOVE VERB ....................................................................................................................................................8 ADD VERB .......................................................................................................................................................9 SUBTRACT VERB .........................................................................................................................................10 MULTIPLY VERB ...........................................................................................................................................11 DIVIDE VERB .................................................................................................................................................11 COMPUTE VERB ...........................................................................................................................................12 REDEFINE CLAUSE ......................................................................................................................................12 IF STATEMENT ..............................................................................................................................................13 EVALUATE STATEMENT ..............................................................................................................................14 PERFORM STATEMENTS .............................................................................................................................14 EXIT, STOP RUN, EXIT PROGRAM AND GOBACK .....................................................................................17 SUB PROGRAMS...........................................................................................................................................18 TABLE HANDLING..........................................................................................................................................20 INTERNAL SORT............................................................................................................................................22 FILE HANDLING.............................................................................................................................................23 DB2 - DATABASE 2 .......................................................................................................................................28 COMPILATION PROCESS ............................................................................................................................36 INCLUDE and COPY statements....................................................................................................................39 1

MAINFRAME MATERIAL - COBOL, DB2, AND CICS
AUTHOR - K PHANI KUMAR, JOINS .............................................................................................................................................................39

2

MAINFRAME MATERIAL - COBOL, DB2, AND CICS
AUTHOR - K PHANI KUMAR,

COBOL - COMMON BUSINESS ORIENTED LANGUAGE COBOL stands for COMMON BUSINESS ORIENTED LANGUAGE. COBOL Programs are used for commercial data processing. COBOL is an English like language. DIVISIONS A COBOL program consists of 4 divisions. • • • • IDENTIFICATION DIVISION ENVIRONMENT DIVISION DATA DIVISION PROCEDURE DIVISION

IDENTIFICATION DIVISION:• It’s used to identify the COBOL program. • It tells the system what the program name is, who has written it, when it was compiled etc. IDENTIFICATION DIVISION. PROGRAM-ID. CR25410. AUTHOR. PHANI. INSTALLATION. WIPRO. DATE-WRITTEN. 12-12-2005. ENVIRONMENT DIVISION:• It’s used to tell the system what is the source compute and object computers used in the programs. • And also what are the input and output files used in the program. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. 3270. OBJECT-COMPUTER. 3278. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CNTLCARD-FILE ASSIGN TO CARDFILE. SELECT CHARGEBACK-CONTROL-FILE ASSIGN TO CBUCCF ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS CCF-RECORD-KEY-FD FILE STATUS IS STATUS-IND.
3

MAINFRAME MATERIAL - COBOL, DB2, AND CICS
AUTHOR - K PHANI KUMAR,

• •

CONFIGURATION SECTION gives the source and object computer details. i.e. it gives the information about where the program has been writer(Terminal) and where it can be executed. This section is optional now. INPUT-OUTPUT SECTION gives the input and output files that the program is going to be used. Whatever the files that we use in COBOL program that has to be declared in the JCL.

DATA DIVISION:• It’s used to declare the variables used in the COBOL program, and to specify the file attributes, and to pass the data from one program to another program. It contains FILE SECTION, WORKING-STORAGE SECTION and LINKAGE-SECTION. • • • FILE-SECTION - If we use any files in the COBOL program that has to be declared here. WORKING-STORAGE SECTION - It’s used to declare all the variables used in the COBOL program. LINKAGE SECTION - It’s used to pass the data from main program to sub program.

DATA DIVISION. FILE SECTION. FD CNTLCARD-FILE BLOCK CONTAINS 0 RECORDS RECORD CONTAINS 80 CHARACTERS. LABEL RECORDS ARE STANDARD DATA RECORD IS CNTLCARD-REC. 01 CNTLCARD-REC PIC X(80). WORKING-STORAGE SECTION. 77 RECORDS-READ PIC 9(7) 77 RECORDS-SELECTED PIC 9(7) LINKAGE SECTION.

VALUE 0 COMP-3. VALUE 0 COMP-3.

PROCEDURE DIVISION:• It’s used to write the logic of the program. The COBOL instructions start from here. And also the execution of the program begins from the PROCEDURE DIVISION.

4

o Margin-B . IDENTIFICATION DIVISION. DB2. Columns 1 to 6 will be used by the user for writing the sequence numbers. 12-12-2005. Margin-A contains the Division names. Column 7 is used for indicating o *  Comment o _  Continuation o D  Debugging line Each member will be having two margins. DISPLAY ‘HELLOW WORLD OF MAINFRMES’. DATE-WRITTEN. DATA DIVISION. AND CICS AUTHOR . ENVIRONMENT DIVISION. Margin-B contains the logic of your program. Columns 73rd to 80 used by the System for writing the offset address.It starts from column 12th to 72nd. File description and Sort Descriptions. 5 . WIPRO. STOP RUN. Paragraph names. PROCEDURE DIVISION. INSTALLATION. o Margin-A . HELLOPGM. COBOL CODING SHEET • • • • • • • Every COBOL program has to be written in a 80 columns and 24 rows PDS member. A-START. PHANI. AUTHOR. Level numbers.It starts from column 8th. PROGRAM-ID.COBOL. Section names.K PHANI KUMAR.MAINFRAME MATERIAL .

NUMERIC ==> It will be represented using 9 2. ALPHABETIC ==> It will be represented using A LEVEL NUMBERS • • • • In COBOL each variable has to be declared with a level number. DATA TYPES • In COBOL we have the following data types. DB2.COBOL.K PHANI KUMAR. ALPHA NUMERIC ==> It will be represented using X 3.MAINFRAME MATERIAL .49 level numbers in COBOL. 77. Ex6 . 1. We have 01 .01 is used to declare the group variable. And also special level numbers 66. AND CICS AUTHOR . 88. Level No .

MAINFRAME MATERIAL . PIC X(1) PIC X(1) PIC X(1) VALUE SPACES. VALUE Clause : We can assign an initial value to the elementary dataitems/variables by using the VALUE clause.99 PICTURE S9V9 -> Stores a +ve/-ve real from –9. SPACES. VALUE SPACES. 01 WS-NAME. VALUE SPACES. PICTURE Clause: Examples PICTURE 999 -> Stores a 3 digit +ve no. how much the width of the data-type is. VALUE SPACES. 05 INITIAL 05 SUR-NAME 05 FIRST-NAME PIC X(1) PIC X(15) PIC X(20) VALUE SPACES. It gives the data-type and the size of the data-item. PICTURE S999 -> Stores a 3 digit +ve/-ve no. VALUE SPACES. whether. 01 WORK-REF-NUM. 77. SPACES.COBOL. SPACES. and 88. 05 WORK-REF-NUM-1 05 WORK-REF-NUM-2 05 FILLER 05 WORK-REF-DATE 05 FILLER 05 WORK-REF-19-23 01 WS-NAME. 05 INITIAL 05 SUR-NAME 05 FIRST-NAME PIC PIC PIC PIC PIC PIC X(1) X(2) X(4) 9(4) X(7) X(5) VALUE VALUE VALUE VALUE VALUE VALUE SPACES. AND CICS AUTHOR . It also shows. PICTURE XXXX -> Stores a string of 4 characters PICTURE 99V99 -> Stores a +ve real from 0-99. DB2. or alpha-numeric data. It is an optional clause. XXXX as X(4).This level number is used for RENAMES clause. Here 01 is a Group level item and 05 are called as Sub-Level items.9 to +9. 999V99 as 9(3)V9(2).9 Shorthand Notation : You can abbreviate 9999 as 9(4). 7 . This specifies. the storage location stores numbers.K PHANI KUMAR. 66 .52 VALUE ’26-06-09’ SPECIAL LEVEL NUMBERS • Special level numbers are 66. SPACES. S99999 as S9(5) etc. alphabets. 01 WS-EMP-SALARY 01 WS-EMP-JDATE PIC 9(4)V99 PIC X(10) VALUE 1000. ZERO.

VALUE SPACES. The way MOVE statement work is different for NUMERIC and ALPHABETIC. DISPLAY RECORD-3. PIC 9(2) VALUE 30.This level number is used for condition names. 66 RECORD-3 RENAMES FIELD-B THRU FIELD-C. Format-1:8 . MOVE VERB • • • MOVE verb is used to move the values from one variable to another variable. PIC 9(2) VALUE 40. VALUE '22'. ALPHA-NUMERIC variables. 01 WS-INPUT. AND CICS AUTHOR . 88 . VALUES '00' '97'. SUR-NAME. O\P . FIRST-NAME. VALUE '23'. VALUE '10'.This level number is used for declaring the individual items.COBOL. DB2.2030 77 . 01 STATUS-IND 88 GOOD-STATUS 88 88 88 END-OF-FILE-STATUS DUP-REC-STATUS NO-RECORD-FOUND PIC XX VALUE SPACES.s 77 77 INITIAL SUR-NAME PIC X(1) PIC X(15) VALUE SPACES.MAINFRAME MATERIAL . Now we have two variables WS-NAME. 10 FIELD-A 10 FIELD-B 05 RECORD-2. 05 RECORD-1. There are different MOVE statements. WS-FULL-NAME contains the same values. 10 FIELD-C 10 FIELD-D PIC 9(2) VALUE 10. 66 WS-FULL-NAME RENAMES INITIAL.K PHANI KUMAR. That means there will be no sub-levels for that variable. PIC 9(2) VALUE 20.

K PHANI KUMAR. 9(3). B. X(30).35. O\P . 05 NAME 05 AGE 05 SALARY 05 ADDR PIC PIC PIC PIC X(15).Both EMP-REC-1 and EMP-REC-2 are having the common variables. DISPLAY B. MOVE 123 TO A. ==> Value of A is stored in the variable B. 9(3). ==> Value in A is 25 then it adds 10 to variable A. ADD 10 TO A. Format-2:MOVE 123 TO A. DISPLAY A. Format-1:01 A PIC 9(2)VALUE 25.MAINFRAME MATERIAL . MOVE EMP-REC-1 CORRESPONDING EMP-REC-2. It will move the variables which are common. 9(5)V9(2).COBOL. 9(5)V9(2).35 25 9 . 05 NAME PIC 05 AGE PIC 05 SALARY PIC 01 EMP-REC-2. ADD 10 TO A. AND CICS AUTHOR . Format-3:01 EMP-REC-1. ==> Value 123 is stored in the variable A. MOVE A TO B. DB2. NOTE . ADD VERB • ADD verb is used to add the variables or constants. O\P . 01 B PIC 9(2)VALUE 15. Format-2:01 A PIC 9(2)VALUE 25. B. ==> Value 123 is stored in the variable A & B. X(15). if we want to move the common variables we use the FORMAT-3. DISPLAY A.

DISPLAY C. DISPLAY B. ==> Value in A is 25 then it subtracts 10 from variable A. SUBTRACT 10 FROM A. 01 C PIC S9(2). DISPLAY A.K PHANI KUMAR.25 15 40 ==> Here A & B values are not changed and result stored in C SUBTRACT VERB • SUBTRACT verb is used to subtract the variables or constants. 01 B PIC 9(2)VALUE 15. SUBTRACT 10 FROM A. DISPLAY C. O\P . O\P . DISPLAY A.15 05 Format-3:01 A PIC 9(2)VALUE 25. B.COBOL. ADD A TO B GIVING C. 10 . Format-1:01 A PIC 9(2)VALUE 25.15. O\P . DISPLAY B. 01 B PIC 9(2)VALUE 15. 01 B PIC 9(2)VALUE 15. 01 C PIC 9(2). SUBTRACT A FROM B GIVING C. Format-2:01 A PIC 9(2)VALUE 25. DISPLAY A. DISPLAY B. DB2. DISPLAY A.MAINFRAME MATERIAL . AND CICS AUTHOR . Format-3:01 A PIC 9(2)VALUE 25.

Format-1:01 A PIC 9(3)VALUE 25. DISPLAY A.MAINFRAME MATERIAL . O\P . DB2. AND CICS AUTHOR .2 Format-2:01 A PIC 9(3)VALUE 25. O\P .250 Format-2:01 A PIC 9(3)VALUE 25. DISPLAY B. 01 B PIC 9(3)VALUE 10. Format-1:01 A PIC 9(3)VALUE 25.K PHANI KUMAR. MUPLTIPLY 10 BY A. 01 C PIC 9(3). O\P . 11 . 01 B PIC 9(3)VALUE 10.25 10 250 DIVIDE VERB • DIVIDE verb is used for Division. O\P . DISPLAY A. MUPLTIPLY A BY B GIVING C. DIVIDE 10 INTO B. DISPLAY A.COBOL. DISPLAY C.25 15 -10 ==> Here A & B values are not changed and result stored in C MULTIPLY VERB • MULTIPLY verb is used for Multiplication.

And also we can use it for assigning a value to a variable. DISPLAY C. 9(3). 01 C PIC 01 D PIC 9(3). 05 WS-AUG28-TODAY-DAY PIC 9(3). DIVIDE A INTO B GIVING C REMAINDER D. DB2. ExCOMPUTE A = 100. REDEFINE CLAUSE • Ex:01 01 WS-AUG28-TODAY-DATE PIC 9(7). 05 WS-AUG28-TODAY-CENTURY PIC 9(2). SUBTRACT. O\P . DISPLAY B. So for doing this we can use COMPUTE verb. AND CICS AUTHOR . REDEFINE clause is used to redefine the same memory location with different names and also with different data types. MULTIPLY and DIVIDE verbs. DISPLAY A. WS-AUG28-TODAY-REF REDEFINES WS-AUG28-TODAY-DATE. DISPLAY C. 12 .25 10 2 5 COMPUTE VERB • • For doing large arithmetic operations we can’t use the ADD.MAINFRAME MATERIAL . COMPUTE A = (B+C)/E.COBOL. 05 WS-AUG28-TODAY-YEAR PIC 9(2).K PHANI KUMAR.

05 WS-REST-OF-CARD-NUM PIC 9(12). 13 . 01 01 WS-CARD-NUMBER PIC X(16).K PHANI KUMAR. WS-CARD-NUMBER-REF REDEFINES WS-CARD-NUMBER. If the condition is false then it will directly execute the statement-X. 05 WS-NETWORK-NUMBER PIC 9(4). DB2.MAINFRAME MATERIAL .COBOL. 2 and 3. Statement-X. AND CICS AUTHOR . Here if the condition is true then it will execute the statements1. Format-2:IF <CONDITION> THEN Statement1 Statement2 Statement3 ELSE Statement4 Statement5 Statement6 END-IF. IF STATEMENT • IF statement is used for decision making in COBOL. Format-1:IF <CONDITION> THEN Statement1 Statement2 Statement3 END-IF. ExIF AMT > 0 DISPLAY ‘AMOUNT IS POSITIVE ‘ AMT ELSE DISPLAY ‘AMOUNT IS NEGATIVE ‘ AMT END-IF.

COBOL. Format-1: .In this format the control will go to the specified paragraph and executes all the statements mentioned in that and returns back to the statement after the PERFORM.K PHANI KUMAR. Format-2:ExEVALUATE SQLCODE WHEN 0 DISPLAY ‘DB2 QUERY SUCCESSFULLY COMPLETED’ WHEN 100 DISPLAY ‘ROW NOT FOUND’ WHEN -811 DISPLAY ‘MULTIPLE ROWS FOUND’ WHEN OTHER DISPLAY ‘UNKNOWN ERROR WHILE EXECUTING THE TRANSACTION’ END-EVALUATE. Format-1:ExEVALUATE TRUE WHEN SQLCODE = 0 DISPLAY ‘DB2 QUERY SUCCESSFULLY COMPLETED’ WHEN SQLCODE = 100 DISPLAY ‘ROW NOT FOUND’ WHEN SQLCODE = -811 DISPLAY ‘MULTIPLE ROWS FOUND’ WHEN OTHER DISPLAY ‘UNKNOWN ERROR WHILE EXECUTING THE TRANSACTION’ END-EVALUATE. This is like a CASE statement in C language. We have 5 different types of PERFORM statements. 14 . • EVALUATE STATEMENT EVALUATE statement is also used for decision making in COBOL. • It calls the Paragraph only one time in this case. PERFORM B-CALCULATE-SALARY.MAINFRAME MATERIAL . AND CICS AUTHOR . DB2. PERFORM STATEMENTS • PERFORM statement is used for conditional branching in COBOL.

AND CICS AUTHOR . PERFORM B-CALCULATE-SALARY UNTIL UNTIL END-OF-FILE = ‘YES’. DB2.K PHANI KUMAR. PERFORM B-CALCULATE-SALARY UNTIL 10 TIMES.In this format the control will go to the specified paragraph and executes all the statements mentioned in that UNTIL a specified number of times and then returns back to the statement after the PERFORM. PERFORM B-CALCULATE-SALARY VARYING CTR FROM 1 BY 1 UNTIL CTR > 10.In this format the control will go to the specified paragraph and executes all the statements mentioned in that UNTIL a specified condition is TRUE. 15 .COBOL.MAINFRAME MATERIAL . (BY 1). Format-4: . • It calls the Paragraph until a specified condition is TRUE. In this example the CTR starts from 1 and for each iteration it will increment with value 1. Format-3: .In this format the control will go to the specified paragraph and executes all the statements mentioned in that UNTIL a specified condition is TRUE. Format-2: . Here it will maintain a counter and increments it to the value specified for each iteration. • It calls the Paragraph 10 Times.

K PHANI KUMAR. DB2. DISPLAY ‘ INDIA ‘.COBOL. STOP RUN.MAINFRAME MATERIAL . 100-MAIN-PARA. 300-UK-PARA. DISPLAY ‘START OF PROGRAM’. STOP RUN. PERFORM 200-INDIA-PARA. 400-USA-PARA. 200-INDIA-PARA. DISPLAY ‘ UK ‘. DISPLAY ‘END OF PROGRAM’. O\P INDIA INDIA INDIA Ex-3:PROCEDURE DIVISION. DISPLAY ‘ INDIA ‘. PERFORM 200-INDIA-PARA THRU 400-USA-PARA UNTIL WS-FLAG = ‘YES’ DISPLAY ‘END OF PROGRAM’. O\P INDIA Ex-2:PROCEDURE DIVISION. DISPLAY ‘END OF PROGRAM’. PERFORM 200-INDIA-PARA UNTIL 3 TIMES. AND CICS AUTHOR . DISPLAY ‘ INDIA ‘. MOVE ‘YES’ TO WS-FLAG. 200-INDIA-PARA. O\P INDIA UK USA 16 . DISPLAY ‘ USA ‘. 200-INDIA-PARA. STOP RUN. DISPLAY ‘START OF PROGRAM’. 100-MAIN-PARA. DISPLAY ‘START OF PROGRAM’. 100-MAIN-PARA. Ex-1:PROCEDURE DIVISION.

100-MAIN-PARA. EXIT. EXIT. STOP RUN. DISPLAY ‘ INDIA ‘. PERFORM 200-INDIA-PARA THRU 400-USA-PARA UNTIL WS-FLAG = ‘YES’ STOP RUN. EXIT PROGRAM. DB2. 17 . EXIT. PROCEDURE DIVISION. 200-INDIA-PARA. STOP RUN. EXIT. • And the control goes back to the OS. 100-EXIT. PROCEDURE DIVISION. STOP RUN: • This statement is used to indicate its end of the program. EXIT PROGRAM AND GOBACK EXIT: • This statement is used to indicate its end of the paragraph.COBOL. AND CICS AUTHOR . 100-EXIT. EXIT.K PHANI KUMAR. 100-MAIN-PARA. Must be used in the Sub-programs. EXIT • • • PROGRAM AND GO BACK: This statement is also used to indicate its end of the program. PROCEDURE DIVISION.MAINFRAME MATERIAL . Control will goes back to the main program from where it’s called. 100-MAIN-PARA. 200-EXIT. 100-EXIT. DISPLAY ‘HELLOW IBM MAINFRAMES‘. DISPLAY ‘HELLOW IBM MAINFRAMES‘.

MAINFRAME MATERIAL .K PHANI KUMAR. WS-C. WS-B. LINKAGE SECTION. the sub-program has to make the below changes. SUB PROGRAMS • In COBOL CALL is statement is used to transfer the control from Main program to Sub-programs. • BY VALUE . DB2. o We need to define the No of arguments that we want to receive in the LINKAGE SECTION of the Sub-program. WS-B.You have to specify this explicitly while calling the sub-program. In this we are just passing the value of a variable and if any change to that variable in the sub-program that will not be reflected in the main program. AND CICS AUTHOR .This is the default one and in this if you change a variable in the Sub-Program that will be reflected in the Main Program automatically. o BY REFERENCE o BY VALUE o BY CONTENCT • BY REFERENCE .You have to specify this explicitly while calling the sub-program. WS-C. WS-B. There are three ways of calling a sub-program.COBOL. (OR) CALL ‘CR2510’ BY REFERENCE USING WS-A. • BY CONTENT . Changes in the Sub-Program:To receive the data passed from main program. WS-C. CALL ‘CR2510’ BY VALUE USING WS-A. WS-C. CALL ‘CR2510’ BY CONTENT USING WS-A. 18 . WS-B. CALL ‘CR2510’ USING WS-A. In this we are just passing the value of a variable and sub-program is not allowed to change the value of this variable.

A-EXIT. AND CICS AUTHOR . 05 LS-A 05 LS-B 05 LS-C PIC 9(2). O\P:VALUE OF A BEFORE CALLING SUB PROGRAM 30 VALUE OF A AFTER CALLING SUB PROGRAM 45 Sub-Programs are called using the below methods.MAINFRAME MATERIAL . SUB PROGRAM. DISPLAY 'VALUE OF A BEFORE CALLING SUB PROGRAM' WS-A. PROGRAM-ID. LS-B. PROGRAM-ID. 1. o PROCEDURE DIVISION USING LS-A. IDENTIFICATION DIVISION. LS-C. ENVIRONMENT DIVISION.COBOL. EXIT. PROCEDURE DIVISION. STOP RUN. PIC 9(2). LINKAGE SECTION. DISPLAY 'VALUE OF A AFTER CALLING SUB PROGRAM' WS-A. CALL 'SUB-PGM1' USING WS-A. 01 DATA. DB2. MAINPGM. STATIC CALL 19 . A-EXIT. PIC 9(2). DATA DIVISION. A-START. DATA DIVISION. WORKING-STORAGE SECTION. A-START. EXIT. 01 LS-A PIC 9(2). EXIT PROGRAM. Ex:MAIN PROGRAM IDENTIFICATION DIVISION. 01 WS-A PIC 9(2) VALUE 30. ENVIRONMENT DIVISION. PROCEDURE DIVISION USING LS-A. MOVE 45 TO LS-A.K PHANI KUMAR. SUB-PGM1.

In Dynamic Call. o Programs are called using ‘PGM-NAME’. DB2. programs are called as below. AND CICS AUTHOR . 2. (Embedded in Quotes). o As the main program and sub programs load module will be in one load module execution is faster. If one OCCCURS clause is there that means its ONE-DIMENSIONAL ARRAY. o In Static Call main program and Sub program will be having the same load module.MAINFRAME MATERIAL . MOVE ‘SUB-PGM1’ TO WS-PGM-NAME CALL WS-PGM-NAME USING WS-A. o The compiler option NODYNAM have to be used.In Static Call. We can define the TABLE using the OCCURS clause in COBOL. How to define the ONE-DIMENSTIONAL ARRAYS:20 . Disadvantages: o If there is a change in one sub-program. programs are called as below. o Programs to be called will be come to know at run time. You can’t define the OCCURS clause in the 01 level.COBOL. o If there is a change in the sub-program then only sub-program has to be recompiled. o The compiler option DYNAM has to be used. o In Dynamic Call main program and Sub program will be having the separate load modules. DYNAMIC CALL STATIC CALL: . all the programs has to be compiled to get the latest load module.K PHANI KUMAR. TABLE HANDLING • • • • • • In COBOL arrays handling is called as Table handling. If two OCCCURS clauses are there that means its TWO-DIMENSIONAL ARRAY and so on. You can define up to 7 OCCURS clauses in COBOL. o The length of the load module is big as it contains all the programs load modules. DYNAMIC CALL: . Disadvantages: o As the load modules are different to pick up the load module of sub program into memory for execution takes a bit time. CALL 'SUB-PGM1' USING WS-A.

In the above example there 30 students in the class and for each Student there are 6 subjects. SEARCH operates with the occurrence of an element. The above example defines 1-D table where it can store up to 24 rows where is row size is 3 bytes. 01 STATE-TAB. How to define the ONE-DIMENSTIONAL ARRAYS DYNAMICALLY:01 STATE-TAB.MAINFRAME MATERIAL . 21 .K PHANI KUMAR. OCCURS 6 TIMES. Then INDEX is used for checking or retrieving the records in a faster manner. 05 NAME 10 SUBJECT PIC X(20) PIC 9(3) OCCURS 30 TIMES. STATE-TAB. 05 DIST-NAME PIC X(3) OCCURS 1 TO 100 TIMES DEPENDING ON WS-VAL. DB2. What is SEARCH and SEARCH ALL? SEARCH 1. We need to set the INDEX variable to 1. 05 DIST-NAME PIC X(3) OCCURS 24 TIMES.3 * 24 ==> 72 bytes How to define the TWO-DIMENSTIONAL ARRAYS:01 STUDENT-TAB. How • • • • to define the TABLE with INDEX option:INDEX is used to create the INDEX in the table. Total Size .COBOL. If the WS-VAL contains 30 then it will defines up to 30 rows only. 01 Why we use INDEX? INDEX is used when we want to do a SEARCH for a particular string in the table. AND CICS AUTHOR . SEARCH is Sequential search. 2. 05 DIST-NAME PIC X(5) OCCURS 24 TIMES INDEX BY IDX. To increment or decrement the value of the INDEX variable we need to use SET UPBY or SET DOWNBY keywords. • We don’t need to declare the index variables separately in the WORKINGSTORAGE SECTION.

If the table size is very huge then go for the SEARCH ALL. 3. We can use any WHEN conditions in SEARCH. 7.COBOL. We can use only equal operator in SEARCH. We can use any relational operators in SEARCH. 6. SEARCH ALL1. 5. o Sort work file  This file is required if the input file contains huge records to sort.SORT DESCRIPTION For doing the SORT we required 3 files. 4. DB2. This is the faster way searching an element. In SEARCH the data needs to be in sorted order. SEARCH operates with the displacement (Address) of an element. For sorting we need to define the SORT work files in the JCL. If we do the sorting in the JCL using the utility SORT then it’s called the EXTERNAL sort. We can use only one WHEN condition in SEARCH. The SORT work files will be represented in the COBOL program using the SD SD .MAINFRAME MATERIAL . In SEARCH the data need not in sorted order. o Input file o Output file Syntax:SORT work-file ON ASCENDING KEY key-name USING ip-file GIVING op-file. 4. 22 .K PHANI KUMAR. 3. SEARCH DIST-NAME(IDX) AT END DISPLAY ‘NAME NOT FOUND’ WHEN DIST-NAME(IDX) = ‘HYD’ DISPLAY ‘NAME FOUND’ NOT AT END SET IDX UPBY 1 END-SEARCH INTERNAL SORT • • • • • • If we do the SORTING in the COBOL program then it’s called the INTERNAL sorting. EX:SET 1 TO IDX. AND CICS AUTHOR . 5. 2. SEARCH ALL is Binary search.

OS will places the status code in the variable declared using FILE STATUS. REWRITE. Use one off the statements (READ. AND CICS AUTHOR . 1. Close the file using the statement CLOSE. OUTPUT. Declare the files in the INPUT-OUTPUT SECTION of ENVIRONMENT DIVISION.COBOL. So we need to mention ORGANIZATION and ACCESS MODE as SEQUENTIAL. Hence mention the below values for KSDS.To read the records from the file 2. FILE-CONTROL. ENVIRONMENT DIVISION. I-O. SELECT IN-FILE ASSIGN TO INDD ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-IN-FILE-STAT. OPEN the file in one off the modes (INPUT. All the files used in the JCL needs to be declared in the ENVIRONMENT DIVISION and also in the DATA DIVISION. INPUT . 23 . the records will be organized based on the Index order and accessed Sequentially or Dynamically or Randomly. OUTPUT . I-O . • After every operation on the file. 1. • PS FILE:• In PS file. We can OPEN the file in the below modes. 3. the records will be organized in Sequential order and accessed in Sequential order only. CONFIGURATION SECTION. • ORGANIZATION IS INDEXED • ACCESS MODE IS SEQUENTIAL\RANDOM\DYNAMIC • And also you need to mention the Key as below. Declare the file attributes in the FILE SECTION of DATA DIVISION. FILE HANDLING • • • COBOL can handle PS files and VSAM files.MAINFRAME MATERIAL . Follow the below steps in order to use the files in the COBOL program. EXTEND -To append the records at the bottom of the file. EXTEND) 4. 2.To write the records into the file 3. DELETE) 5.To read and write the records 4. WRITE. KSDS FILE:• In KSDS file.K PHANI KUMAR. INPUT-OUTPUT SECTION. DB2.

the records will be organized based on the Entry and accessed sequentially. DB2. • RECORD KEY IS EMP-ID.COBOL. Hence mention the below values for ESDS. Ex-3 ENVIRONMENT DIVISION. Ex-2 ENVIRONMENT DIVISION. Ex-1 ENVIRONMENT DIVISION. CONFIGURATION SECTION. SELECT IN-FILE ASSIGN TO AS-ESDS-DD ORGANIZATION IS SEQUENTIAL 24 . CONFIGURATION SECTION. FILE-CONTROL. ESDS FILE:• In ESDS file. FILE-CONTROL. SELECT IN-FILE ASSIGN TO KSDS-DD ORGANIZATION IS INDEXED ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-IN-FILE-STAT. AND CICS AUTHOR .K PHANI KUMAR. INPUT-OUTPUT SECTION. CONFIGURATION SECTION. Ex-1 ENVIRONMENT DIVISION. CONFIGURATION SECTION. SELECT IN-FILE ASSIGN TO KSDS-DD ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC FILE STATUS IS WS-IN-FILE-STAT. SELECT IN-FILE ASSIGN TO KSDS-DD ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM FILE STATUS IS WS-IN-FILE-STAT. INPUT-OUTPUT SECTION.MAINFRAME MATERIAL . INPUT-OUTPUT SECTION.before the DDNAME. FILE-CONTROL. • ORGANIZATION IS SEQUENTIAL • ACCESS MODE IS SEQUENTIAL • To differentiate the PS file and ESDS file you need to put AS. FILE-CONTROL. INPUT-OUTPUT SECTION.

MAINFRAME MATERIAL . RRDS FILE:• In RRDS file. DB2. Syntax to READ from the file: READ IN-FILE INTO WS-IN-REC AT END MOVE ‘YES’ END-READ. SELECT IN-FILE ASSIGN TO RRDS-DD ORGANIZATION IS RELATIVE ACCESS MODE IS SEQUENTIAL \ RANDOM \ DYNAMIC FILE STATUS IS WS-IN-FILE-STAT. FILE-CONTROL. ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-IN-FILE-STAT. Syntax to OPEN the file: OPEN OPEN OPEN OPEN INPUT OUTPUT I-O EXTEND IN-FILE OUT-FILE IN-FILE IN-FILE IF WS-IN-FILE-STAT = ‘00’ CONTINUE ELSE DISPLAY ‘ERROR IN OPENING THE FILE’ END-IF. CONFIGURATION SECTION. INPUT-OUTPUT SECTION. • ORGANIZATION IS RELATIVE • ACCESS MODE IS SEQUENTIAL \ RANDOM \ DYNAMIC Ex-1 ENVIRONMENT DIVISION. Hence mention the below values for RRDS. Syntax to WRITE into the file: 25 TO EOF . AND CICS AUTHOR .COBOL. the records will be organized based on the relative number and accessed sequentially or randomly or dynamically.K PHANI KUMAR.

77 WS-STAT-1 PIC X(2). FILE SECTION. IDENTIFICATION DIVISION. CONFIGURATION SECTION. 77 EOF-IN PIC X(3). SELECT OUT-FILE ASSIGN TO OUT-DD ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-STAT2.K PHANI KUMAR. 01 IN-REC PIC X(80). Example program to read from the PS file and write into the PS file. 05 WS-IN-SALARY PIC 9(5). 05 WS-OUT-EID PIC 9(5). PERFORM 300-READ-INFILE UNTIL EOF-IN = 'YES'. DATA DIVISION. DISPLAY ' PROGRAM STARTED '. 01 WS-OUT-REC. FD IN-FILE. WRITE OUT-FILE-REC FROM IN-FILE-REC. 77 WS-STAT-2 PIC X(2). PROGRAM-ID. 05 WS-IN-EID PIC 9(5). 05 WS-OUT-ADDR PIC X(30). 26 .COBOL. 05 WS-IN-ENAME PIC X(30). PROCEDURE DIVISION. ENVIRONMENT DIVISION. 05 WS-OUT-SALARY PIC 9(5). 05 WS-OUT-ENAME PIC X(30). 05 WS-OUT-DEPTNAME PIC X(10). 01 WS-IN-REC. PSFILE. FD OUT-FILE. SELECT IN-FILE ASSIGN TO IN-DD ORGANIZATION IS SEQUENTIAL ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-STAT1.MAINFRAME MATERIAL . AND CICS AUTHOR . 100-INITIAL-PARA. FILE-CONTROL. DB2. 01 OUT-REC PIC X(80). INPUT-OUTPUT SECTION. 05 WS-IN-ADDR PIC X(30). LABEL RECORDS ARE STANDARD RECORD CONTAINS 80 CHARACTERS BLOCK CONTAINS 0 RECORDS. LABEL RECORDS ARE STANDARD RECORD CONTAINS 80 CHARACTERS BLOCK CONTAINS 0 RECORDS. 05 WS-IN-DEPTNAME PIC X(10). PERFORM 200-OPEN-FILES. WORKING-STORAGE SECTION.

EXIT. 300-READ-INFILE.K PHANI KUMAR.MAINFRAME MATERIAL . OUT-FILE. IF WS-STAT2 = '00' CONTINUE ELSE DISPLAY ' ERROR IN OPENING OUTPUT FILE ' STOP RUN END-IF. DB2. IF WS-STAT1 = '00' CONTINUE ELSE DISPLAY ' ERROR IN OPENING INPUT FILE ' STOP RUN END-IF. 200-EXIT. EXIT. EXIT. MOVE MOVE MOVE MOVE MOVE WS-IN-EID WS-IN-ENAME WS-IN-ADDR WS-IN-SALARY WS-IN-DEPTNAME TO EOF-IN TO TO TO TO TO WS-OUT-EID WS-OUT-ENAME WS-OUT-ADDR WS-OUT-SALARY WS-OUT-DEPTNAME WRITE OUT-REC 300-EXIT. STOP RUN. 100-EXIT. 27 . AND CICS AUTHOR . READ INFILE INTO WS-IN-REC AT END MOVE 'YES' END-READ. 400-CLOSE-FILES. PERFORM 400-CLOSE-FILES. DISPLAY ' PROGRAM ENDED '. CLOSE IN-FILE.COBOL. 400-EXIT. EXIT. 200-OPEN-FILES. FROM WS-OUT-REC. OPEN INPUT IN-FILE OUTPUT OUT-FILE.

COBOL. 1. DB2 SQL commands are categorized into 3 types. and alter the tables.DATA DEFINITION LANGUAGE 2. DB2 . • Storage Groups • Databases • Table spaces • Tables 28 .MAINFRAME MATERIAL . And Table contains data in Rows and Columns. Rows are called as Records and Columns are called as Fields. DB2 is a RDBMS (Relational Database Management System) which contains Tables.DATABASE 2 • • • DB2 is called as Universal Database as it can be accommodated with any operating system or any programming language. DML . CREATE ALTER DROP DECLARE CREATE: .DATA MANIPULATION LANGUAGE 3.This statement is used to create the following db2 objects.These statements are used to create.K PHANI KUMAR. drop. DDL .DATA CONTROL LANGUAGE DATA DEFINITON LANGUAGE . AND CICS AUTHOR . DB2. DCL .

16KB. Partitioned Table space . o Simple Table space o Segmented Table space o Partitioned Table space Simple Table space . At installation.K PHANI KUMAR. 8KB. • There are 3 types of Table spaces. 32KB.Here the space is divided into equal parts called as segments and each segment contains rows from only table.MAINFRAME MATERIAL .Here the space is divided into Partitions and each partition is assigned to only one table. This storage group is named SYSDEFLT. • The DB2 catalog table SYSIBM. The Volumes hold the data sets in which tables and indexes are actually stored. DB2. the system default storage group is defined. Data base: • A data base is stored in the Storage group • A data base contains the table spaces. AND CICS AUTHOR . • In this the space is divided into pages and each page size is 4 KB. then DB2 uses the default storage group to allocate space. If you do not explicitly manage your storage.Here the table space contain more than one tables.SYSVOLUMES contains a row for each DASD volume. Segmented Table space .COBOL. 29 . Table Spaces: • A table space contains the tables and is to be stored in the data base.SYSSTOGROUP contains a row for each storage group that you define. • • • • Indexes Triggers Views Stored Procedures Storage Group: • A Storage Group is a group of volumes on DASD (direct access storage device). and the table SYSIBM. Default is 4KB.

CREATE TABLESPACE SALESHX IN MYDB USING STOGROUP MYSTOGRP PRIQTY 4000 SECQTY 130 ERASE NO DSSIZE 16G NUMPARTS 48 (PARTITION 46 ==> PARTITIONED TABLE SPACE COMPRESS YES. PARTITION 48 COMPRESS YES) LOCKSIZE PAGE BUFFERPOOL BP1 CLOSE NO. DB2. How to create the Table space:CREATE TABLESPACE MYTS IN MYDB USING STOGROUP MYSTOGRP PRIQTY 30720 SECQTY 10240 SEGSIZE 32 ==> SEGEMENTED TABLE SPACE LOCKSIZE TABLE BUFFERPOOL BP0 CLOSE NO. PARTITION 47 COMPRESS YES.COBOL. EMP_LAST_NAME CHAR(25). Table • A table can contain the data in the form of rows and columns. DEPT CHAR(10) ) USING FSSADMDB.FSSADMTS 30 .K PHANI KUMAR.MAINFRAME MATERIAL . EMP_FIRST_NAME CHAR(30). CREATE TABLE EMPLOYEE ( EMP_ID SMALLINT NOT NULL PRIMARY KEY.2). where the table space is stored in the Database. How to create the Table:• In IBM-DB2 the table has to be stored in the Table space. AND CICS AUTHOR . SALARY DECIMAL(5.

EMPLOYEE (EMP_ID ASC) USING STOGROUP DSN8G910 PRIQTY 512 SECQTY 64 ERASE NO BUFFERPOOL BP1 CLOSE YES DB2 keys:Unique Keys • A unique key contains the unique values • You can have any number of Unique keys in a table • A Unique key can’t contain null values Primary Keys • A Primary key is a special Unique key • It also does not contain any unique values • And you should have only one Primary key for a table.MAINFRAME MATERIAL .Here EMPNO is the PK and DEPTNO is the FK PK DEPTN O C01 D11 E21 PK EMPNO LASTNAM E FK DEPTNAM MGRN E O PAYROLL 30 FINANCE 60 ADMIN ----FK DEPTN O ROLE 31 . EMPLOYEE. EMPLOYEE table .EMPXDX ON FSS106DB. DEPT table . How to define the Primary Key separately CREATE UNIQUE INDEX FSS106DB.K PHANI KUMAR. In the below figure we have two tables DEPT. AND CICS AUTHOR .Here DEPTNO is the PK and MGRNO is the FK. DB2. Foreign Key • A Foreign key enforces a relation between two tables.COBOL.

This is used for controlling the data stored on the database.MAINFRAME MATERIAL . INSERT access only to the user id FSS117.This is used for controlling the access on the db2 objects.To give the access to a particular user id or to all the users on the db2 objects we use this command. ALTER TABLE EMPLOYEE DROP .K PHANI KUMAR. 2. 1. DROP TABLE EMPLOYEE DROP INDEX EMPIDX DATA CONTROL LANGUAGE . GRANT ON TABLE EMPLOYEE SELECT. 30 KUMAR 200 BROWN 340 JOHN C01 D11 E21 MGR SE SSE ALTER . 3. INSERT TO FSS117  This will give the SEELCT. DB2. REVOKE . table space and other objects. SELECT INSERT UPDATE DELETE 32 . GRANT . AND CICS AUTHOR .this command is used to alter the table. GRANT ON TABLE EMPLOYEE ALL TO PUBLIC  This will give all the accesses to all the users.This command is used to drop the table. GRANT.COBOL. When we drop the table all the rows and columns of it will be automatically deleted. REVOKE are the commands used in this language. 4. DATA MANIPULATION LANGUAGE .Is used to revoke the access.

EMPNAME FROM EMPLOYEE  This will return only the columns EMPID. 1. WHERE clause . NOT) SELECT EMPID.  This will give rows where BETWEEN Operator . EMPID . SELECT EMPID.SELECT statement is used to get all the data or required data from the tables. SELECT .K PHANI KUMAR.MAINFRAME MATERIAL . DB2. IN Operator . EMPNAME from EMPLOYEE table. EMPNAME FROM EMPLOYEE WHERE EMPID = 1001. SELECT EMPID. EMPNAME. EMPNAME. 3. OR.COBOL. SELECT DISTINCT(DEPTNAME) FROM DEPT  This will eliminate the duplicate rows from DEPTNAME column and display the result.1001 & 1002. SELECT EMPID. Types of SELECT statements:SELECT * FROM EMPLOYEE  This will return all rows & columns from the EMPLOYEE table 2. SALARY FROM EMPLOYEE WHERE EMPID BETWEEN 1001 AND 1100  This will retrieve all the rows where EMPID is in between 1001 to 1100. AND CICS AUTHOR .This will check the list of values and display only the matched rows.This will check the range of values and display only the matched rows. SALARY FROM EMPLOYEE 33 . SELECT EMPID. 1001  This will give only one row where EMPID - You can also use any logical operator (AND.The WHERE clause is used for checking the condition before retrieving the results from the table. EMPNAME FROM EMPLOYEE WHERE EMPID = 1001 AND EMPID = 1002.

_  To check for a particular character. AND CICS AUTHOR . 1. LIKE Operator . 1100. If we want find the rows where the EMPNAME starts with KUMAR. SALARY FROM EMPLOYEE WHERE EMPNAME LIKE ‘__M%’  Here first two characters are (_) and then written the 3rd character as M and then %.1010.1100)  This will retrieve all the rows where EMPID is in the list 1001. EMPNAME.LIKE operator is used with the character data types and is used to check for the wild card strings. EMPNAME. SELECT COUNT(*) FROM EMPLOYEE  This will return the number of rows (Including duplicate) SELCT COUNT(DISTINCT *) FROM EMPLOYEE  This will return the number of rows (Excluding duplicate) AVG .COBOL. Ex1 . MIN 5.1003. SELECT EMPID. AVG 3.K PHANI KUMAR.MAINFRAME MATERIAL . 1010. COUNT 2. SELECT AVG(SALARY) FROM EMPLOYEE  This will return the average salary of each employee 34 . DB2. 1003.This function is used to find the average value of a column. DB2 Column functions Below are the most common used DB2 column functions. MAX 4. WHERE EMPID IN (1001. SUM COUNT . SELECT EMPID.This function is used to count the number of rows in a db2 table. SALARY FROM EMPLOYEE WHERE EMPNAME LIKE ‘KUMAR%’  This will retrieve all the rows where EMPNAME starts with the string KUMAR • • %  Wild card character which checks for the entire string.Retrieve all the rows where 3rd character of the EMPNAME is M.

To find the average salary of each department from the EMPLOYEE table. SELECT DEPTNAME.K PHANI KUMAR. HAVING .This will return the minimum value of a column. AVG(SALARY) FROM EMPLOYEE GROUP BY DEPTNAME ORDER BY DEPTNAME DESC.This clause is used to group the result records into one row and display the result. AVG(SALARY) FROM EMPLOYEE GROUP BY DEPTNAME ORDER BY . SELECT MAX(SALARY) FROM EMPLOYEE  This will give the maximum salary from the EMPLOYEE table. SELECT MIN(SALARY) FROM EMPLOYEE  This will give the minimum salary from the EMPLOYEE table.This will add the values of a column and produce the sum.This will return the maximum value of a column. MIN . SELECT SUM(SALARY) FROM EMPLOYEE  This will produce the sum of all the employee’s salary.HAVING clause is used to check the condition on the result rows and then display only the matching rows. 35 .This clause is used to display the results in Ascending or Descending order. Ex .INSERT statement is used to insert the rows into the DB2 table. GROUP BY . Difference between WHERE and HAVING? • • The WHERE clause selects rows before grouping and HAVING clause selects rows after grouping. SELECT DEPTNAME. DB2. SUM . AND CICS AUTHOR .COBOL. INSERT . MAX .MAINFRAME MATERIAL . The WHERE clause can be used without GROUP BY clause and HAVING has to be used with the GROUP BY clause.

1.UPDATE statement is used to update the columns of the DB2 table. 'ARCHITECTURE'. UPDATE . If SQLCODE = -803 then it means a duplicate record exist. DELETE FROM EMPLOYEE WHERE EMPID = 1001  Deletes only one row. AND CICS AUTHOR . • INSERT INTO DEPARTMENT VALUES ('E31'.K PHANI KUMAR. • The INSERT using n ROWS form is used to insert multiple rows into the table or view using the values provided in a host-structure-array.MAINFRAME MATERIAL . DELETE . DB2. 'E01') INSERT INTO MA_EMPPROJACT SELECT * FROM EMPPROJACT INSERT INTO DEPARTMENT 10 ROWS VALUES (:DEPT) INSERT INTO EMPPROJACT VALUES ('000140'. There are three forms of this statement: The INSERT using VALUES form is used to insert a single row into the table or view using the values provided or referenced. 'PL2100'. UPDATE EMPLOYEE SET SALARY = 10000 WHERE EMPID = 1001. 30) WITH CHG If a row is inserted into the DB2 table you will get the SQLCODE = 0 to indicate it has inserted successfully. COMPILATION PROCESS The compilation process for COBOL-DB2 program includes various steps. PRE COMPILATION 36 .DELETE statement is used to delete the rows of the DB2 table.COBOL. DELETE FROM EMPLOYEE  Deletes all the rows from Employee table.  This will set the salary to 10000 for the EMPID 1001 UPDATE EMPLOYEE SET SALARY = SALARY + 1000  This will increment the salary of all the employee’s to 10000. • The INSERT using SELECT form is used to insert one or more rows into the table or view using values from other tables or views. '00390'.

PACKAGE 2. • A Package can’t be executable so we need to have the PLAN to execute a Cobol-DB2 program. PLAN • A PLAN take one or more DBRMs or one or more PACKAGEs as input and produces the application plan. • And it places a TIME STAMP on the DBRM module. 4. 5. COMPILATION LINK EDIT BIND EXECUTE PRE COMPILATION • In this process the compiler checks for the all the SQL statements which are embedded within the EXEC SQL and END-EXEC statements and puts into a module called as DBRM. It contains two types. 3.K PHANI KUMAR. 2. AND CICS AUTHOR .COBOL. PACKAGE • A PACKAGE takes DBRM as input and produces a single package containing the optimized access path logic. 1.BIND reads the sql statements from DBRM and produces the access path logic to retrieve the data from DB2. • The Package then can be bound into Plan using BIND PLAN command. • A PLAN is required to execute the COBOL-DB2 program. PLAN. • And converts all the SQL statements into COBOL CALL statements. • The advantage of the PACKAGE is if one of the program is changed instead of binding the entire plan will just BIND the impacted program. DB2. Parameters used in the BIND card BIND PLAN(FSS106) MEMBER(CRC210A0) ACTION(REP) ACQUIRE(USE) RELEASE(COMMIT) 37 . COMPILATION • It will do a normal Compilation BIND .MAINFRAME MATERIAL . So it will save the binding time and cost.

REP . when your program execution is completed. DELETE. ACTION .To add the member name into the PLAN list. This option is not allowed when it’s BIND or REBIND. RELEASE(COMMINT) . There are four types of ISOLATION levels. RELEASE(DEALLOCATE) . 2.COBOL.You can use two options here ADD . ACQUIRED(USE) . AND CICS AUTHOR .Acquires the lock when the object is first accessed. 2. DB2. CURSOR STABILITY . MEMBER . CURSOR STABILITY READ STABILITY REPEATABLE READ UNCOMMITED READ 1. UPDATE operations from other processes until the first process is end. 4. ACQUIRE(ALLOCATE) . Nothing but your program name. 3. ACQUIRE and RELEASE These two options of BIND will determine when to lock the db2 object (Table.Your DBRM name has to give here.To replace the already existing member name in the PLAN list. ISOLATION(CS) OWNER(FSS106) PLAN name .Here in Training we give the plan name as the user id. 1.In this DB2 locks all the rows of the table and does not allow any INSERT.MAINFRAME MATERIAL . 38 . Partition or Tablespace) and when to release the lock on the db2 object. READ STABILITY .K PHANI KUMAR. Once the page scan is done then it will release the lock and then move to the next page.Acquires the lock when the DB2 object is allocated.Releases the lock when there is an explicit COMMIT statement in your program.e.In this DB2 locks the table on the page wise and this is the default lock. ISOLATION LEVELS The ISOLATION option on the BIND card determines the types of locking the table.In this DB2 locks each row on the table and does not allow any process until the lock is released.Releases the lock when the object is deallocated i. 3. REPEATABLE READ .

COPY statement expands the copybooks at the time of compilation stage. • EMPLOYEE TABLE ENO 1001 1002 1003 1004 1005 1006 1007 NAME PHANI KUMAR INDRA REDDY MAHESH RAGHU RAGHAV SALARY 30000 45000 22000 48000 12300 26300 87564 DEPTNO D001 D001 D002 D002 D001 D003 D003 39 . INCLUDE and COPY statements INCLUDE and COPY statements are used to include the copybooks in the COBOL program. In this case you will go for the JOIN to combine two tables and retrieve the required columns. LEFT OUTER JOIN 3.K PHANI KUMAR. INNER JOIN OR SIMPLE JOIN 2. FULL OUTER JOIN Or OUTER JOIN You need to write the JOIN in the FROM clause of SELECT statement. 1.COBOL. RIGHT OUTER JOIN 4. So all your SQL copybooks should be mentioned using the INCLUDE statement. • DB2 supports below joins. Ex - EXEC SQL INCLUDE SQLCA END-EXEC. INCLUDE statement expands the copybooks in the pre-compilation stage. DB2. 4.MAINFRAME MATERIAL . so if there are db2 errors it will not be caught at the time of pre-compilation stage. UNCOMMITED READ .In this DB2 locks all the rows of the table and does not allow any other processes until an explicit commit is done. AND CICS AUTHOR . JOINS Sometimes you may required to retrieve some columns from TABLE-1 and some columns of TABLE-2.

DEPT B WHERE A.NAME. LEFT OUTER JOIN 40 .MAINFRAME MATERIAL . A.K PHANI KUMAR.1011 as there is no department like ---.DEPTNAE FROM EMPLOYEE A. B.NAME.It has display only the 10 rows of EMPLOYEE table and has not displayed ENO . AND CICS AUTHOR . DB2.ENO. B.DEPTNO O\P ENO 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 NAME PHANI KUMAR INDRA REDDY MAHESH RAGHU RAGHAV RAVI MANOJ SIMHA DEPTNAME SOFTWARE SOFTWARE PAYROLL PAYROLL SOFTWARE FINANCE FINANCE PAYROLL FINANCE SOFTWARE NOTE .DEPTNAE FROM EMPLOYEE A INNER JOIN DEPT B WHERE A.DEPTNO = B. SELECT A.in DEPT table.DEPTNO OR SELECT A.COBOL.DEPTNO = B.ENO. A. 1008 RAVI 15600 1009 MANOJ 98500 1010 SIMHA 35000 1011 KISHORE 43000 D002 D003 D001 ---- DEPT TABLE DEPTNO D001 D002 D003 D004 DEPTNAME SOFTWARE PAYROLL FINANCE TRANSPORT INNER JOIN In this it will give only the rows that match the condition.

B. B.MAINFRAME MATERIAL . A.ENO.COBOL. A.DEPTNO = B. AND CICS AUTHOR .DEPTNO ENO 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 NAME PHANI KUMAR INDRA REDDY MAHESH RAGHU RAGHAV RAVI MANOJ SIMHA KISHORE DEPTNAME SOFTWARE SOFTWARE PAYROLL PAYROLL SOFTWARE FINANCE FINANCE PAYROLL FINANCE SOFTWARE ---- 1011 .DEPTNO = B.K PHANI KUMAR.Is a non matching row but still we got it in the output and the reason for this is LEFT OUTER JOIN returns the non matching rows also from the left side of the table.NAME. SELECT A.DEPTNAE FROM EMPLOYEE A RIGHT OUTER JOIN DEPT B WHERE A. SELECT A.DEPTNAE FROM EMPLOYEE A LEFT OUTER JOIN DEPT B WHERE A. In this it will give only the rows that match the condition and also the non matching rows from the left side of the table.ENO.DEPTNO ENO 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 ---NAME PHANI KUMAR INDRA REDDY MAHESH RAGHU RAGHAV RAVI MANOJ SIMHA ---DEPTNAME SOFTWARE SOFTWARE PAYROLL PAYROLL SOFTWARE FINANCE FINANCE PAYROLL FINANCE SOFTWARE TRANSPORT 41 . RIGHT OUTER JOIN In this it will give only the rows that match the condition and also the non matching rows from the right side of the table. DB2.NAME.

DEPTNO = B.COBOL. B. SELECT A.MAINFRAME MATERIAL . DB2.K PHANI KUMAR.DEPTNAE FROM EMPLOYEE A FULL OUTER JOIN DEPT B WHERE A. AND CICS AUTHOR . FULL OUTER JOIN In this it will give only the rows that match the condition and also the non matching rows from the left side of the table and then right side of the table.NAME.DEPTNO ENO 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 ---NAME PHANI KUMAR INDRA REDDY MAHESH RAGHU RAGHAV RAVI MANOJ SIMHA KISHORE ---DEPTNAME SOFTWARE SOFTWARE PAYROLL PAYROLL SOFTWARE FINANCE FINANCE PAYROLL FINANCE SOFTWARE ---TRANSPORT 42 . A.ENO.

SELECT EMPNO FROM DSN8810.COBOL. DB2. Opposite of COMMIT. updated. • When you use the UNION the column names in both queries should have same name and should contain same number of columns. 43 . deleted till that point of time.EMPPROJACT WHERE PROJNO = 'MA2112' OR PROJNO = 'MA2113' OR PROJNO = 'AD3111' ORDER BY EMPNO. That means db2 saves the data what ever is inserted. • UNION will eliminate the duplicate rows. EXEC SQL COMMIT END-EXEC.K PHANI KUMAR. EXEC SQL ROLLBACK END-EXEC.This option is used to commit the work done. AND CICS AUTHOR .EMP WHERE WORKDEPT = 'D11' UNION ALL SELECT EMPNO FROM DSN8810. COMMIT & ROLLBACK options COMMIT .This option is used to not save the work done. • It works based on the rows. UNION & UNION ALL • This is used to merge the rows of same table or different tables.MAINFRAME MATERIAL . ROLLBACK .

DB2.K PHANI KUMAR.COBOL. AND CICS AUTHOR .MAINFRAME MATERIAL . 44 .

Sign up to vote on this title
UsefulNot useful