DBA Data[Home] [Help]

APPS.AME_ENGINE SQL Statements

The following lines contain the word 'select', 'insert', 'update' or 'delete':

Line: 18

    set engIsTestTransaction to false (via a call to updateTransactionState), and it should
    set engIsLocalTransaction to true.  The API should set both engIsTestTransaction and
    engIsLocalTransaction to false.  The ame_util.runtimeException checks engIsLocalTransaction
    to determine whether to log an exception to the Workflow context stack.
  */
  engIsLocalTransaction boolean := true;
Line: 28

    a value of true in the absence of a call to updateTransactionState, before the
    call to ame_util.runtimeException.  That is, unless a call to updateTransactionState
    sets this variable's value, we assume the transaction is a test transaction, to
    avoid writing spurious exceptions to the Workflow context stack.
   */
  engIsTestTransaction boolean := true;
Line: 35

    updateTransactionState sets the following variables.  They indicate which parts of its
    cycle the engine should or should not execute.
  */
  engPrepareItemData boolean;
Line: 46

  engUpdateCurrentApproverList boolean;
Line: 47

  engUpdateOldApproverList boolean;
Line: 79

  engDeletedApproverList ame_util.approversTable2; /* kept compact */
Line: 80

  engInsertedApproverList ame_util.approversTable2; /* kept compact */
Line: 82

  /* lists related to approver insertion and deletion */
  engInsertionOrderTypeList ame_util.stringList; /* corresponds in order to engInsertedApproverList */
Line: 84

  engInsertionParameterList ame_util.longestStringList; /* corresponds in order to engInsertedApproverList */
Line: 85

  engInsertionIsSpecialForwardee ame_util.charList; /* ame_util.booleanTrue if insertee is a special forwardee */
Line: 86

  engInsApproverIndex ame_util.idList; /*maintain the approver index for the insertion*/
Line: 267

      1.  deletes a row in the compact engApp lists if the rule represented by the row
          is of insufficient relative priority.
      2.  re-compacts the same lists (preserving the above lexicographic ordering).
    At this point, a rule with several actions still appears just once in the engApp
    lists.  The procedure fetchApplicableActions
      1.  populates engAppActionTypeIds, engAppParameters, and engAppParameterTwos.
      2.  splits out the actions in a rule so that the rule has one row in the engApp
          lists for each of the rule's actions.
      3.  converts each combination rule's rule type to the rule type that corresponds
          with the rule's action type.
      4.  re-sorts the lists lexicographically by these values:
            rule's item-class order number
            rule's item-class ID
            item ID of the item to which the rule applies
            rule type
            action-type order number
            action-type ID.
    fetchApplicableActions deletes engAppPriorities because priorities have already been
    processed; so engAppPriorities should not be referenced after fetchApplicableActions
Line: 287

      1.  deletes from the engApp variables any list-creation (authority) rules
          suppressed by the exception rules.
      2.  re-compacts the lists (preserving the above lexicographic ordering).
      3.  converts the exception rules to list-creation rules.
    processExceptions occurs in the engine algorithm after applicable actions have been
    fetched, so that the actions of any list-creation rules suppressed by exception
    rules will have been fetched unnecessarily.  The assumption here is that exception
    rules are deprecated, so if performance becomes an issue, exception rules should be
    converted to list-creation rules with appropriate priorities.
  */
  engAppActionTypeIds ame_util.idList;
Line: 328

     needs to be called a second time after adhoc insertions and surrogate processing */
  engRepeatSubstitutions    boolean;
Line: 399

  engStInsertionIndexes ame_util.idList;
Line: 400

  engInsertionOrderList ame_util.idList;
Line: 403

  engInsertionReasonList ame_util.stringList;
Line: 404

  engInsertionDateList ame_util.dateList;
Line: 460

  procedure fetchDeletedApprovers;
Line: 464

  procedure fetchInsertedApprovers;
Line: 475

  procedure insertIntoTransApprovalHistory
              (transactionIdIn  ame_trans_approval_history.transaction_id%type
              ,applicationIdIn  ame_trans_approval_history.application_id%type
              ,orderNumberIn    ame_trans_approval_history.order_number%type
              ,nameIn           ame_trans_approval_history.name%type
              ,appCategoryIn    ame_trans_approval_history.approver_category%type
              ,itemClassIn      ame_trans_approval_history.item_class%type
              ,itemIdIn         ame_trans_approval_history.item_id%type
              ,actionTypeIdIn   ame_trans_approval_history.action_type_id%type
              ,authorityIn      ame_trans_approval_history.authority%type
              ,statusIn         ame_trans_approval_history.status%type
              ,grpOrChainIdIn   ame_trans_approval_history.group_or_chain_id%type
              ,occurrenceIn     ame_trans_approval_history.occurrence%type
              ,apiInsertionIn   ame_trans_approval_history.api_insertion%type
              ,memberOrderNumberIn ame_trans_approval_history.member_order_number%type
              ,notificationIdIn ame_trans_approval_history.notification_id%type
              ,userCommentsIn   ame_trans_approval_history.user_comments%type
              ,dateClearedIn    ame_trans_approval_history.date_cleared%type
              ,historyTypeIn    varchar2);
Line: 511

  procedure processAdHocInsertions;
Line: 517

  procedure populateInsertionIndexes(indexIn in integer
                                    ,insertionOrderIn in integer);
Line: 524

                       fetchInsertionsIn in boolean,
                       fetchDeletionsIn in boolean,
                       fetchAttributeValuesIn in boolean,
                       fetchInactiveAttValuesIn in boolean,
                       processProductionActionsIn in boolean,
                       processProductionRulesIn in boolean,
                       updateCurrentApproverListIn in boolean,
                       updateOldApproverListIn in boolean,
                       processPrioritiesIn in boolean,
                       prepareItemDataIn in boolean,
                       prepareRuleIdsIn in boolean,
                       prepareRuleDescsIn in boolean,
                       prepareApproverTreeIn in boolean default false,
                       transactionIdIn in varchar2,
                       ameApplicationIdIn in integer default null,
                       fndApplicationIdIn in integer default null,
                       transactionTypeIdIn in varchar2 default null);
Line: 541

  procedure setInsertedApprovalStatus(currentApproverIndexIn in integer
                                      ,approvalStatusIn in varchar2);
Line: 545

  procedure updateOldApproverList;
Line: 910

  function insertionExists(orderTypeIn in varchar2,
                           parameterIn in varchar2) return boolean as
    begin
      for i in 1 .. engInsertionOrderTypeList.count loop
        if(engInsertionOrderTypeList(i) = orderTypeIn and
           engInsertionParameterList(i) = parameterIn) then
          return(true);
Line: 923

                                    routineNameIn => 'insertionExists',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 928

    end insertionExists;
Line: 1028

      select application_id
        into ameApplicationId
        from ame_calling_apps
        where
          fnd_application_id = fndApplicationIdIn and
          ((transactionTypeIdIn is null and transaction_type_id is null) or
           (transaction_type_id = transactionTypeIdIn)) and
          /* Don't use engEffectiveRuleDate here. */
          sysdate between
            start_date and
            nvl(end_date - ame_util.oneSecond, sysdate) and
          rownum < 2; /* Avoids second fetch otherwise required by ANSI standard to check for too many rows. */
Line: 1133

      if(actionTypeIdIn = ame_util.nullInsertionActionTypeId or actionTypeIdIn = -2 ) then
        return(null);
Line: 1511

          If we're not trying to match an inserted approver with nullInsertionActionTypeId and
          nullInsertionGroupOrChainId, and one of the input arguments is null, match the most
          recently added group or chain.
        */
        for i in reverse 1 .. engStApproversCount loop
          if(engStApprovers(i).action_type_id <> ame_util.nullInsertionActionTypeId and
             engStApprovers(i).group_or_chain_id <> ame_util.nullInsertionGroupOrChainId and
             engStApprovers(i).item_class is not null and
             engStApprovers(i).item_id is not null and
             engStApprovers(i).action_type_id is not null and
             engStApprovers(i).group_or_chain_id is not null) then
            itemClass := engStApprovers(i).item_class;
Line: 1537

          One of the input arguments is null, and all approvers in the list have nullInsertionActionTypeId and
          nullInsertionGroupOrChainId.  So these are the only action-type ID and group-or-chain ID we can match.
          In this case, match the item class and item ID of the most recent insertion.
        */
        itemClass := engStApprovers(engStApproversCount).item_class;
Line: 1591

      select state
        into tempState
        from ame_temp_handler_states
        where
          handler_name = handlerName and
          ((application_id is null and engAmeApplicationId is null) or
           (application_id = engAmeApplicationId)) and
          ((parameter is null and parameterIn is null) or
           (parameter = parameterIn)) and
          rownum < 2; /* Avoids second fetch otherwise required by ANSI standard to check for too many rows. */
Line: 1668

      select attribute_value_1 into tempValue from ame_test_trans_att_values
        where application_id = engAmeApplicationId
          and transaction_id = engTransactionId
          and attribute_id = attributeIdIn
          and item_class_id = itemClassIdIn
          and item_id    = itemIdIn;
Line: 1678

            select attribute_value_1
              into tempValue
              from ame_test_trans_att_values
             where application_id = engAmeApplicationId
               and transaction_id = engTransactionId
               and attribute_id = attributeIdIn
               and item_class_id = getItemClassId(ame_util.headerItemClassName)
               and item_id    = engTransactionId;
Line: 1923

  function getNextInsertionOrder return integer as
    maxInsertionOrderNumber number;
Line: 1926

      select max(insertion_order)
        into maxInsertionOrderNumber
        from ame_temp_insertions
       where transaction_id = engTransactionId
         and application_id = engAmeApplicationId;
Line: 1931

      if maxinsertionOrderNumber is null
      then
        return 1;
Line: 1935

        return (maxInsertionOrderNumber + 1);
Line: 1940

                                    routineNameIn => 'getNextInsertionOrder',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 1945

    end getNextInsertionOrder;
Line: 2166

         approverIn.api_insertion is null or
         approverIn.authority is null or
         approverIn.action_type_id is null or
         approverIn.group_or_chain_id is null or
         approverIn.occurrence is null or
         approverIn.source is null or
         approverIn.item_class is null or
         approverIn.item_id is null or
         approverIn.item_class_order_number is null or
         approverIn.item_order_number is null or
         approverIn.sub_list_order_number is null or
         approverIn.action_type_order_number is null or
         approverIn.group_or_chain_order_number is null or
         approverIn.member_order_number is null) then
        raise nullFieldException;
Line: 2296

    /* insert the approver into the tree.In the way if any of other nodes  */
    /* are missing create them.                                            */
    previousTreeNodeIndex := 1;
Line: 2505

        select count(*)
          into tempApproverTypeCount
          from ame_approver_types
         where orig_system = approverIn.orig_system
           and sysdate between start_date and end_date;
Line: 2555

      delete
        from ame_temp_handler_states
        where
          handler_name = handlerName and
          application_id = engAmeApplicationId and
          ((parameter is null and parameterIn is null) or
           (parameter = parameterIn));
Line: 2611

      engAppItemClassIds.delete(tempFirstIndex, tempLastIndex);
Line: 2612

      engAppItemIds.delete(tempFirstIndex, tempLastIndex);
Line: 2613

      engAppApproverCategories.delete(tempFirstIndex, tempLastIndex);
Line: 2614

      engAppRuleIds.delete(tempFirstIndex, tempLastIndex);
Line: 2615

      engRuleAppliedYN.delete(tempFirstIndex, tempLastIndex);
Line: 2616

      engAppRuleTypes.delete(tempFirstIndex, tempLastIndex);
Line: 2617

      engAppRuleItemClassIds.delete(tempFirstIndex, tempLastIndex);
Line: 2618

      engAppAppItemIds.delete(tempFirstIndex, tempLastIndex);
Line: 2620

        engAppPriorities.delete(tempFirstIndex, tempLastIndex);
Line: 2623

        engAppActionTypeIds.delete(tempFirstIndex, tempLastIndex);
Line: 2626

        engAppParameters.delete(tempFirstIndex, tempLastIndex);
Line: 2627

        engAppParameterTwos.delete(tempFirstIndex, tempLastIndex);
Line: 2659

        deletes them in an unpredictable order, and does not re-compact the lists; so the
Line: 2702

        tempPendingRuleIds.delete;
Line: 2717

        /* Delete this condition from currentConditionRuleCounts. */
        currentConditionRuleCounts.delete(tempConditionId);
Line: 2731

            tempIndex2 indexes the current currentAC variables, which may be deleted.  tempIndex3
            indexes tempPendingRuleIds.
          */
          tempIndex := currentACUsageConditionIds.first;
Line: 2742

              currentACUsageConditionIds.delete(tempIndex2);
Line: 2743

              currentACUsageRuleIds.delete(tempIndex2);
Line: 2792

            indexes the current currentAC variable, which may be deleted; and tempIndex3
Line: 2805

                currentACUsageConditionIds.delete(tempIndex2);
Line: 2806

                currentACUsageRuleIds.delete(tempIndex2);
Line: 3004

        deletes them in an unpredictable order, and does not re-compact the lists; so the
Line: 3049

        tempPendingRuleIds.delete;
Line: 3064

        /* Delete this condition from currentConditionRuleCounts. */
        currentConditionRuleCounts.delete(tempConditionId);
Line: 3095

            tempIndex2 indexes the current currentAC variables, which may be deleted.  tempIndex3
            indexes tempPendingRuleIds.
          */
          tempIndex := currentACUsageConditionIds.first;
Line: 3106

              currentACUsageConditionIds.delete(tempIndex2);
Line: 3107

              currentACUsageRuleIds.delete(tempIndex2);
Line: 3151

            indexes the current currentAC variable (which may be deleted).
          */
          for pendingRuleIndex in 1 .. tempPendingRuleIds.count loop
            tempIndex := currentACUsageConditionIds.first;
Line: 3163

                currentACUsageConditionIds.delete(tempIndex2);
Line: 3164

                currentACUsageRuleIds.delete(tempIndex2);
