Sei sulla pagina 1di 114
EASYTRIEVE PLUS Objective:To provide an insight into EASYTRIEVE PLUS and its utilization in Database Management

EASYTRIEVE PLUS

Objective:To provide an insight into EASYTRIEVE PLUS and its utilization in Database Management Systems.

Course Details No: C014 Name Easytrieve Introduction Easytrieve is a tool which helps in information

Course Details

No:

C014

Name

Easytrieve

Introduction

Easytrieve is a tool which helps in information retrieval and in Data Base Management.This material gives an insight into how Easytrieve can be used with IMS and DB2 DBMS.

Course Details Pre-Requisite Knowledge of IMS and DB2 DBMS. Target To be decided by the

Course Details

Pre-Requisite

Knowledge of IMS and DB2 DBMS.

Target

To be decided by the CR and SWS

Audience

Mode of

Class Room

Training Evaluation Criteria

Attendance > 80 % and/or (Case study Completion or Test score > 50 %)

Lesson Plan M# Topic Time(hrs) 1 Introduction 1 2 Library Section 1 3 Activity Section

Lesson Plan

M#

Topic

Time(hrs)

1

Introduction

1

2

Library Section

1

3

Activity Section

2

4

Error Messages

0.5

5

Easytrieve with IMS

1

6

Easytrieve with DB2

2

7

   

8

   

9

   
• This material is made for EBSCO - Easytrieve to Cobol conversion project training program.

• This material is made for EBSCO - Easytrieve to Cobol conversion project training program. As it is project specific, it will not be peer reviewed.

Modules • Introduction • Library Section • Activity section • Error Messages • Dealing with

Modules

Introduction

Library Section

Activity section

Error Messages

Dealing with DB2

Dealing with IMS

Duration : 8 Hrs

Module 1- Introduction Duration : 1 hour • Introduction to Easytrieve Plus • Capabilities :-

Module 1- Introduction

Duration : 1 hour

Introduction to Easytrieve Plus

Capabilities :-

File Processing

Operations

Output

Program Structure

Module 2-Library Section • Data Formats • Mask • Record Definitions • Arrays Duration :

Module 2-Library Section

Data Formats

Mask

Record Definitions

Arrays

Duration : 1 hour

Module 3-Activity Section Duration: 2 hours • JOB Statement • Assignment Statement • Conditional Branching

Module 3-Activity Section

Duration: 2 hours

JOB Statement

Assignment Statement

Conditional Branching

Case Stmt / PERFORM Stmt / STOP stmt

Input / Output Stmt

Controlled I/O

Procedure Processing

Module 4- Error Messages Duration:1/2 hr • Error Messages • Error Codes • Syntax Diagnostic

Module 4- Error Messages

Duration:1/2 hr

Error Messages

Error Codes

Syntax Diagnostic Messages

Module 5- Dealing with DB2

EZT Plus Structure

DB2 Statements

Cursors-Processing

SQLCA

Error Handling

Duration : 1 hour

Module 6- Dealing with IMS

Duration : 2 hours

Introduction to IMS Database

FILE Statement

RECORD Statement

SSA

DLI Functions

DLI statement

RETRIEVE Statement

Module 1- Introduction Duration : 1 hours • Introduction to Easytrieve Plus • Capabilities :-

Module 1- Introduction

Duration : 1 hours

Introduction to Easytrieve Plus

Capabilities :-

File Processing

Operations

Output

Program Structure

EASYTRIEVE PLUS • A tool which helps information retrieval and Data Base Management system for

EASYTRIEVE PLUS

A tool which helps information retrieval and Data Base Management system for simplified programming. Provides the user with Good reporting capabilities.

Capabilities 1. File Processing : - Processes SAM, ISAM, VSAM or IMS/DLI Files Allows fixed,

Capabilities

1. File Processing : - Processes SAM, ISAM, VSAM or IMS/DLI Files Allows fixed, variable, undefined, or spanned record formats. Matches unlimited number of files.

2. Operations: Sorts on any number of Keys

3. Output: Very Good Reporting Features Automatically formats output with all totals calculated internally. Provides summary report.

Program Structure • Environment section - Optional – Override standard EZT options and choose new

Program Structure

Environment section - Optional Override standard EZT options and choose new one by using PARM

Library Section - Optional for defining all files and Working storage

Activity Section - Mandatory JOB statement and SORT statements

