/*********************************************************************
* Copyright (C) 2000 by Progress Software Corporation ("PSC"),       *
* 14 Oak Park, Bedford, MA 01730, and other contributors as listed   *
* below.  All Rights Reserved.                                       *
*                                                                    *
* The Initial Developer of the Original Code is PSC.  The Original   *
* Code is Progress IDE code released to open source December 1, 2000.*
*                                                                    *
* The contents of this file are subject to the Possenet Public       *
* License Version 1.0 (the "License"); you may not use this file     *
* except in compliance with the License.  A copy of the License is   *
* available as of the date of this notice at                         *
* http://www.possenet.org/license.html                               *
*                                                                    *
* Software distributed under the License is distributed on an "AS IS"*
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. You*
* should refer to the License for the specific language governing    *
* rights and limitations under the License.                          *
*                                                                    *
* Contributors: MIP Holdings (Pty) Ltd ("MIP")                       *
*               PSC                                                  *
*                                                                    *
*********************************************************************/

TRIGGER PROCEDURE FOR DELETE OF gsc_entity_mnemonic .

/* Created automatically using ERwin ICF Trigger template db/af/erw/afercustrg.i
   Do not change manually. Customisations to triggers should be placed in separate
   include files pulled into the trigger. ICF auto generates write trigger custom
   include files. Delete or create customisation include files need to be created
   manually. Be sure to put the hook in ERwin directly so as not to have you changes
   overwritten.
   User defined Macro (UDP) Summary (case sensitive)
   gsc_entity_mnemonic           Expands to full table name, e.g. gsm_user
   %TableFLA            Expands to table unique code, e.g. gsmus
   %TableObj            If blank or not defined expands to table_obj with no prefix (framework standard)
                        If defined, uses this field as the object field
                        If set to "none" then indicates table does not have an object field
   XYZ                  Do not define so we can compare against an empty string

   See docs for explanation of replication macros 
*/   

&SCOPED-DEFINE TRIGGER_TABLE gsc_entity_mnemonic
&SCOPED-DEFINE TRIGGER_FLA gscem
&SCOPED-DEFINE TRIGGER_OBJ entity_mnemonic_obj


DEFINE BUFFER lb_table FOR gsc_entity_mnemonic.      /* Used for recursive relationships */
DEFINE BUFFER lb1_table FOR gsc_entity_mnemonic.     /* Used for lock upgrades */

DEFINE BUFFER o_gsc_entity_mnemonic FOR gsc_entity_mnemonic.

/* Standard top of DELETE trigger code */
{af/sup/aftrigtopd.i}

  




/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic has gsm_filter_data ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gsm_filter_data WHERE
    gsm_filter_data.owning_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gsm_filter_data":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic has gsm_scm_xref ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gsm_scm_xref WHERE
    gsm_scm_xref.owning_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gsm_scm_xref":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic is the child of ryc_relationship ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST ryc_relationship WHERE
    ryc_relationship.child_entity = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|ryc_relationship":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic is the parent of ryc_relationship ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST ryc_relationship WHERE
    ryc_relationship.parent_entity = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|ryc_relationship":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic has gsc_entity_display_field ON PARENT DELETE CASCADE */
&IF DEFINED(lbe_entity_display_field) = 0 &THEN
  DEFINE BUFFER lbe_entity_display_field FOR gsc_entity_display_field.
  &GLOBAL-DEFINE lbe_entity_display_field yes
&ENDIF
FOR EACH gsc_entity_display_field NO-LOCK
   WHERE gsc_entity_display_field.entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic
   ON STOP UNDO, RETURN ERROR "AF^104^gscemtrigd.p^delete gsc_entity_display_field":U:
    FIND FIRST lbe_entity_display_field EXCLUSIVE-LOCK
         WHERE ROWID(lbe_entity_display_field) = ROWID(gsc_entity_display_field)
         NO-ERROR.
    IF AVAILABLE lbe_entity_display_field THEN
      DO:
        {af/sup/afvalidtrg.i &action = "DELETE" &table = "lbe_entity_display_field"}
      END.