Line: 3202

      select
        ame_rules.rule_id rule_id,
        nvl(ame_rules.item_class_id,
            headerItemClassIdIn) item_class_id,
        ame_rules.rule_type rule_type,
        ame_rule_usages.priority priority,
        ame_rule_usages.approver_category approver_category
      from
        ame_rules,
        ame_rule_usages,
        ame_item_class_usages
      where
        ame_rules.rule_id = ame_rule_usages.rule_id and
        ame_rule_usages.item_id = engAmeApplicationId and
        nvl(ame_rules.item_class_id, headerItemClassIdIn) = ame_item_class_usages.item_class_id and
        ame_item_class_usages.application_id = engAmeApplicationId and
        (processPrioritiesIn = ame_util.booleanFalse or
         (ame_rules.rule_type = ame_util.combinationRuleType and
          (combinationRulePriorityModeIn <> ame_util.absoluteRulePriority or
           combinationRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.authorityRuleType and
          (authorityRulePriorityModeIn <> ame_util.absoluteRulePriority or
           authorityRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.exceptionRuleType and
          (exceptionRulePriorityModeIn <> ame_util.absoluteRulePriority or
           exceptionRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.listModRuleType and
          (listModRulePriorityModeIn <> ame_util.absoluteRulePriority or
           listModRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.substitutionRuleType and
          (substRulePriorityModeIn <> ame_util.absoluteRulePriority or
           substRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.preListGroupRuleType and
          (preRulePriorityModeIn <> ame_util.absoluteRulePriority or
           preRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.postListGroupRuleType and
          (postRulePriorityModeIn <> ame_util.absoluteRulePriority or
           postRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.productionRuleType and
          (productionRulePriorityModeIn <> ame_util.absoluteRulePriority or
           productionRuleThresholdIn >= ame_rule_usages.priority))) and
        (processProductionRulesIn = ame_util.booleanTrue or
         ame_rules.rule_type <> ame_util.productionRuleType) and
        not exists (select *
                      from
                        ame_conditions,
                        ame_condition_usages
                      where
                        ame_conditions.condition_type <> ame_util.listModConditionType and
                        ame_conditions.condition_id = ame_condition_usages.condition_id and
                        ame_condition_usages.rule_id = ame_rules.rule_id and
                        engEffectiveRuleDate between
                          ame_conditions.start_date and
                          nvl(ame_conditions.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
                        engEffectiveRuleDate between
                          ame_condition_usages.start_date and
                          nvl(ame_condition_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
                        /* Avoids second fetch otherwise required by ANSI standard to check for too many rows. */
                        rownum < 2) and
        engEffectiveRuleDate between
          ame_rules.start_date and
          nvl(ame_rules.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
        engEffectiveRuleDate between
          ame_rule_usages.start_date and
          nvl(ame_rule_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
        engEffectiveRuleDate between
          ame_item_class_usages.start_date and
          nvl(ame_item_class_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate)
      order by
        ame_item_class_usages.item_class_order_number,
        item_class_id,
        ame_rules.rule_type,
        ame_rules.rule_id;
Line: 3478

      select
        condition_id,
        string_value
      from ame_string_values
      where
        condition_id in
          (select ame_condition_usages.condition_id
            from
              ame_attributes,
              ame_conditions,
              ame_condition_usages,
              ame_rule_usages
            where
              ame_attributes.attribute_type = ame_util.stringAttributeType and
              ame_attributes.attribute_id = ame_conditions.attribute_id and
              ame_conditions.condition_id = ame_condition_usages.condition_id and
              ame_condition_usages.rule_id = ame_rule_usages.rule_id and
              ame_rule_usages.item_id = engAmeApplicationId and
              engEffectiveRuleDate between
                ame_attributes.start_date and
                nvl(ame_attributes.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
              engEffectiveRuleDate between
                ame_conditions.start_date and
                nvl(ame_conditions.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
              engEffectiveRuleDate between
                ame_condition_usages.start_date and
                nvl(ame_condition_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
              engEffectiveRuleDate between
                ame_rule_usages.start_date and
                nvl(ame_rule_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate)) and
        engEffectiveRuleDate between
          ame_string_values.start_date and
          nvl(ame_string_values.end_date - ame_util.oneSecond, engEffectiveRuleDate)
      order by condition_id;
Line: 3531

      select
        ame_conditions.condition_id condition_id,
        ame_conditions.condition_type condition_type,
        ame_conditions.attribute_id attribute_id,
        ame_conditions.parameter_one parameter_one,
        ame_conditions.parameter_two parameter_two,
        ame_conditions.parameter_three parameter_three,
        ame_conditions.include_lower_limit,
        ame_conditions.include_upper_limit,
        ame_condition_usages.rule_id rule_id,
        ame_rules.rule_type rule_type,
        nvl(ame_rules.item_class_id,
            headerItemClassIdIn) rule_item_class,
        ame_rule_usages.priority priority,
        ame_rule_usages.approver_category
      from
        ame_attributes,
        ame_conditions,
        ame_condition_usages,
        ame_rules,
        ame_rule_usages
      where
        ame_attributes.attribute_id = ame_conditions.attribute_id and
        ame_conditions.condition_type <> ame_util.listModConditionType and
        ame_conditions.condition_id = ame_condition_usages.condition_id and
        ame_condition_usages.rule_id = ame_rules.rule_id and
        ame_rules.rule_id = ame_rule_usages.rule_id and
        ame_rule_usages.item_id = engAmeApplicationId and
        (processPrioritiesIn = ame_util.booleanFalse or
         (ame_rules.rule_type = ame_util.combinationRuleType and
          (combinationRulePriorityModeIn <> ame_util.absoluteRulePriority or
           combinationRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.authorityRuleType and
          (authorityRulePriorityModeIn <> ame_util.absoluteRulePriority or
           authorityRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.exceptionRuleType and
          (exceptionRulePriorityModeIn <> ame_util.absoluteRulePriority or
           exceptionRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.listModRuleType and
          (listModRulePriorityModeIn <> ame_util.absoluteRulePriority or
           listModRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.substitutionRuleType and
          (substRulePriorityModeIn <> ame_util.absoluteRulePriority or
           substRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.preListGroupRuleType and
          (preRulePriorityModeIn <> ame_util.absoluteRulePriority or
           preRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.postListGroupRuleType and
          (postRulePriorityModeIn <> ame_util.absoluteRulePriority or
           postRuleThresholdIn >= ame_rule_usages.priority)) or
         (ame_rules.rule_type = ame_util.productionRuleType and
          (productionRulePriorityModeIn <> ame_util.absoluteRulePriority or
           productionRuleThresholdIn >= ame_rule_usages.priority))) and
        (processProductionRulesIn = ame_util.booleanTrue or
         ame_rules.rule_type <> ame_util.productionRuleType) and
        engEffectiveRuleDate between
          ame_attributes.start_date and
          nvl(ame_attributes.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
        engEffectiveRuleDate between
          ame_conditions.start_date and
          nvl(ame_conditions.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
        engEffectiveRuleDate between
          ame_condition_usages.start_date and
          nvl(ame_condition_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
        engEffectiveRuleDate between
          ame_rules.start_date and
          nvl(ame_rules.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
        engEffectiveRuleDate between
          ame_rule_usages.start_date and
          nvl(ame_rule_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate)
      order by
        rule_item_class,
        ame_rules.rule_type,
        ame_rules.rule_id,
        ame_attributes.item_class_id;
Line: 3774

      select
        ame_actions.action_type_id,
        ame_actions.parameter,
        ame_actions.parameter_two
        from
          ame_actions,
          ame_action_usages
        where
          ame_actions.action_id = ame_action_usages.action_id and
          ame_action_usages.rule_id = ruleIdIn and
          engEffectiveRuleDate between
            ame_actions.start_date and
            nvl(ame_actions.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
          engEffectiveRuleDate between
            ame_action_usages.start_date and
            nvl(ame_action_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate);
Line: 3803

      /* Delete priorities, to make sure they don't get used from here on. */
      engAppPriorities.delete;
Line: 3809

        tempActionTypeIds.delete;
Line: 3810

        tempParameters.delete;
Line: 3811

        tempParameterTwos.delete;
Line: 3899

      engAppLMSubItemClassIds.delete;
Line: 3900

      engAppLMSubItemIds.delete;
Line: 3915

      select
        ame_attributes.attribute_id attribute_id,
        ame_attributes.name attribute_name,
        ame_attributes.attribute_type attribute_type,
        ame_attributes.item_class_id item_class_id,
        ame_attribute_usages.query_string,
        ame_attribute_usages.is_static
        from
          ame_attributes,
          ame_attribute_usages,
          ame_item_class_usages
        where
          ame_attributes.name not in (ame_util.workflowItemKeyAttribute, ame_util.workflowItemTypeAttribute) and
          ame_attributes.attribute_id = ame_attribute_usages.attribute_id and
          ame_attribute_usages.application_id = applicationIdIn and
          ame_item_class_usages.application_id = applicationIdIn and
          ame_attributes.item_class_id = ame_item_class_usages.item_class_id and
          (fetchInactivesIn = ame_util.booleanTrue or
           ame_attribute_usages.use_count > 0 or
           ame_attributes.attribute_id in
            (select ame_attributes2.attribute_id
              from
                ame_attributes ame_attributes2,
                ame_mandatory_attributes
              where
                ame_attributes2.attribute_id = ame_mandatory_attributes.attribute_id and
                ame_mandatory_attributes.action_type_id = -1 and
                engEffectiveRuleDate between
                  ame_attributes2.start_date and
                  nvl(ame_attributes2.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
                engEffectiveRuleDate between
                  ame_mandatory_attributes.start_date and
                  nvl(ame_mandatory_attributes.end_date - ame_util.oneSecond, engEffectiveRuleDate))) and
          engEffectiveRuleDate between
            ame_attributes.start_date and
            nvl(ame_attributes.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
          engEffectiveRuleDate between
            ame_attribute_usages.start_date and
            nvl(ame_attribute_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
          engEffectiveRuleDate between
            ame_item_class_usages.start_date and
            nvl(ame_item_class_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate)
        /*
          The order-by conditions are all necessary.  The second is to break
          item_class_order_number ties in a determinate order.  The third is
          to display attribute names in alphabetical order on the test tab.
          Compare the itemClassUsageCursor cursor in the procedure updateTransactionState.
        */
        order by
          ame_item_class_usages.item_class_order_number,
          ame_item_class_usages.item_class_id,
          ame_attributes.name;
Line: 3968

      select
        attribute_value_1,
        attribute_value_2,
        attribute_value_3
      from ame_test_trans_att_values
      where
        application_id = engAmeApplicationId and
        transaction_id = engTransactionId and
        attribute_id = attributeIdIn
      order by item_id;
Line: 3979

      select attribute_value_1
      from ame_test_trans_att_values
      where
        application_id = engAmeApplicationId and
        transaction_id = engTransactionId and
        attribute_id = attributeIdIn
      order by item_id;
Line: 3987

      select attribute_value_1
      from ame_test_trans_att_values
      where
        application_id = engAmeApplicationId and
        transaction_id = engTransactionId and
        attribute_id = attributeIdIn and
        item_class_id = getItemClassId(ame_util.headerItemClassName) and
        item_id = engTransactionId;
Line: 4023

        in a select statement.
      */
      if(fetchInactivesIn) then
        fetchInactives := ame_util.booleanTrue;
Line: 4088

              tempAttributeValues1.delete;
Line: 4089

              tempAttributeValues2.delete;
Line: 4090

              tempAttributeValues3.delete;
Line: 4181

              tempAttributeValues1.delete;
Line: 4182

              tempAttributeValues2.delete;
Line: 4183

              tempAttributeValues3.delete;
Line: 4340

      select
        ame_attributes.attribute_id attribute_id,
        ame_attributes.name attribute_name,
        ame_attributes.attribute_type attribute_type,
        ame_attributes.item_class_id item_class_id,
        ame_attribute_usages.query_string,
        ame_attribute_usages.is_static
        from
          ame_attributes,
          ame_attribute_usages,
          ame_item_class_usages
        where
          ame_attributes.name not in (ame_util.workflowItemKeyAttribute, ame_util.workflowItemTypeAttribute) and
          ame_attributes.attribute_id = ame_attribute_usages.attribute_id and
          ame_attribute_usages.application_id = applicationIdIn and
          ame_item_class_usages.application_id = applicationIdIn and
          ame_attributes.item_class_id = ame_item_class_usages.item_class_id and
          (ame_attribute_usages.use_count = 0 and
           ame_attributes.attribute_id not in
            (select ame_attributes2.attribute_id
              from
                ame_attributes ame_attributes2,
                ame_mandatory_attributes
              where
                ame_attributes2.attribute_id = ame_mandatory_attributes.attribute_id and
                ame_mandatory_attributes.action_type_id = -1 and
                sysdate between
                  ame_attributes2.start_date and
                  nvl(ame_attributes2.end_date - ame_util.oneSecond, sysdate) and
                sysdate between
                  ame_mandatory_attributes.start_date and
                  nvl(ame_mandatory_attributes.end_date - ame_util.oneSecond, sysdate))) and
          sysdate between
            ame_attributes.start_date and
            nvl(ame_attributes.end_date - ame_util.oneSecond, sysdate) and
          sysdate between
            ame_attribute_usages.start_date and
            nvl(ame_attribute_usages.end_date - ame_util.oneSecond, sysdate) and
          sysdate between
            ame_item_class_usages.start_date and
            nvl(ame_item_class_usages.end_date - ame_util.oneSecond, sysdate) and
            -- Condition to check whether the attribute is used in the rule
            exists
            (
              select 1
               from ame_conditions,
                    ame_condition_usages,
                    ame_rules,
                    ame_rule_usages
              where ame_conditions.attribute_id = ame_attributes.attribute_id
                and ame_conditions.condition_id = ame_condition_usages.condition_id
                and ame_condition_usages.rule_id = ame_rules.rule_id
                and ame_rules.rule_id = ame_rule_usages.rule_id
                and ame_rule_usages.item_id = applicationIdIn
                and ((engEffectiveRuleDate between ame_rules.start_date
                        and nvl(ame_rules.end_date - (1/86400), engEffectiveRuleDate)))
                and ((engEffectiveRuleDate between ame_rule_usages.start_date
                        and nvl(ame_rule_usages.end_date - (1/86400), engEffectiveRuleDate)))
                and engEffectiveRuleDate between ame_conditions.start_date
                      and nvl(ame_conditions.end_date - (1/86400), engEffectiveRuleDate)
                and ((engEffectiveRuleDate between ame_condition_usages.start_date
                      and nvl(ame_condition_usages.end_date - (1/86400), engEffectiveRuleDate)))
              union
              select 1
                from ame_mandatory_attributes,
                     ame_actions,
                     ame_action_usages,
                     ame_rules,
                     ame_rule_usages
               where ame_mandatory_attributes.attribute_id = ame_attributes.attribute_id
                 and ame_mandatory_attributes.action_type_id =
                        ame_actions.action_type_id
                 and ame_actions.action_id = ame_action_usages.action_id
                 and ame_action_usages.rule_id = ame_rules.rule_id
                 and ame_rules.rule_id = ame_rule_usages.rule_id
                 and ame_rule_usages.item_id = applicationIdIn
                 and ((engEffectiveRuleDate between ame_rules.start_date
                 and nvl(ame_rules.end_date - (1/86400), engEffectiveRuleDate)))
                 and ((engEffectiveRuleDate between ame_rule_usages.start_date
                 and nvl(ame_rule_usages.end_date - (1/86400), engEffectiveRuleDate)))
                 and engEffectiveRuleDate between ame_mandatory_attributes.start_date
                 and nvl(ame_mandatory_attributes.end_date - (1/86400), engEffectiveRuleDate)
                 and engEffectiveRuleDate between ame_actions.start_date
                 and nvl(ame_actions.end_date - (1/86400), engEffectiveRuleDate)
                 and ((engEffectiveRuleDate between ame_action_usages.start_date
                 and nvl(ame_action_usages.end_date - (1/86400), engEffectiveRuleDate)))
            )
        /*
          The order-by conditions are all necessary.  The second is to break
          item_class_order_number ties in a determinate order.  The third is
          to display attribute names in alphabetical order on the test tab.
          Compare the itemClassUsageCursor cursor in the procedure updateTransactionState.
        */
        order by
          ame_item_class_usages.item_class_order_number,
          ame_item_class_usages.item_class_id,
          ame_attributes.name;
Line: 4438

      select
        attribute_value_1,
        attribute_value_2,
        attribute_value_3
      from ame_test_trans_att_values
      where
        application_id = engAmeApplicationId and
        transaction_id = engTransactionId and
        attribute_id = attributeIdIn
      order by item_id;
Line: 4449

      select attribute_value_1
      from ame_test_trans_att_values
      where
        application_id = engAmeApplicationId and
        transaction_id = engTransactionId and
        attribute_id = attributeIdIn
      order by item_id;
Line: 4457

      select attribute_value_1
      from ame_test_trans_att_values
      where
        application_id = engAmeApplicationId and
        transaction_id = engTransactionId and
        attribute_id = attributeIdIn and
        item_class_id = getItemClassId(ame_util.headerItemClassName) and
        item_id = engTransactionId;
Line: 4548

              tempAttributeValues1.delete;
Line: 4549

              tempAttributeValues2.delete;
Line: 4550

              tempAttributeValues3.delete;
Line: 4641

              tempAttributeValues1.delete;
Line: 4642

              tempAttributeValues2.delete;
Line: 4643

              tempAttributeValues3.delete;
Line: 4782

      select
        ame_action_type_config.action_type_id,
        ame_action_type_config.voting_regime,
        ame_action_type_config.order_number,
        ame_action_type_config.chain_ordering_mode,
        ame_action_types.name,
        ame_action_types.procedure_name,
        ame_action_type_usages.rule_type
        from
          ame_action_type_config,
          ame_action_types,
          ame_action_type_usages
        where
          ame_action_type_config.application_id = engAmeApplicationId and
          ame_action_types.action_type_id = ame_action_type_config.action_type_id and
          ame_action_type_usages.action_type_id = ame_action_types.action_type_id and
          /*
            Only action types for list-creation and exception rules have two action-type usages;
Line: 4814

      select
        decode(nvl(application_id,0),0,0,-1) application_id,
        /* modified from
           application_id to
           decode(nvl(application_id,0),0,0,-1) application_id
           for the bug 5614208 */
        variable_name,
        variable_value
        from ame_config_vars
        where
          (application_id = 0 or application_id is null or application_id = engAmeApplicationId) and
          /* Config vars can impact the approver list, so use engEffectiveRuleDate here. */
          engEffectiveRuleDate between
            start_date and
            nvl(end_date - ame_util.oneSecond, engEffectiveRuleDate)
        order by
          variable_name,
          application_id;
Line: 4914

  procedure fetchDeletedApprovers as
    cursor deletedApproversCursor(applicationIdIn in integer,
                                  transactionIdIn in varchar2) is
      select
        name,
        item_class,
        item_id,
        approver_category,
        action_type_id,
        group_or_chain_id,
        occurrence,
        effective_date,
        reason
        from ame_temp_deletions
        where
          application_id = applicationIdIn and
          transaction_id = transactionIdIn;
Line: 4942

      open deletedApproversCursor(applicationIdIn => engAmeApplicationId,
                                   transactionIdIn => engTransactionId);
Line: 4944

      fetch deletedApproversCursor bulk collect
        into
          approverNames,
          itemClasses,
          itemIds,
          approverCategories,
          actionTypeIds,
          groupOrChainIds,
          occurrences,
          engSuppressionDateList,
          engSupperssionReasonList;
Line: 4955

      close deletedApproversCursor;
Line: 4958

        engDeletedApproverList(i).name := approverNames(i);
Line: 4959

        engDeletedApproverList(i).item_class := itemClasses(i);
Line: 4960

        engDeletedApproverList(i).item_id := itemIds(i);
Line: 4961

        engDeletedApproverList(i).approver_category := approverCategories(i);
Line: 4962

        engDeletedApproverList(i).action_type_id := actionTypeIds(i);
Line: 4963

        engDeletedApproverList(i).group_or_chain_id := groupOrChainIds(i);
Line: 4964

        engDeletedApproverList(i).occurrence := occurrences(i);
Line: 4968

          if(deletedApproversCursor%isopen) then
            close deletedApproversCursor;
Line: 4972

                                    routineNameIn => 'fetchDeletedApprovers',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 4976

    end fetchDeletedApprovers;
Line: 4977

  procedure fetchInsertedApprovers as
    cursor insertedApproversCursor(applicationIdIn in integer,
                                   transactionIdIn in varchar2) is
      select
        name,
        item_class,
        item_id,
        nvl(approver_category,ame_util.approvalApproverCategory) approver_category,
        api_insertion,
        authority,
        order_type,
        parameter,
        special_forwardee,
        insertion_order,
        effective_date,
        reason,
        approval_status
        from ame_temp_insertions
        where
          application_id = applicationIdIn and
          transaction_id = transactionIdIn
          order by insertion_order;
Line: 4999

    approverApiInsertions ame_util.charList;
Line: 5008

      open insertedApproversCursor(applicationIdIn => engAmeApplicationId,
                                   transactionIdIn => engTransactionId);
Line: 5010

      fetch insertedApproversCursor bulk collect
        into
          approverNames,
          approverItemClasses,
          approverItemIds,
          approverCategories,
          approverApiInsertions,
          approverAuthorities,
          engInsertionOrderTypeList,
          engInsertionParameterList,
          engInsertionIsSpecialForwardee,
          engInsertionOrderList,
          engInsertionDateList,
          engInsertionReasonList,
          approvalStatuses;
Line: 5025

      close insertedApproversCursor;
Line: 5028

        engInsertedApproverList(i).name := approverNames(i);
Line: 5029

        engInsertedApproverList(i).item_class := approverItemClasses(i);
Line: 5030

        engInsertedApproverList(i).item_id := approverItemIds(i);
Line: 5031

        engInsertedApproverList(i).approver_category := approverCategories(i);
Line: 5032

        engInsertedApproverList(i).api_insertion := approverApiInsertions(i);
Line: 5033

        engInsertedApproverList(i).authority := approverAuthorities(i);
Line: 5034

        engInsertedApproverList(i).approval_status := approvalStatuses(i);
Line: 5036

                                                         origSystemOut => engInsertedApproverList(i).orig_system,
                                                         origSystemIdOut =>engInsertedApproverList(i).orig_system_id);
Line: 5041

          if(insertedApproversCursor%isopen) then
            close insertedApproversCursor;
Line: 5045

                                    routineNameIn => 'fetchInsertedApprovers',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 5049

    end fetchInsertedApprovers;
Line: 5052

      select
        ame_item_classes.item_class_id,
        ame_item_classes.name,
        ame_item_class_usages.item_id_query,
        ame_item_class_usages.item_class_order_number,
        ame_item_class_usages.item_class_par_mode,
        ame_item_class_usages.item_class_sublist_mode
        from
          ame_item_classes,
          ame_item_class_usages
        where
          ame_item_classes.item_class_id = ame_item_class_usages.item_class_id and
          ame_item_class_usages.application_id = applicationIdIn and
          engEffectiveRuleDate between
            ame_item_classes.start_date and
            nvl(ame_item_classes.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
          engEffectiveRuleDate between
            ame_item_class_usages.start_date and
            nvl(ame_item_class_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate)
        /*
          The order-by conditions are both critical.  The second is to break
          item_class_order_number ties in a determinate order.  Compare the
          attributeCursor cursor in the procedure fetchAttributeValues.
        */
        order by
          ame_item_class_usages.item_class_order_number,
          ame_item_class_usages.item_class_id;
Line: 5080

      select distinct item_id
      from ame_test_trans_att_values
      where
        application_id = engAmeApplicationId and
        transaction_id = engTransactionId and
        item_class_id = itemClassIdIn
      order by item_id;
Line: 5110

        itemIds.delete;
Line: 5224

      select
        fnd_application_id,
        transaction_type_id
        into
          fndApplicationIdOut,
          transactionTypeIdOut
        from ame_calling_apps
        where
          application_id = applicationIdIn and
          /* Don't use engEffectiveRuleDate here. */
          sysdate between
            start_date and
            nvl(end_date - ame_util.oneSecond, sysdate) and
          rownum < 2; /* Avoids second fetch otherwise required by ANSI standard to check for too many rows. */
Line: 5251

      select
        name,
        item_class,
        item_id,
        approver_category,
        api_insertion,
        authority,
        approval_status,
        action_type_id,
        group_or_chain_id,
        occurrence
        from ame_temp_old_approver_lists
        where
          application_id = applicationIdIn and
          transaction_id = transactionIdIn
          order by order_number;
Line: 5268

    approverApiInsertions ame_util.charList;
Line: 5287

          approverApiInsertions,
          approverAuthorities,
          approverStatuses,
          actionTypeIds,
          groupOrChainIds,
          occurrences;
Line: 5300

        engOldApproverList(i).api_insertion := approverApiInsertions(i);
Line: 5326

      select
        orig_system,
        orig_system_id,
        parameter,
        upper(parameter_name),
        query_string,
        order_number,
        decode(parameter_name,
               ame_util.approverOamGroupId, null,
               ame_approver_type_pkg.getWfRolesName(orig_system, orig_system_id)) name,
        decode(parameter_name,
               ame_util.approverOamGroupId, null,
               ame_approver_type_pkg.getApproverDisplayName2(orig_system, orig_system_id)) display_name
        from ame_approval_group_members
        where
          approval_group_id = groupIdIn
        order by order_number;
Line: 5385

        /* This is not the first time this query is being executed, so find and delete all old approvers in this group. */
        for n in 1 .. engGroupMemberGroupIds.count loop
          if( engGroupMemberGroupIds(n) = groupIdIn ) then
            -- delete all occurrences of this
             engGroupMemberGroupIds(n) := null;
Line: 5410

        engGroupMemberGroupIds.delete(outputIndex, engGroupMemberGroupIds.count);
Line: 5414

        tempGroupMembers.delete; -- for bug 4616570
Line: 5755

      select
        order_number,
        voting_regime
        from ame_approval_group_config
        where
          application_id = engAmeApplicationId and
          approval_group_id = groupIdIn and
        engEffectiveRuleDate between
          start_date and
          nvl(end_date - ame_util.oneSecond, engEffectiveRuleDate);
Line: 5843

        approversOut(i).api_insertion := engStApprovers(i).api_insertion;
Line: 5879

        approversOut(i).api_insertion := engStApprovers(i).api_insertion;
Line: 5932

    parameter ame_temp_insertions.parameter%type;
Line: 5943

      for i in 1 .. engInsertedApproverList.count loop
        if(engInsertionParameterList(i) = parameter) then
          nameOut := engInsertedApproverList(i).name;
Line: 5946

          ame_approver_type_pkg.getOrigSystemIdAndDisplayName(nameIn => engInsertedApproverList(i).name,
                                                              origSystemOut => origSystemOut,
                                                              origSystemIdOut => origSystemIdOut,
                                                              displayNameOut => displayNameOut);
Line: 5950

          sourceOut := ame_util.otherInsertion;
Line: 5951

          setDeviationReasonDate(engInsertionReasonList(i),engInsertionDateList(i));
Line: 5963

  procedure getHandlerCOAInsertion(nameIn in varchar2,
                                   itemClassIn in varchar2,
                                   itemIdIn in varchar2,
                                   actionTypeIdIn in integer,
                                   groupOrChainIdIn in integer,
                                   occurrenceIn in integer,
                                   approvalStatusIn in varchar2,
                                   nameOut out nocopy varchar2,
                                   origSystemOut out nocopy varchar2,
                                   origSystemIdOut out nocopy integer,
                                   displayNameOut out nocopy varchar2,
                                   sourceOut out nocopy varchar2) as
    parameter ame_temp_insertions.parameter%type;
Line: 5988

      for i in 1 .. engInsertedApproverList.count loop
        if(engInsertedApproverList(i).api_insertion = ame_util.apiAuthorityInsertion and
           engInsertionOrderTypeList(i) = ame_util.afterApprover and
           engInsertionParameterList(i) = parameter) then
          nameOut := engInsertedApproverList(i).name;
Line: 5993

          ame_approver_type_pkg.getOrigSystemIdAndDisplayName(nameIn => engInsertedApproverList(i).name,
                                                              origSystemOut => origSystemOut,
                                                              origSystemIdOut => origSystemIdOut,
                                                              displayNameOut => displayNameOut);
Line: 5997

          if(engInsertionIsSpecialForwardee(i) = ame_util.booleanTrue) then
            sourceOut := ame_util.specialForwardInsertion;
Line: 6000

            sourceOut := ame_util.forwardInsertion;
Line: 6002

            sourceOut := ame_util.approveAndForwardInsertion;
Line: 6004

            sourceOut := ame_util.otherInsertion;
Line: 6006

          setDeviationReasonDate(engInsertionReasonList(i),engInsertionDateList(i));
Line: 6013

                                    routineNameIn => 'getHandlerCOAInsertion',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 6017

    end getHandlerCOAInsertion;
Line: 6414

          itemIdsOut.delete;
Line: 6507

  procedure getInsertions
    (positionIn             in            number
    ,orderTypeIn            in            varchar2 default null
    ,coaInsertionsYNIn      in            varchar2 default ame_util.booleanTrue
    ,availableInsertionsOut    out nocopy ame_util.insertionsTable2
    ) as

    engStApproversCount         integer;
Line: 6515

    availableInsertionsIndex    integer; /* pre-increment */
Line: 6524

    tempInsertionDoesNotExist   boolean;
Line: 6525

    tempParameter               ame_temp_insertions.parameter%type;
Line: 6536

    availableInsertionsIndex := 0;
Line: 6545

        if (not ame_engine.insertionExists
                  (orderTypeIn   => ame_util.absoluteOrder
                  ,parameterIn   => tempParameter
                  )) then
          availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6550

          availableInsertionsOut(availableInsertionsIndex).item_class := ame_util.headerItemClassName;
Line: 6551

          availableInsertionsOut(availableInsertionsIndex).item_id := engTransactionId;
Line: 6552

          availableInsertionsOut(availableInsertionsIndex).action_type_id := null;
Line: 6553

          availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := null;
Line: 6554

          availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.absoluteOrder;
Line: 6555

          availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6556

          availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6557

          availableInsertionsOut(availableInsertionsIndex).authority := ame_util.preApprover;
Line: 6558

          availableInsertionsOut(availableInsertionsIndex).description :=
                                        ame_util.absoluteOrderDescription || positionIn || '.  ';
Line: 6563

        if (not ame_engine.insertionExists
                  (orderTypeIn   => ame_util.absoluteOrder
                  ,parameterIn   => tempParameter
                  )) then
          availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6568

          availableInsertionsOut(availableInsertionsIndex).item_class := ame_util.headerItemClassName;
Line: 6569

          availableInsertionsOut(availableInsertionsIndex).item_id := engTransactionId;
Line: 6570

          availableInsertionsOut(availableInsertionsIndex).action_type_id := null;
Line: 6571

          availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := null;
Line: 6572

          availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.absoluteOrder;
Line: 6573

          availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6574

          availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6575

          availableInsertionsOut(availableInsertionsIndex).authority := ame_util.authorityApprover;
Line: 6576

          availableInsertionsOut(availableInsertionsIndex).description :=
                                         ame_util.absoluteOrderDescription || positionIn || '.  ';
Line: 6581

        if (not ame_engine.insertionExists
                  (orderTypeIn   => ame_util.absoluteOrder
                  ,parameterIn   => tempParameter
                  )) then
          availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6586

          availableInsertionsOut(availableInsertionsIndex).item_class := ame_util.headerItemClassName;
Line: 6587

          availableInsertionsOut(availableInsertionsIndex).item_id := engTransactionId;
Line: 6588

          availableInsertionsOut(availableInsertionsIndex).action_type_id := null;
Line: 6589

          availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := null;
Line: 6590

          availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.absoluteOrder;
Line: 6591

          availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6592

          availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6593

          availableInsertionsOut(availableInsertionsIndex).authority := ame_util.postApprover;
Line: 6594

          availableInsertionsOut(availableInsertionsIndex).description :=
                                         ame_util.absoluteOrderDescription || positionIn || '.  ';
Line: 6602

          /* Attribute to the insertee the relevant properties of the approver at positionIn. */
          if (not ame_engine.insertionExists
                    (orderTypeIn   => ame_util.absoluteOrder
                    ,parameterIn   => tempParameter
                    )) then
            availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6608

            availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn).item_class;
Line: 6609

            availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn).item_id;
Line: 6610

            availableInsertionsOut(availableInsertionsIndex).action_type_id := engStApprovers(positionIn).action_type_id;
Line: 6611

            availableInsertionsOut(availableInsertionsIndex).group_or_chain_id :=
                                                                       engStApprovers(positionIn).group_or_chain_id;
Line: 6613

            availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.absoluteOrder;
Line: 6614

            availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6615

            availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6616

            availableInsertionsOut(availableInsertionsIndex).authority := engStApprovers(positionIn).authority;
Line: 6617

            availableInsertionsOut(availableInsertionsIndex).description :=
                                         ame_util.absoluteOrderDescription || positionIn || '.  ';
Line: 6625

          those of the approver at positionIn (if any), add a second available insertion, attributing
          to the insertee the relevant properties of engStApprovers(positionIn - 1).
        */
        if (positionIn = engStApproversCount + 1 or
            (positionIn > 1 and
             (engStApprovers(positionIn).group_or_chain_id <> engStApprovers(positionIn - 1).group_or_chain_id or
              engStApprovers(positionIn).action_type_id <> engStApprovers(positionIn - 1).action_type_id or
              engStApprovers(positionIn).item_id <> engStApprovers(positionIn - 1).item_id or
              engStApprovers(positionIn).item_class <> engStApprovers(positionIn - 1).item_class
             ))) then

          /* Attribute to the insertee the relevant properties of the approver at positionIn - 1. */
          if (not ame_engine.insertionExists
                    (orderTypeIn   => ame_util.absoluteOrder
                    ,parameterIn   => tempParameter
                    )) then
            availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6642

            availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn - 1).item_class;
Line: 6643

            availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn - 1).item_id;
Line: 6644

            availableInsertionsOut(availableInsertionsIndex).action_type_id :=
                                                                   engStApprovers(positionIn - 1).action_type_id;
Line: 6646

            availableInsertionsOut(availableInsertionsIndex).group_or_chain_id :=
                                                                 engStApprovers(positionIn - 1).group_or_chain_id;
Line: 6648

            availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.absoluteOrder;
Line: 6649

            availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6650

            availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6651

            availableInsertionsOut(availableInsertionsIndex).authority := engStApprovers(positionIn - 1).authority;
Line: 6652

            availableInsertionsOut(availableInsertionsIndex).description :=
                                                    ame_util.absoluteOrderDescription || positionIn || '.  ';
Line: 6690

        if (not ame_engine.insertionExists
                  (orderTypeIn   => ame_util.afterApprover
                  ,parameterIn   => tempParameter
                  )) then
          availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6695

          availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn - 1).item_class;
Line: 6696

          availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn - 1).item_id;
Line: 6697

          availableInsertionsOut(availableInsertionsIndex).action_type_id :=
                                                                engStApprovers(positionIn - 1).action_type_id;
Line: 6699

          availableInsertionsOut(availableInsertionsIndex).group_or_chain_id :=
                                                             engStApprovers(positionIn - 1).group_or_chain_id;
Line: 6701

          availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.afterApprover;
Line: 6702

          availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6703

          availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6704

          availableInsertionsOut(availableInsertionsIndex).authority := engStApprovers(positionIn - 1).authority;
Line: 6705

          availableInsertionsOut(availableInsertionsIndex).description :=
                                           ame_util.afterApproverDescription || prevApproverDescription;
Line: 6712

              engStApprovers(positionIn).api_insertion <> ame_util.apiInsertion and
              engStApprovers(positionIn).approver_category = ame_util.approvalApproverCategory and
              coaInsertionsYNIn = ame_util.booleanTrue and
              (not ame_engine.insertionExists
                   (orderTypeIn   => ame_util.afterApprover
                   ,parameterIn   => tempParameter
                   ))) then /* COA */
            availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6720

            availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn - 1).item_class;
Line: 6721

            availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn - 1).item_id;
Line: 6722

            availableInsertionsOut(availableInsertionsIndex).action_type_id :=
                                                             engStApprovers(positionIn - 1).action_type_id;
Line: 6724

            availableInsertionsOut(availableInsertionsIndex).group_or_chain_id :=
                                                                 engStApprovers(positionIn - 1).group_or_chain_id;
Line: 6726

            availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.afterApprover;
Line: 6728

            availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6729

            availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiAuthorityInsertion;
Line: 6730

            availableInsertionsOut(availableInsertionsIndex).authority := engStApprovers(positionIn - 1).authority;
Line: 6731

            availableInsertionsOut(availableInsertionsIndex).description :=
                                         ame_util.afterApproverDescription || prevApproverDescription;
Line: 6769

        if (not ame_engine.insertionExists
                  (orderTypeIn   => ame_util.beforeApprover
                  ,parameterIn   => tempParameter
                  )) then
          availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6774

          availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn).item_class;
Line: 6775

          availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn).item_id;
Line: 6776

          availableInsertionsOut(availableInsertionsIndex).action_type_id := engStApprovers(positionIn).action_type_id;
Line: 6777

          availableInsertionsOut(availableInsertionsIndex).group_or_chain_id :=
                                                                    engStApprovers(positionIn).group_or_chain_id;
Line: 6779

          availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.beforeApprover;
Line: 6780

          availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6781

          availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6782

          availableInsertionsOut(availableInsertionsIndex).authority := engStApprovers(positionIn).authority;
Line: 6783

          availableInsertionsOut(availableInsertionsIndex).description :=
                                             ame_util.beforeApproverDescription || nextApproverDescription;
Line: 6793

    if (coaInsertionsYNIn = ame_util.booleanTrue and
        (orderTypeIn is null or
        orderTypeIn = ame_util.firstAuthority)) then

      if (positionIn < engStApproversCount + 1 and
          engStApprovers(positionIn).authority = ame_util.authorityApprover and
          engStApprovers(positionIn).api_insertion <> ame_util.apiInsertion) then
        tempBoolean := true; /* tempBoolean remains true if no previous authority is found. */
Line: 6810

              engStApprovers(i).api_insertion <> ame_util.apiInsertion) then
            tempBoolean := false;
Line: 6827

          if (not ame_engine.insertionExists
                    (orderTypeIn   => ame_util.firstAuthority
                    ,parameterIn   => tempParameter
                    )) then
            availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6832

            availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn).item_class;
Line: 6833

            availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn).item_id;
Line: 6834

            availableInsertionsOut(availableInsertionsIndex).action_type_id :=
                                                                   engStApprovers(positionIn).action_type_id;
Line: 6836

            availableInsertionsOut(availableInsertionsIndex).group_or_chain_id :=
                                                                 engStApprovers(positionIn).group_or_chain_id;
Line: 6838

            availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.firstAuthority;
Line: 6839

            availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6840

            availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiAuthorityInsertion;
Line: 6841

            availableInsertionsOut(availableInsertionsIndex).authority := ame_util.authorityApprover;
Line: 6842

            availableInsertionsOut(availableInsertionsIndex).description := ame_util.firstAuthorityDescription;
Line: 6850

      Assume that in the case of an entirely empty approver list, we allow insertion of a first
      post-approver into the header item's list only.  Otherwise, we only allow insertion of a
      first post-approver into a non-empty item list.  Here is the case analysis:
          if(the approver list is empty) then
            allow a first-post-approver insertion for the header
          elsif(positionIn is after the end of the approver list) then
            if(the last approver in the list is not a post-approver) then
              allow a first-post-approver insertion for the last approver's item
            end if
          elsif(positionIn = 1) then
            if(the first approver in the list is a post-approver_ then
              allow a first-post-approver insertion for the first approver's item
            end if
          else
            if(the engStApprovers at positionIn - 1 and positionIn are for the same item) then
              if(the first approver is not a post-approver and
                 the second approver is a post-approver) then
                allow a first-post-approver insertion for the engStApprovers' item
              end if
            else
              if(the second approver is a post-approver) then
                allow a first-post-approver insertion for the second approver's item
              end if
              if(the first approver is not a post-approver) then
                allow a first-post-approver insertion for the first approver's item
              end if
            end if
          end if
    */
    if (orderTypeIn is null or
        orderTypeIn = ame_util.firstPostApprover) then

      if (engStApproversCount = 0) then
        tempParameter := ame_util.firstPostParameter ||
                         ame_util.fieldDelimiter ||
                         ame_util.headerItemClassName ||
                         ame_util.fieldDelimiter ||
                         engTransactionId;
Line: 6889

        if (not ame_engine.insertionExists
                  (orderTypeIn => ame_util.firstPostApprover
                  ,parameterIn => tempParameter
                  )) then
          availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6894

          availableInsertionsOut(availableInsertionsIndex).item_class := ame_util.headerItemClassName;
Line: 6895

          availableInsertionsOut(availableInsertionsIndex).item_id := engTransactionId;
Line: 6896

          availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 6897

          availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 6898

          availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.firstPostApprover;
Line: 6899

          availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6900

          availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6901

          availableInsertionsOut(availableInsertionsIndex).authority := ame_util.postApprover;
Line: 6902

          availableInsertionsOut(availableInsertionsIndex).description := ame_util.firstPostApproverDescription;
Line: 6911

          if (not ame_engine.insertionExists
                    (orderTypeIn   => ame_util.firstPostApprover
                    ,parameterIn   => tempParameter
                    )) then
            availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6916

            availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(engStApproversCount).item_class;
Line: 6917

            availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(engStApproversCount).item_id;
Line: 6918

            availableInsertionsOut(availableInsertionsIndex).action_type_id :=
                                                                        ame_util.nullInsertionActionTypeId;
Line: 6920

            availableInsertionsOut(availableInsertionsIndex).group_or_chain_id :=
                                                                      ame_util.nullInsertionGroupOrChainId;
Line: 6922

            availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.firstPostApprover;
Line: 6923

            availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6924

            availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6925

            availableInsertionsOut(availableInsertionsIndex).authority := ame_util.postApprover;
Line: 6926

            availableInsertionsOut(availableInsertionsIndex).description := ame_util.firstPostApproverDescription;
Line: 6936

          if (not ame_engine.insertionExists
                    (orderTypeIn   => ame_util.firstPostApprover
                    ,parameterIn   => tempParameter
                    )) then
            availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6941

            availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(1).item_class;
Line: 6942

            availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(1).item_id;
Line: 6943

            availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 6944

            availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 6945

            availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.firstPostApprover;
Line: 6946

            availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6947

            availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6948

            availableInsertionsOut(availableInsertionsIndex).authority := ame_util.postApprover;
Line: 6949

            availableInsertionsOut(availableInsertionsIndex).description := ame_util.firstPostApproverDescription;
Line: 6962

            if (not ame_engine.insertionExists
                      (orderTypeIn => ame_util.firstPostApprover
                      ,parameterIn => tempParameter
                      )) then
              availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6967

              availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn).item_class;
Line: 6968

              availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn).item_id;
Line: 6969

              availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 6970

              availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 6971

              availableInsertionsOut(availableInsertionsIndex).group_or_chain_id :=
                                                            engStApprovers(positionIn).group_or_chain_id;
Line: 6973

              availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.firstPostApprover;
Line: 6974

              availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6975

              availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6976

              availableInsertionsOut(availableInsertionsIndex).authority := ame_util.postApprover;
Line: 6977

              availableInsertionsOut(availableInsertionsIndex).description := ame_util.firstPostApproverDescription;
Line: 6987

            if (not ame_engine.insertionExists
                      (orderTypeIn   => ame_util.firstPostApprover
                      ,parameterIn   => tempParameter
                      )) then
              availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 6992

              availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn).item_class;
Line: 6993

              availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn).item_id;
Line: 6994

              availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 6995

              availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 6996

              availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.firstPostApprover;
Line: 6997

              availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 6998

              availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 6999

              availableInsertionsOut(availableInsertionsIndex).authority := ame_util.postApprover;
Line: 7000

              availableInsertionsOut(availableInsertionsIndex).description := ame_util.firstPostApproverDescription;
Line: 7010

            if (not ame_engine.insertionExists
                      (orderTypeIn   => ame_util.firstPostApprover
                      ,parameterIn   => tempParameter
                      )) then
              availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 7015

              availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn - 1).item_class;
Line: 7016

              availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn - 1).item_id;
Line: 7017

              availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 7018

              availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 7019

              availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.firstPostApprover;
Line: 7020

              availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 7021

              availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 7022

              availableInsertionsOut(availableInsertionsIndex).authority := ame_util.postApprover;
Line: 7023

              availableInsertionsOut(availableInsertionsIndex).description := ame_util.firstPostApproverDescription;
Line: 7032

      Assume that in the case of an entirely empty approver list, we allow insertion of a first
      pre-approver into the header item's list only.  Otherwise, we only allow insertion of a
      first pre-approver into a non-empty item list.  Here is the case analysis:
        if(the approver list is empty) then
          allow a first-pre-approver insertion for the header item
        elsif(positionIn = 1) then
          allow a first-pre-approver insertion for the first approver's item
        elsif(positionIn < engStApproversCount + 1) then
          if(the engStApprovers at positionIn - 1 and positionIn are for different items) then
            allow a first-pre-approver insertion for the second approver's item
          end if
        end if
    */
    if (orderTypeIn is null or
        orderTypeIn = ame_util.firstPreApprover) then

      if (engStApproversCount = 0) then
        tempParameter := ame_util.firstPreApprover ||
                         ame_util.fieldDelimiter ||
                         ame_util.headerItemClassName ||
                         ame_util.fieldDelimiter ||
                         engTransactionId;
Line: 7054

        if (not ame_engine.insertionExists
                  (orderTypeIn => ame_util.firstPreApprover
                  ,parameterIn => tempParameter
                  )) then
          availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 7059

          availableInsertionsOut(availableInsertionsIndex).item_class := ame_util.headerItemClassName;
Line: 7060

          availableInsertionsOut(availableInsertionsIndex).item_id := engTransactionId;
Line: 7061

          availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 7062

          availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 7063

          availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.firstPreApprover;
Line: 7064

          availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 7065

          availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 7066

          availableInsertionsOut(availableInsertionsIndex).authority := ame_util.preApprover;
Line: 7067

          availableInsertionsOut(availableInsertionsIndex).description := ame_util.firstPreApproverDescription;
Line: 7075

        if (not ame_engine.insertionExists
                  (orderTypeIn   => ame_util.firstPreApprover
                  ,parameterIn   => tempParameter
                  )) then
          availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 7080

          availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(1).item_class;
Line: 7081

          availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(1).item_id;
Line: 7082

          availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 7083

          availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 7084

          availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.firstPreApprover;
Line: 7085

          availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 7086

          availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 7087

          availableInsertionsOut(availableInsertionsIndex).authority := ame_util.preApprover;
Line: 7088

          availableInsertionsOut(availableInsertionsIndex).description := ame_util.firstPreApproverDescription;
Line: 7098

          if (not ame_engine.insertionExists
                    (orderTypeIn   => ame_util.firstPreApprover
                    ,parameterIn   => tempParameter
                    )) then
            availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 7103

            availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn).item_class;
Line: 7104

            availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn).item_id;
Line: 7105

            availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 7106

            availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 7107

            availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.firstPreApprover;
Line: 7108

            availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 7109

            availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 7110

            availableInsertionsOut(availableInsertionsIndex).authority := ame_util.preApprover;
Line: 7111

            availableInsertionsOut(availableInsertionsIndex).description := ame_util.firstPreApproverDescription;
Line: 7119

      Assume that in the case of an entirely empty approver list, we allow insertion of a last
      post-approver into the header item's list only.  Otherwise, we only allow insertion of a
      last post-approver into a non-empty item list.  Here is the case analysis:
        if(the approver list is empty) then
          allow last-post-approver insertion for the header item
        elsif(positionIn = engStApproversCount + 1) then
          allow last-post-approver insertion for the last approver's item
        elsif(positionIn > 1) then
          if(the engStApprovers at positionIn - 1 and positionIn are for different items) then
            allow last-post-approver insertion for the former approver's item
          end if
        end if
    */
    if (orderTypeIn is null or
        orderTypeIn = ame_util.lastPostApprover) then
      if (engStApproversCount = 0) then
        tempParameter := ame_util.lastPostApprover ||
                         ame_util.fieldDelimiter ||
                         ame_util.headerItemClassName ||
                         ame_util.fieldDelimiter ||
                         engTransactionId;
Line: 7140

        if (not ame_engine.insertionExists
                  (orderTypeIn   => ame_util.lastPostApprover
                  ,parameterIn   => tempParameter
                  )) then
          availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 7145

          availableInsertionsOut(availableInsertionsIndex).item_class := ame_util.headerItemClassName;
Line: 7146

          availableInsertionsOut(availableInsertionsIndex).item_id := engTransactionId;
Line: 7147

          availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 7148

          availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 7149

          availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.lastPostApprover;
Line: 7150

          availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 7151

          availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 7152

          availableInsertionsOut(availableInsertionsIndex).authority := ame_util.postApprover;
Line: 7153

          availableInsertionsOut(availableInsertionsIndex).description := ame_util.lastPostApproverDescription;
Line: 7161

        if (not ame_engine.insertionExists
                  (orderTypeIn => ame_util.lastPostApprover
                  ,parameterIn => tempParameter
                  )) then
          availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 7166

          availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(engStApproversCount).item_class;
Line: 7167

          availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(engStApproversCount).item_id;
Line: 7168

          availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 7169

          availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 7170

          availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.lastPostApprover;
Line: 7171

          availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 7172

          availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 7173

          availableInsertionsOut(availableInsertionsIndex).authority := ame_util.postApprover;
Line: 7174

          availableInsertionsOut(availableInsertionsIndex).description := ame_util.lastPostApproverDescription;
Line: 7184

          if (not ame_engine.insertionExists
                    (orderTypeIn   => ame_util.lastPostApprover
                    ,parameterIn   => tempParameter
                    )) then
            availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 7189

            availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn - 1).item_class;
Line: 7190

            availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn - 1).item_id;
Line: 7191

            availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 7192

            availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 7193

            availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.lastPostApprover;
Line: 7194

            availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 7195

            availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 7196

            availableInsertionsOut(availableInsertionsIndex).authority := ame_util.postApprover;
Line: 7197

            availableInsertionsOut(availableInsertionsIndex).description := ame_util.lastPostApproverDescription;
Line: 7205

      Assume that in the case of an entirely empty approver list, we allow insertion of a last
      pre-approver into the header item's list only.  Otherwise, we only allow insertion of a
      last pre-approver into a non-empty item list.  Here is the case analysis:
        if(the approver list is empty) then
          allow last-pre-approver insertion for the header item
        elsif(positionIn = 1) then
          if(the approver at position 1 is not a pre-approver) then
            allow last-pre-approver insertion for the item of the first approver
          end if
        elsif(positionIn <= engStApproversCount) then
          if(the engStApprovers at positionIn - 1 and positionIn are for the same item) then
            if(the approver at positionIn - 1 is a pre-approver and
               the approver at positionIn is not a pre-approver) then
              allow last-pre-approver insertion for the engStApprovers' item
            end if
          else
            if(the approver at positionIn is not a pre-approver) then
              allow last-pre-approver insertion for the item of the approver at positionIn
            end if
          end if
        end if
    */
    if (orderTypeIn is null or
        orderTypeIn = ame_util.lastPreApprover) then
      if (engStApproversCount = 0) then
        tempParameter := ame_util.lastPreApprover ||
                         ame_util.fieldDelimiter ||
                         ame_util.headerItemClassName ||
                         ame_util.fieldDelimiter ||
                         engTransactionId;
Line: 7235

        if (not ame_engine.insertionExists
                  (orderTypeIn => ame_util.lastPreApprover
                  ,parameterIn => tempParameter)) then
          availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 7239

          availableInsertionsOut(availableInsertionsIndex).item_class := ame_util.headerItemClassName;
Line: 7240

          availableInsertionsOut(availableInsertionsIndex).item_id := engTransactionId;
Line: 7241

          availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 7242

          availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 7243

          availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.lastPreApprover;
Line: 7244

          availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 7245

          availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 7246

          availableInsertionsOut(availableInsertionsIndex).authority := ame_util.preApprover;
Line: 7247

          availableInsertionsOut(availableInsertionsIndex).description := ame_util.lastPreApproverDescription;
Line: 7256

          if (not ame_engine.insertionExists
                    (orderTypeIn   => ame_util.lastPreApprover
                    ,parameterIn   => tempParameter
                    )) then
            availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 7261

            availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(1).item_class;
Line: 7262

            availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(1).item_id;
Line: 7263

            availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 7264

            availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 7265

            availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.lastPreApprover;
Line: 7266

            availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 7267

            availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 7268

            availableInsertionsOut(availableInsertionsIndex).authority := ame_util.preApprover;
Line: 7269

            availableInsertionsOut(availableInsertionsIndex).description := ame_util.lastPreApproverDescription;
Line: 7282

            if (not ame_engine.insertionExists
                      (orderTypeIn  => ame_util.lastPreApprover
                      ,parameterIn  => tempParameter
                      )) then
              availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 7287

              availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn).item_class;
Line: 7288

              availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn).item_id;
Line: 7289

              availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 7290

              availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 7291

              availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.lastPreApprover;
Line: 7292

              availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 7293

              availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 7294

              availableInsertionsOut(availableInsertionsIndex).authority := ame_util.preApprover;
Line: 7295

              availableInsertionsOut(availableInsertionsIndex).description := ame_util.lastPreApproverDescription;
Line: 7305

            if (not ame_engine.insertionExists
                      (orderTypeIn   => ame_util.lastPreApprover
                      ,parameterIn   => tempParameter
                      )) then
              availableInsertionsIndex := availableInsertionsIndex + 1;
Line: 7310

              availableInsertionsOut(availableInsertionsIndex).item_class := engStApprovers(positionIn).item_class;
Line: 7311

              availableInsertionsOut(availableInsertionsIndex).item_id := engStApprovers(positionIn).item_id;
Line: 7312

              availableInsertionsOut(availableInsertionsIndex).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 7313

              availableInsertionsOut(availableInsertionsIndex).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 7314

              availableInsertionsOut(availableInsertionsIndex).order_type := ame_util.lastPreApprover;
Line: 7315

              availableInsertionsOut(availableInsertionsIndex).parameter := tempParameter;
Line: 7316

              availableInsertionsOut(availableInsertionsIndex).api_insertion := ame_util.apiInsertion;
Line: 7317

              availableInsertionsOut(availableInsertionsIndex).authority := ame_util.preApprover;
Line: 7318

              availableInsertionsOut(availableInsertionsIndex).description := ame_util.lastPreApproverDescription;
Line: 7330

        ,messageNameIn            => 'AME_400418_INVALID_INSERTION'
        );
Line: 7334

        ,routineNameIn     => 'getInsertions'
        ,exceptionNumberIn => errorCode
        ,exceptionStringIn => errorMessage
        );
Line: 7343

        ,routineNameIn     => 'getInsertions'
        ,exceptionNumberIn => sqlcode
        ,exceptionStringIn => sqlerrm
        );
