Sie sind auf Seite 1von 16

Exception Handling

Day 16

Exception Handling:
Overview:
This module enables the student to understand the concept of

Exception handling.

Outline:
Topics

covered,
Input Specification (IPDS, IPJX, IPN)
Data structure
File information data structure
Program status data structure

Objective:
By the end of this module, the student should be able to understand:
Data structure
INFDS, INFSR and *PSSR data structure

DukeStar Technologies Pvt. Ltd.

1/16

No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

Data Structure:
The RPG/400 program allows you to define an area in storage and the layout of the fields,
called subfields, within the area. This area in storage is called a data structure.
You can use a data structure to:

Define the same internal area multiple times using different data formats

Operate on a field and change its contents

Divide a field into subfields without using the MOVE or MOVEL operation codes

Define a data structure and its subfields in the same way a record is defined

Define multiple occurrences of a set of data

Group non-contiguous data into contiguous internal storage locations.

In addition, there are three special data structures, each with a specific purpose:

A data area data structure (identified by a U in position 18 of the data structure


statement)

A file information data structure (referred to by the keyword INFDS on a file


description specifications continuation line)

A program-status data structure (identified by an S in position 18 of the data


structure statement).

Data structures can be program-described or externally described.

Data Structure Statement Specifications


Data structure statements are defined on the input specifications and must follow all input
specifications for records. The specifications for data structure statements are:
Position

Entry

7-12

Name of the data structure being defined. This entry is optional for a program-described data
structure, and is required for an externally described data structure, a file information data
structure (INFDS), and a data area data structure.

13-16

Blank

17

Blank: Program-described data structure.


E: Externally described data structure. The data structure subfields definitions are retrieved
from an externally described record format.

18

Blank: Other than a program status, data area or initialized data structure.
I
:
S :
U :

Globally initialized data structure.


Program-status data structure.
Data area data structure.

DukeStar Technologies Pvt. Ltd.

2/16

No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

19-20

DS

21-30

Blank: The data structure is program described.


Entry: This is the name of the file whose first record format contains the field descriptions used
as the subfields descriptions for this data structure.

31-43

Blank

44-47

Blank: A single occurrence data structure.


nnnn: A number (right-adjusted) indicating the number of occurrences
Of the data structure.
Note: This entry must be blank for a data area data structure, a file
Information data structure, and a program-status data structure.

48-51

Length of data structure (optional). This entry must be right adjusted.

52-74

Blank

Rules for Specifying Data Structure Statements


Remember the following when you specify data structure statements:

The data structure name must be a symbolic name with a maximum of six
characters. The name can appear on only one data structure specification, cannot
be a look ahead field, and can be specified anywhere a character field is allowed.

All entries for one data structure and its subfields must appear together; they
cannot be mixed with entries for other data structures.

The data structure length is determined by the first specification in the program
that defines a length in one of the preceding ways. Subsequent conflicting lengths
are incorrect. The length of a data structure is one of the following:
o

The length specified in the input-field specifications if the data structure


name is an input field

The length specified in positions 48 through 51 of the data structure


statement

The highest To position of a subfield within a data structure if the data


structure name is not an input field.

A compile-time or prerun-time array cannot be used in a data area data structure or


in a multiple-occurrence data structure.

Data structures are character data and can be from 1 to 9999 characters in length.

A data structure and a subfield of a data structure cannot have the same name.

Special Data Structures


Special data structures include:
DukeStar Technologies Pvt. Ltd.

3/16

No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

Data area data structures


File information data structures (INFDS)
Program-status data structures.

Data Area Data Structure


A data area data structure, identified by a U in position 18 of the data structure statement,
indicates to the RPG/400 program that it should read in and lock the data area of the same
name at program initialization and should write out and unlock the same data area at the
end of the program. Data area data structures, as in all other data structures, have the
type character. A data area read into a data area data structure must also be character.
The data area and data area data structure must have the same name unless you rename
the data area within the RPG/400 program by using the *NAMVAR DEFN statement.
You can specify the data area operations (IN, OUT, and UNLCK) and have the type for a
data area that is implicitly read in and written out. Before you use a data area data
structure with these operations, you must specify that data area in the result field of the
*NAMVAR DEFN statement. A data area data structure cannot be specified in the result
field of a PARM operation. If you specify blanks for the data area data structure (positions 7
through 12 of the input specifications line that contains a U in position 18), the RPG/400
program uses a local data area. To provide a name for a local data area, use the *NAMVAR
DEFN operation, with *LDA in factor 2 and the name in the result field. If data structure
name entry is blank then the local data area is used.
This data area either you can create using CRTDTAARA command or if not created by you
then system will create it in QTEMP library at the start of job and will delete it at the end of
the job.
Following example shows how we divide fields using subfields using Data Area Data
Structure:
Step 1:
Create data area using CRTDTAARA command on command line and press F4:
Create Data Area (CRTDTAARA)
Type choices, press Enter.
Data area . . . . . . . . . . .
Library . . . . . . . . . . .
Type . . . . . . . . . . . . . .

