You are on page 1of 44

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

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

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

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

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

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

SUBTRACT 10 FROM A. DISPLAY A. DISPLAY B. ==> Value in A is 25 then it subtracts 10 from variable A. DISPLAY A.15. DISPLAY B. 10 .MAINFRAME MATERIAL . DISPLAY C. Format-1:01 A PIC 9(2)VALUE 25.COBOL. O\P . Format-2:01 A PIC 9(2)VALUE 25. Format-3:01 A PIC 9(2)VALUE 25. SUBTRACT A FROM B GIVING C. DISPLAY B. 01 B PIC 9(2)VALUE 15.15 05 Format-3:01 A PIC 9(2)VALUE 25.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. AND CICS AUTHOR . DISPLAY A. O\P . SUBTRACT 10 FROM A. DISPLAY C. 01 C PIC S9(2). DB2. B. 01 C PIC 9(2). 01 B PIC 9(2)VALUE 15. DISPLAY A. ADD A TO B GIVING C. O\P .

DISPLAY A.250 Format-2:01 A PIC 9(3)VALUE 25. DISPLAY A. O\P . O\P . DISPLAY B. 11 . Format-1:01 A PIC 9(3)VALUE 25. DB2. 01 B PIC 9(3)VALUE 10.K PHANI KUMAR. 01 B PIC 9(3)VALUE 10. 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.COBOL. DISPLAY A.MAINFRAME MATERIAL . DIVIDE 10 INTO B. MUPLTIPLY A BY B GIVING C. 01 C PIC 9(3). O\P .2 Format-2:01 A PIC 9(3)VALUE 25. Format-1:01 A PIC 9(3)VALUE 25. AND CICS AUTHOR . O\P . MUPLTIPLY 10 BY A.25 10 250 DIVIDE VERB • DIVIDE verb is used for Division.

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

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

K PHANI KUMAR.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. • It calls the Paragraph only one time in this case. 14 . PERFORM STATEMENTS • PERFORM statement is used for conditional branching in COBOL. PERFORM B-CALCULATE-SALARY. Format-1: .MAINFRAME MATERIAL . 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. This is like a CASE statement in C language. AND CICS AUTHOR . We have 5 different types of PERFORM statements.COBOL. 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. DB2. • EVALUATE STATEMENT EVALUATE statement is also used for decision making in COBOL.

PERFORM B-CALCULATE-SALARY UNTIL UNTIL END-OF-FILE = ‘YES’. PERFORM B-CALCULATE-SALARY UNTIL 10 TIMES. AND CICS AUTHOR . • It calls the Paragraph 10 Times.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.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.K PHANI KUMAR. 15 . Format-3: .COBOL. Format-4: . In this example the CTR starts from 1 and for each iteration it will increment with value 1. (BY 1).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. • It calls the Paragraph until a specified condition is TRUE.MAINFRAME MATERIAL . Here it will maintain a counter and increments it to the value specified for each iteration. Format-2: . DB2.

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

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

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

MOVE 45 TO LS-A. ENVIRONMENT DIVISION. o PROCEDURE DIVISION USING LS-A. CALL 'SUB-PGM1' USING WS-A. DATA DIVISION. IDENTIFICATION DIVISION. ENVIRONMENT DIVISION. DISPLAY 'VALUE OF A AFTER CALLING SUB PROGRAM' WS-A. STOP RUN. LS-C. 01 LS-A PIC 9(2). 01 DATA. DATA DIVISION.K PHANI KUMAR. PROGRAM-ID. A-EXIT. 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. PIC 9(2). WORKING-STORAGE SECTION. EXIT. PIC 9(2). LINKAGE SECTION. PROCEDURE DIVISION USING LS-A. 1. EXIT PROGRAM. LS-B. MAINPGM. 01 WS-A PIC 9(2) VALUE 30.MAINFRAME MATERIAL . PROGRAM-ID. Ex:MAIN PROGRAM IDENTIFICATION DIVISION. A-EXIT. A-START. A-START. SUB PROGRAM. PROCEDURE DIVISION. 05 LS-A 05 LS-B 05 LS-C PIC 9(2). SUB-PGM1.COBOL. DISPLAY 'VALUE OF A BEFORE CALLING SUB PROGRAM' WS-A. EXIT. DB2. AND CICS AUTHOR . STATIC CALL 19 .

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

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

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

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

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