Line: 7348

  end getInsertions;
Line: 7361

        /* Select the values, as they were not cached. */
        select
          ame_conditions.parameter_one,
          ame_conditions.parameter_two
          into
            parameterOne,
            parameterTwo
          from
            ame_conditions,
            ame_condition_usages
          where
            ame_condition_usages.rule_id = ruleIdIn and
            ame_condition_usages.condition_id = ame_conditions.condition_id and
            ame_conditions.condition_type = ame_util.listModConditionType and
            engEffectiveRuleDate between
              ame_conditions.start_date and
              nvl(ame_conditions.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
            engEffectiveRuleDate between
              ame_condition_usages.start_date and
              nvl(ame_condition_usages.end_date - ame_util.oneSecond, engEffectiveRuleDate) and
            rownum < 2; /* Avoids second fetch otherwise required by ANSI standard to check for too many rows. */
Line: 7481

      ame_engine.updateTransactionState(isTestTransactionIn  => false
                                       ,isLocalTransactionIn => false
                                       ,fetchConfigVarsIn    => true
                                       ,fetchOldApproversIn  => true
                                       ,fetchInsertionsIn    => true
                                       ,fetchDeletionsIn     => true
                                       ,fetchAttributeValuesIn      => true
                                       ,fetchInactiveAttValuesIn    => false
                                       ,processProductionActionsIn  => tempProcessProductionActions
                                       ,processProductionRulesIn    => tempProcessProductionRules
                                       ,updateCurrentApproverListIn => true
                                       ,updateOldApproverListIn     => true
                                       ,processPrioritiesIn   => true
                                       ,prepareItemDataIn     => tempPrepareItemData
                                       ,prepareRuleIdsIn      => false
                                       ,prepareRuleDescsIn    => false
                                       ,prepareApproverTreeIn => true
                                       ,transactionIdIn       => transactionIdIn
                                       ,ameApplicationIdIn    => null
                                       ,fndApplicationIdIn    => applicationIdIn
                                       ,transactionTypeIdIn   => transactionTypeIn);
Line: 7557

                setInsertedApprovalStatus(currentApproverIndexIn => currentTreeNode.approver_index
                                           ,approvalStatusIn => ame_util.notifiedStatus );
Line: 7574

                  update ame_temp_old_approver_lists
                     set approval_status = ame_util.notifiedByRepeatedStatus
                   where application_id = ameApplicationId
                     and transaction_id = transactionIdIn
                     and name           = engStApprovers(engStRepeatedAppIndexes(x)).name --nextApproversOut(i).name
                     and item_class        = engStApprovers(engStRepeatedAppIndexes(x)).item_class
                     and item_id           = engStApprovers(engStRepeatedAppIndexes(x)).item_id
                     and action_type_id    = engStApprovers(engStRepeatedAppIndexes(x)).action_type_id
                     and group_or_chain_id = engStApprovers(engStRepeatedAppIndexes(x)).group_or_chain_id
                     and occurrence        = engStApprovers(engStRepeatedAppIndexes(x)).occurrence
                     and (approval_status is null or approval_status = ame_util.repeatedStatus);
Line: 7586

                     setInsertedApprovalStatus(currentApproverIndexIn => engStRepeatedAppIndexes(x)
                                    ,approvalStatusIn => ame_util.notifiedByRepeatedStatus);
Line: 7625

                  setInsertedApprovalStatus(currentApproverIndexIn => engStApproversTree(currentTreeNode.sibling_index).approver_index
                                           ,approvalStatusIn =>ame_util.notifiedStatus );
Line: 7643

                    update ame_temp_old_approver_lists
                       set approval_status = ame_util.notifiedByRepeatedStatus
                     where application_id = ameApplicationId
                       and transaction_id = transactionIdIn
                       and name           = engStApprovers(engStRepeatedAppIndexes(x)).name --nextApproversOut(i).name
                       and item_class        = engStApprovers(engStRepeatedAppIndexes(x)).item_class
                       and item_id           = engStApprovers(engStRepeatedAppIndexes(x)).item_id
                       and action_type_id    = engStApprovers(engStRepeatedAppIndexes(x)).action_type_id
                       and group_or_chain_id = engStApprovers(engStRepeatedAppIndexes(x)).group_or_chain_id
                       and occurrence        = engStApprovers(engStRepeatedAppIndexes(x)).occurrence
                       and (approval_status is null or approval_status = ame_util.repeatedStatus);
Line: 7655

                       setInsertedApprovalStatus(currentApproverIndexIn => engStRepeatedAppIndexes(x)
                                                ,approvalStatusIn => ame_util.notifiedByRepeatedStatus);
Line: 7784

            update ame_temp_old_approver_lists
               set approval_status = ame_util.notifiedStatus
             where item_class = nextApproversOut(i).item_class
               and item_id = nextApproversOut(i).item_id
               and name = nextApproversOut(i).name
               and action_type_id = nextApproversOut(i).action_type_id
               and group_or_chain_id = nextApproversOut(i).group_or_chain_id
               and occurrence = nextApproversOut(i).occurrence
               and transaction_id = transactionIdIn
               and application_id = ameApplicationId;
Line: 7794

           /* Insert into Approval Notification History Table */
          insertIntoTransApprovalHistory
            (transactionIdIn         => transactionIdIn
            ,applicationIdIn         => ameApplicationId
            ,orderNumberIn           => nextApproversOut(i).approver_order_number
            ,nameIn                  => nextApproversOut(i).name
            ,appCategoryIn           => nextApproversOut(i).approver_category
            ,itemClassIn             => nextApproversOut(i).item_class
            ,itemIdIn                => nextApproversOut(i).item_id
            ,actionTypeIdIn          => nextApproversOut(i).action_type_id
            ,authorityIn             => nextApproversOut(i).authority
            ,statusIn                => ame_util.notifiedStatus
            ,grpOrChainIdIn          => nextApproversOut(i).group_or_chain_id
            ,occurrenceIn            => nextApproversOut(i).occurrence
            ,apiInsertionIn          => nextApproversOut(i).api_insertion
            ,memberOrderNumberIn     => nextApproversOut(i).member_order_number
            ,notificationIdIn        => null
            ,userCommentsIn          => null
            ,dateClearedIn           => null
            ,historyTypeIn           => 'APPROVERPRESENT');
Line: 7843

        nextApproversOut.delete;
Line: 7932

            tempRuleIdList.delete;
Line: 7964

        itemIndexesOut.delete;
Line: 7965

        itemItemClassesOut.delete;
Line: 7966

        itemIdsOut.delete;
Line: 7967

        itemSourcesOut.delete;
Line: 8005

        tempRuleIdList.delete;
Line: 8051

          tempRuleIdList.delete;
Line: 8091

        prodIndexesOut.delete;
Line: 8092

        productionNamesOut.delete;
Line: 8093

        productionValuesOut.delete;
Line: 8115

        tempRuleIdList.delete;
Line: 8138

          tempRuleIdList.delete;
Line: 8181

        engStRuleDescriptions.delete;
Line: 8182

        engStRuleIds.delete;
Line: 8183

        engStRuleIndexes.delete;
Line: 8464

        select count(*)
          into tempCount
          from ame_temp_transactions
          where
            application_id = ameApplicationIdIn and
            transaction_id = transactionIdIn and
            rownum < 2; /* Avoids second fetch otherwise required by ANSI standard to check for too many rows. */
Line: 8472

          insert into ame_temp_transactions(
            application_id,
            transaction_id,
            row_timestamp) values(
              ameApplicationIdIn,
              transactionIdIn,
              sysdate); /* Don't use engEffectiveRuleDate here. */
Line: 8479

          updateTransactionState(isTestTransactionIn => false,
                                 isLocalTransactionIn => true,
                                 fetchConfigVarsIn => true,
                                 fetchOldApproversIn => true,
                                 fetchInsertionsIn => true,
                                 fetchDeletionsIn => true,
                                 fetchAttributeValuesIn => true,
                                 fetchInactiveAttValuesIn => false,
                                 processProductionActionsIn => false,
                                 processProductionRulesIn => false,
                                 updateCurrentApproverListIn => true,
                                 updateOldApproverListIn => true,
                                 processPrioritiesIn => true,
                                 prepareItemDataIn => true,
                                 prepareRuleIdsIn => true,
                                 prepareRuleDescsIn => false,
                                 prepareApproverTreeIn => true,
                                 transactionIdIn => transactionIdIn,
                                 ameApplicationIdIn => ameApplicationIdIn);
Line: 8504

                 fetchInsertionsIn => approverListStageIn > 1,
                 fetchDeletionsIn => approverListStageIn > 2,
                 fetchAttributeValuesIn => true,
                 fetchInactiveAttValuesIn => false,
                 processProductionActionsIn => true,
                 processProductionRulesIn => true,
                 updateCurrentApproverListIn => true,
                 updateOldApproverListIn => true,
                 processPrioritiesIn => true,
                 prepareItemDataIn => true,
                 prepareRuleIdsIn => true,
                 prepareRuleDescsIn => false,
                 prepareApproverTreeIn => true,
                 transactionIdIn => transactionIdIn,
                 ameApplicationIdIn => ameApplicationIdIn);