F3=Exit
F4=Prompt
F5=Refresh
F13=How to use this display

*DTA1
*CURLIB

Name
Name, *CURLIB
*DEC, *CHAR, *LGL, *DDM

F10=Additional parameters
F24=More keys

Bottom
F12=Cancel

Step 2:
Write data area as DTA1 which is data area name, library name and provide data area
type *CHAR.
Data area is having 3 types:
DukeStar Technologies Pvt. Ltd.

4/16

No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

Decimal (*DEC)
Character (*CHAR)
Logical (*LGL)
Step3: after inserting above information press F10 to fill additional attributes like data
areas length as shown below:
Create Data Area (CRTDTAARA)
Type choices, press Enter.
Data area . . . . .
Library . . . . .
Type . . . . . . . .
Length:
Length . . . . . .
Decimal positions
Initial value . . .
Text 'description' .

. . . . . . > DTA1
. . . . . . >
PB01U010
. . . . . . > *CHAR

Name
Name, *CURLIB
*DEC, *CHAR, *LGL, *DDM

.
.
.
.

1-2000
0-9

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

20
*BLANK

Additional Parameters
Authority

. . . . . . . . . . .

F3=Exit
F4=Prompt
F24=More keys

F5=Refresh

*LIBCRTAUT

Name, *LIBCRTAUT, *CHANGE...

F12=Cancel

Bottom
F13=How to use this display

Press enter to create dta1 in library pb01u01o.


Step 4:
Write simple RPG program to see how Data Area DS is define or use in RPG.
To define Data Area DS use the prompt as given below:
Columns . . . :
1 71
Edit
PB01U01S/MYRPG
SEU==>
DADS1
FMT DS .....IDsname....NODsExt-file++.............OccrLen+....................
*************** Beginning of data *************************************
0000.01
* USE IPDS PROMPT HAVING U AT OPTION TO DEFINE DATA AREA DS.
0001.00
IDTA1
UDS

U is for Data Area DS


Data area name created using CRTDTAARA
Prompt type . . .
Data Struct
Name
DTA1

Number

F3=Exit
F4=Prompt
F12=Cancel

DS command
Sequence number . . .
Option
U

DS
DS

F5=Refresh
F23=Select prompt

External
File Name

0001.00
Occurs

Length

F11=Previous record
F24=More keys

See the following IPJ prompt where to define the attributes of subfield.

DukeStar Technologies Pvt. Ltd.

5/16

No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

IPJ :
Positions

Name

7-42
43

Data format

44-47
48-51
52

From
To
Decimal positions

53-58
59-60

Field name
Control Level

61-62

Match fields

63-64

Field record relation

65-70

Field indicators

71-74
75-80

Comments

Entry
Blank
Blank
P
B
L
R
1-9999
1-9999
Blank
0-9
Symbolic name
Blank
L1-L9
Blank
M1-M9
Blank
01-99
L1-L9
MR
U1-U8
H1-H9
RT
Blank
01-99
H1-H9
U1-U8
RT
Blank
Optional

Columns . . . :
1 71
Edit
PB01U01S/MYRPG
SEU==>
DADS1
FMT DS .....IDsname....NODsExt-file++.............OccrLen+....................
*************** Beginning of data *************************************
0000.01
* USE IPDS PROMPT HAVING U AT OPTION TO DEFINE DATA AREA DS.
0001.00
IDTA1
UDS
0000.10
* USE IPJ PROMPT TO DEFINE SUBFIELDS OF DATA AREA DS.
0002.00
I
1
62AMT1

Prompt type . . .
P/B/L/R

From
1

Field Record
Relation
F3=Exit
F4=Prompt
F12=Cancel

Sequence number . . .

To
6
Positive
Field

Decimal
Positions
2
Negative
Field

F5=Refresh
F23=Select prompt

DukeStar Technologies Pvt. Ltd.

0002.00

Field
Name
AMT1
Zero /
Blank

Control
Level

Matching
Fields