Environment Section Environment Section (Optional) Given in comments. Used to describe the program ID, Description,

Environment Section

Environment Section (Optional) Given in comments. Used to describe the program ID, Description, Date written etc. Ex: PARM DEBUG(PGM1)

*PROGRAM-ID *AUTHOR. *DATE WRITTEN. *DESCRIPTION.

PGM1.

IMR.

08/20/1997.

Sample Program

Library Section • Library Section Used to define all input/output files and Working storage fields

Library Section

Library Section Used to define all input/output files and Working storage fields in the program Example:

FILE PERSNL FB(150 1800)

NAME

17

16

A

LAST-NAME

NAME

8

A

PAY-GROSS

94

8

A

Activity Section • Activity Section (Mandatory) – Two types of activities - JOB and SORT

Activity Section

Activity Section (Mandatory)

Two types of activities - JOB and SORT

JOB Statement indicates the start of the program logic.

SORT Statement is used to sort the sequential files.

Any number of JOB and SORT statement.

Activity Section • JOB activities read information from input files examine and manipulate information, write

Activity Section

JOB activities read information from input files examine and manipulate information, write information to output files, and produce printed reports.

SORT activities create sorted sequential output files that contain all or part of the records from another (input) file.

Statement Area • Each line contain a single statement. Can also have multiple statements in

Statement Area

Each line contain a single statement. Can also have multiple statements in Single line Cost = A + B. PRICE = COST + Others

Any non blank line starting with ‘*’ will be treated as comment line.

eg.

Continuation • Can continue lines in a statement to the next line using + or

Continuation

Can continue lines in a statement to the next line using + or - character. Eg

Field name

JOB INPUT

W

8

A

+

VALUE ‘ABC- DEF’. NULL +

START INITIALISE

Quiz • What will be the value of the variable- VAR1 W RING’ 1 4

Quiz

What will be the value of the variable-

VAR1

W

RING’

1

4

N

VALUE ‘THIS IS ST -

What are the activities in the Activity section?

Quiz Answers • ‘THIS IS ST • JOB and SORT RING’ Rel. Dt: 07 Jun,

Quiz Answers

‘THIS IS ST JOB and SORT

RING’

Module 2 - Library Section

Library Section

Data Formats

Mask

Record Definitions

Duration: 1 hrs

Library Section The Library section of your program provides 1. A general description of the

Library Section

The Library section of your program provides

1. A general description of the groups of data (files) on which your program is going to operate (via the FILE statement)

2. A specific description of the individual items of data (fields) within each record of the files or within working storage (via the DEFINE statement optionally)