Line: 8524

        processAdHocInsertions;
Line: 8626

                                   fetchInsertionsIn in boolean default true,
                                   fetchDeletionsIn in boolean default true,
                                   fetchAttributeValuesIn in boolean default true,
                                   fetchInactiveAttValuesIn in boolean default false) as
    begin
      setContext(isTestTransactionIn => false,
                 isLocalTransactionIn => true,
                 fetchConfigVarsIn => true,
                 fetchOldApproversIn => true,
                 fetchInsertionsIn => true,
                 fetchDeletionsIn => true,
                 fetchAttributeValuesIn => true,
                 fetchInactiveAttValuesIn => false,
                 processProductionActionsIn => false,
                 processProductionRulesIn => false,
                 updateCurrentApproverListIn => true,
                 updateOldApproverListIn => true,
                 processPrioritiesIn => true,
                 prepareItemDataIn => false,
                 prepareRuleIdsIn => false,
                 prepareRuleDescsIn => false,
                 prepareApproverTreeIn => false,
                 transactionIdIn => transactionIdIn,
                 ameApplicationIdIn => ameApplicationIdIn,
                 fndApplicationIdIn => null,
                 transactionTypeIdIn => transactionTypeIdIn);
Line: 8660

  procedure updateDeviationList( sourceIndexIn in number
                              ,targetIndexIn in number) as
  begin
   if engDeviationResultList.exists(sourceIndexIn) then
     engDeviationResultList(targetIndexIn) := engDeviationResultList(sourceIndexIn);
Line: 8665

     engDeviationResultList.delete(sourceIndexIn);
Line: 8672

                                routineNameIn => 'updateDeviationList',
                                exceptionNumberIn => sqlcode,
                                exceptionStringIn => sqlerrm);
Line: 8675

  end updateDeviationList;
Line: 8676

  procedure insertApprover(indexIn in integer,
                           approverIn in ame_util.approverRecord2,
                           adjustMemberOrderNumbersIn in boolean default false,
                           approverLocationIn in boolean default ame_util.lastAmongEquals,
                           inserteeIndexIn in number default null,
                           currentInsIndex in integer default null) as
    engStApproversCount integer;
Line: 8727

       If the status is not available in ame_temp_insertions get it from
       ame_temp_old_approver_lists
      */
      if engStApprovers(indexIn).approval_status is null then
        engStApprovers(indexIn).approval_status :=  getHandlerApprovalStatus(approverIn => engStApprovers(indexIn));
Line: 8778

                select voting_regime
                  into tempVotingRegime
                  from ame_approval_group_config
                 where approval_group_id = engStApprovers(previousIndex).group_or_chain_id
                   and application_id = engAmeApplicationId
                   and sysdate between start_date and nvl(end_Date - (1/86400), sysdate);
Line: 8813

          if inserteeIndexIn is not null then
            engTempReason := engInsertionReasonList(inserteeIndexIn);
Line: 8815

            engTempDate := engInsertionDateList(inserteeIndexIn);
Line: 8826

        /* is true update the member order number in the tree                       */
        /* Add the approver to tree                                                 */
          if adjustMemberOrderNumbersIn then
            approverTreeIndex := engStApproversTree.first;
Line: 8847

          if inserteeIndexIn is not null then
            engTempReason := engInsertionReasonList(inserteeIndexIn);
Line: 8849

            engTempDate := engInsertionDateList(inserteeIndexIn);
Line: 8866

                                    routineNameIn => 'insertApprover',
                                    exceptionNumberIn => errorCode,
                                    exceptionStringIn => errorMessage);
Line: 8873

                                    routineNameIn => 'insertApprover',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 8877

    end insertApprover;
Line: 8878

  procedure insertApprovers(firstIndexIn in integer,
                            approversIn in ame_util.approversTable2) as
    approversInCount integer;
Line: 8914

      /* Insert the new approvers to the tree */
      if engPrepareApproverTree then
        /* Approvers Tree is sparse */
        loopIndex := engStApproversTree.last;
Line: 8949

                                    routineNameIn => 'insertApprovers',
                                    exceptionNumberIn => errorCode,
                                    exceptionStringIn => errorMessage);
Line: 8956

                                    routineNameIn => 'insertApprovers',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 8960

    end insertApprovers;
Line: 8961

  procedure insertIntoTransApprovalHistory
              (transactionIdIn  ame_trans_approval_history.transaction_id%type
              ,applicationIdIn  ame_trans_approval_history.application_id%type
              ,orderNumberIn    ame_trans_approval_history.order_number%type
              ,nameIn           ame_trans_approval_history.name%type
              ,appCategoryIn    ame_trans_approval_history.approver_category%type
              ,itemClassIn      ame_trans_approval_history.item_class%type
              ,itemIdIn         ame_trans_approval_history.item_id%type
              ,actionTypeIdIn   ame_trans_approval_history.action_type_id%type
              ,authorityIn      ame_trans_approval_history.authority%type
              ,statusIn         ame_trans_approval_history.status%type
              ,grpOrChainIdIn   ame_trans_approval_history.group_or_chain_id%type
              ,occurrenceIn     ame_trans_approval_history.occurrence%type
              ,apiInsertionIn   ame_trans_approval_history.api_insertion%type
              ,memberorderNumberIn ame_trans_approval_history.member_order_number%type
              ,notificationIdIn ame_trans_approval_history.notification_id%type
              ,userCommentsIn   ame_trans_approval_history.user_comments%type
              ,dateClearedIn    ame_trans_approval_history.date_cleared%type
              ,historyTypeIn    varchar2) as
    tempTransHistoryId ame_trans_approval_history.trans_history_id%type;
Line: 8988

    tempApiInsertion   ame_trans_approval_history.api_insertion%type;
Line: 9005

            select ame_trans_approval_history_s.nextval
              into tempTransHistoryId
              from dual;