F11=Previous record
F24=More keys

6/16

No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

Define other fields AMT2 and SUM using same prompt IPJ as shown below. Use
*NAMVAR define data area DTA1 and initialize values 100 and 200.20 to fields AMT1 and
AMT2 respectively. Add this amount to variable or subfield SUM.
Columns . . . :
1 71
Edit
PB01U01S/MYRPG
SEU==>
DADS1
FMT DS .....IDsname....NODsExt-file++.............OccrLen+....................
*************** Beginning of data *************************************
0000.01
* USE IPDS PROMPT HAVING U AT OPTION TO DEFINE DATA AREA DS.
0001.00
IDTA1
UDS
0000.10
* USE IPJ PROMPT TO DEFINE SUBFIELDS OF DATA AREA DS.
0002.00
I
1
62AMT1
0003.00
I
7 122AMT2
0004.00
I
13 202SUM
0005.00
C
*NAMVAR
DEFN
DTA1
0006.00
C
Z-ADD100
AMT1
0007.00
C
Z-ADD200.20
AMT2
0008.00
C
AMT1
ADD AMT2
SUM
0009.00
C
*LOCK
OUT DTA1
0010.00
C
UNLCKDTA1
0011.00
C
SUM
DSPLY
0012.00
C
SETON
LR
****************** End of data ****************************************

F3=Exit
F4=Prompt
F16=Repeat find

F5=Refresh
F9=Retrieve
F17=Repeat change

F10=Cursor
F11=Toggle
F24=More keys

Exception or error handling:


In any application development exception/error handling plays a very important role. The
errors can occur at any time while running the application program. Therefore, you as a
programmer should be capable of handling such errors rather than allowing them to
abnormally end the program itself. The term exception tells about the study of various
error conditions and error handling implies detecting and correcting errors.
RPG/400 provides File Information Data Structure (INFDS), file exception/error subroutine
(INFSR), program status data structure and program exception/error subroutine (*PSSR) for
exception/error handling.
INFSR is used with *PSSR is used to find file level exception and only program level
exception are handle by Program Status Data Structure using *PSSR.
When error code is greater than 99 then user can able to use *PSSR routine. Other wise
user have to use simple subroutine to handle the exception.
These are some error codes which are use to handle the error.
TABLE FILE ERROR CODES
NORMAL CONDITIONS
CODES
MEANING
00000
No exception/error occurred.
00002
Function key used to end display.
00011
End of file on a read (input).
00012
No record found on a CHAIN, SETGT, SETLL operation.
00013
Subfile is full on a write operation.
EXCEPTION-ERROR CONDITIONS
01011
Undefined record type (input record does not match
record-identifying indicator).
DukeStar Technologies Pvt. Ltd.

7/16

No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16
01021
01031
01041
01051
01071
01121
01122
01123
01124
01125
01126
01201
01211
01215
01216
01217
01218
01221
01231
01235
01241
01251
01255
01261
01281
01282
01285
01286
01287
01299
01331
Program status Codes
NORMAL CONDITIONS
CODES
00000
00001

Tried to write a record that already exists(file being used


has unique keys and key duplicate, or attempted to use
duplicate relative record number to a subfile).
Match field out of sequence.
Array/table load sequence error.
Excess entries in array/table file.
Numeric sequence error.
No indicator on the DDS keyword for Print Key
No indicator on the DDS keyword for Roll Up Key.
No indicator on the DDS keyword for Roll Down key.
No indicator on the DDS keyword for Clear Key.
No indicator on the DDS keyword for Help Key.
No indicator on the DDS keyword for Home Key.
Record mismatch detected on input.
I/O operation to a closed file.
OPEN issued to a file already open.
Error on an implicit OPEN/CLOSE operation.
Error on an explicit OPEN/CLOSE operation.
Record already locked.
Update operation attempted without a prior read.
Error on SPECIAL file.
Error in PRTCTL space or skip entries.
Record number not found. (Record number specified in
record address file is not present in file being processed.)
Permanent I/O error occurred.
Session or device error occurred. Recovery may be
possible.
Attempt to exceed maximum number of acquired devices.
Operation to un acquired device.
Job ending with controlled option.
Attempt to acquire a device already acquired.
Attempt to open shared file with SAVDS or IND options
Responses to indicators overlap IND indicators.
Other I/O error detected.
Wait time exceeded for READ from WORKSTN file.
MEANING
No exception error occurred.
Called program returns with the LR indicator on.