File Declaration The syntax of File declaration is FILE [file type <file-name> <IS/VIRTUAL>

File Declaration

The syntax of File declaration is

FILE [file type

<file-name>

<IS/VIRTUAL>

<DLI (DB-NAME)> <VS>] [ device type is <CARD> <PRINTER> <DISK/TAPE> ]

File Type Parameter IS VIRTUAL DLI - Indexed Sequential Access Method - Easytrieve Plus virtual

File Type Parameter

IS

VIRTUAL

DLI

- Indexed Sequential Access Method - Easytrieve Plus virtual file manager (VFM) - designates an IMS/DLI

database ,dbd-name is alphabetic and names the database definition within the Program Specification Block (PSB) to be processed.

Field Definitions This is the name you give to the field you are defining. It

Field Definitions

This is the name you give to the field you are defining. It must start with a letter ; can contain letters, numbers, and special characters; and can be from 1 to 40 characters long.

Data Formats For Fields A - Alphabetic. Binary N - zoned decimal. P - Packed

Data Formats For Fields

A

- Alphabetic.

Binary

N

- zoned decimal.

P

- Packed decimal.

B

-

A - Alphabetic A - Alphabetic. Use when none of the numeric data types apply

A - Alphabetic

A - Alphabetic. Use when none of the numeric data types apply to this field. Example:

Name

17

6

A

N - Zoned Decimal N - zoned decimal. The field contains digits 0 thru 9

N - Zoned Decimal

N - zoned decimal. The field contains digits 0 thru 9 in external decimal form.

Example:

Date-Of-Hire

136

6

N

SALARY

1

4

N

2

P - Packed Packed. Example: Pay-Gross 94 4 P 2 Rel. Dt: 07 Jun, 1999

P - Packed

Packed.

Example:

Pay-Gross

94

4 P 2

B - Binary Depending upon their field length, binary fields can contain values whose maximum

B - Binary

Depending upon their field length, binary fields can contain values whose maximum is equivalent to the following number of decimal digits :

Length in Bytes

Digits

1

3

2

5

3

8

4

10

Field Declaration Example : POS Length TYPE DEC FILE EMP-FILE EMP-REC 1 40 A EMP-ID

Field Declaration

Example :

POS

Length

TYPE

DEC

FILE EMP-FILE EMP-REC

1

40

A

EMP-ID

1

5

N

EMP-NAME

5

25

A

EMP-

SALARY

30

5

P

2

EMP-

PERKS

35

5

B

0

Example File Declaration FILE PERSNL FB (150 1800) NAME 17 16 A LAST-NAME NAME 8

Example File Declaration

FILE PERSNL FB (150 1800) NAME

17

16

A

LAST-NAME

NAME

8

A

PAY-GROSS

94

4

P 2

DEPT FILE PHSSF DLI (NPDH006)

98

3

N

HIS-PSB

1

250

A

HIS-STATUS 11

2

A

ReDefinition While defining a grouped field definitions the name of the group should be defined

ReDefinition

While defining a grouped field definitions the name of the group should be defined first with full length and individual fields should be defined by referring to group name, starting position and length of the individual field. Eg.

Date-of-hire

w

6

N

hire-mm

date-of-hire

2

N

hire-dd

date-of-hire +2

2

N

hire-yy

date-of-hire +4

2

N

Example: WS Declaration

SALARY

W

4

P 2

CURR-DATE

W

8

N

CURR-MM CURR-DATE

2

N

CURR-DD CURR -DATE + 2

2

N

CURR-YY

CURR-DATE + 4

4

N

Arrays • The OCCURS option establishes an array for the field. • Example: WS-VAR1 Accessing

Arrays

The OCCURS option establishes an array for the field.

Example:

WS-VAR1

Accessing 20th occurrence of variable-

WS-VAR1(20)

W

3

N

0

OCCURS 40

Arrays (Contd.) • Indexing is data reference that results when EZT Plus derives a displacement

Arrays (Contd.)

Indexing is data reference that results when EZT Plus derives a displacement value to correspond to a particular occurrence in a field name.

Example:

WS-VAR1 W 3 N 0 OCCURS 4 INDEX INDX Accessing 3rd occurrence of variable- INDX = (3 - 1) * 4

WS-VAR1

Initialization Parameter: Value Syntax: { VALUE Literal-1} Example YEAR W 4 N Value 1999 Rel.

Initialization

Parameter: Value

Syntax:

{ VALUE Literal-1}

Example YEAR W 4 N Value 1999

Mask Parameter O ptional MASK parameter can specify a pattern (edit mask) for printing a

Mask Parameter

Optional MASK parameter can specify a pattern (edit mask) for printing a numeric field on a report. Alphabetic fields cannot be edited. Syntax: MASK [letter] [BWZ] [letter-4]

For example:-

WS-TFLAG

W

3

P

0

MASK ('ZZ,ZZ9')

WS-CFLAG

W

3

P

0

MASK ('--,--9')

Points to Note W.R.T MASK [BWZ] BWZ (Blank When Zero) suppresses printing a numeric field

Points to Note W.R.T MASK

[BWZ] BWZ (Blank When Zero) suppresses printing a numeric field when it contains all zeroes. Example:

N 0 VALUE 123 MASK +

W-VAR1

W

6

‘BWZ’

Print Edit Mask It is an alphabetic literal created with a combination of the following

Print Edit Mask

It is an alphabetic literal created with a combination of the following characters :- 9 - causes any digit to print. Z - causes any digit except leading zeroes to print * - causes an asterisk to replace leading zero digits

Print Edit Mask(Contd.) - - causes a minus sign to print before the first or

Print Edit Mask(Contd.)

- - causes a minus sign to print before the first or after the last digit of a negative number. $ - causes a currency symbol to print before the first non-zero digit. X - allows any character to be printed with the edited data.

Examples • ONE W 4 B VALUE 1 • WS-TEST-MODE-FLAG W 1 A W 36

Examples

ONE

W

4

B

VALUE 1

WS-TEST-MODE-FLAG W

1

A

W 36

A

WS-NPGDATE-AREA WS-NPGDATE

WS-NPGDATE-AREA

6

N

WS-DATE1

W

6

N

WS-DD1

WS-DATE1

2

N

WS-MM1

WS-DATE1 +2 2

N

WS-YY1

WS-DATE1 +4 2

N

WS-STOREYYMM

W

4

N

MASK ('ZZZZ')

WS-APPLIT

W

25

A

OCCURS

5

Module 3-Activity Section Duration: 2 hrs • JOB Statement • Assignment Statement • Conditional Branching

Module 3-Activity Section

Duration: 2 hrs

JOB Statement

Assignment Statement

Conditional Branching

Case Stmt / PERFORM Stmt / STOP stmt

Input / Output Stmt

Controlled I/O

Procedure Processing

Activity Section Activity section is an important part of Easytrieve Plus program since it covers

Activity Section

Activity section is an important part of Easytrieve Plus program since it covers logic, statement framing and almost similar to procedure division in COBOL. JOB START

Job Stmt. Identifies the files whose Records are automatically provided JOB INPUT(FILE-NAME [KEY(FIELD-NAME)] [NAME

Job Stmt.

Identifies the files whose Records are automatically provided JOB INPUT(FILE-NAME [KEY(FIELD-NAME)] [NAME Job-name]

Example • JOB INPUT ( MAST-FILE-KEY(MAST-EMP-ID) + TRAN-FILE KEY(TRAN-EMP-ID)) • JOB INPUT NULL • JOB

Example

JOB INPUT ( MAST-FILE-KEY(MAST-EMP-ID) + TRAN-FILE KEY(TRAN-EMP-ID))

JOB INPUT NULL

JOB INPUT PAYFILE

JOB INPUT JDB +

START

JOB

INIT

Null Subparameter NULL - code this subparameter to inhibit automatic input. Normally, a job is

Null Subparameter

NULL - code this subparameter to

inhibit

automatic input. Normally, a job is implicitly stopped when the automatic input file(s) is exhausted. However, if

you code NULL, the program continues running until a STOP statement is executed. Example : JOB INPUT NULL

SORT Activity SORT File-name-1 TO File-name-2 + USING (Field-name) + [BEFORE (proc name)] + [Name

SORT Activity

SORT File-name-1 TO File-name-2 + USING (Field-name) + [BEFORE (proc name)] + [Name Sort-name]

Report • REPORT is the first stmt of the report declaratives. • Parameters: Format Determination

Report

REPORT is the first stmt of the report declaratives.

Parameters:

Format Determination File Directing Spacing Control Testing Aids

Report(Cond.) REPORT report-name + [Summary] LABELS ([ACROSS literal-1] + [DOWN literal-2] + [SIZE literal-3] +

Report(Cond.)

REPORT report-name + [Summary]

LABELS

([ACROSS literal-1] + [DOWN literal-2] + [SIZE literal-3] + [NEWPAGE]

Format

Determination

File

Directing

[PRINTER file-name]

Report(Contd.) [PAGESIZE literal-4] + [LINESIZE literal-5] + [SPREAD] + [NOSPREAD] [LIMIT literal-6] + [EVERY literal-7]

Report(Contd.)

[PAGESIZE literal-4] + [LINESIZE literal-5] + [SPREAD] + [NOSPREAD]

[LIMIT literal-6] + [EVERY literal-7]

Spacing Control

Testing Aids

Assignment Statement The format used to copy data from one field to another, or from

Assignment Statement

The format used to copy data from one field to another, or from a literal to a field. The syntax

field-1 [= EQ] field-2 [literal-1]

In the above, the value of field-1 is set equal to the value of field-2 or literal-1.

Points To Note a. Only one equivalent may be specified i.e. either field-2 or literal-1

Points To Note

a. Only one equivalent may be specified i.e. either field-2 or literal-1 e.g field-1 = field-2 or field-1 = literal-1 b. If field-1 has been DEFINEd as alphabetic, literal must also be alphabetic. If literal is shorter than field-1, padding is on the right. C. If both field-1 and field-2 are alphabetic, but not the same size, padding or truncation, as appropriate occurs on the right.

Contd …. D. If field-1 is alphabetic and field-2 is numeric, the resulting value in

Contd ….

D. If field-1 is alphabetic and field-2 is numeric, the resulting value in field-1 will be zonal decimal, with padding or truncation on the left, as necessary.

E. If field-1 is numeric, field-2 or literal must be numeric.

Conditional Branching • IF salary GT 7778 bonus = 888 ELSE bonus = 999 END-IF.

Conditional Branching

IF salary GT 7778 bonus = 888 ELSE bonus = 999 END-IF.

DO and END-DO

GOTO procedure/para name

PERFORM

Case Stmt CASE <field-1> when <value-1> perform action-1 when <value-2> perform

Case Stmt

CASE <field-1>

when

<value-1>

perform action-1

when

<value-2>

perform action-2 END-CASE

Perform Stmt PERFORM procedure/para name PERFORM statement cause a branch to another location in the

Perform Stmt

PERFORM procedure/para name

PERFORM statement cause a branch to another location in the program.

Input / Output Stmts EASYTRIEVE PLUS supports the following input and output statements JOB -

Input / Output Stmts

EASYTRIEVE PLUS supports the following input and output statements

JOB

- DISPLAY -

PRINT

-

specifies the input file initiates report output produces printed output not directly supported by a report.

Print Statement The PRINT statement initiates report output by causing the named report to extract

Print Statement

The PRINT statement initiates report output by causing the named report to extract the current value of the fields to be output and to format them according to the specifications immediately or deferred.

E.g

PRINT report-name

Print Stmt. (Cond.) The report-name parameter is the name of the report which contains the

Print Stmt. (Cond.)

The report-name parameter is the name of the report which contains the data being output with the PRINT statement. It is important that the data should be made available along with report format before executing the print statement.

Display Stmt The Display statement outputs data to the system printer or a named file.

Display Stmt

The Display statement outputs data to the system printer or a named file. This data is spaced according to the specified parameters.

DISPLAY [field-name] e.g DISPLAY error-message

Procedure Processing Procedures are defined using the PROC and END-PROC statements. Invoked By : PERFORM

Procedure Processing

Procedures are defined using the PROC and END-PROC statements. Invoked By : PERFORM statement. PROC and END-PROC statements <proc-name>. PROC Statements Statements END-PROC

Relational Operators Valid Relational Operators are = EQ NE Equal Not equal LT < Less

Relational Operators

Valid Relational Operators are =

EQ

NE

Equal Not equal

LT

<

Less than

LE

<=

Less than or equal to

GT

>

Greater than

GE

>=

Greater than or equal to

STOP Stmt This statement terminates EASYTRIEVE PLUS activities. It can be used for premature termination

STOP Stmt

This statement terminates EASYTRIEVE PLUS activities. It can be used for premature termination of activities using automatic input. The STOP statement must be used to terminate JOB activities which have INPUT NULL. Format

STOP [EXECUTE] STOP

Controlled I/O Stmts Provides the capability to process any sequential or keyed file (ISAM or

Controlled I/O Stmts

Provides the capability to process any sequential or keyed file (ISAM or VSAM). Stmts are:-

GET

POINT

sequentially reads one record positions a keyed file to a particular record for subsequent sequential I/O - sequentially writes one record - reads one keyed record - rewrites, adds one keyed record.

-

-

PUT

READ

WRITE

GET Stmt • The GET statement makes the next sequential record of the named file

GET Stmt

The GET statement makes the next sequential record of the named file available for processing.

Syntax:

GET file-name

The file name parameter is required. It can be any file name declared in the Library section.

PUT Stmt. • The PUT statement outputs data to a sequential file whose name is

PUT Stmt.

The PUT statement outputs data to a sequential file whose name is specified in the statement.

Syntax PUT file-name-1 [from file-name-2]

PUT creates new sequential file or adds consecutive records to an existing VSAM file.

Both file-name-1 and file-name-2 should be declared in Library section.

Point Stmt The POINT statement initiates a search for a position within an indexed or

Point Stmt

The POINT statement initiates a search for a position within an indexed or relative-record file, based on a comparison between keys in the file and a search value specified in the statement. Syntax:

POINT file-name [EQ/GE] [field-name, + literal]

Point stmt.(Contd.) • The POINT statement only locates the specified position of the record in

Point stmt.(Contd.)

The POINT statement only locates the specified position of the record in the file. We still have to use GET statement to retrieve the data for processing.

File-name must have a declaration in the Library section of the program.

READ stmt • The READ statement provides random access to keyed and relative-record VSAM and

READ stmt

The READ statement provides random access to keyed and relative-record VSAM and ISAM files.

Syntax :

READ file-name KEY field-name STATUS

File-name is the file need to be accessed and should be declared in the Library section of the program.

Read Stmt (Contd.) KEY field-name This parameter serves as a search value to identify the

Read Stmt (Contd.)

KEY field-name This parameter serves as a search value to identify the specific record to be retrieved. The contents of the specified field-name must match the contents of the key of the desired record. STATUS This parameter is optional. If included,

Read Stmt. (Contd.) Execution of the READ statement sets a return code in the FILE-STATUS

Read Stmt. (Contd.)

Execution of the READ statement sets a return code in the FILE-STATUS field of the input file to indicate the success or failure of the operation.

Write Stmt The WRITE statement is used in the maintenance of keyed and relative-record VSAM

Write Stmt

The WRITE statement is used in the maintenance of keyed and relative-record VSAM files. Write updates or deletes the current record of the named file, or adds new records. Syntax:

WRITE file-name [delete,update,add] from

file-name-1

Write Stmt(Contd.) File-name names the file to be modified. It must have declaration in the

Write Stmt(Contd.)

File-name names the file to be modified. It must have declaration in the library section [delete update

add]

These parameters specify the maintenance activity to be performed. They are required for deleting or adding records. It is optional

Write Stmt(Contd.) for update activity. The default is UPDATE. File-name-1 This is optional. If included,

Write Stmt(Contd.)

for update activity. The default is UPDATE.

File-name-1

This is optional. If included, the write statement copies the current record to the file-name.

Exercise 1 • Which file is retrieved in the following cases? FILE FILE1 VAR1 1

Exercise 1

• Which file is retrieved in the following cases?

FILE FILE1

VAR1

1

10

A

VAR2

11

2

N

FILE FILE2

VAR3

1

10

A

VAR4

11

2

N

(1) JOB INPUT VAR1 (2) JOB SORT FILE1 TO FILE2 + USING (VAR2) (3) JOB (4) JOB INPUT NULL

Exercise 2 • What will be produced in the Report? REPORT ABC TITLE 01 COL

Exercise 2

What will be produced in the Report? REPORT ABC TITLE 01 COL 20 SSN TITLE 02 SYSDATE COL 20 NAME (Assume, SSN = 123-45-6789 and NAME = ‘IMR’)

Module 4- Error Messages • Topics Duration: 1/2 hrs • Error Messages • Error Codes

Module 4- Error Messages

• Topics

Duration: 1/2 hrs

• Error Messages

• Error Codes

• Syntax Diagnostic Messages

Error Types Easytreive Plus provides a comprehensive set of diagnostic messages which fall into 2

Error Types

Easytreive Plus provides a comprehensive set of diagnostic messages which fall into 2 categories Operational Errors & Pgm Syntax Errors

Error Codes A001 File OPEN Error A002 Invalid block Size A003 Insufficient Core storage A005

Error Codes

A001 File OPEN Error A002 Invalid block Size A003 Insufficient Core storage A005 I/O error A007 Table input not in sequence A008 Too many table entries A009 report processing terminated due to sort error A012 Invalid Length of file name A013 wrong record length for a file

Syntax Diagnostic Messages B003 - Expected continuation not received B004 - Report Exceeds page size

Syntax Diagnostic Messages

B003 - Expected continuation not received B004 - Report Exceeds page size B007 - Invalid IF - END-if pairing B010 - Invalid Block size B011- Table input not in sequence B012 - Duplicate name for a file, field or report B027 - Not a valid name file,field or report B048 - Field name not in file B094 - Invalid record format

Module 6- Dealing with DB2

EZT Plus Structure

DB2 Statements

Cursors-Processing

SQLCA

Error Handling

Duration : 1 hours

Structure of EZT Plus For DB2 • Environment Section – PARM statement only • Library

Structure of EZT Plus

For DB2

• Environment Section

– PARM statement only

• Library Definition Section

– Host variable declaration and cursor declaration

• Activity Description section(s)

– DB2 processing like opening, fetching, closing the cursor.

DB2 Statements • Add SQL before every DB2 Statement Example: SQL UPDATE PHVICCI + SET

DB2 Statements

• Add SQL before every DB2 Statement

Example:

SQL UPDATE PHVICCI + SET PH_INIT_CNT_RPRNT = + :BLANKONE + WHERE CURRENT OF VICCICURSOR

Cursor-Processing • Best way to handle the DB2. • Steps involved – Declare cursor –

Cursor-Processing

• Best way to handle the DB2.

• Steps involved

Declare cursor

Open Cursor

Fetch Cursor

Close Cursor

Cursor-Processing(Contd.)

Declare the Cursor • Declared in Library section as- SQL DECLARE <cursor-name> CURSOR FOR <select statement(query)>

Example :

SQL DECLARE EMPCURSOR CURSOR + FOR SELECT EMPNO, ENAME FROM + EMP_TABLE WHERE DEPTNO = 100

Cursor-Processing(Contd.)

Open the Cursor • Coded in Activity Section as- SQL OPEN <cursor-name>

Example :

SQL OPEN EMPCURSOR

Cursor-Processing(Contd.)

Fetch the Cursor • Coded in Activity Section as- SQL FETCH <cursor-name> INTO :<host- variables>

Example :

SQL FETCH EMPCURSOR INTO + :W-NO + :W-NAME

Cursor-Processing(Contd.)

Close the Cursor • Coded in Activity Section as- SQL CLOSE <cursor-name>

Example :

SQL CLOSE EMPCURSOR

SQLCA • No need to include SQLCA explicitly. • Any field of SQLCA can be

SQLCA

• No need to include SQLCA explicitly.

• Any field of SQLCA can be used without declaration.

Example:

IF SQLCODE NE +0, +100

----

Error Handling • SQLCODE is used to find the error if occurred. • DSNTIAR routine

Error Handling

• SQLCODE is used to find the error if occurred.

• DSNTIAR routine can be used to handle the errors. It is a standard error-reporting routine IBM supplied as a part of DB2.

• DSNTIAR requires three arguments.

First argument is SQLCA

Second argument identifies the data area where you want DSNTIAR to return formatted error messages.

Third arg. Is numeric item that contains the length of the individual text lines the routine returns.

Error Handling(Contd.) • Calling DSNTIAR in Easytrieve Plus- Activity Section Entry:- IF SQLCODE NE +0

Error Handling(Contd.)

• Calling DSNTIAR in Easytrieve Plus- Activity Section Entry:- IF SQLCODE NE +0 +100 PERFORM ERR-ROUTINE END-IF ERR-ROUTINE. PROC CALL DSNTIAR USING + (SQLCA, WS-SQL-MSG, WS-SQL-TEXT-LEN)

--------

Error Handling(Contd.) Library Section Entry :- WS-SQL-MSG W 1682 A WS-SQL-MSG-LEN WS-SQL-MSG 2 B 0

Error Handling(Contd.)

Library Section Entry :- WS-SQL-MSG W 1682 A WS-SQL-MSG-LEN WS-SQL-MSG 2 B 0 + VALUE +1680 WS-SQL-MSG-LINE WS-SQL-MSG +2 80 A + OCCURS 21 INDEX MSG-INDX WS-SQL-TEXT-LEN W 4 B 0 VALUE +80 DB2-RETURN-CODE W 2 B 0

Quiz 1. Which DB2 routine is used to deal with SQL errors? 2. In which

Quiz

1. Which DB2 routine is used to deal with SQL

errors?

2. In which section of Easytrieve Plus cursors are opened?

3. In which section of Easytrieve Plus SQLCA is included?

Quiz - Answers 1. DSNTIAR. 2. Activity section 3. No declaration for SQLCA Rel. Dt:

Quiz - Answers

1. DSNTIAR.

2. Activity section

3. No declaration for SQLCA

Module 6- Dealing with IMS

Duration : 2 hours

• Introduction to IMS Database

• FILE Statement

• RECORD Statement

• SSA

• DLI Functions

• DLI statement

• RETRIEVE Statement

Introduction to IMS Database

• Hierarchical Database

• Most, if not all, IMS data bases use VSAM data sets, either KSDS or RRDS.

• Root (parent) and Child hierarchy.

• Root segment is the entry point to Database

• Maximum level is 15 from root to lowest child

Introduction to IMS Database

I M S D a t a b a s e V e n d
I
M
S
D
a
t
a
b
a
s
e
V
e
n
d
I
t
e
m
I
t
e
m
I
t
e
m
L
o
c
L
o
c
L
o
c
L
o
c
L
o
c
L
o
c
L
o
c
FILE Statement • Identifies the Database • Defines the PCB to be processed • Syntax

FILE Statement

• Identifies the Database

• Defines the PCB to be processed

• Syntax :-

FILE filename DLI (dbd-name [literal-1]

• Example:

FILE HISDB DLI (NPDH006) HIS-PCB 1 250 A HIS-STATUS 11 2 A

RECORD Statement • Identifies the database segment segments which are to be available for processing.

RECORD Statement

• Identifies the database segment segments which are to be available for processing.

• One RECORD statement must be coded for each segment of the database to be processed.

• Must be coded in the same order as in PSB which defines the database.

• All segment of the database need not be defined, but the parent of each RECORD must be coded.

RECORD Statement(Contd.)

• Syntax :- RECORD segment-1 literal-1 [segment-2] Literal-1 - positive integer (length of segment)

• Segment-2 -Parent of segment-1

• Example :

RECORD ECHILD 262 EROOT

ESTAFNO

1

7

A

ESURNME 8

20

A

Record Definitions Record definition should start with word RECORD followed by record name. Record allocates

Record Definitions

Record definition should start with word RECORD followed by record name. Record allocates a work work space which contains the segment data during execution

RECORD

EROOT

STAFF-NO

1

7

N

SURNAME

8

20

A

INITIALS

DEPT

48

138

6

4

A

A

Record Formats F = Fixed unblocked V = Variable unblocked U = undefined FB= Fixed

Record Formats

F

= Fixed unblocked

V

= Variable unblocked

U

= undefined

FB= Fixed blocked VB= Variable Blocked VSS = variable blocked spanned.

SSA • Segment Search Argument • Unqualified SSAs • Qualified SSAs • Unqualified SSA- SSA-UNQUAL

SSA

• Segment Search Argument

• Unqualified SSAs

• Qualified SSAs

• Unqualified SSA-

SSA-UNQUAL W 8 A VALUE ‘EROOT

• Qualified SSAs

SSA-QUAL

W

27

A

+

VALUE ‘EROOT

(ESTAFNO > 10000)

DLI Functions • Four character field • Specifies the operation to be performed • GU,

DLI Functions

• Four character field

• Specifies the operation to be performed

• GU, GN, GNP, GHU, GHN, GHNP, ISRT, REPL, DLET

• G indicates ‘GET’

• H indicates ‘HOLD’- is used in either updating or Deleting the segment.

DLI statement • Provides controlled I/O of an IMS database. • Anywhere in the JOB

DLI statement

• Provides controlled I/O of an IMS database.

• Anywhere in the JOB

• Complete control over the creation and maintenance of a database.

• Syntax :- DLI file-name record-name ‘dli-function’ [SSANO field-name] SSA ssa-name

– file-name identifies the database to be processed

DLI statement(Contd.) • Example - DLI HISDB EROOT ‘GU’ SSA (SSA-QUAL) In library section- SSA-QUAL

DLI statement(Contd.)

• Example - DLI HISDB EROOT ‘GU’ SSA (SSA-QUAL) In library section- SSA-QUAL W 27 A VALUE ‘EROOT (ES - TAFNO = ‘) SSA-ROOT-KEY SSA-QUAL +19 7 A SSA-END SSA-QUAL +27 1 A VALUE ‘)’

RETRIEVE Statement • Immediately following the JOB statement • Describe automatic database input. • Only

RETRIEVE Statement

• Immediately following the JOB statement

• Describe automatic database input.

• Only one RETRIEVE Statement in JOB activity

• Syntax:- RETRIEVE file-name SELECT (record-name [SSA ssa-name] +

[

LIMIT ‘literal’] +

[

WHILE (condition) ]…)

RETRIEVE Statement • Example : JOB INPUT JDB RETRIEVE JDB SELECT JROOT + WHILE (

RETRIEVE Statement

• Example :

JOB INPUT JDB RETRIEVE JDB SELECT JROOT + WHILE ( A-DATABASE = ‘NPDH006’ + AND A-SEGMENT = ‘EROOT’)

Handling Status code • Two character field • spaces - Successful retrieval • GE- Segment

Handling Status code

• Two character field

• spaces - Successful retrieval

• GE- Segment not found

• GB- End of Database

• GA- Current position goes up one or more level

• GP - Issuing GNP without establishing parentage.