Line: 9008

            insert into AME_TRANS_APPROVAL_HISTORY
                (TRANS_HISTORY_ID
                ,TRANSACTION_ID
                ,APPLICATION_ID
                ,ROW_TIMESTAMP
                ,ORDER_NUMBER
                ,NAME
                ,APPROVER_CATEGORY
                ,ITEM_CLASS
                ,ITEM_ID
                ,ACTION_TYPE_ID
                ,AUTHORITY
                ,STATUS
                ,GROUP_OR_CHAIN_ID
                ,OCCURRENCE
                ,API_INSERTION
                ,MEMBER_ORDER_NUMBER
                ,NOTIFICATION_ID
                ,USER_COMMENTS
                ,DATE_CLEARED
                )select tempTransHistoryId
                       ,transactionIdIn
                       ,applicationIdIn
                       ,sysdate
                       ,approvers(i).approver_order_number
                       ,approvers(i).name
                       ,approvers(i).approver_category
                       ,approvers(i).item_class
                       ,approvers(i).item_id
                       ,approvers(i).action_type_id
                       ,approvers(i).authority
                       ,ame_util.beatByFirstResponderStatus
                       ,approvers(i).group_or_chain_id
                       ,approvers(i).occurrence
                       ,approvers(i).api_insertion
                       ,approvers(i).member_order_number
                       ,notificationIdIn
                       ,null
                       ,null
                   from dual;
Line: 9052

      select ame_trans_approval_history_s.nextval
        into tempTransHistoryId
        from dual;
Line: 9056

        insert into AME_TRANS_APPROVAL_HISTORY
                (TRANS_HISTORY_ID
                ,TRANSACTION_ID
                ,APPLICATION_ID
                ,ROW_TIMESTAMP
                ,ORDER_NUMBER
                ,NAME
                ,APPROVER_CATEGORY
                ,ITEM_CLASS
                ,ITEM_ID
                ,ACTION_TYPE_ID
                ,AUTHORITY
                ,STATUS
                ,GROUP_OR_CHAIN_ID
                ,OCCURRENCE
                ,API_INSERTION
                ,MEMBER_ORDER_NUMBER
                ,NOTIFICATION_ID
                ,USER_COMMENTS
                ,DATE_CLEARED
                )values
                (tempTransHistoryId
                ,transactionIdIn
                ,applicationIdIn
                ,sysdate
                ,orderNumberIn
                ,nameIn
                ,appCategoryIn
                ,itemClassIn
                ,itemIdIn
                ,actionTypeIdIn
                ,authorityIn
                ,statusIn
                ,grpOrChainIdIn
                ,occurrenceIn
                ,apiInsertionIn
                ,memberorderNumberIn
                ,notificationIdIn
                ,userCommentsIn
                ,dateClearedIn);
Line: 9098

          select atah.item_class item_class
                ,atah.item_id item_id
                ,atah.order_number order_number
                ,atah.authority authority
                ,atah.action_type_id action_type_id
                ,atah.group_or_chain_id group_or_chain_id
                ,atah.occurrence occurrence
                ,atah.api_insertion api_insertion
                ,atah.member_order_number member_order_number
            into tempItemClass
                ,tempItemId
                ,tempOrderNumber
                ,tempAuthority
                ,tempActionTypeId
                ,tempGroupOrChainId
                ,tempOccurrence
                ,tempApiInsertion
                ,tempMemberOrderNumber
            from ame_trans_approval_history atah
                ,fnd_lookups lookup
                ,fnd_lookups lookup2
                ,ame_approval_groups apg
           where atah.date_cleared is null
             and atah.transaction_id = transactionIdIn
             and atah.application_id = applicationIdIn
             and atah.name = tempName
             and atah.trans_history_id =
                   (select max(b.trans_history_id)
                      from ame_trans_approval_history b
                     where atah.transaction_id = b.transaction_id
                       and atah.application_id = b.application_id
                       and atah.name = b.name
                       and atah.approver_category = b.approver_category
                       and atah.item_class = b.item_class
                       and atah.item_id = b.item_id
                       and atah.action_type_id = b.action_type_id
                       and atah.authority = b.authority
                       and atah.group_or_chain_id = b.group_or_chain_id
                       and atah.occurrence = b.occurrence
                       and b.date_cleared is null )
             and lookup.lookup_type = 'AME_SUBLIST_TYPES'
             and lookup.lookup_code = atah.authority
             and lookup2.lookup_type = 'AME_APPROVAL_STATUS'
             and lookup2.lookup_code = atah.status
             and apg.approval_group_id(+) = atah.group_or_chain_id
             and sysdate between nvl(apg.start_date,sysdate) and nvl(apg.end_date,sysdate);
Line: 9153

            tempApiInsertion   := null;
Line: 9177

        if apiInsertionIn is not null then
          tempApiInsertion := apiInsertionIn;
Line: 9183

        insert into AME_TRANS_APPROVAL_HISTORY
                (TRANS_HISTORY_ID
                ,TRANSACTION_ID
                ,APPLICATION_ID
                ,ROW_TIMESTAMP
                ,ORDER_NUMBER
                ,NAME
                ,APPROVER_CATEGORY
                ,ITEM_CLASS
                ,ITEM_ID
                ,ACTION_TYPE_ID
                ,AUTHORITY
                ,STATUS
                ,GROUP_OR_CHAIN_ID
                ,OCCURRENCE
                ,API_INSERTION
                ,MEMBER_ORDER_NUMBER
                ,NOTIFICATION_ID
                ,USER_COMMENTS
                ,DATE_CLEARED
               ) values
               (tempTransHistoryId
               ,transactionIdIn
               ,applicationIdIn
               ,sysdate
               ,tempOrderNumber
               ,nameIn
               ,appCategoryIn
               ,tempItemClass
               ,tempItemId
               ,tempActionTypeId
               ,tempAuthority
               ,statusIn
               ,tempGroupOrChainId
               ,tempOccurrence
               ,tempApiInsertion
               ,tempMemberOrderNumber
               ,notificationIdIn
               ,userCommentsIn
               ,dateClearedIn
               );
Line: 9228

                                    routineNameIn => 'insertIntoTransApprovalHistory',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 9232

    end insertIntoTransApprovalHistory;
Line: 9238

      select 'Y'
        from ame_temp_trans_locks
       where fnd_application_id = fndApplicationIdIn
         and transaction_id = transactionIdIn
         and transaction_type_id = transactionTypeIdIn;
Line: 9245

        The ame_temp_trans_locks_pk unique index will prevent the following insert from occurring
        if another row has already been inserted into ame_temp_trans_locks with the same
        fnd_application_id, transaction_type_id, and transaction_id values (even though the other
        insert is not committed).
      */
      tempTransIsLocked := null;
Line: 9260

      insert into ame_temp_trans_locks(fnd_application_id,
                                       transaction_type_id,
                                       transaction_id,
                                       row_timestamp) values(
                                       fndApplicationIdIn,
                                       transactionTypeIdIn,
                                       transactionIdIn,
                                       sysdate);
Line: 9282

      select count(*)
        into tempCount
        from ame_temp_transactions
        where
          application_id = engAmeApplicationId and
          transaction_id = engTransactionId and
          rownum < 2; /* Avoids second fetch otherwise required by ANSI standard to check for too many rows. */
Line: 9290

        select ame_temp_transactions_s.nextval into tempTransSeqId from dual;
Line: 9291

        insert into ame_temp_transactions(
          application_id,
          transaction_id,
          row_timestamp,
          temp_transactions_id
          ) values(
            engAmeApplicationId,
            engTransactionId,
            sysdate,
            tempTransSeqId); /* Don't use engEffectiveRuleDate here. */
Line: 9454

        /* Update the temp variables when the item changes. */
        if(engStApprovers(i).item_id <> tempItemId or
           engStApprovers(i).item_class <> tempItemClass) then
          tempItemId := engStApprovers(i).item_id;
Line: 9471

        /* Update the process-complete engSt variables as appropriate. */
        -- check for pending/yet to be notified approvers
        if(engStItemAppProcessCompleteYN(tempItemIndex) <> ame_util2.completeFullyRejected and
           ((engStApprovers(i).approver_category = ame_util.approvalApproverCategory and
             (engStApprovers(i).approval_status is null or
              engStApprovers(i).approval_status in (ame_util.nullStatus
                                                   ,ame_util.notifiedStatus
                                                   ,ame_util.repeatedStatus
                                                   ,ame_util.notifiedByRepeatedStatus))) or
            (engStApprovers(i).approver_category = ame_util.fyiApproverCategory and
             (engStApprovers(i).approval_status is null or
             engStApprovers(i).approval_status = ame_util.nullStatus)))) then
          if engStItemAppProcessCompleteYN(tempItemIndex) in (ame_util2.completeNoApprovers
                                                             ,ame_util2.completeFullyApproved) then
            engStItemAppProcessCompleteYN(tempItemIndex) := ame_util2.notCompleted;
Line: 9574

  procedure processAdHocInsertions as
    displacedInserteeIndexes ame_util.idList;
Line: 9582

    tempItemClass ame_temp_insertions.item_class%type;
Line: 9583

    tempItemId ame_temp_insertions.item_id%type;
Line: 9584

    tempOrderType ame_temp_insertions.order_type%type;
Line: 9588

        for each inserted approver:
          orig_system
          orig_system_id
          display_name
          action_type_id
          group_or_chain_id
          occurrence
          source
          approval_status
          item_class_order_number
          item_order_number
          sub_list_order_number
          action_type_order_number
          group_or_chain_order_number
          member_order_number
        The first three of these fields get populated at the beginning of the outermost loop below.
        The other fields get populated just before the actual insertion occurs.  This procedure must
        therefore decide how to set the order-number fields.  The procedure attempts to set the
        order numbers consistent with the order relation of the insertion, where the order relation
        anchors the insertion to the approver preceeding or following the insertion in engStApprovers.
        See the comments near specific insertApprover calls below.
      */
      engStApproversCount := engStApprovers.count;
Line: 9611

      for i in 1 .. engInsertedApproverList.count loop
        if(engInsertedApproverList(i).authority <> ame_util.authorityApprover or
           engInsertedApproverList(i).api_insertion = ame_util.apiInsertion) then
          ame_approver_type_pkg.getOrigSystemIdAndDisplayName(nameIn => engInsertedApproverList(i).name,
                                                              origSystemOut => engInsertedApproverList(i).orig_system,
                                                              origSystemIdOut => engInsertedApproverList(i).orig_system_id,
                                                              displayNameOut => engInsertedApproverList(i).display_name);
Line: 9618

          parameterFields.delete;
Line: 9619

          parseFields(stringIn => engInsertionParameterList(i),
                      fieldsOut => parameterFields);
Line: 9622

          if(engInsertionOrderTypeList(i) = ame_util.absoluteOrder) then
            tempIndex := engInsertionParameterList(i);
Line: 9627

            engInsertedApproverList(i).source := ame_util.otherInsertion;
Line: 9629

               engStApprovers(tempIndex - 1).authority = engInsertedApproverList(i).authority and
               engStApprovers(tempIndex - 1).item_class = engInsertedApproverList(i).item_class and
               engStApprovers(tempIndex - 1).item_id = engInsertedApproverList(i).item_id
               ) then
              /* Group the insertion with the preceeding approver in engStApprovers. */
              engInsertedApproverList(i).action_type_id := engStApprovers(tempIndex - 1).action_type_id;
Line: 9635

              engInsertedApproverList(i).group_or_chain_id := engStApprovers(tempIndex - 1).group_or_chain_id;
Line: 9636

              engInsertedApproverList(i).occurrence :=
                getHandlerOccurrence(nameIn => engInsertedApproverList(i).name,
                                     itemClassIn => engInsertedApproverList(i).item_class,
                                     itemIdIn => engInsertedApproverList(i).item_id,
                                     actionTypeIdIn => engInsertedApproverList(i).action_type_id,
                                     groupOrChainIdIn => engInsertedApproverList(i).group_or_chain_id);
Line: 9642

              engInsertedApproverList(i).item_class_order_number :=
                engStApprovers(tempIndex - 1).item_class_order_number;
Line: 9644

              engInsertedApproverList(i).item_order_number := engStApprovers(tempIndex - 1).item_order_number;
Line: 9645

              engInsertedApproverList(i).sub_list_order_number := engStApprovers(tempIndex - 1).sub_list_order_number;
Line: 9646

              engInsertedApproverList(i).action_type_order_number :=
                engStApprovers(tempIndex - 1).action_type_order_number;
Line: 9648

              engInsertedApproverList(i).group_or_chain_order_number :=
                engStApprovers(tempIndex - 1).group_or_chain_order_number;
Line: 9651

              /* Group the insertion with the following approver in engStApprovers. */
              engInsertedApproverList(i).authority := engStApprovers(tempIndex).authority;
Line: 9653

              engInsertedApproverList(i).action_type_id := engStApprovers(tempIndex).action_type_id;
Line: 9654

              engInsertedApproverList(i).group_or_chain_id := engStApprovers(tempIndex).group_or_chain_id;
Line: 9655

              engInsertedApproverList(i).occurrence :=
                getHandlerOccurrence(nameIn => engInsertedApproverList(i).name,
                                     itemClassIn => engInsertedApproverList(i).item_class,
                                     itemIdIn => engInsertedApproverList(i).item_id,
                                     actionTypeIdIn => engInsertedApproverList(i).action_type_id,
                                     groupOrChainIdIn => engInsertedApproverList(i).group_or_chain_id);
Line: 9661

              engInsertedApproverList(i).item_class_order_number := engStApprovers(tempIndex).item_class_order_number;
Line: 9662

              engInsertedApproverList(i).item_order_number := engStApprovers(tempIndex).item_order_number;
Line: 9663

              engInsertedApproverList(i).sub_list_order_number := engStApprovers(tempIndex).sub_list_order_number;
Line: 9664

              engInsertedApproverList(i).action_type_order_number := engStApprovers(tempIndex).action_type_order_number;
Line: 9665

              engInsertedApproverList(i).group_or_chain_order_number :=
                engStApprovers(tempIndex).group_or_chain_order_number;
Line: 9669

              engInsertedApproverList(i).action_type_id := ame_util.nullInsertionActionTypeId;
Line: 9670

              engInsertedApproverList(i).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 9671

              engInsertedApproverList(i).occurrence := 1;
Line: 9672

              engInsertedApproverList(i).item_class_order_number :=
                getItemClassOrderNumber(itemClassIdIn =>
                  getItemClassId(itemClassNameIn => engInsertedApproverList(i).item_class));
Line: 9675

              engInsertedApproverList(i).item_order_number :=
                getItemOrderNumber(itemClassNameIn => engInsertedApproverList(i).item_class,
                                   itemIdIn => engInsertedApproverList(i).item_id);
Line: 9678

              engInsertedApproverList(i).sub_list_order_number :=
                getSublistOrderNum(itemClassNameIn => ame_util.headerItemClassName,
                                   authorityIn => ame_util.postApprover);
Line: 9681

              engInsertedApproverList(i).action_type_order_number := getNullActionTypeOrderNumber;
Line: 9682

              engInsertedApproverList(i).group_or_chain_order_number := 1;
Line: 9687

                ,'ame_engine.processAdhocInsertions'
                ,'Adhoc Insertion approver(absolute order) ::: ' || engInsertedApproverList(i).name
                );
Line: 9691

            insertApprover(indexIn => tempIndex,
                           approverIn => engInsertedApproverList(i),
                           adjustMemberOrderNumbersIn => true,
                           inserteeIndexIn => i,
                           currentInsIndex => i);
Line: 9696

            populateInsertionIndexes(indexIn => tempIndex
                                    ,insertionOrderIn => engInsertionOrderList(i));
Line: 9700

          elsif(engInsertionOrderTypeList(i) in (ame_util.afterApprover,
                                                 ame_util.beforeApprover)) then
            tempIndex := 1; /* post-increment */
Line: 9707

                the insertion parameter.
              */
              if(engStApprovers(tempIndex).name = parameterFields(1) and
                 engStApprovers(tempIndex).occurrence = parameterFields(6) and
                 engStApprovers(tempIndex).group_or_chain_id = parameterFields(5) and
                 engStApprovers(tempIndex).action_type_id = parameterFields(4) and
                 engStApprovers(tempIndex).item_id = parameterFields(3) and
                 engStApprovers(tempIndex).item_class = parameterFields(2)) then
                tempBoolean := true;
Line: 9716

                if(engInsertionOrderTypeList(i) = ame_util.afterApprover) then
                  tempIndex2 := tempIndex + 1;
Line: 9721

                engInsertedApproverList(i).action_type_id := engStApprovers(tempIndex).action_type_id;
Line: 9722

                engInsertedApproverList(i).group_or_chain_id := engStApprovers(tempIndex).group_or_chain_id;
Line: 9723

                engInsertedApproverList(i).occurrence :=
                  getHandlerOccurrence(nameIn => engInsertedApproverList(i).name,
                                       itemClassIn => engInsertedApproverList(i).item_class,
                                       itemIdIn => engInsertedApproverList(i).item_id,
                                       actionTypeIdIn => engInsertedApproverList(i).action_type_id,
                                       groupOrChainIdIn => engInsertedApproverList(i).group_or_chain_id);
Line: 9729

                if(engInsertionIsSpecialForwardee(i) = ame_util.booleanTrue) then
                  engInsertedApproverList(i).source := ame_util.specialForwardInsertion;
Line: 9732

                  if(engInsertionOrderTypeList(i) = ame_util.afterApprover and
                     engStApprovers(tempIndex).approval_status = ame_util.forwardStatus) then
                    engInsertedApproverList(i).source := ame_util.forwardInsertion;
Line: 9735

                  elsif(engInsertionOrderTypeList(i) = ame_util.afterApprover and
                        engStApprovers(tempIndex).approval_status = ame_util.approveAndForwardStatus) then
                    engInsertedApproverList(i).source := ame_util.approveAndForwardInsertion;
Line: 9739

                    engInsertedApproverList(i).source := ame_util.otherInsertion;
Line: 9742

                engInsertedApproverList(i).item_class_order_number := engStApprovers(tempIndex).item_class_order_number;
Line: 9743

                engInsertedApproverList(i).item_order_number := engStApprovers(tempIndex).item_order_number;
Line: 9744

                engInsertedApproverList(i).sub_list_order_number := engStApprovers(tempIndex).sub_list_order_number;
Line: 9745

                engInsertedApproverList(i).action_type_order_number := engStApprovers(tempIndex).action_type_order_number;
Line: 9746

                engInsertedApproverList(i).group_or_chain_order_number :=
                  engStApprovers(tempIndex).group_or_chain_order_number;
Line: 9751

                    ,'ame_engine.processAdhocInsertions'
                    ,'Adhoc Insertion approver(after/before approver) ::: ' || engInsertedApproverList(i).name
                    );
Line: 9755

                insertApprover(indexIn => tempIndex2,
                               approverIn => engInsertedApproverList(i),
                               adjustMemberOrderNumbersIn => true,
                               inserteeIndexIn => i,
                               currentInsIndex => i);
Line: 9760

                populateInsertionIndexes(indexIn => tempIndex2
                                        ,insertionOrderIn => engInsertionOrderList(i));
Line: 9773

              ame_api3.getAvailableInsertions for these order types.
            */
            if(engStApproversCount = 0) then
              /*
                The four first/last pre/post order types can only occur in an empty list if the insertion
                is for the header item.  Treat any other case of these order types as displaced, here.
                In the code blocks below for these four order types, require that engStApproversCount > 0.
              */
              if(parameterFields(3) = ame_util.headerItemClassName and
                 parameterFields(2) = engTransactionId) then
                engInsertedApproverList(i).occurrence := 1;
Line: 9784

                engInsertedApproverList(i).item_class_order_number :=
                  getItemClassOrderNumber(itemClassIdIn =>
                    getItemClassId(itemClassNameIn => ame_util.headerItemClassName));
Line: 9787

                engInsertedApproverList(i).item_order_number := 1;
Line: 9788

                engInsertedApproverList(i).sub_list_order_number :=
                  getSublistOrderNum(itemClassNameIn => ame_util.headerItemClassName,
                                     authorityIn => engInsertedApproverList(i).authority);
Line: 9791

                engInsertedApproverList(i).action_type_order_number := getNullActionTypeOrderNumber;
Line: 9792

                engInsertedApproverList(i).group_or_chain_order_number := 1;
Line: 9793

                engInsertedApproverList(i).member_order_number := 1;
Line: 9794

                insertApprover(indexIn => 1,
                               approverIn => engInsertedApproverList(i),
                               adjustMemberOrderNumbersIn => false,
                               inserteeIndexIn => i,
                               currentInsIndex => i);
Line: 9799

                populateInsertionIndexes(indexIn => 1
                                        ,insertionOrderIn => engInsertionOrderList(i));
Line: 9803

                engInsertedApproverList(i).occurrence := 1;
Line: 9804

                engInsertedApproverList(i).item_class_order_number :=
                  getItemClassOrderNumber(itemClassIdIn =>
                    getItemClassId(itemClassNameIn => engInsertedApproverList(i).item_class));
Line: 9807

                engInsertedApproverList(i).item_order_number := 1;
Line: 9808

                engInsertedApproverList(i).sub_list_order_number :=
                  getSublistOrderNum(itemClassNameIn => engInsertedApproverList(i).item_class,
                                     authorityIn => engInsertedApproverList(i).authority);
Line: 9811

                engInsertedApproverList(i).action_type_order_number := getNullActionTypeOrderNumber;
Line: 9812

                engInsertedApproverList(i).group_or_chain_order_number := 1;
Line: 9813

                engInsertedApproverList(i).member_order_number := 1;
Line: 9814

                displacedInserteeIndexes(displacedInserteeIndexes.count + 1) := i;