EXCEPTION-ERROR CONDITIONS
CODES
00100
00101
00102
00121
00122
00123
00202
00211
00221
00231
00232
00233
00299
00333
DukeStar Technologies Pvt. Ltd.

MEANING
Value out of range for string operation
Negative square root.
Divide by zero
Invalid array index.
OCCUR outside of range.
RESET attempted during initialization subroutine.
Called program failed, halt indicator (H1 through H9) not
on.
Program specified on CALL or FREE not found
Called program tried to use a parameter not passed to it.
Called program returned with halt indicator on.
Halt indicator on in this program.
Halt indicator on when RETRN operation run.
RPG formatted dump failed.
Error on DSPLY operation.
8/16

No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16
00401
00402
00411
00412
00413
00414
00415
00421
00431
00432

Data area specified on IN or OUT not found


*PDA not valid for non-restart job.
Data area types or lengths do not match.
Data area not locked for output
Errors on IN or OUT operation.
User not authorized to use data area.
User not authorized to change data area.
Error on UNLCK operation
Data area previously locked by another program.
Data area locked by program in the same process.
Character field not entirely enclosed by SO and SI.
Decimal data error (invalid digit or sign).
The level numbers of the generating compiler and the runtime subroutines do not match.
Virtual storage exceeded.
Internal failure in RPG compiler or in run-time subroutines.
Program exception in system routine.

00907
00970
09998
09999

The following reserved words define symbolic locations within the file information data
structure (INFDS) and the program status data structure.
*FILE
*OPCODE
*PARMS
*PROGRAM
*RECORD
*ROUTINE
*STATUS
See the following example where we use *STATUS opcode with INFDS.
File- Information Data Structure (INFDS)
The purpose of a file information data structure is to identify exception/error for a file in
the program. It must be unique for each file. A file information data structure contains
predefined subfields that give information about the type of exception or error that
occurred, the operation that the program was running when the exception/error occurred
and the status of various conditions. The INFDS data structure is specified either on the file
description line itself or on a continuation line for that file on position 54-59 (option entry)
and position 60-67 (here the name of entry is entry only). Option entry is used to write
INFDS keyword and field entry is used for writing the name of the file information data
structure.
Following example shows how to handle duplicate record error.
Step 1Following is the Physical File

DukeStar Technologies Pvt. Ltd.

9/16

No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

Columns . . . :
1 71
Edit
PB01U01D/MYDDS
SEU==>
EMPMST
FMT PF .....A..........T.Name++++++RLen++TDpB......Functions++++++++++++++++++
*************** Beginning of data *************************************
0001.00
A
UNIQUE
0002.00
A
R EMPMSTR
0003.00
A
EMPNO
3S 0
0004.00
A
ENAME
10A
0005.00
A
BSAL
7S 0
0006.00
A
DEPT
7A
DFT('A')
0007.00
A
CITY
5A
DFT('PUNE')
0008.00
A
K EMPNO
****************** End of data ****************************************

F3=Exit
F4=Prompt
F16=Repeat find

F5=Refresh
F9=Retrieve
F17=Repeat change

F10=Cursor
F11=Toggle
F24=More keys

Following is the display file


