Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate key error handling

Status
Not open for further replies.

ndevriendt

Programmer
Jan 8, 2002
74
0
0
BE
Hello,

I'm using the following statement to write a record


WRITE FILENAME 55
If *In55 = *On
CALL PROGX
EndIf

I want only call PROGX when the reason of the failing write command is 'DUPLICATE KEY ERROR'.
Is therefore a returing error code that I can test ?

Thanks for your time and answer

Devriendt Nico
 
Hi,
Status code 1021 is "Tried to write a record that already exists (file being used has unique keys and key is duplicate, or attempted to write duplicate relative record number to a subfile)."
To handle WRITE exceptions (file status codes greater than 1000), either the operation code extender ’E’ or an error indicator ER can be specified, but not both.

Here is an example.

Code:
D                SDS
D PGM_STATUS        *STATUS

C         WRITE    FILENAME                55
C         If       *In55 = *On [COLOR=red yellow]And PGM_STATUS = 01021[/color]
C         CALL      PROGX
C         EndIf

[b]OR[/b]

C          WRITE[COLOR=red yellow](E)[/color] FILENAME              [s][b]  55  [/b][/s]
C          If       [COLOR=red yellow]%STATUS = 01021[/color]
C          CALL      PROGX
C          EndIf

Check out File and Program Exception/Errors to get the whole list of file status codes.

_
 
Talkturkey:

Shouldn't that be

Code:
C          WRITE(E) FILENAME                 
C          If       %ERROR And %STATUS = 01021
C          CALL      PROGX
C          EndIf

You don't need the indicator when you use the (E) opcode extender; in that case, you have to condition it on %ERROR (because %STATUS could be 01021 from a previous error).

De mortuis nihil nisi bonum.

 
I also wish we could edit ones own posts.

Flapeyre,
When the operation code extender ’E’ is specified, before the operation begins, this extender sets the
%ERROR and %STATUS built-in functions to return zero.
Therefore, I do not think necessary to also test
%ERROR in that case. If no error occurs, %STATUS will be 0.

MONITOR is a good way to handle the file status as well.

In fact, there is an error in my previous post. I declared the Program Status Data Structure (PSDS) and should have declared the INFDS instead :
D INFDS DS
D FILE_STATUS *STATUS

 
Maybe so, but I think it's clearer to check for both %ERROR and %STATUS. In the examples IBM gives in the manual, they are always checking either the indicator or %ERROR before checking %STATUS.

De mortuis nihil nisi bonum.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top