Line: 9820

              if(engInsertionOrderTypeList(i) = ame_util.firstPostApprover) then
                /*
                  Insert at tempIndex if it's non-null, after checking the possible cases.
                  Recall that the case where engStApproversCount = 0 is handled at the
                  start of the procedure, that the item id is in parameterFields(3), and
                  that the item-class ID is in parameterFields(2).  Here are the cases
                  requiring insertion (always at j + 1).
                  1.  j = 0,
                      post-approver for the right item at j + 1 = 1
                  2.  j > 0,
                      j < engStApproversCount,
                      non-post-approver for the right item at j,
                      post-approver for the right item at j + 1
                  3.  j > 0,
                      j < engStApproversCount,
                      non-post-approver for the right item at j,
                      any approver for the wrong item at j + 1
                  4.  j > 0,
                      j = engStApproversCount,
                      non-post-approver for the right item at j
                  5.  j > 0,
                      j < engStApproversCount,
                      any approver for the wrong item at j,
                      post-approver for the right item at j + 1
                  Finally, note that the way the code is written, case 4 must be checked
                  before cases 2, 3, and 5, to ensure that for these cases,
                  j + 1 <= engStApproversCount.
                */
                /* The zero lower limit is intentional. */
                for j in 0 .. engStApproversCount loop
                  tempIndex2 := j + 1;
Line: 9897

              elsif(engInsertionOrderTypeList(i) = ame_util.firstPreApprover) then
                /*
                  Insert at tempIndex if it's non-null, after checking the possible cases.
                  Recall that the case where engStApproversCount = 0 is handled at the
                  start of the procedure.  Here are the cases requiring insertion (always
                  at j).
                  1.  j = 1,
                      any approver for the right item at j = 1
                  2.  j > 1,
                      any approver for the wrong item at j - 1,
                      any approver for the right item at j
                */
                for j in 1 .. engStApproversCount loop
                  if(j = 1) then
                    if(engStApprovers(1).item_id = parameterFields(3) and
                       engStApprovers(1).item_class = parameterFields(2)) then /* case 1 */
                      tempIndex := 1;
Line: 9931

              elsif(engInsertionOrderTypeList(i) = ame_util.lastPostApprover) then
                /*
                  Insert at tempIndex if it's non-null, after checking the possible cases.
                  Recall that the case where engStApproversCount = 0 is handled at the
                  start of the procedure.  Here are the cases requiring insertion (always
                  at j + 1).
                  1.  j = engStApproversCount,
                      any approver for the right item at j
                  2.  j < engStApproversCount,
                      any approver for right item at j,
                      any approver for wrong item at j + 1
                */
                for j in 1 .. engStApproversCount loop
                  if(j = engStApproversCount) then
                    if(engStApprovers(j).item_id = parameterFields(3) and
                       engStApprovers(j).item_class = parameterFields(2)) then
                      tempIndex := engStApproversCount + 1;
Line: 9967

              else /* engInsertionOrderTypeList(i) = ame_util.lastPreApprover */
                /*
                  Insert at tempIndex if it's non-null, after checking the possible cases.
                  Recall that the case where engStApproversCount = 0 is handled at the
                  start of the procedure.  Here are the cases (always inserting at j):
                  1.  j = 1,
                      non-pre-approver for the right item at 1
                  2.  j > 1,
                      j <= engStApproversCount,
                      the approver at j - 1 is for the right item,
                      the approver at j is for the right item,
                      the approver at j - 1 is a pre-approver,
                      the approver at j is not a pre-approver
                  3.  j > 1,
                      j <= engStApproversCount,
                      any approver at j - 1 for the wrong item,
                      the approver at j is for the right item,
                      the approver at j is not a pre-approver
                */
                for j in 1 .. engStApproversCount loop
                  if(j = 1) then
                    if(engStApprovers(1).item_id = parameterFields(3) and
                       engStApprovers(1).item_class = parameterFields(2) and
                       engStApprovers(1).authority <> ame_util.preApprover) then /* case 1 */
                      tempIndex := 1;
Line: 10013

              /* Set the remaining fields in the insertee's approverRecord2. */
              engInsertedApproverList(i).source := ame_util.otherInsertion;
Line: 10016

                engInsertedApproverList(i).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 10020

                /* engInsertedApproverList(i).action_type_id := ame_util.nullInsertionActionTypeId; */
Line: 10021

                engInsertedApproverList(i).occurrence :=
                  getHandlerOccurrence(nameIn => engInsertedApproverList(i).name,
                                       itemClassIn => engInsertedApproverList(i).item_class,
                                       itemIdIn => engInsertedApproverList(i).item_id,
                                       actionTypeIdIn => engInsertedApproverList(i).action_type_id,
                                       groupOrChainIdIn => engInsertedApproverList(i).group_or_chain_id);
Line: 10027

                engInsertedApproverList(i).item_class_order_number :=
                  getItemClassOrderNumber(itemClassIdIn =>
                    getItemClassId(itemClassNameIn => engInsertedApproverList(i).item_class));
Line: 10030

                engInsertedApproverList(i).item_order_number :=
                  getItemOrderNumber(itemClassNameIn => engInsertedApproverList(i).item_class,
                                                 itemIdIn => engInsertedApproverList(i).item_id);
Line: 10036

                if engInsertionOrderTypeList(i) = ame_util.firstPreApprover or
                        engInsertionOrderTypeList(i) = ame_util.lastPreApprover then
                  engInsertedApproverList(i).sub_list_order_number :=
                    getSublistOrderNum(itemClassNameIn => engInsertedApproverList(i).item_class,
                                       authorityIn => ame_util.preApprover);
Line: 10041

                elsif engInsertionOrderTypeList(i) = ame_util.firstPostApprover or
                        engInsertionOrderTypeList(i) = ame_util.lastPostApprover then
                  engInsertedApproverList(i).sub_list_order_number :=
                    getSublistOrderNum(itemClassNameIn => engInsertedApproverList(i).item_class,
                                       authorityIn => ame_util.postApprover);
Line: 10050

                /* engInsertedApproverList(i).action_type_order_number := getNullActionTypeOrderNumber; */
Line: 10051

                engInsertedApproverList(i).action_type_order_number := 1;
Line: 10052

                engInsertedApproverList(i).group_or_chain_order_number := 1;
Line: 10054

                engInsertedApproverList(i).group_or_chain_id := ame_util.nullInsertionGroupOrChainId;
Line: 10058

                /* engInsertedApproverList(i).action_type_id := ame_util.nullInsertionActionTypeId;*/
Line: 10059

                engInsertedApproverList(i).occurrence :=
                  getHandlerOccurrence(nameIn => engInsertedApproverList(i).name,
                                       itemClassIn => engInsertedApproverList(i).item_class,
                                       itemIdIn => engInsertedApproverList(i).item_id,
                                       actionTypeIdIn => engInsertedApproverList(i).action_type_id,
                                       groupOrChainIdIn => engInsertedApproverList(i).group_or_chain_id);
Line: 10065

                engInsertedApproverList(i).item_class_order_number :=
                  engStApprovers(tempAnchorIndex).item_class_order_number;
Line: 10067

                engInsertedApproverList(i).item_order_number :=
                  engStApprovers(tempAnchorIndex).item_order_number;
Line: 10069

                engInsertedApproverList(i).sub_list_order_number :=
                  engStApprovers(tempAnchorIndex).sub_list_order_number;
Line: 10074

                /*engInsertedApproverList(i).action_type_order_number :=                */
                /*  engStApprovers(tempAnchorIndex).action_type_order_number;           */
Line: 10076

                if engInsertionOrderTypeList(i) = ame_util.firstPreApprover or
                     engInsertionOrderTypeList(i) = ame_util.firstPostApprover then
                  engInsertedApproverList(i).action_type_order_number :=
                    engStApprovers(tempAnchorIndex).action_type_order_number - 1;
Line: 10080

                elsif engInsertionOrderTypeList(i) = ame_util.lastPreApprover or
                     engInsertionOrderTypeList(i) = ame_util.lastPostApprover then
                  engInsertedApproverList(i).action_type_order_number :=
                    engStApprovers(tempAnchorIndex).action_type_order_number + 1;
Line: 10085

                engInsertedApproverList(i).group_or_chain_order_number :=
                  engStApprovers(tempAnchorIndex).group_or_chain_order_number;
Line: 10088

              /* Perform the insertion if the proper position has been located. */
              if(tempIndex is null) then
                displacedInserteeIndexes(displacedInserteeIndexes.count + 1) := i;
Line: 10095

                if engInsertionOrderTypeList(i) = ame_util.firstPreApprover or
                        engInsertionOrderTypeList(i) = ame_util.firstPostApprover then
                  engInsertedApproverList(i).action_type_id := -1;
Line: 10101

                      ,'ame_engine.processAdhocInsertions'
                      ,'Adhoc Insertion approver(first pre/first post approver) ::: ' || engInsertedApproverList(i).name
                      );
Line: 10105

                  insertApprover(indexIn => tempIndex,
                                 approverIn => engInsertedApproverList(i),
                                 adjustMemberOrderNumbersIn => true,
                                 approverLocationIn => ame_util.firstAmongEquals,
                                 inserteeIndexIn => i,
                                 currentInsIndex => i);
Line: 10111

                  populateInsertionIndexes(indexIn => tempIndex
                                          ,insertionOrderIn => engInsertionOrderList(i));
Line: 10113

                elsif engInsertionOrderTypeList(i) = ame_util.lastPreApprover or
                        engInsertionOrderTypeList(i) = ame_util.lastPostApprover then
                  engInsertedApproverList(i).action_type_id := -2;
Line: 10119

                      ,'ame_engine.processAdhocInsertions'
                      ,'Adhoc Insertion approver(last pre/last post approver) ::: ' || engInsertedApproverList(i).name
                      );
Line: 10123

                  insertApprover(indexIn => tempIndex,
                                 approverIn => engInsertedApproverList(i),
                                 adjustMemberOrderNumbersIn => true,
                                 approverLocationIn => ame_util.lastAmongEquals,
                                 inserteeIndexIn => i,
                                 currentInsIndex => i);
Line: 10129

                  populateInsertionIndexes(indexIn => tempIndex
                                          ,insertionOrderIn => engInsertionOrderList(i));
Line: 10139

        Insert any displaced approvers at the end of their items' lists, if possible; and
Line: 10142

      for i in 1 .. displacedInserteeIndexes.count loop
        parameterFields.delete;
Line: 10144

        parseFields(stringIn => engInsertionParameterList(displacedInserteeIndexes(i)),
                    fieldsOut => parameterFields);
Line: 10146

        /* Set tempBoolean false if displaced approver i is inserted at the end of its item's list. */
        tempBoolean := true;
Line: 10158

                ,'ame_engine.processAdhocInsertions'
                ,'Adhoc Insertion approver(displaced) ::: ' || engInsertedApproverList(displacedInserteeIndexes(i)).name
                );
Line: 10162

            insertApprover(indexIn => j + 1,
                           approverIn => engInsertedApproverList(displacedInserteeIndexes(i)),
                           adjustMemberOrderNumbersIn => true,
                           inserteeIndexIn => i,
                           currentInsIndex => i);
Line: 10167

            populateInsertionIndexes(indexIn => j + 1
                                    ,insertionOrderIn => engInsertionOrderList(displacedInserteeIndexes(i)));
Line: 10177

              ,'ame_engine.processAdhocInsertions'
              ,'Adhoc Insertion approver(displaced) ::: ' || engInsertedApproverList(displacedInserteeIndexes(i)).name
              );
Line: 10181

          insertApprover(indexIn => engStApproversCount + 1,
                         approverIn => engInsertedApproverList(displacedInserteeIndexes(i)),
                         adjustMemberOrderNumbersIn => false,
                         inserteeIndexIn => i,
                         currentInsIndex => i);
Line: 10186

          populateInsertionIndexes(indexIn => engStApproversCount + 1
                                  ,insertionOrderIn => engInsertionOrderList(displacedInserteeIndexes(i)));
Line: 10194

                                    routineNameIn => 'processAdHocInsertions',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 10198

    end processAdHocInsertions;
Line: 10289

  procedure populateInsertionIndexes(indexIn in integer
                                    ,insertionOrderIn in integer) as
    firstIndex integer;
Line: 10295

      firstIndex := engStInsertionIndexes.first;
Line: 10296

      if(engStInsertionIndexes.exists(firstIndex)) then
        lastIndex := engStInsertionIndexes.last;
Line: 10298

        while engStInsertionIndexes.exists(lastIndex) and lastIndex >= indexIn loop
          tempValue := engStInsertionIndexes(lastIndex);
Line: 10300

          engStInsertionIndexes(lastIndex + 1) := tempValue;
Line: 10301

          engStInsertionIndexes.delete(lastIndex);
Line: 10302

          lastIndex := engStInsertionIndexes.prior(lastIndex + 1);
Line: 10304

        engStInsertionIndexes(indexIn) := insertionOrderIn;
Line: 10306

        engStInsertionIndexes(indexIn) := insertionOrderIn;
Line: 10308

    end populateInsertionIndexes;
Line: 10323

      for i in 1 .. engDeletedApproverList.count loop
        for j in 1 .. engStApprovers.count loop
          if(engStApprovers(j).name = engDeletedApproverList(i).name and
             engStApprovers(j).occurrence = engDeletedApproverList(i).occurrence and
             engStApprovers(j).group_or_chain_id = engDeletedApproverList(i).group_or_chain_id and
             engStApprovers(j).action_type_id = engDeletedApproverList(i).action_type_id and
             engStApprovers(j).item_id = engDeletedApproverList(i).item_id and
             engStApprovers(j).item_class = engDeletedApproverList(i).item_class) then
            engStApprovers(j).approval_status := ame_util.suppressedStatus;
Line: 10431

            tempExcOrdCondAttributeIds.delete;
Line: 10449

                    copy it at each iteration, so we can freely delete entries in the
                    copy.
                  */
                  tempAttributeIdsToMatch.delete;
Line: 10474

                        tempAttributeIdsToMatch.delete(tempAttributeId);
Line: 10487

                      exception's ordinary conditions' attributes were matched; so, delete the authority
Line: 10491

                    engAppItemClassIds.delete(j);
Line: 10492

                    engAppItemIds.delete(j);
Line: 10493

                    engAppRuleIds.delete(j);
Line: 10494

                    engRuleAppliedYN.delete(j);
Line: 10495

                    engAppRuleTypes.delete(j);
Line: 10496

                    engAppActionTypeIds.delete(j);
Line: 10497

                    engAppParameters.delete(j);
Line: 10498

                    engAppParameterTwos.delete(j);
Line: 10499

                    engAppRuleItemClassIds.delete(j);
Line: 10500

                    engAppAppItemIds.delete(j);
Line: 10517

      /* Re-compact the engApp lists if any authority rules got deleted. */
      if(authorityRuleSuppressed) then
        compactEngAppLists(compactPrioritiesIn => false,
                           compactActionTypeIdsIn => true,
                           compactParametersIn => true);
Line: 10643

                  per-item approver responses.  See the ame_api2.updateApprovalStatus code for details.
                  Also, don't suppress special forwardees.  See bug 3401298 for details.
                */
                if(engStApprovers(j).approval_status is null and
                   engStApprovers(j).source not like ame_util.specialForwardInsertion || '%') then
                  engStApprovers(j).approval_status := ame_util.repeatedStatus;
Line: 10680

          repeatedIndexesList.delete;
Line: 10841

                    /* Update the current action-type state variables. */
                    engAppHandlerFirstIndex := tempIndex;
Line: 10855

            /* Update the current state variables. */
            currentFirstRuleIndexes.delete;
Line: 10857

            currentLastRuleIndexes.delete;
Line: 10903

    ruleDeleted boolean;
Line: 10919

      ruleDeleted := false;
Line: 10929

          tempThresholds.delete;
Line: 10967

                engAppRuleIds.delete(i);
Line: 10968

                engRuleAppliedYN.delete(i);
Line: 10969

                engAppItemClassIds.delete(i);
Line: 10970

                engAppItemIds.delete(i);
Line: 10971

                engAppPriorities.delete(i);
Line: 10972

                engAppApproverCategories.delete(i);
Line: 10973

                engAppRuleTypes.delete(i);
Line: 10974

                engAppRuleItemClassIds.delete(i);
Line: 10975

                engAppAppItemIds.delete(i);
Line: 10976

                ruleDeleted := true;
Line: 11021

                  engAppRuleIds.delete(oldTempIndex);
Line: 11022

                  engRuleAppliedYN.delete(oldTempIndex);
Line: 11023

                  engAppItemClassIds.delete(oldTempIndex);
Line: 11024

                  engAppItemIds.delete(oldTempIndex);
Line: 11025

                  engAppPriorities.delete(oldTempIndex);
Line: 11026

                  engAppApproverCategories.delete(oldTempIndex);
Line: 11027

                  engAppRuleTypes.delete(oldTempIndex);
Line: 11028

                  engAppRuleItemClassIds.delete(oldTempIndex);
Line: 11029

                  engAppAppItemIds.delete(oldTempIndex);
Line: 11030

                  ruleDeleted := true;
Line: 11040

      /* If relative-priority processing deleted one or more rules from the engApp lists, compact them. */
      if(ruleDeleted) then
        compactEngAppLists(compactPrioritiesIn => true,
                           compactActionTypeIdsIn => false,
                           compactParametersIn => false);
Line: 11076

          tempSurrogateApprover.api_insertion := ame_util.apiInsertion;
Line: 11077

          tempSurrogateApprover.source := ame_util.surrogateInsertion;
Line: 11099

             instead of in insertApprover. This will ensure that the surrogate has the same
             order as the unresponsive approver. Also changed call to insertApprover so that
             adjustMemberOrderNumbers is false */
          tempSurrogateApprover.member_order_number := engStApprovers(tempIndex).member_order_number;
Line: 11114

          insertApprover(indexIn => tempIndex + 1,
                         approverIn => tempSurrogateApprover,
                         adjustMemberOrderNumbersIn => false);
Line: 11149

                       fetchInsertionsIn in boolean,
                       fetchDeletionsIn in boolean,
                       fetchAttributeValuesIn in boolean,
                       fetchInactiveAttValuesIn in boolean,
                       processProductionActionsIn in boolean,
                       processProductionRulesIn in boolean,
                       updateCurrentApproverListIn in boolean,
                       updateOldApproverListIn in boolean,
                       processPrioritiesIn in boolean,
                       prepareItemDataIn in boolean,
                       prepareRuleIdsIn in boolean,
                       prepareRuleDescsIn in boolean,
                       prepareApproverTreeIn in boolean default false,
                       transactionIdIn in varchar2,
                       ameApplicationIdIn in integer default null,
                       fndApplicationIdIn in integer default null,
                       transactionTypeIdIn in varchar2 default null) as
    badLocalTransException exception;
Line: 11176

      engLMParameterOnes.delete;
Line: 11177

      engLMParameterTwos.delete;
Line: 11178

      engGroupMemberGroupIds.delete;
Line: 11179

      engGroupMemberNames.delete;
Line: 11180

      engGroupMemberOrderNumbers.delete;
Line: 11181

      engGroupMemberDisplayNames.delete;
Line: 11182

      engGroupMemberOrigSystems.delete;
Line: 11183

      engGroupMemberOrigSystemIds.delete;
Line: 11184

      engGroupUseItemBind.delete;
Line: 11185

      engAppActionTypeIds.delete;
Line: 11186

      engAppApproverCategories.delete;
Line: 11187

      engAppItemClassIds.delete;
Line: 11188

      engAppItemIds.delete;
Line: 11189

      engAppLMSubItemClassIds.delete;
Line: 11190

      engAppLMSubItemIds.delete;
Line: 11191

      engAppParameters.delete;
Line: 11192

      engAppParameterTwos.delete;
Line: 11193

      engAppPriorities.delete;
Line: 11194

      engAppRuleIds.delete;
Line: 11195

      engRuleAppliedYN.delete;
Line: 11196

      engAppRuleTypes.delete;
Line: 11197

      engAppRuleItemClassIds.delete;
Line: 11198

      engAppAppItemIds.delete;
Line: 11199

      engAppPerAppProdFirstIndexes.delete;
Line: 11200

      engAppPerAppProdRuleIds.delete;
Line: 11201

      engAppPerAppProdVariableNames.delete;
Line: 11202

      engAppPerAppProdVariableValues.delete;
Line: 11203

      engStApprovers.delete;
Line: 11205

      engStApproversTree.delete;
Line: 11206

      engStItemClasses.delete;
Line: 11207

      engStItemIds.delete;
Line: 11208

      engStItemIndexes.delete;
Line: 11209

      engStItemSources.delete;
Line: 11210

      engStProductionIndexes.delete;
Line: 11212

      engStRepeatedIndexes.delete;
Line: 11213

      engStRepeatedAppIndexes.delete;
Line: 11214

      engStRuleDescriptions.delete;
Line: 11215

      engStRuleIds.delete;
Line: 11216

      engStRuleIndexes.delete;
Line: 11217

      engStSourceTypes.delete;
Line: 11219

      engStSuspendedItems.delete;
Line: 11220

      engStSuspendedItemClasses.delete;
Line: 11221

      engStProductionsTable.delete;
Line: 11222

      engStVariableNames.delete;
Line: 11223

      engStVariableValues.delete;
Line: 11224

      engStItemAppProcessCompleteYN.delete;
