Beruflich Dokumente
Kultur Dokumente
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
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
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
In addition, there are three special data structures, each with a specific purpose:
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
18
Blank: Other than a program status, data area or initialized data structure.
I
:
S :
U :
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
31-43
Blank
44-47
48-51
52-74
Blank
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
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.
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
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
F12=Cancel
Bottom
F13=How to use this display
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.
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
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
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
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
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
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
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
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
Exception Handling
Day 16
EMPNO
999-
OOOOOOOOOOOOOOOOOOOO
F3-TOEXIT
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
Exception Handling
Day 16
Position
Entry
7-52
53
54-59
60-65
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
Exception Handling
Day 16
18
Option
19-20
21-30
Record
identifying
indictors
External file name
31-43
44-47
Occurrences
48-51
52-74
75-80
comments
Blank
I
S
U
DS
External name or data
Structure
Blank
Blank
1-9999
Blank
1-9999
Blank
Optional
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.
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
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.
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.
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.