DBA Data[Home] [Help]

APPS.WMS_TASK_DISPATCH_ENGINE SQL Statements

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

Line: 114

      insert into WMS_DISPATCH_TASKS_GTMP
        (
          grouping_document_type,
          grouping_document_number,
          grouping_source_type_id
        )
      values
        (
          p_grp_doc_type,
          p_grp_doc_num,
          p_grp_src_type_id
        );
Line: 152

      DELETE FROM WMS_DISPATCH_TASKS_GTMP
      WHERE GROUPING_DOCUMENT_NUMBER IN (SELECT * FROM TABLE(wms_picking_pkg.list_cartonization_id));
Line: 269

      Added condition in all the cursors selecting cycle count tasks to select
      only those tasks whose cycle count have not been disabled by entering
      an Inactive Date.
      Added the table mtl_cycle_count_headers in the FROM clause and joined with
      mtl_cycle_count_entries and checked for disable_date value with sysdate.
    */

    -- Cursor #1 for selecting the most optimal task
    -- 1. Sub is passed         (1)
    -- 2. Non cycle count tasks (1)
    -- 3. Cycle count tasks     (1)
    CURSOR l_curs_opt_task_111 IS
       SELECT DISTINCT
    qt.task_id task_num,
    qt.pick_slip,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status,  --bug 4310093
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          transaction_temp_id task_id,
          pick_slip_number pick_slip,
               cartonization_id,
          organization_id,
               subinventory_code,
          locator_id,
          move_order_line_id,
          transaction_type_id,
          transaction_action_id,
          transaction_source_id,
          transaction_source_type_id
        FROM mtl_material_transactions_temp mmtt
        WHERE wms_task_type IS NOT NULL
             AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                              parent_line_id, transaction_temp_id)
        AND Decode(transaction_source_type_id,
         2, l_so_allowed,
	 4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
         5, Decode(transaction_type_id, 35, l_wip_allowed),
         8, l_io_allowed,
         13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
	  --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )
        UNION ALL
        SELECT
          MIN(mcce.cycle_count_entry_id) task_id,
          TO_NUMBER(NULL) pick_slip,
          To_number(NULL) cartonization_id,
          mcce.organization_id,
          mcce.subinventory subinventory_code,
          mcce.locator_id,
          To_number(NULL) move_order_line_id,
               4 transaction_type_id,
          4 transaction_action_id,
          mcce.cycle_count_header_id transaction_source_id,
          9 transaction_source_type_id
        FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
        WHERE mcce.entry_status_code IN(1, 3)
          AND NVL(mcce.export_flag, 2) = 2
          -- bug 3972076
          --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
          AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
          AND NVL(mcch.disable_date,sysdate+1)> sysdate
          GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) qt,
       mtl_txn_request_lines mol,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status in ( 2,3) -- Queued and dispatched tasks only bug 4310093
    AND wdt.person_id = p_sign_on_emp_id
    AND wdt.organization_id = p_sign_on_org_id
    AND NVL(qt.cartonization_id, -999) = NVL(l_cartonization_id, NVL(qt.cartonization_id, -999))
    AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND qt.move_order_line_id = mol.line_id(+)
    AND qt.subinventory_code = p_sign_on_zone
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
    AND qt.locator_id = loc.inventory_location_id
       UNION ALL
       SELECT DISTINCT
    wdtv.task_id task_num,
    NVL(wdtv.pick_slip_number, -1) pick_slip,
    wdtv.wms_task_type_id,
    nvl(wdtv.task_priority, 0),
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    task_status,
         wdtv.transaction_type_id,
    wdtv.transaction_action_id,
    wdtv.transaction_source_id,
    wdtv.transaction_source_type_id
       FROM
    -- inlined wms_dispatchable_tasks_v, bug 2648133
    (SELECT
       transaction_temp_id task_id,
       standard_operation_id user_task_type_id,
       wms_task_type wms_task_type_id,
       organization_id,
       subinventory_code zone,
       locator_id,
       task_priority,
       revision,
       lot_number,
       transaction_uom,
       transaction_quantity,
       pick_rule_id,
       pick_slip_number,
       cartonization_id,
       inventory_item_id,
       move_order_line_id,
       1 task_status,
       transaction_type_id,
       transaction_action_id,
       transaction_source_id,
       transaction_source_type_id
     FROM mtl_material_transactions_temp mmtt
     WHERE wms_task_type IS NOT NULL
       AND transaction_status = 2
       AND(wms_task_status IS NULL OR wms_task_status = 1) --Added for task planning WB. bug#2651318
            AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                             parent_line_id, transaction_temp_id)
            AND Decode(transaction_source_type_id,
             2, l_so_allowed,
             4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
             5, Decode(transaction_type_id, 35, l_wip_allowed),
             8, l_io_allowed,
             13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
				    --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )

     UNION ALL
     SELECT
       MIN(mcce.cycle_count_entry_id) task_id,
       MIN(mcce.standard_operation_id) user_task_type_id,
       3 wms_task_type_id,
       mcce.organization_id,
       mcce.subinventory zone,
       mcce.locator_id,
       MIN(mcce.task_priority) task_priority,
       mcce.revision revision,
       MIN(mcce.lot_number) lot_number,
       '' transaction_uom,
       TO_NUMBER(NULL) transaction_quantity,
       TO_NUMBER(NULL) pick_rule_id,
       TO_NUMBER(NULL) pick_slip_number,
       TO_NUMBER(NULL) cartonization_id,
       mcce.inventory_item_id,
       TO_NUMBER(NULL) move_order_line_id,
       1 task_status,
       4 transaction_type_id,
       4 transaction_action_id,
       mcce.cycle_count_header_id transaction_source_id,
       9 transaction_source_type_id
     FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
     WHERE mcce.entry_status_code IN(1, 3)
       AND NVL(mcce.export_flag, 2) = 2
       -- bug 3972076
       --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
       AND mcce.cycle_count_header_id = mcch.cycle_count_header_id

     -----bug6903708---
      AND mcce.organization_id = mcch.organization_id
      AND mcch.organization_id = p_sign_on_org_id
      ---------------------------

       AND NVL(mcch.disable_date,sysdate+1)> sysdate
     GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv,
    -- inlined wms_person_resource_utt_v, bug 2648133
    (SELECT
       utt_emp.standard_operation_id standard_operation_id,
       utt_emp.resource_id role,
       utt_eqp.resource_id equipment,
       utt_emp.person_id emp_id,
       utt_eqp.inventory_item_id eqp_id,
       NULL eqp_srl  /* removed for bug 2095237 */
     FROM
       (SELECT
          x_utt_res1.standard_operation_id standard_operation_id,
          x_utt_res1.resource_id resource_id,
          x_emp_r.person_id
        FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
        WHERE x_utt_res1.resource_id = r1.resource_id
          AND r1.resource_type = 2
          AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp,
       (SELECT
          x_utt_res2.standard_operation_id standard_operation_id,
          x_utt_res2.resource_id,
          x_eqp_r.inventory_item_id
        FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
        WHERE x_utt_res2.resource_id = r2.resource_id
        AND r2.resource_type = 1
        AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
      WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v,
    mtl_item_locations loc,
    mtl_secondary_inventories sub,
    mtl_txn_request_lines mol,
    mtl_txn_request_headers moh
       WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
    AND wdtv.organization_id = p_sign_on_org_id
    AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
    AND wdtv.zone = p_sign_on_zone --  removed NVL, bug 2648133
    AND NVL(wdtv.cartonization_id, -999) = NVL(l_cartonization_id, NVL(wdtv.cartonization_id, -999))
    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
    AND wdtv.locator_id = loc.inventory_location_id(+)
    AND wdtv.zone = sub.secondary_inventory_name
    AND wdtv.organization_id = sub.organization_id
    AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
    AND moh.header_id(+) = mol.header_id
    AND Decode(Nvl(moh.move_order_type, -1),
          2, l_rep_allowed,
          1, l_mot_moi_allowed,
          -1, 1,
          1) = 1
    --AND Nvl(wdtv.pick_slip_number, -1) <> l_pick_slip -- bug 2832818
    -- bug 4358107
    AND NOT EXISTS
         ( SELECT 1
           FROM WMS_DISPATCH_TASKS_GTMP
           WHERE (p_task_method = 'DISCRETE'
                  and
                  grouping_document_number = wdtv.pick_slip_number
                 )
                 or
                 (
                  p_task_method = 'ORDERPICK'
                  and
                  grouping_document_number = wdtv.transaction_source_id
                  and
                  grouping_source_type_id = wdtv.transaction_source_type_id
                 )
                 or
                 (p_task_method = 'PICKBYLABEL'
                  and
                  grouping_document_number = wdtv.cartonization_id
                 )
		 or    --6598260   start
		 (    grouping_document_number = wdtv.cartonization_id
		      and
		      grouping_document_type = 'CARTON_TASK'
		 )     --6598260    end
         )
    -- bug 4358107
    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
         (SELECT NULL
          FROM mtl_material_transactions_temp mmtt
          WHERE mmtt.transaction_temp_id = wdtv.task_id
          AND mmtt.parent_line_id IS NOT NULL
               AND mmtt.parent_line_id <> mmtt.transaction_temp_id
          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
    AND NOT EXISTS -- exclude tasks already dispatched and queued
         (SELECT NULL
          FROM wms_dispatched_tasks wdt1
          WHERE wdt1.transaction_temp_id = wdtv.task_id
          AND wdt1.task_type = wdtv.wms_task_type_id)
    -- excluded skipped tasks
    AND wdtv.task_id NOT IN
         (SELECT wdtv.task_id
          FROM wms_skip_task_exceptions wste, mtl_parameters mp
          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
          AND wste.task_id = wdtv.task_id
          AND wste.organization_id = mp.organization_id)
         --J Addition
    AND wdtv.zone not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
                              )
       ORDER BY
    task_priority desc,
    batch_id,
    task_status DESC,
    sub_picking_order,
         loc_picking_order,
    distance,
    task_num;
Line: 604

       SELECT DISTINCT
    qt.task_id task_num,
    qt.pick_slip,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status,  --bug 4310093
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          transaction_temp_id task_id,
          pick_slip_number pick_slip,
               cartonization_id,
          organization_id,
               subinventory_code,
          locator_id,
          move_order_line_id,
          transaction_type_id,
          transaction_action_id,
          transaction_source_id,
          transaction_source_type_id
        FROM mtl_material_transactions_temp mmtt
        WHERE wms_task_type IS NOT NULL
             AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                              parent_line_id, transaction_temp_id)
        AND Decode(transaction_source_type_id,
         2, l_so_allowed,
         4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
         5, Decode(transaction_type_id, 35, l_wip_allowed),
         8, l_io_allowed,
         13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
				            --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )
) qt,
       mtl_txn_request_lines mol,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status = 2  --bug 6326482queued task only bug   -- Queued and dispatched tasks only bug 4310093
    AND wdt.person_id = p_sign_on_emp_id
    AND wdt.organization_id = p_sign_on_org_id
    AND NVL(qt.cartonization_id, -999) = NVL(l_cartonization_id, NVL(qt.cartonization_id, -999))
    AND NVL(e.equipment_id, -999) = NVL(l_q_sign_on_equipment_id, NVL(e.equipment_id, -999))--bug 6326482
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND qt.move_order_line_id = mol.line_id(+)
    AND qt.subinventory_code = p_sign_on_zone
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
         AND qt.locator_id = loc.inventory_location_id
	    UNION ALL
      --bug 6326482 for dispatched tasks
       SELECT DISTINCT
    qt.task_id task_num,
    qt.pick_slip,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status,
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          transaction_temp_id task_id,
	  wms_task_status task_status,--bug 6326482 added to know the previous state of dispatched tasks
          pick_slip_number pick_slip,
               cartonization_id,
          organization_id,
               subinventory_code,
          locator_id,
          move_order_line_id,
          transaction_type_id,
          transaction_action_id,
          transaction_source_id,
          transaction_source_type_id
        FROM mtl_material_transactions_temp mmtt
        WHERE wms_task_type IS NOT NULL
             AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                              parent_line_id, transaction_temp_id)
        AND Decode(transaction_source_type_id,
         2, l_so_allowed,
         4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5094839*/
         5, Decode(transaction_type_id, 35, l_wip_allowed),
         8, l_io_allowed,
         13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
				    --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )
) qt,
       mtl_txn_request_lines mol,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status = 3  -- bug  6326482 dispatched tasks
    AND wdt.person_id = p_sign_on_emp_id
    AND wdt.organization_id = p_sign_on_org_id
    AND NVL(qt.cartonization_id, -999) = NVL(l_cartonization_id, NVL(qt.cartonization_id, -999))
    --bug 6326482
    AND ((qt.task_status is NULL
    AND NVL(e.equipment_id, -999) = NVL(l_q_sign_on_equipment_id, NVL(e.equipment_id, -999)))
    or
    (qt.task_status = 1
    AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))))--bug 6326482
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND qt.move_order_line_id = mol.line_id(+)
    AND qt.subinventory_code = p_sign_on_zone
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
         AND qt.locator_id = loc.inventory_location_id
       UNION ALL
       SELECT DISTINCT
    wdtv.task_id task_num,
    NVL(wdtv.pick_slip_number, -1) pick_slip,
    wdtv.wms_task_type_id,
    nvl(wdtv.task_priority, 0),
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    task_status,
         wdtv.transaction_type_id,
    wdtv.transaction_action_id,
    wdtv.transaction_source_id,
    wdtv.transaction_source_type_id
       FROM
    -- inlined wms_dispatchable_tasks_v, bug 2648133
    (SELECT
       transaction_temp_id task_id,
       standard_operation_id user_task_type_id,
       wms_task_type wms_task_type_id,
       organization_id,
       subinventory_code zone,
       locator_id,
       task_priority,
       revision,
       lot_number,
       transaction_uom,
       transaction_quantity,
       pick_rule_id,
       pick_slip_number,
       cartonization_id,
       inventory_item_id,
       move_order_line_id,
       1 task_status,
       transaction_type_id,
       transaction_action_id,
       transaction_source_id,
       transaction_source_type_id
     FROM mtl_material_transactions_temp mmtt
     WHERE wms_task_type IS NOT NULL
       AND transaction_status = 2
       AND(wms_task_status IS NULL OR wms_task_status = 1) --Added for task planning WB. bug#2651318
            AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                             parent_line_id, transaction_temp_id)
            AND Decode(transaction_source_type_id,
             2, l_so_allowed,
             4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
             5, Decode(transaction_type_id, 35, l_wip_allowed),
             8, l_io_allowed,
             13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
    --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )
) wdtv,
    -- inlined wms_person_resource_utt_v, bug 2648133
    (SELECT
       utt_emp.standard_operation_id standard_operation_id,
       utt_emp.resource_id role,
       utt_eqp.resource_id equipment,
       utt_emp.person_id emp_id,
       utt_eqp.inventory_item_id eqp_id,
       NULL eqp_srl  /* removed for bug 2095237 */
     FROM
       (SELECT
          x_utt_res1.standard_operation_id standard_operation_id,
          x_utt_res1.resource_id resource_id,
          x_emp_r.person_id
        FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
        WHERE x_utt_res1.resource_id = r1.resource_id
          AND r1.resource_type = 2
          AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp,
       (SELECT
          x_utt_res2.standard_operation_id standard_operation_id,
          x_utt_res2.resource_id,
          x_eqp_r.inventory_item_id
        FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
        WHERE x_utt_res2.resource_id = r2.resource_id
        AND r2.resource_type = 1
        AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
     WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v,
    mtl_item_locations loc,
    mtl_secondary_inventories sub,
    mtl_txn_request_lines mol,
    mtl_txn_request_headers moh
       WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
    AND wdtv.organization_id = p_sign_on_org_id
    AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
    AND wdtv.zone = p_sign_on_zone --  removed NVL, bug 2648133
    AND NVL(wdtv.cartonization_id, -999) = NVL(l_cartonization_id, NVL(wdtv.cartonization_id, -999))
    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
    AND wdtv.locator_id = loc.inventory_location_id(+)
    AND wdtv.zone = sub.secondary_inventory_name
    AND wdtv.organization_id = sub.organization_id
    AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
    AND moh.header_id(+) = mol.header_id
    AND Decode(Nvl(moh.move_order_type, -1),
          2, l_rep_allowed,
          1, l_mot_moi_allowed,
          -1, 1,
          1) = 1
    --AND Nvl(wdtv.pick_slip_number, -1) <> l_pick_slip -- bug 2832818
    -- bug 4358107
    AND NOT EXISTS
         ( SELECT 1
           FROM WMS_DISPATCH_TASKS_GTMP
           WHERE (p_task_method = 'DISCRETE'
                  and
                  grouping_document_number = wdtv.pick_slip_number
                 )
                 or
                 (
                  p_task_method = 'ORDERPICK'
                  and
                  grouping_document_number = wdtv.transaction_source_id
                  and
                  grouping_source_type_id = wdtv.transaction_source_type_id
                 )
                 or
                 (p_task_method = 'PICKBYLABEL'
                  and
                  grouping_document_number = wdtv.cartonization_id
                 )
		 or    --6598260   start
		 (    grouping_document_number = wdtv.cartonization_id
		      and
		      grouping_document_type = 'CARTON_TASK'
		 )     --6598260    end
         )
    -- bug 4358107
    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
         (SELECT NULL
          FROM mtl_material_transactions_temp mmtt
          WHERE mmtt.transaction_temp_id = wdtv.task_id
          AND mmtt.parent_line_id IS NOT NULL
               AND mmtt.parent_line_id <> mmtt.transaction_temp_id
          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
    AND NOT EXISTS -- exclude tasks already dispatched and queued
         (SELECT NULL
          FROM wms_dispatched_tasks wdt1
          WHERE wdt1.transaction_temp_id = wdtv.task_id
          AND wdt1.task_type = wdtv.wms_task_type_id)
    -- excluded skipped tasks
    AND wdtv.task_id NOT IN
         (SELECT wdtv.task_id
          FROM wms_skip_task_exceptions wste, mtl_parameters mp
          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
          AND wste.task_id = wdtv.task_id
          AND wste.organization_id = mp.organization_id)
         --J Addition
    AND wdtv.zone not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
         )
       ORDER BY
    task_priority desc,
    batch_id,
    task_status DESC,
    sub_picking_order,
         loc_picking_order,
    distance,
    task_num;
Line: 953

       SELECT DISTINCT
    qt.task_id task_num,
    qt.pick_slip,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    To_number (NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status, --bug 4310093
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          MIN(mcce.cycle_count_entry_id) task_id,
          TO_NUMBER(NULL) pick_slip,
          To_number(NULL) cartonization_id,
          mcce.organization_id,
          mcce.subinventory subinventory_code,
          mcce.locator_id,
          To_number(NULL) move_order_line_id,
               4 transaction_type_id,
          4 transaction_action_id,
          mcce.cycle_count_header_id transaction_source_id,
          9 transaction_source_type_id
        FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
        WHERE mcce.entry_status_code IN(1, 3)
          AND NVL(mcce.export_flag, 2) = 2
          -- bug 3972076
          --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
          AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
      -----bug6903708---

      AND mcce.organization_id = mcch.organization_id
      AND mcch.organization_id = p_sign_on_org_id

        ---------------------------

          AND NVL(mcch.disable_date,sysdate+1)> sysdate
          GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) qt,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status in ( 2,3) -- Queued and dispatched tasks only bug 4310093
    AND wdt.person_id = p_sign_on_emp_id
    AND wdt.organization_id = p_sign_on_org_id
    AND NVL(qt.cartonization_id, -999) = NVL(l_cartonization_id, NVL(qt.cartonization_id, -999))
    AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = p_sign_on_zone
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
    AND qt.locator_id = loc.inventory_location_id
       UNION ALL
       SELECT DISTINCT
    wdtv.task_id task_num,
    NVL(wdtv.pick_slip_number, -1) pick_slip,
    wdtv.wms_task_type_id,
    nvl(wdtv.task_priority, 0),
    To_number(NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    task_status,
         wdtv.transaction_type_id,
    wdtv.transaction_action_id,
    wdtv.transaction_source_id,
    wdtv.transaction_source_type_id
       FROM
    -- inlined wms_dispatchable_tasks_v, bug 2648133
    (SELECT
       MIN(mcce.cycle_count_entry_id) task_id,
       MIN(mcce.standard_operation_id) user_task_type_id,
       3 wms_task_type_id,
       mcce.organization_id,
       mcce.subinventory zone,
       mcce.locator_id,
       MIN(mcce.task_priority) task_priority,
       mcce.revision revision,
       MIN(mcce.lot_number) lot_number,
       '' transaction_uom,
       TO_NUMBER(NULL) transaction_quantity,
       TO_NUMBER(NULL) pick_rule_id,
       TO_NUMBER(NULL) pick_slip_number,
       TO_NUMBER(NULL) cartonization_id,
       mcce.inventory_item_id,
       TO_NUMBER(NULL) move_order_line_id,
       1 task_status,
       4 transaction_type_id,
       4 transaction_action_id,
       mcce.cycle_count_header_id transaction_source_id,
       9 transaction_source_type_id
     FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
     WHERE mcce.entry_status_code IN(1, 3)
       AND NVL(mcce.export_flag, 2) = 2
       -- bug 3972076
       --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
       AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
      -----bug6903708---
      AND mcce.organization_id = mcch.organization_id
      AND mcch.organization_id = p_sign_on_org_id
        ---------------------------

       AND NVL(mcch.disable_date,sysdate+1)> sysdate
     GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv,
    -- inlined wms_person_resource_utt_v, bug 2648133
    (SELECT
       utt_emp.standard_operation_id standard_operation_id,
       utt_emp.resource_id role,
       utt_eqp.resource_id equipment,
       utt_emp.person_id emp_id,
       utt_eqp.inventory_item_id eqp_id,
       NULL eqp_srl  /* removed for bug 2095237 */
     FROM
       (SELECT
          x_utt_res1.standard_operation_id standard_operation_id,
          x_utt_res1.resource_id resource_id,
          x_emp_r.person_id
        FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
        WHERE x_utt_res1.resource_id = r1.resource_id
          AND r1.resource_type = 2
          AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp,
       (SELECT
          x_utt_res2.standard_operation_id standard_operation_id,
          x_utt_res2.resource_id,
          x_eqp_r.inventory_item_id
        FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
        WHERE x_utt_res2.resource_id = r2.resource_id
        AND r2.resource_type = 1
        AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
     WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v,
    mtl_item_locations loc,
    mtl_secondary_inventories sub
       WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
    AND wdtv.organization_id = p_sign_on_org_id
    AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
    AND wdtv.zone = p_sign_on_zone --  removed NVL, bug 2648133
    AND NVL(wdtv.cartonization_id, -999) = NVL(l_cartonization_id, NVL(wdtv.cartonization_id, -999))
    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
    AND wdtv.locator_id = loc.inventory_location_id(+)
    AND wdtv.zone = sub.secondary_inventory_name
    AND wdtv.organization_id = sub.organization_id
    --AND Nvl(wdtv.pick_slip_number, -1) <> l_pick_slip -- bug 2832818
    -- bug 4358107
    AND NOT EXISTS
         ( SELECT 1
           FROM WMS_DISPATCH_TASKS_GTMP
           WHERE (p_task_method = 'DISCRETE'
                  and
                  grouping_document_number = wdtv.pick_slip_number
                 )
                 or
                 (
                  p_task_method = 'ORDERPICK'
                  and
                  grouping_document_number = wdtv.transaction_source_id
                  and
                  grouping_source_type_id = wdtv.transaction_source_type_id
                 )
                 or
                 (p_task_method = 'PICKBYLABEL'
                  and
                  grouping_document_number = wdtv.cartonization_id
                 )
         )
    -- bug 4358107
    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
         (SELECT NULL
          FROM mtl_material_transactions_temp mmtt
          WHERE mmtt.transaction_temp_id = wdtv.task_id
          AND mmtt.parent_line_id IS NOT NULL
               AND mmtt.parent_line_id <> mmtt.transaction_temp_id
          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
    AND NOT EXISTS -- exclude tasks already dispatched and queued
         (SELECT NULL
          FROM wms_dispatched_tasks wdt1
          WHERE wdt1.transaction_temp_id = wdtv.task_id
          AND wdt1.task_type = wdtv.wms_task_type_id)
    -- excluded skipped tasks
    AND wdtv.task_id NOT IN
         (SELECT wdtv.task_id
          FROM wms_skip_task_exceptions wste, mtl_parameters mp
          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
          AND wste.task_id = wdtv.task_id
          AND wste.organization_id = mp.organization_id)
         --J Addition
             AND wdtv.zone not in (
                     SELECT wd.subinventory_code
                     FROM  wms_devices_b wd
                         , wms_bus_event_devices wbed
                     WHERE 1 = 1
                         and wd.device_id = wbed.device_id
                        AND wbed.organization_id = wd.organization_id
                        AND wd.enabled_flag   = 'Y'
                        AND wbed.enabled_flag = 'Y'
                        AND wbed.business_event_id = 10
                        AND wd.subinventory_code IS NOT NULL
                        AND wd.force_sign_on_flag = 'Y'
                        AND wd.device_id NOT IN (SELECT device_id
                                    FROM wms_device_assignment_temp
                                   WHERE employee_id = p_sign_on_emp_id)
                  )
       ORDER BY
    task_priority desc,
    task_status DESC,
    sub_picking_order,
         loc_picking_order,
    distance,
    task_num;
Line: 1184

       SELECT DISTINCT
    qt.task_id task_num,
    qt.pick_slip,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status,  --bug 4310093
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          transaction_temp_id task_id,
          pick_slip_number pick_slip,
               cartonization_id,
          organization_id,
               subinventory_code,
          locator_id,
          move_order_line_id,
          transaction_type_id,
          transaction_action_id,
          transaction_source_id,
          transaction_source_type_id
        FROM mtl_material_transactions_temp mmtt
        WHERE wms_task_type IS NOT NULL
             AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                              parent_line_id, transaction_temp_id)
        AND Decode(transaction_source_type_id,
         2, l_so_allowed,
	 4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
         5, Decode(transaction_type_id, 35, l_wip_allowed),
         8, l_io_allowed,
         13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
				    --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )

        UNION ALL
        SELECT
          MIN(mcce.cycle_count_entry_id) task_id,
          TO_NUMBER(NULL) pick_slip,
          To_number(NULL) cartonization_id,
          mcce.organization_id,
          mcce.subinventory subinventory_code,
          mcce.locator_id,
          To_number(NULL) move_order_line_id,
          4 transaction_type_id,
          4 transaction_action_id,
          mcce.cycle_count_header_id transaction_source_id,
          9 transaction_source_type_id
        FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
        WHERE mcce.entry_status_code IN(1, 3)
          AND NVL(mcce.export_flag, 2) = 2
          -- bug 3972076
          --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
          AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
           -----bug6903708---
          AND mcce.organization_id = mcch.organization_id
          AND mcch.organization_id = p_sign_on_org_id
          ---------------------------
          AND NVL(mcch.disable_date,sysdate+1)> sysdate
          GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) qt,
       mtl_txn_request_lines mol,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status in ( 2,3) -- Queued and dispatched tasks only bug 4310093
    AND wdt.person_id = p_sign_on_emp_id
    AND wdt.organization_id = p_sign_on_org_id
    AND NVL(qt.cartonization_id, -999) = NVL(l_cartonization_id, NVL(qt.cartonization_id, -999))
    AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND qt.move_order_line_id = mol.line_id(+)
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
    AND qt.locator_id = loc.inventory_location_id
       UNION ALL
       SELECT DISTINCT
    wdtv.task_id task_num,
    NVL(wdtv.pick_slip_number, -1) pick_slip,
    wdtv.wms_task_type_id,
    nvl(wdtv.task_priority, 0),
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    task_status,
         wdtv.transaction_type_id,
    wdtv.transaction_action_id,
    wdtv.transaction_source_id,
    wdtv.transaction_source_type_id
       FROM
    -- inlined wms_dispatchable_tasks_v, bug 2648133
    (SELECT
       transaction_temp_id task_id,
       standard_operation_id user_task_type_id,
       wms_task_type wms_task_type_id,
       organization_id,
       subinventory_code zone,
       locator_id,
       task_priority,
       revision,
       lot_number,
       transaction_uom,
       transaction_quantity,
       pick_rule_id,
       pick_slip_number,
       cartonization_id,
       inventory_item_id,
       move_order_line_id,
       1 task_status,
       transaction_type_id,
       transaction_action_id,
       transaction_source_id,
       transaction_source_type_id
     FROM mtl_material_transactions_temp mmtt
     WHERE wms_task_type IS NOT NULL
       AND transaction_status = 2
       AND(wms_task_status IS NULL OR wms_task_status = 1) --Added for task planning WB. bug#2651318
            AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                             parent_line_id, transaction_temp_id)
            AND Decode(transaction_source_type_id,
             2, l_so_allowed,
             4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
             5, Decode(transaction_type_id, 35, l_wip_allowed),
             8, l_io_allowed,
             13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
	--7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )

     UNION ALL
     SELECT
       MIN(mcce.cycle_count_entry_id) task_id,
       MIN(mcce.standard_operation_id) user_task_type_id,
       3 wms_task_type_id,
       mcce.organization_id,
       mcce.subinventory zone,
       mcce.locator_id,
       MIN(mcce.task_priority) task_priority,
       mcce.revision revision,
       MIN(mcce.lot_number) lot_number,
       '' transaction_uom,
       TO_NUMBER(NULL) transaction_quantity,
       TO_NUMBER(NULL) pick_rule_id,
       TO_NUMBER(NULL) pick_slip_number,
       TO_NUMBER(NULL) cartonization_id,
       mcce.inventory_item_id,
       TO_NUMBER(NULL) move_order_line_id,
       1 task_status,
       4 transaction_type_id,
       4 transaction_action_id,
       mcce.cycle_count_header_id transaction_source_id,
       9 transaction_source_type_id
     FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
     WHERE mcce.entry_status_code IN(1, 3)
       AND NVL(mcce.export_flag, 2) = 2
       -- bug 3972076
       --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
       AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
       AND NVL(mcch.disable_date,sysdate+1)> sysdate

      -----bug6903708---
      AND mcce.organization_id = mcch.organization_id
      AND mcch.organization_id = p_sign_on_org_id
       ---------------------------

     GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv,
    -- inlined wms_person_resource_utt_v, bug 2648133
    (SELECT
       utt_emp.standard_operation_id standard_operation_id,
       utt_emp.resource_id role,
       utt_eqp.resource_id equipment,
       utt_emp.person_id emp_id,
       utt_eqp.inventory_item_id eqp_id,
       NULL eqp_srl  /* removed for bug 2095237 */
     FROM
       (SELECT
          x_utt_res1.standard_operation_id standard_operation_id,
          x_utt_res1.resource_id resource_id,
          x_emp_r.person_id
        FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
        WHERE x_utt_res1.resource_id = r1.resource_id
          AND r1.resource_type = 2
          AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp,
       (SELECT
          x_utt_res2.standard_operation_id standard_operation_id,
          x_utt_res2.resource_id,
          x_eqp_r.inventory_item_id
        FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
        WHERE x_utt_res2.resource_id = r2.resource_id
        AND r2.resource_type = 1
        AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
     WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v,
    mtl_item_locations loc,
    mtl_secondary_inventories sub,
    mtl_txn_request_lines mol,
    mtl_txn_request_headers moh
       WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
    AND wdtv.organization_id = p_sign_on_org_id
    AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
    AND NVL(wdtv.cartonization_id, -999) = NVL(l_cartonization_id, NVL(wdtv.cartonization_id, -999))
    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
    AND wdtv.locator_id = loc.inventory_location_id(+)
    AND wdtv.zone = sub.secondary_inventory_name
    AND wdtv.organization_id = sub.organization_id
    AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
    AND moh.header_id(+) = mol.header_id
    AND Decode(Nvl(moh.move_order_type, -1),
          2, l_rep_allowed,
          1, l_mot_moi_allowed,
          -1, 1,
          1) = 1
    --AND Nvl(wdtv.pick_slip_number, -1) <> l_pick_slip -- bug 2832818
    -- bug 4358107
    AND NOT EXISTS
         ( SELECT 1
           FROM WMS_DISPATCH_TASKS_GTMP
           WHERE (p_task_method = 'DISCRETE'
                  and
                  grouping_document_number = wdtv.pick_slip_number
                 )
                 or
                 (
                  p_task_method = 'ORDERPICK'
                  and
                  grouping_document_number = wdtv.transaction_source_id
                  and
                  grouping_source_type_id = wdtv.transaction_source_type_id
                 )
                 or
                 (p_task_method = 'PICKBYLABEL'
                  and
                  grouping_document_number = wdtv.cartonization_id
                 )
		 or    --6598260   start
		 ( grouping_document_number = wdtv.cartonization_id
		   and
		   grouping_document_type = 'CARTON_TASK'
		 )    --6598260   end
         )
    -- bug 4358107
    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
         (SELECT NULL
          FROM mtl_material_transactions_temp mmtt
          WHERE mmtt.transaction_temp_id = wdtv.task_id
          AND mmtt.parent_line_id IS NOT NULL
               AND mmtt.parent_line_id <> mmtt.transaction_temp_id
          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
    AND NOT EXISTS -- exclude tasks already dispatched and queued
         (SELECT NULL
          FROM wms_dispatched_tasks wdt1
          WHERE wdt1.transaction_temp_id = wdtv.task_id
          AND wdt1.task_type = wdtv.wms_task_type_id)
    -- excluded skipped tasks
    AND wdtv.task_id NOT IN
         (SELECT wdtv.task_id
          FROM wms_skip_task_exceptions wste, mtl_parameters mp
          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
          AND wste.task_id = wdtv.task_id
          AND wste.organization_id = mp.organization_id)
         --J Addition
    AND wdtv.zone not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
    )

       ORDER BY
    task_priority desc,
    batch_id,
    task_status DESC,
    sub_picking_order,
         loc_picking_order,
    distance,
    task_num;
Line: 1511

       SELECT DISTINCT
    qt.task_id task_num,
    qt.pick_slip,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status,  --bug 4310093
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          transaction_temp_id task_id,
          pick_slip_number pick_slip,
               cartonization_id,
          organization_id,
               subinventory_code,
          locator_id,
          move_order_line_id,
          transaction_type_id,
          transaction_action_id,
          transaction_source_id,
          transaction_source_type_id
        FROM mtl_material_transactions_temp mmtt
        WHERE wms_task_type IS NOT NULL
             AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                              parent_line_id, transaction_temp_id)
        AND Decode(transaction_source_type_id,
         2, l_so_allowed,
         4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
         5, Decode(transaction_type_id, 35, l_wip_allowed),
         8, l_io_allowed,
         13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
 	         --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )
) qt,
       mtl_txn_request_lines mol,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status = 2 -- bug 6326482 queued tasks only-- Queued and dispatched tasks only bug 4310093
    AND wdt.person_id = p_sign_on_emp_id
    AND wdt.organization_id = p_sign_on_org_id
    AND NVL(qt.cartonization_id, -999) = NVL(l_cartonization_id, NVL(qt.cartonization_id, -999))
    AND NVL(e.equipment_id, -999) = NVL(l_q_sign_on_equipment_id, NVL(e.equipment_id, -999))
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND qt.move_order_line_id = mol.line_id(+)
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
    AND qt.locator_id = loc.inventory_location_id
     UNION ALL
       --bug 6326482 for dispatched tasks
       SELECT DISTINCT
    qt.task_id task_num,
    qt.pick_slip,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status,
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          transaction_temp_id task_id,
	  wms_task_status task_status, -- bug 6326482 added to get the previous state of dispatched tasks
          pick_slip_number pick_slip,
               cartonization_id,
          organization_id,
               subinventory_code,
          locator_id,
          move_order_line_id,
          transaction_type_id,
          transaction_action_id,
          transaction_source_id,
          transaction_source_type_id
        FROM mtl_material_transactions_temp mmtt
        WHERE wms_task_type IS NOT NULL
             AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                              parent_line_id, transaction_temp_id)
        AND Decode(transaction_source_type_id,
         2, l_so_allowed,
         4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5094839*/
         5, Decode(transaction_type_id, 35, l_wip_allowed),
         8, l_io_allowed,
         13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
    --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )
) qt,
       mtl_txn_request_lines mol,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status =3 -- bug 6326482 dispatched  tasks only
     AND wdt.person_id = p_sign_on_emp_id
    AND wdt.organization_id = p_sign_on_org_id
    AND NVL(qt.cartonization_id, -999) = NVL(l_cartonization_id, NVL(qt.cartonization_id, -999))
    --bug 6326482
  AND ((qt.task_status is NULL
    AND NVL(e.equipment_id, -999) = NVL(l_q_sign_on_equipment_id, NVL(e.equipment_id, -999)))
    or
    (qt.task_status = 1
    AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))))--bug 6326482
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND qt.move_order_line_id = mol.line_id(+)
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
    AND qt.locator_id = loc.inventory_location_id
       UNION ALL
       SELECT DISTINCT
    wdtv.task_id task_num,
    NVL(wdtv.pick_slip_number, -1) pick_slip,
    wdtv.wms_task_type_id,
    nvl(wdtv.task_priority, 0),
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    task_status,
         wdtv.transaction_type_id,
    wdtv.transaction_action_id,
    wdtv.transaction_source_id,
    wdtv.transaction_source_type_id
       FROM
    -- inlined wms_dispatchable_tasks_v, bug 2648133
    (SELECT
       transaction_temp_id task_id,
       standard_operation_id user_task_type_id,
       wms_task_type wms_task_type_id,
       organization_id,
       subinventory_code zone,
       locator_id,
       task_priority,
       revision,
       lot_number,
       transaction_uom,
       transaction_quantity,
       pick_rule_id,
       pick_slip_number,
       cartonization_id,
       inventory_item_id,
       move_order_line_id,
       1 task_status,
       transaction_type_id,
       transaction_action_id,
       transaction_source_id,
       transaction_source_type_id
     FROM mtl_material_transactions_temp mmtt
     WHERE wms_task_type IS NOT NULL
       AND transaction_status = 2
       AND(wms_task_status IS NULL OR wms_task_status = 1) --Added for task planning WB. bug#2651318
            AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                             parent_line_id, transaction_temp_id)
            AND Decode(transaction_source_type_id,
             2, l_so_allowed,
             4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
             5, Decode(transaction_type_id, 35, l_wip_allowed),
             8, l_io_allowed,
             13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
	--7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )
) wdtv,
    -- inlined wms_person_resource_utt_v, bug 2648133
    (SELECT
       utt_emp.standard_operation_id standard_operation_id,
       utt_emp.resource_id role,
       utt_eqp.resource_id equipment,
       utt_emp.person_id emp_id,
       utt_eqp.inventory_item_id eqp_id,
       NULL eqp_srl  /* removed for bug 2095237 */
     FROM
       (SELECT
          x_utt_res1.standard_operation_id standard_operation_id,
          x_utt_res1.resource_id resource_id,
          x_emp_r.person_id
        FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
        WHERE x_utt_res1.resource_id = r1.resource_id
          AND r1.resource_type = 2
          AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp,
       (SELECT
          x_utt_res2.standard_operation_id standard_operation_id,
          x_utt_res2.resource_id,
          x_eqp_r.inventory_item_id
        FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
        WHERE x_utt_res2.resource_id = r2.resource_id
        AND r2.resource_type = 1
        AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
     WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v,
    mtl_item_locations loc,
    mtl_secondary_inventories sub,
    mtl_txn_request_lines mol,
    mtl_txn_request_headers moh
       WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
    AND wdtv.organization_id = p_sign_on_org_id
    AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
    AND NVL(wdtv.cartonization_id, -999) = NVL(l_cartonization_id, NVL(wdtv.cartonization_id, -999))
    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
    AND wdtv.locator_id = loc.inventory_location_id(+)
    AND wdtv.zone = sub.secondary_inventory_name
    AND wdtv.organization_id = sub.organization_id
    AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
    AND moh.header_id(+) = mol.header_id
    AND Decode(Nvl(moh.move_order_type, -1),
          2, l_rep_allowed,
          1, l_mot_moi_allowed,
          -1, 1,
          1) = 1
    --AND Nvl(wdtv.pick_slip_number, -1) <> l_pick_slip -- bug 2832818
    -- bug 4358107
    AND NOT EXISTS
         ( SELECT 1
           FROM WMS_DISPATCH_TASKS_GTMP
           WHERE (p_task_method = 'DISCRETE'
                  and
                  grouping_document_number = wdtv.pick_slip_number
                 )
                 or
                 (
                  p_task_method = 'ORDERPICK'
                  and
                  grouping_document_number = wdtv.transaction_source_id
                  and
                  grouping_source_type_id = wdtv.transaction_source_type_id
                 )
                 or
                 (p_task_method = 'PICKBYLABEL'
                  and
                  grouping_document_number = wdtv.cartonization_id
                 )
		  or    --6598260   start
	         ( grouping_document_number = wdtv.cartonization_id
	           and
	           grouping_document_type = 'CARTON_TASK'
	         )     --6598260    end
         )
    -- bug 4358107
    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
         (SELECT NULL
          FROM mtl_material_transactions_temp mmtt
          WHERE mmtt.transaction_temp_id = wdtv.task_id
          AND mmtt.parent_line_id IS NOT NULL
               AND mmtt.parent_line_id <> mmtt.transaction_temp_id
          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
    AND NOT EXISTS -- exclude tasks already dispatched and queued
         (SELECT NULL
          FROM wms_dispatched_tasks wdt1
          WHERE wdt1.transaction_temp_id = wdtv.task_id
          AND wdt1.task_type = wdtv.wms_task_type_id)
    -- excluded skipped tasks
    AND wdtv.task_id NOT IN
         (SELECT wdtv.task_id
          FROM wms_skip_task_exceptions wste, mtl_parameters mp
          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
          AND wste.task_id = wdtv.task_id
          AND wste.organization_id = mp.organization_id)
         --J Addition
                AND wdtv.zone not in (
                        SELECT wd.subinventory_code
                        FROM  wms_devices_b wd
                            , wms_bus_event_devices wbed
                        WHERE 1 = 1
                            and wd.device_id = wbed.device_id
                           AND wbed.organization_id = wd.organization_id
                           AND wd.enabled_flag   = 'Y'
                           AND wbed.enabled_flag = 'Y'
                           AND wbed.business_event_id = 10
                           AND wd.subinventory_code IS NOT NULL
                           AND wd.force_sign_on_flag = 'Y'
                           AND wd.device_id NOT IN (SELECT device_id
                                       FROM wms_device_assignment_temp
                                      WHERE employee_id = p_sign_on_emp_id)
                     )
       ORDER BY
    task_priority desc,
    batch_id,
    task_status DESC,
    sub_picking_order,
         loc_picking_order,
    distance,
    task_num;
Line: 1857

       SELECT DISTINCT
    qt.task_id task_num,
    qt.pick_slip,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    To_number (NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status, --bug 4310093
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          MIN(mcce.cycle_count_entry_id) task_id,
          TO_NUMBER(NULL) pick_slip,
          To_number(NULL) cartonization_id,
          mcce.organization_id,
          mcce.subinventory subinventory_code,
          mcce.locator_id,
          To_number(NULL) move_order_line_id,
               4 transaction_type_id,
          4 transaction_action_id,
          mcce.cycle_count_header_id transaction_source_id,
          9 transaction_source_type_id
        FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
        WHERE mcce.entry_status_code IN(1, 3)
          AND NVL(mcce.export_flag, 2) = 2
          -- bug 3972076
          --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
          AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
          AND NVL(mcch.disable_date,sysdate+1)> sysdate
          GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) qt,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status in (2,3) -- Queued and dispatched tasks only bug 4310093
    AND wdt.person_id = p_sign_on_emp_id
    AND wdt.organization_id = p_sign_on_org_id
    AND NVL(qt.cartonization_id, -999) = NVL(l_cartonization_id, NVL(qt.cartonization_id, -999))
    AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
    AND qt.locator_id = loc.inventory_location_id
       UNION ALL
       SELECT DISTINCT
    wdtv.task_id task_num,
    NVL(wdtv.pick_slip_number, -1) pick_slip,
    wdtv.wms_task_type_id,
    nvl(wdtv.task_priority, 0),
    To_number(NULL) batch_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    task_status,
         wdtv.transaction_type_id,
    wdtv.transaction_action_id,
    wdtv.transaction_source_id,
    wdtv.transaction_source_type_id
       FROM
    -- inlined wms_dispatchable_tasks_v, bug 2648133
    (SELECT
       MIN(mcce.cycle_count_entry_id) task_id,
       MIN(mcce.standard_operation_id) user_task_type_id,
       3 wms_task_type_id,
       mcce.organization_id,
       mcce.subinventory zone,
       mcce.locator_id,
       MIN(mcce.task_priority) task_priority,
       mcce.revision revision,
       MIN(mcce.lot_number) lot_number,
       '' transaction_uom,
       TO_NUMBER(NULL) transaction_quantity,
       TO_NUMBER(NULL) pick_rule_id,
       TO_NUMBER(NULL) pick_slip_number,
       TO_NUMBER(NULL) cartonization_id,
       mcce.inventory_item_id,
       TO_NUMBER(NULL) move_order_line_id,
       1 task_status,
       4 transaction_type_id,
       4 transaction_action_id,
       mcce.cycle_count_header_id transaction_source_id,
       9 transaction_source_type_id
     FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
     WHERE mcce.entry_status_code IN(1, 3)
       AND NVL(mcce.export_flag, 2) = 2
       -- bug 3972076
       --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
       AND mcce.cycle_count_header_id = mcch.cycle_count_header_id

      -----bug6903708---
      AND mcce.organization_id = mcch.organization_id
      AND mcch.organization_id = p_sign_on_org_id
       ---------------------------

       AND NVL(mcch.disable_date,sysdate+1)> sysdate
     GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv,
    -- inlined wms_person_resource_utt_v, bug 2648133
    (SELECT
       utt_emp.standard_operation_id standard_operation_id,
       utt_emp.resource_id role,
       utt_eqp.resource_id equipment,
       utt_emp.person_id emp_id,
       utt_eqp.inventory_item_id eqp_id,
       NULL eqp_srl  /* removed for bug 2095237 */
     FROM
       (SELECT
          x_utt_res1.standard_operation_id standard_operation_id,
          x_utt_res1.resource_id resource_id,
          x_emp_r.person_id
        FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
        WHERE x_utt_res1.resource_id = r1.resource_id
          AND r1.resource_type = 2
          AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp,
       (SELECT
          x_utt_res2.standard_operation_id standard_operation_id,
          x_utt_res2.resource_id,
          x_eqp_r.inventory_item_id
        FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
        WHERE x_utt_res2.resource_id = r2.resource_id
        AND r2.resource_type = 1
        AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
     WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v,
    mtl_item_locations loc,
    mtl_secondary_inventories sub
       WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
    AND wdtv.organization_id = p_sign_on_org_id
    AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
    AND NVL(wdtv.cartonization_id, -999) = NVL(l_cartonization_id, NVL(wdtv.cartonization_id, -999))
    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
    AND wdtv.locator_id = loc.inventory_location_id(+)
    AND wdtv.zone = sub.secondary_inventory_name
    AND wdtv.organization_id = sub.organization_id
    --AND Nvl(wdtv.pick_slip_number, -1) <> l_pick_slip -- bug 2832818
    -- bug 4358107
    AND NOT EXISTS
         ( SELECT 1
           FROM WMS_DISPATCH_TASKS_GTMP
           WHERE (p_task_method = 'DISCRETE'
                  and
                  grouping_document_number = wdtv.pick_slip_number
                 )
                 or
                 (
                  p_task_method = 'ORDERPICK'
                  and
                  grouping_document_number = wdtv.transaction_source_id
                  and
                  grouping_source_type_id = wdtv.transaction_source_type_id
                 )
                 or
                 (p_task_method = 'PICKBYLABEL'
                  and
                  grouping_document_number = wdtv.cartonization_id
                 )
         )
    -- bug 4358107
    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
         (SELECT NULL
          FROM mtl_material_transactions_temp mmtt
          WHERE mmtt.transaction_temp_id = wdtv.task_id
          AND mmtt.parent_line_id IS NOT NULL
               AND mmtt.parent_line_id <> mmtt.transaction_temp_id
          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
    AND NOT EXISTS -- exclude tasks already dispatched and queued
         (SELECT NULL
          FROM wms_dispatched_tasks wdt1
          WHERE wdt1.transaction_temp_id = wdtv.task_id
          AND wdt1.task_type = wdtv.wms_task_type_id)
    -- excluded skipped tasks
    AND wdtv.task_id NOT IN
         (SELECT wdtv.task_id
          FROM wms_skip_task_exceptions wste, mtl_parameters mp
          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
          AND wste.task_id = wdtv.task_id
          AND wste.organization_id = mp.organization_id)
         --J Addition
    AND wdtv.zone not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
    )
       ORDER BY
    task_priority desc,
    task_status DESC,
    sub_picking_order,
         loc_picking_order,
    distance,
    task_num;
Line: 2083

       SELECT DISTINCT
    qt.task_id task_num,
    qt.subinventory_code,
    qt.locator_id,
    qt.pick_slip,
    qt.transaction_uom,
    qt.transaction_quantity,
    qt.lot_number,
    qt.operation_plan_id,
    qt.standard_operation_id,
    wdt.effective_start_date,
    wdt.effective_end_date,
    wdt.person_resource_id,
    wdt.machine_resource_id,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    mol.line_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status,  --bug 4310093
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          transaction_temp_id task_id,
          pick_slip_number pick_slip,
               cartonization_id,
          organization_id,
               subinventory_code,
          locator_id,
          inventory_item_id,
          revision,
          transaction_uom,
          transaction_quantity,
          lot_number,
          operation_plan_id,
          standard_operation_id,
          move_order_line_id,
          transaction_type_id,
          transaction_action_id,
          transaction_source_id,
          transaction_source_type_id
        FROM mtl_material_transactions_temp mmtt
        WHERE wms_task_type IS NOT NULL
             AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                              parent_line_id, transaction_temp_id)
        AND Decode(transaction_source_type_id,
         2, l_so_allowed,
         4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
         5, Decode(transaction_type_id, 35, l_wip_allowed),
         8, l_io_allowed,
         13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
  --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )


        UNION ALL
        SELECT
          MIN(mcce.cycle_count_entry_id) task_id,
          TO_NUMBER(NULL) pick_slip,
          To_number(NULL) cartonization_id,
          mcce.organization_id,
          mcce.subinventory subinventory_code,
          mcce.locator_id,
          mcce.inventory_item_id,
          mcce.revision,
          To_char(NULL) transaction_uom,
          To_number(NULL) transaction_quantity,
          MIN(mcce.lot_number) lot_number,
          To_number(NULL) operation_plan_id,
          MIN(mcce.standard_operation_id) standard_operation_id,
          To_number(NULL) move_order_line_id,
               4 transaction_type_id,
          4 transaction_action_id,
          mcce.cycle_count_header_id transaction_source_id,
          9 transaction_source_type_id
        FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
        WHERE mcce.entry_status_code IN(1, 3)
          AND NVL(mcce.export_flag, 2) = 2
          -- bug 3972076
          --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
          AND mcce.cycle_count_header_id = mcch.cycle_count_header_id

           -----bug6903708---
           AND mcce.organization_id = mcch.organization_id
           AND mcch.organization_id = p_sign_on_org_id
           ---------------------------

          AND NVL(mcch.disable_date,sysdate+1)> sysdate
          GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) qt,
       mtl_txn_request_lines mol,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status in ( 2,3) -- Queued and dispatched tasks only bug 4310093
    AND wdt.person_id = p_sign_on_emp_id
         AND wdt.organization_id = p_sign_on_org_id
    AND ((qt.pick_slip = v_pick_slip_number AND p_task_method = 'DISCRETE')
         OR (p_task_method IN ('MANUAL', 'WAVE', 'BULK', 'DISCRETE')
                  AND qt.task_id = v_task_id AND wdt.task_type = v_task_type)
         OR (p_task_method = 'ORDERPICK'
                  AND Decode(qt.transaction_source_type_id,
                             2, qt.transaction_source_id,
                             5, Decode(qt.transaction_type_id, 35, qt.transaction_source_id),
                             8, qt.transaction_source_id,
                             13, Decode(qt.transaction_type_id, 51, qt.transaction_source_id),
                             -1) = nvl(v_transaction_source_id, -1))
        OR (p_task_method = 'PICKBYLABEL' AND qt.cartonization_id = l_cartonization_id)
        OR (p_task_method = 'CLUSTERPICKBYLABEL' AND
            qt.cartonization_id IN (SELECT * FROM TABLE(wms_picking_pkg.list_cartonization_id))))
    -- Bug: 7254397
    AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND qt.move_order_line_id = mol.line_id(+)
    AND NVL(qt.subinventory_code, '@@@') = NVL(p_sign_on_zone, NVL(qt.subinventory_code, '@@@'))
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
    AND qt.locator_id = loc.inventory_location_id
       UNION ALL
       SELECT DISTINCT
    wdtv.task_id task_num,
    wdtv.subinventory_code,
    wdtv.locator_id,
    NVL(wdtv.pick_slip_number, -1) pick_slip,
    wdtv.transaction_uom,
    wdtv.transaction_quantity,
    wdtv.lot_number,
    wdtv.operation_plan_id,
    wdtv.user_task_type_id standard_operation_id,
    v.effective_start_date,
    v.effective_end_date,
    v.role person_resource_id,
    v.equipment machine_resource_id,
    wdtv.wms_task_type_id,
    nvl(wdtv.task_priority, 0),
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
         mol.line_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    task_status,
         wdtv.transaction_type_id,
    wdtv.transaction_action_id,
    wdtv.transaction_source_id,
    wdtv.transaction_source_type_id
       FROM
    -- inlined wms_dispatchable_tasks_v, bug 2648133
    (SELECT
       transaction_temp_id task_id,
       standard_operation_id user_task_type_id,
       wms_task_type wms_task_type_id,
       organization_id,
       subinventory_code,
       locator_id,
       task_priority,
       revision,
       lot_number,
       transaction_uom,
       transaction_quantity,
       pick_rule_id,
       pick_slip_number,
       cartonization_id,
       inventory_item_id,
       move_order_line_id,
       1 task_status,
       transaction_type_id,
       transaction_action_id,
       transaction_source_id,
       transaction_source_type_id,
       operation_plan_id
     FROM mtl_material_transactions_temp mmtt
     WHERE wms_task_type IS NOT NULL
       AND transaction_status = 2
       AND(wms_task_status IS NULL OR wms_task_status = 1) --Added for task planning WB. bug#2651318
            AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                             parent_line_id, transaction_temp_id)
            AND Decode(transaction_source_type_id,
             2, l_so_allowed,
             4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
             5, Decode(transaction_type_id, 35, l_wip_allowed),
             8, l_io_allowed,
             13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
				          --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )

     UNION ALL
     SELECT
       MIN(mcce.cycle_count_entry_id) task_id,
       MIN(mcce.standard_operation_id) user_task_type_id,
       3 wms_task_type_id,
       mcce.organization_id,
       mcce.subinventory subinventory_code,
       mcce.locator_id,
       MIN(mcce.task_priority) task_priority,
       mcce.revision revision,
       MIN(mcce.lot_number) lot_number,
       '' transaction_uom,
       TO_NUMBER(NULL) transaction_quantity,
       TO_NUMBER(NULL) pick_rule_id,
       TO_NUMBER(NULL) pick_slip_number,
       TO_NUMBER(NULL) cartonization_id,
       mcce.inventory_item_id,
       TO_NUMBER(NULL) move_order_line_id,
       1 task_status,
       4 transaction_type_id,
       4 transaction_action_id,
       mcce.cycle_count_header_id transaction_source_id,
       9 transaction_source_type_id,
       To_number(NULL) operation_plan_id
     FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
     WHERE mcce.entry_status_code IN(1, 3)
       AND NVL(mcce.export_flag, 2) = 2
       -- bug 3972076
       --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
       AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
        -----bug6903708---
       AND mcce.organization_id = mcch.organization_id
       AND mcch.organization_id = p_sign_on_org_id
        ---------------------------

       AND NVL(mcch.disable_date,sysdate+1)> sysdate
     GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv,
    -- inlined wms_person_resource_utt_v, bug 2648133
    (SELECT
       utt_emp.standard_operation_id standard_operation_id,
       utt_emp.resource_id role,
       utt_eqp.resource_id equipment,
       utt_emp.person_id emp_id,
       utt_emp.effective_start_date,
       utt_emp.effective_end_date,
       utt_eqp.inventory_item_id eqp_id,
       NULL eqp_srl  /* removed for bug 2095237 */
     FROM
       (SELECT
          x_utt_res1.standard_operation_id standard_operation_id,
          x_utt_res1.resource_id resource_id,
          x_emp_r.person_id,
          x_emp_r.effective_start_date,
               x_emp_r.effective_end_date
        FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
        WHERE x_utt_res1.resource_id = r1.resource_id
          AND r1.resource_type = 2
          AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp,
       (SELECT
          x_utt_res2.standard_operation_id standard_operation_id,
          x_utt_res2.resource_id,
          x_eqp_r.inventory_item_id
        FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
        WHERE x_utt_res2.resource_id = r2.resource_id
        AND r2.resource_type = 1
        AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
     WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v,
    mtl_item_locations loc,
    mtl_secondary_inventories sub,
    mtl_txn_request_lines mol,
    mtl_txn_request_headers moh
       WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
    AND ((wdtv.pick_slip_number = v_pick_slip_number AND p_task_method = 'DISCRETE')
         OR (p_task_method IN ('MANUAL', 'WAVE', 'BULK', 'DISCRETE')
                  AND wdtv.task_id = v_task_id AND wdtv.wms_task_type_id = v_task_type)
         OR (p_task_method = 'ORDERPICK'
                  AND Decode(wdtv.transaction_source_type_id,
                             2, wdtv.transaction_source_id,
                             5, Decode(wdtv.transaction_type_id, 35, wdtv.transaction_source_id),
                             8, wdtv.transaction_source_id,
                             13, Decode(wdtv.transaction_type_id, 51, wdtv.transaction_source_id),
                             -1) = nvl(v_transaction_source_id, -1))
        OR (p_task_method = 'PICKBYLABEL' AND wdtv.cartonization_id = l_cartonization_id)
        OR (p_task_method = 'CLUSTERPICKBYLABEL' AND
            wdtv.cartonization_id IN (SELECT * FROM TABLE(wms_picking_pkg.list_cartonization_id))))
    AND wdtv.organization_id = p_sign_on_org_id
    AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
    AND NVL(wdtv.subinventory_code, '@@@') = NVL(p_sign_on_zone, NVL(wdtv.subinventory_code, '@@@'))   AND NVL(wdtv.cartonization_id, -999) = NVL(l_cartonization_id, NVL(wdtv.cartonization_id, -999))
    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
    AND wdtv.locator_id = loc.inventory_location_id(+)
    AND wdtv.subinventory_code = sub.secondary_inventory_name
    AND wdtv.organization_id = sub.organization_id
    AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
    AND moh.header_id(+) = mol.header_id
    AND Decode(Nvl(moh.move_order_type, -1),
          2, l_rep_allowed,
          1, l_mot_moi_allowed,
          -1, 1,
          1) = 1
    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
         (SELECT NULL
          FROM mtl_material_transactions_temp mmtt
          WHERE mmtt.transaction_temp_id = wdtv.task_id
          AND mmtt.parent_line_id IS NOT NULL
               AND mmtt.parent_line_id <> mmtt.transaction_temp_id
          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
    AND NOT EXISTS -- exclude tasks already dispatched and queued
         (SELECT NULL
          FROM wms_dispatched_tasks wdt1
          WHERE wdt1.transaction_temp_id = wdtv.task_id
          AND wdt1.task_type = wdtv.wms_task_type_id)
    -- Bug 7254397: exclude tasks from locked cartons
    AND NOT EXISTS
        ( SELECT 1
           FROM WMS_DISPATCH_TASKS_GTMP
           WHERE p_task_method = 'CLUSTERPICKBYLABEL'
                AND
                  grouping_document_number = wdtv.cartonization_id)
    -- excluded skipped tasks
    AND wdtv.task_id NOT IN
         (SELECT wdtv.task_id
          FROM wms_skip_task_exceptions wste, mtl_parameters mp
          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
          AND wste.task_id = wdtv.task_id
          AND wste.organization_id = mp.organization_id)
         --J Addition
    AND wdtv.subinventory_code not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
    )
    ORDER BY
         sub_picking_order,
    loc_picking_order,
    distance,
    task_priority desc,
    batch_id,
    task_status DESC,
    task_num;
Line: 2463

       SELECT DISTINCT
    qt.task_id task_num,
    qt.subinventory_code,
    qt.locator_id,
    qt.pick_slip,
    qt.transaction_uom,
    qt.transaction_quantity,
    qt.lot_number,
    qt.operation_plan_id,
    qt.standard_operation_id,
    wdt.effective_start_date,
    wdt.effective_end_date,
    wdt.person_resource_id,
    wdt.machine_resource_id,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    mol.line_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status,  --bug 4310093
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          transaction_temp_id task_id,
          pick_slip_number pick_slip,
               cartonization_id,
          organization_id,
               subinventory_code,
          locator_id,
          inventory_item_id,
          revision,
          transaction_uom,
          transaction_quantity,
          lot_number,
          operation_plan_id,
          standard_operation_id,
          move_order_line_id,
          transaction_type_id,
          transaction_action_id,
          transaction_source_id,
          transaction_source_type_id
        FROM mtl_material_transactions_temp mmtt
        WHERE wms_task_type IS NOT NULL
             AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                              parent_line_id, transaction_temp_id)
        AND Decode(transaction_source_type_id,
         2, l_so_allowed,
	 4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
         5, Decode(transaction_type_id, 35, l_wip_allowed),
         8, l_io_allowed,
         13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
                      --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )
	       ) qt,
       mtl_txn_request_lines mol,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status = 2 --bug 6326482 queued task only -- Queued and dispatched  tasks only bug 4310093
    AND wdt.person_id = p_sign_on_emp_id
    AND wdt.organization_id = p_sign_on_org_id
    AND ((qt.pick_slip = v_pick_slip_number AND p_task_method = 'DISCRETE')
         OR (p_task_method IN ('MANUAL', 'WAVE', 'BULK', 'DISCRETE')
                  AND qt.task_id = v_task_id AND wdt.task_type = v_task_type)
              OR (p_task_method = 'ORDERPICK'
                  AND Decode(qt.transaction_source_type_id,
                             2, qt.transaction_source_id,
                             5, Decode(qt.transaction_type_id, 35, qt.transaction_source_id),
                             8, qt.transaction_source_id,
                             13, Decode(qt.transaction_type_id, 51, qt.transaction_source_id),
                             -1) = nvl(v_transaction_source_id, -1))
              OR (p_task_method = 'PICKBYLABEL' AND qt.cartonization_id = l_cartonization_id)
              OR (p_task_method = 'CLUSTERPICKBYLABEL' AND
           						 qt.cartonization_id IN (SELECT * FROM TABLE(wms_picking_pkg.list_cartonization_id))))
    AND NVL(e.equipment_id, -999) = NVL(l_q_sign_on_equipment_id, NVL(e.equipment_id, -999))--bug 6326482
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND qt.move_order_line_id = mol.line_id(+)
    AND NVL(qt.subinventory_code, '@@@') = NVL(p_sign_on_zone, NVL(qt.subinventory_code, '@@@'))
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
    AND qt.locator_id = loc.inventory_location_id
      UNION ALL
       --bug 6326482
      SELECT DISTINCT
    qt.task_id task_num,
    qt.subinventory_code,
    qt.locator_id,
    qt.pick_slip,
    qt.transaction_uom,
    qt.transaction_quantity,
    qt.lot_number,
    qt.operation_plan_id,
    qt.standard_operation_id,
    wdt.effective_start_date,
    wdt.effective_end_date,
    wdt.person_resource_id,
    wdt.machine_resource_id,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
    mol.line_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status,
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          transaction_temp_id task_id,
	  wms_task_status task_status, --bug 6326482 added to check for the previous state of dispatched tasks
          pick_slip_number pick_slip,
               cartonization_id,
          organization_id,
               subinventory_code,
          locator_id,
          inventory_item_id,
          revision,
          transaction_uom,
          transaction_quantity,
          lot_number,
          operation_plan_id,
          standard_operation_id,
          move_order_line_id,
          transaction_type_id,
          transaction_action_id,
          transaction_source_id,
          transaction_source_type_id
        FROM mtl_material_transactions_temp mmtt
        WHERE wms_task_type IS NOT NULL
             AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                              parent_line_id, transaction_temp_id)
        AND Decode(transaction_source_type_id,
         2, l_so_allowed,
         4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5094839*/
         5, Decode(transaction_type_id, 35, l_wip_allowed),
         8, l_io_allowed,
         13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
                    --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )
	       ) qt,
       mtl_txn_request_lines mol,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status = 3 -- bug 6326482 dispatched  tasks
    AND wdt.person_id = p_sign_on_emp_id
    AND wdt.organization_id = p_sign_on_org_id
    AND ((qt.pick_slip = v_pick_slip_number AND p_task_method = 'DISCRETE')
         OR (p_task_method IN ('MANUAL', 'WAVE', 'BULK', 'DISCRETE')
                  AND qt.task_id = v_task_id AND wdt.task_type = v_task_type)
              OR (p_task_method = 'ORDERPICK'
                  AND Decode(qt.transaction_source_type_id,
                             2, qt.transaction_source_id,
                             5, Decode(qt.transaction_type_id, 35, qt.transaction_source_id),
                             8, qt.transaction_source_id,
                             13, Decode(qt.transaction_type_id, 51, qt.transaction_source_id),
                             -1) = nvl(v_transaction_source_id, -1))
              OR (p_task_method = 'PICKBYLABEL' AND qt.cartonization_id = l_cartonization_id)
        OR (p_task_method = 'CLUSTERPICKBYLABEL' AND
            qt.cartonization_id IN (SELECT * FROM TABLE(wms_picking_pkg.list_cartonization_id))))
	     -- -bug 6326482
 AND ((qt.task_status is NULL
    AND NVL(e.equipment_id, -999) = NVL(l_q_sign_on_equipment_id, NVL(e.equipment_id, -999)))
    or
    (qt.task_status = 1
    AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))))--bug 6326482
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND qt.move_order_line_id = mol.line_id(+)
    AND NVL(qt.subinventory_code, '@@@') = NVL(p_sign_on_zone, NVL(qt.subinventory_code, '@@@'))
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
    AND qt.locator_id = loc.inventory_location_id
       UNION ALL
       SELECT DISTINCT
    wdtv.task_id task_num,
    wdtv.subinventory_code,
    wdtv.locator_id,
    NVL(wdtv.pick_slip_number, -1) pick_slip,
    wdtv.transaction_uom,
    wdtv.transaction_quantity,
    wdtv.lot_number,
    wdtv.operation_plan_id,
    wdtv.user_task_type_id standard_operation_id,
    v.effective_start_date,
    v.effective_end_date,
    v.role person_resource_id,
    v.equipment machine_resource_id,
    wdtv.wms_task_type_id,
    nvl(wdtv.task_priority, 0),
    Decode(l_sequence_picks_across_waves, 2, mol.header_id, NULL) batch_id,
         mol.line_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    task_status,
         wdtv.transaction_type_id,
    wdtv.transaction_action_id,
    wdtv.transaction_source_id,
    wdtv.transaction_source_type_id
       FROM
    -- inlined wms_dispatchable_tasks_v, bug 2648133
    (SELECT
       transaction_temp_id task_id,
       standard_operation_id user_task_type_id,
       wms_task_type wms_task_type_id,
       organization_id,
       subinventory_code,
       locator_id,
       task_priority,
       revision,
       lot_number,
       transaction_uom,
       transaction_quantity,
       pick_rule_id,
       pick_slip_number,
       cartonization_id,
       inventory_item_id,
       move_order_line_id,
       1 task_status,
       transaction_type_id,
       transaction_action_id,
       transaction_source_id,
       transaction_source_type_id,
       operation_plan_id
     FROM mtl_material_transactions_temp mmtt
     WHERE wms_task_type IS NOT NULL
       AND transaction_status = 2
       AND(wms_task_status IS NULL OR wms_task_status = 1) --Added for task planning WB. bug#2651318
            AND transaction_temp_id = Decode(p_task_method, 'BULK',
                                             parent_line_id, transaction_temp_id)
            AND Decode(transaction_source_type_id,
             2, l_so_allowed,
	     4, Decode(transaction_action_id, 1, l_moi_allowed, 2, decode(wms_task_type, 4, l_rep_allowed, l_mot_allowed)), /*Bug#5188179*/
             5, Decode(transaction_type_id, 35, l_wip_allowed),
             8, l_io_allowed,
             13, Decode(transaction_type_id,
                                   51, l_wip_allowed,
                                   Decode(transaction_action_id, 2, decode(wms_task_type, 4, l_rep_allowed)))) = 1
				    --7169220: USERS LOCKED
 	         AND (mmtt.cartonization_id is null
 	                                 or not exists
 	                                         (select 1 from mtl_material_transactions_temp mmtt1 ,wms_dispatched_tasks wdt1
 	                                         where mmtt1.transaction_temp_id <> mmtt.transaction_temp_id
 	                                         and wdt1.transaction_temp_id = mmtt1.transaction_temp_id
 	                                         and wdt1.status = 9
 	                                         and mmtt1.cartonization_id = mmtt.cartonization_id)
 	                                 )
	) wdtv,
    -- inlined wms_person_resource_utt_v, bug 2648133
    (SELECT
       utt_emp.standard_operation_id standard_operation_id,
       utt_emp.resource_id role,
       utt_eqp.resource_id equipment,
       utt_emp.person_id emp_id,
       utt_emp.effective_start_date,
       utt_emp.effective_end_date,
       utt_eqp.inventory_item_id eqp_id,
       NULL eqp_srl  /* removed for bug 2095237 */
     FROM
       (SELECT
          x_utt_res1.standard_operation_id standard_operation_id,
          x_utt_res1.resource_id resource_id,
          x_emp_r.person_id,
          x_emp_r.effective_start_date,
               x_emp_r.effective_end_date
        FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
        WHERE x_utt_res1.resource_id = r1.resource_id
          AND r1.resource_type = 2
          AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp,
       (SELECT
          x_utt_res2.standard_operation_id standard_operation_id,
          x_utt_res2.resource_id,
          x_eqp_r.inventory_item_id
        FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
        WHERE x_utt_res2.resource_id = r2.resource_id
        AND r2.resource_type = 1
        AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
     WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v,
    mtl_item_locations loc,
    mtl_secondary_inventories sub,
    mtl_txn_request_lines mol,
    mtl_txn_request_headers moh
       WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
    AND ((wdtv.pick_slip_number = v_pick_slip_number AND p_task_method = 'DISCRETE')
         OR (p_task_method IN ('MANUAL', 'WAVE', 'BULK', 'DISCRETE')
                  AND wdtv.task_id = v_task_id AND wdtv.wms_task_type_id = v_task_type)
              OR (p_task_method = 'ORDERPICK'
                  AND Decode(wdtv.transaction_source_type_id,
                             2, wdtv.transaction_source_id,
                             5, Decode(wdtv.transaction_type_id, 35, wdtv.transaction_source_id),
                             8, wdtv.transaction_source_id,
                             13, Decode(wdtv.transaction_type_id, 51, wdtv.transaction_source_id),
                             -1) = nvl(v_transaction_source_id, -1))
              OR (p_task_method = 'PICKBYLABEL' AND wdtv.cartonization_id = l_cartonization_id)
        OR (p_task_method = 'CLUSTERPICKBYLABEL' AND
            wdtv.cartonization_id IN (SELECT * FROM TABLE(wms_picking_pkg.list_cartonization_id))))
    AND wdtv.organization_id = p_sign_on_org_id
    AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
    AND NVL(wdtv.subinventory_code, '@@@') = NVL(p_sign_on_zone, NVL(wdtv.subinventory_code, '@@@'))
    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
    AND wdtv.locator_id = loc.inventory_location_id(+)
    AND wdtv.subinventory_code = sub.secondary_inventory_name
    AND wdtv.organization_id = sub.organization_id
    AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
    AND moh.header_id(+) = mol.header_id
    AND Decode(Nvl(moh.move_order_type, -1),
          2, l_rep_allowed,
          1, l_mot_moi_allowed,
          -1, 1,
          1) = 1
    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
         (SELECT NULL
          FROM mtl_material_transactions_temp mmtt
          WHERE mmtt.transaction_temp_id = wdtv.task_id
          AND mmtt.parent_line_id IS NOT NULL
               AND mmtt.parent_line_id <> mmtt.transaction_temp_id
          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
    AND NOT EXISTS -- exclude tasks already dispatched and queued
         (SELECT NULL
          FROM wms_dispatched_tasks wdt1
          WHERE wdt1.transaction_temp_id = wdtv.task_id
          AND wdt1.task_type = wdtv.wms_task_type_id)
    -- Bug 7254397: exclude tasks from locked cartons
    AND NOT EXISTS
        ( SELECT 1
           FROM WMS_DISPATCH_TASKS_GTMP
           WHERE p_task_method = 'CLUSTERPICKBYLABEL'
                AND
                  grouping_document_number = wdtv.cartonization_id)
    -- excluded skipped taskS
    AND wdtv.task_id NOT IN
         (SELECT wdtv.task_id
          FROM wms_skip_task_exceptions wste, mtl_parameters mp
          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
          AND wste.task_id = wdtv.task_id
          AND wste.organization_id = mp.organization_id)
         --J Addition
    AND wdtv.subinventory_code not in (
               SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
      )
       ORDER BY
    sub_picking_order,
    loc_picking_order,
    distance,
    task_priority desc,
    batch_id,
    task_status DESC,
    task_num;
Line: 2881

       SELECT DISTINCT
    qt.task_id task_num,
    qt.subinventory_code,
    qt.locator_id,
    qt.pick_slip,
    qt.transaction_uom,
    qt.transaction_quantity,
    qt.lot_number,
    qt.operation_plan_id,
    qt.standard_operation_id,
    wdt.effective_start_date,
    wdt.effective_end_date,
    wdt.person_resource_id,
    wdt.machine_resource_id,
    wdt.task_type wms_task_type_id,
    nvl(wdt.priority, 0) task_priority,
    To_number(NULL) batch_id,
    To_number(NULL) line_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    wdt.status task_status,  --bug 4310093
    qt.transaction_type_id,
    qt.transaction_action_id,
    qt.transaction_source_id,
    qt.transaction_source_type_id
       FROM wms_dispatched_tasks wdt,
            (SELECT
          MIN(mcce.cycle_count_entry_id) task_id,
          TO_NUMBER(NULL) pick_slip,
          To_number(NULL) cartonization_id,
          mcce.organization_id,
          mcce.subinventory subinventory_code,
          mcce.locator_id,
          mcce.inventory_item_id,
          mcce.revision,
          To_char(NULL) transaction_uom,
          To_number(NULL) transaction_quantity,
          MIN(mcce.lot_number) lot_number,
          To_number(NULL) operation_plan_id,
          MIN(mcce.standard_operation_id) standard_operation_id,
          To_number(NULL) move_order_line_id,
               4 transaction_type_id,
          4 transaction_action_id,
          mcce.cycle_count_header_id transaction_source_id,
          9 transaction_source_type_id
        FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
        WHERE mcce.entry_status_code IN(1, 3)
          AND NVL(mcce.export_flag, 2) = 2
          -- bug 3972076
          --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
          AND mcce.cycle_count_header_id = mcch.cycle_count_header_id

           -----bug6903708---
           AND mcce.organization_id = mcch.organization_id
           AND mcch.organization_id = p_sign_on_org_id
            ---------------------------

          AND NVL(mcch.disable_date,sysdate+1)> sysdate
          GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) qt,
       mtl_secondary_inventories sub,
       mtl_item_locations loc,
       (SELECT
          bsor.standard_operation_id,
          bre.resource_id,
          bre.inventory_item_id equipment_id
        FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
        WHERE bsor.resource_id = bre.resource_id
        AND br.resource_type = 1
        AND bsor.resource_id = br.resource_id) e
       WHERE wdt.transaction_temp_id = qt.task_id
    AND wdt.status in ( 2,3) -- Queued and dispatched tasks only bug 4310093
    AND wdt.person_id = p_sign_on_emp_id
    AND wdt.organization_id = p_sign_on_org_id
    AND (qt.task_id = v_task_id AND wdt.task_type = v_task_type)
    AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
    AND wdt.user_task_type = e.standard_operation_id(+)
    AND NVL(qt.subinventory_code, '@@@') = NVL(p_sign_on_zone, NVL(qt.subinventory_code, '@@@'))
    AND qt.organization_id = sub.organization_id
    AND qt.subinventory_code = sub.secondary_inventory_name
    AND qt.organization_id = loc.organization_id
    AND qt.locator_id = loc.inventory_location_id
       UNION ALL
       SELECT DISTINCT
    wdtv.task_id task_num,
    wdtv.subinventory_code,
    wdtv.locator_id,
    NVL(wdtv.pick_slip_number, -1) pick_slip,
    wdtv.transaction_uom,
    wdtv.transaction_quantity,
    wdtv.lot_number,
    wdtv.operation_plan_id,
    wdtv.user_task_type_id standard_operation_id,
    v.effective_start_date,
    v.effective_end_date,
    v.role person_resource_id,
    v.equipment machine_resource_id,
    wdtv.wms_task_type_id,
    nvl(wdtv.task_priority, 0),
    To_number(NULL) batch_id,
    To_number(NULL) line_id,
    sub.picking_order sub_picking_order,
    loc.picking_order loc_picking_order,
    ((nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x) +
     (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y) +
     (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)) distance,
    task_status,
         wdtv.transaction_type_id,
    wdtv.transaction_action_id,
    wdtv.transaction_source_id,
    wdtv.transaction_source_type_id
       FROM
    -- inlined wms_dispatchable_tasks_v, bug 2648133
    (SELECT
       MIN(mcce.cycle_count_entry_id) task_id,
       MIN(mcce.standard_operation_id) user_task_type_id,
       3 wms_task_type_id,
       mcce.organization_id,
       mcce.subinventory subinventory_code,
       mcce.locator_id,
       MIN(task_priority) task_priority,
       mcce.revision revision,
       MIN(mcce.lot_number) lot_number,
       '' transaction_uom,
       TO_NUMBER(NULL) transaction_quantity,
       TO_NUMBER(NULL) pick_rule_id,
       TO_NUMBER(NULL) pick_slip_number,
       TO_NUMBER(NULL) cartonization_id,
       mcce.inventory_item_id,
       TO_NUMBER(NULL) move_order_line_id,
       1 task_status,
       4 transaction_type_id,
       4 transaction_action_id,
       mcce.cycle_count_header_id transaction_source_id,
       9 transaction_source_type_id,
       To_number(NULL) operation_plan_id
     FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
     WHERE mcce.entry_status_code IN(1, 3)
       AND NVL(mcce.export_flag, 2) = 2
       -- bug 3972076
       --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
       AND mcce.cycle_count_header_id = mcch.cycle_count_header_id

        -----bug6903708---
        AND mcce.organization_id = mcch.organization_id
        AND mcch.organization_id = p_sign_on_org_id
        ---------------------------

       AND NVL(mcch.disable_date,sysdate+1)> sysdate
     GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv,
    -- inlined wms_person_resource_utt_v, bug 2648133
    (SELECT
       utt_emp.standard_operation_id standard_operation_id,
       utt_emp.resource_id role,
       utt_eqp.resource_id equipment,
       utt_emp.person_id emp_id,
       utt_emp.effective_start_date,
       utt_emp.effective_end_date,
       utt_eqp.inventory_item_id eqp_id,
       NULL eqp_srl  /* removed for bug 2095237 */
     FROM
       (SELECT
          x_utt_res1.standard_operation_id standard_operation_id,
          x_utt_res1.resource_id resource_id,
          x_emp_r.person_id,
          x_emp_r.effective_start_date,
               x_emp_r.effective_end_date
        FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
        WHERE x_utt_res1.resource_id = r1.resource_id
          AND r1.resource_type = 2
          AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp,
       (SELECT
          x_utt_res2.standard_operation_id standard_operation_id,
          x_utt_res2.resource_id,
          x_eqp_r.inventory_item_id
        FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
        WHERE x_utt_res2.resource_id = r2.resource_id
        AND r2.resource_type = 1
        AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
     WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v,
    mtl_item_locations loc,
    mtl_secondary_inventories sub
       WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
    AND (wdtv.task_id = v_task_id AND wdtv.wms_task_type_id = v_task_type)
    AND wdtv.organization_id = p_sign_on_org_id
    AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
    AND NVL(wdtv.subinventory_code, '@@@') = NVL(p_sign_on_zone, NVL(wdtv.subinventory_code, '@@@'))
    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
    AND wdtv.locator_id = loc.inventory_location_id(+)
    AND wdtv.subinventory_code = sub.secondary_inventory_name
    AND wdtv.organization_id = sub.organization_id
    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
         (SELECT NULL
          FROM mtl_material_transactions_temp mmtt
          WHERE mmtt.transaction_temp_id = wdtv.task_id
          AND mmtt.parent_line_id IS NOT NULL
               AND mmtt.parent_line_id <> mmtt.transaction_temp_id
          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
    AND NOT EXISTS -- exclude tasks already dispatched and queued
         (SELECT NULL
          FROM wms_dispatched_tasks wdt1
          WHERE wdt1.transaction_temp_id = wdtv.task_id
          AND wdt1.task_type = wdtv.wms_task_type_id)
    -- excluded skipped tasks
    AND wdtv.task_id NOT IN
         (SELECT wdtv.task_id
          FROM wms_skip_task_exceptions wste, mtl_parameters mp
          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
          AND wste.task_id = wdtv.task_id
          AND wste.organization_id = mp.organization_id)
         --J Addition
    AND wdtv.subinventory_code not in (
         SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
      )
       ORDER BY
         sub_picking_order,
    loc_picking_order,
    distance,
    task_priority desc,
    batch_id,
    task_status DESC,
    task_num;
Line: 3121

      SELECT transaction_temp_id
   FROM mtl_material_transactions_temp
   WHERE transaction_temp_id = v_transaction_temp_id
   FOR UPDATE nowait;
Line: 3127

      SELECT transaction_temp_id
   FROM mtl_material_transactions_temp
   WHERE pick_slip_number = v_pick_slip_number
   AND NVL(subinventory_code, '@@@') = NVL(p_sign_on_zone, NVL(subinventory_code, '@@@'))
   FOR UPDATE nowait;
Line: 3137

      SELECT transaction_temp_id
   FROM mtl_material_transactions_temp
   WHERE transaction_source_id = v_order_header_id
   AND transaction_source_type_id = v_transaction_source_type_id
   AND transaction_action_id = v_transaction_action_id
   AND transaction_type_id = v_transaction_type_id
   AND NVL(subinventory_code, '@@@') = NVL(p_sign_on_zone, NVL(subinventory_code, '@@@'))
   FOR UPDATE nowait;
Line: 3147

      SELECT transaction_temp_id
   FROM mtl_material_transactions_temp
   WHERE cartonization_id = v_cartonization_id
   AND NVL(subinventory_code, '@@@') = NVL(p_sign_on_zone, NVL(subinventory_code, '@@@'))
   FOR UPDATE nowait;
Line: 3154

      SELECT cycle_count_entry_id
   FROM mtl_cycle_count_entries
   WHERE cycle_count_entry_id = v_cycle_count_entry_id
   FOR UPDATE nowait;
Line: 3160

      SELECT task_filter_source, task_filter_value
        FROM wms_task_filter_b wtf, wms_task_filter_dtl wtfd
        WHERE task_filter_name = v_filter_name
        AND wtf.task_filter_id = wtfd.task_filter_id;
Line: 3166

      SELECT column_value LPN_ID FROM TABLE(wms_picking_pkg.list_cartonization_id);
Line: 3290

    SELECT transaction_temp_id, task_type, loaded_time
    INTO l_last_loaded_task_id, l_last_loaded_task_type, l_last_loaded_time
    FROM (SELECT transaction_temp_id, task_type, loaded_time
          FROM wms_dispatched_tasks wdt
          WHERE wdt.person_id = p_sign_on_emp_id
          AND wdt.loaded_time = (SELECT MAX(loaded_time)
                  FROM wms_dispatched_tasks
                  WHERE person_id = p_sign_on_emp_id))
    WHERE ROWNUM = 1; -- make sure only one task selected
Line: 3316

       SELECT transaction_id, task_type, loaded_time
    INTO l_last_dropoff_task_id, l_last_dropoff_task_type, l_last_dropoff_time
    FROM (SELECT transaction_id, task_type, loaded_time
          FROM wms_dispatched_tasks_history wdth
          WHERE wdth.person_id = p_sign_on_emp_id
          AND wdth.drop_off_time = (SELECT MAX(drop_off_time)
                FROM wms_dispatched_tasks_history
                WHERE person_id = p_sign_on_emp_id))
    WHERE ROWNUM = 1; -- make sure only one task selected
Line: 3367

        SELECT NVL(loc.x_coordinate, 0), NVL(loc.y_coordinate, 0), NVL(loc.z_coordinate, 0)
          INTO l_cur_x, l_cur_y, l_cur_z
          FROM mtl_item_locations loc,
               (SELECT
           transaction_temp_id task_id,
           standard_operation_id user_task_type_id,
           wms_task_type wms_task_type_id,
           organization_id organization_id,
           subinventory_code zone,
           locator_id locator_id,
           task_priority task_priority,
           revision revision,
           lot_number lot_number,
           transaction_uom transaction_uom,
           transaction_quantity transaction_quantity,
           pick_rule_id pick_rule_id,
           pick_slip_number pick_slip_number,
           cartonization_id cartonization_id,
           inventory_item_id,
           move_order_line_id
           FROM mtl_material_transactions_temp
           WHERE wms_task_type IS NOT NULL
           AND transaction_status = 2
           UNION ALL
           SELECT
           MIN(cycle_count_entry_id) task_id,
           MIN(standard_operation_id) user_task_type_id,
           3 wms_task_type_id,
           organization_id organization_id,
           subinventory zone,
           locator_id locator_id,
           MIN(task_priority) task_priority,
           revision revision,
             MIN(lot_number) lot_number,
             '' transaction_uom,
             TO_NUMBER(NULL) transaction_quantity,
             TO_NUMBER(NULL) pick_rule_id,
             TO_NUMBER(NULL) pick_slip_number,
             TO_NUMBER(NULL) cartonization_id,
            inventory_item_id,
             TO_NUMBER(NULL) move_order_line_id
             FROM mtl_cycle_count_entries
            WHERE  entry_status_code IN(1, 3)
             AND  NVL(export_flag, 2) = 2
             -- bug 3972076
             --AND  NVL(TRUNC(count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
             GROUP BY  cycle_count_header_id, organization_id, subinventory, locator_id, inventory_item_id, revision) wdtv -- inlined wms_dispatchable_tasks_v, bug 2648133
          WHERE wdtv.locator_id = loc.inventory_location_id
       AND wdtv.organization_id = loc.organization_id
       AND wdtv.task_id = l_last_task_id
       AND wdtv.wms_task_type_id = l_last_task_type;
Line: 3438

              SELECT NVL(loc.x_coordinate, 0)
                   , NVL(loc.y_coordinate, 0)
                   , NVL(loc.z_coordinate, 0)
                INTO l_cur_x
                   , l_cur_y
                   , l_cur_z
                FROM mtl_item_locations loc, mtl_material_transactions mmt
               WHERE mmt.locator_id = loc.inventory_location_id
                 AND mmt.organization_id = loc.organization_id
                 AND mmt.transaction_set_id = l_last_task_id
                 AND ROWNUM = 1;
Line: 3464

              SELECT NVL(loc.x_coordinate, 0)
                   , NVL(loc.y_coordinate, 0)
                   , NVL(loc.z_coordinate, 0)
                INTO l_cur_x
                   , l_cur_y
                   , l_cur_z
                FROM mtl_item_locations loc, mtl_cycle_count_entries mcce
               WHERE mcce.locator_id = loc.inventory_location_id
                 AND mcce.organization_id = loc.organization_id
                 AND mcce.cycle_count_entry_id = l_last_task_id;
Line: 3925

                SELECT cartonization_id INTO l_lpn_id
                FROM   mtl_material_transactions_temp mmtt
                WHERE  mmtt.transaction_temp_id=  l_task_id;
Line: 3939

                         SELECT count(1) INTO l_wdt_count  FROM  wms_dispatched_tasks wdt, mtl_material_transactions_temp mmtt
                          WHERE mmtt.cartonization_id = l_lpn_id
                           AND wdt.transaction_temp_id = mmtt.transaction_temp_id
                           AND wdt.status in(3,9)   AND wdt.person_id <>  p_sign_on_emp_id ;
Line: 4172

       INSERT INTO wms_ordered_tasks
    (task_id,
     wms_task_type,
     task_sequence_id,
     subinventory_code,
     locator_id,
     revision,
     transaction_uom,
     transaction_quantity,
     lot_number,
     priority,
     operation_plan_id,
     standard_operation_id,
     effective_start_date,
     effective_end_date,
     person_resource_id,
     machine_resource_id,
     move_order_line_id)
    VALUES
    (l_task_id,
     l_task_type_id,
     l_ordered_tasks_count,
     l_subinventory_code,
     l_locator_id,
     l_revision,
     l_transaction_uom,
     l_transaction_quantity,
     l_lot_number,
     l_task_priority,
     l_operation_plan_id,
     l_standard_operation_id,
     l_effective_start_date,
     l_effective_end_date,
     l_person_resource_id,
     l_machine_resource_id,
     l_move_order_line_id);
Line: 4259

      SELECT
     task_id,
     subinventory_code,
     locator_id,
          revision,
          transaction_uom,
          transaction_quantity,
          lot_number,
          wms_task_type,
     priority,
     operation_plan_id,
     standard_operation_id,
     effective_start_date,
     effective_end_date,
     person_resource_id,
     machine_resource_id,
     move_order_line_id
      FROM wms_ordered_tasks
      ORDER BY task_sequence_id;
Line: 4402

      Added condition in all the cursors selecting cycle count tasks to select
      only those tasks whose cycle count have not been disabled by entering
      an Inactive Date.
      Added the table mtl_cycle_count_headers in the FROM clause and joined with
      mtl_cycle_count_entries and checked for disable_date value with sysdate.
    */

    -- Cursor # 1 for selecting the most optimal task
    -- 1. sub is passed  (1)
    -- 2. order by across wave (1)
    -- 3. not express pick (0)

    CURSOR l_curs_opt_task_110 IS
      SELECT DISTINCT wdtv.task_id task_id
                    , NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                            AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
                            AND NVL(mcch.disable_date,sysdate+1)> sysdate
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND wdtv.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
        AND Nvl(wdtv.pick_slip_number, -1) <> l_opt_task_pick_slip -- bug 2832818
        AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
             --J Addition
                   AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
         )
      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
                    , wdtv.task_id;
Line: 4567

      SELECT DISTINCT wdtv.task_id task_id
                    , -- added distinct for bug 2657909
                      NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , -- added following because of distinct for bug 2657909
                      mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                            AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
                            AND NVL(mcch.disable_date,sysdate+1)> sysdate
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                --    mtl_system_items msi    -- bug 2648133
      WHERE           v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND wdtv.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
           AND Nvl(wdtv.pick_slip_number, -1) <> l_opt_task_pick_slip -- bug 2832818
            AND wms_express_pick_task.is_express_pick_task_eligible(wdtv.task_id) = 'S'
                  AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
             --J Addition
                   AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
            )
      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
                    , wdtv.task_id;
Line: 4723

      SELECT DISTINCT wdtv.task_id task_id
                    , -- added distinct for bug 2657909
                      NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , -- added following because of distinct for bug 2657909
                      mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                            AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
                            AND NVL(mcch.disable_date,sysdate+1)> sysdate
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
        AND Nvl(wdtv.pick_slip_number, -1) <> l_opt_task_pick_slip -- bug 2832818
              AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
            --J Addition
                   AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
         )
      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
                    , wdtv.task_id;
Line: 4876

      SELECT DISTINCT wdtv.task_id task_id
                    , -- added distinct for bug 2657909
                      NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , -- added following because of distinct for bug 2657909
                      mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                            AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
                            AND NVL(mcch.disable_date,sysdate+1)> sysdate
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
                  AND wms_express_pick_task.is_express_pick_task_eligible(wdtv.task_id) = 'S'
        AND Nvl(wdtv.pick_slip_number, -1) <> l_opt_task_pick_slip -- bug 2832818
              AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
             --J Addition
                   AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
         )
      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
                    , wdtv.task_id;
Line: 5030

      SELECT DISTINCT wdtv.task_id task_id
                    , -- added distinct for bug 2657909
                      NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                            AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
                            AND NVL(mcch.disable_date,sysdate+1)> sysdate
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                --   mtl_system_items msi      -- bug 2648133
      WHERE           v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND wdtv.ZONE = p_sign_on_zone
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  --   AND Nvl(v.eqp_srl, '@@@') = Nvl(l_sign_on_equipment_srl, Nvl(v.eqp_srl, '@@@'))   removed for bug 2095237
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
        AND Nvl(wdtv.pick_slip_number, -1) <> l_opt_task_pick_slip -- bug 2832818
              AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
             --J Addition
                   AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
         )
      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
                    , wdtv.task_id;
Line: 5184

      SELECT DISTINCT wdtv.task_id task_id
                    , -- added distinct for bug 2657909
                      NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            -- AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                            AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
                            AND NVL(mcch.disable_date,sysdate+1)> sysdate
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND wdtv.ZONE = p_sign_on_zone
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
                  AND wms_express_pick_task.is_express_pick_task_eligible(wdtv.task_id) = 'S'
        AND Nvl(wdtv.pick_slip_number, -1) <> l_opt_task_pick_slip -- bug 2832818
               AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
            --J Addition
                   AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
            )
      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
                    , wdtv.task_id;
Line: 5337

      SELECT DISTINCT wdtv.task_id task_id
                    , -- added distinct for bug 2657909
                      NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            -- AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                            AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
                            AND NVL(mcch.disable_date,sysdate+1)> sysdate
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
     AND Nvl(wdtv.pick_slip_number, -1) <> l_opt_task_pick_slip -- bug 2832818
                AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
            --J Addition
                   AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
      )
      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
                    , wdtv.task_id;
Line: 5488

      SELECT DISTINCT wdtv.task_id task_id
                    , -- added distinct for bug 2657909
                      NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                            AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
                            AND NVL(mcch.disable_date,sysdate+1)> sysdate
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
                  AND wms_express_pick_task.is_express_pick_task_eligible(wdtv.task_id) = 'S'
        AND Nvl(wdtv.pick_slip_number, -1) <> l_opt_task_pick_slip -- bug 2832818
             AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
             --J Addition
                   AND  wdtv.ZONE not in  (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
         )
      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
                    , wdtv.task_id;
Line: 5635

      SELECT DISTINCT wdtv.task_id task_id
                    , -- added distinct for bug 2657909
                      NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , -- added following because of distinct for bug 2657909
                      mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                            AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
                            AND NVL(mcch.disable_date,sysdate+1)> sysdate
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND(wdtv.pick_slip_number = v_pick_slip_number
                      OR(wdtv.task_id = v_task_id
                         AND wdtv.wms_task_type_id = v_task_type))
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND NVL(wdtv.ZONE, '@@@') = NVL(p_sign_on_zone, NVL(wdtv.ZONE, '@@@'))
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
                  AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
            --J Addition
                   AND  wdtv.ZONE not in  (
                        SELECT wd.subinventory_code
                        FROM  wms_devices_b wd
                            , wms_bus_event_devices wbed
                        WHERE 1 = 1
                            and wd.device_id = wbed.device_id
                           AND wbed.organization_id = wd.organization_id
                           AND wd.enabled_flag   = 'Y'
                           AND wbed.enabled_flag = 'Y'
                           AND wbed.business_event_id = 10
                           AND wd.subinventory_code IS NOT NULL
                           AND wd.force_sign_on_flag = 'Y'
                           AND wd.device_id NOT IN (SELECT device_id
                                       FROM wms_device_assignment_temp
                                      WHERE employee_id = p_sign_on_emp_id)
                     )
      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
                    , wdtv.task_id;
Line: 5786

      SELECT DISTINCT wdtv.task_id task_id
                    , -- added distinct for bug 2657909
                      NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , -- added following because of distinct for bug 2657909
                      mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                            AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
                            AND NVL(mcch.disable_date,sysdate+1)> sysdate
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                --    mtl_system_items msi    -- bug 2648133
      WHERE           v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND(wdtv.pick_slip_number = v_pick_slip_number
                      OR(wdtv.task_id = v_task_id
                         AND wdtv.wms_task_type_id = v_task_type))
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND NVL(wdtv.ZONE, '@@@') = NVL(p_sign_on_zone, NVL(wdtv.ZONE, '@@@'))
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  --    AND Nvl(v.eqp_srl, '@@@') = Nvl(l_sign_on_equipment_srl, Nvl(v.eqp_srl, '@@@'))   removed for bug 2095237
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
                  AND wms_express_pick_task.is_express_pick_task_eligible(wdtv.task_id) = 'S'
                  AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
            --J Addition
                               AND  wdtv.ZONE not in (
                                 SELECT wd.subinventory_code
                                 FROM  wms_devices_b wd
                                     , wms_bus_event_devices wbed
                                 WHERE 1 = 1
                                     and wd.device_id = wbed.device_id
                                    AND wbed.organization_id = wd.organization_id
                                    AND wd.enabled_flag   = 'Y'
                                    AND wbed.enabled_flag = 'Y'
                                    AND wbed.business_event_id = 10
                                    AND wd.subinventory_code IS NOT NULL
                                    AND wd.force_sign_on_flag = 'Y'
                                    AND wd.device_id NOT IN (SELECT device_id
                                                FROM wms_device_assignment_temp
                                               WHERE employee_id = p_sign_on_emp_id)
                              )
      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
                    , wdtv.task_id;
Line: 5940

      SELECT DISTINCT wdtv.task_id task_id
                    , -- added distinct for bug 2657909
                      NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND(wdtv.pick_slip_number = v_pick_slip_number
                      OR(wdtv.task_id = v_task_id
                         AND wdtv.wms_task_type_id = v_task_type))
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND NVL(wdtv.ZONE, '@@@') = NVL(p_sign_on_zone, NVL(wdtv.ZONE, '@@@'))
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
                  AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
           --J Addition
                              AND  wdtv.ZONE not in (
                                 SELECT wd.subinventory_code
                                 FROM  wms_devices_b wd
                                     , wms_bus_event_devices wbed
                                 WHERE 1 = 1
                                     and wd.device_id = wbed.device_id
                                    AND wbed.organization_id = wd.organization_id
                                    AND wd.enabled_flag   = 'Y'
                                    AND wbed.enabled_flag = 'Y'
                                    AND wbed.business_event_id = 10
                                    AND wd.subinventory_code IS NOT NULL
                                    AND wd.force_sign_on_flag = 'Y'
                                    AND wd.device_id NOT IN (SELECT device_id
                                                FROM wms_device_assignment_temp
                                               WHERE employee_id = p_sign_on_emp_id)
                              )

      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
                    , wdtv.task_id;
Line: 6088

      SELECT DISTINCT wdtv.task_id task_id
                    , -- added distinct for bug 2657909
                      NVL(wdtv.pick_slip_number, -1) pick_slip
                    , wdtv.wms_task_type_id
                    , nvl(wdtv.task_priority, 0)
                    , mol.header_id
                    , sub.picking_order
                    , loc.picking_order
                    , nvl(loc.x_coordinate, 0)
                    , nvl(loc.y_coordinate, 0)
                    , nvl(loc.z_coordinate, 0)
                 FROM (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(wms_task_status IS NULL
                              OR wms_task_status = 1) --Added for task planning WB. bug#2651318
                       UNION ALL
                       SELECT   MIN(mcce.cycle_count_entry_id) task_id
                              , MIN(mcce.standard_operation_id) user_task_type_id
                              , 3 wms_task_type_id
                              , mcce.organization_id organization_id
                              , mcce.subinventory ZONE
                              , mcce.locator_id locator_id
                              , MIN(mcce.task_priority) task_priority
                              , mcce.revision revision
                              , MIN(mcce.lot_number) lot_number
                              , '' transaction_uom
                              , TO_NUMBER(NULL) transaction_quantity
                              , TO_NUMBER(NULL) pick_rule_id
                              , TO_NUMBER(NULL) pick_slip_number
                              , TO_NUMBER(NULL) cartonization_id
                              , mcce.inventory_item_id
                              , TO_NUMBER(NULL) move_order_line_id
                           FROM mtl_cycle_count_entries mcce, mtl_cycle_count_headers mcch
                          WHERE mcce.entry_status_code IN(1, 3)
                            AND NVL(mcce.export_flag, 2) = 2
                            -- bug 3972076
                            --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                            AND mcce.cycle_count_header_id = mcch.cycle_count_header_id
                            AND NVL(mcch.disable_date,sysdate+1)> sysdate
                       GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id, mcce.revision) wdtv
                    , -- inlined wms_dispatchable_tasks_v, bug 2648133
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations loc
                    , mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND(wdtv.pick_slip_number = v_pick_slip_number
                      OR(wdtv.task_id = v_task_id
                         AND wdtv.wms_task_type_id = v_task_type))
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = NVL(l_sys_task_type, wdtv.wms_task_type_id) -- restrict to picking tasks or all tasks
                  AND wdtv.user_task_type_id = v.standard_operation_id -- join task to resource view, check if user defined task type match
                  AND NVL(wdtv.ZONE, '@@@') = NVL(p_sign_on_zone, NVL(wdtv.ZONE, '@@@')) -- bug 2648133
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id(+) -- join task to MOL, outer join for tasks do not have MOL
                  AND wms_express_pick_task.is_express_pick_task_eligible(wdtv.task_id) = 'S'
                  AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
             --*****************
                        --J Addition
                            AND  wdtv.ZONE not in  (
                              SELECT wd.subinventory_code
                              FROM  wms_devices_b wd
                                  , wms_bus_event_devices wbed
                              WHERE 1 = 1
                                  and wd.device_id = wbed.device_id
                                 AND wbed.organization_id = wd.organization_id
                                 AND wd.enabled_flag   = 'Y'
                                 AND wbed.enabled_flag = 'Y'
                                 AND wbed.business_event_id = 10
                                 AND wd.subinventory_code IS NOT NULL
                                 AND wd.force_sign_on_flag = 'Y'
                                 AND wd.device_id NOT IN (SELECT device_id
                                             FROM wms_device_assignment_temp
                                            WHERE employee_id = p_sign_on_emp_id)
                           )
      ORDER BY        nvl(wdtv.task_priority, 0)
                    , -- removed order by segments for bug 2657909
                      sub.picking_order
                    , loc.picking_order
                    , (
                         (loc.x_coordinate - l_cur_x) *(loc.x_coordinate - l_cur_x)
                       + (loc.y_coordinate - l_cur_y) *(loc.y_coordinate - l_cur_y)
                       + (loc.z_coordinate - l_cur_z) *(loc.z_coordinate - l_cur_z)
                      )
          , wdtv.task_id;
Line: 6240

      SELECT transaction_temp_id
   FROM mtl_material_transactions_temp mmtt
   WHERE mmtt.pick_slip_number = v_pick_slip_number
   FOR UPDATE nowait;
Line: 6309

'SELECT wdtv.task_id, wdtv.zone, wdtv.locator_id,
wdtv.revision, wdtv.transaction_uom,
wdtv.transaction_quantity, wdtv.lot_number, wdtv.wms_task_type_id,wdtv.task_priority
FROM  wms_dispatchable_tasks_v wdtv
WHERE
wdtv.organization_id = ' || p_sign_on_org_id ||'
AND Nvl(wdtv.zone, ''@@@'') = Nvl('''|| p_sign_on_zone || ''', Nvl(wdtv.zone, ''@@@''))
AND wdtv.user_task_type_id IN
(
 SELECT standard_operation_id
 FROM wms_person_resource_utt_v v
 WHERE v.emp_id = ' || p_sign_on_emp_id  ||'
 AND Nvl(v.eqp_srl, ''@@@'') = Nvl(''' || l_sign_on_equipment_srl || ''', Nvl(v.eqp_srl, ''@@@''))
 AND Nvl(v.eqp_id, -999) = Nvl(' || l_equipment_id_str ||', Nvl(v.eqp_id, -999))
 )
--***********
AND wdtv.task_id NOT IN
(SELECT wdtv.task_id FROM wms_skip_task_exceptions wste, mtl_parameters mp
 WHERE ((SYSDATE - wste.creation_date)*24*60) < mp.skip_task_waiting_minutes
 AND wste.task_id = wdtv.task_id
 AND wste.organization_id = mp.organization_id )
--************
AND wdtv.task_id NOT IN
(SELECT wdt1.transaction_temp_id
 FROM wms_dispatched_tasks wdt1
 --   WHERE wdt1.status = 1
 UNION ALL
 SELECT wdt2.transaction_temp_id
 FROM wms_exceptions wms_except, wms_dispatched_tasks wdt2
 WHERE wms_except.person_id = ' || p_sign_on_emp_id || '
 AND wdt2.task_id = wms_except.task_id
 AND discrepancy_type = 1
 )
ORDER BY wdtv.pick_slip_number, wdtv.task_priority, wdtv.task_id';
Line: 6354

        SELECT transaction_temp_id
             , task_type
             , loaded_time
          INTO l_last_loaded_task_id
             , l_last_loaded_task_type
             , l_last_loaded_time
          FROM (SELECT transaction_temp_id
                     , task_type
                     , loaded_time
                  FROM wms_dispatched_tasks wdt
                 WHERE wdt.person_id = p_sign_on_emp_id
                   AND wdt.loaded_time = (SELECT MAX(loaded_time)
                                            FROM wms_dispatched_tasks
                                           WHERE person_id = p_sign_on_emp_id))
         WHERE ROWNUM = 1 -- make sure only one task selected
                          ;
Line: 6387

        SELECT transaction_id
             , task_type
             , loaded_time
          INTO l_last_dropoff_task_id
             , l_last_dropoff_task_type
             , l_last_dropoff_time
          FROM (SELECT transaction_id
                     , task_type
                     , loaded_time
                  FROM wms_dispatched_tasks_history wdth
                 WHERE wdth.person_id = p_sign_on_emp_id
                   AND wdth.drop_off_time = (SELECT MAX(drop_off_time)
                                               FROM wms_dispatched_tasks_history
                                              WHERE person_id = p_sign_on_emp_id))
         WHERE ROWNUM = 1 -- make sure only one task selected
                          ;
Line: 6446

            SELECT NVL(loc.x_coordinate, 0)
                 , NVL(loc.y_coordinate, 0)
                 , NVL(loc.z_coordinate, 0)
              INTO l_cur_x
                 , l_cur_y
                 , l_cur_z
              FROM mtl_item_locations loc
                 , (SELECT transaction_temp_id task_id
                         , standard_operation_id user_task_type_id
                         , wms_task_type wms_task_type_id
                         , organization_id organization_id
                         , subinventory_code ZONE
                         , locator_id locator_id
                         , task_priority task_priority
                         , revision revision
                         , lot_number lot_number
                         , transaction_uom transaction_uom
                         , transaction_quantity transaction_quantity
                         , pick_rule_id pick_rule_id
                         , pick_slip_number pick_slip_number
                         , cartonization_id cartonization_id
                         , inventory_item_id
                         , move_order_line_id
                      FROM mtl_material_transactions_temp
                     WHERE wms_task_type IS NOT NULL
                       AND transaction_status = 2
                    UNION ALL
                    SELECT   MIN(cycle_count_entry_id) task_id
                           , MIN(standard_operation_id) user_task_type_id
                           , 3 wms_task_type_id
                           , organization_id organization_id
                           , subinventory ZONE
                           , locator_id locator_id
                           , MIN(task_priority) task_priority
                           , revision revision
                           , MIN(lot_number) lot_number
                           , '' transaction_uom
                           , TO_NUMBER(NULL) transaction_quantity
                           , TO_NUMBER(NULL) pick_rule_id
                           , TO_NUMBER(NULL) pick_slip_number
                           , TO_NUMBER(NULL) cartonization_id
                           , inventory_item_id
                           , TO_NUMBER(NULL) move_order_line_id
                        FROM mtl_cycle_count_entries
                       WHERE  entry_status_code IN(1, 3)
                         AND  NVL(export_flag, 2) = 2
                         -- bug 3972076
                         --AND  NVL(TRUNC(count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
                    GROUP BY  cycle_count_header_id, organization_id, subinventory, locator_id, inventory_item_id, revision) wdtv -- inlined wms_dispatchable_tasks_v, bug 2648133
             WHERE wdtv.locator_id = loc.inventory_location_id
               AND wdtv.organization_id = loc.organization_id
               AND wdtv.task_id = l_last_task_id
               AND wdtv.wms_task_type_id = l_last_task_type;
Line: 6519

              SELECT NVL(loc.x_coordinate, 0)
                   , NVL(loc.y_coordinate, 0)
                   , NVL(loc.z_coordinate, 0)
                INTO l_cur_x
                   , l_cur_y
                   , l_cur_z
                FROM mtl_item_locations loc, mtl_material_transactions mmt
               WHERE mmt.locator_id = loc.inventory_location_id
                 AND mmt.organization_id = loc.organization_id
                 AND mmt.transaction_set_id = l_last_task_id
                 AND ROWNUM = 1;
Line: 6545

              SELECT NVL(loc.x_coordinate, 0)
                   , NVL(loc.y_coordinate, 0)
                   , NVL(loc.z_coordinate, 0)
                INTO l_cur_x
                   , l_cur_y
                   , l_cur_z
                FROM mtl_item_locations loc, mtl_cycle_count_entries mcce
               WHERE mcce.locator_id = loc.inventory_location_id
                 AND mcce.organization_id = loc.organization_id
                 AND mcce.cycle_count_entry_id = l_last_task_id;
Line: 6910

         SELECT     mmtt.transaction_temp_id
           INTO l_opt_task_id
           FROM mtl_material_transactions_temp mmtt
           WHERE mmtt.transaction_temp_id = l_opt_task_id
           FOR UPDATE NOWAIT;
Line: 6929

              SELECT     mcce.cycle_count_entry_id
                    INTO l_opt_task_id
                    FROM mtl_cycle_count_entries mcce
                   WHERE mcce.cycle_count_entry_id = l_opt_task_id
              FOR UPDATE NOWAIT;
Line: 6954

            INSERT INTO wms_ordered_tasks
                        (
                         task_id
                       , wms_task_type
                       , task_sequence_id
                        )
                 VALUES (
                         l_opt_task_id
                       , l_opt_task_type
                       , l_ordered_tasks_count
                        );
Line: 6976

         SELECT     mmtt.transaction_temp_id
           INTO l_opt_task_id
           FROM mtl_material_transactions_temp mmtt
           WHERE mmtt.transaction_temp_id = l_opt_task_id
           FOR UPDATE NOWAIT;
Line: 6994

              SELECT     mcce.cycle_count_entry_id
                    INTO l_opt_task_id
                    FROM mtl_cycle_count_entries mcce
                   WHERE mcce.cycle_count_entry_id = l_opt_task_id
              FOR UPDATE NOWAIT;
Line: 7018

            INSERT INTO wms_ordered_tasks
                        (
                         task_id
                       , wms_task_type
                       , task_sequence_id
                        )
                 VALUES (
                         l_opt_task_id
                       , l_opt_task_type
                       , l_ordered_tasks_count
                        );
Line: 7088

        SELECT   mmtt.transaction_temp_id task_id
               , mmtt.subinventory_code ZONE
               , mmtt.locator_id locator_id
               , mmtt.revision revision
               , mmtt.transaction_uom transaction_uom
               , mmtt.transaction_quantity transaction_quantity
               , '' lot_number
               , mmtt.wms_task_type wms_task_type_id
               , mmtt.task_priority task_priority
            FROM mtl_material_transactions_temp mmtt, wms_ordered_tasks wot
           WHERE mmtt.wms_task_type IS NOT NULL
             AND mmtt.transaction_status = 2
             AND mmtt.transaction_temp_id = wot.task_id
             AND mmtt.transaction_temp_id > 0
        ORDER BY wot.task_sequence_id;
Line: 7105

        SELECT   MIN(mcce.cycle_count_entry_id) task_id
               , mcce.subinventory ZONE
               , mcce.locator_id locator_id
               , mcce.revision revision
               , '' transaction_uom
               , TO_NUMBER(NULL) transaction_quantity
               , MIN(mcce.lot_number) lot_number
               , 3 wms_task_type_id
               , MIN(mcce.task_priority) task_priority
            FROM mtl_cycle_count_entries mcce, wms_ordered_tasks wot
           WHERE mcce.entry_status_code IN(1, 3)
             AND NVL(mcce.export_flag, 2) = 2
             -- bug 3972076
             --AND NVL(TRUNC(mcce.count_due_date, 'DD'), TRUNC(SYSDATE, 'DD')) >= TRUNC(SYSDATE, 'DD')
             AND mcce.cycle_count_entry_id = wot.task_id
        GROUP BY mcce.cycle_count_header_id, mcce.organization_id, mcce.subinventory, mcce.locator_id, mcce.inventory_item_id
               , mcce.revision
        ORDER BY MIN(wot.task_sequence_id);
Line: 7309

      SELECT DISTINCT wdtv.task_id task_id1
                    , mol.carton_grouping_id
                    , wdtv.wms_task_type_id
                    , NVL(wda.delivery_id, mol.carton_grouping_id) cluster_id
                    , DECODE(wda.delivery_id, NULL, 'C', 'D') cluster_type
                    , nvl(wdtv.task_priority, 0) wdtv_task_priority
                    , sub.secondary_inventory_name sub_secondary_inventory_name
                    , sub.picking_order sub_picking_order
                    , loc.picking_order loc_picking_order
                    , (
                         (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                       + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                       + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                      ) xyz_distance
                    , loc.concatenated_segments loc_concat_segs
                 FROM --wms_dispatchable_tasks_v wdtv,
                      (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(
                              wms_task_status IS NULL
                              OR wms_task_status = 1
                             )                                                      --Added for task planning WB. bug#2651318
                               -- Commented out the following lines because we won't consider cycle counting taks for cluster pick
                               /*UNION ALL
                               SELECT MIN(cycle_count_entry_id) task_id,
                               MIN(standard_operation_id) user_task_type_id,
                               3 wms_task_type_id,
                               organization_id organization_id,
                               subinventory zone,
                               locator_id locator_id,
                               MIN(task_priority) task_priority,
                               revision revision,
                               MIN(lot_number) lot_number,
                               '' transaction_uom,
                               To_number(NULL) transaction_quantity,
                               To_number(NULL) pick_rule_id,
                               To_number(NULL) pick_slip_number,
                               To_number(NULL) cartonization_id,
                               inventory_item_id,
                               To_number(NULL) move_order_line_id
                               FROM mtl_cycle_count_entries
                               WHERE entry_status_code IN (1,3)
                               AND  NVL(export_flag, 2) = 2
                               -- bug 3972076
                               --AND  NVL(Trunc(count_due_date, 'DD'), Trunc(Sysdate, 'DD')) >= Trunc(Sysdate, 'DD')
                               GROUP BY  cycle_count_header_id, organization_id, subinventory, locator_id, inventory_item_id, revision
                                */
                      ) wdtv
                    ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
                      --wms_person_resource_utt_v v,
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations_kfv loc
                    , --changed to kfv bug#2742611
                      mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                    , mtl_txn_request_headers moh
                    , --    mtl_system_items msi    -- bug 2648133
                      wsh_delivery_details_ob_grp_v wdd
                    , -- added
                      wsh_delivery_assignments_v wda --added
                WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
                  AND mol.header_id = moh.header_id
                  AND moh.move_order_type = 3 -- only pick wave move orders are considered
                  AND wdtv.user_task_type_id =
                                             v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                                                                     --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
                  AND wdtv.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id
                   -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
                  -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
                  AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  -- Join with delivery details
                  AND(wdd.move_order_line_id = wdtv.move_order_line_id
                      AND wdd.delivery_detail_id = wda.delivery_detail_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
                  --J Addition
                   AND  wdtv.ZONE not in (
                           SELECT wd.subinventory_code
                           FROM  wms_devices_b wd
                               , wms_bus_event_devices wbed
                           WHERE 1 = 1
                               and wd.device_id = wbed.device_id
                              AND wbed.organization_id = wd.organization_id
                              AND wd.enabled_flag   = 'Y'
                              AND wbed.enabled_flag = 'Y'
                              AND wbed.business_event_id = 10
                              AND wd.subinventory_code IS NOT NULL
                              AND wd.force_sign_on_flag = 'Y'
                              AND wd.device_id NOT IN (SELECT device_id
                                          FROM wms_device_assignment_temp
                                         WHERE employee_id = p_sign_on_emp_id)
                     )

      --*****************
      UNION ALL
      -- This will select the WIP Jobs alone
      SELECT   wdtv.task_id task_id1
             , mol.carton_grouping_id
             , wdtv.wms_task_type_id
             , mol.carton_grouping_id cluster_id
             , 'C' cluster_type
             , nvl(wdtv.task_priority, 0) wdtv_task_priority
             , sub.secondary_inventory_name sub_secondary_inventory_name
             , sub.picking_order sub_picking_order
             , loc.picking_order loc_picking_order
             , (
                  (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
               ) xyz_distance
             , loc.concatenated_segments loc_concat_segs
          FROM --wms_dispatchable_tasks_v wdtv,
               (SELECT transaction_temp_id task_id
                     , standard_operation_id user_task_type_id
                     , wms_task_type wms_task_type_id
                     , organization_id organization_id
                     , subinventory_code ZONE
                     , locator_id locator_id
                     , task_priority task_priority
                     , revision revision
                     , lot_number lot_number
                     , transaction_uom transaction_uom
                     , transaction_quantity transaction_quantity
                     , pick_rule_id pick_rule_id
                     , pick_slip_number pick_slip_number
                     , cartonization_id cartonization_id
                     , inventory_item_id
                     , move_order_line_id
                  FROM mtl_material_transactions_temp
                 WHERE wms_task_type IS NOT NULL
                   AND transaction_status = 2
                   AND(
                       wms_task_status IS NULL
                       OR wms_task_status = 1
                      )                                                      --Added for task planning WB. bug#2651318
                        -- Commented out the following lines because we won't consider cycle counting taks for cluster pick
                        /*UNION ALL
                        SELECT MIN(cycle_count_entry_id) task_id,
                        MIN(standard_operation_id) user_task_type_id,
                        3 wms_task_type_id,
                        organization_id organization_id,
                        subinventory zone,
                        locator_id locator_id,
                        MIN(task_priority) task_priority,
                        revision revision,
                        MIN(lot_number) lot_number,
                        '' transaction_uom,
                        To_number(NULL) transaction_quantity,
                        To_number(NULL) pick_rule_id,
                        To_number(NULL) pick_slip_number,
                        To_number(NULL) cartonization_id,
                        inventory_item_id,
                        To_number(NULL) move_order_line_id
                        FROM mtl_cycle_count_entries
                        WHERE entry_status_code IN (1,3)
                        AND  NVL(export_flag, 2) = 2
                        -- bug 3972076
                        --AND  NVL(Trunc(count_due_date, 'DD'), Trunc(Sysdate, 'DD')) >= Trunc(Sysdate, 'DD')
                        GROUP BY  cycle_count_header_id, organization_id, subinventory, locator_id, inventory_item_id, revision
                         */
               ) wdtv
             ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
               --wms_person_resource_utt_v v,
               (SELECT utt_emp.standard_operation_id standard_operation_id
                     , utt_emp.resource_id ROLE
                     , utt_eqp.resource_id equipment
                     , utt_emp.person_id emp_id
                     , utt_eqp.inventory_item_id eqp_id
                     , NULL eqp_srl  /* removed for bug 2095237 */
                  FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                             , x_utt_res1.resource_id resource_id
                             , x_emp_r.person_id
                          FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                         WHERE x_utt_res1.resource_id = r1.resource_id
                           AND r1.resource_type = 2
                           AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                     , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                             , x_utt_res2.resource_id resource_id
                             , x_eqp_r.inventory_item_id inventory_item_id
                          FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                         WHERE x_utt_res2.resource_id = r2.resource_id
                           AND r2.resource_type = 1
                           AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                 WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
             , -- inlined wms_person_resource_utt_v, bug 2648133
               mtl_item_locations_kfv loc
             , --changed to kfv bug#2742611
               mtl_secondary_inventories sub
             , mtl_txn_request_lines mol
             , mtl_txn_request_headers moh
         --    mtl_system_items msi    -- bug 2648133
      WHERE    v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
           AND wdtv.organization_id = p_sign_on_org_id
           AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
           AND mol.header_id = moh.header_id
           AND moh.move_order_type = 5 -- only WIP jobs are considered : Bug 2666620 BackFlush Removed
           AND wdtv.user_task_type_id = v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                                                                --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
           AND wdtv.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
           AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
           AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
           AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
           AND wdtv.locator_id = loc.inventory_location_id(+)
           AND wdtv.ZONE = sub.secondary_inventory_name
           AND wdtv.organization_id = sub.organization_id
           AND wdtv.move_order_line_id = mol.line_id
           -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
           -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
           AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                          (
                SELECT NULL
                  FROM mtl_material_transactions_temp mmtt
                 WHERE mmtt.transaction_temp_id = wdtv.task_id
                   AND mmtt.parent_line_id IS NOT NULL
                   AND mmtt.wms_task_type = wdtv.wms_task_type_id)
           AND NOT EXISTS -- exclude tasks already dispatched
                          (SELECT NULL
                             FROM wms_dispatched_tasks wdt1
                            WHERE wdt1.transaction_temp_id = wdtv.task_id
                              AND wdt1.task_type = wdtv.wms_task_type_id)
           --******************
           AND wdtv.task_id NOT IN -- excluded skipped tasks
                                   (
                SELECT wdtv.task_id
                  FROM wms_skip_task_exceptions wste, mtl_parameters mp
                 WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                   AND wste.task_id = wdtv.task_id
                   AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                   AND wste.organization_id = mp.organization_id)
      --*****************
      --J Addition
                   AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
      )
      ORDER BY wdtv_task_priority
             , sub_picking_order
             , sub_secondary_inventory_name
             , loc_picking_order
             , xyz_distance
             , loc_concat_segs
             , task_id1;
Line: 7630

      SELECT DISTINCT wdtv.task_id task_id1
                    , mol.carton_grouping_id
                    , wdtv.wms_task_type_id
                    , NVL(wda.delivery_id, mol.carton_grouping_id) cluster_id
                    , DECODE(wda.delivery_id, NULL, 'C', 'D') cluster_type
                    , nvl(wdtv.task_priority, 0) wdtv_task_priority
                    , sub.secondary_inventory_name sub_secondary_inventory_name
                    , sub.picking_order sub_picking_order
                    , loc.picking_order loc_picking_order
                    , (
                         (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                       + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                       + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                      ) xyz_distance
                    , loc.concatenated_segments loc_concat_segs
                 FROM --wms_dispatchable_tasks_v wdtv,
                      (SELECT transaction_temp_id task_id
                            , standard_operation_id user_task_type_id
                            , wms_task_type wms_task_type_id
                            , organization_id organization_id
                            , subinventory_code ZONE
                            , locator_id locator_id
                            , task_priority task_priority
                            , revision revision
                            , lot_number lot_number
                            , transaction_uom transaction_uom
                            , transaction_quantity transaction_quantity
                            , pick_rule_id pick_rule_id
                            , pick_slip_number pick_slip_number
                            , cartonization_id cartonization_id
                            , inventory_item_id
                            , move_order_line_id
                         FROM mtl_material_transactions_temp
                        WHERE wms_task_type IS NOT NULL
                          AND transaction_status = 2
                          AND(
                              wms_task_status IS NULL
                              OR wms_task_status = 1
                             )                                                      --Added for task planning WB. bug#2651318
                               -- Commented out the following lines because we won't consider cycle counting taks for cluster pick
                               /*UNION ALL
                               SELECT MIN(cycle_count_entry_id) task_id,
                               MIN(standard_operation_id) user_task_type_id,
                               3 wms_task_type_id,
                               organization_id organization_id,
                               subinventory zone,
                               locator_id locator_id,
                               MIN(task_priority) task_priority,
                               revision revision,
                               MIN(lot_number) lot_number,
                               '' transaction_uom,
                               To_number(NULL) transaction_quantity,
                               To_number(NULL) pick_rule_id,
                               To_number(NULL) pick_slip_number,
                               To_number(NULL) cartonization_id,
                               inventory_item_id,
                               To_number(NULL) move_order_line_id
                               FROM mtl_cycle_count_entries
                               WHERE entry_status_code IN (1,3)
                               AND  NVL(export_flag, 2) = 2
                               -- bug 3972076
                               -- AND  NVL(Trunc(count_due_date, 'DD'), Trunc(Sysdate, 'DD')) >= Trunc(Sysdate, 'DD')
                               GROUP BY  cycle_count_header_id, organization_id, subinventory, locator_id, inventory_item_id, revision
                                */
                      ) wdtv
                    ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
                      --wms_person_resource_utt_v v,
                      (SELECT utt_emp.standard_operation_id standard_operation_id
                            , utt_emp.resource_id ROLE
                            , utt_eqp.resource_id equipment
                            , utt_emp.person_id emp_id
                            , utt_eqp.inventory_item_id eqp_id
                            , NULL eqp_srl  /* removed for bug 2095237 */
                         FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                    , x_utt_res1.resource_id resource_id
                                    , x_emp_r.person_id
                                 FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                WHERE x_utt_res1.resource_id = r1.resource_id
                                  AND r1.resource_type = 2
                                  AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                            , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                    , x_utt_res2.resource_id resource_id
                                    , x_eqp_r.inventory_item_id inventory_item_id
                                 FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                WHERE x_utt_res2.resource_id = r2.resource_id
                                  AND r2.resource_type = 1
                                  AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                        WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                    , -- inlined wms_person_resource_utt_v, bug 2648133
                      mtl_item_locations_kfv loc
                    , --changed to kfv bug#2742611
                      mtl_secondary_inventories sub
                    , mtl_txn_request_lines mol
                    , mtl_txn_request_headers moh
                    , --    mtl_system_items msi    -- bug 2648133
                      wsh_delivery_details_ob_grp_v wdd
                    , -- added
                      wsh_delivery_assignments_v wda --added
                WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                  AND wdtv.organization_id = p_sign_on_org_id
                  AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
                  AND mol.header_id = moh.header_id
                  AND moh.move_order_type = 3 -- only pick wave move orders are considered
                  AND wdtv.user_task_type_id =
                                             v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                                                                     --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
                  AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                  AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                  AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                  AND wdtv.locator_id = loc.inventory_location_id(+)
                  AND wdtv.ZONE = sub.secondary_inventory_name
                  AND wdtv.organization_id = sub.organization_id
                  AND wdtv.move_order_line_id = mol.line_id
                   -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
                  -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
                  AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                 (
                       SELECT NULL
                         FROM mtl_material_transactions_temp mmtt
                        WHERE mmtt.transaction_temp_id = wdtv.task_id
                          AND mmtt.parent_line_id IS NOT NULL
                          AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                  AND NOT EXISTS -- exclude tasks already dispatched
                                 (SELECT NULL
                                    FROM wms_dispatched_tasks wdt1
                                   WHERE wdt1.transaction_temp_id = wdtv.task_id
                                     AND wdt1.task_type = wdtv.wms_task_type_id)
                  -- Join with delivery details
                  AND(wdd.move_order_line_id = wdtv.move_order_line_id
                      AND wdd.delivery_detail_id = wda.delivery_detail_id)
                  --******************
                  AND wdtv.task_id NOT IN -- excluded skipped tasks
                                          (
                       SELECT wdtv.task_id
                         FROM wms_skip_task_exceptions wste, mtl_parameters mp
                        WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                          AND wste.task_id = wdtv.task_id
                          AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                          AND wste.organization_id = mp.organization_id)
      --*****************
             --J Addition
                         AND  wdtv.ZONE not in (
                        SELECT wd.subinventory_code
                        FROM  wms_devices_b wd
                            , wms_bus_event_devices wbed
                        WHERE 1 = 1
                        and wd.device_id = wbed.device_id
                        AND wbed.organization_id = wd.organization_id
                        AND wd.enabled_flag   = 'Y'
                        AND wbed.enabled_flag = 'Y'
                        AND wbed.business_event_id = 10
                        AND wd.subinventory_code IS NOT NULL
                        AND wd.force_sign_on_flag = 'Y'
                        AND wd.device_id NOT IN (SELECT device_id
                                    FROM wms_device_assignment_temp
                                   WHERE employee_id = p_sign_on_emp_id)
               )

      UNION ALL
      -- This will select the WIP Jobs alone
      SELECT   wdtv.task_id task_id1
             , mol.carton_grouping_id
             , wdtv.wms_task_type_id
             , mol.carton_grouping_id cluster_id
             , 'C' cluster_type
             , nvl(wdtv.task_priority, 0) wdtv_task_priority
             , sub.secondary_inventory_name sub_secondary_inventory_name
             , sub.picking_order sub_picking_order
             , loc.picking_order loc_picking_order
             , (
                  (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
               ) xyz_distance
             , loc.concatenated_segments loc_concat_segs
          FROM --wms_dispatchable_tasks_v wdtv,
               (SELECT transaction_temp_id task_id
                     , standard_operation_id user_task_type_id
                     , wms_task_type wms_task_type_id
                     , organization_id organization_id
                     , subinventory_code ZONE
                     , locator_id locator_id
                     , task_priority task_priority
                     , revision revision
                     , lot_number lot_number
                     , transaction_uom transaction_uom
                     , transaction_quantity transaction_quantity
                     , pick_rule_id pick_rule_id
                     , pick_slip_number pick_slip_number
                     , cartonization_id cartonization_id
                     , inventory_item_id
                     , move_order_line_id
                  FROM mtl_material_transactions_temp
                 WHERE wms_task_type IS NOT NULL
                   AND transaction_status = 2
                   AND(
                       wms_task_status IS NULL
                       OR wms_task_status = 1
                      )                                                      --Added for task planning WB. bug#2651318
                        -- Commented out the following lines because we won't consider cycle counting taks for cluster pick
                        /*UNION ALL
                        SELECT MIN(cycle_count_entry_id) task_id,
                        MIN(standard_operation_id) user_task_type_id,
                        3 wms_task_type_id,
                        organization_id organization_id,
                        subinventory zone,
                        locator_id locator_id,
                        MIN(task_priority) task_priority,
                        revision revision,
                        MIN(lot_number) lot_number,
                        '' transaction_uom,
                        To_number(NULL) transaction_quantity,
                        To_number(NULL) pick_rule_id,
                        To_number(NULL) pick_slip_number,
                        To_number(NULL) cartonization_id,
                        inventory_item_id,
                        To_number(NULL) move_order_line_id
                        FROM mtl_cycle_count_entries
                        WHERE entry_status_code IN (1,3)
                        AND  NVL(export_flag, 2) = 2
                        -- bug 3972076
                        --AND  NVL(Trunc(count_due_date, 'DD'), Trunc(Sysdate, 'DD')) >= Trunc(Sysdate, 'DD')
                        GROUP BY  cycle_count_header_id, organization_id, subinventory, locator_id, inventory_item_id, revision
                         */
               ) wdtv
             ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
               --wms_person_resource_utt_v v,
               (SELECT utt_emp.standard_operation_id standard_operation_id
                     , utt_emp.resource_id ROLE
                     , utt_eqp.resource_id equipment
                     , utt_emp.person_id emp_id
                     , utt_eqp.inventory_item_id eqp_id
                     , NULL eqp_srl  /* removed for bug 2095237 */
                  FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                             , x_utt_res1.resource_id resource_id
                             , x_emp_r.person_id
                          FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                         WHERE x_utt_res1.resource_id = r1.resource_id
                           AND r1.resource_type = 2
                           AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                     , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                             , x_utt_res2.resource_id resource_id
                             , x_eqp_r.inventory_item_id inventory_item_id
                          FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                         WHERE x_utt_res2.resource_id = r2.resource_id
                           AND r2.resource_type = 1
                           AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                 WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
             , -- inlined wms_person_resource_utt_v, bug 2648133
               mtl_item_locations_kfv loc
             , --changed to kfv bug#2742611
               mtl_secondary_inventories sub
             , mtl_txn_request_lines mol
             , mtl_txn_request_headers moh
         --    mtl_system_items msi    -- bug 2648133
      WHERE    v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
           AND wdtv.organization_id = p_sign_on_org_id
           AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
           AND mol.header_id = moh.header_id
           AND moh.move_order_type = 5 -- only WIP jobs are considered : Bug 2666620 BackFlush Removed
           AND wdtv.user_task_type_id = v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                                                                --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
           AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
           AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
           AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
           AND wdtv.locator_id = loc.inventory_location_id(+)
           AND wdtv.ZONE = sub.secondary_inventory_name
           AND wdtv.organization_id = sub.organization_id
           AND wdtv.move_order_line_id = mol.line_id
           -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
           -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
           AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                          (
                SELECT NULL
                  FROM mtl_material_transactions_temp mmtt
                 WHERE mmtt.transaction_temp_id = wdtv.task_id
                   AND mmtt.parent_line_id IS NOT NULL
                   AND mmtt.wms_task_type = wdtv.wms_task_type_id)
           AND NOT EXISTS -- exclude tasks already dispatched
                          (SELECT NULL
                             FROM wms_dispatched_tasks wdt1
                            WHERE wdt1.transaction_temp_id = wdtv.task_id
                              AND wdt1.task_type = wdtv.wms_task_type_id)
           --******************
           AND wdtv.task_id NOT IN -- excluded skipped tasks
                                   (
                SELECT wdtv.task_id
                  FROM wms_skip_task_exceptions wste, mtl_parameters mp
                 WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                   AND wste.task_id = wdtv.task_id
                   AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                   AND wste.organization_id = mp.organization_id)
      --*****************
      --J Addition
                   AND  wdtv.ZONE not in ( SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
            )
      ORDER BY wdtv_task_priority
             , sub_picking_order
             , sub_secondary_inventory_name
             , loc_picking_order
             , xyz_distance
             , loc_concat_segs
             , task_id1;
Line: 7951

      SELECT  DISTINCT
                qt.task_id task_id1
         , mol.carton_grouping_id
         , qt.wms_task_type_id
         , NVL(wda.delivery_id, mol.carton_grouping_id) cluster_id
         , DECODE(wda.delivery_id, NULL, 'C', 'D') cluster_type
         , nvl(qt.task_priority,0) wdtv_task_priority -- Bug 4599496
         , sub.secondary_inventory_name sub_secondary_inventory_name
         , sub.picking_order sub_picking_order
         , loc.picking_order loc_picking_order
         , (
         (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
       + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
       + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
      ) xyz_distance
         , loc.concatenated_segments loc_concat_segs
         ,wdt.status task_status --bug 4310093
         ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
              , wdt.effective_start_date
              , wdt.effective_end_date
              , wdt.person_resource_id
              , wdt.machine_resource_id
      FROM wms_dispatched_tasks wdt,
      (SELECT transaction_temp_id task_id
            , standard_operation_id user_task_type_id
            , wms_task_type wms_task_type_id
            , organization_id organization_id
            , subinventory_code ZONE
            , locator_id locator_id
            , task_priority task_priority
            , revision revision
            , lot_number lot_number
            , transaction_uom transaction_uom
            , transaction_quantity transaction_quantity
            , pick_rule_id pick_rule_id
            , pick_slip_number pick_slip_number
            , cartonization_id cartonization_id
            , inventory_item_id
            , move_order_line_id
         FROM mtl_material_transactions_temp
        WHERE wms_task_type IS NOT NULL
          AND transaction_status = 2
          AND Decode(transaction_source_type_id, 2, l_so_allowed,
         8, l_io_allowed) = 1   -- filter out the request so or io
          AND(
         wms_task_status IS NULL
         OR wms_task_status = 1
             )          --Added for task planning WB. bug#2651318
      ) qt
         , (SELECT
             bsor.standard_operation_id,
             bre.resource_id,
             bre.inventory_item_id equipment_id
           FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
           WHERE bsor.resource_id = bre.resource_id
           AND br.resource_type = 1
           AND bsor.resource_id = br.resource_id) e
         , mtl_item_locations_kfv loc
         , --changed to kfv bug#2742611
      mtl_secondary_inventories sub
         , mtl_txn_request_lines mol
         , mtl_txn_request_headers moh
         , --    mtl_system_items msi    -- bug 2648133
      wsh_delivery_details_ob_grp_v wdd
         , -- added
      wsh_delivery_assignments_v wda --added
     WHERE  wdt.transaction_temp_id = qt.task_id
            AND wdt.status in ( 2,3) -- Queued and dispatched tasks only bug 4310093
            AND wdt.person_id = p_sign_on_emp_id
       AND wdt.organization_id = p_sign_on_org_id
       AND qt.wms_task_type_id = 1 -- restrict to picking tasks
       AND mol.header_id = moh.header_id
       AND moh.move_order_type = 3 -- only pick wave move orders are considered
       AND qt.user_task_type_id =
                   e.standard_operation_id(+)                                                       -- join task to resource view, check if user defined task type match
                            --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
       AND qt.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
       AND NVL(qt.cartonization_id, -999) = NVL(p_cartonization_id, NVL(qt.cartonization_id, -999))
       AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
       AND qt.organization_id = loc.organization_id
       AND qt.locator_id = loc.inventory_location_id
       AND qt.ZONE = sub.secondary_inventory_name
       AND qt.organization_id = sub.organization_id
       AND qt.move_order_line_id = mol.line_id
       -- Join with delivery details
       AND(wdd.move_order_line_id = qt.move_order_line_id
      AND wdd.delivery_detail_id = wda.delivery_detail_id)
        UNION ALL
        SELECT DISTINCT wdtv.task_id task_id1
                      , mol.carton_grouping_id
                      , wdtv.wms_task_type_id
                      , NVL(wda.delivery_id, mol.carton_grouping_id) cluster_id
                      , DECODE(wda.delivery_id, NULL, 'C', 'D') cluster_type
                      , nvl(wdtv.task_priority, 0) wdtv_task_priority
                      , sub.secondary_inventory_name sub_secondary_inventory_name
                      , sub.picking_order sub_picking_order
                      , loc.picking_order loc_picking_order
                      , (
                           (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                         + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                         + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                        ) xyz_distance
                      , loc.concatenated_segments loc_concat_segs
                      ,1 task_status
                      ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
                      ,v.effective_start_date
                      ,v.effective_end_date
                      ,v.role person_resource_id
                      ,v.equipment machine_resource_id
                   FROM --wms_dispatchable_tasks_v wdtv,
                        (SELECT transaction_temp_id task_id
                              , standard_operation_id user_task_type_id
                              , wms_task_type wms_task_type_id
                              , organization_id organization_id
                              , subinventory_code ZONE
                              , locator_id locator_id
                              , task_priority task_priority
                              , revision revision
                              , lot_number lot_number
                              , transaction_uom transaction_uom
                              , transaction_quantity transaction_quantity
                              , pick_rule_id pick_rule_id
                              , pick_slip_number pick_slip_number
                              , cartonization_id cartonization_id
                              , inventory_item_id
                              , move_order_line_id
                           FROM mtl_material_transactions_temp
                          WHERE wms_task_type IS NOT NULL
                            AND transaction_status = 2
                            AND Decode(transaction_source_type_id, 2, l_so_allowed,
                                8, l_io_allowed) = 1   -- filter out the request so or io
                            AND(
                                wms_task_status IS NULL
                                OR wms_task_status = 1
                               )          --Added for task planning WB. bug#2651318
                        ) wdtv
                      ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
                        --wms_person_resource_utt_v v,
                        (SELECT utt_emp.standard_operation_id standard_operation_id
                              , utt_emp.resource_id ROLE
                              , utt_eqp.resource_id equipment
                              , utt_emp.person_id emp_id
                              , utt_eqp.inventory_item_id eqp_id
                              , NULL eqp_srl  /* removed for bug 2095237 */
                              , utt_emp.effective_start_date
                              , utt_emp.effective_end_date
                           FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                      , x_utt_res1.resource_id resource_id
                                      , x_emp_r.person_id
                                      , x_emp_r.effective_start_date
                                      , x_emp_r.effective_end_date
                                   FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                  WHERE x_utt_res1.resource_id = r1.resource_id
                                    AND r1.resource_type = 2
                                    AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                              , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                      , x_utt_res2.resource_id resource_id
                                      , x_eqp_r.inventory_item_id inventory_item_id
                                   FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                  WHERE x_utt_res2.resource_id = r2.resource_id
                                    AND r2.resource_type = 1
                                    AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                          WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                      , -- inlined wms_person_resource_utt_v, bug 2648133
                        mtl_item_locations_kfv loc
                      , --changed to kfv bug#2742611
                        mtl_secondary_inventories sub
                      , mtl_txn_request_lines mol
                      , mtl_txn_request_headers moh
                      , --    mtl_system_items msi    -- bug 2648133
                        wsh_delivery_details_ob_grp_v wdd
                      , -- added
                        wsh_delivery_assignments_v wda --added
                  WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                    AND wdtv.organization_id = p_sign_on_org_id
                    AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
                    AND mol.header_id = moh.header_id
                    AND moh.move_order_type = 3 -- only pick wave move orders are considered
                    AND wdtv.user_task_type_id =
                                               v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                                                                       --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
                    AND wdtv.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
                    AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                    AND wdtv.locator_id = loc.inventory_location_id(+)
                    AND wdtv.ZONE = sub.secondary_inventory_name
                    AND wdtv.organization_id = sub.organization_id
                    AND wdtv.move_order_line_id = mol.line_id
                     -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
                    -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
                    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                   (
                         SELECT NULL
                           FROM mtl_material_transactions_temp mmtt
                          WHERE mmtt.transaction_temp_id = wdtv.task_id
                            AND mmtt.parent_line_id IS NOT NULL
                            AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                    AND NOT EXISTS -- exclude tasks already dispatched
                                   (SELECT NULL
                                      FROM wms_dispatched_tasks wdt1
                                     WHERE wdt1.transaction_temp_id = wdtv.task_id
                                       AND wdt1.task_type = wdtv.wms_task_type_id)
                    -- Join with delivery details
                    AND(wdd.move_order_line_id = wdtv.move_order_line_id
                        AND wdd.delivery_detail_id = wda.delivery_detail_id)
                    --******************
                    AND wdtv.task_id NOT IN -- excluded skipped tasks
                                            (
                         SELECT wdtv.task_id
                           FROM wms_skip_task_exceptions wste, mtl_parameters mp
                          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                            AND wste.task_id = wdtv.task_id
                            AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                            AND wste.organization_id = mp.organization_id)
                     --J Addition
                         AND  wdtv.ZONE not in (
                         SELECT wd.subinventory_code
                        FROM  wms_devices_b wd
                           , wms_bus_event_devices wbed
                        WHERE 1 = 1
                         and wd.device_id = wbed.device_id
                         AND wbed.organization_id = wd.organization_id
                         AND wd.enabled_flag   = 'Y'
                         AND wbed.enabled_flag = 'Y'
                         AND wbed.business_event_id = 10
                         AND wd.subinventory_code IS NOT NULL
                         AND wd.force_sign_on_flag = 'Y'
                         AND wd.device_id NOT IN (SELECT device_id
                              FROM wms_device_assignment_temp
                                WHERE employee_id = p_sign_on_emp_id)
            )

        ORDER BY wdtv_task_priority DESC
                 , batch_id
                 , task_status DESC
                 , sub_picking_order
                 , loc_picking_order
                 , xyz_distance
                 , task_id1;
Line: 8195

        SELECT  DISTINCT
                 wdtv.task_id task_id1
               , mol.carton_grouping_id
               , wdtv.wms_task_type_id
               , mol.carton_grouping_id cluster_id
               , 'C' cluster_type
               , nvl(wdtv.task_priority, 0) wdtv_task_priority
               , sub.secondary_inventory_name sub_secondary_inventory_name
               , sub.picking_order sub_picking_order
               , loc.picking_order loc_picking_order
               , (
                    (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                  + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                  + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                 ) xyz_distance
               , loc.concatenated_segments loc_concat_segs
               ,wdt.status task_status --bug  4310093
               ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
              , wdt.effective_start_date
              , wdt.effective_end_date
              , wdt.person_resource_id
              , wdt.machine_resource_id
            FROM wms_dispatched_tasks wdt,
                 (SELECT transaction_temp_id task_id
                       , standard_operation_id user_task_type_id
                       , wms_task_type wms_task_type_id
                       , organization_id organization_id
                       , subinventory_code ZONE
                       , locator_id locator_id
                       , task_priority task_priority
                       , revision revision
                       , lot_number lot_number
                       , transaction_uom transaction_uom
                       , transaction_quantity transaction_quantity
                       , pick_rule_id pick_rule_id
                       , pick_slip_number pick_slip_number
                       , cartonization_id cartonization_id
                       , inventory_item_id
                       , move_order_line_id
                    FROM mtl_material_transactions_temp
                   WHERE wms_task_type IS NOT NULL
                     AND transaction_status = 2
                     AND(
                         wms_task_status IS NULL
                         OR wms_task_status = 1
                        )                                                      --Added for task planning WB. bug#2651318
                 ) wdtv
               , (SELECT
                       bsor.standard_operation_id,
                       bre.resource_id,
                       bre.inventory_item_id equipment_id
                     FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
                     WHERE bsor.resource_id = bre.resource_id
                     AND br.resource_type = 1
                     AND bsor.resource_id = br.resource_id) e
               ,  mtl_item_locations_kfv loc
               , --changed to kfv bug#2742611
                 mtl_secondary_inventories sub
               , mtl_txn_request_lines mol
               , mtl_txn_request_headers moh
           --    mtl_system_items msi    -- bug 2648133
        WHERE  wdt.transaction_temp_id = wdtv.task_id
            AND wdt.status in ( 2,3) -- Queued and dispatched tasks only bug  4310093
            AND wdt.person_id = p_sign_on_emp_id
            AND wdt.organization_id = p_sign_on_org_id
             AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
             AND mol.header_id = moh.header_id
             AND moh.move_order_type = 5 -- only WIP jobs are considered : Bug 2666620 BackFlush Removed
             AND wdtv.user_task_type_id = e.standard_operation_id(+)                                                       -- join task to resource view, check if user defined task type match
             AND wdtv.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
             AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
             AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
             AND wdtv.organization_id = loc.organization_id
             AND wdtv.locator_id = loc.inventory_location_id
             AND wdtv.ZONE = sub.secondary_inventory_name
             AND wdtv.organization_id = sub.organization_id
             AND wdtv.move_order_line_id = mol.line_id
        UNION ALL
        SELECT   wdtv.task_id task_id1
               , mol.carton_grouping_id
               , wdtv.wms_task_type_id
               , mol.carton_grouping_id cluster_id
               , 'C' cluster_type
               , nvl(wdtv.task_priority, 0) wdtv_task_priority
               , sub.secondary_inventory_name sub_secondary_inventory_name
               , sub.picking_order sub_picking_order
               , loc.picking_order loc_picking_order
               , (
                    (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                  + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                  + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                 ) xyz_distance
               , loc.concatenated_segments loc_concat_segs
               ,1 task_status
               ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
                      ,v.effective_start_date
                      ,v.effective_end_date
                      ,v.role person_resource_id
                      ,v.equipment machine_resource_id
            FROM --wms_dispatchable_tasks_v wdtv,
                 (SELECT transaction_temp_id task_id
                       , standard_operation_id user_task_type_id
                       , wms_task_type wms_task_type_id
                       , organization_id organization_id
                       , subinventory_code ZONE
                       , locator_id locator_id
                       , task_priority task_priority
                       , revision revision
                       , lot_number lot_number
                       , transaction_uom transaction_uom
                       , transaction_quantity transaction_quantity
                       , pick_rule_id pick_rule_id
                       , pick_slip_number pick_slip_number
                       , cartonization_id cartonization_id
                       , inventory_item_id
                       , move_order_line_id
                    FROM mtl_material_transactions_temp
                   WHERE wms_task_type IS NOT NULL
                     AND transaction_status = 2
                     AND(
                         wms_task_status IS NULL
                         OR wms_task_status = 1
                        )                                                      --Added for task planning WB. bug#2651318
                 ) wdtv
               ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
                 --wms_person_resource_utt_v v,
                 (SELECT utt_emp.standard_operation_id standard_operation_id
                       , utt_emp.resource_id ROLE
                       , utt_eqp.resource_id equipment
                       , utt_emp.person_id emp_id
                       , utt_eqp.inventory_item_id eqp_id
                       , NULL eqp_srl  /* removed for bug 2095237 */
                              , utt_emp.effective_start_date
                              , utt_emp.effective_end_date
                    FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                               , x_utt_res1.resource_id resource_id
                               , x_emp_r.person_id
                                      , x_emp_r.effective_start_date
                                      , x_emp_r.effective_end_date
                            FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                           WHERE x_utt_res1.resource_id = r1.resource_id
                             AND r1.resource_type = 2
                             AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                       , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                               , x_utt_res2.resource_id resource_id
                               , x_eqp_r.inventory_item_id inventory_item_id
                            FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                           WHERE x_utt_res2.resource_id = r2.resource_id
                             AND r2.resource_type = 1
                             AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                   WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
               , -- inlined wms_person_resource_utt_v, bug 2648133
                 mtl_item_locations_kfv loc
               , --changed to kfv bug#2742611
                 mtl_secondary_inventories sub
               , mtl_txn_request_lines mol
               , mtl_txn_request_headers moh
           --    mtl_system_items msi    -- bug 2648133
        WHERE    v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
             AND wdtv.organization_id = p_sign_on_org_id
             AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
             AND mol.header_id = moh.header_id
             AND moh.move_order_type = 5 -- only WIP jobs are considered : Bug 2666620 BackFlush Removed
             AND wdtv.user_task_type_id = v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                                                                  --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
             AND wdtv.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
             AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
             AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
             AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
             AND wdtv.locator_id = loc.inventory_location_id(+)
             AND wdtv.ZONE = sub.secondary_inventory_name
             AND wdtv.organization_id = sub.organization_id
             AND wdtv.move_order_line_id = mol.line_id
             -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
             -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
             AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                            (
                  SELECT NULL
                    FROM mtl_material_transactions_temp mmtt
                   WHERE mmtt.transaction_temp_id = wdtv.task_id
                     AND mmtt.parent_line_id IS NOT NULL
                     AND mmtt.wms_task_type = wdtv.wms_task_type_id)
             AND NOT EXISTS -- exclude tasks already dispatched
                            (SELECT NULL
                               FROM wms_dispatched_tasks wdt1
                              WHERE wdt1.transaction_temp_id = wdtv.task_id
                                AND wdt1.task_type = wdtv.wms_task_type_id)
             --******************
             AND wdtv.task_id NOT IN -- excluded skipped tasks
                                     (
                  SELECT wdtv.task_id
                    FROM wms_skip_task_exceptions wste, mtl_parameters mp
                   WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                     AND wste.task_id = wdtv.task_id
                     AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                     AND wste.organization_id = mp.organization_id)
        --*****************
        --J Addition
                    AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
         )
        ORDER BY wdtv_task_priority DESC
                 , batch_id
                 , task_status DESC
                 , sub_picking_order
                 , loc_picking_order
                 , xyz_distance
                 , task_id1;
Line: 8423

      SELECT DISTINCT
                   qt.task_id task_id1
         , mol.carton_grouping_id
         , qt.wms_task_type_id
         , NVL(wda.delivery_id, mol.carton_grouping_id) cluster_id
         , DECODE(wda.delivery_id, NULL, 'C', 'D') cluster_type
         , NVL(qt.task_priority,0) wdtv_task_priority -- Bug 4599496
         , sub.secondary_inventory_name sub_secondary_inventory_name
         , sub.picking_order sub_picking_order
         , loc.picking_order loc_picking_order
         , (
         (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
       + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
       + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
      ) xyz_distance
         , loc.concatenated_segments loc_concat_segs
         ,wdt.status task_status --bug 4310093
         ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
              , wdt.effective_start_date
              , wdt.effective_end_date
              , wdt.person_resource_id
              , wdt.machine_resource_id
      FROM wms_dispatched_tasks wdt,
      (SELECT transaction_temp_id task_id
            , standard_operation_id user_task_type_id
            , wms_task_type wms_task_type_id
            , organization_id organization_id
            , subinventory_code ZONE
            , locator_id locator_id
            , task_priority task_priority
            , revision revision
            , lot_number lot_number
            , transaction_uom transaction_uom
            , transaction_quantity transaction_quantity
            , pick_rule_id pick_rule_id
            , pick_slip_number pick_slip_number
            , cartonization_id cartonization_id
            , inventory_item_id
            , move_order_line_id
         FROM mtl_material_transactions_temp
        WHERE wms_task_type IS NOT NULL
          AND transaction_status = 2
          AND Decode(transaction_source_type_id, 2, l_so_allowed,
         8, l_io_allowed) = 1   -- filter out the request so or io
          AND(
         wms_task_status IS NULL
         OR wms_task_status = 1
             )          --Added for task planning WB. bug#2651318
      ) qt
         , (SELECT
             bsor.standard_operation_id,
             bre.resource_id,
             bre.inventory_item_id equipment_id
           FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
           WHERE bsor.resource_id = bre.resource_id
           AND br.resource_type = 1
           AND bsor.resource_id = br.resource_id) e
         , mtl_item_locations_kfv loc
         , --changed to kfv bug#2742611
      mtl_secondary_inventories sub
         , mtl_txn_request_lines mol
         , mtl_txn_request_headers moh
         , --    mtl_system_items msi    -- bug 2648133
      wsh_delivery_details_ob_grp_v wdd
         , -- added
      wsh_delivery_assignments_v wda --added
     WHERE  wdt.transaction_temp_id = qt.task_id
            AND wdt.status in ( 2,3) -- Queued and dispatched tasks only bug 4310093
            AND wdt.person_id = p_sign_on_emp_id
       AND wdt.organization_id = p_sign_on_org_id
       AND qt.wms_task_type_id = 1 -- restrict to picking tasks
       AND mol.header_id = moh.header_id
       AND moh.move_order_type = 3 -- only pick wave move orders are considered
       AND qt.user_task_type_id =
                   e.standard_operation_id(+)                                                       -- join task to resource view, check if user defined task type match
                            --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
       AND qt.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
       AND NVL(qt.cartonization_id, -999) = NVL(p_cartonization_id, NVL(qt.cartonization_id, -999))
       AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
       AND qt.organization_id = loc.organization_id
       AND qt.locator_id = loc.inventory_location_id
       AND qt.ZONE = sub.secondary_inventory_name
       AND qt.organization_id = sub.organization_id
       AND qt.move_order_line_id = mol.line_id
       -- Join with delivery details
       AND(wdd.move_order_line_id = qt.move_order_line_id
      AND wdd.delivery_detail_id = wda.delivery_detail_id)
        UNION ALL
        SELECT DISTINCT wdtv.task_id task_id1
                      , mol.carton_grouping_id
                      , wdtv.wms_task_type_id
                      , NVL(wda.delivery_id, mol.carton_grouping_id) cluster_id
                      , DECODE(wda.delivery_id, NULL, 'C', 'D') cluster_type
                      , nvl(wdtv.task_priority, 0) wdtv_task_priority
                      , sub.secondary_inventory_name sub_secondary_inventory_name
                      , sub.picking_order sub_picking_order
                      , loc.picking_order loc_picking_order
                      , (
                           (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                         + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                         + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                        ) xyz_distance
                      , loc.concatenated_segments loc_concat_segs
                      ,1 task_status
                      ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
                      ,v.effective_start_date
                      ,v.effective_end_date
                      ,v.role person_resource_id
                      ,v.equipment machine_resource_id
                   FROM --wms_dispatchable_tasks_v wdtv,
                        (SELECT transaction_temp_id task_id
                              , standard_operation_id user_task_type_id
                              , wms_task_type wms_task_type_id
                              , organization_id organization_id
                              , subinventory_code ZONE
                              , locator_id locator_id
                              , task_priority task_priority
                              , revision revision
                              , lot_number lot_number
                              , transaction_uom transaction_uom
                              , transaction_quantity transaction_quantity
                              , pick_rule_id pick_rule_id
                              , pick_slip_number pick_slip_number
                              , cartonization_id cartonization_id
                              , inventory_item_id
                              , move_order_line_id
                           FROM mtl_material_transactions_temp
                          WHERE wms_task_type IS NOT NULL
                            AND transaction_status = 2
                            AND Decode(transaction_source_type_id, 2, l_so_allowed,
                                8, l_io_allowed) = 1   -- filter out the request so or io
                            AND(
                                wms_task_status IS NULL
                                OR wms_task_status = 1
                               )          --Added for task planning WB. bug#2651318
                        ) wdtv
                      ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
                        --wms_person_resource_utt_v v,
                        (SELECT utt_emp.standard_operation_id standard_operation_id
                              , utt_emp.resource_id ROLE
                              , utt_eqp.resource_id equipment
                              , utt_emp.person_id emp_id
                              , utt_eqp.inventory_item_id eqp_id
                              , NULL eqp_srl  /* removed for bug 2095237 */
                              , utt_emp.effective_start_date
                              , utt_emp.effective_end_date
                           FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                      , x_utt_res1.resource_id resource_id
                                      , x_emp_r.person_id
                                      , x_emp_r.effective_start_date
                                      , x_emp_r.effective_end_date
                                   FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                  WHERE x_utt_res1.resource_id = r1.resource_id
                                    AND r1.resource_type = 2
                                    AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                              , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                      , x_utt_res2.resource_id resource_id
                                      , x_eqp_r.inventory_item_id inventory_item_id
                                   FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                  WHERE x_utt_res2.resource_id = r2.resource_id
                                    AND r2.resource_type = 1
                                    AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                          WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                      , -- inlined wms_person_resource_utt_v, bug 2648133
                        mtl_item_locations_kfv loc
                      , --changed to kfv bug#2742611
                        mtl_secondary_inventories sub
                      , mtl_txn_request_lines mol
                      , mtl_txn_request_headers moh
                      , --    mtl_system_items msi    -- bug 2648133
                        wsh_delivery_details_ob_grp_v wdd
                      , -- added
                        wsh_delivery_assignments_v wda --added
                  WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                    AND wdtv.organization_id = p_sign_on_org_id
                    AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
                    AND mol.header_id = moh.header_id
                    AND moh.move_order_type = 3 -- only pick wave move orders are considered
                    AND wdtv.user_task_type_id =
                                               v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                                                                       --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
                    AND wdtv.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
                    AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                    AND wdtv.locator_id = loc.inventory_location_id(+)
                    AND wdtv.ZONE = sub.secondary_inventory_name
                    AND wdtv.organization_id = sub.organization_id
                    AND wdtv.move_order_line_id = mol.line_id
                     -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
                    -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
                    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                   (
                         SELECT NULL
                           FROM mtl_material_transactions_temp mmtt
                          WHERE mmtt.transaction_temp_id = wdtv.task_id
                            AND mmtt.parent_line_id IS NOT NULL
                            AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                    AND NOT EXISTS -- exclude tasks already dispatched
                                   (SELECT NULL
                                      FROM wms_dispatched_tasks wdt1
                                     WHERE wdt1.transaction_temp_id = wdtv.task_id
                                       AND wdt1.task_type = wdtv.wms_task_type_id)
                    -- Join with delivery details
                    AND(wdd.move_order_line_id = wdtv.move_order_line_id
                        AND wdd.delivery_detail_id = wda.delivery_detail_id)
                    --******************
                    AND wdtv.task_id NOT IN -- excluded skipped tasks
                                            (
                         SELECT wdtv.task_id
                           FROM wms_skip_task_exceptions wste, mtl_parameters mp
                          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                            AND wste.task_id = wdtv.task_id
                            AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                            AND wste.organization_id = mp.organization_id)
        --*****************
                        --J Addition
                            AND  wdtv.ZONE not in (
                            SELECT wd.subinventory_code
                           FROM  wms_devices_b wd
                              , wms_bus_event_devices wbed
                           WHERE 1 = 1
                           and wd.device_id = wbed.device_id
                           AND wbed.organization_id = wd.organization_id
                           AND wd.enabled_flag   = 'Y'
                           AND wbed.enabled_flag = 'Y'
                           AND wbed.business_event_id = 10
                           AND wd.subinventory_code IS NOT NULL
                           AND wd.force_sign_on_flag = 'Y'
                           AND wd.device_id NOT IN (SELECT device_id
                                    FROM wms_device_assignment_temp
                                   WHERE employee_id = p_sign_on_emp_id)
                        )
        UNION ALL
        SELECT DISTINCT
                  wdtv.task_id task_id1
               , mol.carton_grouping_id
               , wdtv.wms_task_type_id
               , mol.carton_grouping_id cluster_id
               , 'C' cluster_type
               , nvl(wdtv.task_priority, 0) wdtv_task_priority
               , sub.secondary_inventory_name sub_secondary_inventory_name
               , sub.picking_order sub_picking_order
               , loc.picking_order loc_picking_order
               , (
                    (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                  + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                  + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                 ) xyz_distance
               , loc.concatenated_segments loc_concat_segs
               ,1 task_status
               ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
              , wdt.effective_start_date
              , wdt.effective_end_date
              , wdt.person_resource_id
              , wdt.machine_resource_id
            FROM wms_dispatched_tasks wdt,
                 (SELECT transaction_temp_id task_id
                       , standard_operation_id user_task_type_id
                       , wms_task_type wms_task_type_id
                       , organization_id organization_id
                       , subinventory_code ZONE
                       , locator_id locator_id
                       , task_priority task_priority
                       , revision revision
                       , lot_number lot_number
                       , transaction_uom transaction_uom
                       , transaction_quantity transaction_quantity
                       , pick_rule_id pick_rule_id
                       , pick_slip_number pick_slip_number
                       , cartonization_id cartonization_id
                       , inventory_item_id
                       , move_order_line_id
                    FROM mtl_material_transactions_temp
                   WHERE wms_task_type IS NOT NULL
                     AND transaction_status = 2
                     AND(
                         wms_task_status IS NULL
                         OR wms_task_status = 1
                        )                                                      --Added for task planning WB. bug#2651318
                 ) wdtv
               , (SELECT
                       bsor.standard_operation_id,
                       bre.resource_id,
                       bre.inventory_item_id equipment_id
                     FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
                     WHERE bsor.resource_id = bre.resource_id
                     AND br.resource_type = 1
                     AND bsor.resource_id = br.resource_id) e
               ,  mtl_item_locations_kfv loc
               , --changed to kfv bug#2742611
                 mtl_secondary_inventories sub
               , mtl_txn_request_lines mol
               , mtl_txn_request_headers moh
           --    mtl_system_items msi    -- bug 2648133
        WHERE  wdt.transaction_temp_id = wdtv.task_id
            AND wdt.status = 2 -- Queued tasks only
            AND wdt.person_id = p_sign_on_emp_id
            AND wdt.organization_id = p_sign_on_org_id
             AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
             AND mol.header_id = moh.header_id
             AND moh.move_order_type = 5 -- only WIP jobs are considered : Bug 2666620 BackFlush Removed
             AND wdtv.user_task_type_id = e.standard_operation_id(+)                                                       -- join task to resource view, check if user defined task type match
             AND wdtv.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
             AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
             AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
             AND wdtv.organization_id = loc.organization_id
             AND wdtv.locator_id = loc.inventory_location_id
             AND wdtv.ZONE = sub.secondary_inventory_name
             AND wdtv.organization_id = sub.organization_id
             AND wdtv.move_order_line_id = mol.line_id
        UNION ALL
        -- This will select the WIP Jobs alone
        SELECT DISTINCT
                  wdtv.task_id task_id1
               , mol.carton_grouping_id
               , wdtv.wms_task_type_id
               , mol.carton_grouping_id cluster_id
               , 'C' cluster_type
               , nvl(wdtv.task_priority, 0) wdtv_task_priority
               , sub.secondary_inventory_name sub_secondary_inventory_name
               , sub.picking_order sub_picking_order
               , loc.picking_order loc_picking_order
               , (
                    (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                  + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                  + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                 ) xyz_distance
               , loc.concatenated_segments loc_concat_segs
               ,1 task_status
               ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
                      ,v.effective_start_date
                      ,v.effective_end_date
                      ,v.role person_resource_id
                      ,v.equipment machine_resource_id
            FROM --wms_dispatchable_tasks_v wdtv,
                 (SELECT transaction_temp_id task_id
                       , standard_operation_id user_task_type_id
                       , wms_task_type wms_task_type_id
                       , organization_id organization_id
                       , subinventory_code ZONE
                       , locator_id locator_id
                       , task_priority task_priority
                       , revision revision
                       , lot_number lot_number
                       , transaction_uom transaction_uom
                       , transaction_quantity transaction_quantity
                       , pick_rule_id pick_rule_id
                       , pick_slip_number pick_slip_number
                       , cartonization_id cartonization_id
                       , inventory_item_id
                       , move_order_line_id
                    FROM mtl_material_transactions_temp
                   WHERE wms_task_type IS NOT NULL
                     AND transaction_status = 2
                     AND(
                         wms_task_status IS NULL
                         OR wms_task_status = 1
                        )                                                      --Added for task planning WB. bug#2651318
                 ) wdtv
               ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
                 --wms_person_resource_utt_v v,
                 (SELECT utt_emp.standard_operation_id standard_operation_id
                       , utt_emp.resource_id ROLE
                       , utt_eqp.resource_id equipment
                       , utt_emp.person_id emp_id
                       , utt_eqp.inventory_item_id eqp_id
                       , NULL eqp_srl  /* removed for bug 2095237 */
                              , utt_emp.effective_start_date
                              , utt_emp.effective_end_date
                    FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                               , x_utt_res1.resource_id resource_id
                               , x_emp_r.person_id
                                      , x_emp_r.effective_start_date
                                      , x_emp_r.effective_end_date
                            FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                           WHERE x_utt_res1.resource_id = r1.resource_id
                             AND r1.resource_type = 2
                             AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                       , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                               , x_utt_res2.resource_id resource_id
                               , x_eqp_r.inventory_item_id inventory_item_id
                            FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                           WHERE x_utt_res2.resource_id = r2.resource_id
                             AND r2.resource_type = 1
                             AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                   WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
               , -- inlined wms_person_resource_utt_v, bug 2648133
                 mtl_item_locations_kfv loc
               , --changed to kfv bug#2742611
                 mtl_secondary_inventories sub
               , mtl_txn_request_lines mol
               , mtl_txn_request_headers moh
           --    mtl_system_items msi    -- bug 2648133
        WHERE    v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
             AND wdtv.organization_id = p_sign_on_org_id
             AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
             AND mol.header_id = moh.header_id
             AND moh.move_order_type = 5 -- only WIP jobs are considered : Bug 2666620 BackFlush Removed
             AND wdtv.user_task_type_id = v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                                                                  --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
             AND wdtv.ZONE = p_sign_on_zone --  removed NVL, bug 2648133
             AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
             AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
             AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
             AND wdtv.locator_id = loc.inventory_location_id(+)
             AND wdtv.ZONE = sub.secondary_inventory_name
             AND wdtv.organization_id = sub.organization_id
             AND wdtv.move_order_line_id = mol.line_id
             -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
             -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
             AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                            (
                  SELECT NULL
                    FROM mtl_material_transactions_temp mmtt
                   WHERE mmtt.transaction_temp_id = wdtv.task_id
                     AND mmtt.parent_line_id IS NOT NULL
                     AND mmtt.wms_task_type = wdtv.wms_task_type_id)
             AND NOT EXISTS -- exclude tasks already dispatched
                            (SELECT NULL
                               FROM wms_dispatched_tasks wdt1
                              WHERE wdt1.transaction_temp_id = wdtv.task_id
                                AND wdt1.task_type = wdtv.wms_task_type_id)
             --******************
             AND wdtv.task_id NOT IN -- excluded skipped tasks
                                     (
                  SELECT wdtv.task_id
                    FROM wms_skip_task_exceptions wste, mtl_parameters mp
                   WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                     AND wste.task_id = wdtv.task_id
                     AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                     AND wste.organization_id = mp.organization_id)
        --*****************
        --J Addition
                     AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                       WHERE employee_id = p_sign_on_emp_id)
                            )
     ORDER BY wdtv_task_priority DESC
            , batch_id
            , task_status DESC
            , sub_picking_order
            , loc_picking_order
            , xyz_distance
                      , task_id1;
Line: 8887

      SELECT  DISTINCT
                  qt.task_id task_id1
               , mol.carton_grouping_id
               , qt.wms_task_type_id
               , NVL(wda.delivery_id, mol.carton_grouping_id) cluster_id
               , DECODE(wda.delivery_id, NULL, 'C', 'D') cluster_type
               , NVL(qt.task_priority,0) wdtv_task_priority -- Bug 4599496
               , sub.secondary_inventory_name sub_secondary_inventory_name
               , sub.picking_order sub_picking_order
               , loc.picking_order loc_picking_order
               , (
               (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
             + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
             + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
            ) xyz_distance
               , loc.concatenated_segments loc_concat_segs
               ,wdt.status task_status --bug 4310093
               ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
              , wdt.effective_start_date
              , wdt.effective_end_date
              , wdt.person_resource_id
              , wdt.machine_resource_id
            FROM wms_dispatched_tasks wdt,
            (SELECT transaction_temp_id task_id
                  , standard_operation_id user_task_type_id
                  , wms_task_type wms_task_type_id
                  , organization_id organization_id
                  , subinventory_code ZONE
                  , locator_id locator_id
                  , task_priority task_priority
                  , revision revision
                  , lot_number lot_number
                  , transaction_uom transaction_uom
                  , transaction_quantity transaction_quantity
                  , pick_rule_id pick_rule_id
                  , pick_slip_number pick_slip_number
                  , cartonization_id cartonization_id
                  , inventory_item_id
                  , move_order_line_id
               FROM mtl_material_transactions_temp
              WHERE wms_task_type IS NOT NULL
                AND transaction_status = 2
                AND Decode(transaction_source_type_id, 2, l_so_allowed,
               8, l_io_allowed) = 1   -- filter out the request so or io
                AND(
               wms_task_status IS NULL
               OR wms_task_status = 1
                   )          --Added for task planning WB. bug#2651318
            ) qt
               , (SELECT
                   bsor.standard_operation_id,
                   bre.resource_id,
                   bre.inventory_item_id equipment_id
                 FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
                 WHERE bsor.resource_id = bre.resource_id
                 AND br.resource_type = 1
                 AND bsor.resource_id = br.resource_id) e
               , mtl_item_locations_kfv loc
               , --changed to kfv bug#2742611
            mtl_secondary_inventories sub
               , mtl_txn_request_lines mol
               , mtl_txn_request_headers moh
               , --    mtl_system_items msi    -- bug 2648133
            wsh_delivery_details_ob_grp_v wdd
               , -- added
            wsh_delivery_assignments_v wda --added
           WHERE  wdt.transaction_temp_id = qt.task_id
                  AND wdt.status in( 2,3) -- Queued and dispatched tasks only bug 4310093
                  AND wdt.person_id = p_sign_on_emp_id
             AND wdt.organization_id = p_sign_on_org_id
             AND qt.wms_task_type_id = 1 -- restrict to picking tasks
             AND mol.header_id = moh.header_id
             AND moh.move_order_type = 3 -- only pick wave move orders are considered
             AND qt.user_task_type_id =
                         e.standard_operation_id(+)
             AND NVL(qt.cartonization_id, -999) = NVL(p_cartonization_id, NVL(qt.cartonization_id, -999))
             AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
             AND qt.organization_id = loc.organization_id
             AND qt.locator_id = loc.inventory_location_id
             AND qt.ZONE = sub.secondary_inventory_name
             AND qt.organization_id = sub.organization_id
             AND qt.move_order_line_id = mol.line_id
             -- Join with delivery details
             AND(wdd.move_order_line_id = qt.move_order_line_id
      AND wdd.delivery_detail_id = wda.delivery_detail_id)
       UNION ALL
            SELECT DISTINCT wdtv.task_id task_id1
                            , mol.carton_grouping_id
                            , wdtv.wms_task_type_id
                            , NVL(wda.delivery_id, mol.carton_grouping_id) cluster_id
                            , DECODE(wda.delivery_id, NULL, 'C', 'D') cluster_type
                            , nvl(wdtv.task_priority, 0) wdtv_task_priority
                            , sub.secondary_inventory_name sub_secondary_inventory_name
                            , sub.picking_order sub_picking_order
                            , loc.picking_order loc_picking_order
                            , (
                                 (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                               + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                               + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                              ) xyz_distance
                            , loc.concatenated_segments loc_concat_segs
                            ,1 task_status
                            ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
                      ,v.effective_start_date
                      ,v.effective_end_date
                      ,v.role person_resource_id
                      ,v.equipment machine_resource_id
                         FROM --wms_dispatchable_tasks_v wdtv,
                              (SELECT transaction_temp_id task_id
                                    , standard_operation_id user_task_type_id
                                    , wms_task_type wms_task_type_id
                                    , organization_id organization_id
                                    , subinventory_code ZONE
                                    , locator_id locator_id
                                    , task_priority task_priority
                                    , revision revision
                                    , lot_number lot_number
                                    , transaction_uom transaction_uom
                                    , transaction_quantity transaction_quantity
                                    , pick_rule_id pick_rule_id
                                    , pick_slip_number pick_slip_number
                                    , cartonization_id cartonization_id
                                    , inventory_item_id
                                    , move_order_line_id
                                 FROM mtl_material_transactions_temp
                                WHERE wms_task_type IS NOT NULL
                                  AND transaction_status = 2
                                  AND Decode(transaction_source_type_id, 2, l_so_allowed,
                                      8, l_io_allowed) = 1   -- filter out the request so or io
                                  AND(
                                      wms_task_status IS NULL
                                      OR wms_task_status = 1
                                     )                                                      --Added for task planning WB. bug#2651318
                              ) wdtv
                            ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
                              --wms_person_resource_utt_v v,
                              (SELECT utt_emp.standard_operation_id standard_operation_id
                                    , utt_emp.resource_id ROLE
                                    , utt_eqp.resource_id equipment
                                    , utt_emp.person_id emp_id
                                    , utt_eqp.inventory_item_id eqp_id
                                    , NULL eqp_srl  /* removed for bug 2095237 */
                              , utt_emp.effective_start_date
                              , utt_emp.effective_end_date
                                 FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                            , x_utt_res1.resource_id resource_id
                                            , x_emp_r.person_id
                                      , x_emp_r.effective_start_date
                                      , x_emp_r.effective_end_date
                                         FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                        WHERE x_utt_res1.resource_id = r1.resource_id
                                          AND r1.resource_type = 2
                                          AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                                    , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                            , x_utt_res2.resource_id resource_id
                                            , x_eqp_r.inventory_item_id inventory_item_id
                                         FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                        WHERE x_utt_res2.resource_id = r2.resource_id
                                          AND r2.resource_type = 1
                                          AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                                WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                            , -- inlined wms_person_resource_utt_v, bug 2648133
                              mtl_item_locations_kfv loc
                            , --changed to kfv bug#2742611
                              mtl_secondary_inventories sub
                            , mtl_txn_request_lines mol
                            , mtl_txn_request_headers moh
                            , --    mtl_system_items msi    -- bug 2648133
                              wsh_delivery_details_ob_grp_v wdd
                            , -- added
                              wsh_delivery_assignments_v wda --added
                        WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                          AND wdtv.organization_id = p_sign_on_org_id
                          AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
                          AND mol.header_id = moh.header_id
                          AND moh.move_order_type = 3 -- only pick wave move orders are considered
                          AND wdtv.user_task_type_id =
                                                     v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                          AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                          AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                          AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                          AND wdtv.locator_id = loc.inventory_location_id(+)
                          AND wdtv.ZONE = sub.secondary_inventory_name
                          AND wdtv.organization_id = sub.organization_id
                          AND wdtv.move_order_line_id = mol.line_id
                           -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
                          -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
                          AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                         (
                               SELECT NULL
                                 FROM mtl_material_transactions_temp mmtt
                                WHERE mmtt.transaction_temp_id = wdtv.task_id
                                  AND mmtt.parent_line_id IS NOT NULL
                                  AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                          AND NOT EXISTS -- exclude tasks already dispatched
                                         (SELECT NULL
                                            FROM wms_dispatched_tasks wdt1
                                           WHERE wdt1.transaction_temp_id = wdtv.task_id
                                             AND wdt1.task_type = wdtv.wms_task_type_id)
                          -- Join with delivery details
                          AND(wdd.move_order_line_id = wdtv.move_order_line_id
                              AND wdd.delivery_detail_id = wda.delivery_detail_id)
                          --******************
                          AND wdtv.task_id NOT IN -- excluded skipped tasks
                                                  (
                               SELECT wdtv.task_id
                                 FROM wms_skip_task_exceptions wste, mtl_parameters mp
                                WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                                  AND wste.task_id = wdtv.task_id
                                  AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                                  AND wste.organization_id = mp.organization_id)

                                    --J Addition
                              AND  wdtv.ZONE not in (
                                 SELECT wd.subinventory_code
                                 FROM  wms_devices_b wd
                                     , wms_bus_event_devices wbed
                                 WHERE 1 = 1
                                     and wd.device_id = wbed.device_id
                                    AND wbed.organization_id = wd.organization_id
                                    AND wd.enabled_flag   = 'Y'
                                    AND wbed.enabled_flag = 'Y'
                                    AND wbed.business_event_id = 10
                                    AND wd.subinventory_code IS NOT NULL
                                    AND wd.force_sign_on_flag = 'Y'
                                    AND wd.device_id NOT IN (SELECT device_id
                                                FROM wms_device_assignment_temp
                                               WHERE employee_id = p_sign_on_emp_id)
                           )
         ORDER BY wdtv_task_priority DESC
                 , batch_id
                 , task_status DESC
                 , sub_picking_order
                 , loc_picking_order
                 , xyz_distance
                 , task_id1;
Line: 9127

        SELECT   DISTINCT wdtv.task_id task_id1
               , mol.carton_grouping_id
               , wdtv.wms_task_type_id
               , mol.carton_grouping_id cluster_id
               , 'C' cluster_type
               , nvl(wdtv.task_priority, 0) wdtv_task_priority
               , sub.secondary_inventory_name sub_secondary_inventory_name
               , sub.picking_order sub_picking_order
               , loc.picking_order loc_picking_order
               , (
                    (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                  + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                  + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                 ) xyz_distance
               , loc.concatenated_segments loc_concat_segs
               ,wdt.status task_status  --bug 4310093
               ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
              , wdt.effective_start_date
              , wdt.effective_end_date
              , wdt.person_resource_id
              , wdt.machine_resource_id
            FROM wms_dispatched_tasks wdt,
                 (SELECT transaction_temp_id task_id
                       , standard_operation_id user_task_type_id
                       , wms_task_type wms_task_type_id
                       , organization_id organization_id
                       , subinventory_code ZONE
                       , locator_id locator_id
                       , task_priority task_priority
                       , revision revision
                       , lot_number lot_number
                       , transaction_uom transaction_uom
                       , transaction_quantity transaction_quantity
                       , pick_rule_id pick_rule_id
                       , pick_slip_number pick_slip_number
                       , cartonization_id cartonization_id
                       , inventory_item_id
                       , move_order_line_id
                    FROM mtl_material_transactions_temp
                   WHERE wms_task_type IS NOT NULL
                     AND transaction_status = 2
                     AND(
                         wms_task_status IS NULL
                         OR wms_task_status = 1
                        )                                                      --Added for task planning WB. bug#2651318
                 ) wdtv
               , (SELECT
                       bsor.standard_operation_id,
                       bre.resource_id,
                       bre.inventory_item_id equipment_id
                     FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
                     WHERE bsor.resource_id = bre.resource_id
                     AND br.resource_type = 1
                     AND bsor.resource_id = br.resource_id) e
               ,  mtl_item_locations_kfv loc
               , --changed to kfv bug#2742611
                 mtl_secondary_inventories sub
               , mtl_txn_request_lines mol
               , mtl_txn_request_headers moh
           --    mtl_system_items msi    -- bug 2648133
        WHERE  wdt.transaction_temp_id = wdtv.task_id
            AND wdt.status in ( 2,3) -- Queued and dispatched tasks only bug 4310093
            AND wdt.person_id = p_sign_on_emp_id
            AND wdt.organization_id = p_sign_on_org_id
             AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
             AND mol.header_id = moh.header_id
             AND moh.move_order_type = 5 -- only WIP jobs are considered : Bug 2666620 BackFlush Removed
             AND wdtv.user_task_type_id = e.standard_operation_id(+)                                                       -- join task to resource view, check if user defined task type match
             AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
             AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
             AND wdtv.organization_id = loc.organization_id
             AND wdtv.locator_id = loc.inventory_location_id
             AND wdtv.ZONE = sub.secondary_inventory_name
             AND wdtv.organization_id = sub.organization_id
             AND wdtv.move_order_line_id = mol.line_id
      UNION ALL
      -- This will select the WIP Jobs alone
      SELECT DISTINCT
                  wdtv.task_id task_id1
        , mol.carton_grouping_id
        , wdtv.wms_task_type_id
        , mol.carton_grouping_id cluster_id
        , 'C' cluster_type
        , nvl(wdtv.task_priority, 0) wdtv_task_priority
        , sub.secondary_inventory_name sub_secondary_inventory_name
        , sub.picking_order sub_picking_order
        , loc.picking_order loc_picking_order
        , (
        (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
      + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
      + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
          ) xyz_distance
        , loc.concatenated_segments loc_concat_segs
        ,1 task_status
        ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
                      ,v.effective_start_date
                      ,v.effective_end_date
                      ,v.role person_resource_id
                      ,v.equipment machine_resource_id
     FROM --wms_dispatchable_tasks_v wdtv,
          (SELECT transaction_temp_id task_id
           , standard_operation_id user_task_type_id
           , wms_task_type wms_task_type_id
           , organization_id organization_id
           , subinventory_code ZONE
           , locator_id locator_id
           , task_priority task_priority
           , revision revision
           , lot_number lot_number
           , transaction_uom transaction_uom
           , transaction_quantity transaction_quantity
           , pick_rule_id pick_rule_id
           , pick_slip_number pick_slip_number
           , cartonization_id cartonization_id
           , inventory_item_id
           , move_order_line_id
        FROM mtl_material_transactions_temp
       WHERE wms_task_type IS NOT NULL
         AND transaction_status = 2
         AND(
             wms_task_status IS NULL
             OR wms_task_status = 1
            )                                                      --Added for task planning WB. bug#2651318
          ) wdtv
        ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
          --wms_person_resource_utt_v v,
          (SELECT utt_emp.standard_operation_id standard_operation_id
           , utt_emp.resource_id ROLE
           , utt_eqp.resource_id equipment
           , utt_emp.person_id emp_id
           , utt_eqp.inventory_item_id eqp_id
           , NULL eqp_srl  /* removed for bug 2095237 */
                              , utt_emp.effective_start_date
                              , utt_emp.effective_end_date
        FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
              , x_utt_res1.resource_id resource_id
              , x_emp_r.person_id
                                      , x_emp_r.effective_start_date
                                      , x_emp_r.effective_end_date
           FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
          WHERE x_utt_res1.resource_id = r1.resource_id
            AND r1.resource_type = 2
            AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
           , (SELECT x_utt_res2.standard_operation_id standard_operation_id
              , x_utt_res2.resource_id resource_id
              , x_eqp_r.inventory_item_id inventory_item_id
           FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
          WHERE x_utt_res2.resource_id = r2.resource_id
            AND r2.resource_type = 1
            AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
       WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
        , -- inlined wms_person_resource_utt_v, bug 2648133
          mtl_item_locations_kfv loc
        , --changed to kfv bug#2742611
          mtl_secondary_inventories sub
        , mtl_txn_request_lines mol
        , mtl_txn_request_headers moh
    --    mtl_system_items msi    -- bug 2648133
      WHERE    v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
      AND wdtv.organization_id = p_sign_on_org_id
      AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
      AND mol.header_id = moh.header_id
      AND moh.move_order_type = 5 -- only WIP jobs are considered : Bug 2666620 BackFlush Removed
      AND wdtv.user_task_type_id = v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                        --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
      AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
      AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
      AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
      AND wdtv.locator_id = loc.inventory_location_id(+)
      AND wdtv.ZONE = sub.secondary_inventory_name
      AND wdtv.organization_id = sub.organization_id
      AND wdtv.move_order_line_id = mol.line_id
      -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
      -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
      AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
           (
      SELECT NULL
        FROM mtl_material_transactions_temp mmtt
       WHERE mmtt.transaction_temp_id = wdtv.task_id
         AND mmtt.parent_line_id IS NOT NULL
         AND mmtt.wms_task_type = wdtv.wms_task_type_id)
      AND NOT EXISTS -- exclude tasks already dispatched
           (SELECT NULL
              FROM wms_dispatched_tasks wdt1
             WHERE wdt1.transaction_temp_id = wdtv.task_id
               AND wdt1.task_type = wdtv.wms_task_type_id)
      --******************
      AND wdtv.task_id NOT IN -- excluded skipped tasks
               (
      SELECT wdtv.task_id
        FROM wms_skip_task_exceptions wste, mtl_parameters mp
       WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
         AND wste.task_id = wdtv.task_id
         AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
         AND wste.organization_id = mp.organization_id)
      --*****************
      --J Addition
         AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
         )
      ORDER BY wdtv_task_priority DESC
          , batch_id
          , task_status DESC
          , sub_picking_order
          , loc_picking_order
          , xyz_distance
          , task_id1;
Line: 9351

          SELECT  DISTINCT
                  qt.task_id task_id1
         , mol.carton_grouping_id
         , qt.wms_task_type_id
         , NVL(wda.delivery_id, mol.carton_grouping_id) cluster_id
         , DECODE(wda.delivery_id, NULL, 'C', 'D') cluster_type
         , NVL(qt.task_priority, 0) wdtv_task_priority -- Bug 4599496
         , sub.secondary_inventory_name sub_secondary_inventory_name
         , sub.picking_order sub_picking_order
         , loc.picking_order loc_picking_order
         , (
         (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
       + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
       + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
      ) xyz_distance
         , loc.concatenated_segments loc_concat_segs
         ,wdt.status task_status  --bug 4310093
         ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
              , wdt.effective_start_date
              , wdt.effective_end_date
              , wdt.person_resource_id
              , wdt.machine_resource_id
      FROM wms_dispatched_tasks wdt,
      (SELECT transaction_temp_id task_id
            , standard_operation_id user_task_type_id
            , wms_task_type wms_task_type_id
            , organization_id organization_id
            , subinventory_code ZONE
            , locator_id locator_id
            , task_priority task_priority
            , revision revision
            , lot_number lot_number
            , transaction_uom transaction_uom
            , transaction_quantity transaction_quantity
            , pick_rule_id pick_rule_id
            , pick_slip_number pick_slip_number
            , cartonization_id cartonization_id
            , inventory_item_id
            , move_order_line_id
         FROM mtl_material_transactions_temp
        WHERE wms_task_type IS NOT NULL
          AND transaction_status = 2
          AND Decode(transaction_source_type_id, 2, l_so_allowed,
         8, l_io_allowed) = 1   -- filter out the request so or io
          AND(
         wms_task_status IS NULL
         OR wms_task_status = 1
             )          --Added for task planning WB. bug#2651318
      ) qt
         , (SELECT
             bsor.standard_operation_id,
             bre.resource_id,
             bre.inventory_item_id equipment_id
           FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
           WHERE bsor.resource_id = bre.resource_id
           AND br.resource_type = 1
           AND bsor.resource_id = br.resource_id) e
         , mtl_item_locations_kfv loc
         , --changed to kfv bug#2742611
      mtl_secondary_inventories sub
         , mtl_txn_request_lines mol
         , mtl_txn_request_headers moh
         , --    mtl_system_items msi    -- bug 2648133
      wsh_delivery_details_ob_grp_v wdd
         , -- added
      wsh_delivery_assignments_v wda --added
     WHERE  wdt.transaction_temp_id = qt.task_id
        AND wdt.status in ( 2,3) -- Queued and dispatched tasks only bug 4310093
        AND wdt.person_id = p_sign_on_emp_id
       AND wdt.organization_id = p_sign_on_org_id
       AND qt.wms_task_type_id = 1 -- restrict to picking tasks
       AND mol.header_id = moh.header_id
       AND moh.move_order_type = 3 -- only pick wave move orders are considered
       AND qt.user_task_type_id =
                   e.standard_operation_id(+)
       AND NVL(qt.cartonization_id, -999) = NVL(p_cartonization_id, NVL(qt.cartonization_id, -999))
       AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
       AND qt.organization_id = loc.organization_id
       AND qt.locator_id = loc.inventory_location_id
       AND qt.ZONE = sub.secondary_inventory_name
       AND qt.organization_id = sub.organization_id
       AND qt.move_order_line_id = mol.line_id
       -- Join with delivery details
       AND(wdd.move_order_line_id = qt.move_order_line_id
      AND wdd.delivery_detail_id = wda.delivery_detail_id)
        UNION ALL
        SELECT DISTINCT wdtv.task_id task_id1
                      , mol.carton_grouping_id
                      , wdtv.wms_task_type_id
                      , NVL(wda.delivery_id, mol.carton_grouping_id) cluster_id
                      , DECODE(wda.delivery_id, NULL, 'C', 'D') cluster_type
                      , nvl(wdtv.task_priority, 0) wdtv_task_priority
                      , sub.secondary_inventory_name sub_secondary_inventory_name
                      , sub.picking_order sub_picking_order
                      , loc.picking_order loc_picking_order
                      , (
                           (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                         + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                         + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                        ) xyz_distance
                      , loc.concatenated_segments loc_concat_segs
                      ,1 task_status
                      ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
                      ,v.effective_start_date
                      ,v.effective_end_date
                      ,v.role person_resource_id
                      ,v.equipment machine_resource_id
                   FROM --wms_dispatchable_tasks_v wdtv,
                        (SELECT transaction_temp_id task_id
                              , standard_operation_id user_task_type_id
                              , wms_task_type wms_task_type_id
                              , organization_id organization_id
                              , subinventory_code ZONE
                              , locator_id locator_id
                              , task_priority task_priority
                              , revision revision
                              , lot_number lot_number
                              , transaction_uom transaction_uom
                              , transaction_quantity transaction_quantity
                              , pick_rule_id pick_rule_id
                              , pick_slip_number pick_slip_number
                              , cartonization_id cartonization_id
                              , inventory_item_id
                              , move_order_line_id
                           FROM mtl_material_transactions_temp
                          WHERE wms_task_type IS NOT NULL
                            AND transaction_status = 2
                            AND Decode(transaction_source_type_id, 2, l_so_allowed,
                                8, l_io_allowed) = 1   -- filter out the request so or io
                            AND(
                                wms_task_status IS NULL
                                OR wms_task_status = 1
                               )                                                      --Added for task planning WB. bug#2651318
                        ) wdtv
                      ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
                        --wms_person_resource_utt_v v,
                        (SELECT utt_emp.standard_operation_id standard_operation_id
                              , utt_emp.resource_id ROLE
                              , utt_eqp.resource_id equipment
                              , utt_emp.person_id emp_id
                              , utt_eqp.inventory_item_id eqp_id
                              , NULL eqp_srl  /* removed for bug 2095237 */
                              , utt_emp.effective_start_date
                              , utt_emp.effective_end_date
                           FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                                      , x_utt_res1.resource_id resource_id
                                      , x_emp_r.person_id
                                      , x_emp_r.effective_start_date
                                      , x_emp_r.effective_end_date
                                   FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                                  WHERE x_utt_res1.resource_id = r1.resource_id
                                    AND r1.resource_type = 2
                                    AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                              , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                                      , x_utt_res2.resource_id resource_id
                                      , x_eqp_r.inventory_item_id inventory_item_id
                                   FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                                  WHERE x_utt_res2.resource_id = r2.resource_id
                                    AND r2.resource_type = 1
                                    AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                          WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
                      , -- inlined wms_person_resource_utt_v, bug 2648133
                        mtl_item_locations_kfv loc
                      , --changed to kfv bug#2742611
                        mtl_secondary_inventories sub
                      , mtl_txn_request_lines mol
                      , mtl_txn_request_headers moh
                      , --    mtl_system_items msi    -- bug 2648133
                        wsh_delivery_details_ob_grp_v wdd
                      , -- added
                        wsh_delivery_assignments_v wda --added
                  WHERE v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
                    AND wdtv.organization_id = p_sign_on_org_id
                    AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
                    AND mol.header_id = moh.header_id
                    AND moh.move_order_type = 3 -- only pick wave move orders are considered
                    AND wdtv.user_task_type_id =
                                               v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                                                                       --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
                    AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
                    AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
                    AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
                    AND wdtv.locator_id = loc.inventory_location_id(+)
                    AND wdtv.ZONE = sub.secondary_inventory_name
                    AND wdtv.organization_id = sub.organization_id
                    AND wdtv.move_order_line_id = mol.line_id
                     -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
                    -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
                    AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                                   (
                         SELECT NULL
                           FROM mtl_material_transactions_temp mmtt
                          WHERE mmtt.transaction_temp_id = wdtv.task_id
                            AND mmtt.parent_line_id IS NOT NULL
                            AND mmtt.wms_task_type = wdtv.wms_task_type_id)
                    AND NOT EXISTS -- exclude tasks already dispatched
                                   (SELECT NULL
                                      FROM wms_dispatched_tasks wdt1
                                     WHERE wdt1.transaction_temp_id = wdtv.task_id
                                       AND wdt1.task_type = wdtv.wms_task_type_id)
                    -- Join with delivery details
                    AND(wdd.move_order_line_id = wdtv.move_order_line_id
                        AND wdd.delivery_detail_id = wda.delivery_detail_id)
                    --******************
                    AND wdtv.task_id NOT IN -- excluded skipped tasks
                                            (
                         SELECT wdtv.task_id
                           FROM wms_skip_task_exceptions wste, mtl_parameters mp
                          WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                            AND wste.task_id = wdtv.task_id
                            AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                            AND wste.organization_id = mp.organization_id)
        --*****************
                  --J Addition
                               AND  wdtv.ZONE not in (
                        SELECT wd.subinventory_code
                        FROM  wms_devices_b wd
                            , wms_bus_event_devices wbed
                        WHERE 1 = 1
                            and wd.device_id = wbed.device_id
                           AND wbed.organization_id = wd.organization_id
                           AND wd.enabled_flag   = 'Y'
                           AND wbed.enabled_flag = 'Y'
                           AND wbed.business_event_id = 10
                           AND wd.subinventory_code IS NOT NULL
                           AND wd.force_sign_on_flag = 'Y'
                           AND wd.device_id NOT IN (SELECT device_id
                                       FROM wms_device_assignment_temp
                                      WHERE employee_id = p_sign_on_emp_id)
                  )
        UNION ALL
   SELECT DISTINCT
                  wdtv.task_id task_id1
          , mol.carton_grouping_id
          , wdtv.wms_task_type_id
          , mol.carton_grouping_id cluster_id
          , 'C' cluster_type
          , nvl(wdtv.task_priority, 0) wdtv_task_priority
          , sub.secondary_inventory_name sub_secondary_inventory_name
          , sub.picking_order sub_picking_order
          , loc.picking_order loc_picking_order
          , (
          (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
        + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
        + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
       ) xyz_distance
          , loc.concatenated_segments loc_concat_segs
          ,1 task_status
          ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
              , wdt.effective_start_date
              , wdt.effective_end_date
              , wdt.person_resource_id
              , wdt.machine_resource_id
       FROM wms_dispatched_tasks wdt,
       (SELECT transaction_temp_id task_id
             , standard_operation_id user_task_type_id
             , wms_task_type wms_task_type_id
             , organization_id organization_id
             , subinventory_code ZONE
             , locator_id locator_id
             , task_priority task_priority
             , revision revision
             , lot_number lot_number
             , transaction_uom transaction_uom
             , transaction_quantity transaction_quantity
             , pick_rule_id pick_rule_id
             , pick_slip_number pick_slip_number
             , cartonization_id cartonization_id
             , inventory_item_id
             , move_order_line_id
          FROM mtl_material_transactions_temp
         WHERE wms_task_type IS NOT NULL
           AND transaction_status = 2
           AND(
          wms_task_status IS NULL
          OR wms_task_status = 1
         )                                                      --Added for task planning WB. bug#2651318
       ) wdtv
          , (SELECT
             bsor.standard_operation_id,
             bre.resource_id,
             bre.inventory_item_id equipment_id
           FROM bom_std_op_resources bsor, bom_resources br, bom_resource_equipments bre
           WHERE bsor.resource_id = bre.resource_id
           AND br.resource_type = 1
           AND bsor.resource_id = br.resource_id) e
          ,  mtl_item_locations_kfv loc
          , --changed to kfv bug#2742611
       mtl_secondary_inventories sub
          , mtl_txn_request_lines mol
          , mtl_txn_request_headers moh
      --    mtl_system_items msi    -- bug 2648133
   WHERE  wdt.transaction_temp_id = wdtv.task_id
       AND wdt.status = 2 -- Queued tasks only
       AND wdt.person_id = p_sign_on_emp_id
       AND wdt.organization_id = p_sign_on_org_id
        AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
        AND mol.header_id = moh.header_id
        AND moh.move_order_type = 5 -- only WIP jobs are considered : Bug 2666620 BackFlush Removed
        AND wdtv.user_task_type_id = e.standard_operation_id(+)                                                       -- join task to resource view, check if user defined task type match
        AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
        AND NVL(e.equipment_id, -999) = NVL(l_sign_on_equipment_id, NVL(e.equipment_id, -999))
        AND wdtv.organization_id = loc.organization_id
        AND wdtv.locator_id = loc.inventory_location_id
        AND wdtv.ZONE = sub.secondary_inventory_name
        AND wdtv.organization_id = sub.organization_id
        AND wdtv.move_order_line_id = mol.line_id
        UNION ALL
        -- This will select the WIP Jobs alone
        SELECT DISTINCT
                  wdtv.task_id task_id1
               , mol.carton_grouping_id
               , wdtv.wms_task_type_id
               , mol.carton_grouping_id cluster_id
               , 'C' cluster_type
               , nvl(wdtv.task_priority, 0) wdtv_task_priority
               , sub.secondary_inventory_name sub_secondary_inventory_name
               , sub.picking_order sub_picking_order
               , loc.picking_order loc_picking_order
               , (
                    (nvl(loc.x_coordinate, 0) - l_cur_x) *(nvl(loc.x_coordinate, 0) - l_cur_x)
                  + (nvl(loc.y_coordinate, 0) - l_cur_y) *(nvl(loc.y_coordinate, 0) - l_cur_y)
                  + (nvl(loc.z_coordinate, 0) - l_cur_z) *(nvl(loc.z_coordinate, 0) - l_cur_z)
                 ) xyz_distance
               , loc.concatenated_segments loc_concat_segs
               ,1 task_status
               ,DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL) batch_id
                      ,v.effective_start_date
                      ,v.effective_end_date
                      ,v.role person_resource_id
                      ,v.equipment machine_resource_id
            FROM --wms_dispatchable_tasks_v wdtv,
                 (SELECT transaction_temp_id task_id
                       , standard_operation_id user_task_type_id
                       , wms_task_type wms_task_type_id
                       , organization_id organization_id
                       , subinventory_code ZONE
                       , locator_id locator_id
                       , task_priority task_priority
                       , revision revision
                       , lot_number lot_number
                       , transaction_uom transaction_uom
                       , transaction_quantity transaction_quantity
                       , pick_rule_id pick_rule_id
                       , pick_slip_number pick_slip_number
                       , cartonization_id cartonization_id
                       , inventory_item_id
                       , move_order_line_id
                    FROM mtl_material_transactions_temp
                   WHERE wms_task_type IS NOT NULL
                     AND transaction_status = 2
                     AND(
                         wms_task_status IS NULL
                         OR wms_task_status = 1
                        )                                                      --Added for task planning WB. bug#2651318
                 ) wdtv
               ,          -- inlined wms_dispatchable_tasks_v, bug 2648133
                 --wms_person_resource_utt_v v,
                 (SELECT utt_emp.standard_operation_id standard_operation_id
                       , utt_emp.resource_id ROLE
                       , utt_eqp.resource_id equipment
                       , utt_emp.person_id emp_id
                       , utt_eqp.inventory_item_id eqp_id
                       , NULL eqp_srl  /* removed for bug 2095237 */
                              , utt_emp.effective_start_date
                              , utt_emp.effective_end_date
                    FROM (SELECT x_utt_res1.standard_operation_id standard_operation_id
                               , x_utt_res1.resource_id resource_id
                               , x_emp_r.person_id
                                      , x_emp_r.effective_start_date
                                      , x_emp_r.effective_end_date
                            FROM bom_std_op_resources x_utt_res1, bom_resources r1, bom_resource_employees x_emp_r
                           WHERE x_utt_res1.resource_id = r1.resource_id
                             AND r1.resource_type = 2
                             AND x_utt_res1.resource_id = x_emp_r.resource_id) utt_emp
                       , (SELECT x_utt_res2.standard_operation_id standard_operation_id
                               , x_utt_res2.resource_id resource_id
                               , x_eqp_r.inventory_item_id inventory_item_id
                            FROM bom_std_op_resources x_utt_res2, bom_resources r2, bom_resource_equipments x_eqp_r
                           WHERE x_utt_res2.resource_id = r2.resource_id
                             AND r2.resource_type = 1
                             AND x_utt_res2.resource_id = x_eqp_r.resource_id) utt_eqp
                   WHERE utt_emp.standard_operation_id = utt_eqp.standard_operation_id(+)) v
               , -- inlined wms_person_resource_utt_v, bug 2648133
                 mtl_item_locations_kfv loc
               , --changed to kfv bug#2742611
                 mtl_secondary_inventories sub
               , mtl_txn_request_lines mol
               , mtl_txn_request_headers moh
           --    mtl_system_items msi    -- bug 2648133
        WHERE    v.emp_id = p_sign_on_emp_id -- restrict to sign on employee
             AND wdtv.organization_id = p_sign_on_org_id
             AND wdtv.wms_task_type_id = 1 -- restrict to picking tasks
             AND mol.header_id = moh.header_id
             AND moh.move_order_type = 5 -- only WIP jobs are considered : Bug 2666620 BackFlush Removed
             AND wdtv.user_task_type_id = v.standard_operation_id                                                        -- join task to resource view, check if user defined task type match
                                                                  --AND Nvl(wdtv.zone, '@@@') = Nvl(p_sign_on_zone, Nvl(wdtv.zone, '@@@'))
             AND NVL(wdtv.cartonization_id, -999) = NVL(p_cartonization_id, NVL(wdtv.cartonization_id, -999))
             AND NVL(v.eqp_id, -999) = NVL(l_sign_on_equipment_id, NVL(v.eqp_id, -999))
             AND wdtv.organization_id = loc.organization_id(+) -- join task to loc, outer join for tasks do not have locator
             AND wdtv.locator_id = loc.inventory_location_id(+)
             AND wdtv.ZONE = sub.secondary_inventory_name
             AND wdtv.organization_id = sub.organization_id
             AND wdtv.move_order_line_id = mol.line_id
             -- AND wdtv.organization_id = msi.organization_id    -- bug 2648133
             -- AND wdtv.inventory_item_id = msi.inventory_item_id -- bug 2648133
             AND NOT EXISTS -- exclude child tasks for consolidated bulk tasks
                            (
                  SELECT NULL
                    FROM mtl_material_transactions_temp mmtt
                   WHERE mmtt.transaction_temp_id = wdtv.task_id
                     AND mmtt.parent_line_id IS NOT NULL
                     AND mmtt.wms_task_type = wdtv.wms_task_type_id)
             AND NOT EXISTS -- exclude tasks already dispatched
                            (SELECT NULL
                               FROM wms_dispatched_tasks wdt1
                              WHERE wdt1.transaction_temp_id = wdtv.task_id
                                AND wdt1.task_type = wdtv.wms_task_type_id)
             --******************
             AND wdtv.task_id NOT IN -- excluded skipped tasks
                                     (
                  SELECT wdtv.task_id
                    FROM wms_skip_task_exceptions wste, mtl_parameters mp
                   WHERE ((SYSDATE - wste.creation_date) * 24 * 60) < mp.skip_task_waiting_minutes
                     AND wste.task_id = wdtv.task_id
                     AND wste.wms_task_type = NVL(l_sys_task_type, wste.wms_task_type)
                     AND wste.organization_id = mp.organization_id)
        --*****************
        --J Addition
                     AND  wdtv.ZONE not in (
            SELECT wd.subinventory_code
            FROM  wms_devices_b wd
                , wms_bus_event_devices wbed
            WHERE 1 = 1
                and wd.device_id = wbed.device_id
               AND wbed.organization_id = wd.organization_id
               AND wd.enabled_flag   = 'Y'
               AND wbed.enabled_flag = 'Y'
               AND wbed.business_event_id = 10
               AND wd.subinventory_code IS NOT NULL
               AND wd.force_sign_on_flag = 'Y'
               AND wd.device_id NOT IN (SELECT device_id
                           FROM wms_device_assignment_temp
                          WHERE employee_id = p_sign_on_emp_id)
            )
        ORDER BY wdtv_task_priority DESC
       , batch_id -- DECODE (L_SEQUENCE_PICKS_ACROSS_WAVES, 2, MOL.HEADER_ID, NULL)
       , task_status DESC
       , sub_picking_order
       , loc_picking_order
       , xyz_distance
                 , task_id1;
Line: 9805

      SELECT task_filter_source, task_filter_value
        FROM wms_task_filter_b wtf, wms_task_filter_dtl wtfd
        WHERE task_filter_name = v_filter_name
        AND wtf.task_filter_id = wtfd.task_filter_id;
Line: 9868

                  'SELECT  wdtv.task_id, wdtv.zone, wdtv.locator_id,
                          wdtv.revision, wdtv.transaction_uom,
                          wdtv.transaction_quantity, wdtv.lot_number, wdtv.wms_task_type_id,nvl(wdtv.task_priority, 0)
                   FROM    wms_dispatchable_tasks_v wdtv
                   WHERE   wdtv.organization_id = ' || p_sign_on_org_id ||'
                          AND Nvl(wdtv.zone, ''@@@'') = Nvl('''|| p_sign_on_zone || ''', Nvl(wdtv.zone, ''@@@''))
                          AND wdtv.user_task_type_id IN
                          (
                           SELECT standard_operation_id
                           FROM wms_person_resource_utt_v v
                           WHERE v.emp_id = ' || p_sign_on_emp_id  ||'
                           AND Nvl(v.eqp_srl, ''@@@'') = Nvl(''' || l_sign_on_equipment_srl || ''', Nvl(v.eqp_srl, ''@@@''))
                           AND Nvl(v.eqp_id, -999) = Nvl(' || l_equipment_id_str ||', Nvl(v.eqp_id, -999))
                           )
                          --***********
                          AND wdtv.task_id NOT IN
                          (SELECT wdtv.task_id FROM wms_skip_task_exceptions wste, mtl_parameters mp
                           WHERE ((SYSDATE - wste.creation_date)*24*60) < mp.skip_task_waiting_minutes
                           AND wste.task_id = wdtv.task_id
                           AND wste.organization_id = mp.organization_id )
                          --************
                          AND wdtv.task_id NOT IN
                          (SELECT wdt1.transaction_temp_id
                           FROM wms_dispatched_tasks wdt1
                           --   WHERE wdt1.status = 1
                           UNION ALL
                           SELECT wdt2.transaction_temp_id
                           FROM wms_exceptions wms_except, wms_dispatched_tasks wdt2
                           WHERE wms_except.person_id = ' || p_sign_on_emp_id || '
                           AND wdt2.task_id = wms_except.task_id
                           AND discrepancy_type = 1
                           )
                    ORDER BY wdtv.pick_slip_number, nvl(wdtv.task_priority, 0), wdtv.task_id';
Line: 9913

        SELECT transaction_temp_id
             , task_type
             , loaded_time
          INTO l_last_loaded_task_id
             , l_last_loaded_task_type
             , l_last_loaded_time
          FROM (SELECT transaction_temp_id
                     , task_type
                     , loaded_time
                  FROM wms_dispatched_tasks wdt
                 WHERE wdt.person_id = p_sign_on_emp_id
                   AND wdt.loaded_time = (SELECT MAX(loaded_time)
                                            FROM wms_dispatched_tasks
                                           WHERE person_id = p_sign_on_emp_id))
         WHERE ROWNUM = 1; -- make sure only one task selected
Line: 9945

        SELECT transaction_id
             , task_type
             , loaded_time
          INTO l_last_dropoff_task_id
             , l_last_dropoff_task_type
             , l_last_dropoff_time
          FROM (SELECT transaction_id
                     , task_type
                     , loaded_time
                  FROM wms_dispatched_tasks_history wdth
                 WHERE wdth.person_id = p_sign_on_emp_id
                   AND wdth.drop_off_time = (SELECT MAX(drop_off_time)
                                               FROM wms_dispatched_tasks_history
                                              WHERE person_id = p_sign_on_emp_id))
         WHERE ROWNUM = 1; -- make sure only one task selected
Line: 10002

            SELECT NVL(loc.x_coordinate, 0)
                 , NVL(loc.y_coordinate, 0)
                 , NVL(loc.z_coordinate, 0)
              INTO l_cur_x
                 , l_cur_y
                 , l_cur_z
              FROM mtl_item_locations loc, wms_dispatchable_tasks_v wdtv
             WHERE wdtv.locator_id = loc.inventory_location_id
               AND wdtv.organization_id = loc.organization_id
               AND wdtv.task_id = l_last_task_id
               AND wdtv.wms_task_type_id = l_last_task_type;
Line: 10032

              SELECT NVL(loc.x_coordinate, 0)
                   , NVL(loc.y_coordinate, 0)
                   , NVL(loc.z_coordinate, 0)
                INTO l_cur_x
                   , l_cur_y
                   , l_cur_z
                FROM mtl_item_locations loc, mtl_material_transactions mmt
               WHERE mmt.locator_id = loc.inventory_location_id
                 AND mmt.organization_id = loc.organization_id
                 AND mmt.transaction_set_id = l_last_task_id
                 AND ROWNUM = 1;
Line: 10057

              SELECT NVL(loc.x_coordinate, 0)
                   , NVL(loc.y_coordinate, 0)
                   , NVL(loc.z_coordinate, 0)
                INTO l_cur_x
                   , l_cur_y
                   , l_cur_z
                FROM mtl_item_locations loc, mtl_cycle_count_entries mcce
               WHERE mcce.locator_id = loc.inventory_location_id
                 AND mcce.organization_id = loc.organization_id
                 AND mcce.cycle_count_entry_id = l_last_task_id;
Line: 10386

                SELECT     mmtt.transaction_temp_id
                      INTO t_opt_task_id(idx)
                      FROM mtl_material_transactions_temp mmtt
                     WHERE mmtt.transaction_temp_id = t_opt_task_id(idx)
                FOR UPDATE NOWAIT;
Line: 10416

                        print_debug('Insert task '||t_opt_task_id(idx)||' Effective start date'||t_effective_start_date(idx),4);
Line: 10418

                    INSERT INTO wms_ordered_tasks
                            (
                             task_id
                           , wms_task_type
                           , task_sequence_id
                           , effective_start_date
                           , effective_end_date
                           , person_resource_id
                           , machine_resource_id
                            )
                     VALUES (
                             t_opt_task_id(idx)
                           , t_opt_task_type(idx)
                           , l_ordered_tasks_count
                           , t_effective_start_date(idx)
                           , t_effective_end_date(idx)
                           , t_person_resource_id(idx)
                           , t_machine_resource_id(idx)
                            );
Line: 10438

                      INSERT INTO wms_ordered_tasks
                              (
                               task_id
                             , wms_task_type
                             , task_sequence_id
                              )
                       VALUES (
                               t_opt_task_id(idx)
                             , t_opt_task_type(idx)
                             , l_ordered_tasks_count
                              );
Line: 10465

                  SELECT     mmtt.transaction_temp_id
                        INTO t_opt_task_id(idx)
                        FROM mtl_material_transactions_temp mmtt
                       WHERE mmtt.transaction_temp_id = t_opt_task_id(idx)
                  FOR UPDATE NOWAIT;
Line: 10491

                        print_debug('Insert task '||t_opt_task_id(idx)||' Effective start date'||
                                     t_effective_start_date(idx),4);
Line: 10494

                    INSERT INTO wms_ordered_tasks
                            (
                             task_id
                           , wms_task_type
                           , task_sequence_id
                           , effective_start_date
                           , effective_end_date
                           , person_resource_id
                           , machine_resource_id
                            )
                     VALUES (
                             t_opt_task_id(idx)
                           , t_opt_task_type(idx)
                           , l_ordered_tasks_count
                           , t_effective_start_date(idx)
                           , t_effective_end_date(idx)
                           , t_person_resource_id(idx)
                           , t_machine_resource_id(idx)
                            );
Line: 10514

                      INSERT INTO wms_ordered_tasks
                              (
                               task_id
                             , wms_task_type
                             , task_sequence_id
                              )
                       VALUES (
                               t_opt_task_id(idx)
                             , t_opt_task_type(idx)
                             , l_ordered_tasks_count
                              );
Line: 10649

      SELECT   mmtt.transaction_temp_id task_id
             , mmtt.subinventory_code ZONE
             , mmtt.locator_id locator_id
             , mmtt.revision revision
             , mmtt.transaction_uom transaction_uom
             , mmtt.transaction_quantity transaction_quantity
             , '' lot_number
             , mmtt.wms_task_type wms_task_type_id
             , mmtt.task_priority task_priority
             , mmtt.operation_plan_id,
          mmtt.standard_operation_id,
          wot.effective_start_date,
          wot.effective_end_date,
          wot.person_resource_id,
          wot.machine_resource_id,
          mmtt.move_order_line_id
          FROM mtl_material_transactions_temp mmtt, wms_ordered_tasks wot
         WHERE mmtt.wms_task_type IS NOT NULL
           AND mmtt.transaction_status = 2
           AND mmtt.transaction_temp_id = wot.task_id
           AND mmtt.transaction_temp_id > 0
      ORDER BY wot.task_sequence_id;
Line: 10756

      SELECT mmtt.transaction_temp_id
        FROM wms_cartonization_temp mmtt, mtl_txn_request_lines mol
       WHERE mmtt.move_order_line_id = mol.line_id
         AND mol.header_id = p_move_order_header_id;
Line: 10764

      SELECT mmtt.transaction_temp_id
        FROM wms_cartonization_temp mmtt
        WHERE
             mmtt.parent_line_id   is null     -- non bulked tasks
         OR mmtt.parent_line_id = mmtt.transaction_temp_id;   -- parent line only
Line: 10783

    SELECT move_order_type
      INTO l_move_order_type
      FROM mtl_txn_request_headers
     WHERE header_id = p_move_order_header_id;
Line: 10916

      SELECT equip.internal_volume equip_vol
           , -- equipment volume capacity
             equip.maximum_load_weight equip_weight
           , -- equipment weight capacity
             item.unit_volume item_vol
           , -- item unit volume
             item.unit_weight item_weight
           , -- item unit weight
             equip.volume_uom_code equip_v_uom
           , -- equipment volumn UOM code
             equip.weight_uom_code equip_w_uom
           , -- equipment weight UOM code
             item.volume_uom_code item_v_uom
           , -- item volume UOM code
             item.weight_uom_code item_w_uom -- item weight UOM code
        FROM mtl_system_items equip
           , mtl_system_items item
           , bom_resource_equipments res_equip
           , bom_resources res
           , bom_std_op_resources tt_x_res
       WHERE tt_x_res.standard_operation_id = p_standard_operation_id --join task with task_type-resource x-ref
         AND tt_x_res.resource_id = res.resource_id -- join with resource
         AND res.resource_type = 1 -- resource type for equipment
         AND res_equip.resource_id = tt_x_res.resource_id -- join with resource-equip x-ref
         AND equip.inventory_item_id = res_equip.inventory_item_id -- join with equipment (mtl_system_items)
         AND equip.organization_id = res_equip.organization_id
         AND item.inventory_item_id = p_item_id -- join with item for the item that is transfered
         AND item.organization_id = p_organization_id;
Line: 10953

    SELECT primary_uom_code
      INTO l_item_prim_uom_code
      FROM mtl_system_items
     WHERE inventory_item_id = p_item_id
       AND organization_id = p_organization_id;
Line: 11099

    l_last_update_date           DATE;
Line: 11100

    l_last_updated_by            NUMBER;
Line: 11141

      SELECT   SYSDATE last_update_date
             , g_user_id last_updated_by
             , SYSDATE creation_date
             , g_user_id created_by
             , mmtt.inventory_item_id
             , mmtt.revision
             , mmtt.organization_id
             , mmtt.subinventory_code
             , mmtt.locator_id
             , SUM(mmtt.transaction_quantity)
             , SUM(mmtt.primary_quantity)
             , mmtt.transaction_uom
             , mmtt.transaction_type_id
             , mmtt.transaction_action_id
             , mmtt.transaction_source_type_id
             , MAX(mmtt.transaction_date)
             , MAX(mmtt.acct_period_id)
             , MIN(mmtt.pick_slip_number) -- the earliest created pick slip
             , MIN(mmtt.move_order_line_id) -- any line_id within this header
             , mmtt.transfer_organization
             , mmtt.transfer_subinventory
             , mmtt.transfer_to_location
             , mmtt.wms_task_type
             , mmtt.standard_operation_id
             , MAX(mmtt.task_priority)
             , mmtt.cost_group_id
             , MAX(mmtt.transaction_header_id)
             , mmtt.container_item_id
             , mmtt.cartonization_id
             , mmtt.operation_plan_id
        , mol.carton_grouping_id
        , mmtt.wms_task_status -- carry forward task status also for unreleased/pending statuses
             -- Bug 4584538
             , mmtt.item_primary_uom_code
             , mmtt.item_lot_control_code
             , mmtt.item_serial_control_code
             , mmtt.serial_allocated_flag
             -- Bug 4584538
          FROM wms_cartonization_temp mmtt, mtl_txn_request_lines mol
         WHERE mmtt.move_order_line_id = mol.line_id
           AND mol.header_id = p_move_order_header_id
           AND mmtt.wms_task_type NOT IN(5, 6)
           AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
           AND( EXISTS(SELECT 1
                         FROM mtl_txn_request_headers moh, wsh_pick_grouping_rules spg
                        WHERE spg.pick_grouping_rule_id = moh.grouping_rule_id
                          AND spg.pick_method = '4'
                          AND moh.header_id = mol.header_id)
               OR EXISTS(SELECT 1
                           FROM mtl_system_items msi
                          WHERE msi.inventory_item_id = mmtt.inventory_item_id
                            AND msi.bulk_picked_flag = 'Y')
              )
           AND EXISTS ( SELECT 1 -- Only Consolidate Tasks for Plain item
                          FROM mtl_system_items msi2
                         WHERE msi2.inventory_item_id = mmtt.inventory_item_id
                           AND msi2.lot_control_code = 1
                           AND(msi2.serial_number_control_code = 1
                               OR msi2.serial_number_control_code = 6))
      GROUP BY mmtt.inventory_item_id
             , mmtt.revision
             , mmtt.organization_id
             , mmtt.subinventory_code
             , mmtt.locator_id
             , mmtt.transaction_uom
             , mmtt.transaction_type_id
             , mmtt.transaction_action_id
             , mmtt.transaction_source_type_id
             , mmtt.transfer_organization
             , mmtt.transfer_subinventory
             , mmtt.transfer_to_location
             , mmtt.wms_task_type
             , mmtt.standard_operation_id
             , mmtt.cost_group_id
             , mmtt.container_item_id
             , mmtt.cartonization_id
             , mmtt.operation_plan_id
             , mol.carton_grouping_id -- only consolidate tasks with the same carton_grouping_id (hense delivery)
             , mmtt.wms_task_status
             -- Bug 4584538
             , mmtt.item_primary_uom_code
             , mmtt.item_lot_control_code
             , mmtt.item_serial_control_code
             , mmtt.serial_allocated_flag
             -- Bug 4584538
      HAVING SUM(mmtt.transaction_quantity) <> MIN(mmtt.transaction_quantity) -- make sure one line will not get consolidated
           AND 'Y' <> is_equipment_cap_exceeded(
                        mmtt.standard_operation_id
                      , mmtt.inventory_item_id
                      , mmtt.organization_id
                      , SUM(mmtt.transaction_quantity)
                      , mmtt.transaction_uom
                      ); -- make sure the consolidated quantity does not exceed minimum equipment capacity, this is to make sure a consolidated task will not be splitted later
Line: 11236

      SELECT   SYSDATE last_update_date
             , g_user_id last_updated_by
             , SYSDATE creation_date
             , g_user_id created_by
             , mmtt.inventory_item_id
             , mmtt.revision
             , mmtt.organization_id
             , mmtt.subinventory_code
             , mmtt.locator_id
             , SUM(mmtt.transaction_quantity)
             , SUM(mmtt.primary_quantity)
             , mmtt.transaction_uom
             , mmtt.transaction_type_id
             , mmtt.transaction_action_id
             , mmtt.transaction_source_type_id
             , MAX(mmtt.transaction_date)
             , MAX(mmtt.acct_period_id)
             , MIN(mmtt.pick_slip_number) -- the earliest created pick slip
             , MIN(mmtt.move_order_line_id) -- any line_id within this header
             , mmtt.transfer_organization
             , ''
             , NULL
             , mmtt.wms_task_type
             , mmtt.standard_operation_id
             , MAX(mmtt.task_priority)
             , mmtt.cost_group_id
             , MAX(mmtt.transaction_header_id)
             , mmtt.container_item_id
             , mmtt.cartonization_id
             , mmtt.operation_plan_id
        , NULL
        , mmtt.wms_task_status -- carry forward task status also for unreleased/pending statuses
             -- Bug 4584538
             , mmtt.item_primary_uom_code
             , mmtt.item_lot_control_code
             , mmtt.item_serial_control_code
             , mmtt.serial_allocated_flag
             -- Bug 4584538
          FROM wms_cartonization_temp mmtt, mtl_txn_request_lines mol
         WHERE mmtt.move_order_line_id = mol.line_id
           AND mol.header_id = p_move_order_header_id
           AND mmtt.wms_task_type NOT IN(5, 6)
           AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
           AND( EXISTS(SELECT 1
                         FROM mtl_txn_request_headers moh, wsh_pick_grouping_rules spg
                        WHERE spg.pick_grouping_rule_id = moh.grouping_rule_id
                          AND spg.pick_method = '4'
                          AND moh.header_id = mol.header_id)
               OR EXISTS(SELECT 1
                           FROM mtl_system_items msi
                          WHERE msi.inventory_item_id = mmtt.inventory_item_id
                            AND msi.bulk_picked_flag = 'Y')
              )
           AND EXISTS( SELECT 1 -- Only Consolidate Tasks for Plain item
                         FROM mtl_system_items msi2
                        WHERE msi2.inventory_item_id = mmtt.inventory_item_id
                          AND msi2.lot_control_code = 1
                          AND(msi2.serial_number_control_code = 1
                              OR msi2.serial_number_control_code = 6))
      GROUP BY mmtt.inventory_item_id
             , mmtt.revision
             , mmtt.organization_id
             , mmtt.subinventory_code
             , mmtt.locator_id
             , mmtt.transaction_uom
             , mmtt.transaction_type_id
             , mmtt.transaction_action_id
             , mmtt.transaction_source_type_id
             , mmtt.transfer_organization
             , mmtt.wms_task_type
             , mmtt.standard_operation_id
             , mmtt.cost_group_id
             , mmtt.container_item_id
             , mmtt.cartonization_id
             , mmtt.operation_plan_id
        , mmtt.wms_task_status
             -- Bug 4584538
             , mmtt.item_primary_uom_code
             , mmtt.item_lot_control_code
             , mmtt.item_serial_control_code
             , mmtt.serial_allocated_flag
             -- Bug 4584538
      HAVING   SUM(mmtt.transaction_quantity) <> MIN(mmtt.transaction_quantity) -- make sure one line will not get consolidated
             AND 'Y' <> is_equipment_cap_exceeded(
                        mmtt.standard_operation_id
                      , mmtt.inventory_item_id
                      , mmtt.organization_id
                      , SUM(mmtt.transaction_quantity)
                      , mmtt.transaction_uom
                      ); -- make sure the consolidated quantity does not exceed minimum equipment capacity, this is to make sure a consolidated task will not be splitted later
Line: 11338

    SELECT move_order_type
      INTO l_move_order_type
      FROM mtl_txn_request_headers
     WHERE header_id = p_move_order_header_id;
Line: 11351

        FETCH task_list_wip INTO l_last_update_date
                               , l_last_updated_by
                               , l_creation_date
                               , l_created_by
                               , l_inventory_item_id
                               , l_revision
                               , l_organization_id
                               , l_subinventory_code
                               , l_locator_id
                               , l_transaction_quantity
                               , l_primary_quantity
                               , l_transaction_uom
                               , l_transaction_type_id
                               , l_transaction_action_id
                               , l_transaction_source_type_id
                               , l_transaction_date
                               , l_acct_period_id
                               , l_pick_slip_number
                               , l_move_order_line_id
                               , l_to_org_id
                               , l_to_sub
                               , l_to_loc_id
                               , l_wms_task_type
                               , l_standard_operation_id
                               , l_task_priority
                               , l_cost_group_id
                               , l_transaction_header_id
                               , l_container_item_id
                               , l_cartonization_id
                               , l_operation_plan_id
                               , l_carton_grouping_id
                               , l_wms_task_status
                               -- Bug 4584538
                               , l_primary_uom_code
                               , l_lot_control_code
                               , l_serial_control_code
                               , l_serial_allocated_flag;
Line: 11391

        FETCH task_list INTO  l_last_update_date
                            , l_last_updated_by
                            , l_creation_date
                            , l_created_by
                            , l_inventory_item_id
                            , l_revision
                            , l_organization_id
                            , l_subinventory_code
                            , l_locator_id
                            , l_transaction_quantity
                            , l_primary_quantity
                            , l_transaction_uom
                            , l_transaction_type_id
                            , l_transaction_action_id
                            , l_transaction_source_type_id
                            , l_transaction_date
                            , l_acct_period_id
                            , l_pick_slip_number
                            , l_move_order_line_id
                            , l_to_org_id
                            , l_to_sub
                            , l_to_loc_id
                            , l_wms_task_type
                            , l_standard_operation_id
                            , l_task_priority
                            , l_cost_group_id
                            , l_transaction_header_id
                            , l_container_item_id
                            , l_cartonization_id
                            , l_operation_plan_id
                            , l_carton_grouping_id
                            , l_wms_task_status
                            -- Bug 4584538
                            , l_primary_uom_code
                            , l_lot_control_code
                            , l_serial_control_code
                            , l_serial_allocated_flag;
Line: 11469

      INSERT INTO wms_cartonization_temp
                  (
                    transaction_header_id
                  , transaction_temp_id
                  , posting_flag
                  , transaction_status
                  , last_update_date
                  , last_updated_by
                  , creation_date
                  , created_by
                  , transaction_type_id
                  , transaction_action_id
                  , transaction_source_type_id
                  , organization_id
                  , inventory_item_id
                  , revision
                  , subinventory_code
                  , locator_id
                  , transfer_organization
                  , transfer_subinventory
                  , transfer_to_location
                  , transaction_quantity
                  , primary_quantity
                  , transaction_uom
                  , transaction_date
                  , acct_period_id
                  , cost_group_id
                  -- , move_order_line_id   keep same as patchset J
                  , pick_slip_number
                  , standard_operation_id
                  , wms_task_type
                  , task_priority
                  , container_item_id
                  , cartonization_id
                  , operation_plan_id
                  , wms_task_status
                  , parent_line_id
                  -- Bug 4584538
                  , item_primary_uom_code
                  , item_lot_control_code
                  , item_serial_control_code
                  , serial_allocated_flag
                  -- Bug 4584538
                  )
           VALUES (
                    l_transaction_header_id
                  --, l_new_txn_temp_id
		  , mtl_material_transactions_s.NEXTVAL --Bug 5535030
                  , 'N'
                  , 2
                  , l_last_update_date
                  , l_last_updated_by
                  , l_creation_date
                  , l_created_by
                  , l_transaction_type_id
                  , l_transaction_action_id
                  , l_transaction_source_type_id
                  , l_organization_id
                  , l_inventory_item_id
                  , l_revision
                  , l_subinventory_code
                  , l_locator_id
                  , l_to_org_id
                  , l_to_sub
                  , l_to_loc_id
                  , l_transaction_quantity
                  , l_primary_quantity
                  , l_transaction_uom
                  , l_transaction_date
                  , l_acct_period_id
                  , l_cost_group_id
                  -- , l_move_order_line_id  keep same as patchset J
                  , l_pick_slip_number
                  , l_standard_operation_id
                  , l_wms_task_type
                  , l_task_priority
                  , l_container_item_id
                  , l_cartonization_id
                  , l_operation_plan_id
                  , l_wms_task_status
   --               , l_new_txn_temp_id      -- have the same as patchset J
		  , mtl_material_transactions_s.CURRVAL
                  -- Bug 4584538
                  , l_primary_uom_code
                  , l_lot_control_code
                  , l_serial_control_code
                  , l_serial_allocated_flag
                  -- Bug 4584538
             ) RETURNING transaction_temp_id INTO l_new_txn_temp_id ;
Line: 11564

      UPDATE wms_cartonization_temp
         SET parent_line_id = l_new_txn_temp_id
       WHERE transaction_temp_id <> l_new_txn_temp_id
         AND inventory_item_id = l_inventory_item_id
         AND NVL(revision, '#$%') = NVL(l_revision, NVL(revision, '#$%'))
         AND organization_id = l_organization_id
         AND subinventory_code = l_subinventory_code
         AND NVL(locator_id, -1) = NVL(l_locator_id, NVL(locator_id, -1))
         AND NVL(transfer_organization, -1) = NVL(l_to_org_id, NVL(transfer_organization, -1))
         AND NVL(transfer_to_location, -1) = NVL(l_to_loc_id, NVL(transfer_to_location, -1))
         AND NVL(transfer_subinventory, '#$%') = NVL(l_to_sub, NVL(transfer_subinventory, '#$%'))
         AND transaction_uom = l_transaction_uom
         AND NVL(transaction_type_id, -1) = NVL(l_transaction_type_id, NVL(transaction_type_id, -1))
         AND NVL(transaction_action_id, -1) = NVL(l_transaction_action_id, NVL(transaction_action_id, -1))
         AND NVL(transaction_source_type_id, -1) = NVL(l_transaction_source_type_id, NVL(transaction_source_type_id, -1))
         AND NVL(cost_group_id, -1) = NVL(l_cost_group_id, NVL(cost_group_id, -1))
         AND NVL(container_item_id, -1) = NVL(l_container_item_id, NVL(container_item_id, -1))
         AND NVL(cartonization_id, -1) = NVL(l_cartonization_id, NVL(cartonization_id, -1))
         AND EXISTS(SELECT 1
                      FROM mtl_txn_request_lines mol
                     WHERE mol.line_id = move_order_line_id
                       AND mol.header_id = p_move_order_header_id
                       AND NVL(mol.carton_grouping_id,-1) = NVL(l_carton_grouping_id,NVL(mol.carton_grouping_id,-1)));
Line: 11632

    l_last_update_date           DATE;
Line: 11633

    l_last_updated_by            NUMBER;
Line: 11677

      SELECT   SYSDATE last_update_date
             , g_user_id last_updated_by
             , SYSDATE creation_date
             , g_user_id created_by
             , mmtt.inventory_item_id
             , mmtt.revision
             , mmtt.organization_id
             , mmtt.subinventory_code
             , mmtt.locator_id
             , SUM(mmtt.transaction_quantity)
             , SUM(mmtt.primary_quantity)
             , mmtt.transaction_uom
             , mmtt.transaction_type_id
             , mmtt.transaction_action_id
             , mmtt.transaction_source_type_id
             , MAX(mmtt.transaction_date)
             , MAX(mmtt.acct_period_id)
             , mmtt.transfer_organization
             , mmtt.wms_task_type
             , MAX(mmtt.task_priority)
             , mmtt.cost_group_id
             , MAX(mmtt.transaction_header_id)
             , mmtt.container_item_id
             , mmtt.operation_plan_id
        , mmtt.wms_task_status -- carry forward task status also for unreleased/pending statuses
        , nvl(wda.delivery_id, mol.carton_grouping_id)
        , mmtt.item_primary_uom_code
        , mmtt.item_lot_control_code
        , mmtt.item_serial_control_code
        , mmtt.serial_allocated_flag
          FROM wms_cartonization_temp mmtt, mtl_txn_request_lines mol,wsh_delivery_details_ob_grp_v wdd,wsh_delivery_assignments_v wda
         WHERE mmtt.move_order_line_id = mol.line_id
           -- AND mol.header_id = p_move_order_header_id -- no need since wct only have the records in concerns
           AND mol.line_id = wdd.move_ordeR_line_id
           AND wdd.delivery_detail_id = wda.delivery_detail_id
           AND mmtt.wms_task_type NOT IN(5, 6)
           AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
           AND mmtt.cartonization_id is null -- only bulk non_cartoned lines
           AND ( mmtt.serial_allocated_flag = 'N'  -- do not bulk serial allocated lines
                 or mmtt.serial_allocated_flag is null)
           AND(l_bulk_pick_control = WMS_GLOBALS.BULK_PICK_ENTIRE_WAVE
          -- if bulk picking is not disabled and not pick entire wave only the honor sub/item is left, so no need to check l_bulk_pick_control, only need to check the sub/item  flag
          OR EXISTS(SELECT 1   -- sub is bulk picking enabled
                    FROM mtl_secondary_inventories msi
                    WHERE msi.secondary_inventory_name = mmtt.subinventory_code
                      AND msi.organization_id = mmtt.organization_id
                      AND msi.enable_bulk_pick= 'Y')
          OR EXISTS(SELECT 1   -- item is bulk picking enabled
                    FROM mtl_system_items msi
                    WHERE msi.inventory_item_id = mmtt.inventory_item_id
                      AND msi.bulk_picked_flag = 'Y')
          )
      GROUP BY mmtt.inventory_item_id
             , mmtt.revision
             , mmtt.organization_id
             , mmtt.subinventory_code
             , mmtt.locator_id
             , mmtt.transaction_uom
             , mmtt.transaction_type_id
             , mmtt.transaction_action_id
             , mmtt.transaction_source_type_id
             , mmtt.transfer_organization
             , mmtt.wms_task_type
             , mmtt.cost_group_id
             , mmtt.container_item_id
             , mmtt.operation_plan_id
             , nvl(wda.delivery_id, mol.carton_grouping_id) -- only consolidate tasks with the same carton_grouping_id (hense delivery) if the delivery is checked in the rule
             , mmtt.wms_task_status
             , mmtt.item_primary_uom_code
             , mmtt.item_lot_control_code
             , mmtt.item_serial_control_code
             , mmtt.serial_allocated_flag
      HAVING SUM(mmtt.transaction_quantity) <> MIN(mmtt.transaction_quantity) -- make sure one line will not get consolidated
           ;
Line: 11753

          SELECT   SYSDATE last_update_date
                 , g_user_id last_updated_by
                 , SYSDATE creation_date
                 , g_user_id created_by
                 , mmtt.inventory_item_id
                 , mmtt.revision
                 , mmtt.organization_id
                 , mmtt.subinventory_code
                 , mmtt.locator_id
                 , SUM(mmtt.transaction_quantity)
                 , SUM(mmtt.primary_quantity)
                 , mmtt.transaction_uom
                 , mmtt.transaction_type_id
                 , mmtt.transaction_action_id
                 , mmtt.transaction_source_type_id
                 , MAX(mmtt.transaction_date)
                 , MAX(mmtt.acct_period_id)
                 , mmtt.transfer_organization
                 , mmtt.wms_task_type
                 , MAX(mmtt.task_priority)
                 , mmtt.cost_group_id
                 , MAX(mmtt.transaction_header_id)
                 , mmtt.container_item_id
                 , mmtt.operation_plan_id
               , mmtt.wms_task_status -- carry forward task status also for unreleased/pending statuses
             , mmtt.item_primary_uom_code
          , mmtt.item_lot_control_code
          , mmtt.item_serial_control_code
            , mmtt.serial_allocated_flag
              FROM wms_cartonization_temp mmtt
             WHERE
                   mmtt.wms_task_type NOT IN(5, 6)
               AND mmtt.allocated_lpn_id IS NULL -- if lpn allocated, no need to do consolidation
               AND mmtt.cartonization_id is null -- only bulk non_cartoned lines
                AND ( mmtt.serial_allocated_flag = 'N'  -- do not bulk serial allocated lines
                 or mmtt.serial_allocated_flag is null)
               AND(l_bulk_pick_control = WMS_GLOBALS.BULK_PICK_ENTIRE_WAVE
             -- if bulk picking is not disabled and not pick entire wave only the honor sub/item is left, so no need to check l_bulk_pick_control, only need to check the sub/item  flag
             OR EXISTS(SELECT 1   -- sub is bulk picking enabled
                       FROM mtl_secondary_inventories msi
                       WHERE msi.secondary_inventory_name = mmtt.subinventory_code
                         AND msi.organization_id = mmtt.organization_id
                         AND msi.enable_bulk_pick= 'Y')
             OR EXISTS(SELECT 1   -- item is bulk picking enabled
                       FROM mtl_system_items msi
                       WHERE msi.inventory_item_id = mmtt.inventory_item_id
                         AND msi.bulk_picked_flag = 'Y')
             )
          GROUP BY mmtt.inventory_item_id
                 , mmtt.revision
                 , mmtt.organization_id
                 , mmtt.subinventory_code
                 , mmtt.locator_id
                 , mmtt.transaction_uom
                 , mmtt.transaction_type_id
                 , mmtt.transaction_action_id
                 , mmtt.transaction_source_type_id
                 , mmtt.transfer_organization
                 , mmtt.wms_task_type
                 , mmtt.cost_group_id
                 , mmtt.container_item_id
                 , mmtt.operation_plan_id
                 , mmtt.wms_task_status
             , mmtt.item_primary_uom_code
             , mmtt.item_lot_control_code
             , mmtt.item_serial_control_code
             , mmtt.serial_allocated_flag
         HAVING SUM(mmtt.transaction_quantity) <> MIN(mmtt.transaction_quantity) -- make sure one line will not get consolidated
           ;
Line: 11828

           SELECT   SYSDATE last_update_date
                  , g_user_id last_updated_by
                  , SYSDATE creation_date
                  , g_user_id created_by
                  , mmtt.inventory_item_id
                  , mmtt.revision
                  , mmtt.organization_id
                  , mmtt.subinventory_code
                  , mmtt.locator_id
                  , SUM(mmtt.transaction_quantity)
                  , SUM(mmtt.primary_quantity)
                  , mmtt.transaction_uom
                  , mmtt.transaction_type_id
                  , mmtt.transaction_action_id
                  , mmtt.transaction_source_type_id
                  , MAX(mmtt.transaction_date)
                  , MAX(mmtt.acct_period_id)
                  , mmtt.transfer_organization
                  , mmtt.wms_task_type
                  , MAX(mmtt.task_priority)
                  , mmtt.cost_group_id
                  , MAX(mmtt.transaction_header_id)
                  , mmtt.container_item_id
                  , mmtt.operation_plan_id
                , mmtt.wms_task_status -- carry forward task status also for unreleased/pending statuses
                , nvl(wda.delivery_id, mol.carton_grouping_id)
             , mmtt.item_primary_uom_code
             , mmtt.item_lot_control_code
             , mmtt.item_serial_control_code
             , mmtt.serial_allocated_flag
               FROM wms_cartonization_temp mmtt, mtl_txn_request_lines mol,
                    wsh_delivery_details_ob_grp_v wdd,wsh_delivery_assignments_v wda
               WHERE mmtt.move_order_line_id = mol.line_id
                AND ( mmtt.serial_allocated_flag = 'N'  -- do not bulk serial allocated lines
                      or mmtt.serial_allocated_flag is null)
           AND mol.line_id = wdd.move_ordeR_line_id
           AND wdd.delivery_Detail_id = wda.delivery_detail_id
           GROUP BY mmtt.inventory_item_id
                  , mmtt.revision
                  , mmtt.organization_id
                  , mmtt.subinventory_code
                  , mmtt.locator_id
                  , mmtt.transaction_uom
                  , mmtt.transaction_type_id
                  , mmtt.transaction_action_id
                  , mmtt.transaction_source_type_id
                  , mmtt.transfer_organization
                  , mmtt.wms_task_type
                  , mmtt.cost_group_id
                  , mmtt.container_item_id
                  , mmtt.operation_plan_id
                  , nvl(wda.delivery_id, mol.carton_grouping_id) -- only consolidate tasks with the same carton_grouping_id (hense delivery) if the delivery is checked in the rule
                  , mmtt.wms_task_status
             , mmtt.item_primary_uom_code
             , mmtt.item_lot_control_code
             , mmtt.item_serial_control_code
             , mmtt.serial_allocated_flag
         HAVING SUM(mmtt.transaction_quantity) <> MIN(mmtt.transaction_quantity) -- make sure one line will not get consolidated
                ;
Line: 11889

                SELECT   SYSDATE last_update_date
                       , g_user_id last_updated_by
                       , SYSDATE creation_date
                       , g_user_id created_by
                       , mmtt.inventory_item_id
                       , mmtt.revision
                       , mmtt.organization_id
                       , mmtt.subinventory_code
                       , mmtt.locator_id
                       , SUM(mmtt.transaction_quantity)
                       , SUM(mmtt.primary_quantity)
                       , mmtt.transaction_uom
                       , mmtt.transaction_type_id
                       , mmtt.transaction_action_id
                       , mmtt.transaction_source_type_id
                       , MAX(mmtt.transaction_date)
                       , MAX(mmtt.acct_period_id)
                       , mmtt.transfer_organization
                       , mmtt.wms_task_type
                       , MAX(mmtt.task_priority)
                       , mmtt.cost_group_id
                       , MAX(mmtt.transaction_header_id)
                       , mmtt.container_item_id
                       , mmtt.operation_plan_id
                   , mmtt.wms_task_status -- carry forward task status also for unreleased/pending statuses
             , mmtt.item_primary_uom_code
             , mmtt.item_lot_control_code
             , mmtt.item_serial_control_code
             , mmtt.serial_allocated_flag
                    FROM wms_cartonization_temp mmtt
                    WHERE  mmtt.serial_allocated_flag = 'N'  -- do not bulk serial allocated lines
                           or mmtt.serial_allocated_flag is null
                GROUP BY mmtt.inventory_item_id
                       , mmtt.revision
                       , mmtt.organization_id
                       , mmtt.subinventory_code
                       , mmtt.locator_id
                       , mmtt.transaction_uom
                       , mmtt.transaction_type_id
                       , mmtt.transaction_action_id
                       , mmtt.transaction_source_type_id
                       , mmtt.transfer_organization
                       , mmtt.wms_task_type
                       , mmtt.cost_group_id
                       , mmtt.container_item_id
                       , mmtt.operation_plan_id
                       , mmtt.wms_task_status
             , mmtt.item_primary_uom_code
             , mmtt.item_lot_control_code
             , mmtt.item_serial_control_code
             , mmtt.serial_allocated_flag
               HAVING SUM(mmtt.transaction_quantity) <> MIN(mmtt.transaction_quantity) -- make sure one line will not get consolidated
                     ;
Line: 11977

        Select DELIVERY_FLAG
        Into l_delivery_flag
        From WSH_PICK_GROUPING_RULES
        Where pick_method=WMS_GLOBALS.PICK_METHOD_BULK
          and user_defined_flag = 'N'  -- bulk picking default rule
          and rownum <2; -- in case of psudo translation, multiple records are inserted for the seeded rule
Line: 11985

   SELECT spg.bulk_pick_control
   into l_bulk_pick_control
   FROM wsh_pick_grouping_rules spg
        WHERE spg.pick_grouping_rule_id = INV_CACHE.mtrh_rec.grouping_rule_id;
Line: 12015

        Select DELIVERY_FLAG
   Into l_delivery_flag
   From WSH_PICK_GROUPING_RULES
        Where pick_method=WMS_GLOBALS.PICK_METHOD_BULK
          and user_defined_flag = 'N'  -- default rule
          and rownum <2; -- in case of psudo translation, multiple records are inserted for the seeded rule
Line: 12044

        FETCH task_list INTO  l_last_update_date
                            , l_last_updated_by
                            , l_creation_date
                            , l_created_by
                            , l_inventory_item_id
                            , l_revision
                            , l_organization_id
                            , l_subinventory_code
                            , l_locator_id
                            , l_transaction_quantity
                            , l_primary_quantity
                            , l_transaction_uom
                            , l_transaction_type_id
                            , l_transaction_action_id
                            , l_transaction_source_type_id
                            , l_transaction_date
                            , l_acct_period_id
                            , l_to_org_id
                            , l_wms_task_type
                            , l_task_priority
                            , l_cost_group_id
                            , l_transaction_header_id
                            , l_container_item_id
                            , l_operation_plan_id
                       , l_wms_task_status
                       , l_carton_grouping_id
                       , l_primary_uom_code
                       , l_lot_control_code
                       , l_serial_control_code
                       , l_serial_allocated_flag;
Line: 12076

        FETCH task_list_cross_delivery INTO  l_last_update_date
                               , l_last_updated_by
                               , l_creation_date
                               , l_created_by
                               , l_inventory_item_id
                               , l_revision
                               , l_organization_id
                               , l_subinventory_code
                               , l_locator_id
                               , l_transaction_quantity
                               , l_primary_quantity
                               , l_transaction_uom
                               , l_transaction_type_id
                               , l_transaction_action_id
                               , l_transaction_source_type_id
                               , l_transaction_date
                               , l_acct_period_id
                               , l_to_org_id
                               , l_wms_task_type
                               , l_task_priority
                               , l_cost_group_id
                               , l_transaction_header_id
                               , l_container_item_id
                               , l_operation_plan_id
                               , l_wms_task_status
                               , l_primary_uom_code
                               , l_lot_control_code
                               , l_serial_control_code
                               , l_serial_allocated_flag;
Line: 12109

        FETCH task_list_con INTO  l_last_update_date
                               , l_last_updated_by
                               , l_creation_date
                               , l_created_by
                               , l_inventory_item_id
                               , l_revision
                               , l_organization_id
                               , l_subinventory_code
                               , l_locator_id
                               , l_transaction_quantity
                               , l_primary_quantity
                               , l_transaction_uom
                               , l_transaction_type_id
                               , l_transaction_action_id
                               , l_transaction_source_type_id
                               , l_transaction_date
                               , l_acct_period_id
                               , l_to_org_id
                               , l_wms_task_type
                               , l_task_priority
                               , l_cost_group_id
                               , l_transaction_header_id
                               , l_container_item_id
                               , l_operation_plan_id
                          , l_wms_task_status
                          , l_carton_grouping_id
                               , l_primary_uom_code
                               , l_lot_control_code
                               , l_serial_control_code
                               , l_serial_allocated_flag;
Line: 12141

        FETCH task_list_con_cd INTO  l_last_update_date
                                  , l_last_updated_by
                                  , l_creation_date
                                  , l_created_by
                                  , l_inventory_item_id
                                  , l_revision
                                  , l_organization_id
                                  , l_subinventory_code
                                  , l_locator_id
                                  , l_transaction_quantity
                                  , l_primary_quantity
                                  , l_transaction_uom
                                  , l_transaction_type_id
                                  , l_transaction_action_id
                                  , l_transaction_source_type_id
                                  , l_transaction_date
                                  , l_acct_period_id
                                  , l_to_org_id
                                  , l_wms_task_type
                                  , l_task_priority
                                  , l_cost_group_id
                                  , l_transaction_header_id
                                  , l_container_item_id
                                  , l_operation_plan_id
                                  , l_wms_task_status
                                       , l_primary_uom_code
                                       , l_lot_control_code
                                       , l_serial_control_code
                                       , l_serial_allocated_flag;
Line: 12202

      INSERT INTO wms_cartonization_temp
                  (
                    transaction_header_id
                  , transaction_temp_id
                  , posting_flag
                  , transaction_status
                  , last_update_date
                  , last_updated_by
                  , creation_date
                  , created_by
                  , transaction_type_id
                  , transaction_action_id
                  , transaction_source_type_id
                  , organization_id
                  , inventory_item_id
                  , revision
                  , subinventory_code
                  , locator_id
                  , transfer_organization
                  , transaction_quantity
                  , primary_quantity
                  , transaction_uom
                  , transaction_date
                  , acct_period_id
                  , cost_group_id
                  , wms_task_type
                  , task_priority
                  , container_item_id
             , operation_plan_id
             , wms_task_status
             , parent_line_id
        , item_primary_uom_code
        , item_lot_control_code
        , item_serial_control_code
             , serial_allocated_flag
                  )
           VALUES (
                    l_transaction_header_id
                  --, l_new_txn_temp_id
		  , mtl_material_transactions_s.NEXTVAL --Bug 5535030
                  , 'N'
                  , 2
                  , l_last_update_date
                  , l_last_updated_by
                  , l_creation_date
                  , l_created_by
                  , l_transaction_type_id
                  , l_transaction_action_id
                  , l_transaction_source_type_id
                  , l_organization_id
                  , l_inventory_item_id
                  , l_revision
                  , l_subinventory_code
                  , l_locator_id
                  , l_to_org_id
                  , l_transaction_quantity
                  , l_primary_quantity
                  , l_transaction_uom
                  , l_transaction_date
                  , l_acct_period_id
                  , l_cost_group_id
                  , l_wms_task_type
                  , l_task_priority
                  , l_container_item_id
                  , l_operation_plan_id
             , l_wms_task_status
             --, l_new_txn_temp_id
	, mtl_material_transactions_s.CURRVAL
        , l_primary_uom_code
        , l_lot_control_code
        , l_serial_control_code
        , l_serial_allocated_flag
             )RETURNING transaction_temp_id INTO l_new_txn_temp_id ;
Line: 12282

      UPDATE wms_cartonization_temp wct
         SET parent_line_id = l_new_txn_temp_id
       WHERE transaction_temp_id <> l_new_txn_temp_id
         AND inventory_item_id = l_inventory_item_id
         AND NVL(revision, '#$%') = NVL(l_revision, NVL(revision, '#$%'))
         AND organization_id = l_organization_id
         AND subinventory_code = l_subinventory_code
         AND NVL(locator_id, -1) = NVL(l_locator_id, NVL(locator_id, -1))
         AND NVL(transfer_organization, -1) = NVL(l_to_org_id, NVL(transfer_organization, -1))
         AND transaction_uom = l_transaction_uom
         AND NVL(transaction_type_id, -1) = NVL(l_transaction_type_id, NVL(transaction_type_id, -1))
         AND NVL(transaction_action_id, -1) = NVL(l_transaction_action_id, NVL(transaction_action_id, -1))
         AND NVL(transaction_source_type_id, -1) = NVL(l_transaction_source_type_id, NVL(transaction_source_type_id, -1))
         AND NVL(cost_group_id, -1) = NVL(l_cost_group_id, NVL(cost_group_id, -1))
         AND EXISTS(SELECT 1
                      FROM mtl_txn_request_lines mol,wsh_delivery_details_ob_grp_v wdd,wsh_delivery_assignments_v wda
                     WHERE mol.line_id = wct.move_order_line_id
                       AND mol.line_id = wdd.move_ordeR_line_id
                       AND wdd.delivery_detail_id = wda.delivery_detail_id
                       AND NVL(wda.delivery_id,mol.carton_grouping_id) = l_carton_grouping_id);
Line: 12303

      UPDATE wms_cartonization_temp
               SET parent_line_id = l_new_txn_temp_id
             WHERE transaction_temp_id <> l_new_txn_temp_id
               AND inventory_item_id = l_inventory_item_id
               AND NVL(revision, '#$%') = NVL(l_revision, NVL(revision, '#$%'))
               AND organization_id = l_organization_id
               AND subinventory_code = l_subinventory_code
               AND NVL(locator_id, -1) = NVL(l_locator_id, NVL(locator_id, -1))
               AND NVL(transfer_organization, -1) = NVL(l_to_org_id, NVL(transfer_organization, -1))
               AND transaction_uom = l_transaction_uom
               AND NVL(transaction_type_id, -1) = NVL(l_transaction_type_id, NVL(transaction_type_id, -1))
               AND NVL(transaction_action_id, -1) = NVL(l_transaction_action_id, NVL(transaction_action_id, -1))
               AND NVL(transaction_source_type_id, -1) = NVL(l_transaction_source_type_id, NVL(transaction_source_type_id, -1))
               AND NVL(cost_group_id, -1) = NVL(l_cost_group_id, NVL(cost_group_id, -1));
Line: 12400

      select serial_number_control_code,lot_control_code
      into   l_serial_number_control_code,l_lot_control_code
      from mtl_system_items_b msi,mtl_material_transactions_temp mmtt
      where mmtt.transaction_temp_id = p_parent_transaction_temp_id
        and mmtt.inventory_item_id = msi.inventory_item_id
        and mmtt.organization_id = msi.organization_id;
Line: 12414

          INSERT INTO mtl_transaction_lots_temp
          (transaction_temp_id
          , lot_number
          , transaction_quantity
          , primary_quantity
          , lot_expiration_date
          , last_update_date
          , last_updated_by
          , creation_date
          , created_by
          , serial_transaction_temp_id)   -- always set to null since we don't bulk lines with allocated serial numbers
          (SELECT p_parent_transaction_temp_id,   -- transaction_temp_id of parent line
                  mtlt.lot_number,
                  sum(mtlt.transaction_quantity) transaction_quantity,
                  sum(mtlt.primary_quantity) primary_quantity,
                  mtlt.lot_expiration_date
                 ,SYSDATE
                 ,g_user_id
                 ,SYSDATE
                 ,g_user_id
                 ,null
                  FROM mtl_transaction_lots_temp mtlt,mtl_material_transactions_temp mmtt
                  WHERE
                       mtlt.transaction_temp_id = mmtt.transaction_temp_id
                   and mmtt.parent_line_id = p_parent_transaction_temp_id   -- child task
                   and mmtt.transaction_temp_id <> p_parent_transaction_temp_id -- not parent task
               group by mtlt.lot_number,mtlt.lot_expiration_date);
Line: 12509

      SELECT equip.internal_volume equip_vol
           , -- equipment volume capacity
             equip.maximum_load_weight equip_weight
           , -- equipment weight capacity
             item.unit_volume item_vol
           , -- item unit volume
             item.unit_weight item_weight
           , -- item unit weight
             equip.volume_uom_code equip_v_uom
           , -- equipment volumn UOM code
             equip.weight_uom_code equip_w_uom
           , -- equipment weight UOM code
             item.volume_uom_code item_v_uom
           , -- item volume UOM code
             item.weight_uom_code item_w_uom -- item weight UOM code
        FROM mtl_system_items equip
           , mtl_system_items item
           , wms_cartonization_temp  mmtt
           , bom_resource_equipments res_equip
           , bom_resources res
           , bom_std_op_resources tt_x_res
       WHERE mmtt.transaction_temp_id = p_task_id -- the task in question
         AND mmtt.standard_operation_id = tt_x_res.standard_operation_id --join task with task_type-resource x-ref
         AND tt_x_res.resource_id = res.resource_id -- join with resource
         AND res.resource_type = 1 -- resource type for equipment
         AND res_equip.resource_id = tt_x_res.resource_id -- join with resource-equip x-ref
         AND equip.inventory_item_id = res_equip.inventory_item_id -- join with equipment (mtl_system_items)
         AND equip.organization_id = res_equip.organization_id
         AND item.inventory_item_id = mmtt.inventory_item_id -- join with item for the item that is transfered
         AND item.organization_id = mmtt.organization_id;
Line: 12546

      SELECT equip.internal_volume equip_vol
           , -- equipment volume capacity
             equip.maximum_load_weight equip_weight
           , -- equipment weight capacity
             item.unit_volume item_vol
           , -- item unit volume
             item.unit_weight item_weight
           , -- item unit weight
             equip.volume_uom_code equip_v_uom
           , -- equipment volumn UOM code
             equip.weight_uom_code equip_w_uom
           , -- equipment weight UOM code
             item.volume_uom_code item_v_uom
           , -- item volume UOM code
             item.weight_uom_code item_w_uom -- item weight UOM code
        FROM mtl_system_items equip
           , mtl_system_items item
           , mtl_material_transactions_temp  mmtt
           , bom_resource_equipments res_equip
           , bom_resources res
           , bom_std_op_resources tt_x_res
       WHERE mmtt.transaction_temp_id = p_task_id -- the task in question
         AND mmtt.standard_operation_id = tt_x_res.standard_operation_id --join task with task_type-resource x-ref
         AND tt_x_res.resource_id = res.resource_id -- join with resource
         AND res.resource_type = 1 -- resource type for equipment
         AND res_equip.resource_id = tt_x_res.resource_id -- join with resource-equip x-ref
         AND equip.inventory_item_id = res_equip.inventory_item_id -- join with equipment (mtl_system_items)
         AND equip.organization_id = res_equip.organization_id
         AND item.inventory_item_id = mmtt.inventory_item_id -- join with item for the item that is transfered
         AND item.organization_id = mmtt.organization_id;
Line: 12579

        Select mmtt.transaction_temp_id,mmtt.transaction_quantity
          From wms_cartonization_temp mmtt,mtl_txn_request_lines mol,wsh_delivery_details_ob_grp_v wdd,
               wsh_delivery_assignments_v wda
          WHERE mmtt.parent_line_id = p_parent_line_id
            And mol.line_id = mmtt.move_order_line_id
            and mol.line_id = wdd.move_order_line_id
            and wdd.delivery_detail_id = wda.delivery_detail_id
            and mmtt.transaction_temp_id <> p_parent_line_id
          Order by nvl(wda.delivery_id,mol.carton_grouping_id), mmtt.transaction_quantity DESC;
Line: 12614

      SELECT *
      INTO l_task_rec_old_wct
      FROM wms_cartonization_temp
      WHERE transaction_temp_id = p_task_id;
Line: 12620

      SELECT *
       INTO l_task_rec_old_mmtt
       FROM mtl_material_transactions_temp
       WHERE transaction_temp_id = p_task_id;
Line: 12648

    SELECT NVL(mil.pick_uom_code, msi.pick_uom_code)
         , mmtt.transaction_uom
         , mmtt.inventory_item_id
         , mmtt.transaction_quantity
         , item.primary_uom_code
         , item.lot_control_code
         , item.serial_number_control_code
      INTO l_loc_uom_code
         , l_txn_uom_code
         , l_item_id
         , l_init_qty
         , l_item_prim_uom_code
         , l_lot_control_code
         , l_serial_number_control_code
      FROM wms_cartonization_temp mmtt, mtl_item_locations mil, mtl_secondary_inventories msi, mtl_system_items item
     WHERE mmtt.transaction_temp_id = p_task_id
       AND mmtt.locator_id = mil.inventory_location_id(+)
       AND mmtt.organization_id = mil.organization_id(+)
       AND mmtt.subinventory_code = msi.secondary_inventory_name
       AND mmtt.organization_id = msi.organization_id
       AND mmtt.inventory_item_id = item.inventory_item_id
       AND mmtt.organization_id = item.organization_id;
Line: 12964

      SELECT mtl_material_transactions_s.NEXTVAL
        INTO l_new_temp_id
        FROM DUAL;
Line: 13002

          insert_mmtt(l_task_rec_new_mmtt);
Line: 13004

          insert_wct(l_task_rec_new_wct);
Line: 13036

                update mtl_material_transactions_temp
                set parent_line_id = l_new_temp_id
                where transaction_Temp_id = l_child_rec.transaction_temp_id;
Line: 13047

                    print_debug('update transaction temp id '||l_child_rec.transaction_temp_id
                                || ' with the remaining qty '||l_child_remaining_qty,4);
Line: 13051

                update mtl_material_transactions_temp
                set transaction_quantity =  l_child_remaining_qty
                    , primary_quantity = l_child_remaining_qty * l_txn_pri_uom_ratio
                where transaction_temp_id =  l_child_rec.transaction_temp_id;
Line: 13058

         SELECT mtl_material_transactions_s.NEXTVAL
         INTO l_new_child_temp_id
         FROM DUAL;
Line: 13063

                   select *
                   into
                       l_child_rec_new
                   from mtl_material_transactions_temp
                   where transaction_temp_id =  l_child_rec.transaction_temp_id;
Line: 13073

         l_child_rec_new.parent_line_id       := l_new_temp_id;  -- update the new line with the correct parent
Line: 13087

            insert_mmtt(l_child_rec_new);
Line: 13095

                          print_debug('calling BREAK to insert the lot and serial',4);
Line: 13103

                       IF (l_debug = 1) THEN print_debug('After insert the lot and serial for the split child',4);
Line: 13149

      UPDATE wms_cartonization_temp
         SET transaction_quantity = l_init_qty
           , primary_quantity = l_init_qty * l_txn_pri_uom_ratio
       WHERE transaction_temp_id = p_task_id;
Line: 13158

         UPDATE mtl_material_transactions_temp
       SET transaction_quantity = l_init_qty
         , primary_quantity = l_init_qty * l_txn_pri_uom_ratio
          WHERE transaction_temp_id = p_task_id;
Line: 13182

         DELETE wms_cartonization_temp
     WHERE transaction_temp_id = p_task_id;
Line: 13248

  PROCEDURE insert_mmtt(l_mmtt_rec mtl_material_transactions_temp%ROWTYPE) IS
    l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
Line: 13251

    INSERT INTO mtl_material_transactions_temp
                (
                 transaction_header_id
               , transaction_temp_id
               , source_code
               , source_line_id
               , transaction_mode
               , lock_flag
               , last_update_date
               , last_updated_by
               , creation_date
               , created_by
               , last_update_login
               , request_id
               , program_application_id
               , program_id
               , program_update_date
               , inventory_item_id
               , revision
               , organization_id
               , subinventory_code
               , locator_id
               , transaction_quantity
               , primary_quantity
               , transaction_uom
               , transaction_cost
               , transaction_type_id
               , transaction_action_id
               , transaction_source_type_id
               , transaction_source_id
               , transaction_source_name
               , transaction_date
               , acct_period_id
               , distribution_account_id
               , transaction_reference
               , requisition_line_id
               , requisition_distribution_id
               , reason_id
               , lot_number
               , lot_expiration_date
               , serial_number
               , receiving_document
               , demand_id
               , rcv_transaction_id
               , move_transaction_id
               , completion_transaction_id
               , wip_entity_type
               , schedule_id
               , repetitive_line_id
               , employee_code
               , primary_switch
               , schedule_update_code
               , setup_teardown_code
               , item_ordering
               , negative_req_flag
               , operation_seq_num
               , picking_line_id
               , trx_source_line_id
               , trx_source_delivery_id
               , physical_adjustment_id
               , cycle_count_id
               , rma_line_id
               , customer_ship_id
               , currency_code
               , currency_conversion_rate
               , currency_conversion_type
               , currency_conversion_date
               , ussgl_transaction_code
               , vendor_lot_number
               , encumbrance_account
               , encumbrance_amount
               , ship_to_location
               , shipment_number
               , transfer_cost
               , transportation_cost
               , transportation_account
               , freight_code
               , containers
               , waybill_airbill
               , expected_arrival_date
               , transfer_subinventory
               , transfer_organization
               , transfer_to_location
               , new_average_cost
               , value_change
               , percentage_change
               , material_allocation_temp_id
               , demand_source_header_id
               , demand_source_line
               , demand_source_delivery
               , item_segments
               , item_description
               , item_trx_enabled_flag
               , item_location_control_code
               , item_restrict_subinv_code
               , item_restrict_locators_code
               , item_revision_qty_control_code
               , item_primary_uom_code
               , item_uom_class
               , item_shelf_life_code
               , item_shelf_life_days
               , item_lot_control_code
               , item_serial_control_code
               , item_inventory_asset_flag
               , allowed_units_lookup_code
               , department_id
               , department_code
               , wip_supply_type
               , supply_subinventory
               , supply_locator_id
               , valid_subinventory_flag
               , valid_locator_flag
               , locator_segments
               , current_locator_control_code
               , number_of_lots_entered
               , wip_commit_flag
               , next_lot_number
               , lot_alpha_prefix
               , next_serial_number
               , serial_alpha_prefix
               , shippable_flag
               , posting_flag
               , required_flag
               , process_flag
               , ERROR_CODE
               , error_explanation
               , attribute_category
               , attribute1
               , attribute2
               , attribute3
               , attribute4
               , attribute5
               , attribute6
               , attribute7
               , attribute8
               , attribute9
               , attribute10
               , attribute11
               , attribute12
               , attribute13
               , attribute14
               , attribute15
               , movement_id
               , reservation_quantity
               , shipped_quantity
               , transaction_line_number
               , task_id
               , to_task_id
               , source_task_id
               , project_id
               , source_project_id
               , pa_expenditure_org_id
               , to_project_id
               , expenditure_type
               , final_completion_flag
               , transfer_percentage
               , transaction_sequence_id
               , material_account
               , material_overhead_account
               , resource_account
               , outside_processing_account
               , overhead_account
               , flow_schedule
               , cost_group_id
               , transfer_cost_group_id
               , demand_class
               , qa_collection_id
               , kanban_card_id
               , overcompletion_transaction_qty
               , overcompletion_primary_qty
               , overcompletion_transaction_id
               , end_item_unit_number
               , scheduled_payback_date
               , line_type_code
               , parent_transaction_temp_id
               , put_away_strategy_id
               , put_away_rule_id
               , pick_strategy_id
               , pick_rule_id
               , move_order_line_id
               , task_group_id
               , pick_slip_number
               , reservation_id
               , common_bom_seq_id
               , common_routing_seq_id
               , org_cost_group_id
               , cost_type_id
               , transaction_status
               , standard_operation_id
               , task_priority
               , wms_task_type
               , parent_line_id
               , lpn_id
               , transfer_lpn_id
               , wms_task_status
               , content_lpn_id
               , container_item_id
               , cartonization_id
               , pick_slip_date
               , rebuild_item_id
               , rebuild_serial_number
               , rebuild_activity_id
               , rebuild_job_name
               , organization_type
               , transfer_organization_type
               , owning_organization_id
               , owning_tp_type
               , xfr_owning_organization_id
               , transfer_owning_tp_type
               , planning_organization_id
               , planning_tp_type
               , xfr_planning_organization_id
               , transfer_planning_tp_type
               , secondary_uom_code
               , secondary_transaction_quantity
               , transaction_batch_id
               , transaction_batch_seq
               , allocated_lpn_id
               , schedule_number
               , scheduled_flag
               , class_code
               , schedule_group
               , build_sequence
               , bom_revision
               , routing_revision
               , bom_revision_date
               , routing_revision_date
               , alternate_bom_designator
               , alternate_routing_designator
               , operation_plan_id
               , serial_allocated_flag
               , move_order_header_id
                )
         VALUES (
                 l_mmtt_rec.transaction_header_id
               , l_mmtt_rec.transaction_temp_id
               , l_mmtt_rec.source_code
               , l_mmtt_rec.source_line_id
               , l_mmtt_rec.transaction_mode
               , l_mmtt_rec.lock_flag
               , l_mmtt_rec.last_update_date
               , l_mmtt_rec.last_updated_by
               , l_mmtt_rec.creation_date
               , l_mmtt_rec.created_by
               , l_mmtt_rec.last_update_login
               , l_mmtt_rec.request_id
               , l_mmtt_rec.program_application_id
               , l_mmtt_rec.program_id
               , l_mmtt_rec.program_update_date
               , l_mmtt_rec.inventory_item_id
               , l_mmtt_rec.revision
               , l_mmtt_rec.organization_id
               , l_mmtt_rec.subinventory_code
               , l_mmtt_rec.locator_id
               , l_mmtt_rec.transaction_quantity
               , l_mmtt_rec.primary_quantity
               , l_mmtt_rec.transaction_uom
               , l_mmtt_rec.transaction_cost
               , l_mmtt_rec.transaction_type_id
               , l_mmtt_rec.transaction_action_id
               , l_mmtt_rec.transaction_source_type_id
               , l_mmtt_rec.transaction_source_id
               , l_mmtt_rec.transaction_source_name
               , l_mmtt_rec.transaction_date
               , l_mmtt_rec.acct_period_id
               , l_mmtt_rec.distribution_account_id
               , l_mmtt_rec.transaction_reference
               , l_mmtt_rec.requisition_line_id
               , l_mmtt_rec.requisition_distribution_id
               , l_mmtt_rec.reason_id
               , l_mmtt_rec.lot_number
               , l_mmtt_rec.lot_expiration_date
               , l_mmtt_rec.serial_number
               , l_mmtt_rec.receiving_document
               , l_mmtt_rec.demand_id
               , l_mmtt_rec.rcv_transaction_id
               , l_mmtt_rec.move_transaction_id
               , l_mmtt_rec.completion_transaction_id
               , l_mmtt_rec.wip_entity_type
               , l_mmtt_rec.schedule_id
               , l_mmtt_rec.repetitive_line_id
               , l_mmtt_rec.employee_code
               , l_mmtt_rec.primary_switch
               , l_mmtt_rec.schedule_update_code
               , l_mmtt_rec.setup_teardown_code
               , l_mmtt_rec.item_ordering
               , l_mmtt_rec.negative_req_flag
               , l_mmtt_rec.operation_seq_num
               , l_mmtt_rec.picking_line_id
               , l_mmtt_rec.trx_source_line_id
               , l_mmtt_rec.trx_source_delivery_id
               , l_mmtt_rec.physical_adjustment_id
               , l_mmtt_rec.cycle_count_id
               , l_mmtt_rec.rma_line_id
               , l_mmtt_rec.customer_ship_id
               , l_mmtt_rec.currency_code
               , l_mmtt_rec.currency_conversion_rate
               , l_mmtt_rec.currency_conversion_type
               , l_mmtt_rec.currency_conversion_date
               , l_mmtt_rec.ussgl_transaction_code
               , l_mmtt_rec.vendor_lot_number
               , l_mmtt_rec.encumbrance_account
               , l_mmtt_rec.encumbrance_amount
               , l_mmtt_rec.ship_to_location
               , l_mmtt_rec.shipment_number
               , l_mmtt_rec.transfer_cost
               , l_mmtt_rec.transportation_cost
               , l_mmtt_rec.transportation_account
               , l_mmtt_rec.freight_code
               , l_mmtt_rec.containers
               , l_mmtt_rec.waybill_airbill
               , l_mmtt_rec.expected_arrival_date
               , l_mmtt_rec.transfer_subinventory
               , l_mmtt_rec.transfer_organization
               , l_mmtt_rec.transfer_to_location
               , l_mmtt_rec.new_average_cost
               , l_mmtt_rec.value_change
               , l_mmtt_rec.percentage_change
               , l_mmtt_rec.material_allocation_temp_id
               , l_mmtt_rec.demand_source_header_id
               , l_mmtt_rec.demand_source_line
               , l_mmtt_rec.demand_source_delivery
               , l_mmtt_rec.item_segments
               , l_mmtt_rec.item_description
               , l_mmtt_rec.item_trx_enabled_flag
               , l_mmtt_rec.item_location_control_code
               , l_mmtt_rec.item_restrict_subinv_code
               , l_mmtt_rec.item_restrict_locators_code
               , l_mmtt_rec.item_revision_qty_control_code
               , l_mmtt_rec.item_primary_uom_code
               , l_mmtt_rec.item_uom_class
               , l_mmtt_rec.item_shelf_life_code
               , l_mmtt_rec.item_shelf_life_days
               , l_mmtt_rec.item_lot_control_code
               , l_mmtt_rec.item_serial_control_code
               , l_mmtt_rec.item_inventory_asset_flag
               , l_mmtt_rec.allowed_units_lookup_code
               , l_mmtt_rec.department_id
               , l_mmtt_rec.department_code
               , l_mmtt_rec.wip_supply_type
               , l_mmtt_rec.supply_subinventory
               , l_mmtt_rec.supply_locator_id
               , l_mmtt_rec.valid_subinventory_flag
               , l_mmtt_rec.valid_locator_flag
               , l_mmtt_rec.locator_segments
               , l_mmtt_rec.current_locator_control_code
               , l_mmtt_rec.number_of_lots_entered
               , l_mmtt_rec.wip_commit_flag
               , l_mmtt_rec.next_lot_number
               , l_mmtt_rec.lot_alpha_prefix
               , l_mmtt_rec.next_serial_number
               , l_mmtt_rec.serial_alpha_prefix
               , l_mmtt_rec.shippable_flag
               , l_mmtt_rec.posting_flag
               , l_mmtt_rec.required_flag
               , l_mmtt_rec.process_flag
               , l_mmtt_rec.ERROR_CODE
               , l_mmtt_rec.error_explanation
               , l_mmtt_rec.attribute_category
               , l_mmtt_rec.attribute1
               , l_mmtt_rec.attribute2
               , l_mmtt_rec.attribute3
               , l_mmtt_rec.attribute4
               , l_mmtt_rec.attribute5
               , l_mmtt_rec.attribute6
               , l_mmtt_rec.attribute7
               , l_mmtt_rec.attribute8
               , l_mmtt_rec.attribute9
               , l_mmtt_rec.attribute10
               , l_mmtt_rec.attribute11
               , l_mmtt_rec.attribute12
               , l_mmtt_rec.attribute13
               , l_mmtt_rec.attribute14
               , l_mmtt_rec.attribute15
               , l_mmtt_rec.movement_id
               , l_mmtt_rec.reservation_quantity
               , l_mmtt_rec.shipped_quantity
               , l_mmtt_rec.transaction_line_number
               , l_mmtt_rec.task_id
               , l_mmtt_rec.to_task_id
               , l_mmtt_rec.source_task_id
               , l_mmtt_rec.project_id
               , l_mmtt_rec.source_project_id
               , l_mmtt_rec.pa_expenditure_org_id
               , l_mmtt_rec.to_project_id
               , l_mmtt_rec.expenditure_type
               , l_mmtt_rec.final_completion_flag
               , l_mmtt_rec.transfer_percentage
               , l_mmtt_rec.transaction_sequence_id
               , l_mmtt_rec.material_account
               , l_mmtt_rec.material_overhead_account
               , l_mmtt_rec.resource_account
               , l_mmtt_rec.outside_processing_account
               , l_mmtt_rec.overhead_account
               , l_mmtt_rec.flow_schedule
               , l_mmtt_rec.cost_group_id
               , l_mmtt_rec.transfer_cost_group_id
               , l_mmtt_rec.demand_class
               , l_mmtt_rec.qa_collection_id
               , l_mmtt_rec.kanban_card_id
               , l_mmtt_rec.overcompletion_transaction_qty
               , l_mmtt_rec.overcompletion_primary_qty
               , l_mmtt_rec.overcompletion_transaction_id
               , l_mmtt_rec.end_item_unit_number
               , l_mmtt_rec.scheduled_payback_date
               , l_mmtt_rec.line_type_code
               , l_mmtt_rec.parent_transaction_temp_id
               , l_mmtt_rec.put_away_strategy_id
               , l_mmtt_rec.put_away_rule_id
               , l_mmtt_rec.pick_strategy_id
               , l_mmtt_rec.pick_rule_id
               , l_mmtt_rec.move_order_line_id
               , l_mmtt_rec.task_group_id
               , l_mmtt_rec.pick_slip_number
               , l_mmtt_rec.reservation_id
               , l_mmtt_rec.common_bom_seq_id
               , l_mmtt_rec.common_routing_seq_id
               , l_mmtt_rec.org_cost_group_id
               , l_mmtt_rec.cost_type_id
               , l_mmtt_rec.transaction_status
               , l_mmtt_rec.standard_operation_id
               , l_mmtt_rec.task_priority
               , l_mmtt_rec.wms_task_type
               , l_mmtt_rec.parent_line_id
               , l_mmtt_rec.lpn_id
               , l_mmtt_rec.transfer_lpn_id
               , l_mmtt_rec.wms_task_status
               , l_mmtt_rec.content_lpn_id
               , l_mmtt_rec.container_item_id
               , l_mmtt_rec.cartonization_id
               , l_mmtt_rec.pick_slip_date
               , l_mmtt_rec.rebuild_item_id
               , l_mmtt_rec.rebuild_serial_number
               , l_mmtt_rec.rebuild_activity_id
               , l_mmtt_rec.rebuild_job_name
               , l_mmtt_rec.organization_type
               , l_mmtt_rec.transfer_organization_type
               , l_mmtt_rec.owning_organization_id
               , l_mmtt_rec.owning_tp_type
               , l_mmtt_rec.xfr_owning_organization_id
               , l_mmtt_rec.transfer_owning_tp_type
               , l_mmtt_rec.planning_organization_id
               , l_mmtt_rec.planning_tp_type
               , l_mmtt_rec.xfr_planning_organization_id
               , l_mmtt_rec.transfer_planning_tp_type
               , l_mmtt_rec.secondary_uom_code
               , l_mmtt_rec.secondary_transaction_quantity
               , l_mmtt_rec.transaction_batch_id
               , l_mmtt_rec.transaction_batch_seq
               , l_mmtt_rec.allocated_lpn_id
               , l_mmtt_rec.schedule_number
               , l_mmtt_rec.scheduled_flag
               , l_mmtt_rec.class_code
               , l_mmtt_rec.schedule_group
               , l_mmtt_rec.build_sequence
               , l_mmtt_rec.bom_revision
               , l_mmtt_rec.routing_revision
               , l_mmtt_rec.bom_revision_date
               , l_mmtt_rec.routing_revision_date
               , l_mmtt_rec.alternate_bom_designator
               , l_mmtt_rec.alternate_routing_designator
               , l_mmtt_rec.operation_plan_id
               , l_mmtt_rec.serial_allocated_flag
               , l_mmtt_rec.move_order_header_id
                );
Line: 13716

  END insert_mmtt;
Line: 13718

  PROCEDURE insert_wct(l_wct_rec wms_cartonization_temp%ROWTYPE) IS
    l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
Line: 13721

    INSERT INTO wms_cartonization_temp
                (
                 transaction_header_id
               , transaction_temp_id
               , source_code
               , source_line_id
               , transaction_mode
               , lock_flag
               , last_update_date
               , last_updated_by
               , creation_date
               , created_by
               , last_update_login
               , request_id
               , program_application_id
               , program_id
               , program_update_date
               , inventory_item_id
               , revision
               , organization_id
               , subinventory_code
               , locator_id
               , transaction_quantity
               , primary_quantity
               , transaction_uom
               , transaction_cost
               , transaction_type_id
               , transaction_action_id
               , transaction_source_type_id
               , transaction_source_id
               , transaction_source_name
               , transaction_date
               , acct_period_id
               , distribution_account_id
               , transaction_reference
               , requisition_line_id
               , requisition_distribution_id
               , reason_id
               , lot_number
               , lot_expiration_date
               , serial_number
               , receiving_document
               , demand_id
               , rcv_transaction_id
               , move_transaction_id
               , completion_transaction_id
               , wip_entity_type
               , schedule_id
               , repetitive_line_id
               , employee_code
               , primary_switch
               , schedule_update_code
               , setup_teardown_code
               , item_ordering
               , negative_req_flag
               , operation_seq_num
               , picking_line_id
               , trx_source_line_id
               , trx_source_delivery_id
               , physical_adjustment_id
               , cycle_count_id
               , rma_line_id
               , customer_ship_id
               , currency_code
               , currency_conversion_rate
               , currency_conversion_type
               , currency_conversion_date
               , ussgl_transaction_code
               , vendor_lot_number
               , encumbrance_account
               , encumbrance_amount
               , ship_to_location
               , shipment_number
               , transfer_cost
               , transportation_cost
               , transportation_account
               , freight_code
               , containers
               , waybill_airbill
               , expected_arrival_date
               , transfer_subinventory
               , transfer_organization
               , transfer_to_location
               , new_average_cost
               , value_change
               , percentage_change
               , material_allocation_temp_id
               , demand_source_header_id
               , demand_source_line
               , demand_source_delivery
               , item_segments
               , item_description
               , item_trx_enabled_flag
               , item_location_control_code
               , item_restrict_subinv_code
               , item_restrict_locators_code
               , item_revision_qty_control_code
               , item_primary_uom_code
               , item_uom_class
               , item_shelf_life_code
               , item_shelf_life_days
               , item_lot_control_code
               , item_serial_control_code
               , item_inventory_asset_flag
               , allowed_units_lookup_code
               , department_id
               , department_code
               , wip_supply_type
               , supply_subinventory
               , supply_locator_id
               , valid_subinventory_flag
               , valid_locator_flag
               , locator_segments
               , current_locator_control_code
               , number_of_lots_entered
               , wip_commit_flag
               , next_lot_number
               , lot_alpha_prefix
               , next_serial_number
               , serial_alpha_prefix
               , shippable_flag
               , posting_flag
               , required_flag
               , process_flag
               , ERROR_CODE
               , error_explanation
               , attribute_category
               , attribute1
               , attribute2
               , attribute3
               , attribute4
               , attribute5
               , attribute6
               , attribute7
               , attribute8
               , attribute9
               , attribute10
               , attribute11
               , attribute12
               , attribute13
               , attribute14
               , attribute15
               , movement_id
               , reservation_quantity
               , shipped_quantity
               , transaction_line_number
               , task_id
               , to_task_id
               , source_task_id
               , project_id
               , source_project_id
               , pa_expenditure_org_id
               , to_project_id
               , expenditure_type
               , final_completion_flag
               , transfer_percentage
               , transaction_sequence_id
               , material_account
               , material_overhead_account
               , resource_account
               , outside_processing_account
               , overhead_account
               , flow_schedule
               , cost_group_id
               , transfer_cost_group_id
               , demand_class
               , qa_collection_id
               , kanban_card_id
               , overcompletion_transaction_qty
               , overcompletion_primary_qty
               , overcompletion_transaction_id
               , end_item_unit_number
               , scheduled_payback_date
               , line_type_code
               , parent_transaction_temp_id
               , put_away_strategy_id
               , put_away_rule_id
               , pick_strategy_id
               , pick_rule_id
               , move_order_line_id
               , task_group_id
               , pick_slip_number
               , reservation_id
               , common_bom_seq_id
               , common_routing_seq_id
               , org_cost_group_id
               , cost_type_id
               , transaction_status
               , standard_operation_id
               , task_priority
               , wms_task_type
               , parent_line_id
               , lpn_id
               , transfer_lpn_id
               , wms_task_status
               , content_lpn_id
               , container_item_id
               , cartonization_id
               , pick_slip_date
               , rebuild_item_id
               , rebuild_serial_number
               , rebuild_activity_id
               , rebuild_job_name
               , organization_type
               , transfer_organization_type
               , owning_organization_id
               , owning_tp_type
               , xfr_owning_organization_id
               , transfer_owning_tp_type
               , planning_organization_id
               , planning_tp_type
               , xfr_planning_organization_id
               , transfer_planning_tp_type
               , secondary_uom_code
               , secondary_transaction_quantity
               , transaction_batch_id
               , transaction_batch_seq
               , allocated_lpn_id
               , schedule_number
               , scheduled_flag
               , class_code
               , schedule_group
               , build_sequence
               , bom_revision
               , routing_revision
               , bom_revision_date
               , routing_revision_date
               , alternate_bom_designator
               , alternate_routing_designator
               , operation_plan_id
               , serial_allocated_flag
               , move_order_header_id
                )
         VALUES (
                 l_wct_rec.transaction_header_id
               , l_wct_rec.transaction_temp_id
               , l_wct_rec.source_code
               , l_wct_rec.source_line_id
               , l_wct_rec.transaction_mode
               , l_wct_rec.lock_flag
               , l_wct_rec.last_update_date
               , l_wct_rec.last_updated_by
               , l_wct_rec.creation_date
               , l_wct_rec.created_by
               , l_wct_rec.last_update_login
               , l_wct_rec.request_id
               , l_wct_rec.program_application_id
               , l_wct_rec.program_id
               , l_wct_rec.program_update_date
               , l_wct_rec.inventory_item_id
               , l_wct_rec.revision
               , l_wct_rec.organization_id
               , l_wct_rec.subinventory_code
               , l_wct_rec.locator_id
               , l_wct_rec.transaction_quantity
               , l_wct_rec.primary_quantity
               , l_wct_rec.transaction_uom
               , l_wct_rec.transaction_cost
               , l_wct_rec.transaction_type_id
               , l_wct_rec.transaction_action_id
               , l_wct_rec.transaction_source_type_id
               , l_wct_rec.transaction_source_id
               , l_wct_rec.transaction_source_name
               , l_wct_rec.transaction_date
               , l_wct_rec.acct_period_id
               , l_wct_rec.distribution_account_id
               , l_wct_rec.transaction_reference
               , l_wct_rec.requisition_line_id
               , l_wct_rec.requisition_distribution_id
               , l_wct_rec.reason_id
               , l_wct_rec.lot_number
               , l_wct_rec.lot_expiration_date
               , l_wct_rec.serial_number
               , l_wct_rec.receiving_document
               , l_wct_rec.demand_id
               , l_wct_rec.rcv_transaction_id
               , l_wct_rec.move_transaction_id
               , l_wct_rec.completion_transaction_id
               , l_wct_rec.wip_entity_type
               , l_wct_rec.schedule_id
               , l_wct_rec.repetitive_line_id
               , l_wct_rec.employee_code
               , l_wct_rec.primary_switch
               , l_wct_rec.schedule_update_code
               , l_wct_rec.setup_teardown_code
               , l_wct_rec.item_ordering
               , l_wct_rec.negative_req_flag
               , l_wct_rec.operation_seq_num
               , l_wct_rec.picking_line_id
               , l_wct_rec.trx_source_line_id
               , l_wct_rec.trx_source_delivery_id
               , l_wct_rec.physical_adjustment_id
               , l_wct_rec.cycle_count_id
               , l_wct_rec.rma_line_id
               , l_wct_rec.customer_ship_id
               , l_wct_rec.currency_code
               , l_wct_rec.currency_conversion_rate
               , l_wct_rec.currency_conversion_type
               , l_wct_rec.currency_conversion_date
               , l_wct_rec.ussgl_transaction_code
               , l_wct_rec.vendor_lot_number
               , l_wct_rec.encumbrance_account
               , l_wct_rec.encumbrance_amount
               , l_wct_rec.ship_to_location
               , l_wct_rec.shipment_number
               , l_wct_rec.transfer_cost
               , l_wct_rec.transportation_cost
               , l_wct_rec.transportation_account
               , l_wct_rec.freight_code
               , l_wct_rec.containers
               , l_wct_rec.waybill_airbill
               , l_wct_rec.expected_arrival_date
               , l_wct_rec.transfer_subinventory
               , l_wct_rec.transfer_organization
               , l_wct_rec.transfer_to_location
               , l_wct_rec.new_average_cost
               , l_wct_rec.value_change
               , l_wct_rec.percentage_change
               , l_wct_rec.material_allocation_temp_id
               , l_wct_rec.demand_source_header_id
               , l_wct_rec.demand_source_line
               , l_wct_rec.demand_source_delivery
               , l_wct_rec.item_segments
               , l_wct_rec.item_description
               , l_wct_rec.item_trx_enabled_flag
               , l_wct_rec.item_location_control_code
               , l_wct_rec.item_restrict_subinv_code
               , l_wct_rec.item_restrict_locators_code
               , l_wct_rec.item_revision_qty_control_code
               , l_wct_rec.item_primary_uom_code
               , l_wct_rec.item_uom_class
               , l_wct_rec.item_shelf_life_code
               , l_wct_rec.item_shelf_life_days
               , l_wct_rec.item_lot_control_code
               , l_wct_rec.item_serial_control_code
               , l_wct_rec.item_inventory_asset_flag
               , l_wct_rec.allowed_units_lookup_code
               , l_wct_rec.department_id
               , l_wct_rec.department_code
               , l_wct_rec.wip_supply_type
               , l_wct_rec.supply_subinventory
               , l_wct_rec.supply_locator_id
               , l_wct_rec.valid_subinventory_flag
               , l_wct_rec.valid_locator_flag
               , l_wct_rec.locator_segments
               , l_wct_rec.current_locator_control_code
               , l_wct_rec.number_of_lots_entered
               , l_wct_rec.wip_commit_flag
               , l_wct_rec.next_lot_number
               , l_wct_rec.lot_alpha_prefix
               , l_wct_rec.next_serial_number
               , l_wct_rec.serial_alpha_prefix
               , l_wct_rec.shippable_flag
               , l_wct_rec.posting_flag
               , l_wct_rec.required_flag
               , l_wct_rec.process_flag
               , l_wct_rec.ERROR_CODE
               , l_wct_rec.error_explanation
               , l_wct_rec.attribute_category
               , l_wct_rec.attribute1
               , l_wct_rec.attribute2
               , l_wct_rec.attribute3
               , l_wct_rec.attribute4
               , l_wct_rec.attribute5
               , l_wct_rec.attribute6
               , l_wct_rec.attribute7
               , l_wct_rec.attribute8
               , l_wct_rec.attribute9
               , l_wct_rec.attribute10
               , l_wct_rec.attribute11
               , l_wct_rec.attribute12
               , l_wct_rec.attribute13
               , l_wct_rec.attribute14
               , l_wct_rec.attribute15
               , l_wct_rec.movement_id
               , l_wct_rec.reservation_quantity
               , l_wct_rec.shipped_quantity
               , l_wct_rec.transaction_line_number
               , l_wct_rec.task_id
               , l_wct_rec.to_task_id
               , l_wct_rec.source_task_id
               , l_wct_rec.project_id
               , l_wct_rec.source_project_id
               , l_wct_rec.pa_expenditure_org_id
               , l_wct_rec.to_project_id
               , l_wct_rec.expenditure_type
               , l_wct_rec.final_completion_flag
               , l_wct_rec.transfer_percentage
               , l_wct_rec.transaction_sequence_id
               , l_wct_rec.material_account
               , l_wct_rec.material_overhead_account
               , l_wct_rec.resource_account
               , l_wct_rec.outside_processing_account
               , l_wct_rec.overhead_account
               , l_wct_rec.flow_schedule
               , l_wct_rec.cost_group_id
               , l_wct_rec.transfer_cost_group_id
               , l_wct_rec.demand_class
               , l_wct_rec.qa_collection_id
               , l_wct_rec.kanban_card_id
               , l_wct_rec.overcompletion_transaction_qty
               , l_wct_rec.overcompletion_primary_qty
               , l_wct_rec.overcompletion_transaction_id
               , l_wct_rec.end_item_unit_number
               , l_wct_rec.scheduled_payback_date
               , l_wct_rec.line_type_code
               , l_wct_rec.parent_transaction_temp_id
               , l_wct_rec.put_away_strategy_id
               , l_wct_rec.put_away_rule_id
               , l_wct_rec.pick_strategy_id
               , l_wct_rec.pick_rule_id
               , l_wct_rec.move_order_line_id
               , l_wct_rec.task_group_id
               , l_wct_rec.pick_slip_number
               , l_wct_rec.reservation_id
               , l_wct_rec.common_bom_seq_id
               , l_wct_rec.common_routing_seq_id
               , l_wct_rec.org_cost_group_id
               , l_wct_rec.cost_type_id
               , l_wct_rec.transaction_status
               , l_wct_rec.standard_operation_id
               , l_wct_rec.task_priority
               , l_wct_rec.wms_task_type
               , l_wct_rec.parent_line_id
               , l_wct_rec.lpn_id
               , l_wct_rec.transfer_lpn_id
               , l_wct_rec.wms_task_status
               , l_wct_rec.content_lpn_id
               , l_wct_rec.container_item_id
               , l_wct_rec.cartonization_id
               , l_wct_rec.pick_slip_date
               , l_wct_rec.rebuild_item_id
               , l_wct_rec.rebuild_serial_number
               , l_wct_rec.rebuild_activity_id
               , l_wct_rec.rebuild_job_name
               , l_wct_rec.organization_type
               , l_wct_rec.transfer_organization_type
               , l_wct_rec.owning_organization_id
               , l_wct_rec.owning_tp_type
               , l_wct_rec.xfr_owning_organization_id
               , l_wct_rec.transfer_owning_tp_type
               , l_wct_rec.planning_organization_id
               , l_wct_rec.planning_tp_type
               , l_wct_rec.xfr_planning_organization_id
               , l_wct_rec.transfer_planning_tp_type
               , l_wct_rec.secondary_uom_code
               , l_wct_rec.secondary_transaction_quantity
               , l_wct_rec.transaction_batch_id
               , l_wct_rec.transaction_batch_seq
               , l_wct_rec.allocated_lpn_id
               , l_wct_rec.schedule_number
               , l_wct_rec.scheduled_flag
               , l_wct_rec.class_code
               , l_wct_rec.schedule_group
               , l_wct_rec.build_sequence
               , l_wct_rec.bom_revision
               , l_wct_rec.routing_revision
               , l_wct_rec.bom_revision_date
               , l_wct_rec.routing_revision_date
               , l_wct_rec.alternate_bom_designator
               , l_wct_rec.alternate_routing_designator
               , l_wct_rec.operation_plan_id
               , l_wct_rec.serial_allocated_flag
               , l_wct_rec.move_order_header_id
                );
Line: 14186

  END insert_wct;