Gray & Associates

Gray Grodzicki

(415) 397-1796

Confirm Delete without a Confirm Prompt.

The standard in many shops is to set the confirm prompt option to "No" for interactive functions. This means that you do not get the confirm prompt at the bottom of the screen before processing updates in Edit File and Edit Record functions. It is often desirable to have a confirm prompt before deleting records for all the obvious reasons. It may also be desirable to validate a record marked for deletion before allowing the delete.

If you use the options in an edit file which allows Change and Delete, and select a record for deletion in the subfile select, the validation processing is skipped and the record is just deleted as part of the update process. This is logical. It stands to reason that you would not want to be required to key valid "Customer numbers" or "Start dates" before you could delete a record which was entered in error or is otherwise invalid.

On the other hand, you may want to prevent deletion of a record with a Status = "Closed" or "Active" and issue an error message. You may also want to issue a confirm delete message, "PRESS F11 to Confirm Delete" as a safeguard for the user. This article discusses a technique for the Edit File function. Some variation will work for Edit Record.

The Problem:

When a subfile record is marked for deletion (SFLSEL = "4"), and enter is pressed, we want to issue a message and defer confirm before updating anything. If F11 is then pressed, the selected records are to be deleted. If any additional records are selected for deletion, the message should be re-issued and F11 must be pressed again before anything is updated. We also want to prevent any record with "Status = ACTIVE" from being deleted.

The Code:

1. A User Function Field , "#Delete", must be added to the SFLRCD and hidden. This field is a status field with a value of "YES" or "NO" and is used internally to determine if this is the first time that this record has been selected for deletion. "#Delete" is initialized to "NO" and re-initialized to "NO" any time this record is Validated with SFLSEL not equal "*Delete request". "#Delete" is changed to "YES" each time the confirm delete message is sent.

2. The default "Change Object" function is replaced with an EXCINTFUN, "Chg or Dlt Customer". The parameters for this new function are all of the fields on the file record (same as the parameters for the "Change Object") plus the "#Delete" field. All parameters are input. This "Chg or Delete" function just calls the default CHGOBJ or DLTOBJ based on the value in the parameter #Delete.

3. If any records are deleted, *Reload subfile is required or the deleted records remain on the screen and will cause an error ("Change or Delete could not find record."). This code is placed in the "Extra processing after DBF update".

1> USER: Initialize subfile record (existing record)

. ---

: RCD.#Delete = CND.No

. ---

1> USER: Validate subfile record fields

. ---

: -CASE

: |-RCD.*SFLSEL is *Delete request

: | -CASE

: ||-RCD.Customer Status is ACTIVE

: ||Send error message - "Cus Status=Active-No Delete"

: ||-CTL.*CMD Key is *Delete

: || -CASE

: || |-RCD.#Delete=No

: || | RCD.#Delete=Yes

: || | PGM.*Defer confirm = CND.Defer confirm

: || | Send information message - "F11 Confirm Delete"

: || |-ENDCASE

: ||-*OTHERWISE

***||-*** SFLSEL = DELETE

***||-*** NOT STATUS = ACTIVE

***||-*** NOT F11

***||-*** ISSUE THE CONFIRM PROMPT MESSAGE

: || RCD.#Delete=Yes

: || PGM.*Defer confirm = CND.Defer confirm

: || Send information message - "F11 Confirm Delete"

: ||-ENDCASE

: |-*OTHERWISE

***||-*** SFLSEL NE DELETE

: || RCD.#Delete=No

: |*** EDITS for SFLRCD's go here......

: |-ENDCASE

1CHG or DLT Customer EXCINTFUN

**(Replaces Change Object for Customer) **

2CHG or DLT Customer

2. ---

2: -CASE

2: |-PAR.#Delete is Yes

2: |Delete Customer - CustomerDLTOBJ

2: |-*OTHERWISE

2: |Change Customer - CustomerCHGOBJ

2: |-ENDCASE

2. ---

1> USER: Extra processing after DBF update

. ---

: -CASE

: |-RCD.#Delete is Yes

: |PGM.*Reload subfile = CND.*Yes

: |-ENDCASE

. ---

This example is for an EDTFIL which allows only "Change" (function options F7). If "Add" is required, you must either hide the SFLSEL in "ADD Mode" or insert code to recognize "Add Mode".

1