FILE-CONTROL. SELECT IN-FILE ASSIGN TO RRDS-DD ORGANIZATION IS RELATIVE ACCESS MODE IS SEQUENTIAL \ RANDOM \ DYNAMIC FILE STATUS IS WS-IN-FILE-STAT.K PHANI KUMAR.COBOL. 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. • ORGANIZATION IS RELATIVE • ACCESS MODE IS SEQUENTIAL \ RANDOM \ DYNAMIC Ex-1 ENVIRONMENT DIVISION. ACCESS MODE IS SEQUENTIAL FILE STATUS IS WS-IN-FILE-STAT. INPUT-OUTPUT SECTION. CONFIGURATION SECTION. DB2. AND CICS AUTHOR . RRDS FILE:• In RRDS file. Syntax to READ from the file: READ IN-FILE INTO WS-IN-REC AT END MOVE ‘YES’ END-READ.MAINFRAME MATERIAL . the records will be organized based on the relative number and accessed sequentially or randomly or dynamically. Hence mention the below values for RRDS. Syntax to WRITE into the file: 25 TO EOF .

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

FROM WS-OUT-REC. IF WS-STAT1 = '00' CONTINUE ELSE DISPLAY ' ERROR IN OPENING INPUT FILE ' STOP RUN END-IF. OPEN INPUT IN-FILE OUTPUT OUT-FILE. CLOSE IN-FILE. 300-READ-INFILE. DB2. 200-EXIT. EXIT. EXIT. PERFORM 400-CLOSE-FILES.COBOL. 400-EXIT. 27 . STOP RUN. IF WS-STAT2 = '00' CONTINUE ELSE DISPLAY ' ERROR IN OPENING OUTPUT FILE ' STOP RUN END-IF. AND CICS AUTHOR .MAINFRAME MATERIAL . DISPLAY ' PROGRAM ENDED '. EXIT. EXIT. READ INFILE INTO WS-IN-REC AT END MOVE 'YES' END-READ. 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. OUT-FILE. 200-OPEN-FILES. 100-EXIT. 400-CLOSE-FILES.K PHANI KUMAR.

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

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

COBOL. where the table space is stored in the Database. EMP_FIRST_NAME CHAR(30). CREATE TABLE EMPLOYEE ( EMP_ID SMALLINT NOT NULL PRIMARY KEY. EMP_LAST_NAME CHAR(25). PARTITION 48 COMPRESS YES) LOCKSIZE PAGE BUFFERPOOL BP1 CLOSE NO. AND CICS AUTHOR . DB2. SALARY DECIMAL(5. 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.2). DEPT CHAR(10) ) USING FSSADMDB.MAINFRAME MATERIAL .FSSADMTS 30 . 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 47 COMPRESS YES. Table • A table can contain the data in the form of rows and columns. How to create the Table:• In IBM-DB2 the table has to be stored in the Table space.K PHANI KUMAR.

In the below figure we have two tables DEPT.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. EMPLOYEE. How to define the Primary Key separately CREATE UNIQUE INDEX FSS106DB.COBOL. Foreign Key • A Foreign key enforces a relation between two tables.K PHANI KUMAR. AND CICS AUTHOR . DEPT table . EMPLOYEE table .MAINFRAME MATERIAL . DB2.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 .Here DEPTNO is the PK and MGRNO is the FK.EMPXDX ON FSS106DB.

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

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