Line: 11225

      engConfigVarNames.delete;
Line: 11226

      engConfigVarValues.delete;
Line: 11227

      engForwardingBehaviors.delete;
Line: 11228

      engPriorityModes.delete;
Line: 11229

      engPriorityThresholds.delete;
Line: 11230

      engActionTypeChainOrderModes.delete;
Line: 11231

      engActionTypeOrderNumbers.delete;
Line: 11232

      engActionTypeVotingRegimes.delete;
Line: 11233

      engActionTypeNames.delete;
Line: 11234

      engActionTypeUsages.delete;
Line: 11235

      engActionTypePackageNames.delete;
Line: 11236

      engItemClassIds.delete;
Line: 11237

      engItemClassIndexes.delete;
Line: 11238

      engItemClassItemIdIndexes.delete;
Line: 11239

      engItemClassNames.delete;
Line: 11240

      engItemClassOrderNumbers.delete;
Line: 11241

      engItemClassParModes.delete;
Line: 11242

      engItemClassSublistModes.delete;
Line: 11243

      engItemCounts.delete;
Line: 11244

      engItemIds.delete;
Line: 11245

      engAttributeIsStatics.delete;
Line: 11246

      engAttributeItemClassIds.delete;
Line: 11247

      engAttributeNames.delete;
Line: 11248

      engAttributeTypes.delete;
Line: 11249

      engAttributeValueIndexes.delete;
Line: 11250

      engAttributeValues1.delete;
Line: 11251

      engAttributeValues2.delete;
Line: 11252

      engAttributeValues3.delete;
Line: 11253

      engAttributeQueries.delete;
Line: 11254

      engAttributeVariant.delete;
Line: 11255

      engHeaderConditionValues.delete;
Line: 11256

      engACUsageConditionIds.delete;
Line: 11257

      engACUsageFirstIndexes.delete;
Line: 11258

      engACUsageItemClassCounts.delete;
Line: 11259

      engACUsageRuleIds.delete;
Line: 11260

      engACUsageRulePriorities.delete;
Line: 11261

      engACUsageRuleTypes.delete;
Line: 11262

      engACUsageRuleApprCategories.delete;
Line: 11263

      engACAttributeIds.delete;
Line: 11264

      engACConditionTypes.delete;
Line: 11265

      engACIncludeLowerLimits.delete;
Line: 11266

      engACIncludeUpperLimits.delete;
Line: 11267

      engACParameterOnes.delete;
Line: 11268

      engACParameterThrees.delete;
Line: 11269

      engACParameterTwos.delete;
Line: 11270

      engACStringValueCounts.delete;
Line: 11271

      engACStringValueFirstIndexes.delete;
Line: 11272

      engACStringValues.delete;
Line: 11273

      engOldApproverList.delete;
Line: 11274

      engInsertedApproverList.delete;
Line: 11275

      engInsertionOrderTypeList.delete;
Line: 11276

      engInsertionParameterList.delete;
Line: 11277

      engInsertionIsSpecialForwardee.delete;
Line: 11278

      engDeletedApproverList.delete;
Line: 11279

      engStInsertionIndexes.delete;
Line: 11280

      /*delete deviation related info*/
      engDeviationResultList.delete;
Line: 11282

      engInsertionReasonList.delete;
Line: 11283

      engInsertionDateList.delete;
Line: 11284

      engSuppressionDateList.delete;
Line: 11285

      engSupperssionReasonList.delete;
Line: 11286

      engInsApproverIndex.delete;
Line: 11321

      engUpdateCurrentApproverList := updateCurrentApproverListIn;
Line: 11322

      engUpdateOldApproverList := updateOldApproverListIn;
Line: 11364

           updateCurrentApproverListIn or
           updateOldApproverListIn or
           processPrioritiesIn or
           prepareItemDataIn or
           prepareRuleIdsIn or
           prepareRuleDescsIn) then
          /* Fetch the active condition usages. */
          fetchActiveConditionUsages;
Line: 11378

      /* Optionally fetch the inserted-approvers list. */
      if(fetchInsertionsIn) then
        fetchInsertedApprovers;
Line: 11384

        fetchDeletedApprovers;
Line: 11427

      delete
        from ame_temp_handler_states
        where
          handler_name = handlerName and
          application_id = engAmeApplicationId and
          ((parameter is null and parameterIn is null) or
           (parameter = parameterIn));
Line: 11434

      insert into ame_temp_handler_states(
        handler_name,
        row_timestamp,
        application_id,
        parameter,
        state)
        values(
          handlerName,
          sysdate, /* Don't use engEffectiveRuleDate here. */
          engAmeApplicationId,
          parameterIn,
          stateIn);
Line: 11464

  procedure setInsertedApprovalStatus(currentApproverIndexIn in integer
                                      ,approvalStatusIn in varchar2) as
    begin
      for i in 1..engInsApproverIndex.count loop
        if engInsApproverIndex(i) = currentApproverIndexIn then
          engInsertedApproverList(i).approval_status := approvalStatusIn;
Line: 11470

          update ame_temp_insertions
             set approval_status = approvalStatusIn
          where application_id = engAmeApplicationId
           and transaction_id = engTransactionId
           and insertion_order = engInsertionOrderList(i)
           and order_type = engInsertionOrderTypeList(i)
           and parameter = engInsertionParameterList(i)
           and api_insertion = engInsertedApproverList(i).api_insertion
           and authority = engInsertedApproverList(i).authority;
Line: 11485

                                  routineNameIn => 'setInsertedApprovalStatus',
                                  exceptionNumberIn => sqlcode,
                                  exceptionStringIn => sqlerrm);
Line: 11489

  end setInsertedApprovalStatus;
Line: 11617

      /* Update the occurrence values of the same approver wherever the approver occurs later in the same chain. */
      for i in approverIndexIn + 1 .. engStApprovers.count loop
        if(currentGroupOrChainId <> engStApprovers(i).group_or_chain_id or
           engStApprovers(approverIndexIn).action_type_id <> engStApprovers(i).action_type_id or
           engStApprovers(approverIndexIn).item_id <> engStApprovers(i).item_id or
           engStApprovers(approverIndexIn).item_class <> engStApprovers(i).item_class) then
          exit;
Line: 11690

         delete the rest of the chain.
      */
      truncateCount := lastIndexToTruncate - firstIndexToTruncate + 1;
Line: 11698

      /* Code to delete the approvers from the tree whenever there are approver suppressions */
      if engPrepareApproverTree then
        siblingTreeNodeIndex := ame_util.noSiblingIndex;
Line: 11711

              engStApproversTree.delete(loopIndex);
Line: 11715

              engStApproversTree.delete(loopIndex);
Line: 11729

      /* Delete the last truncateCount places. */
      engStApprovers.delete(engStApproversCount - truncateCount + 1, engStApproversCount);
Line: 11744

        delete from ame_temp_trans_locks
          where
            fnd_application_id = fndApplicationIdIn and
            ((transaction_type_id is null and transactionTypeIdIn is null) or
             transaction_type_id = transactionTypeIdIn) and
            transaction_id = transactionIdIn;
Line: 11760

  procedure updateTransactionState(isTestTransactionIn in boolean,
                                   isLocalTransactionIn in boolean,
                                   fetchConfigVarsIn in boolean,
                                   fetchOldApproversIn in boolean,
                                   fetchInsertionsIn in boolean,
                                   fetchDeletionsIn in boolean,
                                   fetchAttributeValuesIn in boolean,
                                   fetchInactiveAttValuesIn in boolean,
                                   processProductionActionsIn in boolean,
                                   processProductionRulesIn in boolean,
                                   updateCurrentApproverListIn in boolean,
                                   updateOldApproverListIn in boolean,
                                   processPrioritiesIn in boolean,
                                   prepareItemDataIn in boolean,
                                   prepareRuleIdsIn in boolean,
                                   prepareRuleDescsIn in boolean,
                                   prepareApproverTreeIn in boolean default false,
                                   transactionIdIn in varchar2,
                                   ameApplicationIdIn in integer default null,
                                   fndApplicationIdIn in integer default null,
                                   transactionTypeIdIn in varchar2 default null) as
    configVarException exception;
Line: 11789

                 fetchInsertionsIn => fetchInsertionsIn,
                 fetchDeletionsIn => fetchDeletionsIn,
                 fetchAttributeValuesIn => fetchAttributeValuesIn,
                 fetchInactiveAttValuesIn => fetchInactiveAttValuesIn,
                 processProductionActionsIn => processProductionActionsIn,
                 processProductionRulesIn => processProductionRulesIn,
                 updateCurrentApproverListIn => updateCurrentApproverListIn,
                 updateOldApproverListIn => updateOldApproverListIn,
                 processPrioritiesIn => processPrioritiesIn,
                 prepareItemDataIn => prepareItemDataIn,
                 prepareRuleIdsIn => prepareRuleIdsIn,
                 prepareRuleDescsIn => prepareRuleDescsIn,
                 prepareApproverTreeIn => prepareApproverTreeIn,
                 transactionIdIn => transactionIdIn,
                 ameApplicationIdIn => ameApplicationIdIn,
                 fndApplicationIdIn => fndApplicationIdIn,
                 transactionTypeIdIn => transactionTypeIdIn);
Line: 11809

          ,'ame_engine.updateTransactionState'
          ,'AME Application Id ::: ' || engAmeApplicationId
          );
Line: 11814

          ,'ame_engine.updateTransactionState'
          ,'AME Transaction Id ::: ' || engTransactionId
          );
Line: 11819

      if updateOldApproverListIn then
        logTransaction;
Line: 11824

         updateCurrentApproverListIn or
         updateOldApproverListIn or
         processPrioritiesIn or
         prepareItemDataIn or
         prepareRuleIdsIn or
         prepareRuleDescsIn) then
        if(not fetchConfigVarsIn) then
          raise configVarException;
Line: 11837

      if(updateCurrentApproverListIn or
         updateOldApproverListIn) then
        processRules(processOnlyProductionsIn => false);
Line: 11846

          ,'ame_engine.updateTransactionState'
          ,'Approver count after processRules ::: ' || engStApprovers.count
          );
Line: 11850

      if(updateCurrentApproverListIn or
         updateOldApproverListIn) then
        processAdHocInsertions;
Line: 11856

            ,'ame_engine.updateTransactionState'
            ,'Approver count after processAdHocInsertions ::: ' || engStApprovers.count
            );
Line: 11864

            ,'ame_engine.updateTransactionState'
            ,'Approver count after processUnresponsiveApprovers ::: ' || engStApprovers.count
            );
Line: 11873

              ,'ame_engine.updateTransactionState'
              ,'Approver count after repeatSubstitutions ::: ' || engStApprovers.count
              );
Line: 11887

            ,'ame_engine.updateTransactionState'
            ,'Approver count after processSuppressions ::: ' || engStApprovers.count
            );
Line: 11899

            ,'ame_engine.updateTransactionState'
            ,'Approver count after processRepeatedApprovers ::: ' || engStApprovers.count
            );
Line: 11911

          if updateOldApproverListIn then
            ame_approver_deviation_pkg.updateDeviationState(
                                         engAmeApplicationId
                                        ,engTransactionId
                                        ,engDeviationResultList
                                        ,engStApprovalProcessCompleteYN
                                        ,engStApprovers);
Line: 11924

              ,'ame_engine.updateTransactionState'
              ,'**************** No Approvers ******************'
              );
Line: 11931

                ,'ame_engine.updateTransactionState'
                ,'Approver ::: ' || engStApprovers(i).name || ' Order Number ::: ' || engStApprovers(i).approver_order_number
                );
Line: 11937

        if(updateOldApproverListIn) then
          updateOldApproverList;
Line: 11947

                                    routineNameIn => 'updateTransactionState',
                                    exceptionNumberIn => errorCode,
                                    exceptionStringIn => errorMessage);
Line: 11954

                                    routineNameIn => 'updateTransactionState',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 11958

    end updateTransactionState;
Line: 11959

  procedure updateOldApproverList as
    tempActionTypeIds ame_util.idList;
Line: 11973

      delete from ame_temp_old_approver_lists
        where
          application_id = engAmeApplicationId and
          transaction_id = engTransactionId;
Line: 11978

        Bulk insert the transaction's current state into ame_temp_old_approver_lists.
        Take the state from engStApprovers, to account for all operations on the approver list.
      */
      ame_util.convertApproversTable2ToValues(approversTableIn => engStApprovers,
                                              namesOut => tempNames,
                                              itemClassesOut => tempItemClasses,
                                              itemIdsOut => tempItemIds,
                                              apiInsertionsOut => tempApiValues,
                                              authoritiesOut => tempAuthorityValues,
                                              actionTypeIdsOut => tempActionTypeIds,
                                              groupOrChainIdsOut => tempGroupOrChainIds,
                                              occurrencesOut => tempOccurrences,
                                              approverCategoriesOut => tempCategories,
                                              statusesOut => tempStatuses);
Line: 12001

        setInsertedApprovalStatus(currentApproverIndexIn => i
                                 ,approvalStatusIn => engStApprovers(i).approval_status);
Line: 12005

        insert into ame_temp_old_approver_lists(
          transaction_id,
          application_id,
          order_number,
          name,
          item_class,
          item_id,
          api_insertion,
          authority,
          action_type_id,
          group_or_chain_id,
          occurrence,
          approver_category,
          approval_status) values(
            engTransactionId,
            engAmeApplicationId,
            tempOrderNumbers(i),
            tempNames(i),
            tempItemClasses(i),
            tempItemIds(i),
            tempApiValues(i),
            tempAuthorityValues(i),
            tempActionTypeIds(i),
            tempGroupOrChainIds(i),
            tempOccurrences(i),
            tempCategories(i),
            tempStatuses(i));
Line: 12035

                                    routineNameIn => 'updateOldApproverList',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 12039

    end updateOldApproverList;
Line: 12054

  procedure updateApprovalStatus(applicationIdIn in number,
                                 transactionTypeIn in varchar2,
                                 transactionIdIn in varchar2,
                                 approverIn in ame_util.approverRecord2,
                                 notificationIn in ame_util2.notificationRecord
                                         default ame_util2.emptyNotificationRecord,
                                 forwardeeIn in ame_util.approverRecord2 default
                                             ame_util.emptyApproverRecord2,
                                 updateItemIn in boolean default false) as
    ameApplicationId integer;
Line: 12064

    apiInsertionException exception;
Line: 12081

    insertedApprover ame_util.approverRecord2;
Line: 12087

    tempInsertionOrder integer;
Line: 12088

    tempParameter ame_temp_insertions.parameter%type;
Line: 12103

        delete from ame_exceptions_log
          where
            transaction_id = transactionIdIn and
            application_id = ameApplicationId;
Line: 12113

      ame_engine.updateTransactionState(isTestTransactionIn => false,
                                        isLocalTransactionIn => false,
                                        fetchConfigVarsIn => true,
                                        fetchOldApproversIn => true,
                                        fetchInsertionsIn => true,
                                        fetchDeletionsIn => true,
                                        fetchAttributeValuesIn => true,
                                        fetchInactiveAttValuesIn => false,
                                        processProductionActionsIn => false,
                                        processProductionRulesIn => false,
                                        updateCurrentApproverListIn => true,
                                        updateOldApproverListIn => false,
                                        processPrioritiesIn => true,
                                        prepareItemDataIn => false,
                                        prepareRuleIdsIn => false,
                                        prepareRuleDescsIn => false,
                                        prepareApproverTreeIn => true,
                                        transactionIdIn => transactionIdIn,
                                        ameApplicationIdIn => null,
                                        fndApplicationIdIn => applicationIdIn,
                                        transactionTypeIdIn => transactionTypeIn);
Line: 12241

        if(approver.source like (ame_util.specialForwardInsertion || '%')) then
          approverInIsSpecialForwardee := true;
Line: 12249

        /* If approverInIsSpecialForwardee, silently convert api_insertion to
           ame_util.apiInsertion for forwardee */
        if approverInIsSpecialForwardee then
          forwardee.api_insertion := ame_util.apiInsertion;
Line: 12254

        /* Make sure the forwardee has the correct api_insertion value for COA forwarders. */
        if(/* Special forwardees can only do ad-hoc forwardings. */
           (approverInIsSpecialForwardee and
            forwardee.api_insertion <> ame_util.apiInsertion) or
           /* Ad-hoc approvers can only do ad-hoc forwardings. */
           ((not approverInIsSpecialForwardee and
             approver.authority <> ame_util.authorityApprover or
             approver.api_insertion = ame_util.apiInsertion) and
            forwardee.api_insertion <> ame_util.apiInsertion) or
           /* COA approvers other than special forwardees can only do COA forwardings. */
           (not approverInIsSpecialForwardee and
            approver.authority = ame_util.authorityApprover and
            approver.api_insertion <> ame_util.apiInsertion and
            forwardee.api_insertion <> ame_util.apiAuthorityInsertion)) then
          raise apiInsertionException;
Line: 12281

          make sure the forwardee is an ad-hoc insertion.  Make this change silently,
          so calling applications don't have to be originating-system aware.
        */
        if(approver.orig_system <> forwardee.orig_system) then
          forwardee.api_insertion := ame_util.apiInsertion;
Line: 12293

      /* Log the status update to the history table. */
      if(approverInIndex is null) then
        insert into ame_approvals_history(transaction_id,
                                          application_id,
                                          approval_status,
                                          row_timestamp,
                                          item_class,
                                          item_id,
                                          name,
                                          approver_category,
                                          action_type_id,
                                          group_or_chain_id,
                                          occurrence)
          values(transactionIdIn,
                 ameApplicationId,
                 decode(approver.approval_status,
                        ame_util.nullStatus, ame_util.nullHistoryStatus,
                        null, ame_util.nullHistoryStatus,
                        approver.approval_status),
                 sysdate,
                 approver.item_class,
                 approver.item_id,
                 approver.name,
                 approver.approver_category,
                 ame_util.nullHistoryActionTypeId,
                 ame_util.nullHistoryGroupOrChainId,
                 ame_util.nullHistoryOccurrence);
Line: 12324

        update AME_TRANS_APPROVAL_HISTORY
           set date_cleared = sysdate
          where transaction_id = transactionIdIn
            and application_id = ameApplicationId
            and name = approver.name
            and (approver.item_class is null or
                 item_class = approver.item_class)
            and (approver.item_id is null or
                 item_id = approver.item_id)
            and (approver.action_type_id is null or
                 action_type_id = approver.action_type_id)
            and (approver.group_or_chain_id is null or
                 group_or_chain_id = approver.group_or_chain_id)
            and (approver.occurrence is null or
                 occurrence = approver.occurrence)
            and date_cleared is null;
Line: 12342

        insertIntoTransApprovalHistory
          (transactionIdIn         => transactionIdIn
          ,applicationIdIn         => ameApplicationId
          ,orderNumberIn           => approver.approver_order_number
          ,nameIn                  => approver.name
          ,appCategoryIn           => approver.approver_category
          ,itemClassIn             => approver.item_class
          ,itemIdIn                => approver.item_id
          ,actionTypeIdIn          => ame_util.nullHistoryActionTypeId
          ,authorityIn             => approver.authority
          ,statusIn                => approver.approval_status
          ,grpOrChainIdIn          => ame_util.nullHistoryGroupOrChainId
          ,occurrenceIn            => ame_util.nullHistoryOccurrence
          ,apiInsertionIn          => approver.api_insertion
          ,memberOrderNumberIn     => approver.member_order_number
          ,notificationIdIn        => notificationIn.notification_id
          ,userCommentsIn          => notificationIn.user_comments
          ,dateClearedIn           => sysdate
          ,historyTypeIn           => 'APPROVERNOTPRESENT');
Line: 12361

        /* Insert a warning into AME's exception log and return. */
        errorCode := -20001;
Line: 12371

                                  routineNameIn => 'updateApprovalStatus',
                                  exceptionNumberIn => errorCode,
                                  exceptionStringIn => errorMessage);
Line: 12376

      insert into ame_approvals_history(transaction_id,
                                        application_id,
                                        approval_status,
                                        row_timestamp,
                                        item_class,
                                        item_id,
                                        name,
                                        approver_category,
                                        action_type_id,
                                        group_or_chain_id,
                                        occurrence)
        values(transactionIdIn,
               ameApplicationId,
               decode(approver.approval_status,
                      ame_util.nullStatus, ame_util.nullHistoryStatus,
                      null, ame_util.nullHistoryStatus,
                      approver.approval_status),
               sysdate,
               approver.item_class,
               approver.item_id,
               approver.name,
               approver.approver_category,
               approver.action_type_id,
               approver.group_or_chain_id,
               approver.occurrence);
Line: 12408

        insertIntoTransApprovalHistory
          (transactionIdIn         => transactionIdIn
          ,applicationIdIn         => ameApplicationId
          ,orderNumberIn           => approver.approver_order_number
          ,nameIn                  => approver.name
          ,appCategoryIn           => approver.approver_category
          ,itemClassIn             => approver.item_class
          ,itemIdIn                => approver.item_id
          ,actionTypeIdIn          => approver.action_type_id
          ,authorityIn             => approver.authority
          ,statusIn                => approver.approval_status
          ,grpOrChainIdIn          => approver.group_or_chain_id
          ,occurrenceIn            => approver.occurrence
          ,apiInsertionIn          => approver.api_insertion
          ,memberOrderNumberIn     => approver.member_order_number
          ,notificationIdIn        => notificationIn.notification_id
          ,userCommentsIn          => notificationIn.user_comments
          ,dateClearedIn           => sysdate
          ,historyTypeIn           => 'APPROVERPRESENT');
