7.35.2 DELETE Comments / Warnings
-
The use of automatic "crossed update" checks by the DELETE command should be clearly understood.
Consider the following flow of commands:
FETCH WITH_KEY( ) or WITH_RRN( )
DISPLAY
IF_MODE *DELETE
DELETE
ENDIF
Since the DELETE command has no WITH_KEY or WITH_RRN parameter it is indicating that the last record read (by the FETCH command) should be deleted.
In this situation, the "crossed update window" is in the interval between the time the record was FETCHed and the time that it is DELETEd. This could be very long if the user went and had a cup of coffee when the DISPLAY command was on his/her workstation.
This is a correct and valid use of the automatic "crossed update" checking facility. If the record was changed by another job/user between the FETCH and the DELETE, then the DELETE will generate a "crossed update error" (which should be handled just like any other type of validation error).
Now consider this flow of commands:
FETCH WITH_KEY( ) or WITH_RRN( )
DISPLAY
IF_MODE *DELETE
DELETE WITH_KEY( ) or WITH_RRN( )
ENDIF
Since the DELETE command has a WITH_KEY or WITH_RRN parameter it is indicating that a specific record (or group of records) should be read and deleted.
This is a common coding mistake. Everybody knows that the WITH_KEY or WITH_RRN values on the DELETE command should/would be the same as those on the FETCH command. However, the RDML compiler cannot be sure that the values were not changed, so it is forced to (re)read the record before attempting the DELETE.
In this situation, the "crossed update window" is in the interval between the time the record is (re)read by the DELETE command and then deleted by the DELETE command. This interval is very short, and thus the "crossed update" check is effectively disabled.
This is not considered to be a valid and correct use of the DELETE command in an interactive program like this because it effectively disables the automatic "crossed update" check.
-
Where a DELETE operation is issued with no WITH_KEY, WHERE or WITH_RRN parameters specified the last record read from the file will be deleted. Thus the following are equivalent operations:
DELETE FROM_FILE(ORDHDR) WITH_KEY(#ORDNUM)
is functionally equivalent to:
FETCH FROM_FILE(ORDHDR) WITH_KEY(#ORDNUM)
DELETE FROM_FILE(ORDHDR)
and:
DELETE FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM)
is functionally equivalent to:
SELECT FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM)
DELETE FROM_FILE(ORDLIN)
ENDSELECT