SELECT EMPID. EMPNAME. AVG 3. DB2.1100)  This will retrieve all the rows where EMPID is in the list 1001. LIKE Operator .COBOL. SUM COUNT . 1100. DB2 Column functions Below are the most common used DB2 column functions. SALARY FROM EMPLOYEE WHERE EMPNAME LIKE ‘__M%’  Here first two characters are (_) and then written the 3rd character as M and then %. 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 . 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. 1003. WHERE EMPID IN (1001.1003. Ex1 . If we want find the rows where the EMPNAME starts with KUMAR. MIN 5. AND CICS AUTHOR .Retrieve all the rows where 3rd character of the EMPNAME is M. SELECT AVG(SALARY) FROM EMPLOYEE  This will return the average salary of each employee 34 . COUNT 2. _  To check for a particular character.This function is used to count the number of rows in a db2 table.MAINFRAME MATERIAL . EMPNAME. MAX 4.This function is used to find the average value of a column.K PHANI KUMAR. 1010.1010. SELECT EMPID. 1.LIKE operator is used with the character data types and is used to check for the wild card strings.

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

UPDATE statement is used to update the columns of the DB2 table. 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.K PHANI KUMAR. 30) WITH CHG If a row is inserted into the DB2 table you will get the SQLCODE = 0 to indicate it has inserted successfully. If SQLCODE = -803 then it means a duplicate record exist. DELETE FROM EMPLOYEE WHERE EMPID = 1001  Deletes only one row.COBOL.MAINFRAME MATERIAL . 'PL2100'. DELETE . AND CICS AUTHOR . • 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. • INSERT INTO DEPARTMENT VALUES ('E31'. DELETE FROM EMPLOYEE  Deletes all the rows from Employee table. UPDATE EMPLOYEE SET SALARY = 10000 WHERE EMPID = 1001. DB2. • 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. PRE COMPILATION 36 . 'E01') INSERT INTO MA_EMPPROJACT SELECT * FROM EMPPROJACT INSERT INTO DEPARTMENT 10 ROWS VALUES (:DEPT) INSERT INTO EMPPROJACT VALUES ('000140'. 'ARCHITECTURE'. 1.DELETE statement is used to delete the rows of the DB2 table. COMPILATION PROCESS The compilation process for COBOL-DB2 program includes various steps.  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. UPDATE . '00390'.

PLAN • A PLAN take one or more DBRMs or one or more PACKAGEs as input and produces the application plan. 1.COBOL. 4.K PHANI KUMAR. AND CICS AUTHOR . It contains two types. 3.BIND reads the sql statements from DBRM and produces the access path logic to retrieve the data from DB2. • A Package can’t be executable so we need to have the PLAN to execute a Cobol-DB2 program. • A PLAN is required to execute the COBOL-DB2 program. DB2. • And converts all the SQL statements into COBOL CALL statements. PLAN. 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. Parameters used in the BIND card BIND PLAN(FSS106) MEMBER(CRC210A0) ACTION(REP) ACQUIRE(USE) RELEASE(COMMIT) 37 .MAINFRAME MATERIAL . PACKAGE 2. PACKAGE • A PACKAGE takes DBRM as input and produces a single package containing the optimized access path logic. So it will save the binding time and cost. • The Package then can be bound into Plan using BIND PLAN command. COMPILATION • It will do a normal Compilation BIND . 5. • And it places a TIME STAMP on the DBRM module. • 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. 2.

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

JOINS Sometimes you may required to retrieve some columns from TABLE-1 and some columns of TABLE-2. So all your SQL copybooks should be mentioned using the INCLUDE statement. 4. In this case you will go for the JOIN to combine two tables and retrieve the required columns.K PHANI KUMAR. • 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 . COPY statement expands the copybooks at the time of compilation stage. so if there are db2 errors it will not be caught at the time of pre-compilation stage. UNCOMMITED READ .MAINFRAME MATERIAL . INCLUDE statement expands the copybooks in the pre-compilation stage. 1. INNER JOIN OR SIMPLE JOIN 2. INCLUDE and COPY statements INCLUDE and COPY statements are used to include the copybooks in the COBOL program. DB2. • DB2 supports below joins.In this DB2 locks all the rows of the table and does not allow any other processes until an explicit commit is done.COBOL. AND CICS AUTHOR . Ex - EXEC SQL INCLUDE SQLCA END-EXEC. FULL OUTER JOIN Or OUTER JOIN You need to write the JOIN in the FROM clause of SELECT statement. LEFT OUTER JOIN 3. RIGHT OUTER JOIN 4.

COBOL.K PHANI KUMAR. A.NAME.DEPTNO = B.ENO.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 . DEPT B WHERE A.NAME. DB2.DEPTNO = B.DEPTNAE FROM EMPLOYEE A INNER JOIN DEPT B WHERE A. B.in DEPT table. SELECT A. AND CICS AUTHOR .It has display only the 10 rows of EMPLOYEE table and has not displayed ENO .DEPTNO OR SELECT A.1011 as there is no department like ---.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. LEFT OUTER JOIN 40 .MAINFRAME MATERIAL .DEPTNAE FROM EMPLOYEE A.

SELECT A.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. A.DEPTNAE FROM EMPLOYEE A LEFT OUTER JOIN DEPT B WHERE A.COBOL. 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. B.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 .MAINFRAME MATERIAL .ENO. 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. B.DEPTNO = B. A.DEPTNAE FROM EMPLOYEE A RIGHT OUTER JOIN DEPT B WHERE A.NAME.DEPTNO = B.NAME. SELECT A.K PHANI KUMAR.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 .ENO. AND CICS AUTHOR . DB2.

ENO. AND CICS AUTHOR .DEPTNAE FROM EMPLOYEE A FULL OUTER JOIN DEPT B WHERE A. 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. DB2. B.COBOL.MAINFRAME MATERIAL .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 .K PHANI KUMAR. SELECT A.DEPTNO = B.NAME. A.

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

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