Columns . . . :
1 71
Edit
PB01U01D/MYSCR
SEU==>
MAIN
FMT A* .....A*. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7
*************** Beginning of data *************************************
0000.10
A*%%TS SD 20040928 130438 PB01U01
REL-V5R2M0 5722-WDS
0000.20
A*%%EC
0000.30
A
DSPSIZ(24 80 *DS3)
0000.40
A
R MAIN1
0000.50
A*%%TS SD 20040928 130438 PB01U01
REL-V5R2M0 5722-WDS
0000.60
A
CF03(03)
0000.70
A
3 35'INPUT'
0000.80
A
7 24'EMPNO'
0000.90
A
15 29'F3-TOEXIT'
0001.00
A
EMPNO
R
B 7 33REFFLD(EMPMSTR/EMPNO PB01U01D/
0001.10
A
MSG
20
O 12 33
****************** End of data ****************************************

F3=Exit
F4=Prompt
F16=Repeat find

F5=Refresh
F9=Retrieve
F17=Repeat change

F10=Cursor
F11=Toggle
F24=More keys

Above is the DDS (Data description specification) for display file and layout of
this screen MAIN is as follows

DukeStar Technologies Pvt. Ltd.


10/16
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

SIMPLE INPUT SCREEN

EMPNO

999-

OOOOOOOOOOOOOOOOOOOO
F3-TOEXIT

Step 3: start with RPG.


Define physical file with information data structure.
Columns . . . :
1 71
Edit
PB01U01S/MYRPG
SEU==>
EXCEP1
FMT FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of data *************************************
0001.00
FEMPMST
IF E
DISK
KINFDS DS
A

Prompt type . . .

Sequence number . . .

0001.00

File
End of
Designation
File
Sequence
F
Record
Address Type
Device
Continuation
DISK
K
File
File
Entry
Addition
Condition
DS
A

Filename
EMPMST
Mode of
Processing
Exit
INFDS

FX

File
Type
I

F3=Exit
F4=Prompt
F12=Cancel

F5=Refresh
F23=Select prompt

File
Format
E

F11=Previous record
F24=More keys

Above is F specification where we define INFDS. We define EMP physical file.


Now we will move our control to SR1 subroutine for that we have to write the
following information in IPFK or IPFC prompt.
Entries to Define and Name a File Information Data Structure

DukeStar Technologies Pvt. Ltd.


11/16
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

Position

Entry

7-52

Blank (if the information is specified on a separate continuation


line)

53

K (indicates a continuation line)

54-59

INFDS (identifies this data structure as the file information data


structure)

60-65

Name of the file information data structure

Columns . . . :
1 71
Edit
PB01U01S/MYRPG
SEU==>
EXCEP1
FMT FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of data *************************************
0001.00
FEMPMST IF E
DISK
KINFDS DS
A
0002.00
F
KINFSR SR1

Prompt type . . .
External
Record Name

FC

Sequence number . . .

Record Number
Field

F3=Exit
F4=Prompt
F12=Cancel

Continuation
K

F5=Refresh
F23=Select prompt

0002.00
Option
INFSR

F11=Previous record
F24=More keys

Entry
SR1

Subroutine
name

Now we will insert workstation file then define data structure having name DS using
IPDS prompt.

IPDS:
DS Specification line is broken into following parts
1-2
3-5
6
7-12

Positions

Name
Page
Line
Form type
Data structure name

13-16
17

External description

Entry
Page number
Line number
1
Blank
Data structure name
Blank
Blank
E

DukeStar Technologies Pvt. Ltd.


12/16
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16
18

Option

19-20
21-30

Record
identifying
indictors
External file name

31-43
44-47

Occurrences

48-51

Data structure length

52-74
75-80

comments

Blank
I
S
U
DS
External name or data
Structure
Blank
Blank
1-9999
Blank
1-9999
Blank
Optional

Record name: Type the external name of the record format.


Record Identifying indicators:
indicator.

Type a value from 01 to 99 to represent a general

Columns . . . :
1 71
Edit
PB01U01S/MYRPG
SEU==>
EXCEP1
FMT FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of data *************************************
0001.00
FEMPMST IF E
DISK
KINFDS DS
A
0002.00
F
KINFSR SR1
0003.00
FMAIN
CF E
WORKSTN
0004.00
IDS
DS

Prompt type . . .
Data Struct
Name
DS

Number

F3=Exit
F4=Prompt
F12=Cancel

DS

Sequence number . . .
Option

DS
DS

F5=Refresh
F23=Select prompt

External
File Name

0004.00
Occurs

Length

F11=Previous record
F24=More keys

Then insert field name AA and *STATUS at 52 position as shown below using IPJX
prompt.

DukeStar Technologies Pvt. Ltd.


13/16
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

IPJX:
Positions
Positions

Name
Name

7-20
21-30
31-52
53-58
59-60

Entry
Entry
Blank
Field name
Blank
Field name
Blank
L1-L9
Blank
M1-M9
Blank
Blank
01-99
H1-H9
U1-U8
RT
Blank
Optional

External field name


RPG field name
Control level

61-62

Match fields

63-64
65-70

Field indictors

71-74
75-80

Comments

Columns . . . :
1 71
Edit
PB01U01S/MYRPG
SEU==>
EXCEP1
FMT FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of data *************************************
0001.00
FEMPMST IF E
DISK
KINFDS DS
A
0002.00
F
KINFSR SR1
0003.00
FMAIN
CF E
WORKSTN
0004.00
IDS
DS
0005.00
I
*STATUS AA

Prompt type . . .
External
Field Name
Positive
Field

JX

Sequence number . . .

Field
Name
AA
Negative
Field

F3=Exit
F4=Prompt
F12=Cancel

Control
Level

0005.00

Matching
Fields

Zero /
Blank

F5=Refresh
F23=Select prompt

F11=Previous record
F24=More keys

Now simply insert message Duplicate using IPN prompt and do the coding as given
below.
Columns . . . :
1 71
Edit
PB01U01S/MYRPG
SEU==>
EXCEP1
FMT FX .....FFilenameIPEAF........L..I........Device+......KExit++Entry+A....U
*************** Beginning of data *************************************
0001.00
FEMPMST IF E
DISK
KINFDS DS
A
0002.00
F
KINFSR SR1
0003.00
FMAIN
CF E
WORKSTN
0004.00
IDS
DS
Error
Status
0005.00
I
*STATUS AA
0006.00
I
'DUPLICATE'
C
MSG1
0007.00
C
READ EMPMSTR
50
0008.00
C
*IN03
DOWEQ*OFF
0009.00
C
EE
TAG
DukeStar Technologies Pvt. Ltd.
14/16
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

0010.00
C
EXFMTMAIN1
0011.00
C
03
LEAVE
0012.00
C
WRITEEMPMSTR
0013.00
C
CLEARMSG
0014.00
C
ENDDO
0015.00
C
SETON
LR
0016.00
*************************************************************
0017.00
C
SR1
BEGSR
0018.00
C
AA
IFEQ 01021
0019.00
C
MOVE MSG1
MSG
0020.00
C
GOTO EE
0021.00
C
ENDIF
0022.00
C
ENDSR
****************** End of data ****************************************
F3=Exit
F4=Prompt
F16=Repeat find

F5=Refresh
F9=Retrieve
F17=Repeat change

F10=Cursor
F11=Toggle
F24=More keys

Above example shows you how to handle the file related error.
Now in next example see how to handle the program related error.
Program Exception/Errors
The exception/errors that occurred during program execution time are known as program
exception error. i.e. an error on a CALL operation code, division by zero, Square root of a
negative number etc. Therefore if you are doing above operations in a program its always
a good programming practice to provide logic to handle these errors.
A program-status data structure, identified by an S in position 18 of the data structure
statement, provides program exception/error information to the program. You can handle
these errors in one of following ways.

Use error indicator in position 56-57 of those operations that allows such an entry. If
error occurs than the indicator sets on. You can determine the action to be taken by
testing the indicator for on condition.

A program exception/error subroutine *PSSR can be used. This subroutine will


automatically receive control when a program exception /error occurs. Information
regarding the program exception/error is made available through a program status
data structure that will be described in next section

If the error indicator or the program exception/error subroutine is not present than
the RPG/400 default error handler handles program exception/error.

We use a subroutine *PSSR to handle the error, when error occurs program starts
execution of this subroutine.
*PSSR
BEGSR
------------------------------ENDSR
Above is the syntax for subroutine.
So how to implement it in our program is in the following example.

DukeStar Technologies Pvt. Ltd.


15/16
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Exception Handling
Day 16

Columns . . . :
1 71
Edit
PB01U01S/MYRPG
SEU==>
EXMP10
FMT * ..... *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7
*************** Beginning of data *************************************
0000.01
* PROGRAM FOR PROGRAM STATUS DS DEFINE MESSAGE USING IPN PROMPT.
0001.00
I
'OBJECT NOT FOUND'
C
MSG1
0001.01
* DEFINE DS USING IPDS PROMPT.
0002.00
IDS2
SDS
0001.01
* DEFINE FIELD NAME AND *STATUS AT 52 POSITION USING IPJX.
0003.00
I
*STATUS ST
0004.00
C
CALL 'RLG'
0005.00
C
A
TAG
0006.00
C
SETON
LR
0006.01
* SUBROUTINE FOR ERROR HANDLING
0007.00
C
*PSSR
BEGSR
0008.00
C
ST
IFEQ 211
0009.00
C
MSG1
DSPLY
0010.00
C
GOTO A
0011.00
C
ENDIF
0012.00
C
ENDSR
****************** End of data ****************************************

F3=Exit
F4=Prompt
F16=Repeat find

F5=Refresh
F9=Retrieve
F10=Cursor
F11=Toggle
F17=Repeat change
F24=More keys
(C) COPYRIGHT IBM CORP. 1981, 2002.

In above example we use to find out the whether the object of program is existing or not. If
program object is exist then Call command execute or call that particular program. If the
object of the program does not exist then error message will gets displayed Object Not
Found. So the code for that checking is 211.

DukeStar Technologies Pvt. Ltd.


16/16
No part of this document can be copied, reproduced in any form, complete or partial without written consent from DukeStar Technologies Pvt.
Ltd.

Das könnte Ihnen auch gefallen