END.





/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic has gst_audit ON PARENT DELETE CASCADE */
&IF DEFINED(lbe_audit) = 0 &THEN
  DEFINE BUFFER lbe_audit FOR gst_audit.
  &GLOBAL-DEFINE lbe_audit yes
&ENDIF
FOR EACH gst_audit NO-LOCK
   WHERE gst_audit.owning_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic
   ON STOP UNDO, RETURN ERROR "AF^104^gscemtrigd.p^delete gst_audit":U:
    FIND FIRST lbe_audit EXCLUSIVE-LOCK
         WHERE ROWID(lbe_audit) = ROWID(gst_audit)
         NO-ERROR.
    IF AVAILABLE lbe_audit THEN
      DO:
        {af/sup/afvalidtrg.i &action = "DELETE" &table = "lbe_audit"}
      END.
END.





/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic is the join partner for gsc_dataset_entity ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gsc_dataset_entity WHERE
    gsc_dataset_entity.join_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gsc_dataset_entity":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic is included in gsc_dataset_entity ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gsc_dataset_entity WHERE
    gsc_dataset_entity.entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gsc_dataset_entity":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic contains gst_record_version ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gst_record_version WHERE
    gst_record_version.entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gst_record_version":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic  gsm_comment ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gsm_comment WHERE
    gsm_comment.owning_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gsm_comment":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic is for gsm_security_structure ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gsm_security_structure WHERE
    gsm_security_structure.owning_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gsm_security_structure":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic is allocated to gsm_user_allocation ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gsm_user_allocation WHERE
    gsm_user_allocation.owning_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gsm_user_allocation":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic has gsm_entity_field ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gsm_entity_field WHERE
    gsm_entity_field.owning_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gsm_entity_field":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic uses gsc_entity_mnemonic_procedure ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gsc_entity_mnemonic_procedure WHERE
    gsc_entity_mnemonic_procedure.owning_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gsc_entity_mnemonic_procedure":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic  gsc_sequence ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gsc_sequence WHERE
    gsc_sequence.owning_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gsc_sequence":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic  gsm_category ON PARENT DELETE RESTRICT */
IF CAN-FIND(FIRST gsm_category WHERE
    gsm_category.related_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic) THEN
    DO:
      /* Cannot delete parent because child exists! */
      ASSIGN lv-error = YES lv-errgrp = "AF ":U lv-errnum = 101 lv-include = "gsc_entity_mnemonic|gsm_category":U.
      RUN error-message (lv-errgrp, lv-errnum, lv-include).
    END.



/* Generated by ICF ERwin Template */
/* gsc_entity_mnemonic is for the owning object in the related gsm_category ON PARENT DELETE SET NULL */

&IF DEFINED(lbe_category) = 0 &THEN
  DEFINE BUFFER lbe_category FOR gsm_category.
  &GLOBAL-DEFINE lbe_category yes
&ENDIF
FOR EACH gsm_category NO-LOCK
   WHERE gsm_category.owning_entity_mnemonic = gsc_entity_mnemonic.entity_mnemonic
   ON STOP UNDO, RETURN ERROR "AF^104^gscemtrigd.p^update gsm_category":U:
    FIND FIRST lbe_category EXCLUSIVE-LOCK
         WHERE ROWID(lbe_category) = ROWID(gsm_category)
         NO-ERROR.
    IF AVAILABLE lbe_category THEN
      DO:
        
        ASSIGN lbe_category.owning_entity_mnemonic = "":U .
      END.
END.