Line: 12431

        insertIntoTransApprovalHistory
          (transactionIdIn         => transactionIdIn
          ,applicationIdIn         => ameApplicationId
          ,orderNumberIn           => approver.approver_order_number
          ,nameIn                  => approver.name
          ,appCategoryIn           => approver.approver_category
          ,itemClassIn             => approver.item_class
          ,itemIdIn                => approver.item_id
          ,actionTypeIdIn          => approver.action_type_id
          ,authorityIn             => approver.authority
          ,statusIn                => approver.approval_status
          ,grpOrChainIdIn          => approver.group_or_chain_id
          ,occurrenceIn            => approver.occurrence
          ,apiInsertionIn          => approver.api_insertion
          ,memberOrderNumberIn     => approver.member_order_number
          ,notificationIdIn        => notificationIn.notification_id
          ,userCommentsIn          => notificationIn.user_comments
          ,dateClearedIn           => null
          ,historyTypeIn           => 'APPROVERPRESENT');
Line: 12451

        Update the status of approverIn in ame_temp_old_approver_lists.  If updateItemIn
        is true, update also any other occurrences of the same approver for the same item
        class and item ID.
      */
      if(updateItemIn) then
        if(approver.approval_status in (ame_util.forwardStatus, ame_util.approveAndForwardStatus)) then
          /* Update the forwarder proper. */
          update ame_temp_old_approver_lists
            set approval_status = approver.approval_status
            where
              application_id = ameApplicationId and
              transaction_id = transactionIdIn and
              name = approver.name and
              item_class = approver.item_class and
              item_id = approver.item_id and
              action_type_id = approver.action_type_id and
              group_or_chain_id = approver.group_or_chain_id and
              occurrence = approver.occurrence;
Line: 12470

          update ame_temp_old_approver_lists
            set approval_status = ame_util.suppressedStatus
            where
              application_id = ameApplicationId and
              transaction_id = transactionIdIn and
              name = approver.name and
              item_class = approver.item_class and
              item_id = approver.item_id and
              (action_type_id <> approver.action_type_id or
               group_or_chain_id <> approver.group_or_chain_id or
               occurrence <> approver.occurrence);
Line: 12482

          update ame_temp_old_approver_lists
            set approval_status = approver.approval_status
            where
              application_id = ameApplicationId and
              transaction_id = transactionIdIn and
              name = approver.name and
              item_class = approver.item_class and
              item_id = approver.item_id;
Line: 12492

        update ame_temp_old_approver_lists
          set approval_status = approver.approval_status
          where
            application_id = ameApplicationId and
            transaction_id = transactionIdIn and
            name = approver.name and
            item_class = approver.item_class and
            item_id = approver.item_id and
            action_type_id = approver.action_type_id and
            group_or_chain_id = approver.group_or_chain_id and
            occurrence = approver.occurrence;
Line: 12506

        setInsertedApprovalStatus(currentApproverIndexIn => approverInIndex
                                  ,approvalStatusIn => approver.approval_status);
Line: 12516

            update ame_temp_old_approver_lists
               set approval_status = decode(approver.approval_status
                                           ,ame_util.approvedStatus
                                           ,ame_util.approvedByRepeatedStatus
                                           ,ame_util.approveAndForwardStatus
                                           ,ame_util.approvedByRepeatedStatus
                                           ,ame_util.rejectStatus
                                           ,ame_util.rejectedByRepeatedStatus
                                           ,ame_util.forwardStatus
                                           ,ame_util2.forwardByRepeatedStatus
                                           ,ame_util2.reassignStatus
                                           ,ame_util.nullStatus
                                           ,ame_util.noResponseStatus
                                           ,ame_util2.noResponseByRepeatedStatus
                                           ,ame_util.repeatedStatus)
             where application_id = ameApplicationId
               and transaction_id = transactionIdIn
               and name           = approver.name
               and item_class        = currentApprovers(repeatedAppIndexes(z)).item_class
               and item_id           = currentApprovers(repeatedAppIndexes(z)).item_id
               and action_type_id    = currentApprovers(repeatedAppIndexes(z)).action_type_id
               and group_or_chain_id = currentApprovers(repeatedAppIndexes(z)).group_or_chain_id
               and occurrence        = currentApprovers(repeatedAppIndexes(z)).occurrence
               and approval_status in ( ame_util.notifiedByRepeatedStatus
                                       ,ame_util.repeatedStatus);
Line: 12541

            select decode(approver.approval_status
                                           ,ame_util.approvedStatus
                                           ,ame_util.approvedByRepeatedStatus
                                           ,ame_util.approveAndForwardStatus
                                           ,ame_util.approvedByRepeatedStatus
                                           ,ame_util.rejectStatus
                                           ,ame_util.rejectedByRepeatedStatus
                                           ,ame_util.forwardStatus
                                           ,ame_util2.forwardByRepeatedStatus
                                           ,ame_util2.reassignStatus
                                           ,ame_util.nullStatus
                                           ,ame_util.noResponseStatus
                                           ,ame_util2.noResponseByRepeatedStatus
                                           ,ame_util.repeatedStatus) into tempStatus from dual;
Line: 12555

            setInsertedApprovalStatus(currentApproverIndexIn => repeatedAppIndexes(z)
                                     ,approvalStatusIn => tempStatus);
Line: 12587

        update ame_temp_old_approver_lists
          set approval_status = ame_util.beatByFirstResponderStatus
          where
            application_id = ameApplicationId and
            transaction_id = transactionIdIn and
            (name <> approver.name or
             occurrence <> approver.occurrence) and
            item_class = approver.item_class and
            item_id = approver.item_id and
            action_type_id = approver.action_type_id and
            group_or_chain_id = approver.group_or_chain_id and
              approver_category = ame_util.approvalApproverCategory and
              approval_status = ame_util.notifiedStatus;
Line: 12609

            setInsertedApprovalStatus(currentApproverIndexIn => i
                                  ,approvalStatusIn => ame_util.beatByFirstResponderStatus);
Line: 12613

        /* Insert rows in the notification approval history region for approvers
           with beat by first responder */
        insertIntoTransApprovalHistory
          (transactionIdIn         => transactionIdIn
          ,applicationIdIn         => ameApplicationId
          ,orderNumberIn           => approver.approver_order_number
          ,nameIn                  => approver.name
          ,appCategoryIn           => null
          ,itemClassIn             => approver.item_class
          ,itemIdIn                => approver.item_id
          ,actionTypeIdIn          => approver.action_type_id
          ,authorityIn             => null
          ,statusIn                => null
          ,grpOrChainIdIn          => approver.group_or_chain_id
          ,occurrenceIn            => approver.occurrence
          ,apiInsertionIn          => approver.api_insertion
          ,memberOrderNumberIn     => approver.member_order_number
          ,notificationIdIn        => notificationIn.notification_id
          ,userCommentsIn          => null
          ,dateClearedIn           => null
          ,historyTypeIn           => 'BEATBYFIRSTRESPONDER');
Line: 12646

                  update ame_temp_old_approver_lists
                     set approval_status = ame_util.nullStatus
                   where application_id = ameApplicationId
                     and transaction_id = transactionIdIn
                     and name           = currentApprovers(x).name
                     and item_class        = currentApprovers(repeatedAppIndexes(z)).item_class
                     and item_id           = currentApprovers(repeatedAppIndexes(z)).item_id
                     and action_type_id    = currentApprovers(repeatedAppIndexes(z)).action_type_id
                     and group_or_chain_id = currentApprovers(repeatedAppIndexes(z)).group_or_chain_id
                     and occurrence        = currentApprovers(repeatedAppIndexes(z)).occurrence
                     and approval_status   = ame_util.notifiedByRepeatedStatus;
Line: 12658

                       setInsertedApprovalStatus(currentApproverIndexIn => repeatedAppIndexes(z)
                                  ,approvalStatusIn => ame_util.nullStatus);
Line: 12683

          tempInsertionOrder := ame_engine.getNextInsertionOrder;
Line: 12695

          insert into ame_temp_insertions(
              transaction_id,
              application_id,
              insertion_order,
              order_type,
              parameter,
              description,
              name,
              item_class,
              item_id,
              approver_category,
              api_insertion,
              authority,
              effective_date,
              reason) values(
                transactionIdIn,
                ameApplicationId,
                tempInsertionOrder,
                ame_util.afterApprover,
                tempParameter,
                ame_util.afterApproverDescription || approver.display_name,
                forwardee.name,
                forwardee.item_class,
                forwardee.item_id,
                forwardee.approver_category,
                decode(forwarderType,
                       ame_util.chainOfAuthorityForwarder, ame_util.apiAuthorityInsertion,
                       ame_util.apiInsertion),
                approver.authority,
                sysdate,
                ame_approver_deviation_pkg.reassignStatus );
Line: 12734

           approver.api_insertion = ame_util.apiInsertion) then
          forwarderType := ame_util.adHocForwarder;
Line: 12769

          tempInsertionOrder := ame_engine.getNextInsertionOrder;
Line: 12781

          insert into ame_temp_insertions(
              transaction_id,
              application_id,
              insertion_order,
              order_type,
              parameter,
              description,
              name,
              item_class,
              item_id,
              approver_category,
              api_insertion,
              authority,
              effective_date,
              reason) values(
                transactionIdIn,
                ameApplicationId,
                tempInsertionOrder,
                ame_util.afterApprover,
                tempParameter,
                ame_util.afterApproverDescription || approver.display_name,
                forwardee.name,
                forwardee.item_class,
                forwardee.item_id,
                forwardee.approver_category,
                decode(forwarderType,
                       ame_util.chainOfAuthorityForwarder, ame_util.apiAuthorityInsertion,
                       ame_util.apiInsertion),
                approver.authority,
                sysdate
                ,ame_approver_deviation_pkg.forwardReason );
Line: 12814

            All of the insertees generated within this if statement should have the same
            action_type_id and group_or_chain_id as approver.  The insertees' source
            should always be ame_util.specialForwardInsertion.  The insertions' order
            types should always be ame_util.afterApprover.
          */
          forwardingBehavior := ame_engine.getForwardingBehavior(forwarderTypeIn => forwarderType,
                                                                 forwardeeTypeIn => forwardeeType,
                                                                 approvalStatusIn => approver.approval_status);
Line: 12826

              Locate the start of the chain, so we can calculate each insertee's occurrence
              value, for use in the following insertee's insertion parameter.
            */
            for i in reverse 1 .. (approverInIndex - 1) loop
              if(currentApprovers(i).group_or_chain_id <> approver.group_or_chain_id or
                 currentApprovers(i).action_type_id <> approver.action_type_id or
                 currentApprovers(i).item_id <> approver.item_id or
                 currentApprovers(i).item_class <> approver.item_class) then
                firstIndexInChain := i + 1;
Line: 12845

            /* Insert forwardee as ad-hoc or COA, according to whether approverIn is ad-hoc or COA. */
            tempInsertionOrder := ame_engine.getNextInsertionOrder;
Line: 12858

            insert into ame_temp_insertions(
              transaction_id,
              application_id,
              insertion_order,
              order_type,
              parameter,
              description,
              name,
              item_class,
              item_id,
              approver_category,
              api_insertion,
              authority,
              special_forwardee,
              effective_date,
              reason) values(
                transactionIdIn,
                ameApplicationId,
                tempInsertionOrder,
                ame_util.afterApprover,
                tempParameter,
                ame_util.afterApproverDescription || approver.display_name,
                forwardee.name,
                forwardee.item_class,
                forwardee.item_id,
                ame_util.approvalApproverCategory, /* Forwarding is not possible from an FYI approver. */
                decode(forwarderType,
                       ame_util.chainOfAuthorityForwarder, ame_util.apiAuthorityInsertion,
                       ame_util.apiInsertion),
                approver.authority,
                ame_util.booleanTrue,
                sysdate,
                ame_approver_deviation_pkg.forwardReason);
Line: 12891

            if(forwardingBehavior = ame_util.forwarderAndForwardee) then /* Insert the forwarder. */
              tempInsertionOrder := ame_engine.getNextInsertionOrder;
Line: 12904

              insert into ame_temp_insertions(
                transaction_id,
                application_id,
                insertion_order,
                order_type,
                parameter,
                description,
                name,
                item_class,
                item_id,
                approver_category,
                api_insertion,
                authority,
                special_forwardee,
                effective_date,
                reason) values(
                  transactionIdIn,
                  ameApplicationId,
                  tempInsertionOrder,
                  ame_util.afterApprover,
                  tempParameter,
                  ame_util.afterApproverDescription || forwardee.display_name,
                  approver.name,
                  approver.item_class,
                  approver.item_id,
                  ame_util.approvalApproverCategory, /* Forwarding is not possible from an FYI approver. */
                  decode(forwarderType,
                         ame_util.chainOfAuthorityForwarder, ame_util.apiAuthorityInsertion,
                         ame_util.apiInsertion),
                  approver.authority,
                  ame_util.booleanTrue,
                  sysdate,
                  ame_approver_deviation_pkg.forwardForwardeeReason);
Line: 12942

              case we insert starting at the insertee, and ascending the hierarchy up to but not
              including approver.  In the case of ame_util.repeatForwarder, we then add
              approverIn and stop.  In the case of ame_util.skipForwarder, we then add
              approverIn's superior and stop.  The insertees are all COA approvers.
            */
            /* Insert the forwardee. */
            tempInsertionOrder := ame_engine.getNextInsertionOrder;
Line: 12960

            insert into ame_temp_insertions(
              transaction_id,
              application_id,
              insertion_order,
              order_type,
              parameter,
              description,
              name,
              item_class,
              item_id,
              approver_category,
              api_insertion,
              authority,
              special_forwardee,
              effective_date,
              reason) values(
                transactionIdIn,
                ameApplicationId,
                tempInsertionOrder,
                ame_util.afterApprover,
                tempParameter,
                ame_util.afterApproverDescription || approver.display_name,
                forwardee.name,
                forwardee.item_class,
                forwardee.item_id,
                ame_util.approvalApproverCategory, /* Forwarding is not possible from an FYI approver. */
                ame_util.apiAuthorityInsertion,
                ame_util.authorityApprover,
                ame_util.booleanTrue,
                sysdate,
                ame_approver_deviation_pkg.forwardReason);
Line: 12991

            insertedApprover.name := forwardee.name;
Line: 12992

            insertedApprover.orig_system := forwardee.orig_system;
Line: 12993

            insertedApprover.orig_system_id := forwardee.orig_system_id;
Line: 12994

            insertedApprover.item_class := forwardee.item_class;
Line: 12995

            insertedApprover.item_id := forwardee.item_id;
Line: 12996

            insertedApprover.action_type_id := forwardee.action_type_id;
Line: 12997

            insertedApprover.group_or_chain_id :=forwardee.group_or_chain_id;
Line: 12998

            insertedApprover.occurrence := forwardee.occurrence;
Line: 13002

              /* Get the next superior to insert. */
              tempReason := ame_approver_deviation_pkg.forwardEngInsReason;
Line: 13004

              ame_approver_type_pkg.getSuperior(approverIn => insertedApprover,
                                                superiorOut => superiorApprover);
Line: 13017

              /* Calculate insertedApprover.occurrence. */
              insertedApprover.occurrence := 1;
Line: 13020

                if(currentApprovers(i).name = insertedApprover.name) then
                  insertedApprover.occurrence := currentApprovers(i).occurrence + 1;
Line: 13025

              /* Prepare and do the insertion. */
              tempInsertionOrder := ame_engine.getNextInsertionOrder;
Line: 13027

              tempParameter := insertedApprover.name ||
                               ame_util.fieldDelimiter ||
                               insertedApprover.item_class ||
                               ame_util.fieldDelimiter ||
                               insertedApprover.item_id ||
                               ame_util.fieldDelimiter ||
                               insertedApprover.action_type_id ||
                               ame_util.fieldDelimiter ||
                               insertedApprover.group_or_chain_id ||
                               ame_util.fieldDelimiter ||
                               insertedApprover.occurrence;
Line: 13038

              insert into ame_temp_insertions(
                transaction_id,
                application_id,
                insertion_order,
                order_type,
                parameter,
                description,
                name,
                item_class,
                item_id,
                approver_category,
                api_insertion,
                authority,
                special_forwardee,
                effective_date,
                reason) values(
                  transactionIdIn,
                  ameApplicationId,
                  tempInsertionOrder,
                  ame_util.afterApprover,
                  tempParameter,
                  ame_util.afterApproverDescription || insertedApprover.display_name,
                  superiorApprover.name,
                  approver.item_class,
                  approver.item_id,
                  ame_util.approvalApproverCategory, /* Forwarding is not possible from an FYI approver. */
                  ame_util.apiAuthorityInsertion,
                  ame_util.authorityApprover,
                  ame_util.booleanTrue,
                  sysdate,
                  tempReason);
Line: 13072

              insertedApprover.name := superiorApprover.name;
Line: 13073

              insertedApprover.orig_system_id := superiorApprover.orig_system_id;
Line: 13079

              such cases, we insert starting with forwardeeIn and continuing up to and including
              approver.  The insertees are always ad-hoc, and pertain to the same item, sublist,
              action type, and group or chain as the forwarder.
            */
            for i in forwardeeIndex .. approverInIndex loop
              if(i = forwardeeIndex) then
                prevApproverIndex := approverInIndex;
Line: 13097

              tempInsertionOrder := ame_engine.getNextInsertionOrder;
Line: 13109

              insert into ame_temp_insertions(
                transaction_id,
                application_id,
                insertion_order,
                order_type,
                parameter,
                description,
                name,
                item_class,
                item_id,
                approver_category,
                api_insertion,
                authority,
                special_forwardee,
                effective_date,
                reason) values(
                  transactionIdIn,
                  ameApplicationId,
                  tempInsertionOrder,
                  ame_util.afterApprover,
                  tempParameter,
                  ame_util.afterApproverDescription || insertedApprover.display_name,
                  currentApprovers(i).name,
                  approver.item_class,
                  approver.item_id,
                  ame_util.approvalApproverCategory, /* Forwarding is not possible from an FYI approver. */
                  ame_util.apiInsertion,
                  approver.authority,
                  ame_util.booleanTrue,
                  sysdate,
                  ame_approver_deviation_pkg.forwardRemandReason);
Line: 13146

      ame_engine.updateTransactionState(isTestTransactionIn => false,
                                          isLocalTransactionIn => false,
                                          fetchConfigVarsIn => true,
                                          fetchOldApproversIn => true,
                                          fetchInsertionsIn => true,
                                          fetchDeletionsIn => true,
                                          fetchAttributeValuesIn => true,
                                          fetchInactiveAttValuesIn => false,
                                          processProductionActionsIn => false,
                                          processProductionRulesIn => false,
                                          updateCurrentApproverListIn => true,
                                          updateOldApproverListIn => true,
                                          processPrioritiesIn => true,
                                          prepareItemDataIn => false,
                                          prepareRuleIdsIn => false,
                                          prepareRuleDescsIn => false,
                                          transactionIdIn => transactionIdIn,
                                          ameApplicationIdIn => null,
                                          fndApplicationIdIn => applicationIdIn,
                                          transactionTypeIdIn => transactionTypeIn);
Line: 13190

                                    routineNameIn => 'updateApprovalStatus',
                                    exceptionNumberIn => errorCode,
                                    exceptionStringIn => errorMessage);
Line: 13195

        when apiInsertionException then
          ame_engine.unlockTransaction(fndApplicationIdIn => applicationIdIn,
                                       transactionIdIn => transactionIdIn,
                                       transactionTypeIdIn => transactionTypeIn);
Line: 13204

                                    routineNameIn => 'updateApprovalStatus',
                                    exceptionNumberIn => errorCode,
                                    exceptionStringIn => errorMessage);
Line: 13248

                                    routineNameIn => 'updateApprovalStatus',
                                    exceptionNumberIn => errorCode,
                                    exceptionStringIn => errorMessage);
Line: 13258

                                    routineNameIn => 'updateApprovalStatus',
                                    exceptionNumberIn => sqlcode,
                                    exceptionStringIn => sqlerrm);
Line: 13262

    end updateApprovalStatus;
Line: 13263

  procedure updateInsertions(indexIn in integer) as
    tempIndex integer;
Line: 13265

    approverInsertionOrder integer;
Line: 13266

    deletionInsertionOrder integer;
Line: 13268

      if engStInsertionIndexes.exists(indexIn) then
        deletionInsertionOrder := engStInsertionIndexes(indexIn);
Line: 13270

        tempIndex := engStInsertionIndexes.next(indexIn);
Line: 13271

        while engStInsertionIndexes.exists(tempIndex) loop
          approverInsertionOrder := engStInsertionIndexes(tempIndex);
Line: 13273

          if approverInsertionOrder > deletionInsertionOrder then
            update ame_temp_insertions
               set parameter = parameter - 1
             where insertion_order = approverInsertionOrder
               and application_id = engAmeApplicationId
               and transaction_id = engTransactionId
               and order_type = ame_util.absoluteOrder;
Line: 13281

          tempIndex := engStInsertionIndexes.next(tempIndex);
Line: 13284

    end updateInsertions;