DBA Data[Home] [Help]

PACKAGE BODY: APPS.WSMPLBJI

Source


1 PACKAGE BODY WSMPLBJI AS
2 /* $Header: WSMLBJIB.pls 120.11 2006/09/06 06:21:58 mprathap noship $ */
3 
4 -- the following declarations are global to WSMPLBJI
5 -- PS: Although they have been declared as private to the package,
6 -- please note that each concurrent request submitted has it's own
7 -- session, hence each submission of launch worker will have it's
8 -- own set of "global" variables and tables.
9 
10 -- BUG 3934661
11 -- when calling dbms_utility.get_hash_value use larger seed number
12 -- OLD: dbms_utility.get_hash_value(str, 1000, 5625);
13 -- NEW: dbms_utility.get_hash_value(str, 37, 1073741824);
14 
15 v_index NUMBER;
16 v_wsli_index  NUMBER;
17 
18 -- ==============================================================================================
19 -- nested table types used to bulk bind data from wlji to the PL/SQL tables.
20 -- ==============================================================================================
21 type t_wlji_err_code                    is table of wsm_lot_job_interface.error_code%type;
22 type t_wlji_err_msg                     is table of wsm_lot_job_interface.error_msg%type;
23 type t_wlji_last_updt_date              is table of wsm_lot_job_interface.last_update_date%type;
24 type t_wlji_request_id                  is table of wsm_lot_job_interface.request_id%type;
25 type t_wlji_program_id                  is table of wsm_lot_job_interface.program_id%type;
26 type t_wlji_program_application_id      is table of wsm_lot_job_interface.program_application_id%type;
27 type t_wlji_last_updt_by                is table of wsm_lot_job_interface.last_updated_by%type;
28 type t_wlji_creation_date               is table of wsm_lot_job_interface.creation_date%type;
29 type t_wlji_created_by                  is table of wsm_lot_job_interface.created_by%type;
30 type t_wlji_last_updt_login             is table of wsm_lot_job_interface.last_update_login%type;
31 type t_wlji_prog_updt_date              is table of wsm_lot_job_interface.program_update_date%type;
32 type t_wlji_last_updt_by_name           is table of wsm_lot_job_interface.last_updated_by_name%type;
33 type t_wlji_created_by_name             is table of wsm_lot_job_interface.created_by_name%type;
34 type t_wlji_org                         is table of wsm_lot_job_interface.organization_id%type;
35 type t_wlji_item                        is table of wsm_lot_job_interface.primary_item_id%type;
36 type t_wlji_header_id                   is table of wsm_lot_job_interface.header_id%type;
37 type t_wlji_process_status              is table of wsm_lot_job_interface.process_status%type;
38 type t_wlji_routing_reference_id        is table of wsm_lot_job_interface.routing_reference_id%type;
39 type t_wlji_completion_subinventory     is table of wsm_lot_job_interface.completion_subinventory%type;
40 type t_wlji_completion_locator_id       is table of wsm_lot_job_interface.completion_locator_id%type;
41 type t_wlji_mode_flag                   is table of wsm_lot_job_interface.mode_flag%type;
42 type t_wlji_group_id                    is table of wsm_lot_job_interface.group_id%type;
43 type t_wlji_load_type                   is table of wsm_lot_job_interface.load_type%type;
44 type t_wlji_status_type                 is table of wsm_lot_job_interface.status_type%type;
45 type t_wlji_lucd                        is table of wsm_lot_job_interface.last_unit_completion_date%type;
46 type t_wlji_old_completion_date         is table of wsm_lot_job_interface.old_completion_date%type;
47 type t_wlji_bom_reference_id            is table of wsm_lot_job_interface.bom_reference_id%type;
48 type t_wlji_bom_revision_date           is table of wsm_lot_job_interface.bom_revision_date%type;
49 type t_wlji_routing_revision_date       is table of wsm_lot_job_interface.routing_revision_date%type;
50 type t_wlji_wip_supply_type             is table of wsm_lot_job_interface.wip_supply_type%type;
51 type t_wlji_class_code                  is table of wsm_lot_job_interface.class_code%type;
52 type t_wlji_lot_number                  is table of wsm_lot_job_interface.lot_number%type;
53 type t_wlji_job_name                    is table of wsm_lot_job_interface.job_name%type;
54 type t_wlji_description                 is table of wsm_lot_job_interface.description%type;
55 type t_wlji_firm_planned_flag           is table of wsm_lot_job_interface.firm_planned_flag%type;
56 type t_wlji_alt_routing_designator      is table of wsm_lot_job_interface.alternate_routing_designator%type;
57 type t_wlji_alt_bom_designator          is table of wsm_lot_job_interface.alternate_bom_designator%type;
58 type t_wlji_demand_class                is table of wsm_lot_job_interface.demand_class%type;
59 type t_wlji_start_quantity              is table of wsm_lot_job_interface.start_quantity%type;
60 type t_wlji_old_start_quantity          is table of wsm_lot_job_interface.old_start_quantity%type;
61 type t_wlji_wip_entity_id               is table of wsm_lot_job_interface.wip_entity_id%type;
62 type t_wlji_error                       is table of wsm_lot_job_interface.error%type;
63 type t_wlji_process_phase               is table of wsm_lot_job_interface.process_phase%type;
64 type t_wlji_fusd                        is table of wsm_lot_job_interface.first_unit_start_date%type;
65 type t_wlji_fucd                        is table of wsm_lot_job_interface.first_unit_completion_date%type;
66 type t_wlji_last_unit_start_date        is table of wsm_lot_job_interface.last_unit_start_date%type;
67 type t_wlji_scheduling_method           is table of wsm_lot_job_interface.scheduling_method%type;
68 type t_wlji_routing_revision            is table of wsm_lot_job_interface.routing_revision%type;
69 type t_wlji_bom_revision                is table of wsm_lot_job_interface.bom_revision%type;
70 type t_wlji_schedule_group_id           is table of wsm_lot_job_interface.schedule_group_id%type;
71 type t_wlji_schedule_group_name         is table of wsm_lot_job_interface.schedule_group_name%type;
72 type t_wlji_build_sequence              is table of wsm_lot_job_interface.build_sequence%type;
73 type t_wlji_net_quantity                is table of wsm_lot_job_interface.net_quantity%type;
74 type t_wlji_allow_explosion             is table of wsm_lot_job_interface.allow_explosion%type;
75 type t_wlji_old_status_type             is table of wsm_lot_job_interface.old_status_type%type;
76 type t_wlji_interface_id                is table of wsm_lot_job_interface.interface_id%type;
77 type t_wlji_coproducts_supply           is table of wsm_lot_job_interface.coproducts_supply%type;
78 type t_wlji_job_type                    is table of wsm_lot_job_interface.job_type%type;
79 type t_wlji_source_code                 is table of wsm_lot_job_interface.source_code%type;
80 type t_wlji_source_line_id              is table of wsm_lot_job_interface.source_line_id%type;
81 type t_wlji_project_id                  is table of wsm_lot_job_interface.project_id%type;
82 type t_wlji_project_name                is table of wsm_lot_job_interface.project_name%type;
83 type t_wlji_task_id                     is table of wsm_lot_job_interface.task_id%type;
84 type t_wlji_delivery_id                 is table of wsm_lot_job_interface.delivery_id%type;
85 type t_wlji_desc_flx_sgmts              is table of wsm_lot_job_interface.descriptive_flex_segments%type;
86 type t_wlji_project_number              is table of wsm_lot_job_interface.project_number%type;
87 type t_wlji_task_number                 is table of wsm_lot_job_interface.task_number%type;
88 type t_wlji_project_costed              is table of wsm_lot_job_interface.project_costed%type;
89 type t_wlji_end_item_unit_number        is table of wsm_lot_job_interface.end_item_unit_number%type;
90 type t_wlji_overcompl_tol_type          is table of wsm_lot_job_interface.overcompletion_tolerance_type%type;
91 type t_wlji_overcompl_tol_value         is table of wsm_lot_job_interface.overcompletion_tolerance_value%type;
92 type t_wlji_kanban_card_id              is table of wsm_lot_job_interface.kanban_card_id%type;
93 type t_wlji_priority                    is table of wsm_lot_job_interface.priority%type;
94 type t_wlji_due_date                    is table of wsm_lot_job_interface.due_date%type;
95 type t_wlji_task_name                   is table of wsm_lot_job_interface.task_name%type;
96 type t_wlji_process_type                is table of wsm_lot_job_interface.process_type%type;
97 type t_wlji_processing_work_days        is table of wsm_lot_job_interface.processing_work_days%type;
98 type t_wlji_compl_locator_segments      is table of wsm_lot_job_interface.completion_locator_segments%type;
99 type t_wlji_daily_production_rate       is table of wsm_lot_job_interface.daily_production_rate%type;
100 type t_wlji_line_id                     is table of wsm_lot_job_interface.line_id%type;
101 type t_wlji_lot_control_code            is table of wsm_lot_job_interface.lot_control_code%type;
102 type t_wlji_repetitive_schedule_id      is table of wsm_lot_job_interface.repetitive_schedule_id%type;
103 type t_wlji_parent_group_id             is table of wsm_lot_job_interface.parent_group_id%type;
104 type t_wlji_attribute_category          is table of wsm_lot_job_interface.attribute_category%type;
105 type t_wlji_attribute1                  is table of wsm_lot_job_interface.attribute1%type;
106 type t_wlji_attribute2                  is table of wsm_lot_job_interface.attribute2%type;
107 type t_wlji_attribute3                  is table of wsm_lot_job_interface.attribute3%type;
108 type t_wlji_attribute4                  is table of wsm_lot_job_interface.attribute4%type;
109 type t_wlji_attribute5                  is table of wsm_lot_job_interface.attribute5%type;
110 type t_wlji_attribute6                  is table of wsm_lot_job_interface.attribute6%type;
111 type t_wlji_attribute7                  is table of wsm_lot_job_interface.attribute7%type;
112 type t_wlji_attribute8                  is table of wsm_lot_job_interface.attribute8%type;
113 type t_wlji_attribute9                  is table of wsm_lot_job_interface.attribute9%type;
114 type t_wlji_attribute10                 is table of wsm_lot_job_interface.attribute10%type;
115 type t_wlji_attribute11                 is table of wsm_lot_job_interface.attribute11%type;
116 type t_wlji_attribute12                 is table of wsm_lot_job_interface.attribute12%type;
117 type t_wlji_attribute13                 is table of wsm_lot_job_interface.attribute13%type;
118 type t_wlji_attribute14                 is table of wsm_lot_job_interface.attribute14%type;
119 type t_wlji_attribute15                 is table of wsm_lot_job_interface.attribute15%type;
120 type t_wlji_organization_code           is table of wsm_lot_job_interface.organization_code%type;
121 type t_wlji_line_code                   is table of wsm_lot_job_interface.line_code%type;
122 type t_wlji_primary_item_segments       is table of wsm_lot_job_interface.primary_item_segments%type;
123 type t_wlji_bom_reference_segments      is table of wsm_lot_job_interface.bom_reference_segments%type;
124 type t_wlji_rtg_ref_segs                is table of wsm_lot_job_interface.routing_reference_segments%type;
125 type t_wlji_date_released               is table of wsm_lot_job_interface.date_released%type;  --bugfix 2697295
126 
127 
128 -- ==============================================================================================
129 -- instantiating the tables used to bulk bind data from wlji to the PL/SQL tables.
130 -- ==============================================================================================
131 
132 v_wlji_err_code                         t_wlji_err_code := t_wlji_err_code();
133 v_wlji_err_msg                          t_wlji_err_msg := t_wlji_err_msg();
134 v_wlji_last_updt_date                   t_wlji_last_updt_date := t_wlji_last_updt_date();
135 v_wlji_request_id                       t_wlji_request_id := t_wlji_request_id();
136 v_wlji_program_id                       t_wlji_program_id := t_wlji_program_id();
137 v_wlji_program_application_id           t_wlji_program_application_id := t_wlji_program_application_id();
138 v_wlji_last_updt_by                     t_wlji_last_updt_by := t_wlji_last_updt_by();
139 v_wlji_creation_date                    t_wlji_creation_date := t_wlji_creation_date();
140 v_wlji_created_by                       t_wlji_created_by := t_wlji_created_by();
141 v_wlji_last_updt_login                  t_wlji_last_updt_login := t_wlji_last_updt_login();
142 v_wlji_prog_updt_date                   t_wlji_prog_updt_date := t_wlji_prog_updt_date();
143 v_wlji_last_updt_by_name                t_wlji_last_updt_by_name := t_wlji_last_updt_by_name();
144 v_wlji_created_by_name                  t_wlji_created_by_name := t_wlji_created_by_name();
145 v_wlji_org                              t_wlji_org := t_wlji_org();
146 v_wlji_item                             t_wlji_item := t_wlji_item();
147 v_wlji_header_id                        t_wlji_header_id := t_wlji_header_id();
148 v_wlji_process_status                   t_wlji_process_status := t_wlji_process_status();
149 v_wlji_routing_reference_id             t_wlji_routing_reference_id := t_wlji_routing_reference_id();
150 v_wlji_completion_subinventory          t_wlji_completion_subinventory := t_wlji_completion_subinventory();
151 v_wlji_completion_locator_id            t_wlji_completion_locator_id := t_wlji_completion_locator_id();
152 v_wlji_mode_flag                        t_wlji_mode_flag := t_wlji_mode_flag();
153 v_wlji_group_id                         t_wlji_group_id := t_wlji_group_id();
154 v_wlji_load_type                        t_wlji_load_type := t_wlji_load_type();
155 v_wlji_status_type                      t_wlji_status_type := t_wlji_status_type();
156 v_wlji_old_status_type                  t_wlji_old_status_type := t_wlji_old_status_type();
157 v_wlji_lucd                             t_wlji_lucd := t_wlji_lucd();
158 v_wlji_old_completion_date              t_wlji_old_completion_date := t_wlji_old_completion_date();
159 v_wlji_bom_reference_id                 t_wlji_bom_reference_id := t_wlji_bom_reference_id();
160 v_wlji_bom_revision_date                t_wlji_bom_revision_date := t_wlji_bom_revision_date();
161 v_wlji_routing_revision_date            t_wlji_routing_revision_date := t_wlji_routing_revision_date();
162 v_wlji_wip_supply_type                  t_wlji_wip_supply_type := t_wlji_wip_supply_type();
163 v_wlji_class_code                       t_wlji_class_code := t_wlji_class_code();
164 v_wlji_lot_number                       t_wlji_lot_number := t_wlji_lot_number();
165 v_wlji_job_name                         t_wlji_job_name := t_wlji_job_name();
166 v_wlji_description                      t_wlji_description := t_wlji_description();
167 v_wlji_firm_planned_flag                t_wlji_firm_planned_flag := t_wlji_firm_planned_flag();
168 v_wlji_alt_routing_designator           t_wlji_alt_routing_designator := t_wlji_alt_routing_designator();
169 v_wlji_alt_bom_designator               t_wlji_alt_bom_designator := t_wlji_alt_bom_designator();
170 v_wlji_demand_class                     t_wlji_demand_class := t_wlji_demand_class();
171 v_wlji_start_quantity                   t_wlji_start_quantity := t_wlji_start_quantity();
172 v_wlji_old_start_quantity               t_wlji_old_start_quantity := t_wlji_old_start_quantity();
173 v_wlji_wip_entity_id                    t_wlji_wip_entity_id := t_wlji_wip_entity_id();
174 v_wlji_error                            t_wlji_error := t_wlji_error();
175 v_wlji_process_phase                    t_wlji_process_phase := t_wlji_process_phase();
176 v_wlji_fusd                             t_wlji_fusd := t_wlji_fusd();
177 v_wlji_fucd                             t_wlji_fucd := t_wlji_fucd();
178 v_wlji_last_unit_start_date             t_wlji_last_unit_start_date := t_wlji_last_unit_start_date();
179 v_wlji_scheduling_method                t_wlji_scheduling_method := t_wlji_scheduling_method();
180 v_wlji_routing_revision                 t_wlji_routing_revision := t_wlji_routing_revision();
181 v_wlji_bom_revision                     t_wlji_bom_revision := t_wlji_bom_revision();
182 v_wlji_schedule_group_id                t_wlji_schedule_group_id := t_wlji_schedule_group_id();
183 v_wlji_schedule_group_name              t_wlji_schedule_group_name := t_wlji_schedule_group_name();
184 v_wlji_build_sequence                   t_wlji_build_sequence := t_wlji_build_sequence();
185 v_wlji_net_quantity                     t_wlji_net_quantity := t_wlji_net_quantity();
186 v_wlji_allow_explosion                  t_wlji_allow_explosion := t_wlji_allow_explosion();
187 v_wlji_interface_id                     t_wlji_interface_id := t_wlji_interface_id();
188 v_wlji_coproducts_supply                t_wlji_coproducts_supply := t_wlji_coproducts_supply();
189 v_wlji_job_type                         t_wlji_job_type := t_wlji_job_type();
190 v_wlji_source_code                      t_wlji_source_code := t_wlji_source_code();
191 v_wlji_source_line_id                   t_wlji_source_line_id := t_wlji_source_line_id();
192 v_wlji_process_type                     t_wlji_process_type := t_wlji_process_type();
193 v_wlji_processing_work_days             t_wlji_processing_work_days := t_wlji_processing_work_days();
194 v_wlji_daily_production_rate            t_wlji_daily_production_rate := t_wlji_daily_production_rate();
195 v_wlji_line_id                          t_wlji_line_id := t_wlji_line_id();
196 v_wlji_lot_control_code                 t_wlji_lot_control_code := t_wlji_lot_control_code();
197 v_wlji_repetitive_schedule_id           t_wlji_repetitive_schedule_id := t_wlji_repetitive_schedule_id();
198 v_wlji_parent_group_id                  t_wlji_parent_group_id := t_wlji_parent_group_id();
199 v_wlji_attribute_category               t_wlji_attribute_category := t_wlji_attribute_category();
200 v_wlji_attribute1                       t_wlji_attribute1 := t_wlji_attribute1();
201 v_wlji_attribute2                       t_wlji_attribute2 := t_wlji_attribute2();
202 v_wlji_attribute3                       t_wlji_attribute3 := t_wlji_attribute3();
203 v_wlji_attribute4                       t_wlji_attribute4 := t_wlji_attribute4();
204 v_wlji_attribute5                       t_wlji_attribute5 := t_wlji_attribute5();
205 v_wlji_attribute6                       t_wlji_attribute6 := t_wlji_attribute6();
206 v_wlji_attribute7                       t_wlji_attribute7 := t_wlji_attribute7();
207 v_wlji_attribute8                       t_wlji_attribute8 := t_wlji_attribute8();
208 v_wlji_attribute9                       t_wlji_attribute9 := t_wlji_attribute9();
209 v_wlji_attribute10                      t_wlji_attribute10 := t_wlji_attribute10();
210 v_wlji_attribute11                      t_wlji_attribute11 := t_wlji_attribute11();
211 v_wlji_attribute12                      t_wlji_attribute12 := t_wlji_attribute12();
212 v_wlji_attribute13                      t_wlji_attribute13 := t_wlji_attribute13();
213 v_wlji_attribute14                      t_wlji_attribute14 := t_wlji_attribute14();
214 v_wlji_attribute15                      t_wlji_attribute15 := t_wlji_attribute15();
215 v_wlji_organization_code                t_wlji_organization_code := t_wlji_organization_code();
216 v_wlji_line_code                        t_wlji_line_code := t_wlji_line_code();
217 v_wlji_primary_item_segments            t_wlji_primary_item_segments := t_wlji_primary_item_segments();
218 v_wlji_bom_reference_segments           t_wlji_bom_reference_segments := t_wlji_bom_reference_segments();
219 v_wlji_rtg_ref_segs                     t_wlji_rtg_ref_segs := t_wlji_rtg_ref_segs();
220 v_wlji_compl_locator_segments           t_wlji_compl_locator_segments := t_wlji_compl_locator_segments();
221 v_wlji_project_id                       t_wlji_project_id := t_wlji_project_id();
222 v_wlji_project_name                     t_wlji_project_name := t_wlji_project_name();
223 v_wlji_task_id                          t_wlji_task_id := t_wlji_task_id();
224 v_wlji_task_name                        t_wlji_task_name := t_wlji_task_name();
225 v_wlji_desc_flx_sgmts                   t_wlji_desc_flx_sgmts := t_wlji_desc_flx_sgmts();
226 v_wlji_project_number                   t_wlji_project_number := t_wlji_project_number();
227 v_wlji_task_number                      t_wlji_task_number := t_wlji_task_number();
228 v_wlji_project_costed                   t_wlji_project_costed := t_wlji_project_costed();
229 v_wlji_end_item_unit_number             t_wlji_end_item_unit_number := t_wlji_end_item_unit_number();
230 v_wlji_overcompl_tol_type               t_wlji_overcompl_tol_type := t_wlji_overcompl_tol_type();
231 v_wlji_overcompl_tol_value              t_wlji_overcompl_tol_value := t_wlji_overcompl_tol_value();
232 v_wlji_kanban_card_id                   t_wlji_kanban_card_id := t_wlji_kanban_card_id();
233 v_wlji_priority                         t_wlji_priority := t_wlji_priority();
234 v_wlji_due_date                         t_wlji_due_date := t_wlji_due_date();
235 v_wlji_delivery_id                      t_wlji_delivery_id := t_wlji_delivery_id();
236 v_wlji_date_released                    t_wlji_date_released := t_wlji_date_released();       --bugfix 2697295
237 
238 
239 --=======================================================================================================
240 --corresponding table type and table declarations for wsm_starting_lots_interface
241 --=======================================================================================================
242 
243 type t_wsli_header_id           is table of wsm_starting_lots_interface.header_id%type;
244 type t_wsli_lot_number          is table of wsm_starting_lots_interface.lot_number%type;
245 type t_wsli_inventory_item_id   is table of wsm_starting_lots_interface.inventory_item_id%type;
246 type t_wsli_organization_id     is table of wsm_starting_lots_interface.organization_id%type;
247 type t_wsli_quantity            is table of wsm_starting_lots_interface.quantity%type;
248 type t_wsli_subinventory_code   is table of wsm_starting_lots_interface.subinventory_code%type;
249 type t_wsli_locator_id          is table of wsm_starting_lots_interface.locator_id%type;
250 type t_wsli_revision            is table of wsm_starting_lots_interface.revision%type;
251 type t_wsli_last_updated_by     is table of wsm_starting_lots_interface.last_updated_by%type;
252 type t_wsli_created_by          is table of wsm_starting_lots_interface.created_by%type;
253 type t_wsli_primary_uom_code    is table of mtl_system_items.primary_uom_code%type;
254 type t_wsli_comp_issue_qty      is table of wsm_starting_lots_interface.component_issue_quantity%type;
255 
256 v_wsli_header_id                t_wsli_header_id := t_wsli_header_id();
257 v_wsli_lot_number               t_wsli_lot_number := t_wsli_lot_number();
258 v_wsli_inventory_item_id        t_wsli_inventory_item_id := t_wsli_inventory_item_id();
259 v_wsli_organization_id          t_wsli_organization_id := t_wsli_organization_id();
260 v_wsli_quantity                 t_wsli_quantity := t_wsli_quantity();
261 v_wsli_subinventory_code        t_wsli_subinventory_code := t_wsli_subinventory_code();
262 v_wsli_locator_id               t_wsli_locator_id := t_wsli_locator_id();
263 v_wsli_revision                 t_wsli_revision := t_wsli_revision();
264 v_wsli_last_updated_by          t_wsli_last_updated_by := t_wsli_last_updated_by();
265 v_wsli_created_by               t_wsli_created_by := t_wsli_created_by();
266 v_wsli_primary_uom_code         t_wsli_primary_uom_code := t_wsli_primary_uom_code();
267 v_wsli_comp_issue_qty           t_wsli_comp_issue_qty := t_wsli_comp_issue_qty();
268 
269 -- ========================================================================================================
270 -- creating an index by table that'll store the wsli values with header_id as the index for easy validation
271 -- ========================================================================================================
272 
273 type rec_wsli IS record(
274         lot_number              wsm_starting_lots_interface.lot_number%type,
275         inventory_item_id       wsm_starting_lots_interface.inventory_item_id%type,
276         organization_id         wsm_starting_lots_interface.organization_id%type,
277         quantity                wsm_starting_lots_interface.quantity%type,
278         subinventory_code       wsm_starting_lots_interface.subinventory_code%type,
279         locator_id              wsm_starting_lots_interface.locator_id%type,
280         revision                wsm_starting_lots_interface.revision%type,
281         last_updated_by         wsm_starting_lots_interface.last_updated_by%type,
282         created_by              wsm_starting_lots_interface.created_by%type,
283         primary_uom_code        mtl_system_items.primary_uom_code%type,
284         comp_issue_quantity     wsm_starting_lots_interface.component_issue_quantity%type);
285 
286 v_rec_wsli rec_wsli;
287 
288 type t_wsli                     IS table of rec_wsli index by binary_integer;
289 v_wsli  t_wsli;
290 
291 
292 routing_seq_id                  NUMBER;
293 bom_seq_id                      NUMBER;
294 p_common_routing_sequence_id    NUMBER;
295 p_common_bill_sequence_id       NUMBER;
296 l_atleast_one_osp_exists        NUMBER := 0;
297 
298 --***********************************************************************************************
299 -- ==============================================================================================
300 -- PROCESS_INTERFACE_ROWS
301 -- ==============================================================================================
302 --***********************************************************************************************
303 
304 
305 -- BEGIN: CZHDBG TBD after UT
306 function get_one_org_id (
307     p_group_id in number,
308     p_status   in number
309 ) RETURN NUMBER IS
310 
311 cursor c_org is
312     select  organization_id,
313             organization_code
314     from    wsm_lot_job_interface
315     where   process_status = p_status
316     and     NVL(transaction_date, creation_date) <= sysdate+1
317     and     NVL(group_id, -99) = NVL(p_group_id, NVL(group_id, -99))
318     and     load_type in (5, 6)
319     union
320     select  organization_id,
321             organization_code
322     from    wsm_lot_job_dtl_interface
323     where   process_status = p_status
324     and     parent_header_id IS NULL
325     and     NVL(group_id, -99) = NVL(p_group_id, NVL(group_id, -99))
326     and     transaction_date <= sysdate+1;
327 
328 l_temp      number;
329 l_org_id    number      := null;
330 l_org_code  varchar2(10):= null;
331 
332 BEGIN
333 
334     -- get an org_id from interface table
335     OPEN c_org;
336     FETCH c_org into l_org_id, l_org_code;
337     if c_org%NOTFOUND then
338         fnd_file.put_line(fnd_file.log, 'get_one_org_id: No entry is found in interface table');
339         return -1;
340     end if;
341     CLOSE c_org;
342 
343     if l_org_id IS NULL then
344         begin
345             --bug 5051783:Replaced org_organization_definitions with mtl_parameters.
346             select organization_id
347             into   l_org_id
348             --from   ORG_ORGANIZATION_DEFINITIONS
349             from   mtl_parameters
350             where  organization_code = l_org_code;
351         exception
352             when others then
353                 fnd_message.set_name('WSM','WSM_INVALID_FIELD');
354                 fnd_message.set_token('FLD_NAME', 'Organization Code');
355                 fnd_file.put_line(fnd_file.log, 'get_one_org_id: ' || fnd_message.get);
356                 return -1;
357         end;
358     end if;
359 
360     begin
361         select  1
362         into    l_temp
363         from    MTL_PARAMETERS MP ,
364                 WSM_PARAMETERS WSM,
365                 HR_ALL_ORGANIZATION_UNITS ORG,
366                 WIP_PARAMETERS WP
367         where   MP.ORGANIZATION_ID  =  WSM.ORGANIZATION_ID
368         and     ORG.ORGANIZATION_ID =  WSM.ORGANIZATION_ID
369         and     WP.ORGANIZATION_ID  =  WSM.ORGANIZATION_ID
370         and     UPPER(MP.WSM_ENABLED_FLAG)='Y'
371         and     TRUNC(SYSDATE) <= NVL(ORG.DATE_TO, SYSDATE+1)
372         and     WSM.ORGANIZATION_ID = l_org_id;
373     exception
374         when others then
375             fnd_message.set_name('WSM','WSM_INVALID_FIELD');
376             fnd_message.set_token('FLD_NAME', 'Organization ID');
377             fnd_file.put_line(fnd_file.log, 'get_one_org_id: ' || fnd_message.get);
378             return -1;
379     end;
380 
381     return l_org_id;
382 END;
383 -- END: CZHDBG TBD after UT
384 
385 
386 PROCEDURE process_interface_rows (
387         retcode         OUT NOCOPY NUMBER,
388         errbuf          OUT NOCOPY VARCHAR2,
389         p_group_id      IN  NUMBER) IS
390 
391 l_org_id        number;
392 l_profile       number;
393 conc_status     boolean;
394 
395 BEGIN
396 
397     IF (WSMPUTIL.REFER_SITE_LEVEL_PROFILE = 'Y') THEN
398         l_profile := WSMPUTIL.CREATE_LBJ_COPY_RTG_PROFILE(0);
399     ELSE
400         l_org_id := get_one_org_id(p_group_id, WIP_CONSTANTS.PENDING);
401         if (l_org_id = -1) then
402             conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR',
403                         'Error: failed in  get_one_org_id');
404             return;
405         end if;
406         l_profile := WSMPUTIL.CREATE_LBJ_COPY_RTG_PROFILE(l_org_id);
407     END IF;
408 
409     if(l_profile = 2) then
410         g_create_job_copy := 'N';
411         fnd_file.put_line(fnd_file.log,
412             '++++++ Start calling WSMPLBJI.process_lbji_rows_1159 ++++++');
413         process_lbji_rows_1159 (retcode, errbuf, p_group_id);
414         fnd_file.put_line(fnd_file.log,
415             '++++++ End calling WSMPLBJI.process_lbji_rows_1159 ++++++');
416     else
417         g_create_job_copy := 'Y';
418         fnd_file.put_line(fnd_file.log,
419             '++++++ Start calling WSM_LBJ_INTERFACE_PVT.process_lbji_rows ++++++');
420         WSM_LBJ_INTERFACE_PVT.process_lbji_rows(retcode, errbuf, p_group_id);
421         fnd_file.put_line(fnd_file.log,
422             '++++++ End calling WSM_LBJ_INTERFACE_PVT.process_lbji_rows ++++++');
423     end if;
424 
425 END process_interface_rows ;
426 
427 
428 --***********************************************************************************************
429 -- ==============================================================================================
430 -- LAUNCH WORKER
431 -- ==============================================================================================
432 --***********************************************************************************************
433 
434 PROCEDURE  launch_worker (
435         retcode         OUT NOCOPY NUMBER,
436         errbuf          OUT NOCOPY VARCHAR2,
437         l_group_id      IN  NUMBER,
438         alotted_rows    IN  NUMBER  ) IS
439 
440 l_org_id        number; -- CZHDBG: TBD after UT
441 l_profile       number;
442 conc_status     boolean;
443 
444 BEGIN
445 
446     IF (WSMPUTIL.REFER_SITE_LEVEL_PROFILE = 'Y') THEN
447         l_profile := WSMPUTIL.CREATE_LBJ_COPY_RTG_PROFILE(0);
448     ELSE
449         l_org_id := get_one_org_id(l_group_id, WIP_CONSTANTS.RUNNING);
450         if (l_org_id = -1) then
451             conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR',
452                         'Error: failed in  get_one_org_id');
453             return;
454         end if;
455         l_profile := WSMPUTIL.CREATE_LBJ_COPY_RTG_PROFILE(l_org_id);
456     END IF;
457 
458     if(l_profile = 2) then
459         g_create_job_copy := 'N';
460         fnd_file.put_line(fnd_file.log, '++++++ Calling WSMPLBJI.launch_worker_1159 ++++++');
461         WSMPLBJI.launch_worker_1159(retcode, errbuf, l_group_id, alotted_rows);
462     else
463         g_create_job_copy := 'Y';
464         fnd_file.put_line(fnd_file.log, '++++++ Calling WSM_LBJ_INTERFACE_PVT.launch_worker ++++++');
465         WSM_LBJ_INTERFACE_PVT.launch_worker(retcode, errbuf, l_group_id, alotted_rows);
466     end if;
467 
468 END launch_worker;
469 
470 
471 
472 
473 --***********************************************************************************************
474 -- ==============================================================================================
475 -- PROCEDURE build_lbji_info
476 -- ==============================================================================================
477 --***********************************************************************************************
478 
479 -- For job creation, this needs to be called with p_rtg_op_seq_num as the rtg op_seq_num of the
480 -- first operation. The other option is to call this with rtg_op_seq_num as null, then it'll be
481 -- assumed that the procedure is being called for job creation. This is being done solely for
482 -- avoiding repetition of code. hence from a performance point of view.
483 
484 -- p_explode_header_detail = null => write into we,wdj and wo tables
485 --                         = 1 => write only into wo tables
486 --                         = 2 => write only into we/wdj tables
487 
488 -- Note that a new wip_entity_id will be generated only if the procedure is called with
489 -- p_explode_header_detail as null or 2. In some cases we may use build_lbji_info for
490 -- just exploding details for an existing header. In that case, p_explode_header_detail
491 -- should have value 1 and the value of wip_entity_id that is passed is used.
492 
493 -- p_src_client_server: 1 => this procedure is being called from client side,
494 --              any other value => server side call.
495 
496 -- p_po_creation_time: => pass the value of po_creation_time in wip_parameters for the org
497 
498 procedure build_lbji_info(
499         p_routing_seq_id                IN      number,
500         p_common_bill_sequence_id       IN      number,
501         p_explode_header_detail         IN      number,
502         p_status_type                   IN      number,
503         p_class_code                    IN      varchar2,
504         p_org                           IN      number,
505         p_wip_entity_id                 IN OUT NOCOPY number,
506         p_last_updt_date                IN      date,
507         p_last_updt_by                  IN      number,
508         p_creation_date                 IN      date,
509         p_created_by                    IN      number,
510         p_last_updt_login               IN      number,
511         p_request_id                    IN      number,
512         p_program_application_id        IN      number,
513         p_program_id                    IN      number,
514         p_prog_updt_date                IN      date,
515         p_source_line_id                IN      number,
516         p_source_code                   IN      varchar2,
517         p_description                   IN      varchar2,
518         p_item                          IN      number,
519         p_job_type                      IN      number,
520         p_bom_reference_id              IN      number,
521         p_routing_reference_id          IN      number,
522         p_firm_planned_flag             IN      number,
523         p_wip_supply_type               IN      number,
524         p_fusd                          IN      date,
525         p_lucd                          IN      date,
526         p_start_quantity                IN      number,
527         p_net_quantity                  IN      number,
528         p_coproducts_supply             IN      number,
529         p_bom_revision                  IN      varchar2,
530         p_routing_revision              IN      varchar2,
531         p_bom_revision_date             IN      date,
532         p_routing_revision_date         IN      date,
533         p_lot_number                    IN      varchar2,
534         p_alt_bom_designator            IN      varchar2,
535         p_alt_routing_designator        IN      varchar2,
536         p_priority                      IN      number,
537         p_due_date                      IN      date,
538         p_attribute_category            IN      varchar2,
539         p_attribute1                    IN      varchar2,
540         p_attribute2                    IN      varchar2,
541         p_attribute3                    IN      varchar2,
542         p_attribute4                    IN      varchar2,
543         p_attribute5                    IN      varchar2,
544         p_attribute6                    IN      varchar2,
545         p_attribute7                    IN      varchar2,
546         p_attribute8                    IN      varchar2,
547         p_attribute9                    IN      varchar2,
548         p_attribute10                   IN      varchar2,
549         p_attribute11                   IN      varchar2,
550         p_attribute12                   IN      varchar2,
551         p_attribute13                   IN      varchar2,
552         p_attribute14                   IN      varchar2,
553         p_attribute15                   IN      varchar2,
554         p_job_name                      IN      varchar2,
555         p_completion_subinventory       IN      varchar2,
556         p_completion_locator_id         IN      number,
557         p_demand_class                  IN      varchar2,
558         p_project_id                    IN      number,
559         p_task_id                       IN      number,
560         p_schedule_group_id             IN      number,
561         p_build_sequence                IN      number,
562         p_line_id                       IN      number,
563         p_kanban_card_id                IN      number,
564         p_overcompl_tol_type            IN      number,
565         p_overcompl_tol_value           IN      number,
566         p_end_item_unit_number          IN      number,
567         p_rtg_op_seq_num                IN      number,
568         p_src_client_server             IN      number,
569         p_po_creation_time              IN      number,
570         p_date_released                 IN      date,  -- bug 2697295
571         p_error_code             OUT NOCOPY number,
572         p_error_msg              OUT NOCOPY     varchar2) IS
573 
574 
575 l_stmt_num                      number;
576 l_common_routing_sequence_id    number;
577 l_error_code                    number;
578 l_error_msg                     varchar2(2000);
579 l_material_account              number;
580 l_material_overhead_account     number;
581 l_resource_account              number;
582 l_outside_processing_account    number;
583 l_material_variance_account     number;
584 l_resource_variance_account     number;
585 l_outside_proc_var_acc          number;
586 l_std_cost_adjustment_account   number;
587 l_overhead_account              number;
588 l_overhead_variance_account     number;
589 l_po_creation_time              number;
590 l_est_scrap_account             number;
591 l_est_scrap_var_account         number;
592 l_bon_seq_id1                   number;
593 l_bon_seq_id2                   number;
594 l_dummy                         number;
595 l_job_seq_num                   number;
596 l_op_seq_incr                   number;
597 l_end_seq_id                    number;
598 l_start_seq_id                  number;
599 abb_op_seq_num                  number;
600 l_rtg_op_seq_num                number;
601 max_op_seq_num                  number;
602 l_returnstatus                  varchar2(1);
603 translated_meaning              varchar2(240);
604 l_lucd                          date; -- BUG 3520916
605 --Bug 5207481: issued quantity is not updated any more.
606 --l_include_comp_yld              NUMBER; -- VJ: Added for Component Shrinkage project
607 
608 build_job_exception             exception;
609 
610 cursor wsm_bon_cur is (
611     select from_op_seq_id "from_opseq_id", level
612     from   bom_operation_networks
613     where  transition_type = 1
614     start with to_op_seq_id = l_bon_seq_id1 and transition_type = 1
615     connect by to_op_seq_id = prior from_op_seq_id and transition_type = 1
616     union
617     select l_bon_seq_id1 "from_opseq_id", -1
618     from   dual
619 ) order by 2 desc;
620 
621 
622 BEGIN
623     l_rtg_op_seq_num := p_rtg_op_seq_num;
624 
625     if (p_explode_header_detail is null) or (p_explode_header_detail = 2) then
626         select wip_entities_s.nextval
627         into p_wip_entity_id
628         from dual;
629     end if;
630 
631     p_error_code := 0;
632     p_error_msg := '';
633 
634     if (p_explode_header_detail is null) or (p_explode_header_detail = 1) then
635 
636 l_stmt_num := 10;
637         Begin
638 
639             wsmputil.find_common_routing(
640                         p_routing_sequence_id => p_routing_seq_id,
641                         p_common_routing_sequence_id => l_common_routing_sequence_id,
642                         x_err_code => l_error_code,
643                         x_err_msg => l_error_msg);
644 
645             if l_error_code <> 0 then
646                 raise build_job_exception;
647             end if;
648 
649 
650 l_stmt_num := 20;
651 -- If the op-seq-id in bon is effective as of the rgt_rev_date, fine. If it's not, check to see
652 -- if a replacement exitsts in bos. If no, then return error. Otherwise return no error, but
653 -- return the ORIGINAL op-seq-id defined in bon with the understanding that it may actually not be eff.
654 -- This holds for both find_routing_start and end.
655 
656             wsmputil.FIND_ROUTING_START(
657                         l_common_routing_sequence_id,
658                         p_routing_revision_date,  -- CZH.I_OED-1
659                         l_start_seq_id,
660                         l_error_code,
661                         l_error_msg);
662 
663             if l_error_code <> 0 then
664                 raise build_job_exception;
665             end if;
666 
667 
668             -- BA: CZH.I_OED-1, call this to make sure the end is effective
669 l_stmt_num := 25;
670             wsmputil.FIND_ROUTING_END(
671                         l_common_routing_sequence_id,
672                         p_routing_revision_date,  -- CZH.I_OED-1
673                         l_end_seq_id,
674                         l_error_code,
675                         l_error_msg);
676 
677             if l_error_code <> 0 then
678                 raise build_job_exception;
679             end if;
680             -- EA: CZH.I_OED-1
681 
682 l_stmt_num := 35;
683             if l_rtg_op_seq_num is null then -- first operation
684 
685                 -- While this start_seq_id is not necessarily the "effective" op_seq_id as of routing-rev-date in BON,
686                 -- here we are intesrested in the op-seq-num from bos... (abb)
687 
688                 select operation_seq_num
689                 into   l_rtg_op_seq_num
690                 from   bom_operation_sequences
691                 where  operation_sequence_id = l_start_seq_id
692                 and    routing_sequence_id = l_common_routing_sequence_id;
693                 -- BD: CZH.I_OED-1
694                 --and    sysdate <= nvl(disable_date, sysdate+1)
695                 --and    effectivity_date <= sysdate;
696                 -- ED: CZH.I_OED-1
697 
698                 l_bon_seq_id1 := l_start_seq_id;
699             else
700 
701                 -- Here, on the contrary, we are to find the op-seq-id given the op-seq-num. Validations for bonus
702                 -- will make sure that either all the operations till the user-entered op-seq-num is valid
703                 -- or there are replacements defined. Now, in bos, given an op-seq-num, we may find multiple
704                 -- number of op-seq-id's, thus the following sql WOULD have returned multiple rows if not I had
705                 -- included a condition that the op-seq-id must exists in bon too. Note that this op-seq-id
706                 -- is not necessarily the effective one, but this exists in the network and would be used by the
707                 -- wsm_bon_cur cursor to find the other op-seq-id's in the network. IN the cursor loop,
708                 -- wsmputil.replacement_op_seq_id has been used to find the equivalent effective op-seq-id's. (abb)
709 
710                 select  unique(bos.operation_sequence_id)
711                 into    l_bon_seq_id1
712                 from    bom_operation_sequences bos, bom_operation_networks bon
713                 where   bos.operation_seq_num = l_rtg_op_seq_num
714                 and     bos.routing_sequence_id = l_common_routing_sequence_id
715                 -- BA: CZH.OED-2, it may have a replacement
716                 and     (bos.operation_sequence_id = bon.from_op_seq_id
717                 or      bos.operation_sequence_id = bon.to_op_seq_id);
718                 -- EA: CZH.OED-2
719 
720             end if;
721 
722             -- osp begin
723             if  wsmputil.check_po_move (
724                         p_sequence_id => l_bon_seq_id1,
725                         p_sequence_id_type => 'O',
726                         p_routing_rev_date => p_routing_revision_date,
727                         x_err_code => l_error_code,
728                         x_err_msg => l_error_msg) then
729                 fnd_message.set_name('WSM','WSM_FIRST_OP_PO_MOVE');
730                 p_error_code := -1;
731                 p_error_msg := fnd_message.get;
732                 return;
733             end if;
734             --osp end
735 
736 l_stmt_num := 40;
737             select nvl(OP_SEQ_NUM_INCREMENT, 10)
738             into   l_op_seq_incr
739             from   wsm_parameters
740             where  ORGANIZATION_ID = p_org;
741 
742             l_job_seq_num := 0;
743 
744 l_stmt_num := 50;
745             OPEN wsm_bon_cur;
746             LOOP
747                 FETCH wsm_bon_cur into l_bon_seq_id2, l_dummy;
748                 EXIT when wsm_bon_cur%NOTFOUND;
749 
750                 -- BA: CZH.I_OED-2
751                 l_bon_seq_id2 := wsmputil.replacement_op_seq_id(
752                                          l_bon_seq_id2,
753                                          p_routing_revision_date);
754                 -- EA: CZH.I_OED-2
755 
756                 l_job_seq_num := l_job_seq_num + l_op_seq_incr;
757 
758                 -- BA: bug 3520916
759                 if (l_bon_seq_id2 =  l_bon_seq_id1) then
760                     l_lucd := p_lucd;
761                 else
762                     l_lucd := p_fusd;
763                 end if;
764                 -- EA: bug 3520916
765 
766 
767 l_stmt_num := 60;
768                 insert_procedure(
769                         p_seq_id => l_bon_seq_id2,
770                         p_job_seq_num => l_job_seq_num,
771                         p_common_routing_sequence_id => l_common_routing_sequence_id,
772                         p_supply_type => p_wip_supply_type,
773                         p_wip_entity_id => p_wip_entity_id,
774                         p_organization_id => p_org,
775                         p_quantity => p_start_quantity,
776                         p_job_type => p_job_type,
777                         p_bom_reference_id => p_bom_reference_id,
778                         p_rtg_reference_id => p_routing_reference_id,
779                         p_assembly_item_id => p_item,
780                         p_alt_bom_designator => p_alt_bom_designator,
781                         p_alt_rtg_designator => p_alt_routing_designator,
782                         p_fusd => p_fusd,
783                         --p_lucd => p_lucd, -- bug 3520916
784                         p_lucd => l_lucd,   -- bug 3520916
785                         p_rtg_revision_date => p_routing_revision_date,
786                         p_bom_revision_date => p_bom_revision_date,
787                         p_last_updt_date => p_last_updt_date,
788                         p_last_updt_by => p_last_updt_by,
789                         p_creation_date => p_creation_date,
790                         p_created_by => p_created_by,
791                         p_last_updt_login => p_last_updt_login,
792                         p_request_id => p_request_id,
793                         p_program_application_id => p_program_application_id,
794                         p_program_id => p_program_id,
795                         p_prog_updt_date => p_prog_updt_date,
796                         p_error_code => l_error_code,
797                         p_error_msg => l_error_msg);
798 
799                 if l_error_code <> 0 then
800                         raise build_job_exception;
801                 end if;
802 
803             END LOOP;
804             CLOSE wsm_bon_cur;
805 
806 l_stmt_num := 75;
807             select operation_seq_num
808             into   abb_op_seq_num
809             from   wip_operations
810             where  wip_entity_id = p_wip_entity_id
811             and    operation_sequence_id = wsmputil.replacement_op_seq_id(
812                                                  l_bon_seq_id1,
813                                                  p_routing_revision_date);
814 
815 l_stmt_num := 76;
816             select max(operation_seq_num)
817             into   max_op_seq_num
818             from   wip_operations
819             where  wip_entity_id = p_wip_entity_id;
820 
821 
822 l_stmt_num := 80;
823 
824             UPDATE  WIP_OPERATIONS WO
825             set     wo.previous_operation_seq_num =
826                         (select max(operation_seq_num)
827                            from wip_operations
828                           where wip_entity_id = p_wip_entity_id
829                             and operation_seq_num < wo.operation_seq_num),
830                     wo.next_operation_seq_num =
831                         (select min(operation_seq_num)
832                            from wip_operations
833                           where wip_entity_id = p_wip_entity_id
834                             and operation_seq_num > wo.operation_seq_num),
835                     wo.quantity_in_queue = decode(operation_seq_num, max_op_seq_num,
836                                         (decode(p_status_type, 3,
837                                         ROUND(p_start_quantity, WIP_CONSTANTS.MAX_DISPLAYED_PRECISION), 0)), 0)
838             where   wo.wip_entity_id = p_wip_entity_id;
839 
840 
841             if (lbji_debug = 'Y') then
842                 fnd_file.put_line(fnd_file.log,'update wo('||l_stmt_num||'): '|| SQL%ROWCOUNT);
843             end if;
844 
845             update WIP_OPERATIONS
846             --Bug 5207481:Actual quantity changes for bonus:costed_quantity_completed
847             -- is updated instead of quantity_completed.
848             set    wsm_costed_quantity_completed = p_start_quantity
849             --Bug 5510126:Scheduled quantity is getting populated in insert_procedure
850             --for old operations also during move.
851                   ,scheduled_quantity = 0
852             where  wip_entity_id = p_wip_entity_id
853             and    operation_seq_num < abb_op_seq_num;
854 
855             if (lbji_debug = 'Y') then
856                 fnd_file.put_line(fnd_file.log,'update quantity_cmplted in wo('||l_stmt_num||'): '|| SQL%ROWCOUNT);
857             end if;
858 
859            --Bug 5207481:Actual quantity changes for bonus-Start of changes
860             -- CJ: Start changes for Component Shrinkage project --
861            /* select include_component_yield
862             into   l_include_comp_yld
863             from   wip_parameters
864             where  organization_id = p_org;*/
865 
866             --IF (nvl(l_include_comp_yld, 1) = 1) THEN -- Include Component Yield
867                 update wip_requirement_operations
868                 --set    quantity_issued = required_quantity
869                 set    quantity_issued = 0
870                        ,required_quantity = 0
871                 where  wip_entity_id = p_wip_entity_id
872                 and    operation_seq_num < abb_op_seq_num;
873                 --Bug 5207481:Actual quantity changes:Issued qty and reviewed qty should be
874                 --set to 0 irrespective of supply type as these fields are not used by costing now.
875                 --and    wip_supply_type not in (2, 4, 5, 6); -- Fix for bug #2685463
876 
877             /*ELSIF (nvl(l_include_comp_yld, 1) = 2) THEN -- DO NOT Include Component Yield
878                 update wip_requirement_operations
879                 set    quantity_issued = round(quantity_per_assembly * decode(nvl(basis_type,1), 2, 1, p_start_quantity), 6)
880                 where  wip_entity_id = p_wip_entity_id
881                 and    operation_seq_num < abb_op_seq_num
882                 and    wip_supply_type not in (2, 4, 5, 6); -- Fix for bug #2685463
883             END IF;*/
884             -- CJ: End changes for Component Shrinkage project --
885            --Bug 5207481:Actual quantity changes for bonus-End of changes
886 
887             if (lbji_debug = 'Y') then
888                 fnd_file.put_line(fnd_file.log,'update quantity_issued in wro('||l_stmt_num||'): '|| SQL%ROWCOUNT);
889             end if;
890 
891         Exception
892 
893             when build_job_exception then
894                 p_error_code := l_error_code;
895                 p_error_msg := substr('wsmplbji.build_lbji_info: stmt no: '||l_stmt_num||' '||l_error_msg, 1, 2000);
896                 return;
897 
898         End;
899 
900     end if; -- p_explode_header_detail
901 
902     if (p_explode_header_detail is null) or (p_explode_header_detail = 2) then
903 
904 l_stmt_num := 100;
905 
906         if p_explode_header_detail = 2 then
907             wsmputil.find_common_routing(
908                 p_routing_sequence_id => p_routing_seq_id,
909                 p_common_routing_sequence_id => l_common_routing_sequence_id,
910                 x_err_code => p_error_code,
911                 x_err_msg => p_error_msg);
912 
913             if p_error_code <> 0 then
914                 return;
915             end if;
916         end if;
917 
918         BEGIN
919         select  wac.material_account,
920                 wac.material_overhead_account,
921                 wac.resource_account,
922                 wac.outside_processing_account,
923                 wac.material_variance_account,
924                 wac.resource_variance_account,
925                 wac.outside_proc_variance_account,
926                 wac.std_cost_adjustment_account,
927                 wac.overhead_account,
928                 wac.overhead_variance_account,
929                 params.po_creation_time,
930                 wac.est_scrap_account,
931                 wac.est_scrap_var_account
932         into    l_material_account,
933                 l_material_overhead_account,
934                 l_resource_account,
935                 l_outside_processing_account,
936                 l_material_variance_account,
937                 l_resource_variance_account,
938                 l_outside_proc_var_acc,
939                 l_std_cost_adjustment_account,
940                 l_overhead_account,
941                 l_overhead_variance_account,
942                 l_po_creation_time,
943                 l_est_scrap_account,
944                 l_est_scrap_var_account
945         from    wip_accounting_classes wac,
946                 wip_parameters params
947         where   wac.class_code(+)= p_class_code
948         and     wac.organization_id(+)= p_org
949         and     params.organization_id = p_org;
950         EXCEPTION
951             when others then
952                 p_error_code := SQLCODE;
953                 p_error_msg := substr('wsmplbji.build_lbji_info: stmt no: '||l_stmt_num||' '||SQLERRM, 1, 2000);
954                 return;
955         END;
956 
957 
958 
959 l_stmt_num := 110;
960 
961         if wsmputil.WSM_ESA_ENABLED(p_wip_entity_id => null,
962                         err_code => l_error_code,
963                         err_msg => l_error_msg,
964                         p_org_id => p_org,
965                         p_job_type => p_job_type) = 1
966                 and (l_est_scrap_account is null or l_est_scrap_var_account is null) then
967                         fnd_message.set_name('WSM','WSM_NO_WAC_SCRAP_ACC');
968                         fnd_message.set_token('CC',p_class_code);
969                         p_error_code := -1;
970                         p_error_msg := fnd_message.get;
971             return;
972         end if;
973 
974 
975 l_stmt_num := 120;
976 
977         Begin
978 
979             INSERT INTO WIP_DISCRETE_JOBS (
980                  wip_entity_id,
981                  organization_id,
982                  last_update_date,
983                  last_updated_by,
984                  creation_date,
985                  created_by,
986                  last_update_login,
987                  request_id,
988                  program_application_id,
989                  program_id,
990                  program_update_date,
991                  source_line_id,
992                  source_code,
993                  description,
994                  status_type,
995                  date_released,
996                  primary_item_id,
997                  bom_reference_id,
998                  routing_reference_id,
999                  firm_planned_flag,
1000                  job_type,
1001                  wip_supply_type,
1002                  class_code,
1003                  material_account,
1004                  material_overhead_account,
1005                  resource_account,
1006                  outside_processing_account,
1007                  material_variance_account,
1008                  resource_variance_account,
1009                  outside_proc_variance_account,
1010                  std_cost_adjustment_account,
1011                  overhead_account,
1012                  overhead_variance_account,
1013                  scheduled_start_date,
1014                  scheduled_completion_date,
1015                  start_quantity,
1016                  quantity_completed,
1017                  quantity_scrapped,
1018                  net_quantity,
1019                  common_bom_sequence_id,
1020                  common_routing_sequence_id,
1021                  bom_revision,
1022                  routing_revision,
1023                  bom_revision_date,
1024                  routing_revision_date,
1025                  lot_number,
1026                  alternate_bom_designator,
1027                  alternate_routing_designator,
1028                  completion_subinventory,
1029                  completion_locator_id,
1030                  demand_class,
1031                  project_id,
1032                  task_id,
1033                  schedule_group_id,
1034                  build_sequence,
1035                  line_id,
1036                  kanban_card_id,
1037                  overcompletion_tolerance_type,
1038                  overcompletion_tolerance_value,
1039                  end_item_unit_number,
1040                  po_creation_time,
1041                  priority,
1042                  due_date,
1043                  attribute_category,
1044                  attribute1,
1045                  attribute2,
1046                  attribute3,
1047                  attribute4,
1048                  attribute5,
1049                  attribute6,
1050                  attribute7,
1051                  attribute8,
1052                  attribute9,
1053                  attribute10,
1054                  attribute11,
1055                  attribute12,
1056                  attribute13,
1057                  attribute14,
1058                  attribute15,
1059                  est_scrap_account,
1060                  est_scrap_var_account,
1061                  coproducts_supply
1062             )
1063             VALUES
1064             (
1065                  p_wip_entity_id,
1066                  p_org,
1067                  p_last_updt_date,
1068                  p_last_updt_by,
1069                  p_creation_date,
1070                  p_created_by,
1071                  p_last_updt_login,
1072                  p_request_id,
1073                  p_program_application_id,
1074                  p_program_id,
1075                  p_prog_updt_date,
1076                  p_source_line_id,
1077                  p_source_code,
1078                  p_description,
1079                  p_status_type,
1080                  p_date_released,
1081         --       decode(p_status_type, WIP_CONSTANTS.UNRELEASED, NULL, SYSDATE), --Removed TRUNC for HH24MISS
1082                  p_item,
1083                  decode(p_job_type, 3,p_bom_reference_id, null),
1084                  decode(p_job_type, 3, p_routing_reference_id, null),
1085                  p_firm_planned_flag,
1086                  decode(p_job_type, 3, WIP_CONSTANTS.NONSTANDARD, WIP_CONSTANTS.STANDARD),
1087                  p_wip_supply_type,
1088                  p_class_code,
1089                  l_material_account,
1090                  l_material_overhead_account,
1091                  l_resource_account,
1092                  l_outside_processing_account,
1093                  l_material_variance_account,
1094                  l_resource_variance_account,
1095                  l_outside_proc_var_acc,
1096                  l_std_cost_adjustment_account,
1097                  l_overhead_account,
1098                  l_overhead_variance_account,
1099                  TRUNC(p_fusd,'MI'),        --round(p_fusd,'MI'),
1100                  TRUNC(p_lucd,'MI'),        --round(p_lucd,'MI'),
1101                  ROUND(p_start_quantity, WIP_CONSTANTS.MAX_DISPLAYED_PRECISION),
1102                  0,
1103                  0,
1104                  ROUND(p_net_quantity, WIP_CONSTANTS.MAX_DISPLAYED_PRECISION),
1105                  p_common_bill_sequence_id,
1106                  l_common_routing_sequence_id,
1107                  p_bom_revision,
1108                  p_routing_revision,
1109                  p_bom_revision_date, -- HH24MISS -- Removed rounding to 'MI'
1110                  p_routing_revision_date, -- HH24MISS -- Removed rounding to 'MI'
1111                  p_lot_number,
1112                  p_alt_bom_designator,
1113                  p_alt_routing_designator,
1114                  p_completion_subinventory,
1115                  p_completion_locator_id,
1116                  p_demand_class,
1117                  p_project_id,
1118                  p_task_id,
1119                  p_schedule_group_id,
1120                  p_build_sequence,
1121                  p_line_id,
1122                  p_kanban_card_id,
1123                  p_overcompl_tol_type,
1124                  p_overcompl_tol_value,
1125                  p_end_item_unit_number,
1126                  l_po_creation_time,
1127                  p_priority,
1128                  p_due_date,
1129                  p_attribute_category,
1130                  p_attribute1,
1131                  p_attribute2,
1132                  p_attribute3,
1133                  p_attribute4,
1134                  p_attribute5,
1135                  p_attribute6,
1136                  p_attribute7,
1137                  p_attribute8,
1138                  p_attribute9,
1139                  p_attribute10,
1140                  p_attribute11,
1141                  p_attribute12,
1142                  p_attribute13,
1143                  p_attribute14,
1144                  p_attribute15,
1145                  l_est_scrap_account,
1146                  l_est_scrap_var_account,
1147                  p_coproducts_supply
1148             );
1149             --returning date_released into l_date_released;
1150 
1151         Exception
1152             when others then
1153                 p_error_code := SQLCODE;
1154                 p_error_msg := substr('wsmplbji.build_lbji_info: stmt no: '||l_stmt_num||' '||SQLERRM, 1, 2000);
1155                 return;
1156         End;
1157 
1158         if lbji_debug = 'Y' then
1159             fnd_file.put_line(fnd_file.log, 'Inserted '||SQL%ROWCOUNT||' rows into wdj');
1160         end if;
1161 
1162 l_stmt_num := 130;
1163         begin
1164 
1165             INSERT INTO WIP_ENTITIES (
1166                  wip_entity_id,
1167                  organization_id,
1168                  last_update_date,
1169                  last_updated_by,
1170                  creation_date,
1171                  created_by,
1172                  last_update_login,
1173                  request_id,
1174                  program_application_id,
1175                  program_id,
1176                  program_update_date,
1177                  wip_entity_name,
1178                  entity_type,
1179                  description,
1180                  primary_item_id,
1181                  gen_object_id
1182             )
1183             values
1184             (
1185                  p_wip_entity_id,
1186                  p_org,
1187                  p_last_updt_date,
1188                  p_last_updt_by,
1189                  p_creation_date,
1190                  p_created_by,
1191                  p_last_updt_login,
1192                  p_request_id,
1193                  p_program_application_id,
1194                  p_program_id,
1195                  p_prog_updt_date,
1196                  p_job_name,
1197                  5,
1198                  p_description,
1199                  p_item,
1200                  MTL_GEN_OBJECT_ID_S.nextval
1201             );
1202 
1203         exception
1204             when others then
1205                 p_error_code := SQLCODE;
1206                 p_error_msg := substr('wsmplbji.build_lbji_info: stmt no: '||l_stmt_num||' '||SQLERRM, 1, 2000);
1207                 return;
1208         end;
1209 
1210         if lbji_debug = 'Y' then
1211             fnd_file.put_line(fnd_file.log, 'Inserted '||SQL%ROWCOUNT||' rows into we');
1212         end if;
1213 
1214 
1215 l_stmt_num := 135;
1216         -- call Update_Card_Supply_Status to set the status of the kanban card to InProcess,
1217         -- if a card reference exists
1218 
1219         if ( p_kanban_card_id is not null ) then
1220             inv_kanban_pvt.update_card_supply_status(
1221                            x_return_status => l_returnStatus,
1222                            p_kanban_card_id => p_kanban_card_id,
1223                            p_supply_status => inv_kanban_pvt.g_supply_status_InProcess,
1224                            p_document_type => inv_kanban_pvt.G_Doc_type_lot_job,
1225                            p_document_header_id => p_wip_entity_id,
1226                            p_Document_detail_Id => null,
1227                            p_replenish_quantity => p_start_quantity);
1228 
1229             if ( l_returnStatus <> fnd_api.g_ret_sts_success ) then
1230                 p_error_code := -1;
1231                 fnd_message.set_name('WSM', 'WSM_KNBN_CARD_STS_FAIL');
1232                 select meaning
1233                 into   translated_meaning
1234                 from   mfg_lookups
1235                 where  lookup_type = 'MTL_KANBAN_SUPPLY_STATUS'
1236                 and lookup_code = 5
1237                 and upper(enabled_flag) = 'Y';
1238                 fnd_message.set_token('STATUS',translated_meaning);
1239                 p_error_msg := fnd_message.get;
1240                 return;
1241                 end if;
1242         end if;
1243 
1244 
1245 l_stmt_num := 140;
1246 
1247         if p_status_type = WIP_CONSTANTS.RELEASED then
1248             insert_into_period_balances (
1249                     p_wip_entity_id   => p_wip_entity_id,
1250                     p_organization_id => p_org,
1251                     p_class_code      => p_class_code,
1252                     p_release_date    => p_date_released,
1253                     p_error_code      => l_error_code,
1254                     p_err_msg         => l_error_msg );
1255 
1256             if l_error_code <> 0 then
1257                 p_error_code := l_error_code;
1258                 p_error_msg := l_error_msg;
1259                 return;
1260             end if;
1261         end if;
1262 
1263     end if; -- p_explode_header_detail
1264 
1265 
1266     -- osp begin -- this has to be put after insertion into wip_entities
1267     if p_explode_header_detail is null then
1268 
1269         if p_status_type = 3 and p_po_creation_time <> wip_constants.manual_creation then
1270             if p_src_client_server = 1 then
1271 
1272                 if wsmputil.check_osp_operation(p_wip_entity_id, l_job_seq_num, p_org) then
1273                     l_atleast_one_osp_exists := l_atleast_one_osp_exists + 1;
1274                     wip_osp.create_requisition(
1275                             P_Wip_Entity_Id => p_wip_entity_id,
1276                             P_Organization_Id => p_org,
1277                             P_Repetitive_Schedule_Id => null,
1278                             P_Operation_Seq_Num => l_job_seq_num,
1279                             P_Resource_Seq_Num => null,
1280                             P_Run_ReqImport => WIP_CONSTANTS.YES);
1281                 end if; -- check_osp_operation
1282             else
1283 
1284             -- if build_lbji_info is called from form, only then P_Run_ReqImport should be YES, i.e.
1285             -- the requisition import concurrent request should be launched immediately.
1286 
1287                     if wsmputil.check_osp_operation(p_wip_entity_id, l_job_seq_num, p_org) then
1288                         l_atleast_one_osp_exists := l_atleast_one_osp_exists + 1;
1289                         wip_osp.create_requisition(
1290                             P_Wip_Entity_Id => p_wip_entity_id,
1291                             P_Organization_Id => p_org,
1292                             P_Repetitive_Schedule_Id => null,
1293                             P_Operation_Seq_Num => l_job_seq_num,
1294                             P_Resource_Seq_Num => null,
1295                             P_Run_ReqImport => WIP_CONSTANTS.NO);
1296                     end if; -- check_osp_operation
1297 
1298             end if; --  p_src_client_server
1299         end if; --  p_status_type = 3
1300 
1301     end if; -- explode_header_detail
1302     -- osp end
1303 
1304 EXCEPTION
1305     when others then
1306         p_error_code := SQLCODE;
1307         p_error_msg := substr('wsmplbji.build_lbji_info: stmt no: '||l_stmt_num||' '||SQLERRM, 1, 2000);
1308         return;
1309 
1310 
1311 END build_lbji_info;
1312 
1313 
1314 
1315 -- Overloaded version of build_lbji_info where p_released_date is not passed as a parameter
1316 -- bugfix 2697295
1317 
1318 procedure build_lbji_info(
1319         p_routing_seq_id                IN      number,
1320         p_common_bill_sequence_id       IN      number,
1321         p_explode_header_detail         IN      number,
1322         p_status_type                   IN      number,
1323         p_class_code                    IN      varchar2,
1324         p_org                           IN      number,
1325         p_wip_entity_id                 IN OUT NOCOPY number,
1326         p_last_updt_date                IN      date,
1327         p_last_updt_by                  IN      number,
1328         p_creation_date                 IN      date,
1329         p_created_by                    IN      number,
1330         p_last_updt_login               IN      number,
1331         p_request_id                    IN      number,
1332         p_program_application_id        IN      number,
1333         p_program_id                    IN      number,
1334         p_prog_updt_date                IN      date,
1335         p_source_line_id                IN      number,
1336         p_source_code                   IN      varchar2,
1337         p_description                   IN      varchar2,
1338         p_item                          IN      number,
1339         p_job_type                      IN      number,
1340         p_bom_reference_id              IN      number,
1341         p_routing_reference_id          IN      number,
1342         p_firm_planned_flag             IN      number,
1343         p_wip_supply_type               IN      number,
1344         p_fusd                          IN      date,
1345         p_lucd                          IN      date,
1346         p_start_quantity                IN      number,
1347         p_net_quantity                  IN      number,
1348         p_coproducts_supply             IN      number,
1349         p_bom_revision                  IN      varchar2,
1350         p_routing_revision              IN      varchar2,
1351         p_bom_revision_date             IN      date,
1352         p_routing_revision_date         IN      date,
1353         p_lot_number                    IN      varchar2,
1354         p_alt_bom_designator            IN      varchar2,
1355         p_alt_routing_designator        IN      varchar2,
1356         p_priority                      IN      number,
1357         p_due_date                      IN      date,
1358         p_attribute_category            IN      varchar2,
1359         p_attribute1                    IN      varchar2,
1360         p_attribute2                    IN      varchar2,
1361         p_attribute3                    IN      varchar2,
1362         p_attribute4                    IN      varchar2,
1363         p_attribute5                    IN      varchar2,
1364         p_attribute6                    IN      varchar2,
1365         p_attribute7                    IN      varchar2,
1366         p_attribute8                    IN      varchar2,
1367         p_attribute9                    IN      varchar2,
1368         p_attribute10                   IN      varchar2,
1369         p_attribute11                   IN      varchar2,
1370         p_attribute12                   IN      varchar2,
1371         p_attribute13                   IN      varchar2,
1372         p_attribute14                   IN      varchar2,
1373         p_attribute15                   IN      varchar2,
1374         p_job_name                      IN      varchar2,
1375         p_completion_subinventory       IN      varchar2,
1376         p_completion_locator_id         IN      number,
1377         p_demand_class                  IN      varchar2,
1378         p_project_id                    IN      number,
1379         p_task_id                       IN      number,
1380         p_schedule_group_id             IN      number,
1381         p_build_sequence                IN      number,
1382         p_line_id                       IN      number,
1383         p_kanban_card_id                IN      number,
1384         p_overcompl_tol_type            IN      number,
1385         p_overcompl_tol_value           IN      number,
1386         p_end_item_unit_number          IN      number,
1387         p_rtg_op_seq_num                IN      number,
1388         p_src_client_server             IN      number,
1389         p_po_creation_time              IN      number,
1390         p_error_code             OUT NOCOPY     number,
1391         p_error_msg              OUT NOCOPY     varchar2) IS
1392 
1393 l_date_released date;
1394 BEGIN
1395 
1396     if p_status_type = 3 then
1397         l_date_released := sysdate;
1398     else
1399         l_date_released := null;
1400     end if;
1401 
1402     build_lbji_info(
1403                 p_routing_seq_id            => p_routing_seq_id,
1404                 p_common_bill_sequence_id   => p_common_bill_sequence_id,
1405                 p_explode_header_detail     => p_explode_header_detail,
1406                 p_status_type               => p_status_type,
1407                 p_class_code                => p_class_code,
1408                 p_org                       => p_org,
1409                 p_wip_entity_id             => p_wip_entity_id,
1410                 p_last_updt_date            => p_last_updt_date,
1411                 p_last_updt_by              => p_last_updt_by,
1412                 p_creation_date             => p_creation_date,
1413                 p_created_by                => p_created_by,
1414                 p_last_updt_login           => p_last_updt_login,
1415                 p_request_id                => p_request_id,
1416                 p_program_application_id    => p_program_application_id,
1417                 p_program_id                => p_program_id,
1418                 p_prog_updt_date            => p_prog_updt_date,
1419                 p_source_line_id            => p_source_line_id,
1420                 p_source_code               => p_source_code,
1421                 p_description               => p_description,
1422                 p_item                      => p_item,
1423                 p_job_type                  => p_job_type,
1424                 p_bom_reference_id          => p_bom_reference_id,
1425                 p_routing_reference_id      => p_routing_reference_id,
1426                 p_firm_planned_flag         => p_firm_planned_flag,
1427                 p_wip_supply_type           => p_wip_supply_type,
1428                 p_fusd                      => p_fusd,
1429                 p_lucd                      => p_lucd,
1430                 p_start_quantity            => p_start_quantity,
1431                 p_net_quantity              => p_net_quantity,
1432                 p_coproducts_supply         => p_coproducts_supply,
1433                 p_bom_revision              => p_bom_revision,
1434                 p_routing_revision          => p_routing_revision,
1435                 p_bom_revision_date         => p_bom_revision_date,
1436                 p_routing_revision_date     => p_routing_revision_date,
1437                 p_lot_number                => p_lot_number,
1438                 p_alt_bom_designator        => p_alt_bom_designator,
1439                 p_alt_routing_designator    => p_alt_routing_designator,
1440                 p_priority                  => p_priority,
1441                 p_due_date                  => p_due_date,
1442                 p_attribute_category        => p_attribute_category,
1443                 p_attribute1                => p_attribute1,
1444                 p_attribute2                => p_attribute2,
1445                 p_attribute3                => p_attribute3,
1446                 p_attribute4                => p_attribute4,
1447                 p_attribute5                => p_attribute5,
1448                 p_attribute6                => p_attribute6,
1449                 p_attribute7                => p_attribute7,
1450                 p_attribute8                => p_attribute8,
1451                 p_attribute9                => p_attribute9,
1452                 p_attribute10               => p_attribute10,
1453                 p_attribute11               => p_attribute11,
1454                 p_attribute12               => p_attribute12,
1455                 p_attribute13               => p_attribute13,
1456                 p_attribute14               => p_attribute14,
1457                 p_attribute15               => p_attribute15,
1458                 p_job_name                  => p_job_name,
1459                 p_completion_subinventory   => p_completion_subinventory,
1460                 p_completion_locator_id     => p_completion_locator_id,
1461                 p_demand_class              => p_demand_class,
1462                 p_project_id                => p_project_id,
1463                 p_task_id                   => p_task_id,
1464                 p_schedule_group_id         => p_schedule_group_id,
1465                 p_build_sequence            => p_build_sequence,
1466                 p_line_id                   => p_line_id,
1467                 p_kanban_card_id            => p_kanban_card_id,
1468                 p_overcompl_tol_type        => p_overcompl_tol_type,
1469                 p_overcompl_tol_value       => p_overcompl_tol_value,
1470                 p_end_item_unit_number      => p_end_item_unit_number,
1471                 p_rtg_op_seq_num            => p_rtg_op_seq_num,
1472                 p_src_client_server         => p_src_client_server,
1473                 p_po_creation_time          => p_po_creation_time,
1474                 p_date_released             => l_date_released,
1475                 p_error_code                => p_error_code,
1476                 p_error_msg                 =>p_error_msg);
1477 
1478 END build_lbji_info;
1479 
1480 
1481 
1482 
1483 --***********************************************************************************************
1484 -- ==============================================================================================
1485 -- PROCEDURE load_wsli_data
1486 -- ==============================================================================================
1487 --***********************************************************************************************
1488 
1489 PROCEDURE load_wsli_data (l_group_id IN NUMBER) IS
1490 
1491 -- ==============================================================================================
1492 -- cursors used to bulk bind data from wsli to PL/SQL tables
1493 -- ==============================================================================================
1494 cursor c_wsli_1 is
1495 select
1496         wsli.header_id,
1497         wsli.lot_number,
1498         wsli.inventory_item_id,
1499         wsli.organization_id,
1500         wsli.quantity,
1501         wsli.subinventory_code,
1502         wsli.locator_id,
1503         wsli.revision,
1504         wsli.last_updated_by,
1505         wsli.created_by,
1506         msi.primary_uom_code,
1507         wsli.component_issue_quantity
1508 from    wsm_starting_lots_interface wsli,
1509         wsm_lot_job_interface wlji,
1510         mtl_system_items msi
1511 where   wsli.header_id = wlji.source_line_id
1512 and     wlji.group_id = l_group_id
1513 and     wlji.process_status = 2 -- WIP_CONSTANTS.running
1514 and     wlji.mode_flag = 2
1515 and     msi.inventory_item_id = wsli.inventory_item_id
1516 and     msi.organization_id = wsli.organization_id;
1517 
1518 BEGIN
1519 
1520 -- ==============================================================================================
1521 -- bulk fetching data from wsli to PL/SQL tables
1522 -- ==============================================================================================
1523 
1524     open c_wsli_1;
1525 
1526     fetch c_wsli_1 bulk collect into
1527         v_wsli_header_id,
1528         v_wsli_lot_number,
1529         v_wsli_inventory_item_id,
1530         v_wsli_organization_id,
1531         v_wsli_quantity,
1532         v_wsli_subinventory_code,
1533         v_wsli_locator_id,
1534         v_wsli_revision,
1535         v_wsli_last_updated_by,
1536         v_wsli_created_by,
1537         v_wsli_primary_uom_code,
1538         v_wsli_comp_issue_qty;
1539 
1540 -- ==============================================================================================
1541 -- transfering wsli data into index by PL/SQL table for ease of validation
1542 -- ==============================================================================================
1543     v_wsli_index := v_wsli_header_id.first;
1544     while v_wsli_index <= v_wsli_header_id.last
1545     loop
1546         v_wsli(v_wsli_header_id(v_wsli_index)).lot_number := v_wsli_lot_number(v_wsli_index);
1547         v_wsli(v_wsli_header_id(v_wsli_index)).inventory_item_id := v_wsli_inventory_item_id(v_wsli_index);
1548         v_wsli(v_wsli_header_id(v_wsli_index)).organization_id := v_wsli_organization_id(v_wsli_index);
1549         v_wsli(v_wsli_header_id(v_wsli_index)).quantity := v_wsli_quantity(v_wsli_index);
1550         v_wsli(v_wsli_header_id(v_wsli_index)).subinventory_code := v_wsli_subinventory_code(v_wsli_index);
1551         v_wsli(v_wsli_header_id(v_wsli_index)).locator_id := v_wsli_locator_id(v_wsli_index);
1552         v_wsli(v_wsli_header_id(v_wsli_index)).revision := v_wsli_revision(v_wsli_index);
1553         v_wsli(v_wsli_header_id(v_wsli_index)).last_updated_by := v_wsli_last_updated_by(v_wsli_index);
1554         v_wsli(v_wsli_header_id(v_wsli_index)).created_by := v_wsli_created_by(v_wsli_index);
1555         v_wsli(v_wsli_header_id(v_wsli_index)).primary_uom_code := v_wsli_primary_uom_code(v_wsli_index);
1556         v_wsli(v_wsli_header_id(v_wsli_index)).comp_issue_quantity := v_wsli_comp_issue_qty(v_wsli_index);
1557 
1558     v_wsli_index := v_wsli_header_id.next(v_wsli_index);
1559     end loop;
1560 
1561     close c_wsli_1;
1562 
1563 END load_wsli_data;
1564 
1565 
1566 
1567 --***********************************************************************************************
1568 -- ==============================================================================================
1569 -- PROCEDURE check_errored_mmtt_records
1570 -- ==============================================================================================
1571 --***********************************************************************************************
1572 
1573 PROCEDURE check_errored_mmtt_records (
1574         p_header_id     IN NUMBER,
1575         x_err_code      OUT NOCOPY NUMBER,
1576         x_err_msg       OUT NOCOPY VARCHAR2) IS
1577 l_transaction_temp_id   NUMBER;
1578 l_wsli_header_id        NUMBER;
1579 l_wlji_header_id        NUMBER;
1580 l_interface_id          NUMBER;
1581 l_err_code              VARCHAR2(240);
1582 l_err_explanation       VARCHAR2(240);
1583 l_stmt_num              NUMBER;
1584 
1585 cursor recs is
1586         select  mmtt.transaction_temp_id,
1587                 mmtt.error_code,
1588                 mmtt.error_explanation,
1589                 wsli.header_id,
1590                 wlji.header_id
1591         from    mtl_material_transactions_temp mmtt,
1592                 wsm_starting_lots_interface wsli,
1593                 wsm_lot_job_interface wlji
1594         where   mmtt.transaction_header_id = p_header_id
1595         and     mmtt.source_line_id = wsli.header_id
1596         and     wsli.header_id = wlji.source_line_id ;
1597 BEGIN
1598 
1599     open recs;
1600     loop
1601         fetch recs into
1602                 l_transaction_temp_id,
1603                 l_err_code,
1604                 l_err_explanation,
1605                 l_wsli_header_id,
1606                 l_wlji_header_id ;
1607 
1608         exit when recs%notfound ;
1609 
1610         update  wsm_lot_job_interface wljia
1611         set     wljia.process_status = 4,
1612                 wljia.error_code = -2,
1613                 wljia.error_msg = substr(l_err_explanation,1,240)
1614         where   wljia.header_id = l_wlji_header_id ;
1615 
1616         x_err_code := -2;
1617     close recs;
1618     END LOOP;
1619 
1620 EXCEPTION
1621 
1622         when others then
1623                 x_err_code := SQLCODE;
1624                 x_err_msg :=    'WSMPLBJI.check_errored_mmtt_records' ||
1625                                 '(stmt_num='||l_stmt_num||') : '||
1626                                 '(Header_Id=' ||l_wlji_header_id||') : '||
1627                                  SUBSTRB(SQLERRM,1,1000);
1628 END check_errored_mmtt_records;
1629 
1630 
1631 --***********************************************************************************************
1632 -- ==============================================================================================
1633 -- PROCEDURE insert_procedure
1634 -- ==============================================================================================
1635 --***********************************************************************************************
1636 
1637 -- This procedure does not populate any quantity value (except scheduled_quantity) in wip_operations.
1638 -- Quantity is populated in build_lbji_info according to whether the job is unreleased, or bonus
1639 -- (released a special case of bonus). Note however that wsmpwrot.populate_wro called from this
1640 -- operation populates quantity values in wro. Also, this procedure doesn't update the prev/vext_op_seq_num
1641 -- in wo. That's taken care of in build_lbji_info. It's more efficient that way.
1642 
1643 
1644 PROCEDURE insert_procedure(
1645         p_seq_id                        IN      NUMBER,
1646         p_job_seq_num                   IN      NUMBER,
1647         p_common_routing_sequence_id    IN      NUMBER, -- routing of the assembly
1648         p_supply_type                   IN      NUMBER,
1649         p_wip_entity_id                 IN      NUMBER,
1650         p_organization_id               IN      NUMBER,
1651         p_quantity                      IN      NUMBER,
1652         p_job_type                      IN      NUMBER,
1653         p_bom_reference_id              IN      NUMBER,
1654         p_rtg_reference_id              IN      NUMBER,
1655         p_assembly_item_id              IN      NUMBER,
1656         p_alt_bom_designator            IN      VARCHAR2,
1657         p_alt_rtg_designator            IN      VARCHAR2,
1658         p_fusd                          IN      DATE,
1659         p_lucd                          IN      DATE,
1660         p_rtg_revision_date             IN      DATE,
1661         p_bom_revision_date             IN      DATE,
1662         p_last_updt_date                IN      date,
1663         p_last_updt_by                  IN      number,
1664         p_creation_date                 IN      date,
1665         p_created_by                    IN      number,
1666         p_last_updt_login               IN      number,
1667         p_request_id                    IN      number,
1668         p_program_application_id        IN      number,
1669         p_program_id                    IN      number,
1670         p_prog_updt_date                IN      date,
1671         p_error_code             OUT NOCOPY     NUMBER,
1672         p_error_msg              OUT NOCOPY     VARCHAR2) IS
1673 
1674 
1675 l_start_date                    VARCHAR2(50);
1676 l_completion_date               VARCHAR2(50);
1677 --l_routing_rev_date            VARCHAR2(50);  -- CHG: BUG2754825
1678 l_routing_rev_date              DATE;          -- CHG: BUG2754825
1679 l_item_id                       NUMBER;
1680 l_yield                         NUMBER;
1681 l_operation_yield_enabled       VARCHAR2(10);
1682 l_department_id                 NUMBER;
1683 l_scrap_account                 NUMBER;
1684 l_est_scrap_abs_account         NUMBER;
1685 l_first_flag                    NUMBER;
1686 l_op_seq_incr                   NUMBER;
1687 l_error_code                    NUMBER;
1688 l_error_msg                     VARCHAR2(2000);
1689 l_stat_num                      NUMBER;
1690 l_seq_incr                      NUMBER;  --bug 2026218
1691 l_routing_seq_id                NUMBER;  --bug 2445489  assembly item, abb
1692 
1693 e_proc_error                    EXCEPTION;
1694 no_dept_error                   EXCEPTION;
1695 
1696 BEGIN
1697 
1698 
1699         l_start_date := to_char(p_fusd, WIP_CONSTANTS.DT_NOSEC_FMT);
1700         l_completion_date := to_char(p_lucd, WIP_CONSTANTS.DT_NOSEC_FMT);
1701         -- BC: BUG2754825
1702         --l_routing_rev_date := to_char(p_rtg_revision_date, WIP_CONSTANTS.DATETIME_FMT);
1703         l_routing_rev_date := p_rtg_revision_date;
1704         -- EC: BUG2754825
1705 
1706         if p_job_type = 3 then
1707                 l_item_id := p_bom_reference_id;
1708         else
1709                 l_item_id := p_assembly_item_id;
1710         end if;
1711 
1712         select nvl(OP_SEQ_NUM_INCREMENT, 10)
1713         into   l_op_seq_incr
1714         from   wsm_parameters
1715         where  ORGANIZATION_ID = p_organization_id;
1716 
1717 
1718 l_stat_num := 10;
1719         select  yield, to_char(operation_yield_enabled), department_id
1720         into    l_yield, l_operation_yield_enabled,l_department_id
1721         from    bom_operation_sequences
1722         where   operation_sequence_id = p_seq_id;
1723 
1724 l_stat_num := 30;
1725         select  scrap_account, est_absorption_account
1726         into    l_scrap_account, l_est_scrap_abs_account
1727         from    bom_departments
1728         where   department_id = l_department_id;
1729 
1730 
1731 -- abb H optional scrap accounting
1732 l_stat_num := 40;
1733 
1734         if (l_scrap_account is NULL or l_est_scrap_abs_account is NULL) and
1735                 wsmputil.WSM_ESA_ENABLED(
1736                           p_wip_entity_id => null,
1737                           err_code => l_error_code,
1738                           err_msg => l_error_msg,
1739                           p_org_id => p_organization_id,
1740                           p_job_type => p_job_type) = 1 then
1741                 raise no_dept_error;
1742         end if;
1743 
1744 l_stat_num := 50;
1745         INSERT INTO WIP_OPERATIONS
1746                 (WIP_ENTITY_ID,
1747                 OPERATION_SEQ_NUM,
1748                 ORGANIZATION_ID,
1749                 LAST_UPDATE_DATE,
1750                 LAST_UPDATED_BY,
1751                 CREATION_DATE,
1752                 CREATED_BY,
1753                 LAST_UPDATE_LOGIN,
1754                 REQUEST_ID,
1755                 PROGRAM_APPLICATION_ID,
1756                 PROGRAM_ID,
1757                 PROGRAM_UPDATE_DATE,
1758                 OPERATION_SEQUENCE_ID,
1759                 STANDARD_OPERATION_ID,
1760                 DEPARTMENT_ID,
1761                 DESCRIPTION,
1762                 SCHEDULED_QUANTITY,
1763                 QUANTITY_IN_QUEUE,
1764                 QUANTITY_RUNNING,
1765                 QUANTITY_WAITING_TO_MOVE,
1766                 QUANTITY_REJECTED,
1767                 QUANTITY_SCRAPPED,
1768                 QUANTITY_COMPLETED,
1769                 FIRST_UNIT_START_DATE,
1770                 FIRST_UNIT_COMPLETION_DATE,
1771                 LAST_UNIT_START_DATE,
1772                 LAST_UNIT_COMPLETION_DATE,
1773                 PREVIOUS_OPERATION_SEQ_NUM,
1774                 NEXT_OPERATION_SEQ_NUM,
1775                 COUNT_POINT_TYPE,
1776                 BACKFLUSH_FLAG,
1777                 MINIMUM_TRANSFER_QUANTITY,
1778                 DATE_LAST_MOVED,
1779                 ATTRIBUTE_CATEGORY,
1780                 ATTRIBUTE1,
1781                 ATTRIBUTE2,
1782                 ATTRIBUTE3,
1783                 ATTRIBUTE4,
1784                 ATTRIBUTE5,
1785                 ATTRIBUTE6,
1786                 ATTRIBUTE7,
1787                 ATTRIBUTE8,
1788                 ATTRIBUTE9,
1789                 ATTRIBUTE10,
1790                 ATTRIBUTE11,
1791                 ATTRIBUTE12,
1792                 ATTRIBUTE13,
1793                 ATTRIBUTE14,
1794                 ATTRIBUTE15,
1795                 OPERATION_YIELD,
1796                 OPERATION_YIELD_ENABLED)
1797         SELECT  p_wip_entity_id,
1798                 p_job_seq_num,
1799                 p_organization_id,
1800                 p_last_updt_date,
1801                 p_last_updt_by,
1802                 p_creation_date,
1803                 p_created_by,
1804                 p_last_updt_login,
1805                 p_request_id,
1806                 p_program_application_id,
1807                 p_program_id,
1808                 p_prog_updt_date,
1809                 SEQ.OPERATION_SEQUENCE_ID,
1810                 SEQ.STANDARD_OPERATION_ID,
1811                 SEQ.DEPARTMENT_ID,
1812                 SEQ.OPERATION_DESCRIPTION,
1813                 --Bug 5207481:Actual quantity changes-Scheduled_quantity should be zero.
1814                 --Bug 5510126:Scheduled quantity was made as 0 earlier as infinite
1815                 --is going to finally update this.But before infinite scheduler is
1816                 --called, create_requsitions is being called which uses the value
1817                 --in the field scheduled quantity.Hence the previous change is reverted.
1818                 ROUND(p_quantity, WIP_CONSTANTS.MAX_DISPLAYED_PRECISION),
1819                 --0,
1820                 0, 0, 0, 0, 0, 0,
1821                 TO_DATE(l_start_date, WIP_CONSTANTS.DT_NOSEC_FMT),
1822                 TO_DATE(l_completion_date, WIP_CONSTANTS.DT_NOSEC_FMT),
1823                 TO_DATE(l_start_date, WIP_CONSTANTS.DT_NOSEC_FMT),
1824                 TO_DATE(l_completion_date, WIP_CONSTANTS.DT_NOSEC_FMT),
1825                 0,
1826                 0,
1827                 SEQ.COUNT_POINT_TYPE,
1828                 SEQ.BACKFLUSH_FLAG,
1829                 NVL(SEQ.MINIMUM_TRANSFER_QUANTITY, 0),
1830                 '',
1831                 SEQ.ATTRIBUTE_CATEGORY,
1832                 SEQ.ATTRIBUTE1,
1833                 SEQ.ATTRIBUTE2,
1834                 SEQ.ATTRIBUTE3,
1835                 SEQ.ATTRIBUTE4,
1836                 SEQ.ATTRIBUTE5,
1837                 SEQ.ATTRIBUTE6,
1838                 SEQ.ATTRIBUTE7,
1839                 SEQ.ATTRIBUTE8,
1840                 SEQ.ATTRIBUTE9,
1841                 SEQ.ATTRIBUTE10,
1842                 SEQ.ATTRIBUTE11,
1843                 SEQ.ATTRIBUTE12,
1844                 SEQ.ATTRIBUTE13,
1845                 SEQ.ATTRIBUTE14,
1846                 SEQ.ATTRIBUTE15,
1847                 l_yield,
1848                 l_operation_yield_enabled
1849         FROM    BOM_OPERATION_SEQUENCES SEQ
1850         WHERE   SEQ.ROUTING_SEQUENCE_ID = p_common_routing_sequence_id
1851         AND     NVL(SEQ.OPERATION_TYPE, 1) = 1
1852         --BC: CZH.I_OED-1
1853         /****************
1854         AND     TO_DATE(TO_CHAR(SEQ.EFFECTIVITY_DATE, WIP_CONSTANTS.DT_NOSEC_FMT),
1855                      WIP_CONSTANTS.DT_NOSEC_FMT) <=
1856                 TO_DATE(l_routing_rev_date,WIP_CONSTANTS.DT_NOSEC_FMT)
1857         AND     NVL(TO_DATE(TO_CHAR(SEQ.DISABLE_DATE, WIP_CONSTANTS.DT_NOSEC_FMT),
1858                          WIP_CONSTANTS.DT_NOSEC_FMT),
1859                 TO_DATE(l_routing_rev_date,WIP_CONSTANTS.DT_NOSEC_FMT) + 1) >=
1860                 TRUNC(TO_DATE(l_routing_rev_date,WIP_CONSTANTS.DT_NOSEC_FMT))
1861         ****************/
1862 
1863         /** HH24MISSS - Timestamp FPI changes - DATETIME_FMT **/
1864 
1865         -- BC: BUG2754825
1866         --AND   TO_DATE(TO_CHAR(SEQ.EFFECTIVITY_DATE, WIP_CONSTANTS.DATETIME_FMT), WIP_CONSTANTS.DATETIME_FMT)
1867         --          <= TO_DATE(l_routing_rev_date, WIP_CONSTANTS.DATETIME_FMT)
1868         --AND   NVL(TO_DATE(TO_CHAR(SEQ.DISABLE_DATE, WIP_CONSTANTS.DATETIME_FMT), WIP_CONSTANTS.DATETIME_FMT),
1869         --          TO_DATE(l_routing_rev_date, WIP_CONSTANTS.DATETIME_FMT) + 1)
1870         --          >= TO_DATE(l_routing_rev_date, WIP_CONSTANTS.DATETIME_FMT)
1871         AND     l_routing_rev_date BETWEEN SEQ.EFFECTIVITY_DATE AND NVL(SEQ.DISABLE_DATE, l_routing_rev_date+1)
1872         -- EC: BUG2754825
1873 
1874         --EC: CZH.I_OED-1
1875         AND     OPERATION_SEQUENCE_ID = p_seq_id
1876         AND NOT EXISTS (select 'x' from wip_operations
1877                          where wip_entity_id = p_wip_entity_id
1878                          and   operation_sequence_id = p_seq_id
1879                          and   operation_seq_num = p_job_seq_num);
1880         --bugfix 2026218
1881         --copy attachment from operations document attachment defined in the network routing form.
1882         if sql%rowcount > 0 then
1883                 select p_job_seq_num
1884                 into   l_seq_incr
1885                 from   sys.dual;
1886 
1887                 FND_ATTACHED_DOCUMENTS2_PKG.copy_attachments(
1888                                 X_FROM_ENTITY_NAME => 'BOM_OPERATION_SEQUENCES',
1889                                 X_FROM_PK1_VALUE   => to_char(p_seq_id),
1890                                 X_TO_ENTITY_NAME   => 'WSM_LOT_BASED_OPERATIONS',
1891                                 X_TO_PK1_VALUE   => to_char(p_wip_entity_id),
1892                                 X_TO_PK2_VALUE   => to_char(l_seq_incr),
1893                                 X_TO_PK3_VALUE   => to_char(p_organization_id),
1894                                 X_CREATED_BY     => to_char(p_last_updt_by),
1895                                 X_LAST_UPDATE_LOGIN => to_char(p_last_updt_login),
1896                                 X_PROGRAM_APPLICATION_ID => to_char(p_program_application_id),
1897                                 X_PROGRAM_ID => to_char(p_program_id),
1898                                 X_REQUEST_ID => to_char(p_request_id)) ;
1899         end if;
1900         --endfix 20026218
1901 
1902         if lbji_debug = 'Y' then
1903                 fnd_file.put_line(fnd_file.log, 'Inserted '||SQL%ROWCOUNT||' rows into wo');
1904         end if;
1905 
1906 l_stat_num := 60;
1907         -- The below insert is used for Costing Changes (OP Yield)
1908         INSERT INTO WIP_OPERATION_YIELDS
1909                 (WIP_ENTITY_ID,
1910                 OPERATION_SEQ_NUM,
1911                 ORGANIZATION_ID,
1912                 LAST_UPDATE_DATE,
1913                 LAST_UPDATED_BY,
1914                 CREATION_DATE,
1915                 CREATED_BY,
1916                 LAST_UPDATE_LOGIN,
1917                 REQUEST_ID,
1918                 PROGRAM_APPLICATION_ID,
1919                 PROGRAM_ID,
1920                 PROGRAM_UPDATE_DATE,
1921                 STATUS,
1922                 SCRAP_ACCOUNT,
1923                 EST_SCRAP_ABSORB_ACCOUNT)
1924         SELECT  p_wip_entity_id,
1925                 WO.OPERATION_SEQ_NUM,
1926                 p_organization_id,
1927                 p_last_updt_date,
1928                 p_last_updt_by,
1929                 p_creation_date,
1930                 p_created_by,
1931                 p_last_updt_login,
1932                 p_request_id,
1933                 p_program_application_id,
1934                 p_program_id,
1935                 p_prog_updt_date,
1936                 NULL,
1937                 l_scrap_account,
1938                 l_est_scrap_abs_account
1939         FROM    WIP_OPERATIONS WO
1940         WHERE   WO.WIP_ENTITY_ID = p_wip_entity_id
1941         AND     WO.OPERATION_SEQUENCE_ID = p_seq_id
1942         AND     WO.OPERATION_SEQ_NUM NOT IN (SELECT WOY.OPERATION_SEQ_NUM
1943                                              FROM   WIP_OPERATION_YIELDS WOY
1944                                              WHERE  WOY.WIP_ENTITY_ID = p_wip_entity_id);
1945 
1946         if lbji_debug = 'Y' then
1947                 fnd_file.put_line(fnd_file.log, 'Inserted '||SQL%ROWCOUNT||' rows into woy');
1948         end if;
1949 
1950 
1951 l_stat_num := 80;
1952         INSERT INTO WIP_OPERATION_RESOURCES
1953                 (WIP_ENTITY_ID,
1954                 OPERATION_SEQ_NUM,
1955                 RESOURCE_SEQ_NUM,
1956                 ORGANIZATION_ID,
1957                 LAST_UPDATE_DATE, LAST_UPDATED_BY, CREATION_DATE,
1958                 CREATED_BY, LAST_UPDATE_LOGIN, REQUEST_ID,
1959                 PROGRAM_APPLICATION_ID, PROGRAM_ID, PROGRAM_UPDATE_DATE,
1960                 RESOURCE_ID, UOM_CODE,
1961                 BASIS_TYPE, USAGE_RATE_OR_AMOUNT, ACTIVITY_ID,
1962                 SCHEDULED_FLAG, ASSIGNED_UNITS, AUTOCHARGE_TYPE,
1963                 STANDARD_RATE_FLAG, APPLIED_RESOURCE_UNITS, APPLIED_RESOURCE_VALUE,
1964                 START_DATE, COMPLETION_DATE,
1965                 ATTRIBUTE_CATEGORY, ATTRIBUTE1, ATTRIBUTE2,
1966                 ATTRIBUTE3, ATTRIBUTE4, ATTRIBUTE5,
1967                 ATTRIBUTE6, ATTRIBUTE7, ATTRIBUTE8,
1968                 ATTRIBUTE9, ATTRIBUTE10, ATTRIBUTE11,
1969                 ATTRIBUTE12, ATTRIBUTE13, ATTRIBUTE14,
1970                 ATTRIBUTE15,
1971                 SCHEDULE_SEQ_NUM,SUBSTITUTE_GROUP_NUM,PRINCIPLE_FLAG,SETUP_ID,
1972                 -- ST : Detailed Scheduling --
1973                 maximum_assigned_units,
1974                 firm_flag
1975                 -- ST : Detailed Scheduling --
1976                 )
1977          SELECT OPS.WIP_ENTITY_ID,
1978                 OPS.OPERATION_SEQ_NUM,
1979                 ORS.RESOURCE_SEQ_NUM,
1980                 OPS.ORGANIZATION_ID,
1981                 OPS.LAST_UPDATE_DATE, OPS.LAST_UPDATED_BY, OPS.CREATION_DATE,
1982                 OPS.CREATED_BY, OPS.LAST_UPDATE_LOGIN, OPS.REQUEST_ID,
1983                 OPS.PROGRAM_APPLICATION_ID, OPS.PROGRAM_ID,
1984                 OPS.PROGRAM_UPDATE_DATE, ORS.RESOURCE_ID, RSC.UNIT_OF_MEASURE,
1985                 ORS.BASIS_TYPE, ORS.USAGE_RATE_OR_AMOUNT, ORS.ACTIVITY_ID,
1986                 ORS.SCHEDULE_FLAG, ORS.ASSIGNED_UNITS, ORS.AUTOCHARGE_TYPE,
1987                 ORS.STANDARD_RATE_FLAG, 0, 0,
1988                 OPS.FIRST_UNIT_START_DATE, OPS.LAST_UNIT_COMPLETION_DATE,
1989                 ORS.ATTRIBUTE_CATEGORY, ORS.ATTRIBUTE1, ORS.ATTRIBUTE2,
1990                 ORS.ATTRIBUTE3, ORS.ATTRIBUTE4, ORS.ATTRIBUTE5,
1991                 ORS.ATTRIBUTE6, ORS.ATTRIBUTE7, ORS.ATTRIBUTE8,
1992                 ORS.ATTRIBUTE9, ORS.ATTRIBUTE10, ORS.ATTRIBUTE11,
1993                 ORS.ATTRIBUTE12, ORS.ATTRIBUTE13, ORS.ATTRIBUTE14,
1994                 ORS.ATTRIBUTE15,
1995                 ORS.SCHEDULE_SEQ_NUM,ORS.SUBSTITUTE_GROUP_NUM,ORS.PRINCIPLE_FLAG,ORS.SETUP_ID,
1996                 -- ST : Detailed Scheduling --
1997                 ORS.ASSIGNED_UNITS,
1998                 0
1999                 -- ST : Detailed Scheduling --
2000         FROM    BOM_RESOURCES RSC,
2001                 BOM_OPERATION_RESOURCES ORS,
2002                 WIP_OPERATIONS OPS
2003         WHERE   OPS.ORGANIZATION_ID = p_organization_id
2004         AND     OPS.WIP_ENTITY_ID = p_wip_entity_id
2005         AND     OPS.OPERATION_SEQUENCE_ID = ORS.OPERATION_SEQUENCE_ID
2006         AND     ORS.RESOURCE_ID = RSC.RESOURCE_ID
2007         AND     RSC.ORGANIZATION_ID = OPS.ORGANIZATION_ID
2008         AND     ORS.OPERATION_SEQUENCE_ID = p_seq_id
2009         AND     OPS.OPERATION_SEQ_NUM NOT IN (select WOR.OPERATION_SEQ_NUM
2010                                               from Wip_operation_resources WOR
2011                                               where WOR.wip_entity_id = p_wip_entity_id);
2012 
2013         if lbji_debug = 'Y' then
2014                 fnd_file.put_line(fnd_file.log, 'Inserted '||SQL%ROWCOUNT||' rows into wor');
2015         end if;
2016 
2017 l_stat_num := 90;
2018         if p_job_seq_num = l_op_seq_incr then -- if this is the first operation
2019                 l_first_flag := 1;
2020         else
2021                 l_first_flag := 0;
2022         end if;
2023 
2024 l_stat_num := 90.5;
2025         SELECT  common_routing_sequence_id INTO l_routing_seq_id
2026         FROM    BOM_OPERATIONAL_ROUTINGS BOR
2027         WHERE   BOR.assembly_item_id= decode(p_job_type,1,p_assembly_item_id,p_rtg_reference_id)
2028         AND     nvl(BOR.alternate_routing_designator, '***') = nvl(p_alt_rtg_designator, '***')
2029         and     bor.organization_id = p_organization_id;
2030 
2031         WSMPWROT.POPULATE_WRO (
2032                 p_first_flag => l_first_flag,
2033                 p_wip_entity_id => p_wip_entity_id,
2034                 p_organization_id => p_organization_id,
2035                 p_assembly_item_id => l_item_id,
2036                 p_bom_revision_date => p_bom_revision_date,
2037                 p_alt_bom => p_alt_bom_designator,
2038                 p_quantity => p_quantity,
2039                 p_operation_sequence_id => p_seq_id,
2040                 p_wip_supply_type => p_supply_type,
2041                 x_err_code => l_error_code,
2042                 x_err_msg => l_error_msg,
2043                 --BC: 2754825
2044                 --p_routing_revision_date => TO_DATE(l_routing_rev_date, WIP_CONSTANTS.DATETIME_FMT),
2045                 p_routing_revision_date => l_routing_rev_date,
2046                 --EC: 2754825
2047                 p_routing_sequence_id => l_routing_seq_id); --bug 2445489
2048         -- EA: NSO-WLT
2049 
2050                 if l_error_code <> 0 then
2051                         p_error_msg := l_error_msg;
2052                         p_error_code := -1;
2053                         if (lbji_debug = 'Y') then
2054                             fnd_file.put_line(fnd_file.log,p_error_msg);
2055                         end if;
2056                         return;
2057                 end if;
2058 
2059         if lbji_debug = 'Y' then
2060                 fnd_file.put_line(fnd_file.log, 'Inserted rows into wro');
2061         end if;
2062 
2063 EXCEPTION
2064         WHEN NO_DATA_FOUND THEN
2065                 p_error_msg := 'WSMPLBJI.insert_procedure('||l_stat_num||'): No Data Found';
2066                 p_error_code := -1;
2067                 if (lbji_debug = 'Y') then
2068                     fnd_file.put_line(fnd_file.log,p_error_msg);
2069                 end if;
2070 
2071         WHEN e_proc_error THEN
2072                 p_error_msg := 'WSMPLBJI.insert_procedure('||l_stat_num||'): '||p_error_msg;
2073                 p_error_code := -1;
2074                 if (lbji_debug = 'Y') then
2075                     fnd_file.put_line(fnd_file.log,p_error_msg);
2076                 end if;
2077 
2078         WHEN no_dept_error THEN
2079                 fnd_message.set_name('WSM', 'WSM_NO_SCRAP_ACC');
2080                 fnd_message.set_token('DEPT_ID',to_char(l_department_id));
2081                 p_error_msg := fnd_message.get;
2082                 p_error_code := -1;
2083 
2084         when others then
2085                 p_error_code := SQLCODE;
2086                 p_error_msg := 'WSMPLBJI.insert_procedure('||l_stat_num||')'|| substr(SQLERRM,1,200);
2087                 if (lbji_debug = 'Y') then
2088                     fnd_file.put_line(fnd_file.log,p_error_msg);
2089                 end if;
2090 
2091 END insert_procedure;
2092 
2093 
2094 
2095 --***********************************************************************************************
2096 -- ==============================================================================================
2097 -- FUNCTION DISCRETE_CHARGES_EXIST
2098 -- ==============================================================================================
2099 --***********************************************************************************************
2100 
2101 
2102 FUNCTION discrete_charges_exist(
2103         p_wip_entity_id         IN  NUMBER,
2104         p_organization_id       IN  NUMBER,
2105         p_check_mode            IN  NUMBER )
2106 RETURN BOOLEAN IS
2107 
2108 retnvalue BOOLEAN;
2109 charges_exist VARCHAR2(2);
2110 l_stmt_num  NUMBER;
2111 
2112 cursor check_discrete_charges is
2113         SELECT  DISTINCT 'X'
2114         FROM    WIP_DISCRETE_JOBS DJ, WIP_PERIOD_BALANCES WPB
2115         WHERE   DJ.WIP_ENTITY_ID = WPB.WIP_ENTITY_ID
2116                 AND DJ.ORGANIZATION_ID = WPB.ORGANIZATION_ID
2117                 AND DJ.WIP_ENTITY_ID = p_wip_entity_id
2118                 AND DJ.ORGANIZATION_ID = p_organization_id
2119                 AND (DJ.QUANTITY_COMPLETED <> 0
2120                         OR DJ.QUANTITY_SCRAPPED <> 0
2121                         OR WPB.TL_RESOURCE_IN <> 0
2122                         OR WPB.TL_OVERHEAD_IN <> 0
2123                         OR WPB.TL_OUTSIDE_PROCESSING_IN <> 0
2124                         OR WPB.PL_MATERIAL_IN <> 0
2125                         OR WPB.PL_MATERIAL_OVERHEAD_IN <> 0
2126                         OR WPB.PL_RESOURCE_IN <> 0
2127                         OR WPB.PL_OVERHEAD_IN <> 0
2128                         OR WPB.PL_OUTSIDE_PROCESSING_IN <> 0
2129                         OR WPB.TL_MATERIAL_OUT <> 0
2130                         OR WPB.TL_RESOURCE_OUT <> 0
2131                         OR WPB.TL_OVERHEAD_OUT <> 0
2132                         OR WPB.TL_OUTSIDE_PROCESSING_OUT <> 0
2133                         OR WPB.PL_MATERIAL_OUT <> 0
2134                         OR WPB.PL_MATERIAL_OVERHEAD_OUT <> 0
2135                         OR WPB.PL_RESOURCE_OUT <> 0
2136                         OR WPB.PL_OVERHEAD_OUT <> 0
2137                         OR WPB.PL_OUTSIDE_PROCESSING_OUT <> 0
2138                         OR EXISTS (SELECT 'X'
2139                                    FROM   WIP_REQUIREMENT_OPERATIONS
2140                                    WHERE  ORGANIZATION_ID = p_organization_id
2141                                    AND    WIP_ENTITY_ID = p_wip_entity_id
2142                                    AND    QUANTITY_ISSUED <> 0)
2143                         OR EXISTS (SELECT 'X'
2144                                    FROM   WIP_MOVE_TXN_INTERFACE
2145                                    WHERE  ORGANIZATION_ID = p_organization_id
2146                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2147                         OR EXISTS (SELECT 'X'
2148                                    FROM   WSM_LOT_MOVE_TXN_INTERFACE
2149                                    WHERE  ORGANIZATION_ID = p_organization_id
2150                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2151                         OR EXISTS (SELECT 'X'
2152                                    FROM   WIP_COST_TXN_INTERFACE
2153                                    WHERE  ORGANIZATION_ID = p_organization_id
2154                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2155                         OR EXISTS (SELECT 'X'
2156                                    FROM   MTL_MATERIAL_TRANSACTIONS_TEMP
2157                                    WHERE  ORGANIZATION_ID = p_organization_id
2158                                    AND    TRANSACTION_SOURCE_TYPE_ID = 5
2159                                    AND    TRANSACTION_SOURCE_ID = p_wip_entity_id)
2160                         OR EXISTS (SELECT 'X'
2161                                    FROM   WIP_MOVE_TRANSACTIONS
2162                                    WHERE  ORGANIZATION_ID = p_organization_id
2163                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2164                         -- CZH check WLT also
2165                         OR EXISTS (SELECT 'X'
2166                                    FROM   WSM_SM_RESULTING_JOBS
2167                                    WHERE  ORGANIZATION_ID = p_organization_id
2168                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2169                         OR EXISTS (SELECT 'X'
2170                                    FROM   WIP_OPERATION_RESOURCES
2171                                    WHERE  ORGANIZATION_ID = p_organization_id
2172                                    AND    WIP_ENTITY_ID = p_wip_entity_id
2173                                    AND    APPLIED_RESOURCE_UNITS <> 0));
2174 
2175 --check for only shop floor transactions
2176 
2177 cursor check_discrete_charges_1 is
2178         SELECT  DISTINCT 'X'
2179         FROM    WIP_DISCRETE_JOBS DJ, WIP_PERIOD_BALANCES WPB
2180         WHERE   DJ.WIP_ENTITY_ID = WPB.WIP_ENTITY_ID
2181                 AND DJ.ORGANIZATION_ID = WPB.ORGANIZATION_ID
2182                 AND DJ.WIP_ENTITY_ID = p_wip_entity_id
2183                 AND DJ.ORGANIZATION_ID = p_organization_id
2184                 AND (DJ.QUANTITY_COMPLETED <> 0
2185                         OR DJ.QUANTITY_SCRAPPED <> 0
2186                         OR WPB.TL_RESOURCE_IN <> 0
2187                         OR WPB.TL_OVERHEAD_IN <> 0
2188                         OR WPB.TL_OUTSIDE_PROCESSING_IN <> 0
2189                         OR WPB.PL_RESOURCE_IN <> 0
2190                         OR WPB.PL_OVERHEAD_IN <> 0
2191                         OR WPB.PL_OUTSIDE_PROCESSING_IN <> 0
2192                         OR WPB.TL_RESOURCE_OUT <> 0
2193                         OR WPB.TL_OVERHEAD_OUT <> 0
2194                         OR WPB.TL_OUTSIDE_PROCESSING_OUT <> 0
2195                         OR WPB.PL_RESOURCE_OUT <> 0
2196                         OR WPB.PL_OVERHEAD_OUT <> 0
2197                         OR WPB.PL_OUTSIDE_PROCESSING_OUT <> 0
2198                         OR EXISTS (SELECT 'X'
2199                                    FROM   WIP_MOVE_TXN_INTERFACE
2200                                    WHERE  ORGANIZATION_ID = p_organization_id
2201                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2202                         OR EXISTS (SELECT 'X'
2203                                    FROM   WSM_LOT_MOVE_TXN_INTERFACE
2204                                    WHERE  ORGANIZATION_ID = p_organization_id
2205                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2206                         OR EXISTS (SELECT 'X'
2207                                    FROM   WIP_COST_TXN_INTERFACE
2208                                    WHERE  ORGANIZATION_ID = p_organization_id
2209                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2210                         OR EXISTS (SELECT 'X'
2211                                    FROM   WIP_MOVE_TRANSACTIONS
2212                                    WHERE  ORGANIZATION_ID = p_organization_id
2213                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2214                         -- CZH check WLT also
2215                         OR EXISTS (SELECT 'X'
2216                                    FROM   WSM_SM_RESULTING_JOBS
2217                                    WHERE  ORGANIZATION_ID = p_organization_id
2218                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2219                         OR EXISTS (SELECT 'X'
2220                                    FROM   WIP_OPERATION_RESOURCES
2221                                    WHERE  ORGANIZATION_ID = p_organization_id
2222                                    AND    WIP_ENTITY_ID = p_wip_entity_id
2223                                    AND    APPLIED_RESOURCE_UNITS <> 0));
2224 BEGIN
2225 
2226     retnvalue := FALSE;
2227 
2228     if (p_check_mode = 1) then
2229         open check_discrete_charges_1;
2230         fetch check_discrete_charges_1 into charges_exist;
2231 
2232         IF (check_discrete_charges_1%FOUND) THEN
2233                 retnvalue := TRUE;
2234                 close  check_discrete_charges_1;
2235                 RETURN retnvalue;
2236         ELSE
2237                 close  check_discrete_charges_1;
2238         END IF;
2239 
2240     else
2241         open check_discrete_charges;
2242         fetch check_discrete_charges into charges_exist;
2243 
2244         IF (check_discrete_charges%FOUND) THEN
2245                 retnvalue := TRUE;
2246                 close  check_discrete_charges;
2247                 RETURN retnvalue;
2248         ELSE
2249                 close  check_discrete_charges;
2250         END IF;
2251 
2252     end if;
2253 
2254     RETURN retnvalue;
2255 
2256 END discrete_charges_exist;
2257 
2258 
2259 
2260 
2261 
2262 
2263 --***********************************************************************************************
2264 -- ==============================================================================================
2265 -- PROCEDURE insert_into_period_balances
2266 -- ==============================================================================================
2267 --***********************************************************************************************
2268 
2269 
2270 PROCEDURE insert_into_period_balances(
2271         p_wip_entity_id     IN NUMBER,
2272         p_organization_id   IN NUMBER,
2273         p_class_code        IN VARCHAR2,
2274         p_release_date      IN DATE,
2275         p_error_code        OUT NOCOPY NUMBER,
2276         p_err_msg           OUT NOCOPY VARCHAR2 ) IS
2277 
2278 x_user_id       NUMBER := FND_GLOBAL.USER_ID;
2279 x_login_id      NUMBER := FND_GLOBAL.LOGIN_ID;
2280 l_cnt           NUMBER;     -- bug 3571360
2281 --l_inv_period_id number;   -- bug 3126650
2282 
2283 BEGIN
2284 
2285     -- BD: bugfix 3299811, this is a regression of bugfix 3126650
2286     --l_inv_period_id := wsmputil.get_inv_acct_period (
2287     --        x_err_code         => p_error_code,
2288     --        x_err_msg          => p_err_msg,
2289     --        p_organization_id  => p_organization_id,
2290     --        p_date             => trunc(nvl(p_release_date, sysdate)) );
2291     --if(p_error_code <> 0) then
2292     --    p_error_code := -1;
2293     --    fnd_message.set_name('WIP', 'WIP_NO_ACCT_PERIOD');
2294     --    fnd_message.set_token('FLD_NAME','Wip Accounting Period');
2295     --    p_err_msg := fnd_message.get;
2296     --    return;
2297     --end if;
2298     -- ED: bugfix 3299811
2299 
2300     insert into wip_period_balances (
2301             acct_period_id,
2302             wip_entity_id,
2303             last_update_date,
2304             last_updated_by,
2305             creation_date,
2306             created_by,
2307             last_update_login,
2308             organization_id,
2309             class_type,
2310             tl_resource_in,
2311             tl_overhead_in,
2312             tl_outside_processing_in,
2313             pl_material_in,
2314             pl_material_overhead_in,
2315             pl_resource_in,
2316             pl_overhead_in,
2317             pl_outside_processing_in,
2318             tl_material_out,
2319             tl_resource_out,
2320             tl_overhead_out,
2321             tl_outside_processing_out,
2322             pl_material_out,
2323             pl_material_overhead_out,
2324             pl_resource_out,
2325             pl_overhead_out,
2326             pl_outside_processing_out,
2327             pl_material_overhead_var,
2328             pl_material_var,
2329             pl_outside_processing_var,
2330             pl_overhead_var,
2331             pl_resource_var,
2332             tl_material_var,
2333             tl_outside_processing_var,
2334             tl_overhead_var,
2335             tl_resource_var,
2336             tl_material_overhead_out,
2337             tl_material_overhead_var)
2338     select  oap.acct_period_id,
2339             p_wip_entity_id,
2340             sysdate, x_user_id,
2341             sysdate, x_user_id, x_login_id,
2342             p_organization_id, wc.class_type,
2343             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2344             0, 0, 0, 0, 0, 0, 0, 0
2345      from   org_acct_periods oap,
2346             wip_accounting_classes wc
2347      where  wc.class_code = p_class_code
2348      and    wc.organization_id = p_organization_id
2349      and    oap.organization_id = p_organization_id
2350      and    oap.schedule_close_date >=
2351                  trunc(inv_le_timezone_pub.get_le_day_for_inv_org(
2352                         nvl(p_release_date, sysdate),
2353                         p_organization_id))
2354      and    oap.period_close_date is null
2355      and    not exists (
2356                  select 'balance record already there'
2357                  from   wip_period_balances wpb
2358                  where  wpb.wip_entity_id = p_wip_entity_id
2359                  and    wpb.acct_period_id = oap.acct_period_id
2360                  and    wpb.organization_id = oap.organization_id);
2361 
2362     l_cnt := SQL%ROWCOUNT;      -- bug 3571360
2363 
2364     -- BD: bugfix 3299811, this is a regression of bugfix 3126650
2365     --select  l_inv_period_id,
2366     --        p_wip_entity_id,
2367     --        sysdate, x_user_id,
2368     --        sysdate, x_user_id, x_login_id,
2369     --        p_organization_id,
2370     --        wc.class_type,
2371     --        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2372     --        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2373     --        0, 0, 0, 0, 0, 0, 0, 0
2374     --from    wip_accounting_classes wc
2375     --where   wc.class_code = p_class_code
2376     --and     wc.organization_id = p_organization_id
2377     --and     not exists (
2378     --             select 'balance record already there'
2379     --             from   wip_period_balances wpb
2380     --             where  wpb.wip_entity_id = p_wip_entity_id
2381     --             and    wpb.acct_period_id = l_inv_period_id
2382     --             and    wpb.organization_id = p_organization_id);
2383     -- ED: bugfix 3299811
2384 
2385 
2386     if lbji_debug = 'Y' then
2387         fnd_file.put_line(fnd_file.log, 'Inserted '|| l_cnt ||' rows into wip_period_balances');
2388     end if;
2389 
2390     --if SQL%NOTFOUND then      -- bug 3571360
2391     if l_cnt <= 0 then          -- bug 3571360
2392         p_error_code := -1;
2393         fnd_message.set_name('WIP', 'WIP_NO_ACCT_PERIOD');
2394         fnd_message.set_token('FLD_NAME','Wip Accounting Period');
2395         p_err_msg := fnd_message.get;
2396     end if;
2397 
2398 exception
2399         when others then
2400                 p_err_msg := 'WSMPLBJI.insert_into_period_balances: '|| substr(SQLERRM,1,200);
2401                 p_error_code := SQLCODE;
2402 
2403 end insert_into_period_balances;
2404 
2405 
2406 
2407 
2408 --***********************************************************************************************
2409 -- ==============================================================================================
2410 -- PROCESS_INVALID_FIELD
2411 -- ==============================================================================================
2412 --***********************************************************************************************
2413 
2414 
2415 -- ==============================================================================================
2416 -- this is called to display message of WSM_INVALID_FIELD type.
2417 -- sets the process_status to 3, sets values of error_code and error_message,
2418 -- writes into fnd log and calls write_to_wie
2419 -- ==============================================================================================
2420 
2421 PROCEDURE process_invalid_field (
2422         p_fld          IN VARCHAR2,
2423         aux_string     IN VARCHAR2,
2424         stmt_number    IN NUMBER) IS
2425 
2426 x_err_msg  VARCHAR2(2000) := NULL;
2427 
2428 BEGIN
2429 
2430       v_wlji_process_status(v_index) := 3;
2431       v_wlji_err_code(v_index) := -1;
2432       fnd_message.set_name('WSM','WSM_INVALID_FIELD');
2433       fnd_message.set_token('FLD_NAME', p_fld);
2434       x_err_msg :=  fnd_message.get;
2435       v_wlji_err_msg(v_index) := x_err_msg;
2436       fnd_file.put_line(fnd_file.log, 'stmt_num: '|| stmt_number||'  '||x_err_msg||' '||aux_string);
2437       fnd_file.new_line(fnd_file.log, 3);
2438 
2439 
2440 END process_invalid_field;
2441 
2442 
2443 
2444 --***********************************************************************************************
2445 -- ==============================================================================================
2446 -- PROCESS_ERRORRED_FIELD
2447 -- ==============================================================================================
2448 --***********************************************************************************************
2449 
2450 -- ==============================================================================================
2451 -- this is called to display message of any type which does not involve setting any token
2452 -- sets the process_status to 3, sets values of error_code and error_message,
2453 -- writes into fnd log and calls write_to_wie
2454 -- ==============================================================================================
2455 
2456 PROCEDURE process_errorred_field(
2457         p_product      IN VARCHAR2,
2458         p_message_name IN VARCHAR2,
2459         stmt_number    IN NUMBER) IS
2460 
2461 x_err_msg  VARCHAR2(2000) := NULL;
2462 
2463 BEGIN
2464         v_wlji_process_status(v_index) := 3; --ERROR
2465         v_wlji_err_code(v_index) := -1;
2466         fnd_message.set_name(p_product, p_message_name);
2467         x_err_msg :=  fnd_message.get;
2468         v_wlji_err_msg(v_index) := x_err_msg;
2469         fnd_file.put_line(fnd_file.log, 'stmt_num: '|| stmt_number||'  '||x_err_msg);
2470         fnd_file.new_line(fnd_file.log, 3);
2471 
2472 
2473 END process_errorred_field;
2474 
2475 
2476 --***********************************************************************************************
2477 -- ==============================================================================================
2478 -- HANDLE_ERROR
2479 -- ==============================================================================================
2480 --***********************************************************************************************
2481 
2482 
2483 PROCEDURE handle_error  (
2484         p_err_code     IN NUMBER,
2485         p_err_msg      IN VARCHAR2,
2486         stmt_number    IN NUMBER) IS
2487 
2488 BEGIN
2489         v_wlji_process_status(v_index) := 3; --ERROR
2490         v_wlji_err_code(v_index) := p_err_code;
2491         v_wlji_err_msg(v_index) := substr(p_err_msg,1,2000);
2492         fnd_file.put_line(fnd_file.log, 'stmt_num: ' || stmt_number||'  '||p_err_msg);
2493         fnd_file.new_line(fnd_file.log, 3);
2494 
2495 END handle_error;
2496 
2497 
2498 --***********************************************************************************************
2499 -- ==============================================================================================
2500 -- HANDLE_WARNING
2501 -- ==============================================================================================
2502 --***********************************************************************************************
2503 
2504 
2505 PROCEDURE handle_warning(
2506         p_err_msg                      IN      VARCHAR2,
2507         p_header_id                    IN      NUMBER,
2508         p_request_id                   IN      NUMBER,
2509         p_program_id                   IN      NUMBER,
2510         p_program_application_id       IN      NUMBER) IS
2511 
2512 dummy_err_code number;
2513 dummy_err_msg varchar2(2000);
2514 
2515 BEGIN
2516         fnd_file.new_line(fnd_file.log, 1);
2517         fnd_file.put_line(fnd_file.log, '*** WARNING MESSAGE BEGIN ***');
2518         fnd_file.put_line(fnd_file.log, p_err_msg);
2519         fnd_file.put_line(fnd_file.log, '*** WARNING MESSAGE END ***');
2520         fnd_file.new_line(fnd_file.log, 1);
2521         wsmputil.WRITE_TO_WIE (
2522                  p_header_id,
2523                  substr(p_err_msg,1,2000),
2524                  p_request_id,
2525                  p_program_id,
2526                  p_program_application_id,
2527                  2,
2528                  dummy_err_code,
2529                  dummy_err_msg );
2530 END handle_warning;
2531 
2532 
2533 
2534 
2535 --***********************************************************************************************
2536 -- ==============================================================================================
2537 -- OVERLOADED PROCESS_INTERFACE_ROWS
2538 -- ==============================================================================================
2539 --***********************************************************************************************
2540 
2541 PROCEDURE  process_interface_rows (
2542         retcode         OUT NOCOPY NUMBER,
2543         errbuf          OUT NOCOPY VARCHAR2 ) IS
2544 begin
2545 
2546         process_interface_rows (retcode, errbuf, '');
2547 
2548 end process_interface_rows;
2549 
2550 
2551 
2552 --***********************************************************************************************
2553 -- ==============================================================================================
2554 -- FUNCTION honor_kanban_size
2555 -- ==============================================================================================
2556 --***********************************************************************************************
2557 
2558 -- This function should ideally return either 1 or 2 for every kanban (i.e. pull sequence)
2559 -- 1 => honor kanban size limitations
2560 -- 2 => do not honor kanban size limitations
2561 -- This is of course applicable when the user chooses a starting lot for creating a kanban
2562 -- replenishment order, because, otherwise, the order is always created for the kanban size.
2563 -- If a starting lot is chosen, the work order can be of any arbitrary size. If the api returns
2564 -- 1, and if the job quantity exceeds the kanban size, the job quantity is truncated to match the
2565 -- kanban size. E.g. Say kanba size is 20. User chooses an inv lot of quantity 1000, component per
2566 -- is 2, i.e. a work order is generated for 500. If this api returns 1, the work order will be
2567 -- generated for 20 only.
2568 -- Ideally, the option to specify a value for this parameter should be provided when the user creates
2569 -- a pull sequence. For DM_FP I user will see this as an option on wsm parameters screen. Thus of all
2570 -- the parameters passed to the api, only the organization id will be used to query wsm_parameters.
2571 
2572 function  honor_kanban_size (
2573         p_org_id            IN NUMBER,
2574         p_item_id           IN NUMBER,
2575         p_subinv            IN VARCHAR2,
2576         p_locator_id        IN NUMBER,
2577         p_kanban_plan_id    IN NUMBER)
2578 return number is
2579     l_hon_kanban_size number;
2580 begin
2581 
2582     select honor_kanban_size
2583     into   l_hon_kanban_size
2584     from   wsm_parameters
2585     where  organization_id = p_org_id;
2586 
2587     if l_hon_kanban_size is null then
2588         return 2;
2589     else
2590         return l_hon_kanban_size;
2591     end if;
2592 
2593 exception
2594     when others then
2595         return 2;
2596 
2597 end honor_kanban_size;
2598 
2599 
2600 --***********************************************************************************************
2601 -- ==============================================================================================
2602 -- PROCESS_LBJI_ROWS_1159
2603 -- ==============================================================================================
2604 --***********************************************************************************************
2605 
2606 -- This is the old process_interface_rows, retained to support Option A
2607 -- This procedure will not be called for Release 12.
2608 
2609 PROCEDURE  process_lbji_rows_1159 (
2610         retcode         OUT NOCOPY NUMBER,
2611         errbuf          OUT NOCOPY VARCHAR2,
2612         p_group_id      IN  NUMBER) IS
2613 
2614 cursor c_pir is
2615         select  header_id
2616         from    wsm_lot_job_interface
2617         where   process_status = wip_constants.pending
2618 --      and     group_id is null
2619         and     creation_date <= sysdate+1
2620         and     load_type in (5,6)
2621         order by job_name, organization_id;  -- CZH: this will group the job together
2622 
2623 
2624 x_header           NUMBER;
2625 l_group_id         NUMBER;
2626 l_reqid            NUMBER ;
2627 l_stmt_num         NUMBER;
2628 conc_status        BOOLEAN;
2629 alotted_rows       NUMBER := 0;
2630 row_count          NUMBER := 0;
2631 total_no_rows      NUMBER := 0;
2632 no_rows_per_worker NUMBER := 30;
2633 l_user_id          NUMBER;
2634 l_resp_id          NUMBER;
2635 l_resp_appl_id     NUMBER;
2636 
2637 BEGIN
2638 
2639     fnd_file.put_line(fnd_file.log, 'Processing Interface rows..');
2640 
2641     retcode := 0;       -- bugfix 2845397: set the code to 0 (success)
2642 
2643     l_user_id := fnd_global.USER_ID;
2644     l_resp_id := fnd_global.RESP_ID;
2645     l_resp_appl_id := fnd_global.RESP_APPL_ID;
2646 
2647     fnd_global.apps_initialize(l_user_id, l_resp_id, l_resp_appl_id) ;
2648 
2649     if p_group_id is null then
2650 
2651         select  count(*)
2652         into    total_no_rows
2653         from    wsm_lot_job_interface
2654         where   process_status = wip_constants.pending
2655         --and   group_id is null
2656         and     creation_date <= sysdate+1
2657         and     load_type in (5,6);
2658 
2659         if mod(total_no_rows, no_of_workers) = 0 then
2660             no_rows_per_worker := total_no_rows / no_of_workers;
2661         else
2662             no_rows_per_worker := floor(total_no_rows / no_of_workers) + 1;
2663         end if;
2664 
2665         if no_rows_per_worker < batch_size then
2666             no_rows_per_worker := batch_size;
2667         end if;
2668 
2669         fnd_file.put_line(fnd_file.log, 'Total Pending Rows = '||total_no_rows);
2670         fnd_file.put_line(fnd_file.log, 'Number of Workers = '||no_of_workers);
2671         fnd_file.put_line(fnd_file.log, 'Batch Size = '||batch_size);
2672         fnd_file.put_line(fnd_file.log, 'Number of Rows per worker = '||no_rows_per_worker);
2673 
2674         select wsm_lot_job_interface_s.NEXTVAL
2675         into   l_group_id
2676         from   dual;
2677 
2678         open c_pir;
2679         loop
2680 
2681             fetch c_pir into x_header;
2682 
2683             if c_pir%notfound and (c_pir%rowcount - row_count) = 0 then exit; end if;
2684 
2685             if not c_pir%notfound then
2686                 update  wsm_lot_job_interface wlji
2687                 set     wlji.group_id =  l_group_id,
2688                         wlji.process_status = wip_constants.running
2689                 where   header_id = x_header;
2690             end if;
2691 
2692             if (c_pir%rowcount - row_count) = no_rows_per_worker or c_pir%notfound then
2693                 alotted_rows := c_pir%rowcount - row_count;
2694 
2695                 row_count := c_pir%rowcount;
2696 
2697                 l_reqid := FND_REQUEST.SUBMIT_REQUEST (
2698                               application   => 'WSM',
2699                               program       => 'WSMLNCHW',
2700                               sub_request   => FALSE,
2701                               argument1     => l_group_id,
2702                               argument2     => alotted_rows);
2703                 if l_reqid = 0 then
2704                     rollback;
2705                 else
2706                     commit;
2707                 end if;
2708 
2709                 fnd_file.put_line(fnd_file.log, 'Request_id: '||l_reqid||' submitted');
2710 
2711                 if c_pir%notfound then exit; end if;
2712 
2713                 if  not c_pir%notfound then
2714                     select wsm_lot_job_interface_s.NEXTVAL
2715                     into   l_group_id
2716                     from   dual;
2717                 end if;
2718 
2719             end if;
2720 
2721         end loop;
2722         close c_pir;
2723 
2724     else -- p_group_id is not null
2725     -- note that in that case only one worker will be launched, i.e. the benefits of
2726     -- parallelization will not be realized. Hence it's advisable not to use the import lot
2727     -- job program to process rows with a specific group id unless the number of such rows is very small.
2728 
2729         select  count(*)
2730         into    total_no_rows
2731         from    wsm_lot_job_interface
2732         where   process_status = wip_constants.pending
2733         and     group_id = p_group_id
2734         and     creation_date <= sysdate+1
2735         and     load_type in (5,6);
2736 
2737         if total_no_rows > 0 then
2738 
2739             update  wsm_lot_job_interface wlji
2740             set     wlji.process_status = wip_constants.running
2741             where   group_id = p_group_id;
2742 
2743             l_reqid :=  FND_REQUEST.SUBMIT_REQUEST (
2744                               application   => 'WSM',
2745                               program       => 'WSMLNCHW',
2746                               sub_request   => FALSE,
2747                               argument1     => p_group_id,
2748                               argument2     => total_no_rows);
2749 
2750             if l_reqid = 0 then
2751                 rollback;
2752             else
2753                 commit;
2754             end if;
2755 
2756             fnd_file.put_line(fnd_file.log, 'Request_id: '||l_reqid||' submitted');
2757 
2758         else -- total_no_rows <= 0
2759                 fnd_file.put_line(fnd_file.log, 'No Rows found in interface table');
2760         end if;
2761 
2762     end if; -- group_id
2763 
2764 
2765 EXCEPTION
2766 
2767     when others then
2768         retcode := 1;
2769         errbuf := 'WSMLBJIB.process_lbji_rows_1159: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,240);
2770         fnd_file.put_line(fnd_file.log,errbuf);
2771         conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR',errbuf);
2772 
2773 END process_lbji_rows_1159 ;
2774 
2775 
2776 --***********************************************************************************************
2777 -- ==============================================================================================
2778 -- LAUNCH WORKER_1159
2779 -- ==============================================================================================
2780 --***********************************************************************************************
2781 
2782 PROCEDURE  launch_worker_1159 (
2783         retcode         OUT NOCOPY NUMBER,
2784         errbuf          OUT NOCOPY VARCHAR2,
2785         l_group_id      IN  NUMBER,
2786         alotted_rows    IN  NUMBER  ) IS
2787 
2788 -- ==============================================================================================
2789 -- cursors used to bulk bind data from wlji to PL/SQL tables
2790 -- ==============================================================================================
2791 cursor c_wlji_1 is
2792 select
2793         error_code,
2794         error_msg,
2795         last_update_date,
2796         request_id,
2797         program_id,
2798         program_application_id,
2799         last_updated_by,
2800         creation_date,
2801         created_by,
2802         last_update_login,
2803         program_update_date,
2804         last_updated_by_name,
2805         created_by_name,
2806         organization_id,
2807         primary_item_id,
2808         header_id,
2809         process_status,
2810         routing_reference_id,
2811         completion_subinventory,
2812         completion_locator_id,
2813         mode_flag,
2814         group_id,
2815         load_type,
2816         status_type,
2817         last_unit_completion_date,
2818         old_completion_date,
2819         bom_reference_id,
2820         bom_revision_date,
2821         routing_revision_date,
2822         wip_supply_type,
2823         class_code,
2824         lot_number,
2825         job_name,
2826         description,
2827         firm_planned_flag,
2828         alternate_routing_designator,
2829         alternate_bom_designator,
2830         demand_class,
2831         start_quantity,
2832         old_start_quantity,
2833         wip_entity_id,
2834         error,
2835         process_phase,
2836         first_unit_start_date,
2837         first_unit_completion_date,
2838         last_unit_start_date,
2839         scheduling_method,
2840         routing_revision,
2841         bom_revision,
2842         schedule_group_id,
2843         schedule_group_name,
2844         build_sequence,
2845         net_quantity,
2846         allow_explosion,
2847         old_status_type,
2848         interface_id,
2849         coproducts_supply,
2850         source_code,
2851         source_line_id,
2852         process_type,
2853         processing_work_days,
2854         daily_production_rate,
2855         line_id,
2856         lot_control_code,
2857         repetitive_schedule_id,
2858         parent_group_id,
2859         attribute_category,
2860         attribute1,
2861         attribute2,
2862         attribute3,
2863         attribute4,
2864         attribute5,
2865         attribute6,
2866         attribute7,
2867         attribute8,
2868         attribute9,
2869         attribute10,
2870         attribute11,
2871         attribute12,
2872         attribute13,
2873         attribute14,
2874         attribute15,
2875         organization_code,
2876         line_code,
2877         primary_item_segments,
2878         bom_reference_segments,
2879         routing_reference_segments,
2880         completion_locator_segments,
2881         project_id,
2882         project_name,
2883         task_id,
2884         delivery_id,
2885         descriptive_flex_segments,
2886         project_number,
2887         task_number,
2888         project_costed,
2889         end_item_unit_number,
2890         overcompletion_tolerance_type,
2891         overcompletion_tolerance_value,
2892         kanban_card_id,
2893         priority,
2894         due_date,
2895         task_name,
2896         job_type,
2897         date_released        --bugfix 2697295
2898 from    wsm_lot_job_interface
2899 where   group_id = l_group_id
2900 and     process_status = 2 -- WIP_CONSTANTS.running;
2901 order by organization_id,
2902          priority,
2903          due_date;
2904 
2905 -- ==============================================================================================
2906 -- other variables
2907 -- ==============================================================================================
2908 
2909 txn_header_id                   NUMBER;
2910 txn_tmp_header_id               NUMBER;
2911 
2912 l_source_item_rev               VARCHAR2(3);
2913 --l_source_item_rev_date        date;           -- Del: bug 2963225
2914 l_rev_control_code              number;         -- Add: bug 2963225
2915 l_start_lot_revision            number;         -- Add: bug 2963225
2916 l_rev_sysdate                   DATE;
2917 l_last_update_date              DATE := SYSDATE;
2918 l_request_id                    NUMBER := fnd_global.conc_request_id;
2919 l_program_id                    NUMBER := fnd_global.conc_program_id;
2920 l_program_application_id        NUMBER := fnd_global.prog_appl_id;
2921 l_user                          NUMBER := FND_GLOBAL.user_id;
2922 l_login                         NUMBER := FND_GLOBAL.login_id;
2923 l_creation_date                 DATE := sysdate;
2924 l_prog_updt_date                DATE := sysdate;
2925 conc_status                     BOOLEAN;
2926 l_default_subinventory          VARCHAR2(10);
2927 l_default_compl_loc_id          NUMBER;
2928 l_segs                          VARCHAR2(10000);
2929 l_loc_success                   BOOLEAN;
2930 l_sub_loc_control               NUMBER;
2931 l_org_loc_control               NUMBER;
2932 l_item_loc_control              NUMBER;
2933 l_restrict_locators_code        NUMBER;
2934 l_del_int_prof_value            number;
2935 
2936 l_error_code                    NUMBER := 0;
2937 l_return_value                  NUMBER := 0;
2938 l_error_msg                     VARCHAR2(2000) := NULL;
2939 translated_meaning              varchar2(240);
2940 l_error_count                   NUMBER := 0;
2941 l_warning_count                 NUMBER := 0;
2942 x_return_status                 VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
2943 l_returnStatus                  VARCHAR2(1);
2944 x_msg_data                      VARCHAR2(2000);
2945 
2946 l_boolean_success               BOOLEAN := false;
2947 l_inv_worker_req_id             NUMBER := 0;
2948 req_phase                       VARCHAR2(2000);
2949 req_status                      VARCHAR2(2000);
2950 req_devphase                    VARCHAR2(2000);
2951 req_devstatus                   VARCHAR2(2000);
2952 req_message                     VARCHAR2(1000);
2953 req_wait                        BOOLEAN;
2954 
2955 l_atleast_one_row_in_mmtt       NUMBER := 0;
2956 
2957 dummy_err_code                  NUMBER;
2958 dummy_err_msg                   VARCHAR2(2000);
2959 
2960 l_stmt_num                      NUMBER;
2961 
2962 l_item_id                       NUMBER;
2963 l_sub                           VARCHAR2(10);
2964 l_revision                      VARCHAR2(3);
2965 l_quantity                      NUMBER;
2966 l_build_sequence                NUMBER;
2967 l_line_id                       NUMBER;
2968 l_schedule_group_id             NUMBER;
2969 p_date_released                 DATE;
2970 p_old_date_released             DATE;
2971 l_department_id                 NUMBER;
2972 p_est_scrap_account             NUMBER;
2973 p_est_scrap_var_account         NUMBER;
2974 
2975 p_old_primary_item_id           NUMBER;
2976 p_old_class_code                VARCHAR2(10);
2977 p_old_start_date                DATE;
2978 p_old_complete_date             DATE;
2979 p_old_quantity                  NUMBER;
2980 p_old_net_quantity              NUMBER;
2981 p_old_bom_revision              varchar2(3);
2982 p_old_routing_revision          varchar2(3);
2983 p_skip_updt                     NUMBER;
2984 p_old_status_type               NUMBER;
2985 p_old_firm_planned_flag         NUMBER;
2986 p_old_job_type                  NUMBER;
2987 dummy_number                    NUMBER;
2988 dummy_varchar                   VARCHAR2(3);
2989 dummy_date                      DATE;
2990 p_change_bom_alt                NUMBER; -- bug 2762029
2991 p_change_routing_alt            NUMBER; -- bug 2762029
2992 p_change_alt_flag               NUMBER; -- bug 2762029
2993 p_change_bom_reference          NUMBER;
2994 p_change_routing_reference      NUMBER;
2995 p_old_bom_reference_id          NUMBER;
2996 p_old_alt_bom_designator        VARCHAR2(10);
2997 p_old_routing_reference_id      NUMBER;
2998 p_old_alt_routing_designator    VARCHAR2(10);
2999 p_old_bom_revision_date         DATE;
3000 p_old_routing_revision_date     DATE;
3001 p_old_com_rtg_seq_id            NUMBER;
3002 p_old_com_bom_seq_id            NUMBER;
3003 p_old_supply_type               NUMBER;
3004 p_coproducts_supply             NUMBER;
3005 p_scheduled_start_date          DATE;
3006 p_scheduled_completion_date     DATE;
3007 p_old_completion_subinv         varchar2(10);
3008 p_old_completion_locator        number;
3009 temp_start_quantity             NUMBER;
3010 temp_fusd                       DATE;
3011 temp_lucd                       DATE;
3012 temp_supply                     NUMBER;
3013 
3014 xst                             BOOLEAN := true;
3015 l_no_of_records                 NUMBER := 0;
3016 l_aux_mesg                      VARCHAR2(240):= NULL;
3017 str                             VARCHAR2(100);
3018 hash_value                      NUMBER;
3019 l_dummy                         NUMBER := 0;
3020 l_err_msg                       VARCHAR2(2000):= NULL;
3021 
3022 l_locator_id                    NUMBER;
3023 l_job_type                      NUMBER;
3024 l_rev_date                      DATE;
3025 l_date_text                     VARCHAR2(100);
3026 l_component_quantity            NUMBER;
3027 l_kanban_size                   NUMBER;
3028 l_qoh                           NUMBER;
3029 l_att                           NUMBER;
3030 l_atr                           NUMBER;
3031 l_component_yield_factor        NUMBER;
3032 l_required_quantity             NUMBER;
3033 l_quantity_tobe_issued          NUMBER;
3034 l_start_op_seq_id               NUMBER;
3035 l_start_seq_id                  NUMBER;
3036 l_end_seq_id                    NUMBER;
3037 l_txnexist                      NUMBER;
3038 l_qntydiff                      NUMBER;
3039 mtl_locator_type                NUMBER;
3040 l_src_lot_number                wsm_starting_lots_interface.lot_number%type;
3041 l_src_inv_item_id               NUMBER;
3042 l_comp_basis_type               NUMBER ;  --LBM enh: - basis type null=Item, 2=Lot based. defaults to null=Item.
3043 
3044 -- abb H
3045 min_op_seq_num                  NUMBER;
3046 max_op_seq_num                  NUMBER;
3047 l_scrap_account10               NUMBER;
3048 l_est_scrap_abs_account10       NUMBER;
3049 l_scrap_account9999             NUMBER;
3050 l_est_scrap_abs_account9999     NUMBER;
3051 l_temp_cc                       VARCHAR2(10);
3052 
3053 invalid_id_error                EXCEPTION;
3054 invalid_job_name_error          EXCEPTION;
3055 abort_request                   EXCEPTION;
3056 build_job_exception             EXCEPTION;
3057 update_job_exception            EXCEPTION;
3058 invalid_qnty_error              EXCEPTION;
3059 
3060 prev_rowcount                   NUMBER := 0;
3061 aReturnBoolean                  BOOLEAN := false;
3062 
3063 batch_group_id                  NUMBER;
3064 l_rtg_rev_date                  DATE;    --ADD: CZH.I_OED-1
3065 l_bom_rev_date                  DATE;    --ADD: BUGFIX 2380517
3066 
3067 v_load_wsli                     BOOLEAN;
3068 l_req_request_id                number;
3069 l_osp_op_seq_num                NUMBER; -- OSP FP I
3070 
3071 job_type_meaning                VARCHAR2(30);
3072 assembly_name                   VARCHAR2(40);
3073 status_name                     VARCHAR2(30);
3074 org_code                        VARCHAR2(3);
3075 
3076 -- bugfix 2820900:  Added new variables
3077 
3078 x_new_name      varchar2(240);
3079 l_dup_job_name      varchar2(240);
3080 
3081 -- end bugfix 2820900
3082 
3083 BEGIN   -- for launch_worker
3084 
3085     retcode := 0;       -- bugfix 2845397: set the code to 0 (success)
3086 
3087     SAVEPOINT back_to_square_one;
3088 
3089 -- ==============================================================================================
3090 -- bulk fetching data into PL/SQL tables for ease of validation
3091 -- ==============================================================================================
3092 
3093     begin
3094 
3095 l_stmt_num := 1;
3096         WSMPLCVA.load_org_table;
3097 
3098 l_stmt_num := 2;
3099         WSMPLCVA.load_subinventory;
3100 
3101 l_stmt_num := 3;
3102         WSMPLCVA.load_class_code;
3103 
3104         if lbji_debug = 'Y' then
3105             fnd_file.put_line(fnd_file.log, 'loading org/subinv/class-code values into memory (once per worker).. Success.');
3106         end if;
3107 
3108     exception
3109         when others then
3110             raise abort_request;
3111     end;
3112 
3113 -- ==============================================================================================
3114 -- bulk fetching data from wlji to PL/SQL tables
3115 -- ==============================================================================================
3116 
3117 l_stmt_num := 40;
3118     open c_wlji_1;
3119     loop  -- main loop
3120 
3121         v_load_wsli  := true; --i.e. run the load wsli routine for every batch
3122 
3123         fetch c_wlji_1 bulk collect into
3124             v_wlji_err_code,
3125             v_wlji_err_msg,
3126             v_wlji_last_updt_date,
3127             v_wlji_request_id,
3128             v_wlji_program_id,
3129             v_wlji_program_application_id,
3130             v_wlji_last_updt_by,
3131             v_wlji_creation_date,
3132             v_wlji_created_by,
3133             v_wlji_last_updt_login,
3134             v_wlji_prog_updt_date,
3135             v_wlji_last_updt_by_name,
3136             v_wlji_created_by_name,
3137             v_wlji_org,
3138             v_wlji_item,
3139             v_wlji_header_id,
3140             v_wlji_process_status,
3141             v_wlji_routing_reference_id,
3142             v_wlji_completion_subinventory,
3143             v_wlji_completion_locator_id,
3144             v_wlji_mode_flag,
3145             v_wlji_group_id,
3146             v_wlji_load_type,
3147             v_wlji_status_type,
3148             v_wlji_lucd,
3149             v_wlji_old_completion_date,
3150             v_wlji_bom_reference_id,
3151             v_wlji_bom_revision_date,
3152             v_wlji_routing_revision_date,
3153             v_wlji_wip_supply_type,
3154             v_wlji_class_code,
3155             v_wlji_lot_number,
3156             v_wlji_job_name,
3157             v_wlji_description,
3158             v_wlji_firm_planned_flag,
3159             v_wlji_alt_routing_designator,
3160             v_wlji_alt_bom_designator,
3161             v_wlji_demand_class,
3162             v_wlji_start_quantity,
3163             v_wlji_old_start_quantity,
3164             v_wlji_wip_entity_id,
3165             v_wlji_error,
3166             v_wlji_process_phase ,
3167             v_wlji_fusd,
3168             v_wlji_fucd,
3169             v_wlji_last_unit_start_date,
3170             v_wlji_scheduling_method,
3171             v_wlji_routing_revision ,
3172             v_wlji_bom_revision ,
3173             v_wlji_schedule_group_id,
3174             v_wlji_schedule_group_name,
3175             v_wlji_build_sequence ,
3176             v_wlji_net_quantity ,
3177             v_wlji_allow_explosion ,
3178             v_wlji_old_status_type,
3179             v_wlji_interface_id ,
3180             v_wlji_coproducts_supply,
3181             v_wlji_source_code,
3182             v_wlji_source_line_id,
3183             v_wlji_process_type,
3184             v_wlji_processing_work_days,
3185             v_wlji_daily_production_rate,
3186             v_wlji_line_id,
3187             v_wlji_lot_control_code,
3188             v_wlji_repetitive_schedule_id,
3189             v_wlji_parent_group_id,
3190             v_wlji_attribute_category,
3191             v_wlji_attribute1,
3192             v_wlji_attribute2,
3193             v_wlji_attribute3,
3194             v_wlji_attribute4 ,
3195             v_wlji_attribute5 ,
3196             v_wlji_attribute6 ,
3197             v_wlji_attribute7 ,
3198             v_wlji_attribute8 ,
3199             v_wlji_attribute9 ,
3200             v_wlji_attribute10 ,
3201             v_wlji_attribute11 ,
3202             v_wlji_attribute12 ,
3203             v_wlji_attribute13 ,
3204             v_wlji_attribute14 ,
3205             v_wlji_attribute15 ,
3206             v_wlji_organization_code,
3207             v_wlji_line_code ,
3208             v_wlji_primary_item_segments,
3209             v_wlji_bom_reference_segments,
3210             v_wlji_rtg_ref_segs,
3211             v_wlji_compl_locator_segments,
3212             v_wlji_project_id ,
3213             v_wlji_project_name ,
3214             v_wlji_task_id ,
3215             v_wlji_delivery_id ,
3216             v_wlji_desc_flx_sgmts,
3217             v_wlji_project_number ,
3218             v_wlji_task_number ,
3219             v_wlji_project_costed ,
3220             v_wlji_end_item_unit_number,
3221             v_wlji_overcompl_tol_type,
3222             v_wlji_overcompl_tol_value,
3223             v_wlji_kanban_card_id ,
3224             v_wlji_priority ,
3225             v_wlji_due_date ,
3226             v_wlji_task_name,
3227             v_wlji_job_type,
3228             v_wlji_date_released   --bugfix 2697295
3229         limit batch_size;
3230 
3231         if lbji_debug = 'Y' then
3232             fnd_file.put_line(fnd_file.log, 'no of rows loaded for the current batch: '||c_wlji_1%rowcount);
3233         end if;
3234 
3235         if c_wlji_1%rowcount - prev_rowcount <> 0 then
3236 
3237             -- do the procesing --
3238 -- ==============================================================================================
3239 -- getting the header_id to be populated for mmtt
3240 -- ==============================================================================================
3241 
3242             select mtl_material_transactions_s.nextval
3243             into   txn_header_id
3244             from   dual;
3245 
3246 -- ==============================================================================================
3247 -- updating the group_id column of wlji with a number unique for this particular batch. This'll
3248 -- help when I select corresponding rows from wsli.
3249 -- ==============================================================================================
3250 l_stmt_num := 78;
3251 
3252             select wsm_lot_job_interface_s.NEXTVAL
3253             into   batch_group_id
3254             from   dual;
3255 
3256             forall indx in v_wlji_header_id.first..v_wlji_header_id.last
3257             update wsm_lot_job_interface
3258             set    group_id = batch_group_id
3259             where  header_id = v_wlji_header_id(indx);
3260 
3261             fnd_file.put_line(fnd_file.output, '         ----  Lot Based Job Creation  ----         ');
3262             fnd_file.put_line(fnd_file.output, ' ');
3263             fnd_file.put_line(fnd_file.output, ' ');
3264 
3265 -- ==============================================================================================
3266 -- processing of data begins here
3267 -- ==============================================================================================
3268 l_stmt_num := 80;
3269 
3270             v_index := v_wlji_header_id.first;
3271             while v_index <= v_wlji_header_id.last
3272             loop  -- inner loop
3273 
3274                 if lbji_debug = 'Y' then
3275                     fnd_file.put_line(fnd_file.log,'***************************************************************');
3276                     fnd_file.put_line(fnd_file.log,'new job ... wlji header_id: '||v_wlji_header_id(v_index));
3277                     fnd_file.put_line(fnd_file.log,'        ... job name: '||v_wlji_job_name(v_index));
3278                     fnd_file.put_line(fnd_file.log,'***************************************************************');
3279                 end if;
3280 
3281                 SAVEPOINT row_skip;
3282 
3283                 BEGIN  -- main block
3284 
3285                     routing_seq_id := '';
3286                     bom_seq_id := '';
3287                     dummy_err_code := 0;
3288                     dummy_err_msg := NULL;
3289                     l_error_code := 0;
3290                     l_return_value := 0;
3291                     l_error_msg:= NULL;
3292                     x_return_status:= FND_API.G_RET_STS_SUCCESS;
3293                     l_returnStatus :=  FND_API.G_RET_STS_SUCCESS;
3294                     l_dummy:= 0;
3295                     xst:= true;
3296                     str := '';
3297                     hash_value := 0;
3298                     l_no_of_records:= 0;
3299                     l_err_msg:= NULL;
3300                     l_aux_mesg:= NULL;
3301                     l_default_subinventory := '';
3302                     l_default_compl_loc_id := 0;
3303                     l_segs := '';
3304                     l_loc_success := true;
3305                     l_sub_loc_control := 0;
3306                     l_org_loc_control := 0;
3307                     l_item_loc_control := 0;
3308                     l_restrict_locators_code := 0;
3309                     l_item_id := 0;
3310                     l_sub := '';
3311                     l_revision := '';
3312                     l_quantity := 0;
3313                     l_locator_id := 0;
3314                     l_rev_date := '';
3315                     l_date_text := '';
3316                     l_component_quantity := 0;
3317                     l_qoh := 0;
3318                     l_att := 0;
3319                     l_atr := 0;
3320                     l_component_yield_factor := 0;
3321                     l_required_quantity := 0;
3322                     l_quantity_tobe_issued := 0;
3323                     l_start_op_seq_id := 0;
3324                     l_start_seq_id := 0;
3325                     l_end_seq_id := 0;
3326                     p_date_released := '';
3327                     p_old_date_released := '';
3328                     p_common_bill_sequence_id := 0;
3329                     p_common_routing_sequence_id := 0;
3330                     p_old_primary_item_id := 0;
3331                     p_old_class_code := '';
3332                     p_old_start_date := '';
3333                     p_old_complete_date := '';
3334                     p_est_scrap_account := NULL;
3335                     p_est_scrap_var_account := NULL;
3336                     p_old_quantity := 0;
3337                     p_old_bom_revision := '';
3338                     p_old_routing_revision := '';
3339                     p_old_net_quantity := 0;
3340                     p_skip_updt:=0;
3341                     p_old_status_type := 0;
3342                     l_department_id := 0;
3343                     p_old_firm_planned_flag := 0;
3344                     p_old_job_type:= 0;
3345                     dummy_number:=0;
3346                     dummy_varchar:='';
3347                     dummy_date:=sysdate;
3348                     p_change_bom_reference:=0;
3349                     p_change_routing_reference:=0;
3350                     p_change_bom_alt:=0;
3351                     p_change_routing_alt:=0;
3352                     p_change_alt_flag:=0;
3353                     p_old_bom_reference_id:=0;
3354                     p_old_alt_bom_designator:='';
3355                     p_old_routing_reference_id:=0;
3356                     p_old_alt_routing_designator:='';
3357                     p_old_bom_revision_date:='';
3358                     p_old_routing_revision_date:='';
3359                     p_old_com_rtg_seq_id:=0;
3360                     p_old_com_bom_seq_id:=0;
3361                     p_old_supply_type:=0;
3362                     p_scheduled_start_date:='';
3363                     p_scheduled_completion_date:='';
3364                     p_old_completion_subinv:='';
3365                     p_old_completion_locator:='';
3366                     p_coproducts_supply:='';
3367                     temp_start_quantity:=0;
3368                     temp_fusd:='';
3369                     temp_lucd:='';
3370                     temp_supply:=0;
3371                     l_build_sequence := 0;
3372                     l_line_id := 0;
3373                     l_schedule_group_id := 0;
3374                     l_src_lot_number:=NULL;
3375                     l_src_inv_item_id:=NULL;
3376 
3377                     -- abb H
3378                     min_op_seq_num:=0;
3379                     max_op_seq_num:=0;
3380                     l_scrap_account10:=NULL;
3381                     l_est_scrap_abs_account10:=NULL;
3382                     l_scrap_account9999:=NULL;
3383                     l_est_scrap_abs_account9999:=NULL;
3384 
3385                     v_wlji_err_code(v_index)                := l_error_code;
3386                     v_wlji_err_msg(v_index)                 := l_error_msg;
3387                     v_wlji_last_updt_date(v_index)          := l_last_update_date;
3388                     v_wlji_request_id(v_index)              := l_request_id;
3389                     v_wlji_program_id(v_index)              := l_program_id;
3390                     v_wlji_program_application_id(v_index)  := l_program_application_id;
3391                     v_wlji_creation_date(v_index)           := l_creation_date;
3392                     v_wlji_last_updt_login(v_index)         := l_login;
3393                     v_wlji_prog_updt_date(v_index)          := l_prog_updt_date;
3394 
3395 
3396 -- ==============================================================================================
3397 -- VALIDATIONS BEGIN
3398 -- ==============================================================================================
3399 
3400 l_stmt_num := 81;
3401                     -- *** job_type = 3 => non-standard job. Anything else/null => standard job ***
3402                     if v_wlji_job_type(v_index) is null then v_wlji_job_type(v_index):= 1; end if;
3403 
3404 
3405 l_stmt_num := 82;
3406                     -- *** mode_flag cannot be 2 for non-standard jobs ***
3407                     if v_wlji_job_type(v_index) = 3 and v_wlji_mode_flag(v_index) = 2 then
3408                         l_aux_mesg := 'Mode Flag cannot be 2 for Non Standard Jobs';
3409                         process_invalid_field('MODE FlAG',
3410                                               l_aux_mesg,
3411                                               l_stmt_num);
3412                         l_error_code := -1;
3413                         GOTO skip_validate_constants;
3414                     end if;
3415 
3416 
3417 l_stmt_num := 83;
3418                     -- *** load_wsli_data loads relevant rows from wsli into PL/SQL ***
3419                     -- *** tables for easy validation. I do not want this procedure ***
3420                     -- *** to be executed if there's no mode_flag = 2 rec in wlji.  ***
3421                     -- *** v_load_wsli (true/false) ensures that the procedure is   ***
3422                     -- *** called only once per worker                              ***
3423                     if v_wlji_load_type(v_index) = 5 and v_wlji_mode_flag(v_index) = 2
3424                        and v_load_wsli = true then
3425 
3426                         if (lbji_debug = 'Y') then
3427                             fnd_file.put_line(fnd_file.log,'loading wsli for batch group id: '||batch_group_id||'..');
3428                         end if;
3429 
3430                         load_wsli_data(batch_group_id);
3431                         v_load_wsli := false;
3432                     end if;
3433 
3434 
3435 l_stmt_num := 84;
3436                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
3437                         if v_wlji_firm_planned_flag(v_index) is null then
3438                             v_wlji_firm_planned_flag(v_index) := 2;
3439                         elsif v_wlji_firm_planned_flag(v_index) <> 1 and
3440                               v_wlji_firm_planned_flag(v_index) <> 2 then
3441                             l_aux_mesg := 'Firm Planned Flag should be 1 or 2';
3442                             process_invalid_field('FIRM_PLANNED_FLAG',
3443                                                   l_aux_mesg,
3444                                                   l_stmt_num);
3445                             l_error_code := -1;
3446                             GOTO skip_validate_constants;
3447                         end if;
3448                     end if;
3449 
3450 
3451 l_stmt_num := 85;
3452                     if WSMPVERS.get_osfm_release_version < '110509' and v_wlji_kanban_card_id(v_index) is not null then
3453                         l_error_code := -1;
3454                         process_errorred_field('WSM',
3455                                                'WSM_KANBAN_NOT ALLOWED',
3456                                                 l_stmt_num);
3457                     end if;
3458                     if l_error_code <> 0 then
3459                         l_error_count := l_error_count + 1;
3460                         GOTO skip_other_steps;
3461                     end if;
3462 
3463 
3464 l_stmt_num := 91;
3465                     -- *** check that there's a row in wsli for this mode 2 job ***
3466                     xst := true;
3467                     if v_wlji_load_type(v_index) = 5 AND v_wlji_mode_flag(v_index) = 2 then
3468                         if v_wlji_source_line_id(v_index) is NULL then
3469                             l_error_code := -1;
3470                             process_errorred_field('WSM',
3471                                                    'WSM_START_LOT_REQUIRED',
3472                                                    l_stmt_num);
3473                         else
3474                             xst := v_wsli.exists(v_wlji_source_line_id(v_index));
3475                             if xst = false then
3476                                 l_error_code := -1;
3477                                 process_errorred_field('WSM',
3478                                                        'WSM_START_LOT_REQUIRED',
3479                                                        l_stmt_num);
3480                             end if;
3481                         end if;
3482                     end if;
3483 
3484                     if l_error_code <> 0 then
3485                         l_error_count := l_error_count + 1;
3486                             GOTO skip_other_steps;
3487                     end if;
3488                     xst := true;
3489 
3490 
3491 l_stmt_num := 100;
3492                     -- *** validate org id begin ***
3493                     xst :=  WSMPLCVA.v_org.exists(v_wlji_org(v_index));
3494                     if xst = false then
3495                         l_error_code := -1;
3496                         process_invalid_field('ORGANIZATION ID',
3497                                               '',
3498                                               l_stmt_num);
3499                     end if;
3500 
3501                     if l_error_code <> 0 then
3502                         l_error_count := l_error_count + 1;
3503                         GOTO skip_other_steps;
3504                     end if;
3505                     xst := true;
3506 
3507                     if lbji_debug = 'Y' then
3508                         fnd_file.put_line(fnd_file.log, 'Org Id Validation..Success.');
3509                     end if;
3510                     -- *** validate org id end ***
3511 
3512 
3513 l_stmt_num := 110;
3514                     -- *** make sure that no one is trying to create a wip lot out of an inventory ***
3515                     -- *** lot by splitting/merging/etc. CZH: check wlsmi
3516                     if v_wlji_load_type(v_index) = 5 then
3517 
3518                         begin
3519                             select  1
3520                             into    l_no_of_records
3521                             from    wsm_starting_lots_interface    wsli,
3522                                     wsm_lot_split_merges_interface wlsmi
3523                             where   wsli.lot_number = v_wlji_job_name(v_index)
3524                             and     wsli.header_id = wlsmi.header_id
3525                             and     wlsmi.process_status in (1,2);
3526 
3527                         exception
3528                             when too_many_rows then l_no_of_records := 1;
3529                             when no_data_found then NULL;
3530                         end;
3531 
3532                         if l_no_of_records <> 0 then
3533                             l_error_code := -1;
3534                             process_errorred_field('WSM',
3535                                                    'WSM_LOT_EXISTS',
3536                                                    l_stmt_num);
3537                         end if;
3538 
3539                         if l_error_code <> 0 then
3540                             l_error_count := l_error_count + 1;
3541                             GOTO skip_other_steps;
3542                         end if;
3543                         l_no_of_records := 0;
3544 
3545                         if lbji_debug = 'Y' then
3546                             fnd_file.put_line(fnd_file.log, 'Checking existance of inv lots of the same name.. Success');
3547                         end if;
3548 
3549                     end if; -- load type 5
3550 
3551 
3552 l_stmt_num := 120;
3553                     -- *** validate constants begin ***  CZH: this should be moved above
3554 
3555 l_stmt_num := 130;
3556                     if (v_wlji_load_type(v_index) <> 5) AND (v_wlji_load_type(v_index) <> 6) then
3557                         l_aux_mesg := 'Load type should be 5 or 6';
3558                         process_invalid_field('LOAD TYPE',
3559                                               l_aux_mesg,
3560                                               l_stmt_num);
3561                         l_error_code := -1;
3562                         GOTO skip_validate_constants;
3563                     end if;
3564 
3565 l_stmt_num := 140;
3566                     if v_wlji_load_type(v_index) = 5 AND
3567                       (v_wlji_scheduling_method(v_index) <> 3 AND
3568                        v_wlji_scheduling_method(v_index) <> 2) then
3569                         l_aux_mesg := 'Scheduling method should be 2 or 3 for load_type 5';
3570                         process_invalid_field('SCHEDULING METHOD',
3571                                               l_aux_mesg,
3572                                               l_stmt_num);
3573                         l_error_code := -1;
3574                         GOTO skip_validate_constants;
3575                     end if;
3576 
3577 l_stmt_num := 150;
3578                     if v_wlji_load_type(v_index) = 5 AND
3579                        v_wlji_job_type(v_index) <> 3 and
3580                        v_wlji_mode_flag(v_index) not in (1,2) then
3581                         l_aux_mesg := 'For creating new jobs, mode flag should have value 1 or 2';
3582                         process_invalid_field('MODE FLAG',
3583                                               l_aux_mesg,
3584                                               l_stmt_num);
3585                         l_error_code := -1;
3586                         GOTO skip_validate_constants;
3587                     elsif v_wlji_job_type(v_index) = 3 then
3588                         if v_wlji_mode_flag(v_index) <> 1 then
3589                             if lbji_debug = 'Y' then
3590                                 fnd_file.put_line(fnd_file.log, 'Ignoring mode_flag, has to be 1 for non-standard jobs.');
3591                             end if;
3592                         end if;
3593                         if v_wlji_mode_flag(v_index) is null then
3594                             v_wlji_mode_flag(v_index) := 1;
3595                         end if;
3596                     end if;
3597 
3598 l_stmt_num := 160;
3599                     if v_wlji_load_type(v_index)  = 6 AND
3600                       (v_wlji_scheduling_method(v_index) <> 3 AND
3601                        v_wlji_scheduling_method(v_index) <> 2) then
3602                         l_aux_mesg := 'Scheduling method should be 2 or 3 for load_type 6';
3603                         process_invalid_field('SCHEDULING METHOD',
3604                                                l_aux_mesg,
3605                                                l_stmt_num);
3606                         l_error_code := -1;
3607                         GOTO skip_validate_constants;
3608                     end if;
3609 
3610 l_stmt_num := 170;
3611                     if UPPER(v_wlji_allow_explosion(v_index))  = 'N' then
3612                         process_errorred_field('WSM',
3613                                                'WSM_ALLOW_EXPL_Y',
3614                                                l_stmt_num);
3615                         l_error_code := -1;
3616                         GOTO skip_validate_constants;
3617                     else
3618                         v_wlji_allow_explosion(v_index) := 'Y';
3619                     end if;
3620 
3621 l_stmt_num := 180;
3622                     if v_wlji_wip_supply_type(v_index) is null then
3623                         v_wlji_wip_supply_type(v_index) := 7;
3624                     elsif v_wlji_wip_supply_type(v_index) not in (1,2,3,4,5,7) then
3625                         l_aux_mesg := '';
3626                         process_invalid_field('WIP SUPPLY TYPE',
3627                                               l_aux_mesg,
3628                                               l_stmt_num);
3629                         l_error_code := -1;
3630                         GOTO skip_validate_constants;
3631                     end if;
3632 
3633 l_stmt_num := 181;
3634                     if v_wlji_status_type(v_index) not in
3635                     (WIP_CONSTANTS.UNRELEASED,
3636                      WIP_CONSTANTS.RELEASED,
3637                      WIP_CONSTANTS.HOLD,
3638                      WIP_CONSTANTS.CANCELLED) then
3639                         l_aux_mesg := '';
3640                         process_invalid_field('STATUS TYPE',
3641                                               l_aux_mesg,
3642                                               l_stmt_num);
3643                         l_error_code := -1;
3644                         GOTO skip_validate_constants;
3645                     end if;
3646 
3647 << skip_validate_constants >>
3648 
3649                     if l_error_code <> 0 then
3650                         l_error_count := l_error_count + 1;
3651                         GOTO skip_other_steps;
3652                     end if;
3653                     l_aux_mesg := '';
3654 
3655                     if lbji_debug = 'Y' then
3656                         fnd_file.put_line(fnd_file.log, 'Validating Constants.. Success.');
3657                     end if;
3658 
3659                     -- *** validate constants end ***
3660 
3661 
3662 
3663 l_stmt_num := 181.5;
3664                     l_error_code := 0;
3665                     l_err_msg := '';
3666 
3667                     -- *** validation of a non-standard job for creation***
3668 
3669                     if v_wlji_job_type(v_index) = 3 and v_wlji_load_type(v_index) = 5 then
3670 
3671                         -- validation_level = 0 => validations performed during job creation
3672 
3673                         -- *** Error Code and Message Guide ***
3674                         -- 1: Routing Reference Cannot be Null
3675                         -- 2: Invalid Assembly Item Id
3676                         -- 3: Invalid Routing Reference Id
3677                         -- 4: Invalid Bom Reference Id
3678                         -- 5: Invalid Alternate Routing Designator
3679                         -- 0: Invalid Alternate Bom Designator -- WARNING
3680                         -- 7: Start Date cannot be greater than End Date
3681                         -- 8: Both Start and End Dates must be Entered
3682                         -- 9: Invalid Start Quantity
3683                         -- 10: Invalid Net Quantity
3684                         -- 11: Invalid Class Code
3685                         -- 12: Invalid Completion Locator Id
3686                         -- 13: Invalid Completion Subinventory
3687                         -- 14: Invalid Firm Planned Flag
3688 
3689 
3690                         wsmputil.validate_non_std_references(v_wlji_item(v_index),
3691                                   v_wlji_routing_reference_id(v_index),
3692                                   v_wlji_bom_reference_id(v_index),
3693                                   v_wlji_alt_routing_designator(v_index),
3694                                   v_wlji_alt_bom_designator(v_index),
3695                                   v_wlji_org(v_index),
3696                                   v_wlji_fusd(v_index),
3697                                   v_wlji_lucd(v_index),
3698                                   v_wlji_start_quantity(v_index),
3699                                   v_wlji_net_quantity(v_index),
3700                                   v_wlji_class_code(v_index),
3701                                   v_wlji_completion_subinventory(v_index),
3702                                   v_wlji_completion_locator_id(v_index),
3703                                   v_wlji_firm_planned_flag(v_index),
3704                                   v_wlji_bom_revision(v_index),
3705                                   v_wlji_bom_revision_date(v_index),
3706                                   v_wlji_routing_revision(v_index),
3707                                   v_wlji_routing_revision_date(v_index),
3708                                   routing_seq_id,
3709                                   bom_seq_id,
3710                                   0,
3711                                   l_error_code,
3712                                   l_err_msg);
3713 
3714 
3715                         if l_error_code <> 0 then
3716                             HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
3717                             l_error_code := -1;
3718                         end if;
3719 
3720                         if l_error_code = 0 and l_err_msg is not null then
3721                             fnd_file.new_line(fnd_file.log, 2);
3722                             fnd_file.put_line(fnd_file.log,l_err_msg);
3723                             fnd_file.new_line(fnd_file.log, 2);
3724                             l_err_msg := '';
3725                         end if;
3726                     end if; -- non-standard validations end
3727 
3728                     if l_error_code <> 0 then
3729                         l_error_count := l_error_count + 1;
3730                         GOTO skip_other_steps;
3731                     end if;
3732 
3733 
3734 l_stmt_num := 240;
3735                     -- *** validate assembly quantity begin ***
3736                     if v_wlji_job_type(v_index) <> 3 then
3737 
3738                         if v_wlji_start_quantity(v_index) < 0 then
3739                             l_error_code := -1;
3740                             l_aux_mesg := 'Start quantity cannot be negative';
3741                             process_invalid_field(
3742                                   'START QUANTITY',
3743                                   l_aux_mesg,
3744                                   l_stmt_num);
3745                             GOTO skip_validate_strt_qnty;
3746                         end if;
3747 
3748 
3749                         if v_wlji_load_type(v_index) = 5 and
3750                           (v_wlji_start_quantity(v_index) is NULL or
3751                            v_wlji_start_quantity(v_index) = 0) then
3752                             l_error_code := -1;
3753                             l_aux_mesg := 'Start quantity cannot be NULL or 0 for job creation';
3754                             process_invalid_field(
3755                                   'START QUANTITY',
3756                                   l_aux_mesg,
3757                                   l_stmt_num);
3758                         end if;
3759 
3760 << skip_validate_strt_qnty >>
3761 
3762                         if l_error_code <> 0 then
3763                             l_error_count := l_error_count + 1;
3764                             GOTO skip_other_steps;
3765                         end if;
3766                         l_aux_mesg := '';
3767 
3768                         if lbji_debug = 'Y' and v_wlji_mode_flag(v_index) = 1 then
3769                             fnd_file.put_line(fnd_file.log, 'Assembly Quantity OK');
3770                         end if;
3771                     end if; -- job_type
3772                     -- *** validate assembly quantity end ***
3773 
3774 l_stmt_num := 260;
3775                     -- *** validate mode one item id begin ***
3776                     -- CZH: why only for standard job ???
3777                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
3778 
3779                         if v_wlji_mode_flag(v_index) = 1 then
3780                             xst :=  WSMPLCVA.v_item.exists(v_wlji_item(v_index));
3781                         else -- mode flag 2
3782                             str := to_char(v_wlji_item(v_index))||
3783                                    to_char(v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id);
3784                             hash_value := dbms_utility.get_hash_value(str, 37, 1073741824);
3785 
3786                             xst := WSMPLCVA.v_mode2_item.exists(hash_value)
3787                                    AND WSMPLCVA.v_mode2_item(hash_value).INVENTORY_ITEM_ID =
3788                                             v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
3789                                    AND WSMPLCVA.v_mode2_item(hash_value).PRIMARY_ITEM_ID = v_wlji_item(v_index);
3790                         end if;
3791 
3792                         if xst = false then
3793 
3794                             begin
3795                                 select  1
3796                                 into    l_no_of_records
3797                                 from    mtl_system_items_kfv msi
3798                                 where   msi.inventory_item_id = v_wlji_item(v_index)
3799                                 and     msi.organization_id = v_wlji_org(v_index)
3800                                 and     msi.lot_control_code = 2;
3801                             exception
3802                                 when too_many_rows then l_no_of_records := 1;
3803                                 when no_data_found then
3804                                     l_error_code := -1;
3805                                     process_errorred_field('WSM',
3806                                                            'WSM_ASSEMBLY_NO_LOT',
3807                                                            l_stmt_num);
3808                             end;
3809 
3810                             if l_no_of_records <> 0 then
3811                                 begin
3812                                     l_no_of_records := 0;
3813                                     select  1
3814                                     into    l_no_of_records
3815                                     from    mtl_system_items_kfv msi
3816                                     where   msi.inventory_item_id = v_wlji_item(v_index)
3817                                     and     msi.organization_id = v_wlji_org(v_index)
3818                                     and     msi.serial_number_control_code = 1;
3819                                 exception
3820                                     when too_many_rows then l_no_of_records := 1;
3821                                     when no_data_found then
3822                                         l_error_code := -1;
3823                                         process_errorred_field('WSM',
3824                                                                'WSM_ASSEMBLY_NOT_SERIAL',
3825                                                                l_stmt_num);
3826                                 end;
3827                             end if;
3828 
3829                         end if; -- xst = false
3830 
3831                         if xst = false AND l_no_of_records <> 0 then
3832                             if v_wlji_mode_flag(v_index) = 2 then
3833                                 WSMPLCVA.v_mode2_item(hash_value).INVENTORY_ITEM_ID :=
3834                                     v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id;
3835                                 WSMPLCVA.v_mode2_item(hash_value).PRIMARY_ITEM_ID :=
3836                                     v_wlji_item(v_index);
3837                             else -- mode flag = 1
3838                                 WSMPLCVA.v_item(v_wlji_item(v_index)) := v_wlji_item(v_index);
3839                             end if;
3840                         end if;
3841 
3842                         if l_error_code <> 0 then
3843                             l_error_count := l_error_count + 1;
3844                             GOTO skip_other_steps;
3845                         end if;
3846                         l_no_of_records := 0;
3847                         l_dummy := 0;
3848                         l_aux_mesg := '';
3849                         xst := true;
3850                         str := '';
3851                         hash_value := 0;
3852 
3853                         if lbji_debug = 'Y' then
3854                             fnd_file.put_line(fnd_file.log, 'Validation of Item.. Success');
3855                         end if;
3856 
3857                     end if; -- load type 5
3858                     -- *** validate mode one item id end ***
3859 
3860 
3861 l_stmt_num := 280;
3862                     -- *** validate dates begin ***
3863                     if v_wlji_load_type(v_index) = 5 then
3864 
3865                         IF v_wlji_fusd(v_index) IS NOT NULL AND
3866                            v_wlji_lucd(v_index) IS NOT NULL THEN
3867 
3868                             IF  v_wlji_fusd(v_index) > v_wlji_lucd(v_index) THEN
3869                                 process_errorred_field('WSM',
3870                                                        'WSM_FUSD_GT_LUCD',
3871                                                        l_stmt_num);
3872                                 l_error_code := -1;
3873                                 GOTO skip_date_validation;
3874                             END IF;
3875                         ELSIF v_wlji_fusd(v_index) IS NULL AND
3876                               v_wlji_lucd(v_index) IS NULL THEN
3877                             process_errorred_field('WSM',
3878                                                    'WSM_DATES_NULL',
3879                                                    l_stmt_num);
3880                             l_error_code := -1;
3881                             GOTO skip_date_validation;
3882                         END IF;
3883 
3884                         IF v_wlji_fusd(v_index) IS NOT NULL AND
3885                            v_wlji_lucd(v_index) IS NULL THEN
3886                             v_wlji_lucd(v_index) := wsmputil.GET_SCHEDULED_DATE (
3887                                        v_wlji_org(v_index),
3888                                        v_wlji_item(v_index),
3889                                        'F',
3890                                        v_wlji_fusd(v_index),
3891                                        --v_wlji_start_quantity(v_index),
3892                                        l_error_code,
3893                                        l_err_msg,
3894                                        v_wlji_start_quantity(v_index));     --Fixed bug # 2313574
3895 
3896                             if lbji_debug = 'Y' then
3897                                 fnd_file.put_line(fnd_file.log, 'Getting complete date based on item lead time');
3898                             end if;
3899 
3900                         END IF ;
3901 
3902 
3903                         IF v_wlji_fusd(v_index) IS NULL AND
3904                            v_wlji_lucd(v_index) IS NOT NULL THEN
3905                             v_wlji_fusd(v_index) := wsmputil.GET_SCHEDULED_DATE (
3906                                        v_wlji_org(v_index),
3907                                        v_wlji_item(v_index),
3908                                        'B',
3909                                        v_wlji_lucd(v_index),
3910                                        --v_wlji_start_quantity(v_index),
3911                                        l_error_code,
3912                                        l_err_msg,
3913                                        v_wlji_start_quantity(v_index));     --Fixed bug # 2313574
3914 
3915                             if lbji_debug = 'Y' then
3916                                 fnd_file.put_line(fnd_file.log, 'Getting start date based on item lead time');
3917                             end if;
3918                         END IF;
3919 
3920                         if l_error_code <> 0 OR l_err_msg IS NOT NULL then
3921                             HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
3922                             l_error_code := -1;
3923                         end if;
3924 
3925 << skip_date_validation >>
3926 
3927                         if l_error_code <> 0 then
3928                             l_error_count := l_error_count + 1;
3929                             GOTO skip_other_steps;
3930                         end if;
3931                         l_err_msg := '';
3932 
3933                         if lbji_debug = 'Y' then
3934                             fnd_file.put_line(fnd_file.log, 'Date Validation.. Success.');
3935                         end if;
3936 
3937                     end if; -- load type 5
3938                     -- *** validate dates end ***
3939 
3940 
3941 l_stmt_num := 300;
3942                     -- *** validate net quantity begin ***
3943                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
3944 
3945                         if (v_wlji_net_quantity(v_index) < 0) then
3946                             l_aux_mesg := 'Net Quantity should be > 0';
3947                             process_invalid_field('NET QUANTITY',
3948                                                   l_aux_mesg,
3949                                                   l_stmt_num);
3950                             l_error_code := -1;
3951                         end if;
3952 
3953                         if (v_wlji_net_quantity(v_index) IS NULL) then
3954                             v_wlji_net_quantity(v_index) :=  v_wlji_start_quantity(v_index);
3955                         end if;
3956 
3957                         if v_wlji_net_quantity(v_index) > v_wlji_start_quantity(v_index) then
3958                             l_aux_mesg := 'Net Quantity should be <= start quantity';
3959                             process_invalid_field('NET QUANTITY',
3960                                                   l_aux_mesg,
3961                                                   l_stmt_num);
3962                             l_error_code := -1;
3963                         end if;
3964                         if l_error_code <> 0 then
3965                             l_error_count := l_error_count + 1;
3966                             GOTO skip_other_steps;
3967                         end if;
3968                         l_aux_mesg := '';
3969 
3970                         if lbji_debug = 'Y' then
3971                             fnd_file.put_line(fnd_file.log, 'Net Quantity Validation.. Success.');
3972                         end if;
3973 
3974                     end if; -- load type 5
3975                     -- *** validate net quantity end ***
3976 
3977 
3978                     l_stmt_num := 320;
3979                     -- *** validate coproduct-supply flag begin ***
3980                     if v_wlji_load_type(v_index) = 5 then
3981 
3982                         IF v_wlji_coproducts_supply(v_index) is NULL THEN
3983                             v_wlji_coproducts_supply(v_index) :=
3984                                     WSMPLCVA.v_org(v_wlji_org(v_index)).COPRODUCTS_SUPPLY_DEFAULT;
3985                         ELSIF ( v_wlji_coproducts_supply(v_index) <> 1
3986                             OR  v_wlji_coproducts_supply(v_index) <> 2)  THEN
3987                             v_wlji_coproducts_supply(v_index) := 2;
3988                         END IF;
3989 
3990                         if l_error_code <> 0 then
3991                             l_error_count := l_error_count + 1;
3992                             GOTO skip_other_steps;
3993                         end if;
3994 
3995                         if lbji_debug = 'Y' then
3996                             fnd_file.put_line(fnd_file.log, 'Co Product Supply Flag Validation.. Success.');
3997                         end if;
3998 
3999                     end if; -- load type 5
4000                     -- *** validate coproduct-supply flag end ***
4001 
4002 
4003 l_stmt_num := 340;
4004                     -- *** get routing_seq_id begin ***
4005                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
4006 
4007                         begin
4008                         -- bugfix 2681637 validation of alternate designator should check disable_date. (original bug for form 2558447)
4009                         -- view bom_routing_alternates_v does not have designator disable_date infor.
4010 
4011                            select bor.routing_sequence_id,
4012                                   bor.COMPLETION_SUBINVENTORY,
4013                                   bor.COMPLETION_LOCATOR_ID
4014                            into   routing_seq_id,
4015                                   l_default_subinventory,
4016                                   l_default_compl_loc_id
4017                            --from bom_routing_alternates_v bor
4018                            from   bom_operational_routings bor,
4019                                   bom_alternate_designators bad
4020                            where  ((bor.alternate_routing_designator is null and
4021                                     bad.alternate_designator_code is null
4022                                     and bad.organization_id = -1)
4023                                    or (bor.alternate_routing_designator = bad.alternate_designator_code
4024                                        and bor.organization_id = bad.organization_id))
4025                            and    bor.organization_id = v_wlji_org(v_index)
4026                            and    bor.assembly_item_id = v_wlji_item(v_index)
4027                            and    NVL(bor.alternate_routing_designator, '&*') = NVL(v_wlji_alt_routing_designator(v_index), '&*')
4028                            and    bor.routing_type = 1
4029                            and    bor.cfm_routing_flag = 3;
4030                            --Bug 5107339: Disable_date validation is not applicable here.
4031                            --and    trunc(nvl(bad.disable_date, sysdate + 1)) > trunc(sysdate);
4032 
4033                         exception
4034                             when no_data_found then
4035                                 l_aux_mesg := '';
4036                                 process_invalid_field('ALTERNATE ROUTING DESIGNATOR',
4037                                                       l_aux_mesg,
4038                                                       l_stmt_num);
4039                                 l_error_code := -1;
4040                         end;
4041 
4042                         if l_error_code <> 0 then
4043                             l_error_count := l_error_count + 1;
4044                             GOTO skip_other_steps;
4045                         end if;
4046 
4047                         if lbji_debug = 'Y' then
4048                             fnd_file.put_line(fnd_file.log, 'Getting Routing Sequence Id: '||routing_seq_id);
4049                         end if;
4050 
4051                         IF v_wlji_completion_subinventory(v_index) IS NULL AND
4052                            v_wlji_completion_locator_id(v_index) IS NULL THEN
4053                             v_wlji_completion_subinventory(v_index) := l_default_subinventory;
4054                             v_wlji_completion_locator_id(v_index) := l_default_compl_loc_id;
4055                         END IF;
4056 
4057                         IF v_wlji_completion_subinventory(v_index) IS NULL AND
4058                            v_wlji_completion_locator_id(v_index) IS NOT NULL THEN
4059                             v_wlji_completion_subinventory(v_index) := l_default_subinventory;
4060                         END IF;
4061 
4062                         IF v_wlji_completion_subinventory(v_index) IS NOT NULL AND
4063                            v_wlji_completion_locator_id(v_index) IS NULL THEN
4064 
4065                         -- do the subinventory validation here...
4066                         -- validation of subinv begin
4067                             str := to_char(v_wlji_org(v_index))||v_wlji_completion_subinventory(v_index);
4068                             hash_value := dbms_utility.get_hash_value(str, 37, 1073741824);
4069                             if WSMPLCVA.v_subinv.exists(hash_value) then
4070                                 NULL;
4071                             else
4072                                 l_aux_mesg := '';
4073                                 process_invalid_field('COMPLETION SUBINVENTORY',
4074                                                       l_aux_mesg,
4075                                                       l_stmt_num);
4076                                 l_error_code := -1;
4077                             end if;
4078 
4079                             if l_error_code <> 0 then
4080                                 l_error_count := l_error_count + 1;
4081                                 GOTO skip_other_steps;
4082                             end if;
4083 
4084                             l_aux_mesg := '';
4085                             str := '';
4086                             hash_value := 0;
4087 
4088                             -- validation of subinv end
4089 
4090                             select locator_type
4091                             into   mtl_locator_type
4092                             from   mtl_secondary_inventories
4093                             where  secondary_inventory_name = v_wlji_completion_subinventory(v_index)
4094                             and    organization_id = v_wlji_org(v_index);
4095 
4096                             if v_wlji_completion_subinventory(v_index) = l_default_subinventory then
4097                                 v_wlji_completion_locator_id(v_index) := l_default_compl_loc_id;
4098                             else
4099                                 if mtl_locator_type = 2 then
4100                                     l_aux_mesg := '';
4101                                     process_invalid_field('COMPLETION SUBINVENTORY',
4102                                                           l_aux_mesg,
4103                                                           l_stmt_num);
4104                                     l_error_code := -1;
4105                                     l_error_count := l_error_count + 1;
4106                                     GOTO skip_other_steps;
4107                                 else
4108                                     NULL;
4109                                 end if;
4110                             end if;
4111                         END IF;
4112 
4113                         l_aux_mesg := '';
4114                     end if; -- load type 5
4115                     -- *** get routing_seq_id end ***
4116 
4117 
4118                     l_stmt_num := 360;
4119                     -- *** get bill_seq_id begin ***
4120                     --if the alternate_bom_designator has NULL in wlji, bill_seq_id can have either a
4121                     --NULL or a primary bom value. But if the designator has ALT, then there must be a
4122                     --bill id for the alternate bom.
4123 
4124                     if v_wlji_load_type(v_index) = 5  and v_wlji_job_type(v_index) <> 3 then
4125 
4126                         IF v_wlji_alt_bom_designator(v_index) is NULL THEN
4127                             begin
4128                                 SELECT  bom.common_bill_sequence_id
4129                                 INTO    bom_seq_id
4130                                 FROM    bom_bill_of_materials bom
4131                                 WHERE   bom.alternate_bom_designator is NULL
4132                                 AND     BOM.assembly_item_id = v_wlji_item(v_index)
4133                                 AND     bom.organization_id = v_wlji_org(v_index);
4134                             exception
4135                                 WHEN NO_DATA_FOUND THEN
4136                                     NULL;
4137                             end;
4138                         ELSE
4139                             begin
4140                                 -- bugfix 2681637 validation of alternate designator should check disable_date.
4141                                 -- (original bug for form 2558447)
4142                                 -- table bom_bill_of_materials does not have designator disable_date infor.
4143 
4144                                 SELECT  bom.common_bill_sequence_id
4145                                 INTO    bom_seq_id
4146                                 FROM    bom_bill_of_materials bom,
4147                                         bom_alternate_designators bad
4148                                 WHERE   ((bom.alternate_bom_designator is null and
4149                                           bad.alternate_designator_code is null
4150                                           and bad.organization_id = -1)
4151                                          OR (bom.alternate_bom_designator = bad.alternate_designator_code
4152                                              and bom.organization_id = bad.organization_id))
4153                                 AND     bom.alternate_bom_designator = v_wlji_alt_bom_designator(v_index)
4154                                 AND     BOM.assembly_item_id = v_wlji_item(v_index)
4155                                 AND     bom.organization_id = v_wlji_org(v_index);
4156                                 --Bug 5107339: Disable_date validation is not applicable here.
4157                                 --AND     trunc(nvl(bad.disable_date, sysdate + 1)) > trunc(sysdate);
4158 
4159                             exception
4160                                 WHEN no_data_found  THEN
4161                                     l_aux_mesg := '';
4162                                     process_invalid_field('ALTERNATE BOM DESIGNATOR',
4163                                                           l_aux_mesg,
4164                                                           l_stmt_num);
4165                                     l_error_code := -1;
4166                             end;
4167                         END IF;
4168 
4169                         if l_error_code <> 0 then
4170                             l_error_count := l_error_count + 1;
4171                             GOTO skip_other_steps;
4172                         end if;
4173                         l_aux_mesg := '';
4174 
4175                         if lbji_debug = 'Y' then
4176                             fnd_file.put_line(fnd_file.log, 'Getting Bill Sequence Id: '||bom_seq_id);
4177                         end if;
4178 
4179                     end if; -- load type 5
4180                     -- *** get bill_seq_id end ***
4181 
4182 
4183 l_stmt_num := 400;
4184                     -- *** validate locator id begin ***
4185                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
4186 
4187                         SELECT  nvl(msub.locator_type, 1) sub_loc_control,
4188                                 MP.stock_locator_control_code org_loc_control,
4189                                 MS.restrict_locators_code,
4190                                 MS.location_control_code item_loc_control
4191                         into    l_sub_loc_control, l_org_loc_control,
4192                                 l_restrict_locators_code, l_item_loc_control
4193                         FROM    mtl_system_items MS,
4194                                 mtl_secondary_inventories MSUB,
4195                                 mtl_parameters MP
4196                         WHERE   MP.organization_id = v_wlji_org(v_index)
4197                         AND     MS.organization_id = v_wlji_org(v_index)
4198                         AND     MS.inventory_item_id = v_wlji_item(v_index)
4199                         AND     MSUB.secondary_inventory_name = v_wlji_completion_subinventory(v_index)
4200                         AND     MSUB.organization_id = v_wlji_org(v_index);
4201 
4202                         l_locator_id := v_wlji_completion_locator_id(v_index) ;
4203 
4204                         WIP_LOCATOR.validate(
4205                                             v_wlji_org(v_index),
4206                                             v_wlji_item(v_index),
4207                                             v_wlji_completion_subinventory(v_index),
4208                                             l_org_loc_control,
4209                                             l_sub_loc_control,
4210                                             l_item_loc_control,
4211                                             l_restrict_locators_code,
4212                                             NULL, NULL, NULL, NULL,
4213                                             l_locator_id,
4214                                             l_segs,
4215                                             l_loc_success);
4216 
4217                         IF not l_loc_success THEN
4218                             l_aux_mesg := '';
4219                             process_invalid_field('COMPLETION SUBINVENTORY',
4220                                                   l_aux_mesg,
4221                                                   l_stmt_num);
4222                             l_error_code := -1;
4223                         end if;
4224 
4225                         if l_error_code <> 0 then
4226                             l_error_count := l_error_count + 1;
4227                             GOTO skip_other_steps;
4228                         end if;
4229                         l_aux_mesg := '';
4230                         l_locator_id := 0;
4231 
4232                         if lbji_debug = 'Y' then
4233                             fnd_file.put_line(fnd_file.log, 'Locator Id Validation.. Success.');
4234                         end if;
4235 
4236                     end if; -- load type 5
4237                     -- *** validate locator id end ***
4238 
4239 
4240 l_stmt_num := 420;
4241                     -- *** validate last_updt_by begin ***
4242                     if v_wlji_load_type(v_index) = 5 then
4243 
4244                         if v_wlji_last_updt_by(v_index) is NULL then
4245                             v_wlji_last_updt_by(v_index) := l_user;
4246                         else
4247                             xst :=  WSMPLCVA.v_user.exists(v_wlji_last_updt_by(v_index));
4248                             if xst = false then
4249                                 begin
4250                                     select 1
4251                                     into   l_no_of_records
4252                                     from   fnd_user
4253                                     where  user_id = v_wlji_last_updt_by(v_index)
4254                                     and    sysdate between start_date and nvl(end_date,sysdate+1);
4255                                 exception
4256                                     when too_many_rows then l_no_of_records := 1;
4257                                     when no_data_found then
4258                                         l_error_code := -1;
4259                                         l_aux_mesg := '';
4260                                         process_invalid_field( 'Last Updated By',
4261                                                                l_aux_mesg,
4262                                                                l_stmt_num);
4263                                 end;
4264                             end if;
4265 
4266                             if xst = false AND l_no_of_records <> 0 then
4267                                 WSMPLCVA.v_user(v_wlji_last_updt_by(v_index)) := v_wlji_last_updt_by(v_index);
4268                             end if;
4269 
4270 
4271                             if l_error_code <> 0 then
4272                                 l_error_count := l_error_count + 1;
4273                                 GOTO skip_other_steps;
4274                             end if;
4275                             l_aux_mesg := '';
4276                             l_no_of_records := 0;
4277                             xst := true;
4278                         end if;
4279 
4280                         if lbji_debug = 'Y' then
4281                             fnd_file.put_line(fnd_file.log, 'Last Updt By Validation.. Success.');
4282                         end if;
4283 
4284                     end if; -- load type 5
4285                     -- *** validate last_updt_by end ***
4286 
4287 
4288 l_stmt_num := 440;
4289                     -- *** validate created_by begin ***
4290                     if v_wlji_load_type(v_index) = 5 then
4291 
4292                         if v_wlji_created_by(v_index) is NULL then
4293                             v_wlji_created_by(v_index) := l_user;
4294                         else
4295                             xst :=  WSMPLCVA.v_user.exists(v_wlji_created_by(v_index));
4296                             if xst = false then
4297                                 begin
4298                                     select 1
4299                                     into   l_no_of_records
4300                                     from   fnd_user
4301                                     where  user_id = v_wlji_created_by(v_index)
4302                                     and    sysdate between start_date and nvl(end_date,sysdate+1);
4303                                 exception
4304                                     when too_many_rows then l_no_of_records := 1;
4305                                     when no_data_found then
4306                                         l_error_code := -1;
4307                                         l_aux_mesg := '';
4308                                         process_invalid_field( 'Created By', l_aux_mesg, 'l_stmt_num.vldt_created_by');
4309                                 end;
4310                             end if;
4311 
4312                             if xst = false AND l_no_of_records <> 0 then
4313                                 WSMPLCVA.v_user(v_wlji_created_by(v_index)) := v_wlji_created_by(v_index);
4314                             end if;
4315 
4316                             if l_error_code <> 0 then
4317                                 l_error_count := l_error_count + 1;
4318                                 GOTO skip_other_steps;
4319                             end if;
4320                             l_aux_mesg := '';
4321                             l_no_of_records := 0;
4322                             xst := true;
4323                         end if;
4324 
4325                         if lbji_debug = 'Y' then
4326                             fnd_file.put_line(fnd_file.log, 'Created By Validation.. Success.');
4327                         end if;
4328 
4329                     end if; -- load type 5
4330                     -- *** validate created_by end ***
4331 
4332 
4333 l_stmt_num := 460;
4334                     -- *** validate job name and id begin ***
4335                     if LENGTH(v_wlji_job_name(v_index)) > 80 then       -- Changed for OPM Convergence project
4336                         process_errorred_field('WSM',
4337                                                'WSM_JOB_NAME_EIGHTY_CHAR',
4338                                                l_stmt_num);
4339                         l_error_code := -1;
4340                         GOTO skip_job_id_valid;
4341                     end if;
4342 
4343                     l_return_value := 0;
4344 
4345 l_stmt_num := 460.1;
4346                     /*Bug 3414163:Call to Check_wmti is commented.*/
4347                     /*
4348                     l_return_value := wsmputil.CHECK_WMTI(   -- CZH.I
4349                             P_WIP_ENTITY_ID => null,
4350                             P_WIP_ENTITY_NAME => v_wlji_job_name(v_index),
4351                             P_TRANSACTION_DATE => null,
4352                             X_ERR_CODE => l_error_code,
4353                             X_ERR_MSG => l_err_msg,
4354                             P_ORGANIZATION_ID => v_wlji_org(v_index)
4355                             );
4356                     IF (l_return_value > 0 OR l_return_value <> 0) THEN
4357                         process_errorred_field('WSM',
4358                                                'WSM_PENDING_MOVE_TXNS',
4359                                                l_stmt_num);
4360                         l_error_code := -1;
4361                         GOTO skip_job_id_valid;
4362                     END IF;
4363                     */
4364                     /*Bug 3414163:End of changes*/
4365 l_stmt_num := 460.2;
4366                     -- bug 3453139 remove this
4367                     --l_return_value := wsmputil.CHECK_WSMT(   -- CZH.I
4368                     --        P_WIP_ENTITY_ID => null,
4369                     --        P_WIP_ENTITY_NAME => v_wlji_job_name(v_index),
4370                     --        P_TRANSACTION_ID => NULL,
4371                     --        P_TRANSACTION_DATE => null,
4372                     --        X_ERR_CODE => l_error_code,
4373                     --        X_ERR_MSG => l_err_msg,
4374                     --        P_ORGANIZATION_ID => v_wlji_org(v_index)
4375                     --        );
4376 
4377                     --IF (l_return_value > 0 OR l_return_value <> 0) THEN
4378                     --    FND_MESSAGE.SET_NAME('WSM', 'WSM_PENDING_TXN');
4379                     --    FND_MESSAGE.SET_TOKEN('TABLE', 'wsm_split_merge_transactions');
4380                     --    l_err_msg := fnd_message.get;
4381                     --    l_error_code := -1;
4382                     --    HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
4383                     --    l_error_code := -1;
4384                     --    GOTO skip_job_id_valid;
4385                     --ELSE
4386                     --    l_error_code := 0;
4387                     --    l_err_msg := '';
4388                     --END IF;
4389 
4390 
4391 
4392                     Begin
4393                         l_dummy := 0;
4394                         if v_wlji_load_type(v_index) = 5 then
4395 
4396                             if (v_wlji_job_name(v_index) is null) then
4397 
4398                                 -- Derive JOB_NAME.
4399                                 select FND_Profile.value('WIP_JOB_PREFIX') || wip_job_number_s.nextval
4400                                 into   v_wlji_job_name(v_index)
4401                                 from   dual ;
4402 
4403                             else
4404 
4405                                 -- Be sure the provided JOB_NAME is not already in use.
4406                                 begin
4407 
4408                                     select 1 into l_dummy
4409                                     from   wip_entities
4410                                     where
4411                                         wip_entity_name = v_wlji_job_name(v_index) and
4412                                         organization_id = v_wlji_org(v_index);
4413 
4414                                     if l_dummy = 1 then
4415                                         process_errorred_field('WIP',
4416                                                                'WIP_ML_JOB_NAME',
4417                                                                l_stmt_num);
4418                                         l_error_code := -1;
4419                                         GOTO skip_job_id_valid;
4420                                     end if;
4421 
4422                                 exception
4423 
4424                                     -- This Exception added by BBK .
4425                                     when no_data_found then
4426                                             null;
4427 
4428                                     when others then
4429                                             process_errorred_field('WIP',
4430                                                                    'WIP_ML_JOB_NAME',
4431                                                                    l_stmt_num);
4432                                             l_error_code := -1;
4433                                             GOTO skip_job_id_valid;
4434                                 end ;
4435 
4436                             end if ;
4437 
4438                         elsif v_wlji_load_type(v_index) = 6 then
4439 
4440                             if (v_wlji_wip_entity_id(v_index) is null) then
4441 
4442                                 if (v_wlji_job_name(v_index) is null) then
4443                                     raise invalid_job_name_error;
4444                                 end if ;
4445 
4446                                 begin
4447                                     select wip_entity_id
4448                                     into   v_wlji_wip_entity_id(v_index)
4449                                     from   wip_entities
4450                                     where
4451                                         wip_entity_name = v_wlji_job_name(v_index) and
4452                                         organization_id = v_wlji_org(v_index) ;
4453                                 exception when others then
4454                                     raise invalid_job_name_error;
4455                                 end ;
4456 
4457                             else
4458                                 begin
4459 
4460                                     /* commented out by BBK as per Hari to remove dual usage.
4461                                     select 1 into l_dummy from dual where exists (
4462                                         select 1
4463                                         from   wip_discrete_jobs
4464                                         where
4465                                             wip_entity_id = v_wlji_wip_entity_id(v_index) and
4466                                             organization_id = v_wlji_org(v_index) and
4467                                             status_type in (
4468                                                 WIP_CONSTANTS.UNRELEASED,
4469                                                 WIP_CONSTANTS.RELEASED,
4470                                                 WIP_CONSTANTS.HOLD,
4471                                                 WIP_CONSTANTS.CANCELLED)
4472                                         );
4473                                     */
4474                                     -- added by BBK.
4475                                     select 1 into l_dummy
4476                                     from   wip_discrete_jobs
4477                                     where
4478                                         wip_entity_id = v_wlji_wip_entity_id(v_index) and
4479                                         status_type in (
4480                                             WIP_CONSTANTS.UNRELEASED,
4481                                             WIP_CONSTANTS.RELEASED,
4482                                             WIP_CONSTANTS.HOLD,
4483                                             WIP_CONSTANTS.CANCELLED) ;
4484                                 exception
4485                                     -- This Exception added by BBK .
4486                                     when no_data_found then
4487                                         raise invalid_id_error;
4488                                     when others then
4489                                         raise invalid_id_error;
4490                                 end ;
4491 
4492                             end if ;
4493                         end if;
4494 
4495                     Exception
4496                         when invalid_id_error then
4497                             l_aux_mesg := '';
4498                             process_invalid_field('WIP_ENTITY_ID',
4499                                                   l_aux_mesg,
4500                                                   l_stmt_num);
4501                             l_error_code := -1;
4502 
4503                         when invalid_job_name_error then
4504                             l_aux_mesg := '';
4505                             process_invalid_field('JOB_NAME',
4506                                                   l_aux_mesg,
4507                                                   l_stmt_num);
4508                             l_error_code := -1;
4509 
4510                     End;
4511 
4512 << skip_job_id_valid >>
4513 
4514                     if l_error_code <> 0 then
4515                         l_error_count := l_error_count + 1;
4516                         GOTO skip_other_steps;
4517                     end if;
4518                     l_aux_mesg := '';
4519 
4520                     if lbji_debug = 'Y' then
4521                         fnd_file.put_line(fnd_file.log, 'Job Name and Id Validation.. Success.');
4522                     end if;
4523 
4524                     l_dummy := 0;
4525                     -- *** validate job name and id end ***
4526 
4527 
4528 l_stmt_num := 480;
4529                     -- *** validate class code begin ***
4530                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
4531                         begin
4532 
4533                             IF v_wlji_class_code(v_index) is NULL then
4534 
4535                                 begin
4536                                     select wse.DEFAULT_ACCT_CLASS_CODE
4537                                     into   v_wlji_class_code(v_index)
4538                                     from   wsm_sector_extensions wse, wsm_item_extensions wie
4539                                     where  wie.INVENTORY_ITEM_ID = v_wlji_item(v_index)
4540                                     and    wie.ORGANIZATION_ID = v_wlji_org(v_index)
4541                                     and    wie.SECTOR_EXTENSION_ID = wse.SECTOR_EXTENSION_ID
4542                                     and    wie.ORGANIZATION_ID = wse.ORGANIZATION_ID;
4543                                 exception
4544                                     WHEN NO_DATA_FOUND THEN
4545                                         v_wlji_class_code(v_index) := NULL;
4546                                 end;
4547 
4548                                 IF v_wlji_class_code(v_index) is NULL then
4549 
4550                                     begin
4551 
4552                                         select wse.DEFAULT_ACCT_CLASS_CODE
4553                                         into   v_wlji_class_code(v_index)
4554                                         from   wsm_sector_extensions wse, wsm_subinventory_extensions wve
4555                                         where  wve.SECONDARY_INVENTORY_NAME = v_wlji_completion_subinventory(v_index)
4556                                         and    wve.ORGANIZATION_ID = v_wlji_org(v_index)
4557                                         and    wve.SECTOR_EXTENSION_ID = wse.SECTOR_EXTENSION_ID
4558                                         and     wve.ORGANIZATION_ID = wse.ORGANIZATION_ID;
4559                                     exception
4560                                         WHEN NO_DATA_FOUND THEN
4561                                             v_wlji_class_code(v_index) := NULL;
4562                                     end;
4563 
4564                                     IF v_wlji_class_code(v_index) is NULL then
4565                                         v_wlji_class_code(v_index) := WSMPLCVA.v_org(v_wlji_org(v_index)).DEFAULT_ACCT_CLASS_CODE;
4566                                     END IF;
4567 
4568                                 END IF;
4569 
4570                                 IF v_wlji_class_code(v_index) IS NULL THEN
4571                                     raise no_data_found;
4572                                 END IF;
4573 
4574                             ELSE
4575                                 str := to_char(v_wlji_org(v_index))||v_wlji_class_code(v_index);
4576                                 hash_value := dbms_utility.get_hash_value(str, 37, 1073741824);
4577                                 if WSMPLCVA.v_class_code.exists(hash_value) then
4578                                     NULL;
4579                                 else
4580                                     raise no_data_found;
4581                                 end if;
4582                             END IF;
4583 
4584                         exception
4585                             WHEN no_data_found  THEN
4586                                 l_aux_mesg := 'Or class code maybe NULL';
4587                                 process_invalid_field('CLASS_CODE',
4588                                                       l_aux_mesg,
4589                                                       l_stmt_num);
4590                                 l_error_code := -1;
4591                         end;
4592 
4593 
4594                         if l_error_code <> 0 then
4595                             l_error_count := l_error_count + 1;
4596                             GOTO skip_other_steps;
4597                         end if;
4598                         l_aux_mesg := '';
4599                         str := '';
4600                         hash_value := 0;
4601 
4602                         if lbji_debug = 'Y' then
4603                             fnd_file.put_line(fnd_file.log, 'Class Code Validation.. Success.');
4604                         end if;
4605 
4606                     end if; -- load type 5
4607                     -- *** validate class code end ***
4608 
4609 
4610 l_stmt_num := 500;
4611                     -- *** default lot_number begin ***
4612                     if v_wlji_load_type(v_index) = 5 then
4613                         v_wlji_lot_number(v_index) := v_wlji_job_name(v_index);
4614 
4615                         if lbji_debug = 'Y' then
4616                             fnd_file.put_line(fnd_file.log, 'Lot Number Defaulted.. Success.');
4617                         end if;
4618                     end if; -- load type 5
4619                     -- *** default lot_number end ***
4620 
4621 
4622 l_stmt_num := 520;
4623                     -- *** get revisions begin ***
4624                     -- this procedure is called only after date validation so that the start date is not null.
4625                     -- this is to be called only for job creation.
4626 
4627                     -- CZH.I_OED-1: if we are creating a job (load_type = 5), wip_revisions.routing_revision
4628                     -- is called, hence, v_wlji_routing_revision_date(v_index) will be populated
4629 
4630                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
4631 
4632                         if v_wlji_fusd(v_index) > SYSDATE then
4633                             l_rev_date := v_wlji_fusd(v_index);
4634                         else
4635                             l_rev_date := SYSDATE;
4636                         end if;
4637 
4638                         wip_revisions.bom_revision (v_wlji_org(v_index),
4639                                                     v_wlji_item(v_index),
4640                                                     v_wlji_bom_revision(v_index),
4641                                                     v_wlji_bom_revision_date(v_index),
4642                                                     l_rev_date);
4643 
4644 
4645                         wip_revisions.routing_revision (v_wlji_org(v_index),
4646                                                         v_wlji_item(v_index),
4647                                                         v_wlji_routing_revision(v_index),
4648                                                         v_wlji_routing_revision_date(v_index),
4649                                                         l_rev_date);
4650 
4651                         if l_error_code <> 0 then
4652                             l_error_count := l_error_count + 1;
4653                             GOTO skip_other_steps;
4654                         end if;
4655 
4656                         if lbji_debug = 'Y' then
4657                             fnd_file.put_line(fnd_file.log, 'Getting Revisions.. Success.');
4658                         end if;
4659 
4660                     end if; -- load type 5
4661                     -- *** get revisions end ***
4662 
4663 
4664 l_stmt_num := 540;
4665                     -- *** default description begin ***
4666                     -- this is to be called only for job creation.
4667                     if v_wlji_load_type(v_index) = 5 then
4668                         if RTRIM(v_wlji_description(v_index)) is NULL then
4669                             l_date_text := fnd_date.date_to_charDT(sysdate) ;
4670                             fnd_message.set_name('WIP','WIP_MLD_DESC');
4671                             fnd_message.set_token('LOAD_DATE', l_date_text, false) ;
4672                             v_wlji_description(v_index) := FND_Message.get;
4673                         else
4674                             v_wlji_description(v_index) := RTRIM(v_wlji_description(v_index));
4675                         end if;
4676 
4677                         if lbji_debug = 'Y' then
4678                             fnd_file.put_line(fnd_file.log, 'Default Description.. Success.');
4679                         end if;
4680                     end if; -- load type 5
4681                     -- *** default description end ***
4682 
4683 
4684 
4685                     if v_wlji_load_type(v_index) = 5 then
4686 
4687 l_stmt_num := 560;
4688                         -- *** validations for the starting lot in wsli. These validations are ***
4689                         -- *** to be performed only for jobs of mode flag 2.                   ***
4690 
4691                         if v_wlji_mode_flag(v_index) = 2 then
4692                         -- *** validation of starting lot begin ***
4693 l_stmt_num := 600;
4694                             -- BA: bug 3299026 do not allow serial controlled component
4695                             select  SERIAL_NUMBER_CONTROL_CODE,
4696                                     revision_qty_control_code       -- Add bug 2963225
4697                             into    l_dummy,
4698                                     l_rev_control_code              -- Add bug 2963225
4699                             from    mtl_system_items_kfv msi
4700                             where   msi.inventory_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
4701                             and     msi.organization_id = v_wlji_org(v_index);
4702 
4703                             if(l_dummy <> 1) then
4704                                 l_error_code := -1;
4705                                 process_errorred_field('WSM',
4706                                                        'WSM_SERIAL_COMP_NOT_SUPPORTED',
4707                                                        l_stmt_num);
4708                                 l_error_count := l_error_count + 1;
4709                                 GOTO skip_other_steps;
4710                             end if;
4711                             --EA bug 3299026
4712 
4713                             -- *** last_updated_by ***
4714 l_stmt_num := 601;
4715                             xst :=  WSMPLCVA.v_user.exists(v_wsli(v_wlji_source_line_id(v_index)).last_updated_by);
4716                             if xst = false then
4717                                 begin
4718                                     select 1
4719                                     into   l_no_of_records
4720                                     from   fnd_user
4721                                     where  user_id = v_wsli(v_wlji_source_line_id(v_index)).last_updated_by
4722                                     and    sysdate between start_date and nvl(end_date,sysdate+1);
4723                                 exception
4724                                     when too_many_rows then l_no_of_records := 1;
4725                                     when no_data_found then
4726                                         l_error_code := -1;
4727                                         l_aux_mesg := '';
4728                                         process_invalid_field( 'Last Updated By in WSM_STARTING_LOTS_INTERFACE',
4729                                                                 l_aux_mesg,
4730                                                                 l_stmt_num);
4731                                 end;
4732                             end if;
4733 
4734                             if xst = false AND l_no_of_records <> 0 then
4735                                 WSMPLCVA.v_user(v_wsli(v_wlji_source_line_id(v_index)).last_updated_by)
4736                                     := v_wsli(v_wlji_source_line_id(v_index)).last_updated_by;
4737                             end if;
4738 
4739                             if l_error_code <> 0 then
4740                                 l_error_count := l_error_count + 1;
4741                                 GOTO skip_other_steps;
4742                             end if;
4743                             l_aux_mesg := '';
4744                             l_no_of_records := 0;
4745                             xst := true;
4746 
4747                             -- *** created_by ***
4748 l_stmt_num := 602;
4749                             xst :=  WSMPLCVA.v_user.exists(v_wsli(v_wlji_source_line_id(v_index)).created_by);
4750                             if xst = false then
4751                                 begin
4752                                     select 1
4753                                     into   l_no_of_records
4754                                     from   fnd_user
4755                                     where  user_id = v_wsli(v_wlji_source_line_id(v_index)).created_by
4756                                     and    sysdate between start_date and nvl(end_date,sysdate+1);
4757                                 exception
4758                                     when too_many_rows then l_no_of_records := 1;
4759                                     when no_data_found then
4760                                         l_error_code := -1;
4761                                         l_aux_mesg := '';
4762                                         process_invalid_field( 'CREATED BY in WSM_STARTING_LOTS_INTERFACE',
4763                                                                 l_aux_mesg,
4764                                                                 l_stmt_num);
4765                                 end;
4766                             end if;
4767 
4768                             if xst = false AND l_no_of_records <> 0 then
4769                                 WSMPLCVA.v_user(v_wsli(v_wlji_source_line_id(v_index)).created_by)
4770                                             := v_wsli(v_wlji_source_line_id(v_index)).created_by;
4771                             end if;
4772 
4773                             if l_error_code <> 0 then
4774                                 l_error_count := l_error_count + 1;
4775                                 GOTO skip_other_steps;
4776                             end if;
4777                             l_aux_mesg := '';
4778                             l_no_of_records := 0;
4779                             xst := true;
4780                             -- *** created_by ***
4781 
4782 
4783 l_stmt_num := 603;
4784                             begin
4785 
4786                                 select 1 into l_dummy
4787                                 from   mtl_transaction_lots_temp
4788                                 where  lot_number = v_wsli(v_wlji_source_line_id(v_index)).lot_number
4789                                 and    rownum = 1;
4790 
4791                                 if l_dummy <>0 then
4792                                     SELECT 0 into l_dummy
4793                                     FROM   mtl_material_transactions_temp mmtt
4794                                     WHERE  mmtt.organization_id = v_wsli(v_wlji_source_line_id(v_index)).organization_id
4795                                     and    mmtt.inventory_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
4796                                     and    NVL(mmtt.lot_number, '@#$') = v_wsli(v_wlji_source_line_id(v_index)).lot_number
4797                                     and    mmtt.subinventory_code = v_wsli(v_wlji_source_line_id(v_index)).subinventory_code
4798                                     and    NVL(mmtt.locator_id, -9999) = NVL(v_wsli(v_wlji_source_line_id(v_index)).locator_id, -9999)
4799                                     and    mmtt.transaction_type_id = 42 -- Miscellaneous Receipt
4800                                     and    mmtt.transaction_action_id = 27 -- Receipt into stores
4801                                     and    mmtt.transaction_source_type_id = 13 -- Inventory
4802                                     and    v_wsli(v_wlji_source_line_id(v_index)).quantity = ((-1) * mmtt.transaction_quantity)
4803                                     and    mmtt.transaction_date = (
4804                                             SELECT max(mmtt2.transaction_date)
4805                                             FROM mtl_material_transactions_temp mmtt2
4806                                             WHERE mmtt2.organization_id = v_wsli(v_wlji_source_line_id(v_index)).organization_id
4807                                             and mmtt2.inventory_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
4808                                             and NVL(mmtt2.lot_number, '@#$') = NVL(v_wsli(v_wlji_source_line_id(v_index)).lot_number, '@#$')
4809                                             and mmtt2.subinventory_code = v_wsli(v_wlji_source_line_id(v_index)).subinventory_code
4810                                             and NVL(mmtt2.locator_id, -9999) = NVL(v_wsli(v_wlji_source_line_id(v_index)).locator_id, -9999)
4811                                         );
4812                                 end if;
4813                                 If l_dummy <> 0 then
4814                                     fnd_message.set_name('WSM', 'WSM_PENDING_TXN');
4815                                     FND_MESSAGE.SET_TOKEN('TABLE',
4816                                        'Starting Lot:'||v_wsli(v_wlji_source_line_id(v_index)).lot_number
4817                                        ||'Table: mtl_transaction_lots_temp ');
4818                                     l_err_msg := fnd_message.get;
4819                                     l_error_code := -1;
4820                                     HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
4821                                 END IF;
4822 
4823                             exception
4824                                 When NO_DATA_FOUND Then
4825                                     Null;
4826                             end;
4827 
4828                             if l_error_code <> 0 then
4829                                 l_error_count := l_error_count + 1;
4830                                 GOTO skip_other_steps;
4831                             end if;
4832                             l_err_msg := '';
4833                             l_dummy := 0;
4834 
4835 
4836 l_stmt_num := 604;
4837                             -- check that the item in the inventory lot exists as a component of the
4838                             -- assembly item for the given alt bom designator, attached at the first operation.
4839 
4840                             wsmputil.find_common_routing(
4841                                             p_routing_sequence_id => routing_seq_id,
4842                                             p_common_routing_sequence_id => p_common_routing_sequence_id,
4843                                             x_err_code => l_error_code,
4844                                             x_err_msg => l_err_msg);
4845 
4846                             if l_error_code <> 0 OR l_err_msg IS NOT NULL then
4847                                 HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
4848                                 l_error_code := -1;
4849                             end if;
4850 
4851 
4852 l_stmt_num := 604.1;
4853                             -- BA: CZH.I_OED-1
4854                             -- This is for Mode 2 job creation. Hence, v_wlji_routing_revision_date(v_index)
4855                             -- should have been populated
4856                             l_rtg_rev_date := v_wlji_routing_revision_date(v_index);
4857                             l_bom_rev_date := v_wlji_bom_revision_date(v_index); --BUGFIX 2380517
4858                             -- EA: CZH.I_OED-1
4859 
4860                             wsmputil.find_routing_start(
4861                                             p_common_routing_sequence_id,
4862                                             l_rtg_rev_date,              -- ADD: CZH.I_OED-1
4863                                             l_start_op_seq_id,
4864                                             l_error_code,
4865                                             l_err_msg );
4866 
4867                             if l_error_code <> 0 OR l_err_msg IS NOT NULL then
4868                                 HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
4869                                 l_error_code := -1;
4870                             end if;
4871 
4872                             --BA: CZH.I_OED-2
4873                             l_start_op_seq_id := wsmputil.replacement_op_seq_id(
4874                                                             l_start_op_seq_id,
4875                                                             l_rtg_rev_date);
4876                             --EA: CZH.I_OED-2
4877 
4878                             if l_error_code = 0 then
4879                                 begin
4880                                     SELECT  1
4881                                     INTO    l_dummy
4882                                     FROM    BOM_INVENTORY_COMPONENTS BIC,
4883                                             MTL_SYSTEM_ITEMS C
4884                                     WHERE   BIC.COMPONENT_ITEM_ID = C.INVENTORY_ITEM_ID
4885                                     AND     C.ORGANIZATION_ID = v_wlji_org(v_index)
4886                                     AND     BIC.BILL_SEQUENCE_ID = bom_seq_id
4887                                     AND     BIC.COMPONENT_ITEM_ID = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
4888                                     AND     (BIC.operation_seq_num = (SELECT BOS.operation_seq_num
4889                                                                       FROM   BOM_OPERATION_SEQUENCES BOS
4890                                                                       WHERE  operation_sequence_id = l_start_op_seq_id )
4891                                              OR
4892                                              BIC.operation_seq_num = 1)
4893                                     -- BC: BUGFIX 2380517 (CZH.I_OED-2)
4894                                     --AND   EFFECTIVITY_DATE <= SYSDATE
4895                                     --AND   nvl(DISABLE_DATE, SYSDATE + 1) > SYSDATE
4896                                     AND     l_bom_rev_date between BIC.EFFECTIVITY_DATE
4897                                                            and     nvl(BIC.DISABLE_DATE, l_bom_rev_date + 1)
4898                                     -- EC: BUGFIX 2380517
4899                                     AND     EFFECTIVITY_DATE =(
4900                                                 SELECT  MAX (EFFECTIVITY_DATE)
4901                                                 FROM    BOM_INVENTORY_COMPONENTS BIC2,
4902                                                         ENG_REVISED_ITEMS        ERI
4903                                                 WHERE   BIC2.BILL_SEQUENCE_ID = BIC.BILL_SEQUENCE_ID
4904                                                 AND     BIC2.COMPONENT_ITEM_ID = BIC.COMPONENT_ITEM_ID
4905                                                 AND     (decode(BIC2.IMPLEMENTATION_DATE,
4906                                                                 NULL, BIC2.OLD_COMPONENT_SEQUENCE_ID,
4907                                                                 BIC2.COMPONENT_SEQUENCE_ID) =
4908                                                          decode(BIC.IMPLEMENTATION_DATE,
4909                                                                 NULL, BIC.OLD_COMPONENT_SEQUENCE_ID,
4910                                                                 BIC.COMPONENT_SEQUENCE_ID)
4911                                                          OR BIC2.OPERATION_SEQ_NUM = BIC.OPERATION_SEQ_NUM)
4912                                                 --AND   BIC2.EFFECTIVITY_DATE <= SYSDATE       --BUGFIX 2380517
4913                                                 AND     BIC2.EFFECTIVITY_DATE <= l_bom_rev_date  --BUGFIX 2380517
4914                                                 AND     BIC2.REVISED_ITEM_SEQUENCE_ID =
4915                                                         ERI.REVISED_ITEM_SEQUENCE_ID(+)
4916                                                 AND     ( NVL(ERI.STATUS_TYPE,6) IN (4,6,7))
4917                                                 AND     NOT EXISTS (
4918                                                             SELECT 'X'
4919                                                             FROM   BOM_INVENTORY_COMPONENTS BICN,
4920                                                                    ENG_REVISED_ITEMS ERI1
4921                                                             WHERE  BICN.BILL_SEQUENCE_ID = BIC.BILL_SEQUENCE_ID
4922                                                             AND    BICN.OLD_COMPONENT_SEQUENCE_ID =
4923                                                                    BIC.COMPONENT_SEQUENCE_ID
4924                                                             AND    BICN.ACD_TYPE in (2,3)
4925                                                             --AND  BICN.DISABLE_DATE <= SYSDATE       --BUGFIX 2380517
4926                                                             AND    BICN.DISABLE_DATE <= l_bom_rev_date  --BUGFIX 2380517
4927                                                             AND    ERI1.REVISED_ITEM_SEQUENCE_ID = BICN.REVISED_ITEM_SEQUENCE_ID
4928                                                             AND    ( nvl(ERI1.STATUS_TYPE,6) IN (4,6,7) )
4929                                                         )
4930                                             );
4931                                 exception
4932                                     -- BA: BUGFIX 2380517
4933                                     when no_data_found then
4934                                         l_error_code := -1;
4935                                         fnd_message.set_name('WSM','WSM_INVALID_BOM_ROUT');
4936                                         l_err_msg := fnd_message.get;
4937                                         handle_error(l_error_code, l_err_msg, l_stmt_num);
4938                                     --EA: BUGFIX 2380517
4939 
4940                                     when others then
4941                                         l_error_code := SQLCODE;
4942                                         l_err_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
4943                                         handle_error(l_error_code, l_err_msg, l_stmt_num);
4944                                 end;
4945                             end if;
4946 
4947                             if l_error_code <> 0 then
4948                                 l_error_count := l_error_count + 1;
4949                                 GOTO skip_other_steps;
4950                             end if;
4951                             l_dummy := 0;
4952                             l_err_msg := '';
4953 
4954                             if lbji_debug = 'Y' then
4955                                 fnd_file.put_line(fnd_file.log, 'Verify that the component is reqd. at the first operation of the assembly.. Success');
4956                             end if;
4957 
4958 l_stmt_num := 640;
4959                             -- abbKanban begin
4960                             if v_wlji_kanban_card_id(v_index) is not null then
4961                                 if honor_kanban_size(v_wlji_org(v_index),
4962                                                      v_wlji_item(v_index),
4963                                                      v_wlji_completion_subinventory(v_index),
4964                                                      v_wlji_completion_locator_id(v_index),
4965                                                      -1) = 1 then
4966                                     select kanban_size
4967                                     into   l_kanban_size
4968                                     from   mtl_kanban_cards
4969                                     where  kanban_card_id = v_wlji_kanban_card_id(v_index);
4970 
4971                                     if v_wlji_start_quantity(v_index) > l_kanban_size then
4972                                         v_wlji_start_quantity(v_index) := l_kanban_size;
4973                                         v_wlji_net_quantity(v_index) := v_wlji_start_quantity(v_index);
4974                                     end if;
4975                                 end if;
4976                             end if;
4977                             -- abbKanban end
4978 
4979                             -- *** begin validate quantity ***
4980 l_stmt_num := 645;
4981                             -- BC: bug 3852078  do not use wsm_components_v
4982                             /*****
4983                             SELECT  component_quantity, component_yield_factor
4984                             INTO    l_component_quantity, l_component_yield_factor
4985                             FROM    wsm_components_v
4986                             WHERE   assembly_item_id = v_wlji_item(v_index)
4987                             AND     component_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
4988                             AND     nvl(alternate_bom_designator,'NULL') = nvl(v_wlji_alt_bom_designator(v_index),'NULL')
4989                             AND     organization_id = v_wlji_org(v_index);
4990                             *****/
4991 
4992                             SELECT  bic.component_quantity,
4993                                     decode(bic.component_yield_factor, 0, 1,
4994                                            bic.component_yield_factor) component_yield_factor,
4995                                     bic.basis_type             -- LBM enh
4996                             INTO    l_component_quantity,
4997                                     l_component_yield_factor,
4998                                     l_comp_basis_type           -- LBM enh
4999                             from    mtl_System_items msi,
5000                                     bom_inventory_components bic,
5001                                     bom_bill_of_materials bom,
5002                                     bom_bill_of_materials bom2
5003                             WHERE   bic.bill_sequence_id = bom2.bill_sequence_id
5004                             and     bom.common_bill_sequence_id = bom2.bill_sequence_id
5005                             and     msi.organization_id = bom.organization_id
5006                             and     msi.inventory_item_id = bom.assembly_item_id
5007                             and     msi.build_in_wip_flag = 'Y'
5008                             and     msi.pick_components_flag = 'N'
5009                             and     bic.implementation_date is not null
5010                             and     bom.assembly_item_id = v_wlji_item(v_index)
5011                             and     bic.component_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
5012                             and     bom.organization_id = v_wlji_org(v_index)
5013                             and     nvl(bom.alternate_bom_designator,'NULL') = nvl(v_wlji_alt_bom_designator(v_index),'NULL')
5014                             and     l_bom_rev_date between bic.effectivity_date
5015                                                    and     nvl(bic.disable_date, l_bom_rev_date + 1);
5016                             -- EC: bug 3852078
5017 
5018                             -- quantity of component required per assembly
5019                            --3913296:Rounding of required qty is removed and to be issued is rounded
5020                             --l_required_quantity := round((l_component_quantity / l_component_yield_factor), 6);
5021                             l_required_quantity := l_component_quantity / l_component_yield_factor;
5022                             -- LBM enh
5023                             if nvl(l_comp_basis_type, 1) = 2 then  --lot based
5024                                 l_quantity_tobe_issued := round(l_required_quantity, 6);
5025                             else   -- item based
5026                                 l_quantity_tobe_issued := round(l_required_quantity * v_wlji_start_quantity(v_index),6);
5027                             end if;
5028                             -- end LBM enh
5029 
5030 l_stmt_num := 646;
5031                             if v_wsli(v_wlji_source_line_id(v_index)).comp_issue_quantity is not null then
5032                                 if v_wsli(v_wlji_source_line_id(v_index)).comp_issue_quantity <= 0 then
5033                                     l_error_code := -1;
5034                                     process_errorred_field('WSM',
5035                                                            'WSM_QTY_ISSUE_NO_NEG',
5036                                                            l_stmt_num);
5037                                 else
5038                                     l_quantity_tobe_issued := v_wsli(v_wlji_source_line_id(v_index)).comp_issue_quantity;
5039                                 end if;
5040                             end if;
5041 l_stmt_num := 648;
5042                             -- if the user does not provide a revision in wsm_starting_lots_interface
5043                             -- then get the current revision and use that to issue components. if user
5044                             -- provides one, validate it
5045 
5046                             l_source_item_rev := v_wsli(v_wlji_source_line_id(v_index)).revision;
5047                             declare
5048                                 err_lot_revision    exception;  -- Add: bug 2963225
5049                             begin
5050                                 -- BC: bug 2963225 this is to validate the revision of the item
5051                                 -- which is not right, instead, we should validate / default
5052                                 -- the revision of the starting lot, so comment out the following
5053 
5054                                 --l_rev_sysdate := sysdate;
5055                                 --wip_revisions.bom_revision (
5056                                 --       v_wlji_org(v_index),
5057                                 --       v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id,
5058                                 --       l_source_item_rev,
5059                                 --       l_source_item_rev_date,
5060                                 --       l_rev_sysdate);
5061 
5062                                 if l_rev_control_code = 1 then -- not revision control
5063                                     if(l_source_item_rev is not null) then
5064                                         raise err_lot_revision;
5065                                     end if;
5066                                 else    -- revision control item
5067                                     select  revision
5068                                     into    l_start_lot_revision
5069                                     from    WSM_source_lots_v
5070                                     where   lot_number = v_wsli(v_wlji_source_line_id(v_index)).lot_number
5071                                     and     organization_id = v_wlji_org(v_index)
5072                                     and     inventory_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id;
5073 
5074                                     if(l_source_item_rev is null) then
5075                                         v_wsli(v_wlji_source_line_id(v_index)).revision := l_start_lot_revision;
5076                                     elsif(l_source_item_rev <> l_start_lot_revision) then
5077                                         raise err_lot_revision;
5078                                     end if;
5079                                 end if;
5080                                 -- EC: bug 2963225
5081 
5082                             exception
5083                                 when err_lot_revision then  -- Add: bug 2963225
5084                                     l_error_code := -1;
5085                                     l_error_count := l_error_count +1;
5086                                     process_invalid_field('Component Lot Revision', '', l_stmt_num);
5087                                     GOTO skip_other_steps;
5088 
5089                                 when others then
5090                                     l_error_code := -1;
5091                                     l_error_count := l_error_count +1;
5092                                     process_invalid_field('Component Lot Revision', '', l_stmt_num);
5093                                     GOTO skip_other_steps;
5094                             end;
5095 
5096 l_stmt_num := 650;
5097                             wsmputil.return_att_quantity(p_org_id => v_wlji_org(v_index),
5098                                  p_item_id => v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id,
5099                                  p_rev => v_wsli(v_wlji_source_line_id(v_index)).revision,
5100                                  p_lot_no => v_wsli(v_wlji_source_line_id(v_index)).lot_number,
5101                                  p_subinv => v_wsli(v_wlji_source_line_id(v_index)).subinventory_code,
5102                                  p_locator_id => v_wsli(v_wlji_source_line_id(v_index)).locator_id,
5103                                  p_qoh => l_qoh,
5104                                  p_atr => l_atr,
5105                                  p_att => l_att,
5106                                  p_err_code => l_error_code,
5107                                  p_err_msg => l_err_msg );
5108 
5109                             if l_error_code <> 0 then
5110                                 HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
5111                                 l_error_count := l_error_count + 1;
5112                                 GOTO skip_other_steps;
5113                             end if;
5114 
5115                             if l_quantity_tobe_issued > l_att then
5116                                 -- bug 3741740 remove this validation because we allow issue
5117                                 -- less quantity than job required quantity through form
5118                                 -- we will issue all the quantity if qty_tobe_issued > l_att
5119                                 l_quantity_tobe_issued := l_att;
5120                                 --l_error_code := -1;
5121                                 --process_errorred_field('WSM',
5122                                 --                       'WSM_INSUFFICIENT_QTY',
5123                                 --                       l_stmt_num);
5124                             end if;
5125 
5126 
5127                             if l_error_code <> 0 then
5128                                     l_error_count := l_error_count + 1;
5129                                     GOTO skip_other_steps;
5130                             end if;
5131 
5132                             if lbji_debug = 'Y' then
5133                                 fnd_file.put_line(fnd_file.log, 'Mode 2 Quantity Verification.. Success');
5134                             end if;
5135                             -- *** end validate quantity ***
5136 
5137 
5138 l_stmt_num := 661;
5139                             -- *** validate starting lot is not phantom begin ***
5140                             begin
5141                                 SELECT  1
5142                                 INTO    l_dummy
5143                                 FROM    BOM_INVENTORY_COMPONENTS BIC,
5144                                         MTL_SYSTEM_ITEMS         C
5145                                 WHERE   BIC.COMPONENT_ITEM_ID = C.INVENTORY_ITEM_ID
5146                                 AND     C.ORGANIZATION_ID = v_wlji_org(v_index)
5147                                 AND     BIC.BILL_SEQUENCE_ID = bom_seq_id
5148                                 AND     BIC.COMPONENT_ITEM_ID = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
5149                                 AND     (BIC.operation_seq_num = (SELECT  BOS.operation_seq_num
5150                                                                   FROM    BOM_OPERATION_SEQUENCES BOS
5151                                                                   WHERE   operation_sequence_id = l_start_op_seq_id)
5152                                          OR BIC.operation_seq_num = 1 )
5153                                 AND     NVL(BIC.wip_supply_type, 1) <> 6  -- CHG: BUG 2696937/2652076
5154 
5155                                 -- BC: BUGFIX 2380517 (CZH.I_OED-2)
5156                                 --AND   EFFECTIVITY_DATE <= SYSDATE
5157                                 --AND   nvl(DISABLE_DATE, SYSDATE + 1) > SYSDATE
5158                                 AND     l_bom_rev_date between BIC.EFFECTIVITY_DATE
5159                                                        and     nvl(BIC.DISABLE_DATE, l_bom_rev_date + 1)
5160                                 -- EC: BUGFIX 2380517
5161                                 AND     EFFECTIVITY_DATE = (
5162                                             SELECT MAX(EFFECTIVITY_DATE)
5163                                             FROM   BOM_INVENTORY_COMPONENTS BIC2,
5164                                                    ENG_REVISED_ITEMS        ERI
5165                                             WHERE  BIC2.BILL_SEQUENCE_ID = BIC.BILL_SEQUENCE_ID
5166                                             AND    BIC2.COMPONENT_ITEM_ID = BIC.COMPONENT_ITEM_ID
5167                                             AND    (decode(BIC2.IMPLEMENTATION_DATE,
5168                                                            NULL, BIC2.OLD_COMPONENT_SEQUENCE_ID,
5169                                                            BIC2.COMPONENT_SEQUENCE_ID) =
5170                                                     decode(BIC.IMPLEMENTATION_DATE,
5171                                                            NULL, BIC.OLD_COMPONENT_SEQUENCE_ID,
5172                                                            BIC.COMPONENT_SEQUENCE_ID)
5173                                                     OR BIC2.OPERATION_SEQ_NUM = BIC.OPERATION_SEQ_NUM)
5174                                             --AND  BIC2.EFFECTIVITY_DATE <= SYSDATE      --BUGFIX 2380517
5175                                             AND    BIC2.EFFECTIVITY_DATE <= l_bom_rev_date --BUGFIX 2380517
5176                                             AND    BIC2.REVISED_ITEM_SEQUENCE_ID = ERI.REVISED_ITEM_SEQUENCE_ID(+)
5177                                             AND    (NVL(ERI.STATUS_TYPE,6) IN (4,6,7))
5178                                             AND    NOT EXISTS (
5179                                                        SELECT  'X'
5180                                                        FROM    BOM_INVENTORY_COMPONENTS BICN,
5181                                                                ENG_REVISED_ITEMS ERI1
5182                                                        WHERE   BICN.BILL_SEQUENCE_ID = BIC.BILL_SEQUENCE_ID
5183                                                        AND     BICN.OLD_COMPONENT_SEQUENCE_ID = BIC.COMPONENT_SEQUENCE_ID
5184                                                        AND     BICN.ACD_TYPE in (2,3)
5185                                                        --AND   BICN.DISABLE_DATE <= SYSDATE        --BUGFIX 2380517
5186                                                        AND     BICN.DISABLE_DATE <= l_bom_rev_date --BUGFIX 2380517
5187                                                        AND     ERI1.REVISED_ITEM_SEQUENCE_ID = BICN.REVISED_ITEM_SEQUENCE_ID
5188                                                        AND     ( NVL(ERI1.STATUS_TYPE,6) IN (4,6,7) )
5189                                                    )
5190                                         );
5191                             exception
5192                                 -- BA: BUGFIX 2380517
5193                                 when no_data_found then
5194                                     l_error_code := -1;
5195                                     fnd_message.set_name('WSM','WSM_INVALID_BOM_ROUT');
5196                                     l_err_msg := fnd_message.get;
5197                                     handle_error(l_error_code, l_err_msg, l_stmt_num);
5198                                 --EA: BUGFIX 2380517
5199                                 when others then
5200                                     l_error_code := -1;
5201                                     process_errorred_field('WSM',
5202                                                            'WSM_PHANTOM_COMP_NOT_ALLOWED',
5203                                                            l_stmt_num);
5204                             end;
5205 
5206                             if l_error_code <> 0 then
5207                                     l_error_count := l_error_count + 1;
5208                                     GOTO skip_other_steps;
5209                             end if;
5210                             l_dummy := 0;
5211                             l_err_msg := '';
5212 
5213                             if lbji_debug = 'Y' then
5214                             fnd_file.put_line(fnd_file.log, 'Verify that the starting lot is not phantom.. Success');
5215                             end if;
5216                             -- *** validate starting lot is not phantom end ***
5217 
5218                         end if; -- mode flag 2
5219                        -- *** end of mode flag 2 validations ***
5220 
5221                     end if; -- load type 5
5222 
5223 
5224                     -- *** check for disabled ops in the network and provide warning ***
5225                     if v_wlji_load_type(v_index) = 5 then
5226                         wsmputil.find_common_routing(
5227                                     p_routing_sequence_id => routing_seq_id,
5228                                     p_common_routing_sequence_id => p_common_routing_sequence_id,
5229                                     x_err_code => l_error_code,
5230                                     x_err_msg => l_err_msg);
5231 
5232 
5233                         if (wsmputil.network_with_disabled_op(
5234                                               p_common_routing_sequence_id,
5235                                               v_wlji_routing_revision_date(v_index),
5236                                               l_error_code,
5237                                               l_err_msg) = 1)
5238                         then
5239                             fnd_message.set_name('WSM','WSM_NET_HAS_DISABLED_OP');
5240                             l_err_msg := fnd_message.get;
5241                             l_warning_count := l_warning_count + 1;
5242                             handle_warning(p_err_msg => l_err_msg,
5243                                            p_header_id => v_wlji_header_id(v_index),
5244                                            p_request_id => v_wlji_request_id(v_index),
5245                                            p_program_id => v_wlji_program_id(v_index),
5246                                            p_program_application_id => v_wlji_program_application_id(v_index));
5247 
5248                         end if;
5249 
5250                     end if; -- load type 5
5251 
5252 
5253                     -- bugfix 2697295 begin
5254 l_stmt_num := 669;
5255                     if v_wlji_load_type(v_index) = 5 then
5256                         if (v_wlji_status_type(v_index) = WIP_CONSTANTS.UNRELEASED) and (v_wlji_date_released(v_index) is not null ) then
5257 
5258                             v_wlji_date_released(v_index) := null;
5259 
5260                             if lbji_debug = 'Y' then
5261                                 fnd_file.put_line(fnd_file.log, 'value for column DATE_RELEASED is being ignored for unreleased job');
5262                             end if;
5263                         elsif (v_wlji_status_type(v_index) = WIP_CONSTANTS.RELEASED ) then
5264                             if (v_wlji_date_released(v_index) > sysdate ) then
5265 
5266                                 l_error_code := -1;
5267                                 process_errorred_field('WIP',
5268                                                        'WIP_INVALID_RELEASE_DATE',
5269                                                        l_stmt_num);
5270 
5271                             elsif (v_wlji_date_released(v_index) is null) then
5272 
5273                                 v_wlji_date_released(v_index) := sysdate;
5274 
5275                             end if;
5276                         end if;
5277 
5278                         if l_error_code <> 0 then
5279                             l_error_count := l_error_count + 1;
5280                             GOTO skip_other_steps;
5281                         end if;
5282 
5283                         l_err_msg := '';
5284 
5285                         if lbji_debug = 'Y' then
5286                             fnd_file.put_line(fnd_file.log, 'Date_Released Validation.. First Phase Done.');
5287                         end if;
5288 
5289                     end if; -- load type 5
5290                     -- bugfix 2697295 ends
5291 
5292 
5293 l_stmt_num := 670;
5294 
5295                     if v_wlji_job_type(v_index) <> 3 then -- job type for schedule group and build sequence
5296 
5297                         -- *** validate schedule_group_id begin ***
5298                         if (v_wlji_load_type(v_index) = 6 and v_wlji_schedule_group_id(v_index) is NULL) then
5299                             select schedule_group_id
5300                             into   v_wlji_schedule_group_id(v_index)
5301                             from   wip_discrete_jobs
5302                             where  wip_entity_id = v_wlji_wip_entity_id(v_index)
5303                             and    organization_id = v_wlji_org(v_index);
5304                         end if;
5305 
5306                         if (v_wlji_source_code(v_index) = 'WICDOL' and v_wlji_schedule_group_name(v_index) IS NULL
5307                             and v_wlji_schedule_group_id(v_index) IS NULL) then
5308                             insert into wip_schedule_groups (
5309                                     schedule_group_id,
5310                                     schedule_group_name,
5311                                     organization_id,
5312                                     description,
5313                                     created_by,
5314                                     last_updated_by,
5315                                     creation_date,
5316                                     last_update_date)
5317                             select  wip_schedule_groups_s.nextval,
5318                                     wds.name,
5319                                     v_wlji_org(v_index),
5320                                     to_char(sysdate),
5321                                     l_user,
5322                                     l_user,
5323                                     sysdate,
5324                                     sysdate
5325                             from    wsh_new_deliveries wds
5326                             where   wds.delivery_id = v_wlji_delivery_id(v_index)
5327                                     and not exists  (
5328                                             select  1
5329                                             from    wip_schedule_groups wsg
5330                                             where   wsg.organization_id = v_wlji_org(v_index)
5331                                                     and WSG.schedule_group_name = WDS.name);
5332 
5333                             select wsg.schedule_group_name, wsg.schedule_group_id
5334                             into   v_wlji_schedule_group_name(v_index), v_wlji_schedule_group_id(v_index)
5335                             from   wip_schedule_groups wsg,
5336                                    wsh_new_deliveries wds
5337                             where  wds.delivery_id = v_wlji_delivery_id(v_index)
5338                                and wsg.schedule_group_name = wds.name
5339                                and wsg.organization_id = v_wlji_org(v_index);
5340                         end if;
5341 
5342                         if ((v_wlji_schedule_group_id(v_index) is not NULL) and (v_wlji_load_type(v_index) in (5,6))) then
5343                             begin
5344                                 select 1 into l_dummy
5345                                 from   wip_schedule_groups_val_v wsg
5346                                 where  wsg.schedule_group_id = v_wlji_schedule_group_id(v_index)
5347                                 and    wsg.organization_id = v_wlji_org(v_index);
5348                             exception
5349                                 when too_many_rows then
5350                                     l_dummy := 1;
5351                             end;
5352 
5353                             if l_dummy = 0 then
5354                                 l_error_code := -1;
5355                                 process_errorred_field('WIP',
5356                                                        'WIP_ML_SCHEDULE_GROUP',
5357                                                        l_stmt_num);
5358                             end if;
5359                         end if;
5360 
5361 
5362                         if l_error_code <> 0 then
5363                             l_error_count := l_error_count + 1;
5364                             GOTO skip_other_steps;
5365                         end if;
5366                         l_dummy := 0;
5367 
5368                         if lbji_debug = 'Y' then
5369                             fnd_file.put_line(fnd_file.log, 'Schedule Group Id Verification.. Success');
5370                         end if;
5371                         -- *** validate schedule_group_id end ***
5372 
5373 
5374 l_stmt_num := 690;
5375                         -- *** validate build_seq_id begin ***
5376                         begin
5377                             select
5378                                 nvl(v_wlji_build_sequence(v_index), WDJ.build_sequence),
5379                                 nvl(v_wlji_line_id(v_index), WDJ.line_id),
5380                                 nvl(v_wlji_schedule_group_id(v_index), WDJ.schedule_group_id)
5381                             into
5382                                 l_build_sequence,
5383                                 l_line_id,
5384                                 l_schedule_group_id
5385                             from
5386                                 wip_discrete_jobs WDJ
5387                             where
5388                                 WDJ.wip_entity_id = v_wlji_wip_entity_id(v_index);
5389                         exception
5390                             when no_data_found then null;
5391                             when too_many_rows then null;
5392                         end;
5393 
5394                         -- Added by BBK. Only if l_build_sequence is not null, we want to execute
5395                         -- this WIP_VALIDATE function. Otherwise, DO NOT.
5396                         if l_build_sequence is not null and l_build_sequence <> 0 Then
5397                             aReturnBoolean := WIP_Validate.build_sequence (
5398                                     p_build_sequence => l_build_sequence,
5399                                     p_wip_entity_id => v_wlji_wip_entity_id(v_index),
5400                                     p_organization_id => v_wlji_org(v_index),
5401                                     p_line_id => l_line_id,
5402                                     p_schedule_group_id => l_schedule_group_id
5403                                     );
5404 
5405                             if NOT aReturnBoolean Then
5406                                 l_error_code := -1;
5407                                 process_errorred_field('WIP',
5408                                                        'WIP_ML_BUILD_SEQUENCE',
5409                                                        l_stmt_num);
5410                             end if;
5411                         end if;
5412                         -- End of mod by BBK.
5413 
5414                         if l_error_code <> 0 then
5415                             l_error_count := l_error_count + 1;
5416                             GOTO skip_other_steps;
5417                         end if;
5418 
5419                         if lbji_debug = 'Y' then
5420                             fnd_file.put_line(fnd_file.log, 'Build Seq. Id Verification.. Success');
5421                         end if;
5422 
5423                     end if; -- job type <> 3 for schedule group and build sequence.
5424                     -- *** validate build_seq_id end ***
5425 
5426 
5427 --************************************************************************************************
5428 --**************************** Reschedule Job Validations Begin **********************************
5429 --************************************************************************************************
5430                     if v_wlji_load_type(v_index) = 6 then
5431 l_stmt_num := 700;
5432                         select  primary_item_id,
5433                                 class_code,
5434                                 scheduled_start_date,
5435                                 scheduled_completion_date,
5436                                 start_quantity,
5437                                 net_quantity,
5438                                 status_type,
5439                                 firm_planned_flag,
5440                                 job_type,
5441                                 bom_reference_id,
5442                                 alternate_bom_designator,
5443                                 routing_reference_id,
5444                                 alternate_routing_designator,
5445                                 bom_revision_date,
5446                                 routing_revision_date,
5447                                 bom_revision,
5448                                 routing_revision,
5449                                 common_routing_sequence_id,
5450                                 common_bom_sequence_id,
5451                                 wip_supply_type,
5452                                 scheduled_start_date,
5453                                 scheduled_completion_date,
5454                                 coproducts_supply,
5455                                 kanban_card_id,
5456                                 completion_subinventory, -- bug 2762029
5457                                 completion_locator_id, -- bug 2762029
5458                                 date_released
5459                         into    p_old_primary_item_id,
5460                                 p_old_class_code,
5461                                 p_old_start_date,
5462                                 p_old_complete_date,
5463                                 p_old_quantity,
5464                                 p_old_net_quantity,
5465                                 p_old_status_type,
5466                                 p_old_firm_planned_flag,
5467                                 p_old_job_type,
5468                                 p_old_bom_reference_id,
5469                                 p_old_alt_bom_designator,
5470                                 p_old_routing_reference_id,
5471                                 p_old_alt_routing_designator,
5472                                 p_old_bom_revision_date,
5473                                 p_old_routing_revision_date,
5474                                 p_old_bom_revision,  -- bug 2762029
5475                                 p_old_routing_revision, -- bug 2762029
5476                                 p_old_com_rtg_seq_id,
5477                                 p_old_com_bom_seq_id,
5478                                 p_old_supply_type,
5479                                 p_scheduled_start_date,
5480                                 p_scheduled_completion_date,
5481                                 p_coproducts_supply,
5482                                 v_wlji_kanban_card_id(v_index),
5483                                 p_old_completion_subinv,
5484                                 p_old_completion_locator,
5485                                 p_old_date_released
5486                         from    wip_discrete_jobs
5487                         where   wip_entity_id = v_wlji_wip_entity_id(v_index)
5488                         and     organization_id = v_wlji_org(v_index);
5489 
5490                         /* *** Bug 2762029 commenting begins
5491                         -- for update of a standard job, if the user populates any of the following fields,
5492                         -- they are ignored
5493                         if p_old_job_type = 1 then
5494 
5495                                 if
5496                                 (v_wlji_routing_reference_id(v_index) is not null) or
5497                                 (v_wlji_bom_reference_id(v_index) is not null) or
5498                                 (v_wlji_routing_revision_date(v_index) is not null) or
5499                                 (v_wlji_routing_revision(v_index) is not null) or
5500                                 (v_wlji_bom_revision_date(v_index) is not null) or
5501                                 (v_wlji_bom_revision(v_index) is not null) or
5502                                 (v_wlji_alt_bom_designator(v_index) is not null) or
5503                                 (v_wlji_alt_routing_designator(v_index) is not null) then
5504 
5505                                         v_wlji_routing_reference_id(v_index) := null;
5506                                         v_wlji_bom_reference_id(v_index) := null;
5507                                         v_wlji_routing_revision_date(v_index) := null;
5508                                         v_wlji_routing_revision(v_index) := null;
5509                                         v_wlji_bom_revision_date(v_index) := null;
5510                                         v_wlji_bom_revision(v_index) := null;
5511                                         v_wlji_alt_bom_designator(v_index) := null;
5512                                         v_wlji_alt_routing_designator(v_index) := null;
5513 
5514                                         fnd_file.put_line(fnd_file.log, 'Ignoring any of the following fields if provided by the user for this standard job:');
5515                         --              fnd_file.new_line(fnd_file.log, 1);
5516                                         fnd_file.put_line(fnd_file.log, 'ROUTING_REFERENCE_ID, BOM_REFERENCE_ID, ROUTING_REVISION_DATE, ROUTING_REVISION, BOM_REVISION_DATE, BOM_REVISION, ALTERNATE_BOM_DESIGNATOR, ALTERNATE_ROUTING_DESIGNATOR');
5517                                 end if;
5518 
5519                         end if; -- job type 1
5520                         */ -- Bug 2762029 commenting ends
5521 
5522 
5523                         -- Bug 2762029 begins
5524                         -- initializing some variables.
5525                         p_common_bill_sequence_id    := p_old_com_bom_seq_id;
5526                         p_common_routing_sequence_id := p_old_com_rtg_seq_id;
5527 
5528 -- =============================================================================================
5529 -- UPDATE OF ALTERNATES BEGIN
5530 -- =============================================================================================
5531                         Begin
5532                             p_change_bom_alt := 0;
5533                             p_change_routing_alt := 0;
5534                             p_change_alt_flag := 0;
5535 
5536                             -- if the user wants to update an alternate to NULL value, s/he should populate '-99' in the interface.
5537 l_stmt_num := 700.1;
5538                             if p_old_job_type = 1 then
5539 
5540                                 if v_wlji_alt_bom_designator(v_index) is NOT NULL AND
5541                                  ((p_old_alt_bom_designator is NULL AND v_wlji_alt_bom_designator(v_index) <> '-99') OR
5542                                   (p_old_alt_bom_designator is NOT NULL AND
5543                                    v_wlji_alt_bom_designator(v_index) <> p_old_alt_bom_designator)
5544                                  ) THEN
5545                                     p_change_bom_alt := 1;
5546                                 end if;
5547 
5548                                 if v_wlji_alt_routing_designator(v_index) is NOT NULL AND
5549                                  ((p_old_alt_routing_designator is NULL AND v_wlji_alt_routing_designator(v_index) <> '-99') OR
5550                                   (p_old_alt_routing_designator is NOT NULL AND
5551                                    v_wlji_alt_routing_designator(v_index) <> p_old_alt_routing_designator)
5552                                  ) THEN
5553                                     p_change_routing_alt := 1;
5554                                 end if;
5555 
5556                                 -- change bom/routing alternate
5557                                 if (p_change_bom_alt = 1 OR p_change_routing_alt = 1) and p_old_status_type = 1 then
5558                                     p_change_alt_flag := 1; --i.e. update of at least one alternate has happenned
5559 
5560                                     -- populate local variables
5561                                     v_wlji_item(v_index) := p_old_primary_item_id;
5562 
5563                                     if p_change_bom_alt = 1 AND p_change_routing_alt = 0 then
5564                                         if v_wlji_alt_bom_designator(v_index) = '-99' then
5565                                             v_wlji_alt_bom_designator(v_index) := null;
5566                                         end if;
5567                                         v_wlji_alt_routing_designator(v_index) := p_old_alt_routing_designator;
5568                                     end if; --p_change_bom_alt = 1
5569 
5570                                     if p_change_routing_alt = 1 AND p_change_bom_alt = 0 then
5571                                         if v_wlji_alt_routing_designator(v_index) = '-99' then
5572                                             v_wlji_alt_routing_designator(v_index) := null;
5573                                         end if;
5574                                         v_wlji_alt_bom_designator(v_index) := p_old_alt_bom_designator;
5575                                     end if; --p_change_routing_alt = 1
5576 
5577                                     if p_change_routing_alt = 1 AND p_change_bom_alt = 1 then
5578                                         if v_wlji_alt_bom_designator(v_index) = '-99' then
5579                                             v_wlji_alt_bom_designator(v_index) := null;
5580                                         end if;
5581                                         if v_wlji_alt_routing_designator(v_index) = '-99' then
5582                                             v_wlji_alt_routing_designator(v_index) := null;
5583                                         end if;
5584                                     end if;
5585 
5586 l_stmt_num := 700.2;
5587                                     delete from wip_operations where wip_entity_id = v_wlji_wip_entity_id(v_index);
5588                                     delete from wip_operation_resources where wip_entity_id = v_wlji_wip_entity_id(v_index);
5589                                     delete from wip_requirement_operations where wip_entity_id = v_wlji_wip_entity_id(v_index);
5590                                     delete from wip_operation_yields where wip_entity_id = v_wlji_wip_entity_id(v_index);
5591 
5592 l_stmt_num := 700.3;
5593                                     -- Now validate the alternate designators to get the routing and bom sequence id.
5594                                     -- Also get the completion subinventory and locator. If the user has provided them
5595                                     -- use them after validation, else use these default values.
5596                                     -- Also validate/default the bom/rtg revision and revision-dates
5597 
5598                                     begin
5599                                         select bor.routing_sequence_id,
5600                                                bor.COMPLETION_SUBINVENTORY,
5601                                                bor.COMPLETION_LOCATOR_ID
5602                                         into   p_common_routing_sequence_id,
5603                                                l_default_subinventory,
5604                                                l_default_compl_loc_id
5605                                         from   bom_operational_routings bor, bom_alternate_designators bad
5606                                         where  ((bor.alternate_routing_designator is null and bad.alternate_designator_code is null
5607                                                 and bad.organization_id = -1)
5608                                                 or (bor.alternate_routing_designator = bad.alternate_designator_code
5609                                                 and bor.organization_id = bad.organization_id))
5610                                         and    bor.organization_id = v_wlji_org(v_index)
5611                                         and    bor.assembly_item_id = v_wlji_item(v_index)
5612                                         and    NVL(bor.alternate_routing_designator, '&*') = NVL(v_wlji_alt_routing_designator(v_index), '&*')
5613                                         and    bor.routing_type = 1
5614                                         and    bor.cfm_routing_flag = 3;
5615                                         --Bug 5107339: Disable_date validation is not applicable here.
5616                                         -- and    trunc(nvl(bad.disable_date, sysdate + 1)) > trunc(sysdate);
5617 
5618                                     exception
5619                                         when no_data_found then
5620                                             l_aux_mesg := '';
5621                                             process_invalid_field('ALTERNATE ROUTING DESIGNATOR',
5622                                                                   l_aux_mesg,
5623                                                                   l_stmt_num);
5624                                             l_error_code := -1;
5625                                     end;
5626 
5627                                     if l_error_code <> 0 then
5628                                             l_error_count := l_error_count + 1;
5629                                             GOTO skip_resched_validations;
5630                                     end if;
5631 
5632 l_stmt_num := 700.4;
5633                                     IF v_wlji_completion_subinventory(v_index) IS NULL AND
5634                                        v_wlji_completion_locator_id(v_index) IS NULL THEN
5635                                         v_wlji_completion_subinventory(v_index) := l_default_subinventory;
5636                                         v_wlji_completion_locator_id(v_index) := l_default_compl_loc_id;
5637                                     END IF;
5638 
5639                                     IF v_wlji_completion_subinventory(v_index) IS NULL AND
5640                                        v_wlji_completion_locator_id(v_index) IS NOT NULL THEN
5641                                         v_wlji_completion_subinventory(v_index) := l_default_subinventory;
5642                                     END IF;
5643 
5644                                     IF v_wlji_completion_subinventory(v_index) IS NOT NULL AND
5645                                        v_wlji_completion_locator_id(v_index) IS NULL THEN
5646 
5647                                         str := to_char(v_wlji_org(v_index))||v_wlji_completion_subinventory(v_index);
5648                                         hash_value := dbms_utility.get_hash_value(str, 37, 1073741824);
5649                                         if WSMPLCVA.v_subinv.exists(hash_value) then
5650                                             NULL;
5651                                         else
5652                                             l_aux_mesg := '';
5653                                             process_invalid_field('COMPLETION SUBINVENTORY',
5654                                                                   l_aux_mesg,
5655                                                                   l_stmt_num);
5656                                             l_error_code := -1;
5657                                         end if;
5658 
5659                                         if l_error_code <> 0 then
5660                                             l_error_count := l_error_count + 1;
5661                                             GOTO skip_resched_validations;
5662                                         end if;
5663                                         l_aux_mesg := '';
5664                                         str := '';
5665                                         hash_value := 0;
5666 
5667 l_stmt_num := 700.5;
5668                                         select locator_type
5669                                         into   mtl_locator_type
5670                                         from   mtl_secondary_inventories
5671                                         where  secondary_inventory_name = v_wlji_completion_subinventory(v_index)
5672                                         and    organization_id = v_wlji_org(v_index);
5673 
5674                                         if v_wlji_completion_subinventory(v_index) = l_default_subinventory then
5675                                             v_wlji_completion_locator_id(v_index) := l_default_compl_loc_id;
5676                                         else
5677                                             if mtl_locator_type = 2 then
5678                                                 l_aux_mesg := '';
5679                                                 process_invalid_field('COMPLETION SUBINVENTORY',
5680                                                                       l_aux_mesg,
5681                                                                       l_stmt_num);
5682                                                 l_error_code := -1;
5683                                                 l_error_count := l_error_count + 1;
5684                                                 GOTO skip_resched_validations;
5685                                             else
5686                                                 NULL;
5687                                             end if;
5688                                         end if;
5689                                     END IF;
5690 
5691                                     l_aux_mesg := '';
5692 
5693 l_stmt_num := 700.6;
5694                                     IF v_wlji_alt_bom_designator(v_index) is NULL THEN
5695                                         begin
5696                                             SELECT  bom.common_bill_sequence_id
5697                                               INTO  p_common_bill_sequence_id
5698                                               FROM  bom_bill_of_materials bom
5699                                              WHERE  bom.alternate_bom_designator is NULL
5700                                                AND  BOM.assembly_item_id = v_wlji_item(v_index)
5701                                                AND  bom.organization_id = v_wlji_org(v_index);
5702                                         exception
5703                                             WHEN NO_DATA_FOUND THEN
5704                                                 NULL;
5705                                         end;
5706                                     ELSE
5707                                         begin
5708                                                SELECT  bom.common_bill_sequence_id
5709                                                  INTO  p_common_bill_sequence_id
5710                                                  FROM  bom_bill_of_materials bom, bom_alternate_designators bad
5711                                                 WHERE  ((bom.alternate_bom_designator is null and bad.alternate_designator_code is null
5712                                                           and bad.organization_id = -1)
5713                                                          OR (bom.alternate_bom_designator = bad.alternate_designator_code
5714                                                              and bom.organization_id = bad.organization_id))
5715                                                   AND  bom.alternate_bom_designator = v_wlji_alt_bom_designator(v_index)
5716                                                   AND  BOM.assembly_item_id = v_wlji_item(v_index)
5717                                                   AND  bom.organization_id = v_wlji_org(v_index);
5718                                                   --Bug 5107339: Disable_date validation is not applicable here.
5719                                                   --AND  trunc(nvl(bad.disable_date, sysdate + 1)) > trunc(sysdate);
5720 
5721                                         exception
5722                                             WHEN no_data_found  THEN
5723                                                 l_aux_mesg := '';
5724                                                 process_invalid_field('ALTERNATE BOM DESIGNATOR',
5725                                                                       l_aux_mesg,
5726                                                                       l_stmt_num);
5727                                                 l_error_code := -1;
5728                                         end;
5729                                     END IF;
5730 
5731                                     if l_error_code <> 0 then
5732                                         l_error_count := l_error_count + 1;
5733                                         GOTO skip_resched_validations;
5734                                     end if;
5735                                     l_aux_mesg := '';
5736 
5737 l_stmt_num := 700.6;
5738 
5739                                     SELECT  nvl(msub.locator_type, 1) sub_loc_control,
5740                                             MP.stock_locator_control_code org_loc_control,
5741                                             MS.restrict_locators_code,
5742                                             MS.location_control_code item_loc_control
5743                                             into l_sub_loc_control, l_org_loc_control,
5744                                                     l_restrict_locators_code, l_item_loc_control
5745                                     FROM    mtl_system_items MS,
5746                                             mtl_secondary_inventories MSUB,
5747                                             mtl_parameters MP
5748                                     WHERE   MP.organization_id = v_wlji_org(v_index)
5749                                     AND     MS.organization_id = v_wlji_org(v_index)
5750                                     AND     MS.inventory_item_id = v_wlji_item(v_index)
5751                                     AND     MSUB.secondary_inventory_name = v_wlji_completion_subinventory(v_index)
5752                                     AND     MSUB.organization_id = v_wlji_org(v_index);
5753 
5754                                     l_locator_id := v_wlji_completion_locator_id(v_index) ;
5755 
5756                                     WIP_LOCATOR.validate(   v_wlji_org(v_index),
5757                                                             v_wlji_item(v_index),
5758                                                             v_wlji_completion_subinventory(v_index),
5759                                                             l_org_loc_control,
5760                                                             l_sub_loc_control,
5761                                                             l_item_loc_control,
5762                                                             l_restrict_locators_code,
5763                                                             NULL, NULL, NULL, NULL,
5764                                                             l_locator_id,
5765                                                             l_segs,
5766                                                             l_loc_success);
5767 
5768                                     IF not l_loc_success THEN
5769                                         l_aux_mesg := '';
5770                                         process_invalid_field('COMPLETION SUBINVENTORY',
5771                                                               l_aux_mesg,
5772                                                               l_stmt_num);
5773                                         l_error_code := -1;
5774                                     end if;
5775 
5776                                     if l_error_code <> 0 then
5777                                         l_error_count := l_error_count + 1;
5778                                         GOTO skip_resched_validations;
5779                                     end if;
5780                                     l_aux_mesg := '';
5781                                     l_locator_id := 0;
5782 
5783 l_stmt_num := 700.7;
5784                                     if v_wlji_fusd(v_index) is null then
5785                                         v_wlji_fusd(v_index) := p_old_start_date;
5786                                     end if;
5787 
5788                                     if v_wlji_fusd(v_index) > SYSDATE then
5789                                         l_rev_date := v_wlji_fusd(v_index);
5790                                     else
5791                                         l_rev_date := SYSDATE;
5792                                     end if;
5793 
5794                                     wip_revisions.bom_revision (v_wlji_org(v_index),
5795                                                                 v_wlji_item(v_index),
5796                                                                 v_wlji_bom_revision(v_index),
5797                                                                 v_wlji_bom_revision_date(v_index),
5798                                                                 l_rev_date);
5799 
5800 
5801                                     wip_revisions.routing_revision (v_wlji_org(v_index),
5802                                                                     v_wlji_item(v_index),
5803                                                                     v_wlji_routing_revision(v_index),
5804                                                                     v_wlji_routing_revision_date(v_index),
5805                                                                     l_rev_date);
5806 
5807                                     if l_error_code <> 0 then
5808                                             l_error_count := l_error_count + 1;
5809                                             GOTO skip_resched_validations;
5810                                     end if;
5811 
5812 l_stmt_num := 700.8;
5813                                     -- now that we have the bom and rtg seq_id's and values for completion-subinv and locator
5814                                     -- and revision info, we can proceed to populate the wo tables and update wdj
5815 
5816                                     build_lbji_info(p_routing_seq_id => p_common_routing_sequence_id,
5817                                                     p_common_bill_sequence_id => p_common_bill_sequence_id,
5818                                                     p_explode_header_detail => 1,
5819                                                     p_status_type => 1,
5820                                                     p_class_code => null,
5821                                                     p_org => v_wlji_org(v_index),
5822                                                     p_wip_entity_id => v_wlji_wip_entity_id(v_index),
5823                                                     p_last_updt_date => v_wlji_last_updt_date(v_index),
5824                                                     p_last_updt_by => v_wlji_last_updt_by(v_index),
5825                                                     p_creation_date => v_wlji_creation_date(v_index),
5826                                                     p_created_by => v_wlji_created_by(v_index),
5827                                                     p_last_updt_login => v_wlji_last_updt_login(v_index),
5828                                                     p_request_id => v_wlji_request_id(v_index),
5829                                                     p_program_application_id => v_wlji_program_application_id(v_index),
5830                                                     p_program_id => v_wlji_program_id(v_index),
5831                                                     p_prog_updt_date => v_wlji_prog_updt_date(v_index),
5832                                                     p_source_line_id => null,
5833                                                     p_source_code =>  null,
5834                                                     p_description => null,
5835                                                     p_item => p_old_primary_item_id,
5836                                                     p_job_type => 1,
5837                                                     p_bom_reference_id => null,
5838                                                     p_routing_reference_id => null,
5839                                                     p_firm_planned_flag => p_old_firm_planned_flag,
5840                                                     p_wip_supply_type => p_old_supply_type,
5841                                                     p_fusd => p_scheduled_start_date,
5842                                                     p_lucd => p_scheduled_completion_date,
5843                                                     p_start_quantity => p_old_quantity,
5844                                                     p_net_quantity => p_old_net_quantity,
5845                                                     p_coproducts_supply => p_coproducts_supply,
5846                                                     p_bom_revision => v_wlji_bom_revision(v_index),
5847                                                     p_routing_revision => v_wlji_routing_revision(v_index),
5848                                                     p_bom_revision_date => v_wlji_bom_revision_date(v_index),
5849                                                     p_routing_revision_date => v_wlji_routing_revision_date(v_index),
5850                                                     p_lot_number => null,
5851                                                     p_alt_bom_designator => v_wlji_alt_bom_designator(v_index),
5852                                                     p_alt_routing_designator => v_wlji_alt_routing_designator(v_index),
5853                                                     p_priority => null,
5854                                                     p_due_date => null,
5855                                                     p_attribute_category => null,
5856                                                     p_attribute1 => null,
5857                                                     p_attribute2 => null,
5858                                                     p_attribute3 => null,
5859                                                     p_attribute4 => null,
5860                                                     p_attribute5 => null,
5861                                                     p_attribute6 => null,
5862                                                     p_attribute7 => null,
5863                                                     p_attribute8 => null,
5864                                                     p_attribute9 => null,
5865                                                     p_attribute10 => null,
5866                                                     p_attribute11 => null,
5867                                                     p_attribute12 => null,
5868                                                     p_attribute13 => null,
5869                                                     p_attribute14 => null,
5870                                                     p_attribute15 => null,
5871                                                     p_job_name => null,
5872                                                     p_completion_subinventory => v_wlji_completion_subinventory(v_index),
5873                                                     p_completion_locator_id => v_wlji_completion_locator_id(v_index),
5874                                                     p_demand_class => null,
5875                                                     p_project_id => null,
5876                                                     p_task_id => null,
5877                                                     p_schedule_group_id => null,
5878                                                     p_build_sequence => null,
5879                                                     p_line_id => null,
5880                                                     p_kanban_card_id => null,
5881                                                     p_overcompl_tol_type => null,
5882                                                     p_overcompl_tol_value => null,
5883                                                     p_end_item_unit_number => null,
5884                                                     p_rtg_op_seq_num => null,
5885                                                     p_src_client_server => 0,
5886                                                     p_po_creation_time => null,
5887                                                     p_error_code => l_error_code,
5888                                                     p_error_msg => l_error_msg);
5889 
5890                                     if l_error_code <> 0 then
5891                                            handle_error(l_error_code, l_error_msg,  l_stmt_num);
5892                                            l_error_count := l_error_count + 1;
5893                                            GOTO skip_resched_validations;
5894                                     end if;
5895 
5896                                 elsif p_old_status_type <> 1 then
5897                                     fnd_file.put_line(fnd_file.log, 'Ignoring any of the following fields if provided by the user for this standard job:');
5898                                     fnd_file.put_line(fnd_file.log, 'ROUTING_REVISION_DATE, ROUTING_REVISION, BOM_REVISION_DATE, BOM_REVISION,
5899                                                                             ALTERNATE_BOM_DESIGNATOR, ALTERNATE_ROUTING_DESIGNATOR');
5900                                 end if; -- change bom/routing alternate
5901 
5902                             end if; -- job type 1, near l_stmt_num := 700.1;
5903 
5904 
5905                             if p_old_job_type = 1 then
5906                                 v_wlji_bom_reference_id(v_index) := p_old_bom_reference_id;
5907                                 v_wlji_routing_reference_id(v_index) := p_old_routing_reference_id;
5908                                 if p_change_alt_flag = 0 then
5909                                     v_wlji_bom_revision(v_index) := p_old_bom_revision;
5910                                     v_wlji_routing_revision(v_index) := p_old_routing_revision;
5911                                     v_wlji_bom_revision_date(v_index) := p_old_bom_revision_date;
5912                                     v_wlji_routing_revision_date(v_index) := p_old_routing_revision_date;
5913                                     v_wlji_alt_bom_designator(v_index) := p_old_alt_bom_designator;
5914                                     v_wlji_alt_routing_designator(v_index) := p_old_alt_routing_designator;
5915                                     v_wlji_completion_subinventory(v_index) := p_old_completion_subinv;
5916                                     v_wlji_completion_locator_id(v_index) := p_old_completion_locator;
5917                                 end if;
5918                             end if;
5919 
5920                         Exception
5921                             WHEN OTHERS THEN
5922                                 l_error_code := SQLCODE;
5923                                 l_err_msg:='WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
5924                                 handle_error(l_error_code, l_err_msg, l_stmt_num);
5925                                 GOTO skip_resched_validations;
5926                         End;
5927 -- =============================================================================================
5928 -- UPDATE OF ALTERNATES END
5929 -- =============================================================================================
5930                         -- Bug 2762029 ends
5931 
5932 
5933 -- =============================================================================================
5934 --  UPDATE OF REFERENCES BEGINS
5935 -- =============================================================================================
5936 
5937                         -- non standard job bom/routing reference update. The assumption is that this module will
5938                         -- NOT update the quantity/dates/etc., they will be taken care in the later modules.
5939                         -- This module will just look at the reference info, and assume qnty/date/etc to be same
5940                         -- as the old values.
5941 l_stmt_num:= 701;
5942                         if p_old_job_type = 3 then
5943 
5944                             p_change_bom_reference := 0;
5945                             p_change_routing_reference := 0;
5946 
5947                             if   v_wlji_routing_reference_id(v_index) is not null then
5948                                 p_change_routing_reference := 1;
5949                             end if;
5950 
5951                             if   v_wlji_bom_reference_id(v_index) is not null then
5952                                 p_change_bom_reference := 1;
5953                             end if;
5954 
5955 l_stmt_num:= 701.7;
5956                             if p_change_routing_reference = 0 AND p_change_bom_reference = 0 then
5957                                 bom_seq_id := p_old_com_bom_seq_id;
5958                                 v_wlji_bom_revision_date(v_index):= p_old_bom_revision_date;
5959                                 v_wlji_bom_reference_id(v_index):= p_old_bom_reference_id;
5960                                 v_wlji_alt_bom_designator(v_index):= p_old_alt_bom_designator;
5961                                 routing_seq_id := p_old_com_rtg_seq_id;
5962                                 v_wlji_routing_revision_date(v_index):=p_old_routing_revision_date;
5963                                 v_wlji_routing_reference_id(v_index):=p_old_routing_reference_id;
5964                                 v_wlji_alt_routing_designator(v_index):=p_old_alt_routing_designator;
5965                             end if;
5966 
5967 
5968                             -- user can update the bom_reference and the routing reference of a non-standard job only if the
5969                             -- job is unreleased. If the user updates the bom/routing on an unreleased job as well as it's
5970                             -- status to released, the update of the bom/rtg will be assumed to have taken place before
5971                             -- the update of status.
5972 
5973                             if (p_change_bom_reference = 1 or p_change_routing_reference = 1)
5974                                 and  p_old_status_type <> 1 then
5975                                     fnd_file.put_line(fnd_file.log,'Ignoring any of the following fields if provided by the user:');
5976                                     --fnd_file.new_line(fnd_file.log, 1);
5977                                     fnd_file.put_line(fnd_file.log, 'ROUTING_REFERENCE_ID, BOM_REFERENCE_ID, ROUTING_REVISION_DATE , ROUTING_REVISION, BOM_REVISION_DATE, BOM_REVISION, ALTERNATE_BOM_DESIGNATOR, ALTERNATE_ROUTING_DESIGNATOR');
5978                                     v_wlji_bom_revision_date(v_index):= p_old_bom_revision_date;
5979                                     v_wlji_bom_reference_id(v_index):= p_old_bom_reference_id;
5980                                     v_wlji_alt_bom_designator(v_index):= p_old_alt_bom_designator;
5981                                     v_wlji_routing_revision_date(v_index):=p_old_routing_revision_date;
5982                                     v_wlji_routing_reference_id(v_index):=p_old_routing_reference_id;
5983                                     v_wlji_alt_routing_designator(v_index):=p_old_alt_routing_designator;
5984                             end if;
5985 
5986 
5987                             if p_old_status_type = 1 then
5988 
5989                             -- the following three variables will temporarily assume the old values for reasons mentioned above.
5990                             -- their original values will be returned to them for possible verification at the end of the module
5991 
5992                                 temp_start_quantity:=v_wlji_start_quantity(v_index);
5993                                 temp_fusd:=v_wlji_fusd(v_index);
5994                                 temp_lucd:=v_wlji_lucd(v_index);
5995                                 temp_supply:=v_wlji_wip_supply_type(v_index);
5996 
5997                                 v_wlji_start_quantity(v_index):=p_old_quantity;
5998                                 v_wlji_fusd(v_index):=p_old_start_date;
5999                                 v_wlji_lucd(v_index):=p_old_complete_date;
6000                                 v_wlji_wip_supply_type(v_index):=p_old_supply_type;
6001 
6002 l_stmt_num:= 702;
6003                                 if (p_change_bom_reference = 1 or p_change_routing_reference = 1) then
6004 
6005                                     if p_change_bom_reference = 1 then
6006                                         wsmputil.validate_non_std_references(
6007                                                   null,
6008                                                   null,
6009                                                   v_wlji_bom_reference_id(v_index),
6010                                                   null,
6011                                                   v_wlji_alt_bom_designator(v_index),
6012                                                   v_wlji_org(v_index),
6013                                                   sysdate, -- this doesn't really make any diff, not used after all
6014                                                   null,
6015                                                   null,
6016                                                   dummy_number,
6017                                                   null,
6018                                                   null,
6019                                                   null,
6020                                                   dummy_number,
6021                                                   v_wlji_bom_revision(v_index),
6022                                                   v_wlji_bom_revision_date(v_index),
6023                                                   dummy_varchar,
6024                                                   dummy_date,
6025                                                   dummy_number,
6026                                                   bom_seq_id,
6027                                                   1,
6028                                                   l_error_code,
6029                                                   l_err_msg);
6030 
6031                                         if l_error_code <> 0 then
6032                                             HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
6033                                             l_error_code := -1;
6034                                             GOTO skip_resched_validations;
6035                                         end if;
6036                                     end if;
6037 
6038 l_stmt_num:= 703;
6039                                     if p_change_routing_reference = 1 then
6040                                         wsmputil.validate_non_std_references(
6041                                                   null,
6042                                                   v_wlji_routing_reference_id(v_index),
6043                                                   null,
6044                                                   v_wlji_alt_routing_designator(v_index),
6045                                                   null,
6046                                                   v_wlji_org(v_index),
6047                                                   sysdate, -- this doesn't really make any diff, not used after all
6048                                                   null,
6049                                                   null,
6050                                                   dummy_number,
6051                                                   null,
6052                                                   null,
6053                                                   null,
6054                                                   dummy_number,
6055                                                   dummy_varchar,
6056                                                   dummy_date,
6057                                                   v_wlji_routing_revision(v_index),
6058                                                   v_wlji_routing_revision_date(v_index),
6059                                                   routing_seq_id,
6060                                                   dummy_number,
6061                                                   2,
6062                                                   l_error_code,
6063                                                   l_err_msg);
6064 
6065                                         if l_error_code <> 0 then
6066                                             HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
6067                                             l_error_code := -1;
6068                                             GOTO skip_resched_validations;
6069                                         end if;
6070                                     end if;
6071 
6072 l_stmt_num:= 704;
6073                                     if p_change_routing_reference = 1 OR p_change_bom_reference = 1 then
6074                                         begin
6075                                             delete from wip_operations
6076                                             where  wip_entity_id = v_wlji_wip_entity_id(v_index);
6077                                             delete from wip_operation_yields
6078                                             where wip_entity_id = v_wlji_wip_entity_id(v_index);
6079                                             delete from wip_operation_resources
6080                                             where wip_entity_id = v_wlji_wip_entity_id(v_index);
6081                                             delete from wip_requirement_operations
6082                                             where wip_entity_id = v_wlji_wip_entity_id(v_index);
6083                                         exception
6084                                             when others then
6085                                                 rollback;
6086                                                 l_error_code := SQLCODE;
6087                                                 l_err_msg:='WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
6088                                                 handle_error(l_error_code, l_err_msg, l_stmt_num);
6089                                                 GOTO skip_resched_validations;
6090                                         end;
6091                                     end if;
6092 
6093 
6094                                     if p_change_routing_reference = 1 AND p_change_bom_reference = 0 then
6095                                         bom_seq_id := p_old_com_bom_seq_id;
6096                                         v_wlji_bom_revision_date(v_index):= p_old_bom_revision_date;
6097                                         v_wlji_bom_reference_id(v_index):= p_old_bom_reference_id;
6098                                         v_wlji_alt_bom_designator(v_index):= p_old_alt_bom_designator;
6099                                     end if;
6100 
6101                                     if p_change_routing_reference = 0 AND p_change_bom_reference = 1 then
6102                                         routing_seq_id := p_old_com_rtg_seq_id;
6103                                         v_wlji_routing_revision_date(v_index):=p_old_routing_revision_date;
6104                                         v_wlji_routing_reference_id(v_index):=p_old_routing_reference_id;
6105                                         v_wlji_alt_routing_designator(v_index):=p_old_alt_routing_designator;
6106                                     end if;
6107 
6108                                     begin
6109                                         build_lbji_info(
6110                                             p_routing_seq_id => routing_seq_id,
6111                                             p_common_bill_sequence_id => null,
6112                                             p_explode_header_detail => 1,
6113                                             p_status_type => 1,
6114                                             p_class_code => null,
6115                                             p_org => v_wlji_org(v_index),
6116                                             p_wip_entity_id => v_wlji_wip_entity_id(v_index),
6117                                             p_last_updt_date => v_wlji_last_updt_date(v_index),
6118                                             p_last_updt_by => v_wlji_last_updt_by(v_index),
6119                                             p_creation_date => v_wlji_creation_date(v_index),
6120                                             p_created_by => v_wlji_created_by(v_index),
6121                                             p_last_updt_login => v_wlji_last_updt_login(v_index),
6122                                             p_request_id => v_wlji_request_id(v_index),
6123                                             p_program_application_id => v_wlji_program_application_id(v_index),
6124                                             p_program_id => v_wlji_program_id(v_index),
6125                                             p_prog_updt_date => v_wlji_prog_updt_date(v_index),
6126                                             p_source_line_id => null,
6127                                             p_source_code =>  null,
6128                                             p_description => null,
6129                                             p_item => v_wlji_item(v_index),
6130                                             p_job_type => 3,
6131                                             p_bom_reference_id =>  v_wlji_bom_reference_id(v_index),
6132                                             p_routing_reference_id => v_wlji_routing_reference_id(v_index),
6133                                             p_firm_planned_flag => null,
6134                                             p_wip_supply_type => v_wlji_wip_supply_type(v_index),
6135                                             p_fusd => v_wlji_fusd(v_index),
6136                                             p_lucd => v_wlji_lucd(v_index),
6137                                             p_start_quantity => v_wlji_start_quantity(v_index),
6138                                             p_net_quantity => null,
6139                                             p_coproducts_supply => null,
6140                                             p_bom_revision => null,
6141                                             p_routing_revision => null,
6142                                             p_bom_revision_date => v_wlji_bom_revision_date(v_index),
6143                                             p_routing_revision_date => v_wlji_routing_revision_date(v_index),
6144                                             p_lot_number => null,
6145                                             p_alt_bom_designator => v_wlji_alt_bom_designator(v_index),
6146                                             p_alt_routing_designator => v_wlji_alt_routing_designator(v_index),
6147                                             p_priority => null,
6148                                             p_due_date => null,
6149                                             p_attribute_category => null,
6150                                             p_attribute1 => null,
6151                                             p_attribute2 => null,
6152                                             p_attribute3 => null,
6153                                             p_attribute4 => null,
6154                                             p_attribute5 => null,
6155                                             p_attribute6 => null,
6156                                             p_attribute7 => null,
6157                                             p_attribute8 => null,
6158                                             p_attribute9 => null,
6159                                             p_attribute10 => null,
6160                                             p_attribute11 => null,
6161                                             p_attribute12 => null,
6162                                             p_attribute13 => null,
6163                                             p_attribute14 => null,
6164                                             p_attribute15 => null,
6165                                             p_job_name => null,
6166                                             p_completion_subinventory => null,
6167                                             p_completion_locator_id => null,
6168                                             p_demand_class => null,
6169                                             p_project_id => null,
6170                                             p_task_id => null,
6171                                             p_schedule_group_id => null,
6172                                             p_build_sequence => null,
6173                                             p_line_id => null,
6174                                             p_kanban_card_id => null,
6175                                             p_overcompl_tol_type => null,
6176                                             p_overcompl_tol_value => null,
6177                                             p_end_item_unit_number => null,
6178                                             p_rtg_op_seq_num => null,
6179                                             p_src_client_server => 0,
6180                                             p_po_creation_time => WSMPLCVA.v_org(v_wlji_org(v_index)).PO_CREATION_TIME,
6181                                             p_error_code => l_error_code,
6182                                             p_error_msg => l_error_msg);
6183 
6184                                         if l_error_code <> 0 then
6185                                             raise update_job_exception;
6186                                         end if;
6187 
6188                                     exception
6189                                         when update_job_exception then
6190                                             handle_error(l_error_code, l_error_msg, l_stmt_num);
6191                                             l_error_count := l_error_count + 1;
6192                                             GOTO skip_resched_validations;
6193                                     end;
6194 
6195                                 end if;
6196                                 v_wlji_start_quantity(v_index):=temp_start_quantity;
6197                                 v_wlji_fusd(v_index):=temp_fusd;
6198                                 v_wlji_lucd(v_index):=temp_lucd;
6199                                 v_wlji_wip_supply_type(v_index):=temp_supply;
6200 
6201                             end if; -- old_status_type = 1
6202 
6203                         end if; -- job type = 3
6204 
6205 -- =============================================================================================
6206 -- UPDATE OF REFERENCES ENDS
6207 -- =============================================================================================
6208 
6209 
6210                         -- if the user wants to update only the references, the wo/wro/wor/woy updates are not needed
6211                         if (p_old_job_type = 3)
6212                            AND
6213                            (
6214                             (
6215                             (v_wlji_firm_planned_flag(v_index) is null) or
6216                             (v_wlji_firm_planned_flag(v_index) is not null and v_wlji_firm_planned_flag(v_index)=p_old_firm_planned_flag)
6217                             )
6218                             and
6219                             (
6220                             (v_wlji_status_type(v_index) is null) or
6221                             (v_wlji_status_type(v_index) is not null and v_wlji_status_type(v_index)=p_old_status_type)
6222                             )
6223                             and
6224                             (
6225                             (v_wlji_start_quantity(v_index) is null) or
6226                             (v_wlji_start_quantity(v_index) is not null and v_wlji_start_quantity(v_index)=p_old_quantity)
6227                             )
6228                             and
6229                             (
6230                             (v_wlji_net_quantity(v_index) is null) or
6231                             (v_wlji_net_quantity(v_index) is not null and v_wlji_net_quantity(v_index)=p_old_net_quantity)
6232                             )
6233                             and
6234                             (
6235                             (v_wlji_lucd(v_index) is null) or
6236                             (v_wlji_lucd(v_index) is not null and v_wlji_lucd(v_index)=p_scheduled_completion_date)
6237                             )
6238                             and
6239                             (
6240                             (v_wlji_fusd(v_index) is null) or
6241                             (v_wlji_fusd(v_index) is not null and v_wlji_fusd(v_index)=p_scheduled_start_date)
6242                             )
6243                             and
6244                             (
6245                             (v_wlji_coproducts_supply(v_index) is null) or
6246                             (v_wlji_coproducts_supply(v_index) is not null and v_wlji_coproducts_supply(v_index)=p_coproducts_supply)
6247                             )
6248                            ) then
6249                             p_skip_updt:= 1;
6250                         end if;
6251 
6252 
6253                         if lbji_debug = 'Y' then
6254                             if p_skip_updt = 1 then
6255                                 fnd_file.put_line(fnd_file.log, 'Planning to skip update of wo, wor, wro');
6256                             else
6257                                 fnd_file.put_line(fnd_file.log, 'No Plans to skip update of wo, wor, wro');
6258                             end if;
6259                         end if;
6260 
6261 
6262                         -- if the old firm_planned flag was 1, and the user populated null while updating the job,
6263                         -- no changes in quantity and date allowed. If the user changed the flag, this change is considered
6264                         -- "before" making a decision whether to allow update of qnty/date or not.
6265                         if v_wlji_firm_planned_flag(v_index) is NULL then
6266                             v_wlji_firm_planned_flag(v_index) := p_old_firm_planned_flag;
6267                         end if;
6268 
6269                         -- for non-std jobs, the firm flag is always 2. User cannot update it to 1.
6270                         if p_old_job_type = 3 then
6271                             if v_wlji_firm_planned_flag(v_index) is not null and
6272                                v_wlji_firm_planned_flag(v_index) <> 2 then
6273                                 l_aux_mesg := '';
6274                                 process_invalid_field('FIRM PLANNED FLAG',
6275                                                       l_aux_mesg,
6276                                                       l_stmt_num);
6277                                 l_error_code := -1;
6278                                 GOTO skip_resched_validations;
6279                             end if;
6280                         end if;
6281 
6282                         --validate status first
6283 l_stmt_num := 710;
6284 
6285                         IF v_wlji_status_type(v_index) IS NULL THEN
6286                             v_wlji_status_type(v_index) := p_old_status_type;
6287                             -- bugfix 2697295, update of released date only is not allowed
6288                             v_wlji_date_released(v_index) := p_old_date_released;
6289                         ELSIF v_wlji_status_type(v_index) = p_old_status_type THEN
6290                             -- bugfix 2697295, update of released date only is not allowed
6291                             v_wlji_date_released(v_index) := p_old_date_released;
6292                         ELSE
6293 
6294                         -- status type should be one of RELEASED, HOLD, CANCELLED, UNRELEASED
6295 
6296                             IF v_wlji_status_type(v_index) NOT IN (1,3,6,7) THEN
6297                                 l_aux_mesg := '';
6298                                 process_invalid_field('LOAD TYPE',
6299                                                       l_aux_mesg,
6300                                                       l_stmt_num);
6301                                 l_error_code := -1;
6302                                 GOTO skip_resched_validations;
6303                             ELSE
6304 
6305                                 if p_old_status_type = 7   then     -- cancelled
6306                                     l_error_code := -1;
6307                                     process_errorred_field('WSM',
6308                                                            'WSM_RESCHEDULE_CANCEL_JOB',
6309                                                            l_stmt_num);
6310                                     GOTO skip_resched_validations;
6311                                 end if;
6312 
6313                                 -- bugfix 2697295 begin
6314                                 -- if the job is being released from an unreleased state...
6315                                 if p_old_date_released is null and v_wlji_status_type(v_index) = 3 then
6316                                     if (v_wlji_date_released(v_index) is null ) then
6317                                         v_wlji_date_released(v_index) := sysdate;
6318                                     elsif (v_wlji_date_released(v_index) > sysdate ) then
6319                                         l_error_code := -1;
6320                                         process_errorred_field('WIP',
6321                                                                'WIP_INVALID_RELEASE_DATE',
6322                                                                l_stmt_num);
6323                                         GOTO skip_resched_validations;
6324                                     else
6325                                         -- BEGIN: BUG3126650
6326                                         --begin
6327                                         --    select 1
6328                                         --    into   l_dummy
6329                                         --    from   org_acct_periods
6330                                         --    where  organization_id = v_wlji_org(v_index)
6331                                         --    and    trunc(nvl(v_wlji_date_released(v_index),sysdate)) between PERIOD_START_DATE and SCHEDULE_CLOSE_DATE
6332                                         --    and    period_close_date is NULL;
6333                                         --exception
6334                                         --    when NO_DATA_FOUND then
6335                                         --        fnd_message.set_name('WIP', 'WIP_NO_ACCT_PERIOD');
6336                                         --        l_err_msg :=  fnd_message.get;
6337                                         --        l_error_code := -1;
6338                                         --        HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
6339                                         --        GOTO skip_resched_validations;
6340                                         --    when others then
6341                                         --        l_err_msg := SQLERRM;
6342                                         --        l_error_code := SQLCODE;
6343                                         --        HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
6344                                         --        GOTO skip_resched_validations;
6345                                         --end;
6346                                         l_dummy := WSMPUTIL.GET_INV_ACCT_PERIOD(
6347                                                     x_err_code         => l_error_code,
6348                                                     x_err_msg          => l_err_msg,
6349                                                     p_organization_id  => v_wlji_org(v_index),
6350                                                     p_date             => trunc(nvl(v_wlji_date_released(v_index),sysdate)));
6351                                         IF (l_error_code <> 0) THEN
6352                                             HANDLE_ERROR( l_error_code, l_error_msg, l_stmt_num);
6353                                             GOTO skip_resched_validations;
6354                                         END IF;
6355                                         -- END: BUG3126650
6356                                     end if;
6357                                 -- else if the job is being unreleased from a released state...
6358                                 elsif p_old_date_released is not null and v_wlji_status_type(v_index) = 1 then
6359                                     v_wlji_date_released(v_index) := null;
6360                                      -- ignore release date populated by user in any other condition...
6361                                 else
6362                                     v_wlji_date_released(v_index) := p_old_date_released;
6363                                 end if;
6364                                 -- bugfix 2697295 end
6365 
6366                                 if ((p_old_status_type = 3 and v_wlji_status_type(v_index) = 1) OR
6367                                    (p_old_status_type = 6 and  v_wlji_status_type(v_index) = 1)) then
6368 
6369                                     if (discrete_charges_exist(v_wlji_wip_entity_id(v_index), v_wlji_org(v_index),0)) then
6370                                         l_error_code := -1;
6371                                         process_errorred_field('WIP',
6372                                                                'WIP_UNRLS_JOB/SCHED',
6373                                                                l_stmt_num);
6374                                         GOTO skip_resched_validations;
6375 
6376                                     -- osp begin
6377                                     else
6378                                         if wip_osp.po_req_exists (
6379                                                     v_wlji_wip_entity_id(v_index),
6380                                                     null,
6381                                                     v_wlji_org(v_index),
6382                                                     null, 5) then
6383                                             fnd_message.set_name('WSM', 'WSM_JOB_PURCHASE_REQ');
6384                                             l_err_msg := fnd_message.get;
6385                                             l_warning_count := l_warning_count + 1;
6386                                             handle_warning(p_err_msg => l_err_msg,
6387                                                            p_header_id => v_wlji_header_id(v_index),
6388                                                            p_request_id => v_wlji_request_id(v_index),
6389                                                            p_program_id => v_wlji_program_id(v_index),
6390                                                            p_program_application_id => v_wlji_program_application_id(v_index));
6391                                         end if;
6392                                     -- osp end
6393                                     end if;
6394                                 end if;
6395 
6396 l_stmt_num := 712;
6397                                 -- abb H: optional scrap accounting
6398                                 -- if (p_old_status_type IN (1,6)) and (v_wlji_status_type(v_index) = 3) and
6399                                 --     WSMPLCVA.v_org(v_wlji_org(v_index)).ESTIMATED_SCRAP_ACCOUNTING = 1
6400                                 --     and p_old_job_type = 1 then
6401 
6402                                 if (p_old_status_type IN (1,6)) and (v_wlji_status_type(v_index) = 3) and
6403                                     wsmputil.WSM_ESA_ENABLED(p_wip_entity_id => v_wlji_wip_entity_id(v_index),
6404                                                              err_code => l_error_code,
6405                                                              err_msg => l_error_msg,
6406                                                              p_org_id => '',
6407                                                              p_job_type => '') = 1 then
6408 
6409                                     if v_wlji_class_code(v_index) is null then
6410                                         l_temp_cc := p_old_class_code;
6411                                     else
6412                                         l_temp_cc := v_wlji_class_code(v_index);
6413                                     end if;
6414 
6415                                     select est_scrap_account,
6416                                            est_scrap_var_account
6417                                     into   p_est_scrap_account,
6418                                            p_est_scrap_var_account
6419                                     from   wip_accounting_classes
6420                                     where  class_code = l_temp_cc
6421                                     and    organization_id = v_wlji_org(v_index);
6422 
6423                                     if p_est_scrap_account is null or p_est_scrap_var_account is null then
6424                                         v_wlji_process_status(v_index) := 3; --ERROR
6425                                         v_wlji_err_code(v_index) := -1;
6426                                         fnd_message.set_name('WSM','WSM_NO_WAC_SCRAP_ACC');
6427                                         fnd_message.set_token('CC', l_temp_cc);
6428                                         v_wlji_err_msg(v_index) := fnd_message.get;
6429                                         fnd_file.put_line(fnd_file.log, 'stmt_num: '|| l_stmt_num ||'  ' ||v_wlji_err_msg(v_index));
6430                                         fnd_file.new_line(fnd_file.log, 3);
6431                                         l_error_code := -1;
6432                                         GOTO skip_resched_validations;
6433                                     end if;
6434                                         if p_est_scrap_account is null or p_est_scrap_var_account is null then
6435                                         v_wlji_process_status(v_index) := 3; --ERROR
6436                                         v_wlji_err_code(v_index) := -1;
6437                                         fnd_message.set_name('WSM','WSM_NO_WAC_SCRAP_ACC');
6438                                         fnd_message.set_token('CC', l_temp_cc);
6439                                         v_wlji_err_msg(v_index) := fnd_message.get;
6440                                         fnd_file.put_line(fnd_file.log, 'stmt_num: '|| l_stmt_num ||'  ' ||v_wlji_err_msg(v_index));
6441                                         fnd_file.new_line(fnd_file.log, 3);
6442                                         l_error_code := -1;
6443                                         GOTO skip_resched_validations;
6444                                     end if;
6445                                 end if;
6446                             END IF;  -- status
6447                         END IF;
6448 
6449 l_stmt_num := 720;
6450                         --validate quantity
6451 
6452                         IF v_wlji_start_quantity(v_index) IS NULL THEN
6453                             v_wlji_start_quantity(v_index) := p_old_quantity;
6454                         ELSIF  v_wlji_start_quantity(v_index) = p_old_quantity THEN
6455                             NULL;
6456                         ELSIF v_wlji_firm_planned_flag(v_index) = 1 THEN
6457                             l_error_code := -1;
6458                             process_errorred_field('WSM',
6459                                                    'WSM_JOB_FIRM',
6460                                                    l_stmt_num);
6461                             GOTO skip_resched_validations;
6462                         ELSE
6463 
6464                             begin
6465                                 if (p_old_status_type IN (3 ,6)
6466                                    AND v_wlji_status_type(v_index) IN (1,3,6)) then
6467                                     if (discrete_charges_exist(v_wlji_wip_entity_id(v_index), v_wlji_org(v_index),0)) then
6468                                         raise invalid_qnty_error;
6469                                     end if;
6470                                 end if;
6471                             exception
6472                                 when invalid_qnty_error then
6473                                     l_error_code := -1;
6474                                     process_errorred_field('WSM',
6475                                                            'WSM_QNTY_NOCHANGE',
6476                                                            l_stmt_num);
6477                                     GOTO skip_resched_validations;
6478                             end;
6479 
6480                         END IF; -- qty change
6481 
6482                         -- osp begin
6483                         -- create requisitions/additional reuisitions under following conditions:
6484                         -- 1. user updates only status from unreleased to released, quantity unchanged
6485                         -- 2. user updates only quantity (increases) for a released job, status is unchanged
6486                         -- 3. user updates staus to released, and increases quantity.
6487 
6488                         if WSMPLCVA.v_org(v_wlji_org(v_index)).PO_CREATION_TIME <> WIP_CONSTANTS.MANUAL_CREATION then
6489 
6490                             if (v_wlji_status_type(v_index) = 3 and p_old_status_type = 1) then
6491                                 if wsmputil.check_osp_operation(v_wlji_wip_entity_id(v_index), l_osp_op_seq_num , v_wlji_org(v_index)) then
6492                                     l_atleast_one_osp_exists := l_atleast_one_osp_exists + 1;
6493                                     wip_osp.create_requisition(
6494                                             P_Wip_Entity_Id => v_wlji_wip_entity_id(v_index),
6495                                             P_Organization_Id => v_wlji_org(v_index),
6496                                             P_Repetitive_Schedule_Id => null,
6497                                             P_Operation_Seq_Num => l_osp_op_seq_num,
6498                                             P_Resource_Seq_Num => null,
6499                                             P_Run_ReqImport => WIP_CONSTANTS.NO);
6500                                 end if; -- check_osp_operation
6501                             end if;
6502 
6503                             if (v_wlji_start_quantity(v_index) > p_old_quantity) AND v_wlji_status_type(v_index) = 3 then
6504                                 wip_osp.create_additional_req(
6505                                             P_Wip_Entity_Id => v_wlji_wip_entity_id(v_index),
6506                                             P_Organization_id => v_wlji_org(v_index),
6507                                             P_Repetitive_Schedule_Id => null,
6508                                             P_Added_Quantity => (v_wlji_start_quantity(v_index) - p_old_quantity),
6509                                             P_Op_Seq => null);
6510                             end if;
6511 
6512                         end if; -- wip_constants.manual_creation
6513                         -- osp end
6514 
6515 
6516 l_stmt_num := 721;
6517                         -- validate net-quantity
6518 
6519                         if p_old_job_type = 3 then
6520                             if v_wlji_net_quantity(v_index) < 0 or
6521                                 v_wlji_net_quantity(v_index) > v_wlji_start_quantity(v_index) then
6522                                 l_aux_mesg := '';
6523                                 process_invalid_field('NET QUANTITY',
6524                                                       l_aux_mesg,
6525                                                       l_stmt_num);
6526                                 l_error_code := -1;
6527                                 GOTO skip_resched_validations;
6528                             end if;
6529                         end if; -- job type
6530 
6531                         if p_old_job_type = 1 then
6532                             if (v_wlji_net_quantity(v_index) is not null) and (v_wlji_net_quantity(v_index) <> p_old_quantity)
6533                                and (v_wlji_firm_planned_flag(v_index) = 1) then
6534                                 l_error_code := -1;
6535                                 process_errorred_field('WSM',
6536                                                        'WSM_JOB_FIRM',
6537                                                        l_stmt_num);
6538                                 GOTO skip_resched_validations;
6539                             end if;
6540 
6541                             if (v_wlji_net_quantity(v_index) is not null) and (v_wlji_start_quantity(v_index) is null)
6542                                and (v_wlji_net_quantity(v_index) > p_old_quantity) then
6543                                 l_aux_mesg := '';
6544                                 process_invalid_field('NET QUANTITY',
6545                                                       l_aux_mesg,
6546                                                       l_stmt_num);
6547                                 l_error_code := -1;
6548                                 GOTO skip_resched_validations;
6549                             end if;
6550 
6551 l_stmt_num := 722;
6552                             if v_wlji_net_quantity(v_index) is null then
6553                             begin
6554                                 select
6555                                        decode(wdj.primary_item_id, null, 0,
6556                                        decode(wdj.net_quantity,
6557                                        wdj.start_quantity, v_wlji_start_quantity(v_index),
6558                                        least(wdj.net_quantity,
6559                                        nvl(v_wlji_start_quantity(v_index), wdj.net_quantity))))
6560                                 into   v_wlji_net_quantity(v_index)
6561                                 from   wip_discrete_jobs wdj
6562                                 where  wdj.wip_entity_id  = v_wlji_wip_entity_id(v_index)
6563                                 and    wdj.organization_id  = v_wlji_org(v_index);
6564                             exception
6565                                 when others then
6566                                     l_error_code := SQLCODE;
6567                                     l_err_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
6568                                     handle_error(l_error_code, l_err_msg, l_stmt_num);
6569                                     GOTO skip_resched_validations;
6570                             end;
6571                             end if;
6572 
6573                         end if; -- job_type
6574 
6575 
6576 --validate dates
6577 l_stmt_num := 830;
6578 
6579                         if (
6580                             (v_wlji_firm_planned_flag(v_index) = 1)
6581                             AND
6582                             (
6583                             ((v_wlji_fusd(v_index) IS NOT NULL) AND (v_wlji_fusd(v_index) <> p_old_start_date))
6584                              OR
6585                              ((v_wlji_lucd(v_index) IS NOT NULL) AND (v_wlji_lucd(v_index) <> p_old_complete_date))
6586                             )
6587                         ) then
6588                             l_error_code := -1;
6589                              process_errorred_field('WSM',
6590                                                     'WSM_JOB_FIRM',
6591                                                     l_stmt_num);
6592                             GOTO skip_resched_validations;
6593                         end if;
6594 
6595                         IF (((v_wlji_fusd(v_index) IS NULL) AND (v_wlji_lucd(v_index) IS NULL)) OR
6596                             ((v_wlji_fusd(v_index) IS NOT NULL) AND (v_wlji_lucd(v_index) IS NOT NULL))) THEN
6597                             v_wlji_scheduling_method(v_index) := 3;
6598                         ELSE
6599                             v_wlji_scheduling_method(v_index) := 2;
6600                         END IF;
6601 
6602 
6603                         IF v_wlji_scheduling_method(v_index) = 3 THEN
6604                             IF (v_wlji_fusd(v_index) IS NULL) AND (v_wlji_lucd(v_index) IS NULL) THEN
6605                                 v_wlji_fusd(v_index) := p_old_start_date;
6606                                 v_wlji_lucd(v_index) := p_old_complete_date;
6607                             ELSIF ((v_wlji_fusd(v_index) > v_wlji_lucd(v_index)) OR
6608                                   ((v_wlji_fusd(v_index) <> p_old_start_date) AND
6609                                   discrete_charges_exist(v_wlji_wip_entity_id(v_index), v_wlji_org(v_index),1))) THEN
6610                                 l_aux_mesg := '';
6611                                 process_invalid_field('START DATE',
6612                                                       l_aux_mesg,
6613                                                       l_stmt_num);
6614                                 l_error_code := -1;
6615                                 GOTO skip_resched_validations;
6616                             END IF;
6617                         END IF;
6618 
6619                         IF v_wlji_scheduling_method(v_index) = 2 THEN
6620                             IF ((v_wlji_fusd(v_index) IS NOT NULL) AND (v_wlji_lucd(v_index) IS NULL)) THEN
6621                                 IF ((v_wlji_fusd(v_index) <> p_old_start_date) AND
6622                                    discrete_charges_exist(v_wlji_wip_entity_id(v_index), v_wlji_org(v_index),1)) THEN
6623                                     l_aux_mesg := '';
6624                                     process_invalid_field('START DATE',
6625                                                           l_aux_mesg,
6626                                                           l_stmt_num);
6627                                     l_error_code := -1;
6628                                     GOTO skip_resched_validations;
6629                                 ELSE
6630                                     v_wlji_lucd(v_index) := wsmputil.GET_SCHEDULED_DATE(
6631                                                             v_wlji_org(v_index),
6632                                                             v_wlji_item(v_index),
6633                                                             'F',
6634                                                             v_wlji_fusd(v_index),
6635                                                             --v_wlji_start_quantity(v_index),
6636                                                             l_error_code,
6637                                                             l_err_msg,
6638                                                             v_wlji_start_quantity(v_index));  --Fixed bug # 2313574
6639                                 END IF;
6640                             ELSIF ((v_wlji_fusd(v_index) IS NULL) AND (v_wlji_lucd(v_index) IS NOT NULL)) THEN
6641                                     v_wlji_fusd(v_index) := wsmputil.GET_SCHEDULED_DATE (
6642                                                             v_wlji_org(v_index),
6643                                                             v_wlji_item(v_index),
6644                                                             'B',
6645                                                             v_wlji_lucd(v_index),
6646                                                             --v_wlji_start_quantity(v_index),
6647                                                             l_error_code,
6648                                                             l_err_msg,
6649                                                             v_wlji_start_quantity(v_index));  --Fixed bug # 2313574
6650                             END IF;
6651                         END IF;
6652 
6653                         if l_error_code <> 0 OR l_err_msg IS NOT NULL then
6654                             HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
6655                             l_error_code := -1;
6656                             GOTO skip_resched_validations;
6657                         end if;
6658 
6659 
6660                         --validate coproducts
6661 l_stmt_num := 840;
6662 
6663                         if ((v_wlji_coproducts_supply(v_index) IS NOT NULL) and
6664                            (v_wlji_coproducts_supply(v_index) NOT IN (1,2))) then
6665                             l_aux_mesg := '';
6666                             process_invalid_field('COPRODUCTS SUPPLY',
6667                                                   l_aux_mesg,
6668                                                   l_stmt_num);
6669                             l_error_code := -1;
6670                             GOTO skip_resched_validations;
6671                         end if;
6672 
6673 << skip_resched_validations >>
6674 
6675                         if l_error_code <> 0 then
6676                             l_error_count := l_error_count + 1;
6677                             GOTO skip_other_steps;
6678                         end if;
6679 
6680 
6681                         /* -- commenting out Bug 2762029
6682                         -- setting the common routing and bill sequence id for update
6683 
6684                         if p_old_job_type = 1 then
6685                             p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6686                             p_common_bill_sequence_id := p_old_com_bom_seq_id;
6687                         end if;
6688                         */
6689 
6690                         if p_old_job_type = 3 then
6691                             if p_old_status_type = 3 then
6692                                 if p_change_bom_reference = 0 and p_change_routing_reference = 0 then
6693                                     p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6694                                     p_common_bill_sequence_id := p_old_com_bom_seq_id;
6695                                 end if;
6696                                 if p_change_bom_reference = 1 and p_change_routing_reference = 1 then
6697                                     p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6698                                     p_common_bill_sequence_id := p_old_com_bom_seq_id;
6699                                 end if;
6700                                 if p_change_bom_reference = 1 and p_change_routing_reference = 0 then
6701                                     p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6702                                     p_common_bill_sequence_id := p_old_com_bom_seq_id;
6703                                 end if;
6704                                 if p_change_bom_reference = 0 and p_change_routing_reference = 1 then
6705                                     p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6706                                     p_common_bill_sequence_id := p_old_com_bom_seq_id;
6707                                 end if;
6708                             end if;
6709 
6710                             if p_old_status_type = 1 then
6711                                 if p_change_bom_reference = 0 and p_change_routing_reference = 0 then
6712                                     p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6713                                     p_common_bill_sequence_id := p_old_com_bom_seq_id;
6714                                 end if;
6715                                 if p_change_bom_reference = 1 and p_change_routing_reference = 1 then
6716                                     --p_common_routing_sequence_id := p_common_routing_sequence_id;
6717                                     p_common_bill_sequence_id := bom_seq_id;
6718                                 end if;
6719                                 if p_change_bom_reference = 1 and p_change_routing_reference = 0 then
6720                                     --p_common_routing_sequence_id := p_common_routing_sequence_id;
6721                                     p_common_bill_sequence_id := bom_seq_id;
6722                                 end if;
6723                                 if p_change_bom_reference = 0 and p_change_routing_reference = 1 then
6724                                     --p_common_routing_sequence_id := p_common_routing_sequence_id;
6725                                     p_common_bill_sequence_id := bom_seq_id;
6726                                 end if;
6727                             end if;
6728                         end if; -- job type=3
6729 
6730                     end if; --load_type 6
6731 
6732 --************************************************************************************************
6733 --****************************** Reschedule Job Validations End **********************************
6734 --************************************************************************************************
6735 
6736 
6737 
6738 
6739 -- ==============================================================================================
6740 -- VALIDATIONS END, WRITING INTO BASE TABLES BEGIN
6741 -- ==============================================================================================
6742 
6743 -- ==============================================================================================
6744 -- WRITING INTO BASE TABLES FOR JOB CREATION
6745 -- ==============================================================================================
6746 
6747                     if v_wlji_load_type(v_index) = 5 then
6748                     -- calling the build_lbji_info with p_rtg_op_seq_num as the rtg op_seq_num null...
6749                         build_lbji_info(
6750                             p_routing_seq_id => routing_seq_id,
6751                             p_common_bill_sequence_id => bom_seq_id,
6752                             p_explode_header_detail => null,
6753                             p_status_type => v_wlji_status_type(v_index),
6754                             p_class_code => v_wlji_class_code(v_index),
6755                             p_org => v_wlji_org(v_index),
6756                             p_wip_entity_id => v_wlji_wip_entity_id(v_index),
6757                             p_last_updt_date => v_wlji_last_updt_date(v_index),
6758                             p_last_updt_by => v_wlji_last_updt_by(v_index),
6759                             p_creation_date => v_wlji_creation_date(v_index),
6760                             p_created_by => v_wlji_created_by(v_index),
6761                             p_last_updt_login => v_wlji_last_updt_login(v_index),
6762                             p_request_id => v_wlji_request_id(v_index),
6763                             p_program_application_id => v_wlji_program_application_id(v_index),
6764                             p_program_id => v_wlji_program_id(v_index),
6765                             p_prog_updt_date => v_wlji_prog_updt_date(v_index),
6766                             p_source_line_id => v_wlji_source_line_id(v_index),
6767                             p_source_code =>  v_wlji_source_code(v_index),
6768                             p_description => v_wlji_description(v_index),
6769                             p_item => v_wlji_item(v_index),
6770                             p_job_type => v_wlji_job_type(v_index),
6771                             p_bom_reference_id =>  v_wlji_bom_reference_id(v_index),
6772                             p_routing_reference_id => v_wlji_routing_reference_id(v_index),
6773                             p_firm_planned_flag => v_wlji_firm_planned_flag(v_index),
6774                             p_wip_supply_type => v_wlji_wip_supply_type(v_index),
6775                             p_fusd => v_wlji_fusd(v_index),
6776                             p_lucd => v_wlji_lucd(v_index),
6777                             p_start_quantity => v_wlji_start_quantity(v_index),
6778                             p_net_quantity => v_wlji_net_quantity(v_index),
6779                             p_coproducts_supply => v_wlji_coproducts_supply(v_index),
6780                             p_bom_revision => v_wlji_bom_revision(v_index),
6781                             p_routing_revision => v_wlji_routing_revision(v_index),
6782                             p_bom_revision_date => v_wlji_bom_revision_date(v_index),
6783                             p_routing_revision_date => v_wlji_routing_revision_date(v_index),
6784                             p_lot_number => v_wlji_lot_number(v_index),
6785                             p_alt_bom_designator => v_wlji_alt_bom_designator(v_index),
6786                             p_alt_routing_designator => v_wlji_alt_routing_designator(v_index),
6787                             p_priority => v_wlji_priority(v_index),
6788                             p_due_date => v_wlji_due_date(v_index),
6789                             p_attribute_category => v_wlji_attribute_category(v_index),
6790                             p_attribute1 => v_wlji_attribute1(v_index),
6791                             p_attribute2 => v_wlji_attribute2(v_index),
6792                             p_attribute3 => v_wlji_attribute3(v_index),
6793                             p_attribute4 => v_wlji_attribute4(v_index),
6794                             p_attribute5 => v_wlji_attribute5(v_index),
6795                             p_attribute6 => v_wlji_attribute6(v_index),
6796                             p_attribute7 => v_wlji_attribute7(v_index),
6797                             p_attribute8 => v_wlji_attribute8(v_index),
6798                             p_attribute9 => v_wlji_attribute9(v_index),
6799                             p_attribute10 => v_wlji_attribute10(v_index),
6800                             p_attribute11 => v_wlji_attribute11(v_index),
6801                             p_attribute12 => v_wlji_attribute12(v_index),
6802                             p_attribute13 => v_wlji_attribute13(v_index),
6803                             p_attribute14 => v_wlji_attribute14(v_index),
6804                             p_attribute15 => v_wlji_attribute15(v_index),
6805                             p_job_name => v_wlji_job_name(v_index),
6806                             p_completion_subinventory => v_wlji_completion_subinventory(v_index),
6807                             p_completion_locator_id => v_wlji_completion_locator_id(v_index),
6808                             p_demand_class => v_wlji_demand_class(v_index),
6809                             p_project_id => v_wlji_project_id(v_index),
6810                             p_task_id => v_wlji_task_id(v_index),
6811                             p_schedule_group_id => v_wlji_schedule_group_id(v_index),
6812                             p_build_sequence => v_wlji_build_sequence(v_index),
6813                             p_line_id => v_wlji_line_id(v_index),
6814                             p_kanban_card_id => v_wlji_kanban_card_id(v_index),
6815                             p_overcompl_tol_type => v_wlji_overcompl_tol_type(v_index),
6816                             p_overcompl_tol_value => v_wlji_overcompl_tol_value(v_index),
6817                             p_end_item_unit_number => v_wlji_end_item_unit_number(v_index),
6818                             p_rtg_op_seq_num => null,
6819                             p_src_client_server => 0,
6820                             p_po_creation_time => WSMPLCVA.v_org(v_wlji_org(v_index)).PO_CREATION_TIME,
6821                             p_date_released => v_wlji_date_released(v_index),
6822                             p_error_code => l_error_code,
6823                             p_error_msg => l_error_msg);
6824 
6825                         if l_error_code <> 0 then
6826                             handle_error(l_error_code, l_error_msg,  l_stmt_num);
6827                             l_error_count := l_error_count + 1;
6828                             GOTO skip_other_steps;
6829                         end if;
6830 
6831                     end if; -- load_type 5
6832 
6833 
6834 -- ==============================================================================================
6835 -- WRITING INTO BASE TABLES FOR JOB UPDATE
6836 -- ==============================================================================================
6837 
6838 
6839                     if v_wlji_load_type(v_index) = 6 then
6840 
6841                         -- if the user wants to update only the references, the following updates are not needed
6842                         if p_skip_updt = 0 then
6843 
6844                             if discrete_charges_exist(v_wlji_wip_entity_id(v_index), v_wlji_org(v_index),1) then
6845                                 l_txnexist := 1;
6846                             else
6847                                 l_txnexist := 0;
6848                             end if;
6849 
6850 
6851                             if v_wlji_allow_explosion(v_index) = 'Y' and v_wlji_status_type(v_index) <> 7 then
6852                             Begin
6853 l_stmt_num := 1062;
6854                                 if v_wlji_start_quantity(v_index) <> p_old_quantity then
6855                                     l_qntydiff := 1;
6856                                 else
6857                                     l_qntydiff := 0;
6858                                 end if;
6859 
6860                                 UPDATE WIP_OPERATIONS
6861                                 SET
6862                                        FIRST_UNIT_START_DATE = decode(l_txnexist,
6863                                                                       0, NVL(v_wlji_fusd(v_index), FIRST_UNIT_START_DATE),  -- bug 3394520
6864                                                                       FIRST_UNIT_START_DATE),
6865                                        FIRST_UNIT_COMPLETION_DATE = decode(l_txnexist,
6866                                                                            0, NVL(v_wlji_lucd(v_index), FIRST_UNIT_COMPLETION_DATE), -- bug 3394520
6867                                                                            FIRST_UNIT_COMPLETION_DATE),
6868                                        LAST_UNIT_START_DATE = decode(l_txnexist,
6869                                                                      0, NVL(v_wlji_fusd(v_index), LAST_UNIT_START_DATE),  -- bug 3394520
6870                                                                      LAST_UNIT_START_DATE),
6871                                        LAST_UNIT_COMPLETION_DATE = decode(l_txnexist,
6872                                                                           0, NVL(v_wlji_lucd(v_index), LAST_UNIT_COMPLETION_DATE), -- bug 3394520
6873                                                                           LAST_UNIT_COMPLETION_DATE),
6874                                        SCHEDULED_QUANTITY = ROUND(v_wlji_start_quantity(v_index), WIP_CONSTANTS.MAX_DISPLAYED_PRECISION),
6875                                        QUANTITY_IN_QUEUE = decode(v_wlji_status_type(v_index),
6876                                             1, (decode(OPERATION_SEQ_NUM,10,0,QUANTITY_IN_QUEUE)),
6877                                             3, (decode(p_old_status_type,
6878                                                     1, decode(OPERATION_SEQ_NUM,10,ROUND(v_wlji_start_quantity(v_index),
6879                                                              WIP_CONSTANTS.MAX_DISPLAYED_PRECISION), QUANTITY_IN_QUEUE),
6880                                                     decode(l_qntydiff,
6881                                                     1, decode(OPERATION_SEQ_NUM,
6882                                                               10,ROUND(v_wlji_start_quantity(v_index),WIP_CONSTANTS.MAX_DISPLAYED_PRECISION),
6883                                                               QUANTITY_IN_QUEUE),
6884                                                     QUANTITY_IN_QUEUE))),
6885                                        QUANTITY_IN_QUEUE),
6886                                        LAST_UPDATED_BY = v_wlji_last_updt_by(v_index),
6887                                        LAST_UPDATE_DATE = SYSDATE,
6888                                        LAST_UPDATE_LOGIN = v_wlji_last_updt_login(v_index),
6889                                        PROGRAM_UPDATE_DATE = SYSDATE,
6890                                        REQUEST_ID = v_wlji_request_id(v_index),
6891                                        PROGRAM_APPLICATION_ID = v_wlji_program_application_id(v_index),
6892                                        PROGRAM_ID = v_wlji_program_id(v_index)
6893                                 WHERE  ORGANIZATION_ID = v_wlji_org(v_index)
6894                                 AND    WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index);
6895 
6896                                 if lbji_debug = 'Y' then
6897                                     fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into wo');
6898                                 end if;
6899 
6900 l_stmt_num := 1063;
6901                                 UPDATE WIP_OPERATION_RESOURCES
6902                                 SET    START_DATE = decode(l_txnexist,
6903                                                            0, NVL(v_wlji_fusd(v_index), START_DATE), -- bug 3394520
6904                                                            START_DATE),
6905                                        COMPLETION_DATE =  decode(l_txnexist,
6906                                                                  0, NVL(v_wlji_lucd(v_index), COMPLETION_DATE),
6907                                                                  COMPLETION_DATE),
6908                                        LAST_UPDATED_BY = v_wlji_last_updt_by(v_index),
6909                                        LAST_UPDATE_DATE = SYSDATE,
6910                                        LAST_UPDATE_LOGIN = v_wlji_last_updt_login(v_index),
6911                                        PROGRAM_UPDATE_DATE = SYSDATE,
6912                                        REQUEST_ID = v_wlji_request_id(v_index),
6913                                        PROGRAM_APPLICATION_ID = v_wlji_program_application_id(v_index),
6914                                        PROGRAM_ID = v_wlji_program_id(v_index)
6915                                 WHERE  ORGANIZATION_ID = v_wlji_org(v_index)
6916                                 AND    WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index);
6917 
6918                                 if lbji_debug = 'Y' then
6919                                     fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into wor');
6920                                 end if;
6921 
6922 l_stmt_num := 1064;
6923                                 --LBM enh: modified the expression on required_quantity
6924                                 UPDATE WIP_REQUIREMENT_OPERATIONS WRO
6925                                 SET    WRO.DATE_REQUIRED =
6926                                        (SELECT NVL(MIN(FIRST_UNIT_START_DATE), v_wlji_fusd(v_index))
6927                                         FROM   WIP_OPERATIONS
6928                                         WHERE  ORGANIZATION_ID = v_wlji_org(v_index)
6929                                         AND    WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index)
6930                                         AND    OPERATION_SEQ_NUM = ABS(WRO.OPERATION_SEQ_NUM)),
6931                                        LAST_UPDATED_BY = v_wlji_last_updt_by(v_index),
6932                                        LAST_UPDATE_DATE = SYSDATE,
6933                                        LAST_UPDATE_LOGIN = v_wlji_last_updt_login(v_index),
6934                                        REQUEST_ID = v_wlji_request_id(v_index),
6935                                        PROGRAM_UPDATE_DATE = SYSDATE,
6936                                        PROGRAM_ID = v_wlji_program_id(v_index),
6937                                        PROGRAM_APPLICATION_ID = v_wlji_program_application_id(v_index),
6938                                        REQUIRED_QUANTITY = (QUANTITY_PER_ASSEMBLY * decode(wro.basis_type, 2, 1, ROUND(v_wlji_start_quantity(v_index), 6)))
6939                                 WHERE  ORGANIZATION_ID = v_wlji_org(v_index)
6940                                 AND    WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index);
6941 
6942                                 if lbji_debug = 'Y' then
6943                                     fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into wro');
6944                                 end if;
6945 
6946 l_stmt_num := 1065;
6947                                 -- abb H: optional scrap accounting
6948 
6949                                 if (p_old_status_type IN (1,6) and v_wlji_status_type(v_index) = 3) and
6950                                     wsmputil.WSM_ESA_ENABLED(
6951                                             p_wip_entity_id => v_wlji_wip_entity_id(v_index),
6952                                             err_code => l_error_code,
6953                                             err_msg => l_error_msg,
6954                                             p_org_id => '',
6955                                             p_job_type => '') = 1 then
6956 
6957                                     select min(operation_seq_num)
6958                                     into   min_op_seq_num
6959                                     from   wip_operations
6960                                     where  wip_entity_id =  v_wlji_wip_entity_id(v_index);
6961 
6962                                     select bd.scrap_account, bd.est_absorption_account, wo.department_id
6963                                     into   l_scrap_account10, l_est_scrap_abs_account10, l_department_id
6964                                     from   bom_departments bd, wip_operations wo
6965                                     where  wo.wip_entity_id =  v_wlji_wip_entity_id(v_index)
6966                                     and    wo.operation_seq_num = min_op_seq_num
6967                                     and    bd.department_id = wo.department_id;
6968 
6969                                     if l_scrap_account10 is null or l_est_scrap_abs_account10 is null then
6970                                         v_wlji_process_status(v_index) := 3; --ERROR
6971                                         v_wlji_err_code(v_index) := -1;
6972                                         fnd_message.set_name('WSM','WSM_NO_SCRAP_ACC');
6973                                         fnd_message.set_token('DEPT_ID',to_char(l_department_id));
6974                                         v_wlji_err_msg(v_index) := fnd_message.get;
6975                                         fnd_file.put_line(fnd_file.log, 'stmt_num: '|| l_stmt_num ||'  '||v_wlji_err_msg(v_index));
6976                                         fnd_file.new_line(fnd_file.log, 3);
6977                                         l_error_code := -1;
6978                                         l_error_count := l_error_count + 1;
6979                                         GOTO skip_other_steps;
6980                                     end if;
6981 
6982                                     UPDATE WIP_OPERATION_YIELDS WOY
6983                                            SET SCRAP_ACCOUNT = nvl(l_scrap_account10, WOY.SCRAP_ACCOUNT),
6984                                            EST_SCRAP_ABSORB_ACCOUNT = nvl(l_est_scrap_abs_account10, WOY.EST_SCRAP_ABSORB_ACCOUNT)
6985                                     WHERE  WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index)
6986                                     and    operation_seq_num = min_op_seq_num;
6987 
6988                                     if lbji_debug = 'Y' then
6989                                         fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into woy');
6990                                     end if;
6991 
6992                                     select max(operation_seq_num)
6993                                     into   max_op_seq_num
6994                                     from   wip_operations
6995                                     where  wip_entity_id = v_wlji_wip_entity_id(v_index);
6996 
6997                                     select bd.scrap_account, bd.est_absorption_account,  wo.department_id
6998                                     into   l_scrap_account9999, l_est_scrap_abs_account9999, l_department_id
6999                                     from   bom_departments bd, wip_operations wo
7000                                     where  wo.wip_entity_id =  v_wlji_wip_entity_id(v_index)
7001                                     and    wo.operation_seq_num = max_op_seq_num
7002                                     and    bd.department_id = wo.department_id;
7003 
7004                                     if l_scrap_account9999 is null or l_est_scrap_abs_account9999 is null then
7005                                         v_wlji_process_status(v_index) := 3; --ERROR
7006                                         v_wlji_err_code(v_index) := -1;
7007                                         fnd_message.set_name('WSM','WSM_NO_SCRAP_ACC');
7008                                         fnd_message.set_token('DEPT_ID',to_char(l_department_id));
7009                                         v_wlji_err_msg(v_index) := fnd_message.get;
7010                                         fnd_file.put_line(fnd_file.log, 'stmt_num: '|| l_stmt_num ||'  '||v_wlji_err_msg(v_index));
7011                                         fnd_file.new_line(fnd_file.log, 3);
7012                                         l_error_code := -1;
7013                                         l_error_count := l_error_count + 1;
7014                                         GOTO skip_other_steps;
7015                                     end if;
7016 
7017                                     UPDATE WIP_OPERATION_YIELDS WOY
7018                                            SET SCRAP_ACCOUNT = nvl(l_scrap_account9999, WOY.SCRAP_ACCOUNT),
7019                                            EST_SCRAP_ABSORB_ACCOUNT = nvl(l_est_scrap_abs_account9999, WOY.EST_SCRAP_ABSORB_ACCOUNT)
7020                                     WHERE  WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index)
7021                                     and    operation_seq_num = max_op_seq_num;
7022 
7023                                     if lbji_debug = 'Y' then
7024                                         fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into woy');
7025                                     end if;
7026 
7027                                 end if;
7028 
7029                             Exception
7030                                    when others then
7031                                    l_error_code := SQLCODE;
7032                                    l_error_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
7033                                    handle_error(l_error_code, l_error_msg,  l_stmt_num);
7034                                    l_error_count := l_error_count + 1;
7035                                    GOTO skip_other_steps;
7036                             End;
7037                             end if; -- allow_explosion
7038 
7039                         end if; --p_skip_updt
7040 l_stmt_num := 1071;
7041                         Begin
7042                             if p_old_status_type <> 1 AND v_wlji_status_type(v_index) = 1 then
7043                                 delete from wip_period_balances
7044                                 where  wip_entity_id = v_wlji_wip_entity_id(v_index)
7045                                 and    organization_id = v_wlji_org(v_index);
7046                                 if lbji_debug = 'Y' then
7047                                     fnd_file.put_line(fnd_file.log, 'Deleted '||SQL%ROWCOUNT||' rows from wpb');
7048                                 end if;
7049                             end if;
7050 
7051 l_stmt_num := 1072;
7052                             if v_wlji_status_type(v_index) = 7 then --cancelled
7053 
7054                                 -- osp begin
7055                                 if wip_osp.po_req_exists ( v_wlji_wip_entity_id(v_index),
7056                                                            null,
7057                                                            v_wlji_org(v_index),
7058                                                            null, 5) then
7059                                        fnd_message.set_name('WIP', 'WIP_CANCEL_JOB/SCHED_OPEN_PO');
7060                                        l_err_msg := fnd_message.get;
7061                                        l_warning_count := l_warning_count + 1;
7062                                        handle_warning( p_err_msg => l_err_msg,
7063                                                        p_header_id => v_wlji_header_id(v_index),
7064                                                        p_request_id => v_wlji_request_id(v_index),
7065                                                        p_program_id => v_wlji_program_id(v_index),
7066                                                        p_program_application_id => v_wlji_program_application_id(v_index));
7067                                 end if;
7068                                 -- osp end
7069 
7070                                 wip_picking_pvt.cancel_allocations(v_wlji_wip_entity_id(v_index),
7071                                                5,
7072                                                NULL,
7073                                                x_return_status,
7074                                                x_msg_data);
7075 
7076                                 if x_return_status <> FND_API.G_RET_STS_SUCCESS then
7077                                     handle_error(x_return_status, x_msg_data,  l_stmt_num);
7078                                     l_error_count := l_error_count + 1;
7079                                     GOTO skip_other_steps;
7080                                 else
7081                                     update wip_discrete_jobs wdj
7082                                     set    status_type = 7
7083                                     where  wdj.wip_entity_id = v_wlji_wip_entity_id(v_index);
7084                                     if lbji_debug = 'Y' then
7085                                         fnd_file.put_line(fnd_file.log, 'Updated status type to 7 in wdj');
7086                                     end if;
7087                     --
7088                         -- begin Bugfix 2820900 : Update the job name with sector lot extn. once canceled.
7089                     -- Note: Since status update for canceled jobs are not allowed currently, there's
7090                     -- no logic to remove the sector lot extn.
7091                     --
7092                             x_new_name := WSMPOPRN.update_job_name
7093                                         (p_wip_entity_id    => v_wlji_wip_entity_id(v_index),
7094                             p_subinventory      => v_wlji_completion_subinventory(v_index),
7095                             p_org_id        => v_wlji_org(v_index),
7096                                         p_txn_type      => 2,       -- COMPLETION
7097                                         p_update_flag       => TRUE,
7098                                         p_dup_job_name      => l_dup_job_name,
7099                                         x_error_code        => l_error_code,
7100                                         x_error_msg     => l_error_msg);
7101 
7102                    if l_error_code <> 0 then
7103                             handle_error(l_error_code, l_error_msg,  l_stmt_num);
7104                             l_error_count := l_error_count + 1;
7105                             GOTO skip_other_steps;
7106                    end if;
7107 
7108                    --
7109                    -- end bugfix 2820900
7110                    --
7111                                 end if;
7112 
7113                                 --abbKanban begin
7114                                 if v_wlji_kanban_card_id(v_index) is not null then
7115                                     inv_kanban_pvt.Update_Card_Supply_Status
7116                                             (X_Return_Status => l_returnStatus,
7117                                              p_Kanban_Card_Id => v_wlji_kanban_card_id(v_index),
7118                                              p_Supply_Status => inv_kanban_pvt.g_supply_status_Exception);
7119 
7120                                     if ( l_returnStatus <> fnd_api.g_ret_sts_success ) then
7121                                         l_error_code := -1;
7122                                         fnd_message.set_name('WSM', 'WSM_KNBN_CARD_STS_FAIL');
7123 
7124                                         select meaning
7125                                         into   translated_meaning
7126                                         from   mfg_lookups
7127                                         where  lookup_type = 'MTL_KANBAN_SUPPLY_STATUS'
7128                                         and    lookup_code = 7
7129                                         and    upper(enabled_flag) = 'Y';
7130 
7131                                         fnd_message.set_token('STATUS',translated_meaning);
7132                                         l_error_msg := fnd_message.get;
7133                                         handle_error(l_error_code, l_error_msg,  l_stmt_num);
7134                                         l_error_count := l_error_count + 1;
7135                                         GOTO skip_other_steps;
7136                                     end if;
7137 
7138                                     update wip_discrete_jobs
7139                                     set    kanban_card_id = null
7140                                     where  wip_entity_id =  v_wlji_wip_entity_id(v_index);
7141 
7142                                 end if;
7143                                 --abbKanban end
7144 
7145 
7146                             else
7147 l_stmt_num := 1073;
7148                                 -- bug 2762029 modification begin
7149                                 UPDATE      WIP_DISCRETE_JOBS WDJ
7150                                 set         last_updated_by = v_wlji_last_updt_by(v_index),
7151                                             last_update_login = v_wlji_last_updt_login(v_index),
7152                                             request_id = v_wlji_request_id(v_index),
7153                                             program_application_id = v_wlji_program_application_id(v_index),
7154                                             program_id = v_wlji_program_id(v_index),
7155                                             program_update_date = sysdate,
7156                                             last_update_date = sysdate,
7157                                             bom_reference_id = v_wlji_bom_reference_id(v_index),
7158                                             routing_reference_id = v_wlji_routing_reference_id(v_index),
7159                                             common_bom_sequence_id = p_common_bill_sequence_id,
7160                                             common_routing_sequence_id = p_common_routing_sequence_id,
7161                                             bom_revision = v_wlji_bom_revision(v_index),
7162                                             routing_revision = v_wlji_routing_revision(v_index),
7163                                             bom_revision_date = v_wlji_bom_revision_date(v_index),
7164                                             routing_revision_date = v_wlji_routing_revision_date(v_index),
7165                                             alternate_bom_designator = v_wlji_alt_bom_designator(v_index),
7166                                             alternate_routing_designator = v_wlji_alt_routing_designator(v_index),
7167                                             firm_planned_flag = v_wlji_firm_planned_flag(v_index),
7168                                             start_quantity = nvl(round(v_wlji_start_quantity(v_index), wip_constants.max_displayed_precision),
7169                                                         wdj.start_quantity),
7170                                             net_quantity = nvl(round(v_wlji_net_quantity(v_index), wip_constants.max_displayed_precision),
7171                                                         wdj.net_quantity),
7172                                             status_type = nvl(v_wlji_status_type(v_index),wdj.status_type),
7173                                             date_released = v_wlji_date_released(v_index), -- bug 2697295
7174                                             scheduled_start_date = decode(l_txnexist, 0,
7175                                                             trunc(v_wlji_fusd(v_index),'MI'), wdj.scheduled_start_date),
7176                                             scheduled_completion_date = trunc(v_wlji_lucd(v_index),'MI'),
7177                                             completion_locator_id = v_wlji_completion_locator_id(v_index),
7178                                             completion_subinventory = v_wlji_completion_subinventory(v_index),
7179                                             coproducts_supply = nvl(v_wlji_coproducts_supply(v_index), wdj.coproducts_supply),
7180                                             -- BA: BUG3272873
7181                                             source_code = nvl(v_wlji_source_code(v_index),wdj.source_code),
7182                                             source_line_id = nvl(v_wlji_source_line_id(v_index),wdj.source_line_id),
7183                                             overcompletion_tolerance_type = nvl(v_wlji_overcompl_tol_type(v_index),
7184                                                                 wdj.overcompletion_tolerance_type),
7185                                             overcompletion_tolerance_value = nvl(v_wlji_overcompl_tol_value(v_index),
7186                                                                 wdj.overcompletion_tolerance_value),
7187                                             priority = nvl(v_wlji_priority(v_index),wdj.priority),
7188                                             due_date = nvl(v_wlji_due_date(v_index),wdj.due_date),
7189                                             attribute_category = nvl(v_wlji_attribute_category(v_index),wdj.attribute_category),
7190                                             attribute1 = nvl(v_wlji_attribute1(v_index),wdj.attribute1),
7191                                             attribute2 = nvl(v_wlji_attribute2(v_index),wdj.attribute2),
7192                                             attribute3 = nvl(v_wlji_attribute3(v_index),wdj.attribute3),
7193                                             attribute4 = nvl(v_wlji_attribute4(v_index),wdj.attribute4),
7194                                             attribute5 = nvl(v_wlji_attribute5(v_index),wdj.attribute5),
7195                                             attribute6 = nvl(v_wlji_attribute6(v_index),wdj.attribute6),
7196                                             attribute7 = nvl(v_wlji_attribute7(v_index),wdj.attribute7),
7197                                             attribute8 = nvl(v_wlji_attribute8(v_index),wdj.attribute8),
7198                                             attribute9 = nvl(v_wlji_attribute9(v_index),wdj.attribute9),
7199                                             attribute10 = nvl(v_wlji_attribute10(v_index),wdj.attribute10),
7200                                             attribute11 = nvl(v_wlji_attribute11(v_index),wdj.attribute11),
7201                                             attribute12 = nvl(v_wlji_attribute12(v_index),wdj.attribute12),
7202                                             attribute13 = nvl(v_wlji_attribute13(v_index),wdj.attribute13),
7203                                             attribute14 = nvl(v_wlji_attribute14(v_index),wdj.attribute14),
7204                                             attribute15 = nvl(v_wlji_attribute15(v_index),wdj.attribute15),
7205                                             -- EA: BUG3272873
7206                                             est_scrap_account = nvl(p_est_scrap_account, wdj.est_scrap_account),
7207                                             est_scrap_var_account = nvl(p_est_scrap_var_account, wdj.est_scrap_var_account),
7208                                             description = nvl(RTRIM(v_wlji_description(v_index)), wdj.description)
7209                                             where wdj.wip_entity_id = v_wlji_wip_entity_id(v_index);
7210                                             --returning wdj.date_released into p_date_released;
7211                                 -- bug 2762029 modification end
7212                             end if; -- update jobs for which status is not cancelled
7213 
7214                             if lbji_debug = 'Y' then
7215                                 fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows of wdj');
7216                             end if;
7217 
7218 
7219 l_stmt_num := 1074;
7220                             UPDATE WIP_ENTITIES WE
7221                             set    description = nvl(v_wlji_description(v_index), we.description),
7222                                    last_updated_by = v_wlji_last_updt_by(v_index),
7223                                    last_update_login = v_wlji_last_updt_login(v_index),
7224                                    request_id = v_wlji_request_id(v_index),
7225                                    program_application_id = v_wlji_program_application_id(v_index),
7226                                    program_id = v_wlji_program_id(v_index),
7227                                    program_update_date = v_wlji_prog_updt_date(v_index),
7228                                    last_update_date = v_wlji_last_updt_date(v_index)
7229                             where  we.wip_entity_id = v_wlji_wip_entity_id(v_index);
7230 
7231                             if lbji_debug = 'Y' then
7232                                 fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into we');
7233                             end if;
7234 
7235                         Exception
7236                            when others then
7237                            l_error_code := SQLCODE;
7238                            l_error_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
7239                            handle_error(l_error_code, l_error_msg,  l_stmt_num);
7240                            l_error_count := l_error_count + 1;
7241                            GOTO skip_other_steps;
7242                         End;
7243 
7244                     end if; -- load_type 6
7245 
7246 l_stmt_num := 1080;
7247 
7248                     if (
7249                        (v_wlji_load_type(v_index) = 6 AND
7250                         v_wlji_status_type(v_index) = WIP_CONSTANTS.RELEASED and
7251                         p_old_status_type = WIP_CONSTANTS.UNRELEASED)
7252                     ) then
7253 
7254                         if ((v_wlji_load_type(v_index) = 6) AND (v_wlji_class_code(v_index) is NULL)) then
7255                             v_wlji_class_code(v_index) := p_old_class_code;
7256                         end if;
7257                         fnd_file.put_line(fnd_file.log, 'date released ****: '||v_wlji_date_released(v_index));
7258                         insert_into_period_balances (
7259                                 p_wip_entity_id =>  v_wlji_wip_entity_id(v_index),
7260                                 p_organization_id =>  v_wlji_org(v_index),
7261                                 p_class_code =>   v_wlji_class_code(v_index),
7262                                 p_release_date => v_wlji_date_released(v_index), --p_date_released,
7263                                 p_error_code => l_error_code,
7264                                 p_err_msg => l_error_msg
7265                         );
7266 
7267                         if l_error_code <> 0 then
7268                             handle_error(l_error_code, l_error_msg,  l_stmt_num);
7269                             l_error_count := l_error_count + 1;
7270                             GOTO skip_other_steps;
7271                         end if;
7272                     end if;
7273 
7274 
7275 
7276 -- ==============================================================================================
7277 --  MATERIAL TRANSACTION FOR MODE 2 JOB CREATE
7278 -- ==============================================================================================
7279 
7280 l_stmt_num := 1100;
7281                     -- *** material transaction for mode 2 jobs begin ***
7282                     if v_wlji_mode_flag(v_index) = 2 then
7283 
7284                         IF WSMPLCVA.v_org(v_wlji_org(v_index)).MAX_ORG_ACC_PERIODS is null or
7285                            WSMPLCVA.v_org(v_wlji_org(v_index)).MAX_ORG_ACC_PERIODS = 0
7286                         then
7287                              l_error_code := -1;
7288                              process_errorred_field('WIP',
7289                                                     'WIP_NO_ACCT_PERIOD',
7290                                                      l_stmt_num);
7291                             GOTO skip_mat_trans;
7292                         end if;
7293 
7294                         if WSMPLCVA.v_org(v_wlji_org(v_index)).MAX_STK_LOC_CNTRL is null then
7295                             WSMPLCVA.v_org(v_wlji_org(v_index)).MAX_STK_LOC_CNTRL := 1;
7296                         end if;
7297 
7298 l_stmt_num := 1120;
7299                         /* commented out by BBK for DUAL usage reduction.
7300                         select mtl_material_transactions_s.nextval
7301                         into txn_tmp_header_id
7302                         from dual;
7303                         */
7304 
7305 l_stmt_num := 1140;
7306                         Begin  -- material transaction
7307 
7308                             insert into mtl_material_transactions_temp(
7309                                     last_update_date,
7310                                     creation_date,
7311                                     last_updated_by,
7312                                     created_by,
7313                                     last_update_login,
7314                                     transaction_header_id,
7315                                     transaction_source_id,
7316                                     inventory_item_id,
7317                                     organization_id,
7318                                     revision,
7319                                     subinventory_code,
7320                                     locator_id,
7321                                     transaction_quantity,
7322                                     primary_quantity,
7323                                     transaction_uom,
7324                                     transaction_type_id,
7325                                     transaction_action_id,
7326                                     transaction_source_type_id,
7327                                     transaction_date,
7328                                     acct_period_id,
7329                                     source_code,
7330                                     source_line_id,
7331                                     wip_entity_type,
7332                                     negative_req_flag,
7333                                     operation_seq_num,
7334                                     wip_supply_type,
7335                                     wip_commit_flag,
7336                                     process_flag,
7337                                     posting_flag,
7338                                     transaction_temp_id)
7339                             values (
7340                                     v_wlji_last_updt_date(v_index),
7341                                     v_wlji_creation_date(v_index),
7342                                     v_wlji_last_updt_by(v_index),
7343                                     v_wlji_created_by(v_index),
7344                                     v_wlji_last_updt_login(v_index),
7345                                     txn_header_id,                                            /* TRANSACTION_HEADER_ID */
7346                                     v_wlji_wip_entity_id(v_index),                            /* TRANSACTION_SOURCE_ID */
7347                                     v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id, /* INVENTORY_ITEM_ID */
7348                                     v_wlji_org(v_index),                                      /* ORGANIZATION_ID */
7349                                     v_wsli(v_wlji_source_line_id(v_index)).revision,          /* REVISION */
7350                                     v_wsli(v_wlji_source_line_id(v_index)).subinventory_code, /* SUBINVENTORY_CODE */
7351                                     v_wsli(v_wlji_source_line_id(v_index)).locator_id,
7352                                     -l_quantity_tobe_issued,
7353                                     ---1 * v_wsli(v_wlji_source_line_id(v_index)).quantity,   /* TRANSACTION_QUANTITY */
7354                                     ---1 * v_wsli(v_wlji_source_line_id(v_index)).quantity,   /* PRIMARY_QUANTITY */
7355                                     -l_quantity_tobe_issued,
7356                                     v_wsli(v_wlji_source_line_id(v_index)).primary_uom_code,  /* UNIT_OF_MEASURE */
7357                                     35,                                                       /* TRANSACTION_TYPE_ID */
7358                                     1,                                                        /* TRANSACTION_ACTION_ID */
7359                                     5,                                                        /* TRANSACTION_SOURCE_TYPE_ID */
7360                                     SYSDATE,                                                  /* TRANSACTION_DATE */
7361                                     WSMPLCVA.v_org(v_wlji_org(v_index)).MAX_ORG_ACC_PERIODS,  /*ACCT_PERIOD_ID */
7362                                     'WSM',
7363                                     to_char(v_wlji_source_line_id(v_index)),                  /* SOURCE_LINE_ID */
7364                                     5,                                                        /* WIP_ENTITY_TYPE */
7365                                     1,                                                        /* neg req flag */
7366                                     10,                                                       /* op seq */
7367                                     '',                                                       /* supply type */
7368                                     'N',                                                      /* WIP_COMMIT_FLAG */
7369                                     'Y',                                                      /* PROCESS_FLAG */
7370                                     'Y',                                                      /* POSTING_FLAG */
7371                                     -- txn_tmp_header_id                                      /* Transaction Temp Id */
7372                                     mtl_material_transactions_s.nextval                       /* Transaction Temp Id */
7373                                     ) RETURNING transaction_temp_id into txn_tmp_header_id;
7374 
7375                             if lbji_debug = 'Y' then
7376                                 fnd_file.put_line(fnd_file.log, 'Inserted '||SQL%ROWCOUNT||' rows into mmtt');
7377                             end if;
7378 
7379 l_stmt_num := 1160;
7380 
7381                             INSERT INTO MTL_TRANSACTION_LOTS_TEMP (
7382                                     transaction_temp_id,
7383                                     last_update_date,
7384                                     creation_date,
7385                                     last_updated_by,
7386                                     created_by,
7387                                     last_update_login,
7388                                     transaction_quantity,
7389                                     primary_quantity,
7390                                     lot_number)
7391                             values (
7392                             txn_tmp_header_id,
7393                                     v_wlji_last_updt_date(v_index),
7394                                     v_wlji_creation_date(v_index),
7395                                     v_wlji_last_updt_by(v_index),
7396                                     v_wlji_created_by(v_index),
7397                                     v_wlji_last_updt_login(v_index),
7398                                     -l_quantity_tobe_issued,
7399                                     ---1 * v_wsli(v_wlji_source_line_id(v_index)).quantity,
7400                                     ---1 * v_wsli(v_wlji_source_line_id(v_index)).quantity,
7401                                     -l_quantity_tobe_issued,
7402                                     v_wsli(v_wlji_source_line_id(v_index)).lot_number);
7403 
7404                             if lbji_debug = 'Y' then
7405                                 fnd_file.put_line(fnd_file.log, 'Inserted '||SQL%ROWCOUNT||' rows into mtlt');
7406                             end if;
7407 
7408 l_stmt_num := 1160;
7409                             UPDATE WIP_REQUIREMENT_OPERATIONS
7410                             set    wip_supply_type = 1
7411                             where  wip_entity_id = v_wlji_wip_entity_id(v_index)
7412                             and    operation_seq_num = 10
7413                             and    inventory_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id;
7414 
7415 
7416                         Exception  -- material transaction
7417                             when others then
7418                                 l_error_code := SQLCODE;
7419                                 l_error_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
7420                                 handle_error(l_error_code, l_error_msg,  l_stmt_num);
7421                                 GOTO skip_mat_trans;
7422                         End; -- material transaction
7423 
7424 << skip_mat_trans >>
7425 
7426                         if l_error_code <> 0 then
7427                             l_error_count := l_error_count + 1;
7428                             GOTO skip_other_steps;
7429                         end if;
7430 
7431                         l_atleast_one_row_in_mmtt := l_atleast_one_row_in_mmtt + 1;
7432                         l_src_lot_number:=v_wsli(v_wlji_source_line_id(v_index)).lot_number;        -- LOTATTR
7433                         l_src_inv_item_id:=v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id;    -- LOTATTR
7434 
7435                     end if; -- for mode 2
7436                     -- *** material transaction for mode 2 jobs end ***
7437 
7438                     /* LotAttr */
7439                     IF p_old_status_type in (0,1,3,6) THEN  -- Initialized Value,
7440                                 --Unreleased, released, Hold
7441 l_stmt_num := 1170;
7442                         IF (lbji_debug='Y') THEN
7443                             fnd_file.put_line(fnd_file.log, 'Before Calling WSM_LotAttr_PVT.create_update_lotattr');
7444                         END IF;
7445                         WSM_LotAttr_PVT.create_update_lotattr(
7446                                 x_err_code          => l_error_code,
7447                                 x_err_msg           => l_error_msg,
7448                                 p_wip_entity_id     => v_wlji_wip_entity_id(v_index),
7449                                 p_org_id            => v_wlji_org(v_index),
7450                                 p_intf_txn_id       => v_wlji_header_id(v_index),
7451                                 p_intf_src_code     => 'WSM',
7452                                 p_src_lot_number    => l_src_lot_number,
7453                                 p_src_inv_item_id   => l_src_inv_item_id);
7454                         IF (l_error_code <> 0) THEN
7455                             handle_error(l_error_code, l_error_msg,  l_stmt_num);
7456                             l_error_count := l_error_count + 1;
7457                             GOTO skip_other_steps;
7458                         END IF;
7459                         IF (lbji_debug='Y') THEN
7460                            fnd_file.put_line(fnd_file.log, 'WSM_LotAttr_PVT.create_update_lotattr returned Success');
7461                         END IF;
7462 l_stmt_num := 1180;
7463                     END IF; -- p_old_status_type in (1,3,6)
7464 
7465                 EXCEPTION -- main block
7466                     when others then
7467                         l_error_code := SQLCODE;
7468                         l_error_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
7469                         handle_error(l_error_code, l_error_msg,  l_stmt_num);
7470                         l_error_count := l_error_count + 1;
7471 
7472                 END; -- main block
7473 
7474 <<skip_other_steps>>
7475 
7476 
7477                 -- *** write into output file ***
7478                 -- note that this is a rudimentary piece of commentary on the job created,
7479                 -- or failed to create because there's no customer requirement on this.
7480                 if v_wlji_load_type(v_index) = 5 then
7481                     fnd_file.put_line(fnd_file.output, '-------------------------------------------------------');
7482                     --bug 5051783:Replaced org_organization_definitions with mtl_parameters.
7483                     select organization_code
7484                     into   org_code
7485                     --from   ORG_ORGANIZATION_DEFINITIONS
7486                     from   mtl_parameters
7487                     where  organization_id = v_wlji_org(v_index);
7488 
7489                     fnd_file.put_line(fnd_file.output, 'Organization: '||org_code);
7490                     fnd_file.put_line(fnd_file.output, 'Job_name: '|| v_wlji_job_name(v_index));
7491                     select meaning
7492                     into   job_type_meaning
7493                     from   mfg_lookups
7494                     where  lookup_type = 'WIP_DISCRETE_JOB'
7495                     and    lookup_code = v_wlji_job_type(v_index);
7496                     fnd_file.put_line(fnd_file.output, 'Job Type: '|| job_type_meaning);
7497 
7498                     begin
7499                         select unique(concatenated_segments)
7500                         into   assembly_name
7501                         from   mtl_system_items_kfv
7502                         where  inventory_item_id = v_wlji_item(v_index)
7503                         and    organization_id = v_wlji_org(v_index);
7504                     exception
7505                         when others then
7506                             assembly_name := 'Unknown';
7507                     end;
7508                     fnd_file.put_line(fnd_file.output, 'Assembly: '|| assembly_name);
7509                     fnd_file.put_line(fnd_file.output, 'Quantity: '|| v_wlji_start_quantity(v_index));
7510                     fnd_file.put_line(fnd_file.output, 'Start Date: '|| v_wlji_fusd(v_index));
7511                     fnd_file.put_line(fnd_file.output, 'Completion Date: '|| v_wlji_lucd(v_index));
7512                     fnd_file.put_line(fnd_file.output, 'Kanban Card: '|| v_wlji_kanban_card_id(v_index));
7513                     if v_wlji_process_status(v_index) <> 3 then
7514                         status_name := 'Success';
7515                     else
7516                         status_name := 'Falied To Create';
7517                     end if;
7518                     fnd_file.put_line(fnd_file.output, 'Process Status: '|| Status_name);
7519                     if v_wlji_process_status(v_index) = 3 then
7520                     fnd_file.put_line(fnd_file.output, v_wlji_err_msg(v_index));
7521                     end if;
7522                     fnd_file.put_line(fnd_file.output, '-------------------------------------------------------');
7523                 end if; -- load type 5
7524                 -- *** write into output file end***
7525 
7526 
7527 
7528 
7529                 -- *** mark the rows without error to be deleted ***
7530 
7531                 if v_wlji_err_code(v_index) <> 0 then
7532                     rollback to row_skip;
7533                 end if;
7534 
7535                 if v_wlji_process_status(v_index) <> 3 then
7536                     v_wlji_process_status(v_index) := 5; -- 5 : complete without error
7537                     if lbji_debug = 'Y' then
7538                         fnd_file.put_line(fnd_file.log, 'Everything OK, changing the status of the row to 5..');
7539                     end if;
7540                 else
7541                     -- abbkanban begin
7542                     if v_wlji_kanban_card_id(v_index) is not null then
7543                         inv_kanban_pvt.Update_Card_Supply_Status(
7544                                 X_Return_Status => l_returnStatus,
7545                                 p_Kanban_Card_Id => v_wlji_kanban_card_id(v_index),
7546                                 p_Supply_Status => inv_kanban_pvt.g_supply_status_Exception);
7547 
7548                         if ( l_returnStatus <> fnd_api.g_ret_sts_success ) then
7549                             l_error_code := -1;
7550                             fnd_message.set_name('WSM', 'WSM_KNBN_CARD_STS_FAIL');
7551                             select meaning
7552                             into   translated_meaning
7553                             from   mfg_lookups
7554                             where  lookup_type = 'MTL_KANBAN_SUPPLY_STATUS'
7555                             and    lookup_code = 7
7556                             and    upper(enabled_flag) = 'Y';
7557 
7558                             fnd_message.set_token('STATUS',translated_meaning);
7559                             l_error_msg := fnd_message.get;
7560                             handle_error(l_error_code, l_error_msg,  l_stmt_num);
7561                             l_error_count := l_error_count + 1;
7562                         end if;
7563 
7564                         update wip_discrete_jobs
7565                         set    kanban_card_id = null
7566                         where  wip_entity_id =  v_wlji_wip_entity_id(v_index);
7567 
7568                     end if;
7569                     -- abbkanban end
7570 
7571                     dummy_err_code := 0;
7572                     dummy_err_msg := NULL;
7573                     wsmputil.WRITE_TO_WIE (
7574                         v_wlji_header_id(v_index),
7575                         substr(v_wlji_err_msg(v_index),1,2000),
7576                         v_wlji_request_id(v_index),
7577                         v_wlji_program_id(v_index),
7578                         v_wlji_program_application_id(v_index),
7579                         1,
7580                         dummy_err_code,
7581                         dummy_err_msg );
7582 
7583                     if dummy_err_code <> 0 then
7584                         fnd_file.put_line(fnd_file.log, '*** WARNING ***');
7585                         fnd_file.put_line(fnd_file.log, 'WSMPLBJI.launch_worker: '||dummy_err_msg);
7586                         l_error_count := l_error_count + 1;
7587                     end if;
7588                 end if;
7589 
7590                 v_index := v_wlji_header_id.next(v_index);
7591 
7592             end loop; -- inner loop
7593 
7594             if lbji_debug = 'Y' then
7595                 fnd_file.put_line(fnd_file.log, '                    ');
7596                 fnd_file.put_line(fnd_file.log, '                    ');
7597                 fnd_file.put_line(fnd_file.log, '                    ');
7598                 fnd_file.put_line(fnd_file.log, '                    ');
7599             end if;
7600 
7601             -- *** RETCODE return values ***
7602             --      0: success
7603             --      1: success with warning
7604             --      2: error
7605             -- *** RETCODE return values ***
7606 
7607             if l_warning_count <> 0 then
7608                 retcode := 1;
7609                 errbuf := 'The interface process produced atleast one warning message';
7610                 fnd_file.put_line(fnd_file.log,errbuf);
7611                 conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7612             end if;
7613 
7614             if l_error_count <> 0 then
7615                 retcode := 1;
7616                 errbuf := 'The interface process marked atleast one row as errored';
7617                 fnd_file.put_line(fnd_file.log,errbuf);
7618                 conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7619             end if;
7620 
7621             -- *** bulk update wsm_lot_job_interface ***
7622             forall i in v_wlji_process_status.first..v_wlji_process_status.last
7623             update  wsm_lot_job_interface
7624             set     process_status = v_wlji_process_status(i),
7625                     error_code = v_wlji_err_code(i),
7626                     error_msg = v_wlji_err_msg(i),
7627                     request_id = v_wlji_request_id(i),
7628                     program_id = v_wlji_program_id(i),
7629                     program_application_id = v_wlji_program_application_id(i)
7630             where   header_id = v_wlji_header_id(i);
7631 
7632             l_boolean_success := false;
7633 
7634             if l_atleast_one_row_in_mmtt <>0 THEN
7635                 fnd_file.put_line(fnd_file.log, 'Invoking Inventory Worker with header id: '||to_char(txn_header_id));
7636                 l_inv_worker_req_id := FND_REQUEST.submit_request (
7637                                     'INV', 'INCTCW', NULL, NULL, FALSE,
7638                                     --to_char(txn_header_id), '1', NULL, NULL); -- bug 3733798
7639                                     to_char(txn_header_id), '4', NULL, NULL);   -- bug 3733798
7640 
7641                 commit;
7642 
7643                 fnd_file.put_line(fnd_file.log,'Material Transaction temp_header_id is '
7644                             ||to_char(txn_header_id));
7645 
7646                 if l_inv_worker_req_id = 0 then
7647 
7648                     retcode := 1;
7649                     errbuf:= 'WSMPLBJI. Inventory worker returned failure '||
7650                              '(Transaction_header_id=' ||txn_header_id||') : '|| SUBSTRB(SQLERRM,1,1000);
7651                     fnd_file.put_line(fnd_file.log,errbuf);
7652                     conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7653                     update  wsm_lot_job_interface
7654                     set     process_status = 4,
7655                             error_code = -2,
7656                             error_msg = l_error_msg
7657                     where   mode_flag = 2;
7658 
7659                 else -- req_id <> 0
7660 
7661                     fnd_file.put_line(fnd_file.log,'Inventory Transaction Worker request_id is '
7662                             ||to_char(l_inv_worker_req_id));
7663                     req_wait := FND_CONCURRENT.WAIT_FOR_REQUEST
7664                             (request_id => l_inv_worker_req_id,
7665                              interval => 10, -- 10 seconds interval
7666                              max_wait => 36000, -- 10 Hours maximum wait.
7667                              phase => req_phase,
7668                              status => req_status,
7669                              dev_phase => req_devphase,
7670                              dev_status => req_devstatus,
7671                              message => req_message);
7672 
7673                     fnd_file.put_line(fnd_file.log, 'Inventory Transaction Worker status is '
7674                                                                                             ||req_status);
7675                     fnd_file.put_line(fnd_file.log, 'Inventory Transaction Worker Completion Message: '
7676                                                                                             ||req_message);
7677 
7678                     if  req_devphase <> 'COMPLETE' OR  req_devstatus <> 'NORMAL' THEN
7679                         retcode := 1;
7680                         errbuf:= 'WSMPLBJI. Inventory worker returned failure '||
7681                                  '(Transaction_header_id=' ||txn_header_id||') : '||
7682                                  SUBSTRB(SQLERRM,1,1000);
7683                         fnd_file.put_line(fnd_file.log,errbuf);
7684                         conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7685                     end if;
7686 
7687                     check_errored_mmtt_records(txn_header_id, l_error_code, l_error_msg);
7688 
7689                     if (l_error_code <> 0) or (l_error_msg is not null ) then
7690                         retcode := 1;
7691                         errbuf:= 'WSMPLBJI. Errored Records in mmtt ' ||
7692                                  '(Transaction_header_id=' ||txn_header_id||') : '|| SUBSTRB(SQLERRM,1,1000);
7693                         fnd_file.put_line(fnd_file.log,errbuf);
7694                         conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7695                     end if;
7696 
7697                 end if;  -- req_id
7698             end if; -- l_atleast_one_row_in_mmtt
7699 
7700 
7701             -- *** delete marked rows (without error rows) from wlji ***
7702             Begin
7703                 -- bug 3126758
7704                 l_del_int_prof_value := fnd_profile.value('WSM_INTERFACE_HISTORY_DAYS');
7705 
7706                 if l_atleast_one_row_in_mmtt <> 0 then
7707                     delete  from wsm_starting_lots_interface
7708                     where   header_id IN
7709                             (select wlji.source_line_id
7710                             from    wsm_lot_job_interface wlji
7711                             where   wlji.process_status = 5
7712                             --and     wlji.group_id = batch_group_id
7713                             and     NVL(transaction_date, creation_date)
7714                                         <= decode(l_del_int_prof_value,
7715                                                   null,
7716                                                   NVL(transaction_date, creation_date) -1,
7717                                                   SYSDATE-l_del_int_prof_value)
7718                             );
7719 
7720                     if lbji_debug = 'Y' then
7721                         fnd_file.put_line(fnd_file.log, 'Deleted '||SQL%ROWCOUNT||' rows from wsli');
7722                     end if;
7723                 end if;
7724 
7725                 delete  from wsm_lot_job_interface
7726                 where   process_status = 5
7727                 --and     group_id = batch_group_id
7728                 and     NVL(transaction_date, creation_date)
7729                             <= decode(l_del_int_prof_value,
7730                                       null,
7731                                       NVL(transaction_date, creation_date) -1,
7732                                       SYSDATE-l_del_int_prof_value);
7733 
7734                 if lbji_debug = 'Y' then
7735                     fnd_file.put_line(fnd_file.log, 'Deleted '||SQL%ROWCOUNT||' rows from wlji');
7736                 end if;
7737 
7738             Exception
7739                 when others then
7740                     retcode := 1;
7741                     errbuf := 'Deletion of successful rows from interface table(s) failed';
7742                     fnd_file.put_line(fnd_file.log,errbuf);
7743                     conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7744             End;
7745 
7746             commit;
7747 
7748         end if; -- if c_wlji_1%rowcount - prev_rowcount <> 0 then process data
7749 
7750         prev_rowcount := c_wlji_1%rowcount;
7751         exit when c_wlji_1%rowcount = alotted_rows;
7752 
7753     end loop; -- main loop
7754     close c_wlji_1;
7755 
7756     -- osp begin
7757     if l_atleast_one_osp_exists <> 0 then
7758         l_req_request_id := fnd_request.submit_request(
7759                 'PO', 'REQIMPORT', NULL, NULL, FALSE,'WIP', NULL, 'ITEM',
7760                 NULL ,'N', 'Y' , chr(0), NULL, NULL, NULL,
7761                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7762                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7763                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7764                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7765                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7766                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7767                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7768                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7769                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
7770         ) ;
7771 
7772         fnd_file.put_line(fnd_file.log,'Concurrent Request for Requisition Inport Submitted');
7773         fnd_file.put_line(fnd_file.log,'Request_id: '||l_req_request_id);
7774     end if;
7775     -- osp end
7776 
7777     -- phantom project
7778     delete from bom_explosion_temp where group_id = wsmpwrot.explosion_group_id;
7779     wsmpwrot.explosion_group_id := null;
7780     wsmpwrot.use_phantom_routings := null;
7781 
7782     commit;
7783 
7784     if l_error_count = 0 then
7785         retcode := 0;
7786         errbuf := '';
7787         conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('SUCCESS',errbuf);
7788     end if;
7789 
7790 
7791 EXCEPTION  -- for launch_worker
7792     when abort_request then
7793         rollback to back_to_square_one;
7794         retcode := 2;
7795         errbuf := 'WSMLBJIB.launch_worker_1159: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,240);
7796         fnd_file.put_line(fnd_file.log,errbuf);
7797         conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR',errbuf);
7798     when others then
7799         rollback to back_to_square_one;
7800         retcode := 2;
7801         errbuf := 'WSMLBJIB.launch_worker_1159: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,240);
7802         fnd_file.put_line(fnd_file.log,errbuf);
7803         conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR',errbuf);
7804 
7805 END launch_worker_1159;
7806 
7807 END WSMPLBJI;