/* Generic comments deletion */
DEFINE BUFFER lbx_gsm_comment FOR gsm_comment.
DEFINE BUFFER lby_gsm_comment FOR gsm_comment.
IF CAN-FIND(FIRST lbx_gsm_comment 
            WHERE lbx_gsm_comment.owning_obj = gsc_entity_mnemonic.{&TRIGGER_OBJ}) THEN
    FOR EACH lbx_gsm_comment NO-LOCK
       WHERE lbx_gsm_comment.owning_obj = gsc_entity_mnemonic.{&TRIGGER_OBJ}
       ON STOP UNDO, RETURN ERROR "AF^104^gscemtrigd.p^delete gsm_comment":U:
        FIND FIRST lby_gsm_comment EXCLUSIVE-LOCK
             WHERE ROWID(lby_gsm_comment) = ROWID(lbx_gsm_comment)
             NO-ERROR.
        IF AVAILABLE lby_gsm_comment THEN
          DO:
            {af/sup/afvalidtrg.i &action = "DELETE" &table = "lby_gsm_comment"}
          END.
    END.
/* Generic security allocation deletion */
DEFINE BUFFER lbx_gsm_user_allocation FOR gsm_user_allocation.
DEFINE BUFFER lby_gsm_user_allocation FOR gsm_user_allocation.
IF CAN-FIND(FIRST lbx_gsm_user_allocation 
            WHERE lbx_gsm_user_allocation.owning_obj = gsc_entity_mnemonic.{&TRIGGER_OBJ}) THEN
    FOR EACH lbx_gsm_user_allocation NO-LOCK
       WHERE lbx_gsm_user_allocation.owning_obj = gsc_entity_mnemonic.{&TRIGGER_OBJ}
       ON STOP UNDO, RETURN ERROR "AF^104^gscemtrigd.p^delete gsm_user_allocation":U:
        FIND FIRST lby_gsm_user_allocation EXCLUSIVE-LOCK
             WHERE ROWID(lby_gsm_user_allocation) = ROWID(lbx_gsm_user_allocation)
             NO-ERROR.
        IF AVAILABLE lby_gsm_user_allocation THEN
          DO:
            {af/sup/afvalidtrg.i &action = "DELETE" &table = "lby_gsm_user_allocation"}
          END.
    END.
/* Generic multi-media deletion */
DEFINE BUFFER lbx_gsm_multi_media FOR gsm_multi_media.
DEFINE BUFFER lby_gsm_multi_media FOR gsm_multi_media.
IF CAN-FIND(FIRST lbx_gsm_multi_media 
            WHERE lbx_gsm_multi_media.owning_obj = gsc_entity_mnemonic.{&TRIGGER_OBJ}) THEN
    FOR EACH lbx_gsm_multi_media NO-LOCK
       WHERE lbx_gsm_multi_media.owning_obj = gsc_entity_mnemonic.{&TRIGGER_OBJ}
       ON STOP UNDO, RETURN ERROR "AF^104^gscemtrigd.p^delete gsm_multi_media":U:
        FIND FIRST lby_gsm_multi_media EXCLUSIVE-LOCK
             WHERE ROWID(lby_gsm_multi_media) = ROWID(lbx_gsm_multi_media)
             NO-ERROR.
        IF AVAILABLE lby_gsm_multi_media THEN
          DO:
            {af/sup/afvalidtrg.i &action = "DELETE" &table = "lby_gsm_multi_media"}
          END.
    END.










/* Update Audit Log */
IF CAN-FIND(FIRST gsc_entity_mnemonic
            WHERE gsc_entity_mnemonic.entity_mnemonic = 'gscem':U
              AND gsc_entity_mnemonic.auditing_enabled = YES) THEN
  RUN af/app/afauditlgp.p (INPUT "DELETE":U, INPUT "gscem":U, INPUT BUFFER gsc_entity_mnemonic:HANDLE, INPUT BUFFER o_gsc_entity_mnemonic:HANDLE).

/* Standard bottom of DELETE trigger code */
{af/sup/aftrigendd.i}


/* Place any specific DELETE trigger customisations here */



