DBA Data[Home] [Help]

PACKAGE BODY: APPS.WSMPLBJI

Source


1 PACKAGE BODY WSMPLBJI AS
2 /* $Header: WSMLBJIB.pls 120.12.12020000.2 2013/03/26 09:02:53 kswarna ship $ */
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                         /* for bug fix 16327585 */
2175                         OR EXISTS (SELECT 'X'
2176                                    FROM MTL_MATERIAL_TRANSACTIONS
2177                                    WHERE ORGANIZATION_ID = p_organization_id
2178                                    AND TRANSACTION_SOURCE_TYPE_ID = 5
2179                                    AND TRANSACTION_SOURCE_ID = p_wip_entity_id
2180                                    AND COSTED_FLAG IN ('N', 'E')));
2181 --check for only shop floor transactions
2182 
2183 cursor check_discrete_charges_1 is
2184         SELECT  DISTINCT 'X'
2185         FROM    WIP_DISCRETE_JOBS DJ, WIP_PERIOD_BALANCES WPB
2186         WHERE   DJ.WIP_ENTITY_ID = WPB.WIP_ENTITY_ID
2187                 AND DJ.ORGANIZATION_ID = WPB.ORGANIZATION_ID
2188                 AND DJ.WIP_ENTITY_ID = p_wip_entity_id
2189                 AND DJ.ORGANIZATION_ID = p_organization_id
2190                 AND (DJ.QUANTITY_COMPLETED <> 0
2191                         OR DJ.QUANTITY_SCRAPPED <> 0
2192                         OR WPB.TL_RESOURCE_IN <> 0
2193                         OR WPB.TL_OVERHEAD_IN <> 0
2194                         OR WPB.TL_OUTSIDE_PROCESSING_IN <> 0
2195                         OR WPB.PL_RESOURCE_IN <> 0
2196                         OR WPB.PL_OVERHEAD_IN <> 0
2197                         OR WPB.PL_OUTSIDE_PROCESSING_IN <> 0
2198                         OR WPB.TL_RESOURCE_OUT <> 0
2199                         OR WPB.TL_OVERHEAD_OUT <> 0
2200                         OR WPB.TL_OUTSIDE_PROCESSING_OUT <> 0
2201                         OR WPB.PL_RESOURCE_OUT <> 0
2202                         OR WPB.PL_OVERHEAD_OUT <> 0
2203                         OR WPB.PL_OUTSIDE_PROCESSING_OUT <> 0
2204                         OR EXISTS (SELECT 'X'
2205                                    FROM   WIP_MOVE_TXN_INTERFACE
2206                                    WHERE  ORGANIZATION_ID = p_organization_id
2207                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2208                         OR EXISTS (SELECT 'X'
2209                                    FROM   WSM_LOT_MOVE_TXN_INTERFACE
2210                                    WHERE  ORGANIZATION_ID = p_organization_id
2211                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2212                         OR EXISTS (SELECT 'X'
2213                                    FROM   WIP_COST_TXN_INTERFACE
2214                                    WHERE  ORGANIZATION_ID = p_organization_id
2215                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2216                         OR EXISTS (SELECT 'X'
2217                                    FROM   WIP_MOVE_TRANSACTIONS
2218                                    WHERE  ORGANIZATION_ID = p_organization_id
2219                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2220                         -- CZH check WLT also
2221                         OR EXISTS (SELECT 'X'
2222                                    FROM   WSM_SM_RESULTING_JOBS
2223                                    WHERE  ORGANIZATION_ID = p_organization_id
2224                                    AND    WIP_ENTITY_ID = p_wip_entity_id)
2225                         OR EXISTS (SELECT 'X'
2226                                    FROM   WIP_OPERATION_RESOURCES
2227                                    WHERE  ORGANIZATION_ID = p_organization_id
2228                                    AND    WIP_ENTITY_ID = p_wip_entity_id
2229                                    AND    APPLIED_RESOURCE_UNITS <> 0));
2230 BEGIN
2231 
2232     retnvalue := FALSE;
2233 
2234     if (p_check_mode = 1) then
2235         open check_discrete_charges_1;
2236         fetch check_discrete_charges_1 into charges_exist;
2237 
2238         IF (check_discrete_charges_1%FOUND) THEN
2239                 retnvalue := TRUE;
2240                 close  check_discrete_charges_1;
2241                 RETURN retnvalue;
2242         ELSE
2243                 close  check_discrete_charges_1;
2244         END IF;
2245 
2246     else
2247         open check_discrete_charges;
2248         fetch check_discrete_charges into charges_exist;
2249 
2250         IF (check_discrete_charges%FOUND) THEN
2251                 retnvalue := TRUE;
2252                 close  check_discrete_charges;
2253                 RETURN retnvalue;
2254         ELSE
2255                 close  check_discrete_charges;
2256         END IF;
2257 
2258     end if;
2259 
2260     RETURN retnvalue;
2261 
2262 END discrete_charges_exist;
2263 
2264 
2265 
2266 
2267 
2268 
2269 --***********************************************************************************************
2270 -- ==============================================================================================
2271 -- PROCEDURE insert_into_period_balances
2272 -- ==============================================================================================
2273 --***********************************************************************************************
2274 
2275 
2276 PROCEDURE insert_into_period_balances(
2277         p_wip_entity_id     IN NUMBER,
2278         p_organization_id   IN NUMBER,
2279         p_class_code        IN VARCHAR2,
2280         p_release_date      IN DATE,
2281         p_error_code        OUT NOCOPY NUMBER,
2282         p_err_msg           OUT NOCOPY VARCHAR2 ) IS
2283 
2284 x_user_id       NUMBER := FND_GLOBAL.USER_ID;
2285 x_login_id      NUMBER := FND_GLOBAL.LOGIN_ID;
2286 l_cnt           NUMBER;     -- bug 3571360
2287 --l_inv_period_id number;   -- bug 3126650
2288 
2289 BEGIN
2290 
2291     -- BD: bugfix 3299811, this is a regression of bugfix 3126650
2292     --l_inv_period_id := wsmputil.get_inv_acct_period (
2293     --        x_err_code         => p_error_code,
2294     --        x_err_msg          => p_err_msg,
2295     --        p_organization_id  => p_organization_id,
2296     --        p_date             => trunc(nvl(p_release_date, sysdate)) );
2297     --if(p_error_code <> 0) then
2298     --    p_error_code := -1;
2299     --    fnd_message.set_name('WIP', 'WIP_NO_ACCT_PERIOD');
2300     --    fnd_message.set_token('FLD_NAME','Wip Accounting Period');
2301     --    p_err_msg := fnd_message.get;
2302     --    return;
2303     --end if;
2304     -- ED: bugfix 3299811
2305 
2306     insert into wip_period_balances (
2307             acct_period_id,
2308             wip_entity_id,
2309             last_update_date,
2310             last_updated_by,
2311             creation_date,
2312             created_by,
2313             last_update_login,
2314             organization_id,
2315             class_type,
2316             tl_resource_in,
2317             tl_overhead_in,
2318             tl_outside_processing_in,
2319             pl_material_in,
2320             pl_material_overhead_in,
2321             pl_resource_in,
2322             pl_overhead_in,
2323             pl_outside_processing_in,
2324             tl_material_out,
2325             tl_resource_out,
2326             tl_overhead_out,
2327             tl_outside_processing_out,
2328             pl_material_out,
2329             pl_material_overhead_out,
2330             pl_resource_out,
2331             pl_overhead_out,
2332             pl_outside_processing_out,
2333             pl_material_overhead_var,
2334             pl_material_var,
2335             pl_outside_processing_var,
2336             pl_overhead_var,
2337             pl_resource_var,
2338             tl_material_var,
2339             tl_outside_processing_var,
2340             tl_overhead_var,
2341             tl_resource_var,
2342             tl_material_overhead_out,
2343             tl_material_overhead_var)
2344     select  oap.acct_period_id,
2345             p_wip_entity_id,
2346             sysdate, x_user_id,
2347             sysdate, x_user_id, x_login_id,
2348             p_organization_id, wc.class_type,
2349             0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2350             0, 0, 0, 0, 0, 0, 0, 0
2351      from   org_acct_periods oap,
2352             wip_accounting_classes wc
2353      where  wc.class_code = p_class_code
2354      and    wc.organization_id = p_organization_id
2355      and    oap.organization_id = p_organization_id
2356      and    oap.schedule_close_date >=
2357                  trunc(inv_le_timezone_pub.get_le_day_for_inv_org(
2358                         nvl(p_release_date, sysdate),
2359                         p_organization_id))
2360      and    oap.period_close_date is null
2361      and    not exists (
2362                  select 'balance record already there'
2363                  from   wip_period_balances wpb
2364                  where  wpb.wip_entity_id = p_wip_entity_id
2365                  and    wpb.acct_period_id = oap.acct_period_id
2366                  and    wpb.organization_id = oap.organization_id);
2367 
2368     l_cnt := SQL%ROWCOUNT;      -- bug 3571360
2369 
2370     -- BD: bugfix 3299811, this is a regression of bugfix 3126650
2371     --select  l_inv_period_id,
2372     --        p_wip_entity_id,
2373     --        sysdate, x_user_id,
2374     --        sysdate, x_user_id, x_login_id,
2375     --        p_organization_id,
2376     --        wc.class_type,
2377     --        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2378     --        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2379     --        0, 0, 0, 0, 0, 0, 0, 0
2380     --from    wip_accounting_classes wc
2381     --where   wc.class_code = p_class_code
2382     --and     wc.organization_id = p_organization_id
2383     --and     not exists (
2384     --             select 'balance record already there'
2385     --             from   wip_period_balances wpb
2386     --             where  wpb.wip_entity_id = p_wip_entity_id
2387     --             and    wpb.acct_period_id = l_inv_period_id
2388     --             and    wpb.organization_id = p_organization_id);
2389     -- ED: bugfix 3299811
2390 
2391 
2392     if lbji_debug = 'Y' then
2393         fnd_file.put_line(fnd_file.log, 'Inserted '|| l_cnt ||' rows into wip_period_balances');
2394     end if;
2395 
2396     --if SQL%NOTFOUND then      -- bug 3571360
2397     if l_cnt <= 0 then          -- bug 3571360
2398         p_error_code := -1;
2399         fnd_message.set_name('WIP', 'WIP_NO_ACCT_PERIOD');
2400         fnd_message.set_token('FLD_NAME','Wip Accounting Period');
2401         p_err_msg := fnd_message.get;
2402     end if;
2403 
2404 exception
2405         when others then
2406                 p_err_msg := 'WSMPLBJI.insert_into_period_balances: '|| substr(SQLERRM,1,200);
2407                 p_error_code := SQLCODE;
2408 
2409 end insert_into_period_balances;
2410 
2411 
2412 
2413 
2414 --***********************************************************************************************
2415 -- ==============================================================================================
2416 -- PROCESS_INVALID_FIELD
2417 -- ==============================================================================================
2418 --***********************************************************************************************
2419 
2420 
2421 -- ==============================================================================================
2422 -- this is called to display message of WSM_INVALID_FIELD type.
2423 -- sets the process_status to 3, sets values of error_code and error_message,
2424 -- writes into fnd log and calls write_to_wie
2425 -- ==============================================================================================
2426 
2427 PROCEDURE process_invalid_field (
2428         p_fld          IN VARCHAR2,
2429         aux_string     IN VARCHAR2,
2430         stmt_number    IN NUMBER) IS
2431 
2432 x_err_msg  VARCHAR2(2000) := NULL;
2433 
2434 BEGIN
2435 
2436       v_wlji_process_status(v_index) := 3;
2437       v_wlji_err_code(v_index) := -1;
2438       fnd_message.set_name('WSM','WSM_INVALID_FIELD');
2439       fnd_message.set_token('FLD_NAME', p_fld);
2440       x_err_msg :=  fnd_message.get;
2441       v_wlji_err_msg(v_index) := x_err_msg;
2442       fnd_file.put_line(fnd_file.log, 'stmt_num: '|| stmt_number||'  '||x_err_msg||' '||aux_string);
2443       fnd_file.new_line(fnd_file.log, 3);
2444 
2445 
2446 END process_invalid_field;
2447 
2448 
2449 
2450 --***********************************************************************************************
2451 -- ==============================================================================================
2452 -- PROCESS_ERRORRED_FIELD
2453 -- ==============================================================================================
2454 --***********************************************************************************************
2455 
2456 -- ==============================================================================================
2457 -- this is called to display message of any type which does not involve setting any token
2458 -- sets the process_status to 3, sets values of error_code and error_message,
2459 -- writes into fnd log and calls write_to_wie
2460 -- ==============================================================================================
2461 
2462 PROCEDURE process_errorred_field(
2463         p_product      IN VARCHAR2,
2464         p_message_name IN VARCHAR2,
2465         stmt_number    IN NUMBER) IS
2466 
2467 x_err_msg  VARCHAR2(2000) := NULL;
2468 
2469 BEGIN
2470         v_wlji_process_status(v_index) := 3; --ERROR
2471         v_wlji_err_code(v_index) := -1;
2472         fnd_message.set_name(p_product, p_message_name);
2473         x_err_msg :=  fnd_message.get;
2474         v_wlji_err_msg(v_index) := x_err_msg;
2475         fnd_file.put_line(fnd_file.log, 'stmt_num: '|| stmt_number||'  '||x_err_msg);
2476         fnd_file.new_line(fnd_file.log, 3);
2477 
2478 
2479 END process_errorred_field;
2480 
2481 
2482 --***********************************************************************************************
2483 -- ==============================================================================================
2484 -- HANDLE_ERROR
2485 -- ==============================================================================================
2486 --***********************************************************************************************
2487 
2488 
2489 PROCEDURE handle_error  (
2490         p_err_code     IN NUMBER,
2491         p_err_msg      IN VARCHAR2,
2492         stmt_number    IN NUMBER) IS
2493 
2494 BEGIN
2495         v_wlji_process_status(v_index) := 3; --ERROR
2496         v_wlji_err_code(v_index) := p_err_code;
2497         v_wlji_err_msg(v_index) := substr(p_err_msg,1,2000);
2498         fnd_file.put_line(fnd_file.log, 'stmt_num: ' || stmt_number||'  '||p_err_msg);
2499         fnd_file.new_line(fnd_file.log, 3);
2500 
2501 END handle_error;
2502 
2503 
2504 --***********************************************************************************************
2505 -- ==============================================================================================
2506 -- HANDLE_WARNING
2507 -- ==============================================================================================
2508 --***********************************************************************************************
2509 
2510 
2511 PROCEDURE handle_warning(
2512         p_err_msg                      IN      VARCHAR2,
2513         p_header_id                    IN      NUMBER,
2514         p_request_id                   IN      NUMBER,
2515         p_program_id                   IN      NUMBER,
2516         p_program_application_id       IN      NUMBER) IS
2517 
2518 dummy_err_code number;
2519 dummy_err_msg varchar2(2000);
2520 
2521 BEGIN
2522         fnd_file.new_line(fnd_file.log, 1);
2523         fnd_file.put_line(fnd_file.log, '*** WARNING MESSAGE BEGIN ***');
2524         fnd_file.put_line(fnd_file.log, p_err_msg);
2525         fnd_file.put_line(fnd_file.log, '*** WARNING MESSAGE END ***');
2526         fnd_file.new_line(fnd_file.log, 1);
2527         wsmputil.WRITE_TO_WIE (
2528                  p_header_id,
2529                  substr(p_err_msg,1,2000),
2530                  p_request_id,
2531                  p_program_id,
2532                  p_program_application_id,
2533                  2,
2534                  dummy_err_code,
2535                  dummy_err_msg );
2536 END handle_warning;
2537 
2538 
2539 
2540 
2541 --***********************************************************************************************
2542 -- ==============================================================================================
2543 -- OVERLOADED PROCESS_INTERFACE_ROWS
2544 -- ==============================================================================================
2545 --***********************************************************************************************
2546 
2547 PROCEDURE  process_interface_rows (
2548         retcode         OUT NOCOPY NUMBER,
2549         errbuf          OUT NOCOPY VARCHAR2 ) IS
2550 begin
2551 
2552         process_interface_rows (retcode, errbuf, '');
2553 
2554 end process_interface_rows;
2555 
2556 
2557 
2558 --***********************************************************************************************
2559 -- ==============================================================================================
2560 -- FUNCTION honor_kanban_size
2561 -- ==============================================================================================
2562 --***********************************************************************************************
2563 
2564 -- This function should ideally return either 1 or 2 for every kanban (i.e. pull sequence)
2565 -- 1 => honor kanban size limitations
2566 -- 2 => do not honor kanban size limitations
2567 -- This is of course applicable when the user chooses a starting lot for creating a kanban
2568 -- replenishment order, because, otherwise, the order is always created for the kanban size.
2569 -- If a starting lot is chosen, the work order can be of any arbitrary size. If the api returns
2570 -- 1, and if the job quantity exceeds the kanban size, the job quantity is truncated to match the
2571 -- kanban size. E.g. Say kanba size is 20. User chooses an inv lot of quantity 1000, component per
2572 -- is 2, i.e. a work order is generated for 500. If this api returns 1, the work order will be
2573 -- generated for 20 only.
2574 -- Ideally, the option to specify a value for this parameter should be provided when the user creates
2575 -- a pull sequence. For DM_FP I user will see this as an option on wsm parameters screen. Thus of all
2576 -- the parameters passed to the api, only the organization id will be used to query wsm_parameters.
2577 
2578 function  honor_kanban_size (
2579         p_org_id            IN NUMBER,
2580         p_item_id           IN NUMBER,
2581         p_subinv            IN VARCHAR2,
2582         p_locator_id        IN NUMBER,
2583         p_kanban_plan_id    IN NUMBER)
2584 return number is
2585     l_hon_kanban_size number;
2586 begin
2587 
2588     select honor_kanban_size
2589     into   l_hon_kanban_size
2590     from   wsm_parameters
2591     where  organization_id = p_org_id;
2592 
2593     if l_hon_kanban_size is null then
2594         return 2;
2595     else
2596         return l_hon_kanban_size;
2597     end if;
2598 
2599 exception
2600     when others then
2601         return 2;
2602 
2603 end honor_kanban_size;
2604 
2605 
2606 --***********************************************************************************************
2607 -- ==============================================================================================
2608 -- PROCESS_LBJI_ROWS_1159
2609 -- ==============================================================================================
2610 --***********************************************************************************************
2611 
2612 -- This is the old process_interface_rows, retained to support Option A
2613 -- This procedure will not be called for Release 12.
2614 
2615 PROCEDURE  process_lbji_rows_1159 (
2616         retcode         OUT NOCOPY NUMBER,
2617         errbuf          OUT NOCOPY VARCHAR2,
2618         p_group_id      IN  NUMBER) IS
2619 
2620 cursor c_pir is
2621         select  header_id
2622         from    wsm_lot_job_interface
2623         where   process_status = wip_constants.pending
2624 --      and     group_id is null
2625         and     creation_date <= sysdate+1
2626         and     load_type in (5,6)
2627         order by job_name, organization_id;  -- CZH: this will group the job together
2628 
2629 
2630 x_header           NUMBER;
2631 l_group_id         NUMBER;
2632 l_reqid            NUMBER ;
2633 l_stmt_num         NUMBER;
2634 conc_status        BOOLEAN;
2635 alotted_rows       NUMBER := 0;
2636 row_count          NUMBER := 0;
2637 total_no_rows      NUMBER := 0;
2638 no_rows_per_worker NUMBER := 30;
2639 l_user_id          NUMBER;
2640 l_resp_id          NUMBER;
2641 l_resp_appl_id     NUMBER;
2642 
2643 BEGIN
2644 
2645     fnd_file.put_line(fnd_file.log, 'Processing Interface rows..');
2646 
2647     retcode := 0;       -- bugfix 2845397: set the code to 0 (success)
2648 
2649     l_user_id := fnd_global.USER_ID;
2650     l_resp_id := fnd_global.RESP_ID;
2651     l_resp_appl_id := fnd_global.RESP_APPL_ID;
2652 
2653     fnd_global.apps_initialize(l_user_id, l_resp_id, l_resp_appl_id) ;
2654 
2655     if p_group_id is null then
2656 
2657         select  count(*)
2658         into    total_no_rows
2659         from    wsm_lot_job_interface
2660         where   process_status = wip_constants.pending
2661         --and   group_id is null
2662         and     creation_date <= sysdate+1
2663         and     load_type in (5,6);
2664 
2665         if mod(total_no_rows, no_of_workers) = 0 then
2666             no_rows_per_worker := total_no_rows / no_of_workers;
2667         else
2668             no_rows_per_worker := floor(total_no_rows / no_of_workers) + 1;
2669         end if;
2670 
2671         if no_rows_per_worker < batch_size then
2672             no_rows_per_worker := batch_size;
2673         end if;
2674 
2675         fnd_file.put_line(fnd_file.log, 'Total Pending Rows = '||total_no_rows);
2676         fnd_file.put_line(fnd_file.log, 'Number of Workers = '||no_of_workers);
2677         fnd_file.put_line(fnd_file.log, 'Batch Size = '||batch_size);
2678         fnd_file.put_line(fnd_file.log, 'Number of Rows per worker = '||no_rows_per_worker);
2679 
2680         select wsm_lot_job_interface_s.NEXTVAL
2681         into   l_group_id
2682         from   dual;
2683 
2684         open c_pir;
2685         loop
2686 
2687             fetch c_pir into x_header;
2688 
2689             if c_pir%notfound and (c_pir%rowcount - row_count) = 0 then exit; end if;
2690 
2691             if not c_pir%notfound then
2692                 update  wsm_lot_job_interface wlji
2693                 set     wlji.group_id =  l_group_id,
2694                         wlji.process_status = wip_constants.running
2695                 where   header_id = x_header;
2696             end if;
2697 
2698             if (c_pir%rowcount - row_count) = no_rows_per_worker or c_pir%notfound then
2699                 alotted_rows := c_pir%rowcount - row_count;
2700 
2701                 row_count := c_pir%rowcount;
2702 
2703                 l_reqid := FND_REQUEST.SUBMIT_REQUEST (
2704                               application   => 'WSM',
2705                               program       => 'WSMLNCHW',
2706                               sub_request   => FALSE,
2707                               argument1     => l_group_id,
2708                               argument2     => alotted_rows);
2709                 if l_reqid = 0 then
2710                     rollback;
2711                 else
2712                     commit;
2713                 end if;
2714 
2715                 fnd_file.put_line(fnd_file.log, 'Request_id: '||l_reqid||' submitted');
2716 
2717                 if c_pir%notfound then exit; end if;
2718 
2719                 if  not c_pir%notfound then
2720                     select wsm_lot_job_interface_s.NEXTVAL
2721                     into   l_group_id
2722                     from   dual;
2723                 end if;
2724 
2725             end if;
2726 
2727         end loop;
2728         close c_pir;
2729 
2730     else -- p_group_id is not null
2731     -- note that in that case only one worker will be launched, i.e. the benefits of
2732     -- parallelization will not be realized. Hence it's advisable not to use the import lot
2733     -- job program to process rows with a specific group id unless the number of such rows is very small.
2734 
2735         select  count(*)
2736         into    total_no_rows
2737         from    wsm_lot_job_interface
2738         where   process_status = wip_constants.pending
2739         and     group_id = p_group_id
2740         and     creation_date <= sysdate+1
2741         and     load_type in (5,6);
2742 
2743         if total_no_rows > 0 then
2744 
2745             update  wsm_lot_job_interface wlji
2746             set     wlji.process_status = wip_constants.running
2747             where   group_id = p_group_id;
2748 
2749             l_reqid :=  FND_REQUEST.SUBMIT_REQUEST (
2750                               application   => 'WSM',
2751                               program       => 'WSMLNCHW',
2752                               sub_request   => FALSE,
2753                               argument1     => p_group_id,
2754                               argument2     => total_no_rows);
2755 
2756             if l_reqid = 0 then
2757                 rollback;
2758             else
2759                 commit;
2760             end if;
2761 
2762             fnd_file.put_line(fnd_file.log, 'Request_id: '||l_reqid||' submitted');
2763 
2764         else -- total_no_rows <= 0
2765                 fnd_file.put_line(fnd_file.log, 'No Rows found in interface table');
2766         end if;
2767 
2768     end if; -- group_id
2769 
2770 
2771 EXCEPTION
2772 
2773     when others then
2774         retcode := 1;
2775         errbuf := 'WSMLBJIB.process_lbji_rows_1159: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,240);
2776         fnd_file.put_line(fnd_file.log,errbuf);
2777         conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR',errbuf);
2778 
2779 END process_lbji_rows_1159 ;
2780 
2781 
2782 --***********************************************************************************************
2783 -- ==============================================================================================
2784 -- LAUNCH WORKER_1159
2785 -- ==============================================================================================
2786 --***********************************************************************************************
2787 
2788 PROCEDURE  launch_worker_1159 (
2789         retcode         OUT NOCOPY NUMBER,
2790         errbuf          OUT NOCOPY VARCHAR2,
2791         l_group_id      IN  NUMBER,
2792         alotted_rows    IN  NUMBER  ) IS
2793 
2794 -- ==============================================================================================
2795 -- cursors used to bulk bind data from wlji to PL/SQL tables
2796 -- ==============================================================================================
2797 cursor c_wlji_1 is
2798 select
2799         error_code,
2800         error_msg,
2801         last_update_date,
2802         request_id,
2803         program_id,
2804         program_application_id,
2805         last_updated_by,
2806         creation_date,
2807         created_by,
2808         last_update_login,
2809         program_update_date,
2810         last_updated_by_name,
2811         created_by_name,
2812         organization_id,
2813         primary_item_id,
2814         header_id,
2815         process_status,
2816         routing_reference_id,
2817         completion_subinventory,
2818         completion_locator_id,
2819         mode_flag,
2820         group_id,
2821         load_type,
2822         status_type,
2823         last_unit_completion_date,
2824         old_completion_date,
2825         bom_reference_id,
2826         bom_revision_date,
2827         routing_revision_date,
2828         wip_supply_type,
2829         class_code,
2830         lot_number,
2831         job_name,
2832         description,
2833         firm_planned_flag,
2834         alternate_routing_designator,
2835         alternate_bom_designator,
2836         demand_class,
2837         start_quantity,
2838         old_start_quantity,
2839         wip_entity_id,
2840         error,
2841         process_phase,
2842         first_unit_start_date,
2843         first_unit_completion_date,
2844         last_unit_start_date,
2845         scheduling_method,
2846         routing_revision,
2847         bom_revision,
2848         schedule_group_id,
2849         schedule_group_name,
2850         build_sequence,
2851         net_quantity,
2852         allow_explosion,
2853         old_status_type,
2854         interface_id,
2855         coproducts_supply,
2856         source_code,
2857         source_line_id,
2858         process_type,
2859         processing_work_days,
2860         daily_production_rate,
2861         line_id,
2862         lot_control_code,
2863         repetitive_schedule_id,
2864         parent_group_id,
2865         attribute_category,
2866         attribute1,
2867         attribute2,
2868         attribute3,
2869         attribute4,
2870         attribute5,
2871         attribute6,
2872         attribute7,
2873         attribute8,
2874         attribute9,
2875         attribute10,
2876         attribute11,
2877         attribute12,
2878         attribute13,
2879         attribute14,
2880         attribute15,
2881         organization_code,
2882         line_code,
2883         primary_item_segments,
2884         bom_reference_segments,
2885         routing_reference_segments,
2886         completion_locator_segments,
2887         project_id,
2888         project_name,
2889         task_id,
2890         delivery_id,
2891         descriptive_flex_segments,
2892         project_number,
2893         task_number,
2894         project_costed,
2895         end_item_unit_number,
2896         overcompletion_tolerance_type,
2897         overcompletion_tolerance_value,
2898         kanban_card_id,
2899         priority,
2900         due_date,
2901         task_name,
2902         job_type,
2903         date_released        --bugfix 2697295
2904 from    wsm_lot_job_interface
2905 where   group_id = l_group_id
2906 and     process_status = 2 -- WIP_CONSTANTS.running;
2907 order by organization_id,
2908          priority,
2909          due_date;
2910 
2911 -- ==============================================================================================
2912 -- other variables
2913 -- ==============================================================================================
2914 
2915 txn_header_id                   NUMBER;
2916 txn_tmp_header_id               NUMBER;
2917 
2918 l_source_item_rev               VARCHAR2(3);
2919 --l_source_item_rev_date        date;           -- Del: bug 2963225
2920 l_rev_control_code              number;         -- Add: bug 2963225
2921 l_start_lot_revision            number;         -- Add: bug 2963225
2922 l_rev_sysdate                   DATE;
2923 l_last_update_date              DATE := SYSDATE;
2924 l_request_id                    NUMBER := fnd_global.conc_request_id;
2925 l_program_id                    NUMBER := fnd_global.conc_program_id;
2926 l_program_application_id        NUMBER := fnd_global.prog_appl_id;
2927 l_user                          NUMBER := FND_GLOBAL.user_id;
2928 l_login                         NUMBER := FND_GLOBAL.login_id;
2929 l_creation_date                 DATE := sysdate;
2930 l_prog_updt_date                DATE := sysdate;
2931 conc_status                     BOOLEAN;
2932 l_default_subinventory          VARCHAR2(10);
2933 l_default_compl_loc_id          NUMBER;
2934 l_segs                          VARCHAR2(10000);
2935 l_loc_success                   BOOLEAN;
2936 l_sub_loc_control               NUMBER;
2937 l_org_loc_control               NUMBER;
2938 l_item_loc_control              NUMBER;
2939 l_restrict_locators_code        NUMBER;
2940 l_del_int_prof_value            number;
2941 
2942 l_error_code                    NUMBER := 0;
2943 l_return_value                  NUMBER := 0;
2944 l_error_msg                     VARCHAR2(2000) := NULL;
2945 translated_meaning              varchar2(240);
2946 l_error_count                   NUMBER := 0;
2947 l_warning_count                 NUMBER := 0;
2948 x_return_status                 VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
2949 l_returnStatus                  VARCHAR2(1);
2950 x_msg_data                      VARCHAR2(2000);
2951 
2952 l_boolean_success               BOOLEAN := false;
2953 l_inv_worker_req_id             NUMBER := 0;
2954 req_phase                       VARCHAR2(2000);
2955 req_status                      VARCHAR2(2000);
2956 req_devphase                    VARCHAR2(2000);
2957 req_devstatus                   VARCHAR2(2000);
2958 req_message                     VARCHAR2(1000);
2959 req_wait                        BOOLEAN;
2960 
2961 l_atleast_one_row_in_mmtt       NUMBER := 0;
2962 
2963 dummy_err_code                  NUMBER;
2964 dummy_err_msg                   VARCHAR2(2000);
2965 
2966 l_stmt_num                      NUMBER;
2967 
2968 l_item_id                       NUMBER;
2969 l_sub                           VARCHAR2(10);
2970 l_revision                      VARCHAR2(3);
2971 l_quantity                      NUMBER;
2972 l_build_sequence                NUMBER;
2973 l_line_id                       NUMBER;
2974 l_schedule_group_id             NUMBER;
2975 p_date_released                 DATE;
2976 p_old_date_released             DATE;
2977 l_department_id                 NUMBER;
2978 p_est_scrap_account             NUMBER;
2979 p_est_scrap_var_account         NUMBER;
2980 
2981 p_old_primary_item_id           NUMBER;
2982 p_old_class_code                VARCHAR2(10);
2983 p_old_start_date                DATE;
2984 p_old_complete_date             DATE;
2985 p_old_quantity                  NUMBER;
2986 p_old_net_quantity              NUMBER;
2987 p_old_bom_revision              varchar2(3);
2988 p_old_routing_revision          varchar2(3);
2989 p_skip_updt                     NUMBER;
2990 p_old_status_type               NUMBER;
2991 p_old_firm_planned_flag         NUMBER;
2992 p_old_job_type                  NUMBER;
2993 dummy_number                    NUMBER;
2994 dummy_varchar                   VARCHAR2(3);
2995 dummy_date                      DATE;
2996 p_change_bom_alt                NUMBER; -- bug 2762029
2997 p_change_routing_alt            NUMBER; -- bug 2762029
2998 p_change_alt_flag               NUMBER; -- bug 2762029
2999 p_change_bom_reference          NUMBER;
3000 p_change_routing_reference      NUMBER;
3001 p_old_bom_reference_id          NUMBER;
3002 p_old_alt_bom_designator        VARCHAR2(10);
3003 p_old_routing_reference_id      NUMBER;
3004 p_old_alt_routing_designator    VARCHAR2(10);
3005 p_old_bom_revision_date         DATE;
3006 p_old_routing_revision_date     DATE;
3007 p_old_com_rtg_seq_id            NUMBER;
3008 p_old_com_bom_seq_id            NUMBER;
3009 p_old_supply_type               NUMBER;
3010 p_coproducts_supply             NUMBER;
3011 p_scheduled_start_date          DATE;
3012 p_scheduled_completion_date     DATE;
3013 p_old_completion_subinv         varchar2(10);
3014 p_old_completion_locator        number;
3015 temp_start_quantity             NUMBER;
3016 temp_fusd                       DATE;
3017 temp_lucd                       DATE;
3018 temp_supply                     NUMBER;
3019 
3020 xst                             BOOLEAN := true;
3021 l_no_of_records                 NUMBER := 0;
3022 l_aux_mesg                      VARCHAR2(240):= NULL;
3023 str                             VARCHAR2(100);
3024 hash_value                      NUMBER;
3025 l_dummy                         NUMBER := 0;
3026 l_err_msg                       VARCHAR2(2000):= NULL;
3027 
3028 l_locator_id                    NUMBER;
3029 l_job_type                      NUMBER;
3030 l_rev_date                      DATE;
3031 l_date_text                     VARCHAR2(100);
3032 l_component_quantity            NUMBER;
3033 l_kanban_size                   NUMBER;
3034 l_qoh                           NUMBER;
3035 l_att                           NUMBER;
3036 l_atr                           NUMBER;
3037 l_component_yield_factor        NUMBER;
3038 l_required_quantity             NUMBER;
3039 l_quantity_tobe_issued          NUMBER;
3040 l_start_op_seq_id               NUMBER;
3041 l_start_seq_id                  NUMBER;
3042 l_end_seq_id                    NUMBER;
3043 l_txnexist                      NUMBER;
3044 l_qntydiff                      NUMBER;
3045 mtl_locator_type                NUMBER;
3046 l_src_lot_number                wsm_starting_lots_interface.lot_number%type;
3047 l_src_inv_item_id               NUMBER;
3048 l_comp_basis_type               NUMBER ;  --LBM enh: - basis type null=Item, 2=Lot based. defaults to null=Item.
3049 
3050 -- abb H
3051 min_op_seq_num                  NUMBER;
3052 max_op_seq_num                  NUMBER;
3053 l_scrap_account10               NUMBER;
3054 l_est_scrap_abs_account10       NUMBER;
3055 l_scrap_account9999             NUMBER;
3056 l_est_scrap_abs_account9999     NUMBER;
3057 l_temp_cc                       VARCHAR2(10);
3058 
3059 invalid_id_error                EXCEPTION;
3060 invalid_job_name_error          EXCEPTION;
3061 abort_request                   EXCEPTION;
3062 build_job_exception             EXCEPTION;
3063 update_job_exception            EXCEPTION;
3064 invalid_qnty_error              EXCEPTION;
3065 
3066 prev_rowcount                   NUMBER := 0;
3067 aReturnBoolean                  BOOLEAN := false;
3068 
3069 batch_group_id                  NUMBER;
3070 l_rtg_rev_date                  DATE;    --ADD: CZH.I_OED-1
3071 l_bom_rev_date                  DATE;    --ADD: BUGFIX 2380517
3072 
3073 v_load_wsli                     BOOLEAN;
3074 l_req_request_id                number;
3075 l_osp_op_seq_num                NUMBER; -- OSP FP I
3076 
3077 job_type_meaning                VARCHAR2(30);
3078 assembly_name                   VARCHAR2(40);
3079 status_name                     VARCHAR2(30);
3080 org_code                        VARCHAR2(3);
3081 
3082 -- bugfix 2820900:  Added new variables
3083 
3084 x_new_name      varchar2(240);
3085 l_dup_job_name      varchar2(240);
3086 
3087 -- end bugfix 2820900
3088 
3089 BEGIN   -- for launch_worker
3090 
3091     retcode := 0;       -- bugfix 2845397: set the code to 0 (success)
3092 
3093     SAVEPOINT back_to_square_one;
3094 
3095 -- ==============================================================================================
3096 -- bulk fetching data into PL/SQL tables for ease of validation
3097 -- ==============================================================================================
3098 
3099     begin
3100 
3101 l_stmt_num := 1;
3102         WSMPLCVA.load_org_table;
3103 
3104 l_stmt_num := 2;
3105         WSMPLCVA.load_subinventory;
3106 
3107 l_stmt_num := 3;
3108         WSMPLCVA.load_class_code;
3109 
3110         if lbji_debug = 'Y' then
3111             fnd_file.put_line(fnd_file.log, 'loading org/subinv/class-code values into memory (once per worker).. Success.');
3112         end if;
3113 
3114     exception
3115         when others then
3116             raise abort_request;
3117     end;
3118 
3119 -- ==============================================================================================
3120 -- bulk fetching data from wlji to PL/SQL tables
3121 -- ==============================================================================================
3122 
3123 l_stmt_num := 40;
3124     open c_wlji_1;
3125     loop  -- main loop
3126 
3127         v_load_wsli  := true; --i.e. run the load wsli routine for every batch
3128 
3129         fetch c_wlji_1 bulk collect into
3130             v_wlji_err_code,
3131             v_wlji_err_msg,
3132             v_wlji_last_updt_date,
3133             v_wlji_request_id,
3134             v_wlji_program_id,
3135             v_wlji_program_application_id,
3136             v_wlji_last_updt_by,
3137             v_wlji_creation_date,
3138             v_wlji_created_by,
3139             v_wlji_last_updt_login,
3140             v_wlji_prog_updt_date,
3141             v_wlji_last_updt_by_name,
3142             v_wlji_created_by_name,
3143             v_wlji_org,
3144             v_wlji_item,
3145             v_wlji_header_id,
3146             v_wlji_process_status,
3147             v_wlji_routing_reference_id,
3148             v_wlji_completion_subinventory,
3149             v_wlji_completion_locator_id,
3150             v_wlji_mode_flag,
3151             v_wlji_group_id,
3152             v_wlji_load_type,
3153             v_wlji_status_type,
3154             v_wlji_lucd,
3155             v_wlji_old_completion_date,
3156             v_wlji_bom_reference_id,
3157             v_wlji_bom_revision_date,
3158             v_wlji_routing_revision_date,
3159             v_wlji_wip_supply_type,
3160             v_wlji_class_code,
3161             v_wlji_lot_number,
3162             v_wlji_job_name,
3163             v_wlji_description,
3164             v_wlji_firm_planned_flag,
3165             v_wlji_alt_routing_designator,
3166             v_wlji_alt_bom_designator,
3167             v_wlji_demand_class,
3168             v_wlji_start_quantity,
3169             v_wlji_old_start_quantity,
3170             v_wlji_wip_entity_id,
3171             v_wlji_error,
3172             v_wlji_process_phase ,
3173             v_wlji_fusd,
3174             v_wlji_fucd,
3175             v_wlji_last_unit_start_date,
3176             v_wlji_scheduling_method,
3177             v_wlji_routing_revision ,
3178             v_wlji_bom_revision ,
3179             v_wlji_schedule_group_id,
3180             v_wlji_schedule_group_name,
3181             v_wlji_build_sequence ,
3182             v_wlji_net_quantity ,
3183             v_wlji_allow_explosion ,
3184             v_wlji_old_status_type,
3185             v_wlji_interface_id ,
3186             v_wlji_coproducts_supply,
3187             v_wlji_source_code,
3188             v_wlji_source_line_id,
3189             v_wlji_process_type,
3190             v_wlji_processing_work_days,
3191             v_wlji_daily_production_rate,
3192             v_wlji_line_id,
3193             v_wlji_lot_control_code,
3194             v_wlji_repetitive_schedule_id,
3195             v_wlji_parent_group_id,
3196             v_wlji_attribute_category,
3197             v_wlji_attribute1,
3198             v_wlji_attribute2,
3199             v_wlji_attribute3,
3200             v_wlji_attribute4 ,
3201             v_wlji_attribute5 ,
3202             v_wlji_attribute6 ,
3203             v_wlji_attribute7 ,
3204             v_wlji_attribute8 ,
3205             v_wlji_attribute9 ,
3206             v_wlji_attribute10 ,
3207             v_wlji_attribute11 ,
3208             v_wlji_attribute12 ,
3209             v_wlji_attribute13 ,
3210             v_wlji_attribute14 ,
3211             v_wlji_attribute15 ,
3212             v_wlji_organization_code,
3213             v_wlji_line_code ,
3214             v_wlji_primary_item_segments,
3215             v_wlji_bom_reference_segments,
3216             v_wlji_rtg_ref_segs,
3217             v_wlji_compl_locator_segments,
3218             v_wlji_project_id ,
3219             v_wlji_project_name ,
3220             v_wlji_task_id ,
3221             v_wlji_delivery_id ,
3222             v_wlji_desc_flx_sgmts,
3223             v_wlji_project_number ,
3224             v_wlji_task_number ,
3225             v_wlji_project_costed ,
3226             v_wlji_end_item_unit_number,
3227             v_wlji_overcompl_tol_type,
3228             v_wlji_overcompl_tol_value,
3229             v_wlji_kanban_card_id ,
3230             v_wlji_priority ,
3231             v_wlji_due_date ,
3232             v_wlji_task_name,
3233             v_wlji_job_type,
3234             v_wlji_date_released   --bugfix 2697295
3235         limit batch_size;
3236 
3237         if lbji_debug = 'Y' then
3238             fnd_file.put_line(fnd_file.log, 'no of rows loaded for the current batch: '||c_wlji_1%rowcount);
3239         end if;
3240 
3241         if c_wlji_1%rowcount - prev_rowcount <> 0 then
3242 
3243             -- do the procesing --
3244 -- ==============================================================================================
3245 -- getting the header_id to be populated for mmtt
3246 -- ==============================================================================================
3247 
3248             select mtl_material_transactions_s.nextval
3249             into   txn_header_id
3250             from   dual;
3251 
3252 -- ==============================================================================================
3253 -- updating the group_id column of wlji with a number unique for this particular batch. This'll
3254 -- help when I select corresponding rows from wsli.
3255 -- ==============================================================================================
3256 l_stmt_num := 78;
3257 
3258             select wsm_lot_job_interface_s.NEXTVAL
3259             into   batch_group_id
3260             from   dual;
3261 
3262             forall indx in v_wlji_header_id.first..v_wlji_header_id.last
3263             update wsm_lot_job_interface
3264             set    group_id = batch_group_id
3265             where  header_id = v_wlji_header_id(indx);
3266 
3267             fnd_file.put_line(fnd_file.output, '         ----  Lot Based Job Creation  ----         ');
3268             fnd_file.put_line(fnd_file.output, ' ');
3269             fnd_file.put_line(fnd_file.output, ' ');
3270 
3271 -- ==============================================================================================
3272 -- processing of data begins here
3273 -- ==============================================================================================
3274 l_stmt_num := 80;
3275 
3276             v_index := v_wlji_header_id.first;
3277             while v_index <= v_wlji_header_id.last
3278             loop  -- inner loop
3279 
3280                 if lbji_debug = 'Y' then
3281                     fnd_file.put_line(fnd_file.log,'***************************************************************');
3282                     fnd_file.put_line(fnd_file.log,'new job ... wlji header_id: '||v_wlji_header_id(v_index));
3283                     fnd_file.put_line(fnd_file.log,'        ... job name: '||v_wlji_job_name(v_index));
3284                     fnd_file.put_line(fnd_file.log,'***************************************************************');
3285                 end if;
3286 
3287                 SAVEPOINT row_skip;
3288 
3289                 BEGIN  -- main block
3290 
3291                     routing_seq_id := '';
3292                     bom_seq_id := '';
3293                     dummy_err_code := 0;
3294                     dummy_err_msg := NULL;
3295                     l_error_code := 0;
3296                     l_return_value := 0;
3297                     l_error_msg:= NULL;
3298                     x_return_status:= FND_API.G_RET_STS_SUCCESS;
3299                     l_returnStatus :=  FND_API.G_RET_STS_SUCCESS;
3300                     l_dummy:= 0;
3301                     xst:= true;
3302                     str := '';
3303                     hash_value := 0;
3304                     l_no_of_records:= 0;
3305                     l_err_msg:= NULL;
3306                     l_aux_mesg:= NULL;
3307                     l_default_subinventory := '';
3308                     l_default_compl_loc_id := 0;
3309                     l_segs := '';
3310                     l_loc_success := true;
3311                     l_sub_loc_control := 0;
3312                     l_org_loc_control := 0;
3313                     l_item_loc_control := 0;
3314                     l_restrict_locators_code := 0;
3315                     l_item_id := 0;
3316                     l_sub := '';
3317                     l_revision := '';
3318                     l_quantity := 0;
3319                     l_locator_id := 0;
3320                     l_rev_date := '';
3321                     l_date_text := '';
3322                     l_component_quantity := 0;
3323                     l_qoh := 0;
3324                     l_att := 0;
3325                     l_atr := 0;
3326                     l_component_yield_factor := 0;
3327                     l_required_quantity := 0;
3328                     l_quantity_tobe_issued := 0;
3329                     l_start_op_seq_id := 0;
3330                     l_start_seq_id := 0;
3331                     l_end_seq_id := 0;
3332                     p_date_released := '';
3333                     p_old_date_released := '';
3334                     p_common_bill_sequence_id := 0;
3335                     p_common_routing_sequence_id := 0;
3336                     p_old_primary_item_id := 0;
3337                     p_old_class_code := '';
3338                     p_old_start_date := '';
3339                     p_old_complete_date := '';
3340                     p_est_scrap_account := NULL;
3341                     p_est_scrap_var_account := NULL;
3342                     p_old_quantity := 0;
3343                     p_old_bom_revision := '';
3344                     p_old_routing_revision := '';
3345                     p_old_net_quantity := 0;
3346                     p_skip_updt:=0;
3347                     p_old_status_type := 0;
3348                     l_department_id := 0;
3349                     p_old_firm_planned_flag := 0;
3350                     p_old_job_type:= 0;
3351                     dummy_number:=0;
3352                     dummy_varchar:='';
3353                     dummy_date:=sysdate;
3354                     p_change_bom_reference:=0;
3355                     p_change_routing_reference:=0;
3356                     p_change_bom_alt:=0;
3357                     p_change_routing_alt:=0;
3358                     p_change_alt_flag:=0;
3359                     p_old_bom_reference_id:=0;
3360                     p_old_alt_bom_designator:='';
3361                     p_old_routing_reference_id:=0;
3362                     p_old_alt_routing_designator:='';
3363                     p_old_bom_revision_date:='';
3364                     p_old_routing_revision_date:='';
3365                     p_old_com_rtg_seq_id:=0;
3366                     p_old_com_bom_seq_id:=0;
3367                     p_old_supply_type:=0;
3368                     p_scheduled_start_date:='';
3369                     p_scheduled_completion_date:='';
3370                     p_old_completion_subinv:='';
3371                     p_old_completion_locator:='';
3372                     p_coproducts_supply:='';
3373                     temp_start_quantity:=0;
3374                     temp_fusd:='';
3375                     temp_lucd:='';
3376                     temp_supply:=0;
3377                     l_build_sequence := 0;
3378                     l_line_id := 0;
3379                     l_schedule_group_id := 0;
3380                     l_src_lot_number:=NULL;
3381                     l_src_inv_item_id:=NULL;
3382 
3383                     -- abb H
3384                     min_op_seq_num:=0;
3385                     max_op_seq_num:=0;
3386                     l_scrap_account10:=NULL;
3387                     l_est_scrap_abs_account10:=NULL;
3388                     l_scrap_account9999:=NULL;
3389                     l_est_scrap_abs_account9999:=NULL;
3390 
3391                     v_wlji_err_code(v_index)                := l_error_code;
3392                     v_wlji_err_msg(v_index)                 := l_error_msg;
3393                     v_wlji_last_updt_date(v_index)          := l_last_update_date;
3394                     v_wlji_request_id(v_index)              := l_request_id;
3395                     v_wlji_program_id(v_index)              := l_program_id;
3396                     v_wlji_program_application_id(v_index)  := l_program_application_id;
3397                     v_wlji_creation_date(v_index)           := l_creation_date;
3398                     v_wlji_last_updt_login(v_index)         := l_login;
3399                     v_wlji_prog_updt_date(v_index)          := l_prog_updt_date;
3400 
3401 
3402 -- ==============================================================================================
3403 -- VALIDATIONS BEGIN
3404 -- ==============================================================================================
3405 
3406 l_stmt_num := 81;
3407                     -- *** job_type = 3 => non-standard job. Anything else/null => standard job ***
3408                     if v_wlji_job_type(v_index) is null then v_wlji_job_type(v_index):= 1; end if;
3409 
3410 
3411 l_stmt_num := 82;
3412                     -- *** mode_flag cannot be 2 for non-standard jobs ***
3413                     if v_wlji_job_type(v_index) = 3 and v_wlji_mode_flag(v_index) = 2 then
3414                         l_aux_mesg := 'Mode Flag cannot be 2 for Non Standard Jobs';
3415                         process_invalid_field('MODE FlAG',
3416                                               l_aux_mesg,
3417                                               l_stmt_num);
3418                         l_error_code := -1;
3419                         GOTO skip_validate_constants;
3420                     end if;
3421 
3422 
3423 l_stmt_num := 83;
3424                     -- *** load_wsli_data loads relevant rows from wsli into PL/SQL ***
3425                     -- *** tables for easy validation. I do not want this procedure ***
3426                     -- *** to be executed if there's no mode_flag = 2 rec in wlji.  ***
3427                     -- *** v_load_wsli (true/false) ensures that the procedure is   ***
3428                     -- *** called only once per worker                              ***
3429                     if v_wlji_load_type(v_index) = 5 and v_wlji_mode_flag(v_index) = 2
3430                        and v_load_wsli = true then
3431 
3432                         if (lbji_debug = 'Y') then
3433                             fnd_file.put_line(fnd_file.log,'loading wsli for batch group id: '||batch_group_id||'..');
3434                         end if;
3435 
3436                         load_wsli_data(batch_group_id);
3437                         v_load_wsli := false;
3438                     end if;
3439 
3440 
3441 l_stmt_num := 84;
3442                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
3443                         if v_wlji_firm_planned_flag(v_index) is null then
3444                             v_wlji_firm_planned_flag(v_index) := 2;
3445                         elsif v_wlji_firm_planned_flag(v_index) <> 1 and
3446                               v_wlji_firm_planned_flag(v_index) <> 2 then
3447                             l_aux_mesg := 'Firm Planned Flag should be 1 or 2';
3448                             process_invalid_field('FIRM_PLANNED_FLAG',
3449                                                   l_aux_mesg,
3450                                                   l_stmt_num);
3451                             l_error_code := -1;
3452                             GOTO skip_validate_constants;
3453                         end if;
3454                     end if;
3455 
3456 
3457 l_stmt_num := 85;
3458                     if WSMPVERS.get_osfm_release_version < '110509' and v_wlji_kanban_card_id(v_index) is not null then
3459                         l_error_code := -1;
3460                         process_errorred_field('WSM',
3461                                                'WSM_KANBAN_NOT ALLOWED',
3462                                                 l_stmt_num);
3463                     end if;
3464                     if l_error_code <> 0 then
3465                         l_error_count := l_error_count + 1;
3466                         GOTO skip_other_steps;
3467                     end if;
3468 
3469 
3470 l_stmt_num := 91;
3471                     -- *** check that there's a row in wsli for this mode 2 job ***
3472                     xst := true;
3473                     if v_wlji_load_type(v_index) = 5 AND v_wlji_mode_flag(v_index) = 2 then
3474                         if v_wlji_source_line_id(v_index) is NULL then
3475                             l_error_code := -1;
3476                             process_errorred_field('WSM',
3477                                                    'WSM_START_LOT_REQUIRED',
3478                                                    l_stmt_num);
3479                         else
3480                             xst := v_wsli.exists(v_wlji_source_line_id(v_index));
3481                             if xst = false then
3482                                 l_error_code := -1;
3483                                 process_errorred_field('WSM',
3484                                                        'WSM_START_LOT_REQUIRED',
3485                                                        l_stmt_num);
3486                             end if;
3487                         end if;
3488                     end if;
3489 
3490                     if l_error_code <> 0 then
3491                         l_error_count := l_error_count + 1;
3492                             GOTO skip_other_steps;
3493                     end if;
3494                     xst := true;
3495 
3496 
3497 l_stmt_num := 100;
3498                     -- *** validate org id begin ***
3499                     xst :=  WSMPLCVA.v_org.exists(v_wlji_org(v_index));
3500                     if xst = false then
3501                         l_error_code := -1;
3502                         process_invalid_field('ORGANIZATION ID',
3503                                               '',
3504                                               l_stmt_num);
3505                     end if;
3506 
3507                     if l_error_code <> 0 then
3508                         l_error_count := l_error_count + 1;
3509                         GOTO skip_other_steps;
3510                     end if;
3511                     xst := true;
3512 
3513                     if lbji_debug = 'Y' then
3514                         fnd_file.put_line(fnd_file.log, 'Org Id Validation..Success.');
3515                     end if;
3516                     -- *** validate org id end ***
3517 
3518 
3519 l_stmt_num := 110;
3520                     -- *** make sure that no one is trying to create a wip lot out of an inventory ***
3521                     -- *** lot by splitting/merging/etc. CZH: check wlsmi
3522                     if v_wlji_load_type(v_index) = 5 then
3523 
3524                         begin
3525                             select  1
3526                             into    l_no_of_records
3527                             from    wsm_starting_lots_interface    wsli,
3528                                     wsm_lot_split_merges_interface wlsmi
3529                             where   wsli.lot_number = v_wlji_job_name(v_index)
3530                             and     wsli.header_id = wlsmi.header_id
3531                             and     wlsmi.process_status in (1,2);
3532 
3533                         exception
3534                             when too_many_rows then l_no_of_records := 1;
3535                             when no_data_found then NULL;
3536                         end;
3537 
3538                         if l_no_of_records <> 0 then
3539                             l_error_code := -1;
3540                             process_errorred_field('WSM',
3541                                                    'WSM_LOT_EXISTS',
3542                                                    l_stmt_num);
3543                         end if;
3544 
3545                         if l_error_code <> 0 then
3546                             l_error_count := l_error_count + 1;
3547                             GOTO skip_other_steps;
3548                         end if;
3549                         l_no_of_records := 0;
3550 
3551                         if lbji_debug = 'Y' then
3552                             fnd_file.put_line(fnd_file.log, 'Checking existance of inv lots of the same name.. Success');
3553                         end if;
3554 
3555                     end if; -- load type 5
3556 
3557 
3558 l_stmt_num := 120;
3559                     -- *** validate constants begin ***  CZH: this should be moved above
3560 
3561 l_stmt_num := 130;
3562                     if (v_wlji_load_type(v_index) <> 5) AND (v_wlji_load_type(v_index) <> 6) then
3563                         l_aux_mesg := 'Load type should be 5 or 6';
3564                         process_invalid_field('LOAD TYPE',
3565                                               l_aux_mesg,
3566                                               l_stmt_num);
3567                         l_error_code := -1;
3568                         GOTO skip_validate_constants;
3569                     end if;
3570 
3571 l_stmt_num := 140;
3572                     if v_wlji_load_type(v_index) = 5 AND
3573                       (v_wlji_scheduling_method(v_index) <> 3 AND
3574                        v_wlji_scheduling_method(v_index) <> 2) then
3575                         l_aux_mesg := 'Scheduling method should be 2 or 3 for load_type 5';
3576                         process_invalid_field('SCHEDULING METHOD',
3577                                               l_aux_mesg,
3578                                               l_stmt_num);
3579                         l_error_code := -1;
3580                         GOTO skip_validate_constants;
3581                     end if;
3582 
3583 l_stmt_num := 150;
3584                     if v_wlji_load_type(v_index) = 5 AND
3585                        v_wlji_job_type(v_index) <> 3 and
3586                        v_wlji_mode_flag(v_index) not in (1,2) then
3587                         l_aux_mesg := 'For creating new jobs, mode flag should have value 1 or 2';
3588                         process_invalid_field('MODE FLAG',
3589                                               l_aux_mesg,
3590                                               l_stmt_num);
3591                         l_error_code := -1;
3592                         GOTO skip_validate_constants;
3593                     elsif v_wlji_job_type(v_index) = 3 then
3594                         if v_wlji_mode_flag(v_index) <> 1 then
3595                             if lbji_debug = 'Y' then
3596                                 fnd_file.put_line(fnd_file.log, 'Ignoring mode_flag, has to be 1 for non-standard jobs.');
3597                             end if;
3598                         end if;
3599                         if v_wlji_mode_flag(v_index) is null then
3600                             v_wlji_mode_flag(v_index) := 1;
3601                         end if;
3602                     end if;
3603 
3604 l_stmt_num := 160;
3605                     if v_wlji_load_type(v_index)  = 6 AND
3606                       (v_wlji_scheduling_method(v_index) <> 3 AND
3607                        v_wlji_scheduling_method(v_index) <> 2) then
3608                         l_aux_mesg := 'Scheduling method should be 2 or 3 for load_type 6';
3609                         process_invalid_field('SCHEDULING METHOD',
3610                                                l_aux_mesg,
3611                                                l_stmt_num);
3612                         l_error_code := -1;
3613                         GOTO skip_validate_constants;
3614                     end if;
3615 
3616 l_stmt_num := 170;
3617                     if UPPER(v_wlji_allow_explosion(v_index))  = 'N' then
3618                         process_errorred_field('WSM',
3619                                                'WSM_ALLOW_EXPL_Y',
3620                                                l_stmt_num);
3621                         l_error_code := -1;
3622                         GOTO skip_validate_constants;
3623                     else
3624                         v_wlji_allow_explosion(v_index) := 'Y';
3625                     end if;
3626 
3627 l_stmt_num := 180;
3628                     if v_wlji_wip_supply_type(v_index) is null then
3629                         v_wlji_wip_supply_type(v_index) := 7;
3630                     elsif v_wlji_wip_supply_type(v_index) not in (1,2,3,4,5,7) then
3631                         l_aux_mesg := '';
3632                         process_invalid_field('WIP SUPPLY TYPE',
3633                                               l_aux_mesg,
3634                                               l_stmt_num);
3635                         l_error_code := -1;
3636                         GOTO skip_validate_constants;
3637                     end if;
3638 
3639 l_stmt_num := 181;
3640                     if v_wlji_status_type(v_index) not in
3641                     (WIP_CONSTANTS.UNRELEASED,
3642                      WIP_CONSTANTS.RELEASED,
3643                      WIP_CONSTANTS.HOLD,
3644                      WIP_CONSTANTS.CANCELLED) then
3645                         l_aux_mesg := '';
3646                         process_invalid_field('STATUS TYPE',
3647                                               l_aux_mesg,
3648                                               l_stmt_num);
3649                         l_error_code := -1;
3650                         GOTO skip_validate_constants;
3651                     end if;
3652 
3653 << skip_validate_constants >>
3654 
3655                     if l_error_code <> 0 then
3656                         l_error_count := l_error_count + 1;
3657                         GOTO skip_other_steps;
3658                     end if;
3659                     l_aux_mesg := '';
3660 
3661                     if lbji_debug = 'Y' then
3662                         fnd_file.put_line(fnd_file.log, 'Validating Constants.. Success.');
3663                     end if;
3664 
3665                     -- *** validate constants end ***
3666 
3667 
3668 
3669 l_stmt_num := 181.5;
3670                     l_error_code := 0;
3671                     l_err_msg := '';
3672 
3673                     -- *** validation of a non-standard job for creation***
3674 
3675                     if v_wlji_job_type(v_index) = 3 and v_wlji_load_type(v_index) = 5 then
3676 
3677                         -- validation_level = 0 => validations performed during job creation
3678 
3679                         -- *** Error Code and Message Guide ***
3680                         -- 1: Routing Reference Cannot be Null
3681                         -- 2: Invalid Assembly Item Id
3682                         -- 3: Invalid Routing Reference Id
3683                         -- 4: Invalid Bom Reference Id
3684                         -- 5: Invalid Alternate Routing Designator
3685                         -- 0: Invalid Alternate Bom Designator -- WARNING
3686                         -- 7: Start Date cannot be greater than End Date
3687                         -- 8: Both Start and End Dates must be Entered
3688                         -- 9: Invalid Start Quantity
3689                         -- 10: Invalid Net Quantity
3690                         -- 11: Invalid Class Code
3691                         -- 12: Invalid Completion Locator Id
3692                         -- 13: Invalid Completion Subinventory
3693                         -- 14: Invalid Firm Planned Flag
3694 
3695 
3696                         wsmputil.validate_non_std_references(v_wlji_item(v_index),
3697                                   v_wlji_routing_reference_id(v_index),
3698                                   v_wlji_bom_reference_id(v_index),
3699                                   v_wlji_alt_routing_designator(v_index),
3700                                   v_wlji_alt_bom_designator(v_index),
3701                                   v_wlji_org(v_index),
3702                                   v_wlji_fusd(v_index),
3703                                   v_wlji_lucd(v_index),
3704                                   v_wlji_start_quantity(v_index),
3705                                   v_wlji_net_quantity(v_index),
3706                                   v_wlji_class_code(v_index),
3707                                   v_wlji_completion_subinventory(v_index),
3708                                   v_wlji_completion_locator_id(v_index),
3709                                   v_wlji_firm_planned_flag(v_index),
3710                                   v_wlji_bom_revision(v_index),
3711                                   v_wlji_bom_revision_date(v_index),
3712                                   v_wlji_routing_revision(v_index),
3713                                   v_wlji_routing_revision_date(v_index),
3714                                   routing_seq_id,
3715                                   bom_seq_id,
3716                                   0,
3717                                   l_error_code,
3718                                   l_err_msg);
3719 
3720 
3721                         if l_error_code <> 0 then
3722                             HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
3723                             l_error_code := -1;
3724                         end if;
3725 
3726                         if l_error_code = 0 and l_err_msg is not null then
3727                             fnd_file.new_line(fnd_file.log, 2);
3728                             fnd_file.put_line(fnd_file.log,l_err_msg);
3729                             fnd_file.new_line(fnd_file.log, 2);
3730                             l_err_msg := '';
3731                         end if;
3732                     end if; -- non-standard validations end
3733 
3734                     if l_error_code <> 0 then
3735                         l_error_count := l_error_count + 1;
3736                         GOTO skip_other_steps;
3737                     end if;
3738 
3739 
3740 l_stmt_num := 240;
3741                     -- *** validate assembly quantity begin ***
3742                     if v_wlji_job_type(v_index) <> 3 then
3743 
3744                         if v_wlji_start_quantity(v_index) < 0 then
3745                             l_error_code := -1;
3746                             l_aux_mesg := 'Start quantity cannot be negative';
3747                             process_invalid_field(
3748                                   'START QUANTITY',
3749                                   l_aux_mesg,
3750                                   l_stmt_num);
3751                             GOTO skip_validate_strt_qnty;
3752                         end if;
3753 
3754 
3755                         if v_wlji_load_type(v_index) = 5 and
3756                           (v_wlji_start_quantity(v_index) is NULL or
3757                            v_wlji_start_quantity(v_index) = 0) then
3758                             l_error_code := -1;
3759                             l_aux_mesg := 'Start quantity cannot be NULL or 0 for job creation';
3760                             process_invalid_field(
3761                                   'START QUANTITY',
3762                                   l_aux_mesg,
3763                                   l_stmt_num);
3764                         end if;
3765 
3766 << skip_validate_strt_qnty >>
3767 
3768                         if l_error_code <> 0 then
3769                             l_error_count := l_error_count + 1;
3770                             GOTO skip_other_steps;
3771                         end if;
3772                         l_aux_mesg := '';
3773 
3774                         if lbji_debug = 'Y' and v_wlji_mode_flag(v_index) = 1 then
3775                             fnd_file.put_line(fnd_file.log, 'Assembly Quantity OK');
3776                         end if;
3777                     end if; -- job_type
3778                     -- *** validate assembly quantity end ***
3779 
3780 l_stmt_num := 260;
3781                     -- *** validate mode one item id begin ***
3782                     -- CZH: why only for standard job ???
3783                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
3784 
3785                         if v_wlji_mode_flag(v_index) = 1 then
3786                             xst :=  WSMPLCVA.v_item.exists(v_wlji_item(v_index));
3787                         else -- mode flag 2
3788                             str := to_char(v_wlji_item(v_index))||
3789                                    to_char(v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id);
3790                             hash_value := dbms_utility.get_hash_value(str, 37, 1073741824);
3791 
3792                             xst := WSMPLCVA.v_mode2_item.exists(hash_value)
3793                                    AND WSMPLCVA.v_mode2_item(hash_value).INVENTORY_ITEM_ID =
3794                                             v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
3795                                    AND WSMPLCVA.v_mode2_item(hash_value).PRIMARY_ITEM_ID = v_wlji_item(v_index);
3796                         end if;
3797 
3798                         if xst = false then
3799 
3800                             begin
3801                                 select  1
3802                                 into    l_no_of_records
3803                                 from    mtl_system_items_kfv msi
3804                                 where   msi.inventory_item_id = v_wlji_item(v_index)
3805                                 and     msi.organization_id = v_wlji_org(v_index)
3806                                 and     msi.lot_control_code = 2;
3807                             exception
3808                                 when too_many_rows then l_no_of_records := 1;
3809                                 when no_data_found then
3810                                     l_error_code := -1;
3811                                     process_errorred_field('WSM',
3812                                                            'WSM_ASSEMBLY_NO_LOT',
3813                                                            l_stmt_num);
3814                             end;
3815 
3816                             if l_no_of_records <> 0 then
3817                                 begin
3818                                     l_no_of_records := 0;
3819                                     select  1
3820                                     into    l_no_of_records
3821                                     from    mtl_system_items_kfv msi
3822                                     where   msi.inventory_item_id = v_wlji_item(v_index)
3823                                     and     msi.organization_id = v_wlji_org(v_index)
3824                                     and     msi.serial_number_control_code = 1;
3825                                 exception
3826                                     when too_many_rows then l_no_of_records := 1;
3827                                     when no_data_found then
3828                                         l_error_code := -1;
3829                                         process_errorred_field('WSM',
3830                                                                'WSM_ASSEMBLY_NOT_SERIAL',
3831                                                                l_stmt_num);
3832                                 end;
3833                             end if;
3834 
3835                         end if; -- xst = false
3836 
3837                         if xst = false AND l_no_of_records <> 0 then
3838                             if v_wlji_mode_flag(v_index) = 2 then
3839                                 WSMPLCVA.v_mode2_item(hash_value).INVENTORY_ITEM_ID :=
3840                                     v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id;
3841                                 WSMPLCVA.v_mode2_item(hash_value).PRIMARY_ITEM_ID :=
3842                                     v_wlji_item(v_index);
3843                             else -- mode flag = 1
3844                                 WSMPLCVA.v_item(v_wlji_item(v_index)) := v_wlji_item(v_index);
3845                             end if;
3846                         end if;
3847 
3848                         if l_error_code <> 0 then
3849                             l_error_count := l_error_count + 1;
3850                             GOTO skip_other_steps;
3851                         end if;
3852                         l_no_of_records := 0;
3853                         l_dummy := 0;
3854                         l_aux_mesg := '';
3855                         xst := true;
3856                         str := '';
3857                         hash_value := 0;
3858 
3859                         if lbji_debug = 'Y' then
3860                             fnd_file.put_line(fnd_file.log, 'Validation of Item.. Success');
3861                         end if;
3862 
3863                     end if; -- load type 5
3864                     -- *** validate mode one item id end ***
3865 
3866 
3867 l_stmt_num := 280;
3868                     -- *** validate dates begin ***
3869                     if v_wlji_load_type(v_index) = 5 then
3870 
3871                         IF v_wlji_fusd(v_index) IS NOT NULL AND
3872                            v_wlji_lucd(v_index) IS NOT NULL THEN
3873 
3874                             IF  v_wlji_fusd(v_index) > v_wlji_lucd(v_index) THEN
3875                                 process_errorred_field('WSM',
3876                                                        'WSM_FUSD_GT_LUCD',
3877                                                        l_stmt_num);
3878                                 l_error_code := -1;
3879                                 GOTO skip_date_validation;
3880                             END IF;
3881                         ELSIF v_wlji_fusd(v_index) IS NULL AND
3882                               v_wlji_lucd(v_index) IS NULL THEN
3883                             process_errorred_field('WSM',
3884                                                    'WSM_DATES_NULL',
3885                                                    l_stmt_num);
3886                             l_error_code := -1;
3887                             GOTO skip_date_validation;
3888                         END IF;
3889 
3890                         IF v_wlji_fusd(v_index) IS NOT NULL AND
3891                            v_wlji_lucd(v_index) IS NULL THEN
3892                             v_wlji_lucd(v_index) := wsmputil.GET_SCHEDULED_DATE (
3893                                        v_wlji_org(v_index),
3894                                        v_wlji_item(v_index),
3895                                        'F',
3896                                        v_wlji_fusd(v_index),
3897                                        --v_wlji_start_quantity(v_index),
3898                                        l_error_code,
3899                                        l_err_msg,
3900                                        v_wlji_start_quantity(v_index));     --Fixed bug # 2313574
3901 
3902                             if lbji_debug = 'Y' then
3903                                 fnd_file.put_line(fnd_file.log, 'Getting complete date based on item lead time');
3904                             end if;
3905 
3906                         END IF ;
3907 
3908 
3909                         IF v_wlji_fusd(v_index) IS NULL AND
3910                            v_wlji_lucd(v_index) IS NOT NULL THEN
3911                             v_wlji_fusd(v_index) := wsmputil.GET_SCHEDULED_DATE (
3912                                        v_wlji_org(v_index),
3913                                        v_wlji_item(v_index),
3914                                        'B',
3915                                        v_wlji_lucd(v_index),
3916                                        --v_wlji_start_quantity(v_index),
3917                                        l_error_code,
3918                                        l_err_msg,
3919                                        v_wlji_start_quantity(v_index));     --Fixed bug # 2313574
3920 
3921                             if lbji_debug = 'Y' then
3922                                 fnd_file.put_line(fnd_file.log, 'Getting start date based on item lead time');
3923                             end if;
3924                         END IF;
3925 
3926                         if l_error_code <> 0 OR l_err_msg IS NOT NULL then
3927                             HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
3928                             l_error_code := -1;
3929                         end if;
3930 
3931 << skip_date_validation >>
3932 
3933                         if l_error_code <> 0 then
3934                             l_error_count := l_error_count + 1;
3935                             GOTO skip_other_steps;
3936                         end if;
3937                         l_err_msg := '';
3938 
3939                         if lbji_debug = 'Y' then
3940                             fnd_file.put_line(fnd_file.log, 'Date Validation.. Success.');
3941                         end if;
3942 
3943                     end if; -- load type 5
3944                     -- *** validate dates end ***
3945 
3946 
3947 l_stmt_num := 300;
3948                     -- *** validate net quantity begin ***
3949                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
3950 
3951                         if (v_wlji_net_quantity(v_index) < 0) then
3952                             l_aux_mesg := 'Net Quantity should be > 0';
3953                             process_invalid_field('NET QUANTITY',
3954                                                   l_aux_mesg,
3955                                                   l_stmt_num);
3956                             l_error_code := -1;
3957                         end if;
3958 
3959                         if (v_wlji_net_quantity(v_index) IS NULL) then
3960                             v_wlji_net_quantity(v_index) :=  v_wlji_start_quantity(v_index);
3961                         end if;
3962 
3963                         if v_wlji_net_quantity(v_index) > v_wlji_start_quantity(v_index) then
3964                             l_aux_mesg := 'Net Quantity should be <= start quantity';
3965                             process_invalid_field('NET QUANTITY',
3966                                                   l_aux_mesg,
3967                                                   l_stmt_num);
3968                             l_error_code := -1;
3969                         end if;
3970                         if l_error_code <> 0 then
3971                             l_error_count := l_error_count + 1;
3972                             GOTO skip_other_steps;
3973                         end if;
3974                         l_aux_mesg := '';
3975 
3976                         if lbji_debug = 'Y' then
3977                             fnd_file.put_line(fnd_file.log, 'Net Quantity Validation.. Success.');
3978                         end if;
3979 
3980                     end if; -- load type 5
3981                     -- *** validate net quantity end ***
3982 
3983 
3984                     l_stmt_num := 320;
3985                     -- *** validate coproduct-supply flag begin ***
3986                     if v_wlji_load_type(v_index) = 5 then
3987 
3988                         IF v_wlji_coproducts_supply(v_index) is NULL THEN
3989                             v_wlji_coproducts_supply(v_index) :=
3990                                     WSMPLCVA.v_org(v_wlji_org(v_index)).COPRODUCTS_SUPPLY_DEFAULT;
3991                         ELSIF ( v_wlji_coproducts_supply(v_index) <> 1
3992                             OR  v_wlji_coproducts_supply(v_index) <> 2)  THEN
3993                             v_wlji_coproducts_supply(v_index) := 2;
3994                         END IF;
3995 
3996                         if l_error_code <> 0 then
3997                             l_error_count := l_error_count + 1;
3998                             GOTO skip_other_steps;
3999                         end if;
4000 
4001                         if lbji_debug = 'Y' then
4002                             fnd_file.put_line(fnd_file.log, 'Co Product Supply Flag Validation.. Success.');
4003                         end if;
4004 
4005                     end if; -- load type 5
4006                     -- *** validate coproduct-supply flag end ***
4007 
4008 
4009 l_stmt_num := 340;
4010                     -- *** get routing_seq_id begin ***
4011                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
4012 
4013                         begin
4014                         -- bugfix 2681637 validation of alternate designator should check disable_date. (original bug for form 2558447)
4015                         -- view bom_routing_alternates_v does not have designator disable_date infor.
4016 
4017                            select bor.routing_sequence_id,
4018                                   bor.COMPLETION_SUBINVENTORY,
4019                                   bor.COMPLETION_LOCATOR_ID
4020                            into   routing_seq_id,
4021                                   l_default_subinventory,
4022                                   l_default_compl_loc_id
4023                            --from bom_routing_alternates_v bor
4024                            from   bom_operational_routings bor,
4025                                   bom_alternate_designators bad
4026                            where  ((bor.alternate_routing_designator is null and
4027                                     bad.alternate_designator_code is null
4028                                     and bad.organization_id = -1)
4029                                    or (bor.alternate_routing_designator = bad.alternate_designator_code
4030                                        and bor.organization_id = bad.organization_id))
4031                            and    bor.organization_id = v_wlji_org(v_index)
4032                            and    bor.assembly_item_id = v_wlji_item(v_index)
4033                            and    NVL(bor.alternate_routing_designator, '&*') = NVL(v_wlji_alt_routing_designator(v_index), '&*')
4034                            and    bor.routing_type = 1
4035                            and    bor.cfm_routing_flag = 3;
4036                            --Bug 5107339: Disable_date validation is not applicable here.
4037                            --and    trunc(nvl(bad.disable_date, sysdate + 1)) > trunc(sysdate);
4038 
4039                         exception
4040                             when no_data_found then
4041                                 l_aux_mesg := '';
4042                                 process_invalid_field('ALTERNATE ROUTING DESIGNATOR',
4043                                                       l_aux_mesg,
4044                                                       l_stmt_num);
4045                                 l_error_code := -1;
4046                         end;
4047 
4048                         if l_error_code <> 0 then
4049                             l_error_count := l_error_count + 1;
4050                             GOTO skip_other_steps;
4051                         end if;
4052 
4053                         if lbji_debug = 'Y' then
4054                             fnd_file.put_line(fnd_file.log, 'Getting Routing Sequence Id: '||routing_seq_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 NULL THEN
4059                             v_wlji_completion_subinventory(v_index) := l_default_subinventory;
4060                             v_wlji_completion_locator_id(v_index) := l_default_compl_loc_id;
4061                         END IF;
4062 
4063                         IF v_wlji_completion_subinventory(v_index) IS NULL AND
4064                            v_wlji_completion_locator_id(v_index) IS NOT NULL THEN
4065                             v_wlji_completion_subinventory(v_index) := l_default_subinventory;
4066                         END IF;
4067 
4068                         IF v_wlji_completion_subinventory(v_index) IS NOT NULL AND
4069                            v_wlji_completion_locator_id(v_index) IS NULL THEN
4070 
4071                         -- do the subinventory validation here...
4072                         -- validation of subinv begin
4073                             str := to_char(v_wlji_org(v_index))||v_wlji_completion_subinventory(v_index);
4074                             hash_value := dbms_utility.get_hash_value(str, 37, 1073741824);
4075                             if WSMPLCVA.v_subinv.exists(hash_value) then
4076                                 NULL;
4077                             else
4078                                 l_aux_mesg := '';
4079                                 process_invalid_field('COMPLETION SUBINVENTORY',
4080                                                       l_aux_mesg,
4081                                                       l_stmt_num);
4082                                 l_error_code := -1;
4083                             end if;
4084 
4085                             if l_error_code <> 0 then
4086                                 l_error_count := l_error_count + 1;
4087                                 GOTO skip_other_steps;
4088                             end if;
4089 
4090                             l_aux_mesg := '';
4091                             str := '';
4092                             hash_value := 0;
4093 
4094                             -- validation of subinv end
4095 
4096                             select locator_type
4097                             into   mtl_locator_type
4098                             from   mtl_secondary_inventories
4099                             where  secondary_inventory_name = v_wlji_completion_subinventory(v_index)
4100                             and    organization_id = v_wlji_org(v_index);
4101 
4102                             if v_wlji_completion_subinventory(v_index) = l_default_subinventory then
4103                                 v_wlji_completion_locator_id(v_index) := l_default_compl_loc_id;
4104                             else
4105                                 if mtl_locator_type = 2 then
4106                                     l_aux_mesg := '';
4107                                     process_invalid_field('COMPLETION SUBINVENTORY',
4108                                                           l_aux_mesg,
4109                                                           l_stmt_num);
4110                                     l_error_code := -1;
4111                                     l_error_count := l_error_count + 1;
4112                                     GOTO skip_other_steps;
4113                                 else
4114                                     NULL;
4115                                 end if;
4116                             end if;
4117                         END IF;
4118 
4119                         l_aux_mesg := '';
4120                     end if; -- load type 5
4121                     -- *** get routing_seq_id end ***
4122 
4123 
4124                     l_stmt_num := 360;
4125                     -- *** get bill_seq_id begin ***
4126                     --if the alternate_bom_designator has NULL in wlji, bill_seq_id can have either a
4127                     --NULL or a primary bom value. But if the designator has ALT, then there must be a
4128                     --bill id for the alternate bom.
4129 
4130                     if v_wlji_load_type(v_index) = 5  and v_wlji_job_type(v_index) <> 3 then
4131 
4132                         IF v_wlji_alt_bom_designator(v_index) is NULL THEN
4133                             begin
4134                                 SELECT  bom.common_bill_sequence_id
4135                                 INTO    bom_seq_id
4136                                 FROM    bom_bill_of_materials bom
4137                                 WHERE   bom.alternate_bom_designator is NULL
4138                                 AND     BOM.assembly_item_id = v_wlji_item(v_index)
4139                                 AND     bom.organization_id = v_wlji_org(v_index);
4140                             exception
4141                                 WHEN NO_DATA_FOUND THEN
4142                                     NULL;
4143                             end;
4144                         ELSE
4145                             begin
4146                                 -- bugfix 2681637 validation of alternate designator should check disable_date.
4147                                 -- (original bug for form 2558447)
4148                                 -- table bom_bill_of_materials does not have designator disable_date infor.
4149 
4150                                 SELECT  bom.common_bill_sequence_id
4151                                 INTO    bom_seq_id
4152                                 FROM    bom_bill_of_materials bom,
4153                                         bom_alternate_designators bad
4154                                 WHERE   ((bom.alternate_bom_designator is null and
4155                                           bad.alternate_designator_code is null
4156                                           and bad.organization_id = -1)
4157                                          OR (bom.alternate_bom_designator = bad.alternate_designator_code
4158                                              and bom.organization_id = bad.organization_id))
4159                                 AND     bom.alternate_bom_designator = v_wlji_alt_bom_designator(v_index)
4160                                 AND     BOM.assembly_item_id = v_wlji_item(v_index)
4161                                 AND     bom.organization_id = v_wlji_org(v_index);
4162                                 --Bug 5107339: Disable_date validation is not applicable here.
4163                                 --AND     trunc(nvl(bad.disable_date, sysdate + 1)) > trunc(sysdate);
4164 
4165                             exception
4166                                 WHEN no_data_found  THEN
4167                                     l_aux_mesg := '';
4168                                     process_invalid_field('ALTERNATE BOM DESIGNATOR',
4169                                                           l_aux_mesg,
4170                                                           l_stmt_num);
4171                                     l_error_code := -1;
4172                             end;
4173                         END IF;
4174 
4175                         if l_error_code <> 0 then
4176                             l_error_count := l_error_count + 1;
4177                             GOTO skip_other_steps;
4178                         end if;
4179                         l_aux_mesg := '';
4180 
4181                         if lbji_debug = 'Y' then
4182                             fnd_file.put_line(fnd_file.log, 'Getting Bill Sequence Id: '||bom_seq_id);
4183                         end if;
4184 
4185                     end if; -- load type 5
4186                     -- *** get bill_seq_id end ***
4187 
4188 
4189 l_stmt_num := 400;
4190                     -- *** validate locator id begin ***
4191                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
4192 
4193                         SELECT  nvl(msub.locator_type, 1) sub_loc_control,
4194                                 MP.stock_locator_control_code org_loc_control,
4195                                 MS.restrict_locators_code,
4196                                 MS.location_control_code item_loc_control
4197                         into    l_sub_loc_control, l_org_loc_control,
4198                                 l_restrict_locators_code, l_item_loc_control
4199                         FROM    mtl_system_items MS,
4200                                 mtl_secondary_inventories MSUB,
4201                                 mtl_parameters MP
4202                         WHERE   MP.organization_id = v_wlji_org(v_index)
4203                         AND     MS.organization_id = v_wlji_org(v_index)
4204                         AND     MS.inventory_item_id = v_wlji_item(v_index)
4205                         AND     MSUB.secondary_inventory_name = v_wlji_completion_subinventory(v_index)
4206                         AND     MSUB.organization_id = v_wlji_org(v_index);
4207 
4208                         l_locator_id := v_wlji_completion_locator_id(v_index) ;
4209 
4210                         WIP_LOCATOR.validate(
4211                                             v_wlji_org(v_index),
4212                                             v_wlji_item(v_index),
4213                                             v_wlji_completion_subinventory(v_index),
4214                                             l_org_loc_control,
4215                                             l_sub_loc_control,
4216                                             l_item_loc_control,
4217                                             l_restrict_locators_code,
4218                                             NULL, NULL, NULL, NULL,
4219                                             l_locator_id,
4220                                             l_segs,
4221                                             l_loc_success);
4222 
4223                         IF not l_loc_success THEN
4224                             l_aux_mesg := '';
4225                             process_invalid_field('COMPLETION SUBINVENTORY',
4226                                                   l_aux_mesg,
4227                                                   l_stmt_num);
4228                             l_error_code := -1;
4229                         end if;
4230 
4231                         if l_error_code <> 0 then
4232                             l_error_count := l_error_count + 1;
4233                             GOTO skip_other_steps;
4234                         end if;
4235                         l_aux_mesg := '';
4236                         l_locator_id := 0;
4237 
4238                         if lbji_debug = 'Y' then
4239                             fnd_file.put_line(fnd_file.log, 'Locator Id Validation.. Success.');
4240                         end if;
4241 
4242                     end if; -- load type 5
4243                     -- *** validate locator id end ***
4244 
4245 
4246 l_stmt_num := 420;
4247                     -- *** validate last_updt_by begin ***
4248                     if v_wlji_load_type(v_index) = 5 then
4249 
4250                         if v_wlji_last_updt_by(v_index) is NULL then
4251                             v_wlji_last_updt_by(v_index) := l_user;
4252                         else
4253                             xst :=  WSMPLCVA.v_user.exists(v_wlji_last_updt_by(v_index));
4254                             if xst = false then
4255                                 begin
4256                                     select 1
4257                                     into   l_no_of_records
4258                                     from   fnd_user
4259                                     where  user_id = v_wlji_last_updt_by(v_index)
4260                                     and    sysdate between start_date and nvl(end_date,sysdate+1);
4261                                 exception
4262                                     when too_many_rows then l_no_of_records := 1;
4263                                     when no_data_found then
4264                                         l_error_code := -1;
4265                                         l_aux_mesg := '';
4266                                         process_invalid_field( 'Last Updated By',
4267                                                                l_aux_mesg,
4268                                                                l_stmt_num);
4269                                 end;
4270                             end if;
4271 
4272                             if xst = false AND l_no_of_records <> 0 then
4273                                 WSMPLCVA.v_user(v_wlji_last_updt_by(v_index)) := v_wlji_last_updt_by(v_index);
4274                             end if;
4275 
4276 
4277                             if l_error_code <> 0 then
4278                                 l_error_count := l_error_count + 1;
4279                                 GOTO skip_other_steps;
4280                             end if;
4281                             l_aux_mesg := '';
4282                             l_no_of_records := 0;
4283                             xst := true;
4284                         end if;
4285 
4286                         if lbji_debug = 'Y' then
4287                             fnd_file.put_line(fnd_file.log, 'Last Updt By Validation.. Success.');
4288                         end if;
4289 
4290                     end if; -- load type 5
4291                     -- *** validate last_updt_by end ***
4292 
4293 
4294 l_stmt_num := 440;
4295                     -- *** validate created_by begin ***
4296                     if v_wlji_load_type(v_index) = 5 then
4297 
4298                         if v_wlji_created_by(v_index) is NULL then
4299                             v_wlji_created_by(v_index) := l_user;
4300                         else
4301                             xst :=  WSMPLCVA.v_user.exists(v_wlji_created_by(v_index));
4302                             if xst = false then
4303                                 begin
4304                                     select 1
4305                                     into   l_no_of_records
4306                                     from   fnd_user
4307                                     where  user_id = v_wlji_created_by(v_index)
4308                                     and    sysdate between start_date and nvl(end_date,sysdate+1);
4309                                 exception
4310                                     when too_many_rows then l_no_of_records := 1;
4311                                     when no_data_found then
4312                                         l_error_code := -1;
4313                                         l_aux_mesg := '';
4314                                         process_invalid_field( 'Created By', l_aux_mesg, 'l_stmt_num.vldt_created_by');
4315                                 end;
4316                             end if;
4317 
4318                             if xst = false AND l_no_of_records <> 0 then
4319                                 WSMPLCVA.v_user(v_wlji_created_by(v_index)) := v_wlji_created_by(v_index);
4320                             end if;
4321 
4322                             if l_error_code <> 0 then
4323                                 l_error_count := l_error_count + 1;
4324                                 GOTO skip_other_steps;
4325                             end if;
4326                             l_aux_mesg := '';
4327                             l_no_of_records := 0;
4328                             xst := true;
4329                         end if;
4330 
4331                         if lbji_debug = 'Y' then
4332                             fnd_file.put_line(fnd_file.log, 'Created By Validation.. Success.');
4333                         end if;
4334 
4335                     end if; -- load type 5
4336                     -- *** validate created_by end ***
4337 
4338 
4339 l_stmt_num := 460;
4340                     -- *** validate job name and id begin ***
4341                     if LENGTH(v_wlji_job_name(v_index)) > 80 then       -- Changed for OPM Convergence project
4342                         process_errorred_field('WSM',
4343                                                'WSM_JOB_NAME_EIGHTY_CHAR',
4344                                                l_stmt_num);
4345                         l_error_code := -1;
4346                         GOTO skip_job_id_valid;
4347                     end if;
4348 
4349                     l_return_value := 0;
4350 
4351 l_stmt_num := 460.1;
4352                     /*Bug 3414163:Call to Check_wmti is commented.*/
4353                     /*
4354                     l_return_value := wsmputil.CHECK_WMTI(   -- CZH.I
4355                             P_WIP_ENTITY_ID => null,
4356                             P_WIP_ENTITY_NAME => v_wlji_job_name(v_index),
4357                             P_TRANSACTION_DATE => null,
4358                             X_ERR_CODE => l_error_code,
4359                             X_ERR_MSG => l_err_msg,
4360                             P_ORGANIZATION_ID => v_wlji_org(v_index)
4361                             );
4362                     IF (l_return_value > 0 OR l_return_value <> 0) THEN
4363                         process_errorred_field('WSM',
4364                                                'WSM_PENDING_MOVE_TXNS',
4365                                                l_stmt_num);
4366                         l_error_code := -1;
4367                         GOTO skip_job_id_valid;
4368                     END IF;
4369                     */
4370                     /*Bug 3414163:End of changes*/
4371 l_stmt_num := 460.2;
4372                     -- bug 3453139 remove this
4373                     --l_return_value := wsmputil.CHECK_WSMT(   -- CZH.I
4374                     --        P_WIP_ENTITY_ID => null,
4375                     --        P_WIP_ENTITY_NAME => v_wlji_job_name(v_index),
4376                     --        P_TRANSACTION_ID => NULL,
4377                     --        P_TRANSACTION_DATE => null,
4378                     --        X_ERR_CODE => l_error_code,
4379                     --        X_ERR_MSG => l_err_msg,
4380                     --        P_ORGANIZATION_ID => v_wlji_org(v_index)
4381                     --        );
4382 
4383                     --IF (l_return_value > 0 OR l_return_value <> 0) THEN
4384                     --    FND_MESSAGE.SET_NAME('WSM', 'WSM_PENDING_TXN');
4385                     --    FND_MESSAGE.SET_TOKEN('TABLE', 'wsm_split_merge_transactions');
4386                     --    l_err_msg := fnd_message.get;
4387                     --    l_error_code := -1;
4388                     --    HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
4389                     --    l_error_code := -1;
4390                     --    GOTO skip_job_id_valid;
4391                     --ELSE
4392                     --    l_error_code := 0;
4393                     --    l_err_msg := '';
4394                     --END IF;
4395 
4396 
4397 
4398                     Begin
4399                         l_dummy := 0;
4400                         if v_wlji_load_type(v_index) = 5 then
4401 
4402                             if (v_wlji_job_name(v_index) is null) then
4403 
4404                                 -- Derive JOB_NAME.
4405                                 select FND_Profile.value('WIP_JOB_PREFIX') || wip_job_number_s.nextval
4406                                 into   v_wlji_job_name(v_index)
4407                                 from   dual ;
4408 
4409                             else
4410 
4411                                 -- Be sure the provided JOB_NAME is not already in use.
4412                                 begin
4413 
4414                                     select 1 into l_dummy
4415                                     from   wip_entities
4416                                     where
4417                                         wip_entity_name = v_wlji_job_name(v_index) and
4418                                         organization_id = v_wlji_org(v_index);
4419 
4420                                     if l_dummy = 1 then
4421                                         process_errorred_field('WIP',
4422                                                                'WIP_ML_JOB_NAME',
4423                                                                l_stmt_num);
4424                                         l_error_code := -1;
4425                                         GOTO skip_job_id_valid;
4426                                     end if;
4427 
4428                                 exception
4429 
4430                                     -- This Exception added by BBK .
4431                                     when no_data_found then
4432                                             null;
4433 
4434                                     when others then
4435                                             process_errorred_field('WIP',
4436                                                                    'WIP_ML_JOB_NAME',
4437                                                                    l_stmt_num);
4438                                             l_error_code := -1;
4439                                             GOTO skip_job_id_valid;
4440                                 end ;
4441 
4442                             end if ;
4443 
4444                         elsif v_wlji_load_type(v_index) = 6 then
4445 
4446                             if (v_wlji_wip_entity_id(v_index) is null) then
4447 
4448                                 if (v_wlji_job_name(v_index) is null) then
4449                                     raise invalid_job_name_error;
4450                                 end if ;
4451 
4452                                 begin
4453                                     select wip_entity_id
4454                                     into   v_wlji_wip_entity_id(v_index)
4455                                     from   wip_entities
4456                                     where
4457                                         wip_entity_name = v_wlji_job_name(v_index) and
4458                                         organization_id = v_wlji_org(v_index) ;
4459                                 exception when others then
4460                                     raise invalid_job_name_error;
4461                                 end ;
4462 
4463                             else
4464                                 begin
4465 
4466                                     /* commented out by BBK as per Hari to remove dual usage.
4467                                     select 1 into l_dummy from dual where exists (
4468                                         select 1
4469                                         from   wip_discrete_jobs
4470                                         where
4471                                             wip_entity_id = v_wlji_wip_entity_id(v_index) and
4472                                             organization_id = v_wlji_org(v_index) and
4473                                             status_type in (
4474                                                 WIP_CONSTANTS.UNRELEASED,
4475                                                 WIP_CONSTANTS.RELEASED,
4476                                                 WIP_CONSTANTS.HOLD,
4477                                                 WIP_CONSTANTS.CANCELLED)
4478                                         );
4479                                     */
4480                                     -- added by BBK.
4481                                     select 1 into l_dummy
4482                                     from   wip_discrete_jobs
4483                                     where
4484                                         wip_entity_id = v_wlji_wip_entity_id(v_index) and
4485                                         status_type in (
4486                                             WIP_CONSTANTS.UNRELEASED,
4487                                             WIP_CONSTANTS.RELEASED,
4488                                             WIP_CONSTANTS.HOLD,
4489                                             WIP_CONSTANTS.CANCELLED) ;
4490                                 exception
4491                                     -- This Exception added by BBK .
4492                                     when no_data_found then
4493                                         raise invalid_id_error;
4494                                     when others then
4495                                         raise invalid_id_error;
4496                                 end ;
4497 
4498                             end if ;
4499                         end if;
4500 
4501                     Exception
4502                         when invalid_id_error then
4503                             l_aux_mesg := '';
4504                             process_invalid_field('WIP_ENTITY_ID',
4505                                                   l_aux_mesg,
4506                                                   l_stmt_num);
4507                             l_error_code := -1;
4508 
4509                         when invalid_job_name_error then
4510                             l_aux_mesg := '';
4511                             process_invalid_field('JOB_NAME',
4512                                                   l_aux_mesg,
4513                                                   l_stmt_num);
4514                             l_error_code := -1;
4515 
4516                     End;
4517 
4518 << skip_job_id_valid >>
4519 
4520                     if l_error_code <> 0 then
4521                         l_error_count := l_error_count + 1;
4522                         GOTO skip_other_steps;
4523                     end if;
4524                     l_aux_mesg := '';
4525 
4526                     if lbji_debug = 'Y' then
4527                         fnd_file.put_line(fnd_file.log, 'Job Name and Id Validation.. Success.');
4528                     end if;
4529 
4530                     l_dummy := 0;
4531                     -- *** validate job name and id end ***
4532 
4533 
4534 l_stmt_num := 480;
4535                     -- *** validate class code begin ***
4536                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
4537                         begin
4538 
4539                             IF v_wlji_class_code(v_index) is NULL then
4540 
4541                                 begin
4542                                     select wse.DEFAULT_ACCT_CLASS_CODE
4543                                     into   v_wlji_class_code(v_index)
4544                                     from   wsm_sector_extensions wse, wsm_item_extensions wie
4545                                     where  wie.INVENTORY_ITEM_ID = v_wlji_item(v_index)
4546                                     and    wie.ORGANIZATION_ID = v_wlji_org(v_index)
4547                                     and    wie.SECTOR_EXTENSION_ID = wse.SECTOR_EXTENSION_ID
4548                                     and    wie.ORGANIZATION_ID = wse.ORGANIZATION_ID;
4549                                 exception
4550                                     WHEN NO_DATA_FOUND THEN
4551                                         v_wlji_class_code(v_index) := NULL;
4552                                 end;
4553 
4554                                 IF v_wlji_class_code(v_index) is NULL then
4555 
4556                                     begin
4557 
4558                                         select wse.DEFAULT_ACCT_CLASS_CODE
4559                                         into   v_wlji_class_code(v_index)
4560                                         from   wsm_sector_extensions wse, wsm_subinventory_extensions wve
4561                                         where  wve.SECONDARY_INVENTORY_NAME = v_wlji_completion_subinventory(v_index)
4562                                         and    wve.ORGANIZATION_ID = v_wlji_org(v_index)
4563                                         and    wve.SECTOR_EXTENSION_ID = wse.SECTOR_EXTENSION_ID
4564                                         and     wve.ORGANIZATION_ID = wse.ORGANIZATION_ID;
4565                                     exception
4566                                         WHEN NO_DATA_FOUND THEN
4567                                             v_wlji_class_code(v_index) := NULL;
4568                                     end;
4569 
4570                                     IF v_wlji_class_code(v_index) is NULL then
4571                                         v_wlji_class_code(v_index) := WSMPLCVA.v_org(v_wlji_org(v_index)).DEFAULT_ACCT_CLASS_CODE;
4572                                     END IF;
4573 
4574                                 END IF;
4575 
4576                                 IF v_wlji_class_code(v_index) IS NULL THEN
4577                                     raise no_data_found;
4578                                 END IF;
4579 
4580                             ELSE
4581                                 str := to_char(v_wlji_org(v_index))||v_wlji_class_code(v_index);
4582                                 hash_value := dbms_utility.get_hash_value(str, 37, 1073741824);
4583                                 if WSMPLCVA.v_class_code.exists(hash_value) then
4584                                     NULL;
4585                                 else
4586                                     raise no_data_found;
4587                                 end if;
4588                             END IF;
4589 
4590                         exception
4591                             WHEN no_data_found  THEN
4592                                 l_aux_mesg := 'Or class code maybe NULL';
4593                                 process_invalid_field('CLASS_CODE',
4594                                                       l_aux_mesg,
4595                                                       l_stmt_num);
4596                                 l_error_code := -1;
4597                         end;
4598 
4599 
4600                         if l_error_code <> 0 then
4601                             l_error_count := l_error_count + 1;
4602                             GOTO skip_other_steps;
4603                         end if;
4604                         l_aux_mesg := '';
4605                         str := '';
4606                         hash_value := 0;
4607 
4608                         if lbji_debug = 'Y' then
4609                             fnd_file.put_line(fnd_file.log, 'Class Code Validation.. Success.');
4610                         end if;
4611 
4612                     end if; -- load type 5
4613                     -- *** validate class code end ***
4614 
4615 
4616 l_stmt_num := 500;
4617                     -- *** default lot_number begin ***
4618                     if v_wlji_load_type(v_index) = 5 then
4619                         v_wlji_lot_number(v_index) := v_wlji_job_name(v_index);
4620 
4621                         if lbji_debug = 'Y' then
4622                             fnd_file.put_line(fnd_file.log, 'Lot Number Defaulted.. Success.');
4623                         end if;
4624                     end if; -- load type 5
4625                     -- *** default lot_number end ***
4626 
4627 
4628 l_stmt_num := 520;
4629                     -- *** get revisions begin ***
4630                     -- this procedure is called only after date validation so that the start date is not null.
4631                     -- this is to be called only for job creation.
4632 
4633                     -- CZH.I_OED-1: if we are creating a job (load_type = 5), wip_revisions.routing_revision
4634                     -- is called, hence, v_wlji_routing_revision_date(v_index) will be populated
4635 
4636                     if v_wlji_load_type(v_index) = 5 and v_wlji_job_type(v_index) <> 3 then
4637 
4638                         if v_wlji_fusd(v_index) > SYSDATE then
4639                             l_rev_date := v_wlji_fusd(v_index);
4640                         else
4641                             l_rev_date := SYSDATE;
4642                         end if;
4643 
4644                         wip_revisions.bom_revision (v_wlji_org(v_index),
4645                                                     v_wlji_item(v_index),
4646                                                     v_wlji_bom_revision(v_index),
4647                                                     v_wlji_bom_revision_date(v_index),
4648                                                     l_rev_date);
4649 
4650 
4651                         wip_revisions.routing_revision (v_wlji_org(v_index),
4652                                                         v_wlji_item(v_index),
4653                                                         v_wlji_routing_revision(v_index),
4654                                                         v_wlji_routing_revision_date(v_index),
4655                                                         l_rev_date);
4656 
4657                         if l_error_code <> 0 then
4658                             l_error_count := l_error_count + 1;
4659                             GOTO skip_other_steps;
4660                         end if;
4661 
4662                         if lbji_debug = 'Y' then
4663                             fnd_file.put_line(fnd_file.log, 'Getting Revisions.. Success.');
4664                         end if;
4665 
4666                     end if; -- load type 5
4667                     -- *** get revisions end ***
4668 
4669 
4670 l_stmt_num := 540;
4671                     -- *** default description begin ***
4672                     -- this is to be called only for job creation.
4673                     if v_wlji_load_type(v_index) = 5 then
4674                         if RTRIM(v_wlji_description(v_index)) is NULL then
4675                             l_date_text := fnd_date.date_to_charDT(dateval =>sysdate,calendar_aware => 1) ;
4676                             fnd_message.set_name('WIP','WIP_MLD_DESC');
4677                             fnd_message.set_token('LOAD_DATE', l_date_text, false) ;
4678                             v_wlji_description(v_index) := FND_Message.get;
4679                         else
4680                             v_wlji_description(v_index) := RTRIM(v_wlji_description(v_index));
4681                         end if;
4682 
4683                         if lbji_debug = 'Y' then
4684                             fnd_file.put_line(fnd_file.log, 'Default Description.. Success.');
4685                         end if;
4686                     end if; -- load type 5
4687                     -- *** default description end ***
4688 
4689 
4690 
4691                     if v_wlji_load_type(v_index) = 5 then
4692 
4693 l_stmt_num := 560;
4694                         -- *** validations for the starting lot in wsli. These validations are ***
4695                         -- *** to be performed only for jobs of mode flag 2.                   ***
4696 
4697                         if v_wlji_mode_flag(v_index) = 2 then
4698                         -- *** validation of starting lot begin ***
4699 l_stmt_num := 600;
4700                             -- BA: bug 3299026 do not allow serial controlled component
4701                             select  SERIAL_NUMBER_CONTROL_CODE,
4702                                     revision_qty_control_code       -- Add bug 2963225
4703                             into    l_dummy,
4704                                     l_rev_control_code              -- Add bug 2963225
4705                             from    mtl_system_items_kfv msi
4706                             where   msi.inventory_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
4707                             and     msi.organization_id = v_wlji_org(v_index);
4708 
4709                             if(l_dummy <> 1) then
4710                                 l_error_code := -1;
4711                                 process_errorred_field('WSM',
4712                                                        'WSM_SERIAL_COMP_NOT_SUPPORTED',
4713                                                        l_stmt_num);
4714                                 l_error_count := l_error_count + 1;
4715                                 GOTO skip_other_steps;
4716                             end if;
4717                             --EA bug 3299026
4718 
4719                             -- *** last_updated_by ***
4720 l_stmt_num := 601;
4721                             xst :=  WSMPLCVA.v_user.exists(v_wsli(v_wlji_source_line_id(v_index)).last_updated_by);
4722                             if xst = false then
4723                                 begin
4724                                     select 1
4725                                     into   l_no_of_records
4726                                     from   fnd_user
4727                                     where  user_id = v_wsli(v_wlji_source_line_id(v_index)).last_updated_by
4728                                     and    sysdate between start_date and nvl(end_date,sysdate+1);
4729                                 exception
4730                                     when too_many_rows then l_no_of_records := 1;
4731                                     when no_data_found then
4732                                         l_error_code := -1;
4733                                         l_aux_mesg := '';
4734                                         process_invalid_field( 'Last Updated By in WSM_STARTING_LOTS_INTERFACE',
4735                                                                 l_aux_mesg,
4736                                                                 l_stmt_num);
4737                                 end;
4738                             end if;
4739 
4740                             if xst = false AND l_no_of_records <> 0 then
4741                                 WSMPLCVA.v_user(v_wsli(v_wlji_source_line_id(v_index)).last_updated_by)
4742                                     := v_wsli(v_wlji_source_line_id(v_index)).last_updated_by;
4743                             end if;
4744 
4745                             if l_error_code <> 0 then
4746                                 l_error_count := l_error_count + 1;
4747                                 GOTO skip_other_steps;
4748                             end if;
4749                             l_aux_mesg := '';
4750                             l_no_of_records := 0;
4751                             xst := true;
4752 
4753                             -- *** created_by ***
4754 l_stmt_num := 602;
4755                             xst :=  WSMPLCVA.v_user.exists(v_wsli(v_wlji_source_line_id(v_index)).created_by);
4756                             if xst = false then
4757                                 begin
4758                                     select 1
4759                                     into   l_no_of_records
4760                                     from   fnd_user
4761                                     where  user_id = v_wsli(v_wlji_source_line_id(v_index)).created_by
4762                                     and    sysdate between start_date and nvl(end_date,sysdate+1);
4763                                 exception
4764                                     when too_many_rows then l_no_of_records := 1;
4765                                     when no_data_found then
4766                                         l_error_code := -1;
4767                                         l_aux_mesg := '';
4768                                         process_invalid_field( 'CREATED BY in WSM_STARTING_LOTS_INTERFACE',
4769                                                                 l_aux_mesg,
4770                                                                 l_stmt_num);
4771                                 end;
4772                             end if;
4773 
4774                             if xst = false AND l_no_of_records <> 0 then
4775                                 WSMPLCVA.v_user(v_wsli(v_wlji_source_line_id(v_index)).created_by)
4776                                             := v_wsli(v_wlji_source_line_id(v_index)).created_by;
4777                             end if;
4778 
4779                             if l_error_code <> 0 then
4780                                 l_error_count := l_error_count + 1;
4781                                 GOTO skip_other_steps;
4782                             end if;
4783                             l_aux_mesg := '';
4784                             l_no_of_records := 0;
4785                             xst := true;
4786                             -- *** created_by ***
4787 
4788 
4789 l_stmt_num := 603;
4790                             begin
4791 
4792                                 select 1 into l_dummy
4793                                 from   mtl_transaction_lots_temp
4794                                 where  lot_number = v_wsli(v_wlji_source_line_id(v_index)).lot_number
4795                                 and    rownum = 1;
4796 
4797                                 if l_dummy <>0 then
4798                                     SELECT 0 into l_dummy
4799                                     FROM   mtl_material_transactions_temp mmtt
4800                                     WHERE  mmtt.organization_id = v_wsli(v_wlji_source_line_id(v_index)).organization_id
4801                                     and    mmtt.inventory_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
4802                                     and    NVL(mmtt.lot_number, '@#$') = v_wsli(v_wlji_source_line_id(v_index)).lot_number
4803                                     and    mmtt.subinventory_code = v_wsli(v_wlji_source_line_id(v_index)).subinventory_code
4804                                     and    NVL(mmtt.locator_id, -9999) = NVL(v_wsli(v_wlji_source_line_id(v_index)).locator_id, -9999)
4805                                     and    mmtt.transaction_type_id = 42 -- Miscellaneous Receipt
4806                                     and    mmtt.transaction_action_id = 27 -- Receipt into stores
4807                                     and    mmtt.transaction_source_type_id = 13 -- Inventory
4808                                     and    v_wsli(v_wlji_source_line_id(v_index)).quantity = ((-1) * mmtt.transaction_quantity)
4809                                     and    mmtt.transaction_date = (
4810                                             SELECT max(mmtt2.transaction_date)
4811                                             FROM mtl_material_transactions_temp mmtt2
4812                                             WHERE mmtt2.organization_id = v_wsli(v_wlji_source_line_id(v_index)).organization_id
4813                                             and mmtt2.inventory_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
4814                                             and NVL(mmtt2.lot_number, '@#$') = NVL(v_wsli(v_wlji_source_line_id(v_index)).lot_number, '@#$')
4815                                             and mmtt2.subinventory_code = v_wsli(v_wlji_source_line_id(v_index)).subinventory_code
4816                                             and NVL(mmtt2.locator_id, -9999) = NVL(v_wsli(v_wlji_source_line_id(v_index)).locator_id, -9999)
4817                                         );
4818                                 end if;
4819                                 If l_dummy <> 0 then
4820                                     fnd_message.set_name('WSM', 'WSM_PENDING_TXN');
4821                                     FND_MESSAGE.SET_TOKEN('TABLE',
4822                                        'Starting Lot:'||v_wsli(v_wlji_source_line_id(v_index)).lot_number
4823                                        ||'Table: mtl_transaction_lots_temp ');
4824                                     l_err_msg := fnd_message.get;
4825                                     l_error_code := -1;
4826                                     HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
4827                                 END IF;
4828 
4829                             exception
4830                                 When NO_DATA_FOUND Then
4831                                     Null;
4832                             end;
4833 
4834                             if l_error_code <> 0 then
4835                                 l_error_count := l_error_count + 1;
4836                                 GOTO skip_other_steps;
4837                             end if;
4838                             l_err_msg := '';
4839                             l_dummy := 0;
4840 
4841 
4842 l_stmt_num := 604;
4843                             -- check that the item in the inventory lot exists as a component of the
4844                             -- assembly item for the given alt bom designator, attached at the first operation.
4845 
4846                             wsmputil.find_common_routing(
4847                                             p_routing_sequence_id => routing_seq_id,
4848                                             p_common_routing_sequence_id => p_common_routing_sequence_id,
4849                                             x_err_code => l_error_code,
4850                                             x_err_msg => l_err_msg);
4851 
4852                             if l_error_code <> 0 OR l_err_msg IS NOT NULL then
4853                                 HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
4854                                 l_error_code := -1;
4855                             end if;
4856 
4857 
4858 l_stmt_num := 604.1;
4859                             -- BA: CZH.I_OED-1
4860                             -- This is for Mode 2 job creation. Hence, v_wlji_routing_revision_date(v_index)
4861                             -- should have been populated
4862                             l_rtg_rev_date := v_wlji_routing_revision_date(v_index);
4863                             l_bom_rev_date := v_wlji_bom_revision_date(v_index); --BUGFIX 2380517
4864                             -- EA: CZH.I_OED-1
4865 
4866                             wsmputil.find_routing_start(
4867                                             p_common_routing_sequence_id,
4868                                             l_rtg_rev_date,              -- ADD: CZH.I_OED-1
4869                                             l_start_op_seq_id,
4870                                             l_error_code,
4871                                             l_err_msg );
4872 
4873                             if l_error_code <> 0 OR l_err_msg IS NOT NULL then
4874                                 HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
4875                                 l_error_code := -1;
4876                             end if;
4877 
4878                             --BA: CZH.I_OED-2
4879                             l_start_op_seq_id := wsmputil.replacement_op_seq_id(
4880                                                             l_start_op_seq_id,
4881                                                             l_rtg_rev_date);
4882                             --EA: CZH.I_OED-2
4883 
4884                             if l_error_code = 0 then
4885                                 begin
4886                                     SELECT  1
4887                                     INTO    l_dummy
4888                                     FROM    BOM_INVENTORY_COMPONENTS BIC,
4889                                             MTL_SYSTEM_ITEMS C
4890                                     WHERE   BIC.COMPONENT_ITEM_ID = C.INVENTORY_ITEM_ID
4891                                     AND     C.ORGANIZATION_ID = v_wlji_org(v_index)
4892                                     AND     BIC.BILL_SEQUENCE_ID = bom_seq_id
4893                                     AND     BIC.COMPONENT_ITEM_ID = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
4894                                     AND     (BIC.operation_seq_num = (SELECT BOS.operation_seq_num
4895                                                                       FROM   BOM_OPERATION_SEQUENCES BOS
4896                                                                       WHERE  operation_sequence_id = l_start_op_seq_id )
4897                                              OR
4898                                              BIC.operation_seq_num = 1)
4899                                     -- BC: BUGFIX 2380517 (CZH.I_OED-2)
4900                                     --AND   EFFECTIVITY_DATE <= SYSDATE
4901                                     --AND   nvl(DISABLE_DATE, SYSDATE + 1) > SYSDATE
4902                                     AND     l_bom_rev_date between BIC.EFFECTIVITY_DATE
4903                                                            and     nvl(BIC.DISABLE_DATE, l_bom_rev_date + 1)
4904                                     -- EC: BUGFIX 2380517
4905                                     AND     EFFECTIVITY_DATE =(
4906                                                 SELECT  MAX (EFFECTIVITY_DATE)
4907                                                 FROM    BOM_INVENTORY_COMPONENTS BIC2,
4908                                                         ENG_REVISED_ITEMS        ERI
4909                                                 WHERE   BIC2.BILL_SEQUENCE_ID = BIC.BILL_SEQUENCE_ID
4910                                                 AND     BIC2.COMPONENT_ITEM_ID = BIC.COMPONENT_ITEM_ID
4911                                                 AND     (decode(BIC2.IMPLEMENTATION_DATE,
4912                                                                 NULL, BIC2.OLD_COMPONENT_SEQUENCE_ID,
4913                                                                 BIC2.COMPONENT_SEQUENCE_ID) =
4914                                                          decode(BIC.IMPLEMENTATION_DATE,
4915                                                                 NULL, BIC.OLD_COMPONENT_SEQUENCE_ID,
4916                                                                 BIC.COMPONENT_SEQUENCE_ID)
4917                                                          OR BIC2.OPERATION_SEQ_NUM = BIC.OPERATION_SEQ_NUM)
4918                                                 --AND   BIC2.EFFECTIVITY_DATE <= SYSDATE       --BUGFIX 2380517
4919                                                 AND     BIC2.EFFECTIVITY_DATE <= l_bom_rev_date  --BUGFIX 2380517
4920                                                 AND     BIC2.REVISED_ITEM_SEQUENCE_ID =
4921                                                         ERI.REVISED_ITEM_SEQUENCE_ID(+)
4922                                                 AND     ( NVL(ERI.STATUS_TYPE,6) IN (4,6,7))
4923                                                 AND     NOT EXISTS (
4924                                                             SELECT 'X'
4925                                                             FROM   BOM_INVENTORY_COMPONENTS BICN,
4926                                                                    ENG_REVISED_ITEMS ERI1
4927                                                             WHERE  BICN.BILL_SEQUENCE_ID = BIC.BILL_SEQUENCE_ID
4928                                                             AND    BICN.OLD_COMPONENT_SEQUENCE_ID =
4929                                                                    BIC.COMPONENT_SEQUENCE_ID
4930                                                             AND    BICN.ACD_TYPE in (2,3)
4931                                                             --AND  BICN.DISABLE_DATE <= SYSDATE       --BUGFIX 2380517
4932                                                             AND    BICN.DISABLE_DATE <= l_bom_rev_date  --BUGFIX 2380517
4933                                                             AND    ERI1.REVISED_ITEM_SEQUENCE_ID = BICN.REVISED_ITEM_SEQUENCE_ID
4934                                                             AND    ( nvl(ERI1.STATUS_TYPE,6) IN (4,6,7) )
4935                                                         )
4936                                             );
4937                                 exception
4938                                     -- BA: BUGFIX 2380517
4939                                     when no_data_found then
4940                                         l_error_code := -1;
4941                                         fnd_message.set_name('WSM','WSM_INVALID_BOM_ROUT');
4942                                         l_err_msg := fnd_message.get;
4943                                         handle_error(l_error_code, l_err_msg, l_stmt_num);
4944                                     --EA: BUGFIX 2380517
4945 
4946                                     when others then
4947                                         l_error_code := SQLCODE;
4948                                         l_err_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
4949                                         handle_error(l_error_code, l_err_msg, l_stmt_num);
4950                                 end;
4951                             end if;
4952 
4953                             if l_error_code <> 0 then
4954                                 l_error_count := l_error_count + 1;
4955                                 GOTO skip_other_steps;
4956                             end if;
4957                             l_dummy := 0;
4958                             l_err_msg := '';
4959 
4960                             if lbji_debug = 'Y' then
4961                                 fnd_file.put_line(fnd_file.log, 'Verify that the component is reqd. at the first operation of the assembly.. Success');
4962                             end if;
4963 
4964 l_stmt_num := 640;
4965                             -- abbKanban begin
4966                             if v_wlji_kanban_card_id(v_index) is not null then
4967                                 if honor_kanban_size(v_wlji_org(v_index),
4968                                                      v_wlji_item(v_index),
4969                                                      v_wlji_completion_subinventory(v_index),
4970                                                      v_wlji_completion_locator_id(v_index),
4971                                                      -1) = 1 then
4972                                     select kanban_size
4973                                     into   l_kanban_size
4974                                     from   mtl_kanban_cards
4975                                     where  kanban_card_id = v_wlji_kanban_card_id(v_index);
4976 
4977                                     if v_wlji_start_quantity(v_index) > l_kanban_size then
4978                                         v_wlji_start_quantity(v_index) := l_kanban_size;
4979                                         v_wlji_net_quantity(v_index) := v_wlji_start_quantity(v_index);
4980                                     end if;
4981                                 end if;
4982                             end if;
4983                             -- abbKanban end
4984 
4985                             -- *** begin validate quantity ***
4986 l_stmt_num := 645;
4987                             -- BC: bug 3852078  do not use wsm_components_v
4988                             /*****
4989                             SELECT  component_quantity, component_yield_factor
4990                             INTO    l_component_quantity, l_component_yield_factor
4991                             FROM    wsm_components_v
4992                             WHERE   assembly_item_id = v_wlji_item(v_index)
4993                             AND     component_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
4994                             AND     nvl(alternate_bom_designator,'NULL') = nvl(v_wlji_alt_bom_designator(v_index),'NULL')
4995                             AND     organization_id = v_wlji_org(v_index);
4996                             *****/
4997 
4998                             SELECT  bic.component_quantity,
4999                                     decode(bic.component_yield_factor, 0, 1,
5000                                            bic.component_yield_factor) component_yield_factor,
5001                                     bic.basis_type             -- LBM enh
5002                             INTO    l_component_quantity,
5003                                     l_component_yield_factor,
5004                                     l_comp_basis_type           -- LBM enh
5005                             from    mtl_System_items msi,
5006                                     bom_inventory_components bic,
5007                                     bom_bill_of_materials bom,
5008                                     bom_bill_of_materials bom2
5009                             WHERE   bic.bill_sequence_id = bom2.bill_sequence_id
5010                             and     bom.common_bill_sequence_id = bom2.bill_sequence_id
5011                             and     msi.organization_id = bom.organization_id
5012                             and     msi.inventory_item_id = bom.assembly_item_id
5013                             and     msi.build_in_wip_flag = 'Y'
5014                             and     msi.pick_components_flag = 'N'
5015                             and     bic.implementation_date is not null
5016                             and     bom.assembly_item_id = v_wlji_item(v_index)
5017                             and     bic.component_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
5018                             and     bom.organization_id = v_wlji_org(v_index)
5019                             and     nvl(bom.alternate_bom_designator,'NULL') = nvl(v_wlji_alt_bom_designator(v_index),'NULL')
5020                             and     l_bom_rev_date between bic.effectivity_date
5021                                                    and     nvl(bic.disable_date, l_bom_rev_date + 1);
5022                             -- EC: bug 3852078
5023 
5024                             -- quantity of component required per assembly
5025                            --3913296:Rounding of required qty is removed and to be issued is rounded
5026                             --l_required_quantity := round((l_component_quantity / l_component_yield_factor), 6);
5027                             l_required_quantity := l_component_quantity / l_component_yield_factor;
5028                             -- LBM enh
5029                             if nvl(l_comp_basis_type, 1) = 2 then  --lot based
5030                                 l_quantity_tobe_issued := round(l_required_quantity, 6);
5031                             else   -- item based
5032                                 l_quantity_tobe_issued := round(l_required_quantity * v_wlji_start_quantity(v_index),6);
5033                             end if;
5034                             -- end LBM enh
5035 
5036 l_stmt_num := 646;
5037                             if v_wsli(v_wlji_source_line_id(v_index)).comp_issue_quantity is not null then
5038                                 if v_wsli(v_wlji_source_line_id(v_index)).comp_issue_quantity <= 0 then
5039                                     l_error_code := -1;
5040                                     process_errorred_field('WSM',
5041                                                            'WSM_QTY_ISSUE_NO_NEG',
5042                                                            l_stmt_num);
5043                                 else
5044                                     l_quantity_tobe_issued := v_wsli(v_wlji_source_line_id(v_index)).comp_issue_quantity;
5045                                 end if;
5046                             end if;
5047 l_stmt_num := 648;
5048                             -- if the user does not provide a revision in wsm_starting_lots_interface
5049                             -- then get the current revision and use that to issue components. if user
5050                             -- provides one, validate it
5051 
5052                             l_source_item_rev := v_wsli(v_wlji_source_line_id(v_index)).revision;
5053                             declare
5054                                 err_lot_revision    exception;  -- Add: bug 2963225
5055                             begin
5056                                 -- BC: bug 2963225 this is to validate the revision of the item
5057                                 -- which is not right, instead, we should validate / default
5058                                 -- the revision of the starting lot, so comment out the following
5059 
5060                                 --l_rev_sysdate := sysdate;
5061                                 --wip_revisions.bom_revision (
5062                                 --       v_wlji_org(v_index),
5063                                 --       v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id,
5064                                 --       l_source_item_rev,
5065                                 --       l_source_item_rev_date,
5066                                 --       l_rev_sysdate);
5067 
5068                                 if l_rev_control_code = 1 then -- not revision control
5069                                     if(l_source_item_rev is not null) then
5070                                         raise err_lot_revision;
5071                                     end if;
5072                                 else    -- revision control item
5073                                     select  revision
5074                                     into    l_start_lot_revision
5075                                     from    WSM_source_lots_v
5076                                     where   lot_number = v_wsli(v_wlji_source_line_id(v_index)).lot_number
5077                                     and     organization_id = v_wlji_org(v_index)
5078                                     and     inventory_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id;
5079 
5080                                     if(l_source_item_rev is null) then
5081                                         v_wsli(v_wlji_source_line_id(v_index)).revision := l_start_lot_revision;
5082                                     elsif(l_source_item_rev <> l_start_lot_revision) then
5083                                         raise err_lot_revision;
5084                                     end if;
5085                                 end if;
5086                                 -- EC: bug 2963225
5087 
5088                             exception
5089                                 when err_lot_revision then  -- Add: bug 2963225
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 
5095                                 when others then
5096                                     l_error_code := -1;
5097                                     l_error_count := l_error_count +1;
5098                                     process_invalid_field('Component Lot Revision', '', l_stmt_num);
5099                                     GOTO skip_other_steps;
5100                             end;
5101 
5102 l_stmt_num := 650;
5103                             wsmputil.return_att_quantity(p_org_id => v_wlji_org(v_index),
5104                                  p_item_id => v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id,
5105                                  p_rev => v_wsli(v_wlji_source_line_id(v_index)).revision,
5106                                  p_lot_no => v_wsli(v_wlji_source_line_id(v_index)).lot_number,
5107                                  p_subinv => v_wsli(v_wlji_source_line_id(v_index)).subinventory_code,
5108                                  p_locator_id => v_wsli(v_wlji_source_line_id(v_index)).locator_id,
5109                                  p_qoh => l_qoh,
5110                                  p_atr => l_atr,
5111                                  p_att => l_att,
5112                                  p_err_code => l_error_code,
5113                                  p_err_msg => l_err_msg );
5114 
5115                             if l_error_code <> 0 then
5116                                 HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
5117                                 l_error_count := l_error_count + 1;
5118                                 GOTO skip_other_steps;
5119                             end if;
5120 
5121                             if l_quantity_tobe_issued > l_att then
5122                                 -- bug 3741740 remove this validation because we allow issue
5123                                 -- less quantity than job required quantity through form
5124                                 -- we will issue all the quantity if qty_tobe_issued > l_att
5125                                 l_quantity_tobe_issued := l_att;
5126                                 --l_error_code := -1;
5127                                 --process_errorred_field('WSM',
5128                                 --                       'WSM_INSUFFICIENT_QTY',
5129                                 --                       l_stmt_num);
5130                             end if;
5131 
5132 
5133                             if l_error_code <> 0 then
5134                                     l_error_count := l_error_count + 1;
5135                                     GOTO skip_other_steps;
5136                             end if;
5137 
5138                             if lbji_debug = 'Y' then
5139                                 fnd_file.put_line(fnd_file.log, 'Mode 2 Quantity Verification.. Success');
5140                             end if;
5141                             -- *** end validate quantity ***
5142 
5143 
5144 l_stmt_num := 661;
5145                             -- *** validate starting lot is not phantom begin ***
5146                             begin
5147                                 SELECT  1
5148                                 INTO    l_dummy
5149                                 FROM    BOM_INVENTORY_COMPONENTS BIC,
5150                                         MTL_SYSTEM_ITEMS         C
5151                                 WHERE   BIC.COMPONENT_ITEM_ID = C.INVENTORY_ITEM_ID
5152                                 AND     C.ORGANIZATION_ID = v_wlji_org(v_index)
5153                                 AND     BIC.BILL_SEQUENCE_ID = bom_seq_id
5154                                 AND     BIC.COMPONENT_ITEM_ID = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id
5155                                 AND     (BIC.operation_seq_num = (SELECT  BOS.operation_seq_num
5156                                                                   FROM    BOM_OPERATION_SEQUENCES BOS
5157                                                                   WHERE   operation_sequence_id = l_start_op_seq_id)
5158                                          OR BIC.operation_seq_num = 1 )
5159                                 AND     NVL(BIC.wip_supply_type, 1) <> 6  -- CHG: BUG 2696937/2652076
5160 
5161                                 -- BC: BUGFIX 2380517 (CZH.I_OED-2)
5162                                 --AND   EFFECTIVITY_DATE <= SYSDATE
5163                                 --AND   nvl(DISABLE_DATE, SYSDATE + 1) > SYSDATE
5164                                 AND     l_bom_rev_date between BIC.EFFECTIVITY_DATE
5165                                                        and     nvl(BIC.DISABLE_DATE, l_bom_rev_date + 1)
5166                                 -- EC: BUGFIX 2380517
5167                                 AND     EFFECTIVITY_DATE = (
5168                                             SELECT MAX(EFFECTIVITY_DATE)
5169                                             FROM   BOM_INVENTORY_COMPONENTS BIC2,
5170                                                    ENG_REVISED_ITEMS        ERI
5171                                             WHERE  BIC2.BILL_SEQUENCE_ID = BIC.BILL_SEQUENCE_ID
5172                                             AND    BIC2.COMPONENT_ITEM_ID = BIC.COMPONENT_ITEM_ID
5173                                             AND    (decode(BIC2.IMPLEMENTATION_DATE,
5174                                                            NULL, BIC2.OLD_COMPONENT_SEQUENCE_ID,
5175                                                            BIC2.COMPONENT_SEQUENCE_ID) =
5176                                                     decode(BIC.IMPLEMENTATION_DATE,
5177                                                            NULL, BIC.OLD_COMPONENT_SEQUENCE_ID,
5178                                                            BIC.COMPONENT_SEQUENCE_ID)
5179                                                     OR BIC2.OPERATION_SEQ_NUM = BIC.OPERATION_SEQ_NUM)
5180                                             --AND  BIC2.EFFECTIVITY_DATE <= SYSDATE      --BUGFIX 2380517
5181                                             AND    BIC2.EFFECTIVITY_DATE <= l_bom_rev_date --BUGFIX 2380517
5182                                             AND    BIC2.REVISED_ITEM_SEQUENCE_ID = ERI.REVISED_ITEM_SEQUENCE_ID(+)
5183                                             AND    (NVL(ERI.STATUS_TYPE,6) IN (4,6,7))
5184                                             AND    NOT EXISTS (
5185                                                        SELECT  'X'
5186                                                        FROM    BOM_INVENTORY_COMPONENTS BICN,
5187                                                                ENG_REVISED_ITEMS ERI1
5188                                                        WHERE   BICN.BILL_SEQUENCE_ID = BIC.BILL_SEQUENCE_ID
5189                                                        AND     BICN.OLD_COMPONENT_SEQUENCE_ID = BIC.COMPONENT_SEQUENCE_ID
5190                                                        AND     BICN.ACD_TYPE in (2,3)
5191                                                        --AND   BICN.DISABLE_DATE <= SYSDATE        --BUGFIX 2380517
5192                                                        AND     BICN.DISABLE_DATE <= l_bom_rev_date --BUGFIX 2380517
5193                                                        AND     ERI1.REVISED_ITEM_SEQUENCE_ID = BICN.REVISED_ITEM_SEQUENCE_ID
5194                                                        AND     ( NVL(ERI1.STATUS_TYPE,6) IN (4,6,7) )
5195                                                    )
5196                                         );
5197                             exception
5198                                 -- BA: BUGFIX 2380517
5199                                 when no_data_found then
5200                                     l_error_code := -1;
5201                                     fnd_message.set_name('WSM','WSM_INVALID_BOM_ROUT');
5202                                     l_err_msg := fnd_message.get;
5203                                     handle_error(l_error_code, l_err_msg, l_stmt_num);
5204                                 --EA: BUGFIX 2380517
5205                                 when others then
5206                                     l_error_code := -1;
5207                                     process_errorred_field('WSM',
5208                                                            'WSM_PHANTOM_COMP_NOT_ALLOWED',
5209                                                            l_stmt_num);
5210                             end;
5211 
5212                             if l_error_code <> 0 then
5213                                     l_error_count := l_error_count + 1;
5214                                     GOTO skip_other_steps;
5215                             end if;
5216                             l_dummy := 0;
5217                             l_err_msg := '';
5218 
5219                             if lbji_debug = 'Y' then
5220                             fnd_file.put_line(fnd_file.log, 'Verify that the starting lot is not phantom.. Success');
5221                             end if;
5222                             -- *** validate starting lot is not phantom end ***
5223 
5224                         end if; -- mode flag 2
5225                        -- *** end of mode flag 2 validations ***
5226 
5227                     end if; -- load type 5
5228 
5229 
5230                     -- *** check for disabled ops in the network and provide warning ***
5231                     if v_wlji_load_type(v_index) = 5 then
5232                         wsmputil.find_common_routing(
5233                                     p_routing_sequence_id => routing_seq_id,
5234                                     p_common_routing_sequence_id => p_common_routing_sequence_id,
5235                                     x_err_code => l_error_code,
5236                                     x_err_msg => l_err_msg);
5237 
5238 
5239                         if (wsmputil.network_with_disabled_op(
5240                                               p_common_routing_sequence_id,
5241                                               v_wlji_routing_revision_date(v_index),
5242                                               l_error_code,
5243                                               l_err_msg) = 1)
5244                         then
5245                             fnd_message.set_name('WSM','WSM_NET_HAS_DISABLED_OP');
5246                             l_err_msg := fnd_message.get;
5247                             l_warning_count := l_warning_count + 1;
5248                             handle_warning(p_err_msg => l_err_msg,
5249                                            p_header_id => v_wlji_header_id(v_index),
5250                                            p_request_id => v_wlji_request_id(v_index),
5251                                            p_program_id => v_wlji_program_id(v_index),
5252                                            p_program_application_id => v_wlji_program_application_id(v_index));
5253 
5254                         end if;
5255 
5256                     end if; -- load type 5
5257 
5258 
5259                     -- bugfix 2697295 begin
5260 l_stmt_num := 669;
5261                     if v_wlji_load_type(v_index) = 5 then
5262                         if (v_wlji_status_type(v_index) = WIP_CONSTANTS.UNRELEASED) and (v_wlji_date_released(v_index) is not null ) then
5263 
5264                             v_wlji_date_released(v_index) := null;
5265 
5266                             if lbji_debug = 'Y' then
5267                                 fnd_file.put_line(fnd_file.log, 'value for column DATE_RELEASED is being ignored for unreleased job');
5268                             end if;
5269                         elsif (v_wlji_status_type(v_index) = WIP_CONSTANTS.RELEASED ) then
5270                             if (v_wlji_date_released(v_index) > sysdate ) then
5271 
5272                                 l_error_code := -1;
5273                                 process_errorred_field('WIP',
5274                                                        'WIP_INVALID_RELEASE_DATE',
5275                                                        l_stmt_num);
5276 
5277                             elsif (v_wlji_date_released(v_index) is null) then
5278 
5279                                 v_wlji_date_released(v_index) := sysdate;
5280 
5281                             end if;
5282                         end if;
5283 
5284                         if l_error_code <> 0 then
5285                             l_error_count := l_error_count + 1;
5286                             GOTO skip_other_steps;
5287                         end if;
5288 
5289                         l_err_msg := '';
5290 
5291                         if lbji_debug = 'Y' then
5292                             fnd_file.put_line(fnd_file.log, 'Date_Released Validation.. First Phase Done.');
5293                         end if;
5294 
5295                     end if; -- load type 5
5296                     -- bugfix 2697295 ends
5297 
5298 
5299 l_stmt_num := 670;
5300 
5301                     if v_wlji_job_type(v_index) <> 3 then -- job type for schedule group and build sequence
5302 
5303                         -- *** validate schedule_group_id begin ***
5304                         if (v_wlji_load_type(v_index) = 6 and v_wlji_schedule_group_id(v_index) is NULL) then
5305                             select schedule_group_id
5306                             into   v_wlji_schedule_group_id(v_index)
5307                             from   wip_discrete_jobs
5308                             where  wip_entity_id = v_wlji_wip_entity_id(v_index)
5309                             and    organization_id = v_wlji_org(v_index);
5310                         end if;
5311 
5312                         if (v_wlji_source_code(v_index) = 'WICDOL' and v_wlji_schedule_group_name(v_index) IS NULL
5313                             and v_wlji_schedule_group_id(v_index) IS NULL) then
5314                             insert into wip_schedule_groups (
5315                                     schedule_group_id,
5316                                     schedule_group_name,
5317                                     organization_id,
5318                                     description,
5319                                     created_by,
5320                                     last_updated_by,
5321                                     creation_date,
5322                                     last_update_date)
5323                             select  wip_schedule_groups_s.nextval,
5324                                     wds.name,
5325                                     v_wlji_org(v_index),
5326                                     to_char(sysdate),
5327                                     l_user,
5328                                     l_user,
5329                                     sysdate,
5330                                     sysdate
5331                             from    wsh_new_deliveries wds
5332                             where   wds.delivery_id = v_wlji_delivery_id(v_index)
5333                                     and not exists  (
5334                                             select  1
5335                                             from    wip_schedule_groups wsg
5336                                             where   wsg.organization_id = v_wlji_org(v_index)
5337                                                     and WSG.schedule_group_name = WDS.name);
5338 
5339                             select wsg.schedule_group_name, wsg.schedule_group_id
5340                             into   v_wlji_schedule_group_name(v_index), v_wlji_schedule_group_id(v_index)
5341                             from   wip_schedule_groups wsg,
5342                                    wsh_new_deliveries wds
5343                             where  wds.delivery_id = v_wlji_delivery_id(v_index)
5344                                and wsg.schedule_group_name = wds.name
5345                                and wsg.organization_id = v_wlji_org(v_index);
5346                         end if;
5347 
5348                         if ((v_wlji_schedule_group_id(v_index) is not NULL) and (v_wlji_load_type(v_index) in (5,6))) then
5349                             begin
5350                                 select 1 into l_dummy
5351                                 from   wip_schedule_groups_val_v wsg
5352                                 where  wsg.schedule_group_id = v_wlji_schedule_group_id(v_index)
5353                                 and    wsg.organization_id = v_wlji_org(v_index);
5354                             exception
5355                                 when too_many_rows then
5356                                     l_dummy := 1;
5357                             end;
5358 
5359                             if l_dummy = 0 then
5360                                 l_error_code := -1;
5361                                 process_errorred_field('WIP',
5362                                                        'WIP_ML_SCHEDULE_GROUP',
5363                                                        l_stmt_num);
5364                             end if;
5365                         end if;
5366 
5367 
5368                         if l_error_code <> 0 then
5369                             l_error_count := l_error_count + 1;
5370                             GOTO skip_other_steps;
5371                         end if;
5372                         l_dummy := 0;
5373 
5374                         if lbji_debug = 'Y' then
5375                             fnd_file.put_line(fnd_file.log, 'Schedule Group Id Verification.. Success');
5376                         end if;
5377                         -- *** validate schedule_group_id end ***
5378 
5379 
5380 l_stmt_num := 690;
5381                         -- *** validate build_seq_id begin ***
5382                         begin
5383                             select
5384                                 nvl(v_wlji_build_sequence(v_index), WDJ.build_sequence),
5385                                 nvl(v_wlji_line_id(v_index), WDJ.line_id),
5386                                 nvl(v_wlji_schedule_group_id(v_index), WDJ.schedule_group_id)
5387                             into
5388                                 l_build_sequence,
5389                                 l_line_id,
5390                                 l_schedule_group_id
5391                             from
5392                                 wip_discrete_jobs WDJ
5393                             where
5394                                 WDJ.wip_entity_id = v_wlji_wip_entity_id(v_index);
5395                         exception
5396                             when no_data_found then null;
5397                             when too_many_rows then null;
5398                         end;
5399 
5400                         -- Added by BBK. Only if l_build_sequence is not null, we want to execute
5401                         -- this WIP_VALIDATE function. Otherwise, DO NOT.
5402                         if l_build_sequence is not null and l_build_sequence <> 0 Then
5403                             aReturnBoolean := WIP_Validate.build_sequence (
5404                                     p_build_sequence => l_build_sequence,
5405                                     p_wip_entity_id => v_wlji_wip_entity_id(v_index),
5406                                     p_organization_id => v_wlji_org(v_index),
5407                                     p_line_id => l_line_id,
5408                                     p_schedule_group_id => l_schedule_group_id
5409                                     );
5410 
5411                             if NOT aReturnBoolean Then
5412                                 l_error_code := -1;
5413                                 process_errorred_field('WIP',
5414                                                        'WIP_ML_BUILD_SEQUENCE',
5415                                                        l_stmt_num);
5416                             end if;
5417                         end if;
5418                         -- End of mod by BBK.
5419 
5420                         if l_error_code <> 0 then
5421                             l_error_count := l_error_count + 1;
5422                             GOTO skip_other_steps;
5423                         end if;
5424 
5425                         if lbji_debug = 'Y' then
5426                             fnd_file.put_line(fnd_file.log, 'Build Seq. Id Verification.. Success');
5427                         end if;
5428 
5429                     end if; -- job type <> 3 for schedule group and build sequence.
5430                     -- *** validate build_seq_id end ***
5431 
5432 
5433 --************************************************************************************************
5434 --**************************** Reschedule Job Validations Begin **********************************
5435 --************************************************************************************************
5436                     if v_wlji_load_type(v_index) = 6 then
5437 l_stmt_num := 700;
5438                         select  primary_item_id,
5439                                 class_code,
5440                                 scheduled_start_date,
5441                                 scheduled_completion_date,
5442                                 start_quantity,
5443                                 net_quantity,
5444                                 status_type,
5445                                 firm_planned_flag,
5446                                 job_type,
5447                                 bom_reference_id,
5448                                 alternate_bom_designator,
5449                                 routing_reference_id,
5450                                 alternate_routing_designator,
5451                                 bom_revision_date,
5452                                 routing_revision_date,
5453                                 bom_revision,
5454                                 routing_revision,
5455                                 common_routing_sequence_id,
5456                                 common_bom_sequence_id,
5457                                 wip_supply_type,
5458                                 scheduled_start_date,
5459                                 scheduled_completion_date,
5460                                 coproducts_supply,
5461                                 kanban_card_id,
5462                                 completion_subinventory, -- bug 2762029
5463                                 completion_locator_id, -- bug 2762029
5464                                 date_released
5465                         into    p_old_primary_item_id,
5466                                 p_old_class_code,
5467                                 p_old_start_date,
5468                                 p_old_complete_date,
5469                                 p_old_quantity,
5470                                 p_old_net_quantity,
5471                                 p_old_status_type,
5472                                 p_old_firm_planned_flag,
5473                                 p_old_job_type,
5474                                 p_old_bom_reference_id,
5475                                 p_old_alt_bom_designator,
5476                                 p_old_routing_reference_id,
5477                                 p_old_alt_routing_designator,
5478                                 p_old_bom_revision_date,
5479                                 p_old_routing_revision_date,
5480                                 p_old_bom_revision,  -- bug 2762029
5481                                 p_old_routing_revision, -- bug 2762029
5482                                 p_old_com_rtg_seq_id,
5483                                 p_old_com_bom_seq_id,
5484                                 p_old_supply_type,
5485                                 p_scheduled_start_date,
5486                                 p_scheduled_completion_date,
5487                                 p_coproducts_supply,
5488                                 v_wlji_kanban_card_id(v_index),
5489                                 p_old_completion_subinv,
5490                                 p_old_completion_locator,
5491                                 p_old_date_released
5492                         from    wip_discrete_jobs
5493                         where   wip_entity_id = v_wlji_wip_entity_id(v_index)
5494                         and     organization_id = v_wlji_org(v_index);
5495 
5496                         /* *** Bug 2762029 commenting begins
5497                         -- for update of a standard job, if the user populates any of the following fields,
5498                         -- they are ignored
5499                         if p_old_job_type = 1 then
5500 
5501                                 if
5502                                 (v_wlji_routing_reference_id(v_index) is not null) or
5503                                 (v_wlji_bom_reference_id(v_index) is not null) or
5504                                 (v_wlji_routing_revision_date(v_index) is not null) or
5505                                 (v_wlji_routing_revision(v_index) is not null) or
5506                                 (v_wlji_bom_revision_date(v_index) is not null) or
5507                                 (v_wlji_bom_revision(v_index) is not null) or
5508                                 (v_wlji_alt_bom_designator(v_index) is not null) or
5509                                 (v_wlji_alt_routing_designator(v_index) is not null) then
5510 
5511                                         v_wlji_routing_reference_id(v_index) := null;
5512                                         v_wlji_bom_reference_id(v_index) := null;
5513                                         v_wlji_routing_revision_date(v_index) := null;
5514                                         v_wlji_routing_revision(v_index) := null;
5515                                         v_wlji_bom_revision_date(v_index) := null;
5516                                         v_wlji_bom_revision(v_index) := null;
5517                                         v_wlji_alt_bom_designator(v_index) := null;
5518                                         v_wlji_alt_routing_designator(v_index) := null;
5519 
5520                                         fnd_file.put_line(fnd_file.log, 'Ignoring any of the following fields if provided by the user for this standard job:');
5521                         --              fnd_file.new_line(fnd_file.log, 1);
5522                                         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');
5523                                 end if;
5524 
5525                         end if; -- job type 1
5526                         */ -- Bug 2762029 commenting ends
5527 
5528 
5529                         -- Bug 2762029 begins
5530                         -- initializing some variables.
5531                         p_common_bill_sequence_id    := p_old_com_bom_seq_id;
5532                         p_common_routing_sequence_id := p_old_com_rtg_seq_id;
5533 
5534 -- =============================================================================================
5535 -- UPDATE OF ALTERNATES BEGIN
5536 -- =============================================================================================
5537                         Begin
5538                             p_change_bom_alt := 0;
5539                             p_change_routing_alt := 0;
5540                             p_change_alt_flag := 0;
5541 
5542                             -- if the user wants to update an alternate to NULL value, s/he should populate '-99' in the interface.
5543 l_stmt_num := 700.1;
5544                             if p_old_job_type = 1 then
5545 
5546                                 if v_wlji_alt_bom_designator(v_index) is NOT NULL AND
5547                                  ((p_old_alt_bom_designator is NULL AND v_wlji_alt_bom_designator(v_index) <> '-99') OR
5548                                   (p_old_alt_bom_designator is NOT NULL AND
5549                                    v_wlji_alt_bom_designator(v_index) <> p_old_alt_bom_designator)
5550                                  ) THEN
5551                                     p_change_bom_alt := 1;
5552                                 end if;
5553 
5554                                 if v_wlji_alt_routing_designator(v_index) is NOT NULL AND
5555                                  ((p_old_alt_routing_designator is NULL AND v_wlji_alt_routing_designator(v_index) <> '-99') OR
5556                                   (p_old_alt_routing_designator is NOT NULL AND
5557                                    v_wlji_alt_routing_designator(v_index) <> p_old_alt_routing_designator)
5558                                  ) THEN
5559                                     p_change_routing_alt := 1;
5560                                 end if;
5561 
5562                                 -- change bom/routing alternate
5563                                 if (p_change_bom_alt = 1 OR p_change_routing_alt = 1) and p_old_status_type = 1 then
5564                                     p_change_alt_flag := 1; --i.e. update of at least one alternate has happenned
5565 
5566                                     -- populate local variables
5567                                     v_wlji_item(v_index) := p_old_primary_item_id;
5568 
5569                                     if p_change_bom_alt = 1 AND p_change_routing_alt = 0 then
5570                                         if v_wlji_alt_bom_designator(v_index) = '-99' then
5571                                             v_wlji_alt_bom_designator(v_index) := null;
5572                                         end if;
5573                                         v_wlji_alt_routing_designator(v_index) := p_old_alt_routing_designator;
5574                                     end if; --p_change_bom_alt = 1
5575 
5576                                     if p_change_routing_alt = 1 AND p_change_bom_alt = 0 then
5577                                         if v_wlji_alt_routing_designator(v_index) = '-99' then
5578                                             v_wlji_alt_routing_designator(v_index) := null;
5579                                         end if;
5580                                         v_wlji_alt_bom_designator(v_index) := p_old_alt_bom_designator;
5581                                     end if; --p_change_routing_alt = 1
5582 
5583                                     if p_change_routing_alt = 1 AND p_change_bom_alt = 1 then
5584                                         if v_wlji_alt_bom_designator(v_index) = '-99' then
5585                                             v_wlji_alt_bom_designator(v_index) := null;
5586                                         end if;
5587                                         if v_wlji_alt_routing_designator(v_index) = '-99' then
5588                                             v_wlji_alt_routing_designator(v_index) := null;
5589                                         end if;
5590                                     end if;
5591 
5592 l_stmt_num := 700.2;
5593                                     delete from wip_operations where wip_entity_id = v_wlji_wip_entity_id(v_index);
5594                                     delete from wip_operation_resources where wip_entity_id = v_wlji_wip_entity_id(v_index);
5595                                     delete from wip_requirement_operations where wip_entity_id = v_wlji_wip_entity_id(v_index);
5596                                     delete from wip_operation_yields where wip_entity_id = v_wlji_wip_entity_id(v_index);
5597 
5598 l_stmt_num := 700.3;
5599                                     -- Now validate the alternate designators to get the routing and bom sequence id.
5600                                     -- Also get the completion subinventory and locator. If the user has provided them
5601                                     -- use them after validation, else use these default values.
5602                                     -- Also validate/default the bom/rtg revision and revision-dates
5603 
5604                                     begin
5605                                         select bor.routing_sequence_id,
5606                                                bor.COMPLETION_SUBINVENTORY,
5607                                                bor.COMPLETION_LOCATOR_ID
5608                                         into   p_common_routing_sequence_id,
5609                                                l_default_subinventory,
5610                                                l_default_compl_loc_id
5611                                         from   bom_operational_routings bor, bom_alternate_designators bad
5612                                         where  ((bor.alternate_routing_designator is null and bad.alternate_designator_code is null
5613                                                 and bad.organization_id = -1)
5614                                                 or (bor.alternate_routing_designator = bad.alternate_designator_code
5615                                                 and bor.organization_id = bad.organization_id))
5616                                         and    bor.organization_id = v_wlji_org(v_index)
5617                                         and    bor.assembly_item_id = v_wlji_item(v_index)
5618                                         and    NVL(bor.alternate_routing_designator, '&*') = NVL(v_wlji_alt_routing_designator(v_index), '&*')
5619                                         and    bor.routing_type = 1
5620                                         and    bor.cfm_routing_flag = 3;
5621                                         --Bug 5107339: Disable_date validation is not applicable here.
5622                                         -- and    trunc(nvl(bad.disable_date, sysdate + 1)) > trunc(sysdate);
5623 
5624                                     exception
5625                                         when no_data_found then
5626                                             l_aux_mesg := '';
5627                                             process_invalid_field('ALTERNATE ROUTING DESIGNATOR',
5628                                                                   l_aux_mesg,
5629                                                                   l_stmt_num);
5630                                             l_error_code := -1;
5631                                     end;
5632 
5633                                     if l_error_code <> 0 then
5634                                             l_error_count := l_error_count + 1;
5635                                             GOTO skip_resched_validations;
5636                                     end if;
5637 
5638 l_stmt_num := 700.4;
5639                                     IF v_wlji_completion_subinventory(v_index) IS NULL AND
5640                                        v_wlji_completion_locator_id(v_index) IS NULL THEN
5641                                         v_wlji_completion_subinventory(v_index) := l_default_subinventory;
5642                                         v_wlji_completion_locator_id(v_index) := l_default_compl_loc_id;
5643                                     END IF;
5644 
5645                                     IF v_wlji_completion_subinventory(v_index) IS NULL AND
5646                                        v_wlji_completion_locator_id(v_index) IS NOT NULL THEN
5647                                         v_wlji_completion_subinventory(v_index) := l_default_subinventory;
5648                                     END IF;
5649 
5650                                     IF v_wlji_completion_subinventory(v_index) IS NOT NULL AND
5651                                        v_wlji_completion_locator_id(v_index) IS NULL THEN
5652 
5653                                         str := to_char(v_wlji_org(v_index))||v_wlji_completion_subinventory(v_index);
5654                                         hash_value := dbms_utility.get_hash_value(str, 37, 1073741824);
5655                                         if WSMPLCVA.v_subinv.exists(hash_value) then
5656                                             NULL;
5657                                         else
5658                                             l_aux_mesg := '';
5659                                             process_invalid_field('COMPLETION SUBINVENTORY',
5660                                                                   l_aux_mesg,
5661                                                                   l_stmt_num);
5662                                             l_error_code := -1;
5663                                         end if;
5664 
5665                                         if l_error_code <> 0 then
5666                                             l_error_count := l_error_count + 1;
5667                                             GOTO skip_resched_validations;
5668                                         end if;
5669                                         l_aux_mesg := '';
5670                                         str := '';
5671                                         hash_value := 0;
5672 
5673 l_stmt_num := 700.5;
5674                                         select locator_type
5675                                         into   mtl_locator_type
5676                                         from   mtl_secondary_inventories
5677                                         where  secondary_inventory_name = v_wlji_completion_subinventory(v_index)
5678                                         and    organization_id = v_wlji_org(v_index);
5679 
5680                                         if v_wlji_completion_subinventory(v_index) = l_default_subinventory then
5681                                             v_wlji_completion_locator_id(v_index) := l_default_compl_loc_id;
5682                                         else
5683                                             if mtl_locator_type = 2 then
5684                                                 l_aux_mesg := '';
5685                                                 process_invalid_field('COMPLETION SUBINVENTORY',
5686                                                                       l_aux_mesg,
5687                                                                       l_stmt_num);
5688                                                 l_error_code := -1;
5689                                                 l_error_count := l_error_count + 1;
5690                                                 GOTO skip_resched_validations;
5691                                             else
5692                                                 NULL;
5693                                             end if;
5694                                         end if;
5695                                     END IF;
5696 
5697                                     l_aux_mesg := '';
5698 
5699 l_stmt_num := 700.6;
5700                                     IF v_wlji_alt_bom_designator(v_index) is NULL THEN
5701                                         begin
5702                                             SELECT  bom.common_bill_sequence_id
5703                                               INTO  p_common_bill_sequence_id
5704                                               FROM  bom_bill_of_materials bom
5705                                              WHERE  bom.alternate_bom_designator is NULL
5706                                                AND  BOM.assembly_item_id = v_wlji_item(v_index)
5707                                                AND  bom.organization_id = v_wlji_org(v_index);
5708                                         exception
5709                                             WHEN NO_DATA_FOUND THEN
5710                                                 NULL;
5711                                         end;
5712                                     ELSE
5713                                         begin
5714                                                SELECT  bom.common_bill_sequence_id
5715                                                  INTO  p_common_bill_sequence_id
5716                                                  FROM  bom_bill_of_materials bom, bom_alternate_designators bad
5717                                                 WHERE  ((bom.alternate_bom_designator is null and bad.alternate_designator_code is null
5718                                                           and bad.organization_id = -1)
5719                                                          OR (bom.alternate_bom_designator = bad.alternate_designator_code
5720                                                              and bom.organization_id = bad.organization_id))
5721                                                   AND  bom.alternate_bom_designator = v_wlji_alt_bom_designator(v_index)
5722                                                   AND  BOM.assembly_item_id = v_wlji_item(v_index)
5723                                                   AND  bom.organization_id = v_wlji_org(v_index);
5724                                                   --Bug 5107339: Disable_date validation is not applicable here.
5725                                                   --AND  trunc(nvl(bad.disable_date, sysdate + 1)) > trunc(sysdate);
5726 
5727                                         exception
5728                                             WHEN no_data_found  THEN
5729                                                 l_aux_mesg := '';
5730                                                 process_invalid_field('ALTERNATE BOM DESIGNATOR',
5731                                                                       l_aux_mesg,
5732                                                                       l_stmt_num);
5733                                                 l_error_code := -1;
5734                                         end;
5735                                     END IF;
5736 
5737                                     if l_error_code <> 0 then
5738                                         l_error_count := l_error_count + 1;
5739                                         GOTO skip_resched_validations;
5740                                     end if;
5741                                     l_aux_mesg := '';
5742 
5743 l_stmt_num := 700.6;
5744 
5745                                     SELECT  nvl(msub.locator_type, 1) sub_loc_control,
5746                                             MP.stock_locator_control_code org_loc_control,
5747                                             MS.restrict_locators_code,
5748                                             MS.location_control_code item_loc_control
5749                                             into l_sub_loc_control, l_org_loc_control,
5750                                                     l_restrict_locators_code, l_item_loc_control
5751                                     FROM    mtl_system_items MS,
5752                                             mtl_secondary_inventories MSUB,
5753                                             mtl_parameters MP
5754                                     WHERE   MP.organization_id = v_wlji_org(v_index)
5755                                     AND     MS.organization_id = v_wlji_org(v_index)
5756                                     AND     MS.inventory_item_id = v_wlji_item(v_index)
5757                                     AND     MSUB.secondary_inventory_name = v_wlji_completion_subinventory(v_index)
5758                                     AND     MSUB.organization_id = v_wlji_org(v_index);
5759 
5760                                     l_locator_id := v_wlji_completion_locator_id(v_index) ;
5761 
5762                                     WIP_LOCATOR.validate(   v_wlji_org(v_index),
5763                                                             v_wlji_item(v_index),
5764                                                             v_wlji_completion_subinventory(v_index),
5765                                                             l_org_loc_control,
5766                                                             l_sub_loc_control,
5767                                                             l_item_loc_control,
5768                                                             l_restrict_locators_code,
5769                                                             NULL, NULL, NULL, NULL,
5770                                                             l_locator_id,
5771                                                             l_segs,
5772                                                             l_loc_success);
5773 
5774                                     IF not l_loc_success THEN
5775                                         l_aux_mesg := '';
5776                                         process_invalid_field('COMPLETION SUBINVENTORY',
5777                                                               l_aux_mesg,
5778                                                               l_stmt_num);
5779                                         l_error_code := -1;
5780                                     end if;
5781 
5782                                     if l_error_code <> 0 then
5783                                         l_error_count := l_error_count + 1;
5784                                         GOTO skip_resched_validations;
5785                                     end if;
5786                                     l_aux_mesg := '';
5787                                     l_locator_id := 0;
5788 
5789 l_stmt_num := 700.7;
5790                                     if v_wlji_fusd(v_index) is null then
5791                                         v_wlji_fusd(v_index) := p_old_start_date;
5792                                     end if;
5793 
5794                                     if v_wlji_fusd(v_index) > SYSDATE then
5795                                         l_rev_date := v_wlji_fusd(v_index);
5796                                     else
5797                                         l_rev_date := SYSDATE;
5798                                     end if;
5799 
5800                                     wip_revisions.bom_revision (v_wlji_org(v_index),
5801                                                                 v_wlji_item(v_index),
5802                                                                 v_wlji_bom_revision(v_index),
5803                                                                 v_wlji_bom_revision_date(v_index),
5804                                                                 l_rev_date);
5805 
5806 
5807                                     wip_revisions.routing_revision (v_wlji_org(v_index),
5808                                                                     v_wlji_item(v_index),
5809                                                                     v_wlji_routing_revision(v_index),
5810                                                                     v_wlji_routing_revision_date(v_index),
5811                                                                     l_rev_date);
5812 
5813                                     if l_error_code <> 0 then
5814                                             l_error_count := l_error_count + 1;
5815                                             GOTO skip_resched_validations;
5816                                     end if;
5817 
5818 l_stmt_num := 700.8;
5819                                     -- now that we have the bom and rtg seq_id's and values for completion-subinv and locator
5820                                     -- and revision info, we can proceed to populate the wo tables and update wdj
5821 
5822                                     build_lbji_info(p_routing_seq_id => p_common_routing_sequence_id,
5823                                                     p_common_bill_sequence_id => p_common_bill_sequence_id,
5824                                                     p_explode_header_detail => 1,
5825                                                     p_status_type => 1,
5826                                                     p_class_code => null,
5827                                                     p_org => v_wlji_org(v_index),
5828                                                     p_wip_entity_id => v_wlji_wip_entity_id(v_index),
5829                                                     p_last_updt_date => v_wlji_last_updt_date(v_index),
5830                                                     p_last_updt_by => v_wlji_last_updt_by(v_index),
5831                                                     p_creation_date => v_wlji_creation_date(v_index),
5832                                                     p_created_by => v_wlji_created_by(v_index),
5833                                                     p_last_updt_login => v_wlji_last_updt_login(v_index),
5834                                                     p_request_id => v_wlji_request_id(v_index),
5835                                                     p_program_application_id => v_wlji_program_application_id(v_index),
5836                                                     p_program_id => v_wlji_program_id(v_index),
5837                                                     p_prog_updt_date => v_wlji_prog_updt_date(v_index),
5838                                                     p_source_line_id => null,
5839                                                     p_source_code =>  null,
5840                                                     p_description => null,
5841                                                     p_item => p_old_primary_item_id,
5842                                                     p_job_type => 1,
5843                                                     p_bom_reference_id => null,
5844                                                     p_routing_reference_id => null,
5845                                                     p_firm_planned_flag => p_old_firm_planned_flag,
5846                                                     p_wip_supply_type => p_old_supply_type,
5847                                                     p_fusd => p_scheduled_start_date,
5848                                                     p_lucd => p_scheduled_completion_date,
5849                                                     p_start_quantity => p_old_quantity,
5850                                                     p_net_quantity => p_old_net_quantity,
5851                                                     p_coproducts_supply => p_coproducts_supply,
5852                                                     p_bom_revision => v_wlji_bom_revision(v_index),
5853                                                     p_routing_revision => v_wlji_routing_revision(v_index),
5854                                                     p_bom_revision_date => v_wlji_bom_revision_date(v_index),
5855                                                     p_routing_revision_date => v_wlji_routing_revision_date(v_index),
5856                                                     p_lot_number => null,
5857                                                     p_alt_bom_designator => v_wlji_alt_bom_designator(v_index),
5858                                                     p_alt_routing_designator => v_wlji_alt_routing_designator(v_index),
5859                                                     p_priority => null,
5860                                                     p_due_date => null,
5861                                                     p_attribute_category => null,
5862                                                     p_attribute1 => null,
5863                                                     p_attribute2 => null,
5864                                                     p_attribute3 => null,
5865                                                     p_attribute4 => null,
5866                                                     p_attribute5 => null,
5867                                                     p_attribute6 => null,
5868                                                     p_attribute7 => null,
5869                                                     p_attribute8 => null,
5870                                                     p_attribute9 => null,
5871                                                     p_attribute10 => null,
5872                                                     p_attribute11 => null,
5873                                                     p_attribute12 => null,
5874                                                     p_attribute13 => null,
5875                                                     p_attribute14 => null,
5876                                                     p_attribute15 => null,
5877                                                     p_job_name => null,
5878                                                     p_completion_subinventory => v_wlji_completion_subinventory(v_index),
5879                                                     p_completion_locator_id => v_wlji_completion_locator_id(v_index),
5880                                                     p_demand_class => null,
5881                                                     p_project_id => null,
5882                                                     p_task_id => null,
5883                                                     p_schedule_group_id => null,
5884                                                     p_build_sequence => null,
5885                                                     p_line_id => null,
5886                                                     p_kanban_card_id => null,
5887                                                     p_overcompl_tol_type => null,
5888                                                     p_overcompl_tol_value => null,
5889                                                     p_end_item_unit_number => null,
5890                                                     p_rtg_op_seq_num => null,
5891                                                     p_src_client_server => 0,
5892                                                     p_po_creation_time => null,
5893                                                     p_error_code => l_error_code,
5894                                                     p_error_msg => l_error_msg);
5895 
5896                                     if l_error_code <> 0 then
5897                                            handle_error(l_error_code, l_error_msg,  l_stmt_num);
5898                                            l_error_count := l_error_count + 1;
5899                                            GOTO skip_resched_validations;
5900                                     end if;
5901 
5902                                 elsif p_old_status_type <> 1 then
5903                                     fnd_file.put_line(fnd_file.log, 'Ignoring any of the following fields if provided by the user for this standard job:');
5904                                     fnd_file.put_line(fnd_file.log, 'ROUTING_REVISION_DATE, ROUTING_REVISION, BOM_REVISION_DATE, BOM_REVISION,
5905                                                                             ALTERNATE_BOM_DESIGNATOR, ALTERNATE_ROUTING_DESIGNATOR');
5906                                 end if; -- change bom/routing alternate
5907 
5908                             end if; -- job type 1, near l_stmt_num := 700.1;
5909 
5910 
5911                             if p_old_job_type = 1 then
5912                                 v_wlji_bom_reference_id(v_index) := p_old_bom_reference_id;
5913                                 v_wlji_routing_reference_id(v_index) := p_old_routing_reference_id;
5914                                 if p_change_alt_flag = 0 then
5915                                     v_wlji_bom_revision(v_index) := p_old_bom_revision;
5916                                     v_wlji_routing_revision(v_index) := p_old_routing_revision;
5917                                     v_wlji_bom_revision_date(v_index) := p_old_bom_revision_date;
5918                                     v_wlji_routing_revision_date(v_index) := p_old_routing_revision_date;
5919                                     v_wlji_alt_bom_designator(v_index) := p_old_alt_bom_designator;
5920                                     v_wlji_alt_routing_designator(v_index) := p_old_alt_routing_designator;
5921                                     v_wlji_completion_subinventory(v_index) := p_old_completion_subinv;
5922                                     v_wlji_completion_locator_id(v_index) := p_old_completion_locator;
5923                                 end if;
5924                             end if;
5925 
5926                         Exception
5927                             WHEN OTHERS THEN
5928                                 l_error_code := SQLCODE;
5929                                 l_err_msg:='WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
5930                                 handle_error(l_error_code, l_err_msg, l_stmt_num);
5931                                 GOTO skip_resched_validations;
5932                         End;
5933 -- =============================================================================================
5934 -- UPDATE OF ALTERNATES END
5935 -- =============================================================================================
5936                         -- Bug 2762029 ends
5937 
5938 
5939 -- =============================================================================================
5940 --  UPDATE OF REFERENCES BEGINS
5941 -- =============================================================================================
5942 
5943                         -- non standard job bom/routing reference update. The assumption is that this module will
5944                         -- NOT update the quantity/dates/etc., they will be taken care in the later modules.
5945                         -- This module will just look at the reference info, and assume qnty/date/etc to be same
5946                         -- as the old values.
5947 l_stmt_num:= 701;
5948                         if p_old_job_type = 3 then
5949 
5950                             p_change_bom_reference := 0;
5951                             p_change_routing_reference := 0;
5952 
5953                             if   v_wlji_routing_reference_id(v_index) is not null then
5954                                 p_change_routing_reference := 1;
5955                             end if;
5956 
5957                             if   v_wlji_bom_reference_id(v_index) is not null then
5958                                 p_change_bom_reference := 1;
5959                             end if;
5960 
5961 l_stmt_num:= 701.7;
5962                             if p_change_routing_reference = 0 AND p_change_bom_reference = 0 then
5963                                 bom_seq_id := p_old_com_bom_seq_id;
5964                                 v_wlji_bom_revision_date(v_index):= p_old_bom_revision_date;
5965                                 v_wlji_bom_reference_id(v_index):= p_old_bom_reference_id;
5966                                 v_wlji_alt_bom_designator(v_index):= p_old_alt_bom_designator;
5967                                 routing_seq_id := p_old_com_rtg_seq_id;
5968                                 v_wlji_routing_revision_date(v_index):=p_old_routing_revision_date;
5969                                 v_wlji_routing_reference_id(v_index):=p_old_routing_reference_id;
5970                                 v_wlji_alt_routing_designator(v_index):=p_old_alt_routing_designator;
5971                             end if;
5972 
5973 
5974                             -- user can update the bom_reference and the routing reference of a non-standard job only if the
5975                             -- job is unreleased. If the user updates the bom/routing on an unreleased job as well as it's
5976                             -- status to released, the update of the bom/rtg will be assumed to have taken place before
5977                             -- the update of status.
5978 
5979                             if (p_change_bom_reference = 1 or p_change_routing_reference = 1)
5980                                 and  p_old_status_type <> 1 then
5981                                     fnd_file.put_line(fnd_file.log,'Ignoring any of the following fields if provided by the user:');
5982                                     --fnd_file.new_line(fnd_file.log, 1);
5983                                     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');
5984                                     v_wlji_bom_revision_date(v_index):= p_old_bom_revision_date;
5985                                     v_wlji_bom_reference_id(v_index):= p_old_bom_reference_id;
5986                                     v_wlji_alt_bom_designator(v_index):= p_old_alt_bom_designator;
5987                                     v_wlji_routing_revision_date(v_index):=p_old_routing_revision_date;
5988                                     v_wlji_routing_reference_id(v_index):=p_old_routing_reference_id;
5989                                     v_wlji_alt_routing_designator(v_index):=p_old_alt_routing_designator;
5990                             end if;
5991 
5992 
5993                             if p_old_status_type = 1 then
5994 
5995                             -- the following three variables will temporarily assume the old values for reasons mentioned above.
5996                             -- their original values will be returned to them for possible verification at the end of the module
5997 
5998                                 temp_start_quantity:=v_wlji_start_quantity(v_index);
5999                                 temp_fusd:=v_wlji_fusd(v_index);
6000                                 temp_lucd:=v_wlji_lucd(v_index);
6001                                 temp_supply:=v_wlji_wip_supply_type(v_index);
6002 
6003                                 v_wlji_start_quantity(v_index):=p_old_quantity;
6004                                 v_wlji_fusd(v_index):=p_old_start_date;
6005                                 v_wlji_lucd(v_index):=p_old_complete_date;
6006                                 v_wlji_wip_supply_type(v_index):=p_old_supply_type;
6007 
6008 l_stmt_num:= 702;
6009                                 if (p_change_bom_reference = 1 or p_change_routing_reference = 1) then
6010 
6011                                     if p_change_bom_reference = 1 then
6012                                         wsmputil.validate_non_std_references(
6013                                                   null,
6014                                                   null,
6015                                                   v_wlji_bom_reference_id(v_index),
6016                                                   null,
6017                                                   v_wlji_alt_bom_designator(v_index),
6018                                                   v_wlji_org(v_index),
6019                                                   sysdate, -- this doesn't really make any diff, not used after all
6020                                                   null,
6021                                                   null,
6022                                                   dummy_number,
6023                                                   null,
6024                                                   null,
6025                                                   null,
6026                                                   dummy_number,
6027                                                   v_wlji_bom_revision(v_index),
6028                                                   v_wlji_bom_revision_date(v_index),
6029                                                   dummy_varchar,
6030                                                   dummy_date,
6031                                                   dummy_number,
6032                                                   bom_seq_id,
6033                                                   1,
6034                                                   l_error_code,
6035                                                   l_err_msg);
6036 
6037                                         if l_error_code <> 0 then
6038                                             HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
6039                                             l_error_code := -1;
6040                                             GOTO skip_resched_validations;
6041                                         end if;
6042                                     end if;
6043 
6044 l_stmt_num:= 703;
6045                                     if p_change_routing_reference = 1 then
6046                                         wsmputil.validate_non_std_references(
6047                                                   null,
6048                                                   v_wlji_routing_reference_id(v_index),
6049                                                   null,
6050                                                   v_wlji_alt_routing_designator(v_index),
6051                                                   null,
6052                                                   v_wlji_org(v_index),
6053                                                   sysdate, -- this doesn't really make any diff, not used after all
6054                                                   null,
6055                                                   null,
6056                                                   dummy_number,
6057                                                   null,
6058                                                   null,
6059                                                   null,
6060                                                   dummy_number,
6061                                                   dummy_varchar,
6062                                                   dummy_date,
6063                                                   v_wlji_routing_revision(v_index),
6064                                                   v_wlji_routing_revision_date(v_index),
6065                                                   routing_seq_id,
6066                                                   dummy_number,
6067                                                   2,
6068                                                   l_error_code,
6069                                                   l_err_msg);
6070 
6071                                         if l_error_code <> 0 then
6072                                             HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
6073                                             l_error_code := -1;
6074                                             GOTO skip_resched_validations;
6075                                         end if;
6076                                     end if;
6077 
6078 l_stmt_num:= 704;
6079                                     if p_change_routing_reference = 1 OR p_change_bom_reference = 1 then
6080                                         begin
6081                                             delete from wip_operations
6082                                             where  wip_entity_id = v_wlji_wip_entity_id(v_index);
6083                                             delete from wip_operation_yields
6084                                             where wip_entity_id = v_wlji_wip_entity_id(v_index);
6085                                             delete from wip_operation_resources
6086                                             where wip_entity_id = v_wlji_wip_entity_id(v_index);
6087                                             delete from wip_requirement_operations
6088                                             where wip_entity_id = v_wlji_wip_entity_id(v_index);
6089                                         exception
6090                                             when others then
6091                                                 rollback;
6092                                                 l_error_code := SQLCODE;
6093                                                 l_err_msg:='WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
6094                                                 handle_error(l_error_code, l_err_msg, l_stmt_num);
6095                                                 GOTO skip_resched_validations;
6096                                         end;
6097                                     end if;
6098 
6099 
6100                                     if p_change_routing_reference = 1 AND p_change_bom_reference = 0 then
6101                                         bom_seq_id := p_old_com_bom_seq_id;
6102                                         v_wlji_bom_revision_date(v_index):= p_old_bom_revision_date;
6103                                         v_wlji_bom_reference_id(v_index):= p_old_bom_reference_id;
6104                                         v_wlji_alt_bom_designator(v_index):= p_old_alt_bom_designator;
6105                                     end if;
6106 
6107                                     if p_change_routing_reference = 0 AND p_change_bom_reference = 1 then
6108                                         routing_seq_id := p_old_com_rtg_seq_id;
6109                                         v_wlji_routing_revision_date(v_index):=p_old_routing_revision_date;
6110                                         v_wlji_routing_reference_id(v_index):=p_old_routing_reference_id;
6111                                         v_wlji_alt_routing_designator(v_index):=p_old_alt_routing_designator;
6112                                     end if;
6113 
6114                                     begin
6115                                         build_lbji_info(
6116                                             p_routing_seq_id => routing_seq_id,
6117                                             p_common_bill_sequence_id => null,
6118                                             p_explode_header_detail => 1,
6119                                             p_status_type => 1,
6120                                             p_class_code => null,
6121                                             p_org => v_wlji_org(v_index),
6122                                             p_wip_entity_id => v_wlji_wip_entity_id(v_index),
6123                                             p_last_updt_date => v_wlji_last_updt_date(v_index),
6124                                             p_last_updt_by => v_wlji_last_updt_by(v_index),
6125                                             p_creation_date => v_wlji_creation_date(v_index),
6126                                             p_created_by => v_wlji_created_by(v_index),
6127                                             p_last_updt_login => v_wlji_last_updt_login(v_index),
6128                                             p_request_id => v_wlji_request_id(v_index),
6129                                             p_program_application_id => v_wlji_program_application_id(v_index),
6130                                             p_program_id => v_wlji_program_id(v_index),
6131                                             p_prog_updt_date => v_wlji_prog_updt_date(v_index),
6132                                             p_source_line_id => null,
6133                                             p_source_code =>  null,
6134                                             p_description => null,
6135                                             p_item => v_wlji_item(v_index),
6136                                             p_job_type => 3,
6137                                             p_bom_reference_id =>  v_wlji_bom_reference_id(v_index),
6138                                             p_routing_reference_id => v_wlji_routing_reference_id(v_index),
6139                                             p_firm_planned_flag => null,
6140                                             p_wip_supply_type => v_wlji_wip_supply_type(v_index),
6141                                             p_fusd => v_wlji_fusd(v_index),
6142                                             p_lucd => v_wlji_lucd(v_index),
6143                                             p_start_quantity => v_wlji_start_quantity(v_index),
6144                                             p_net_quantity => null,
6145                                             p_coproducts_supply => null,
6146                                             p_bom_revision => null,
6147                                             p_routing_revision => null,
6148                                             p_bom_revision_date => v_wlji_bom_revision_date(v_index),
6149                                             p_routing_revision_date => v_wlji_routing_revision_date(v_index),
6150                                             p_lot_number => null,
6151                                             p_alt_bom_designator => v_wlji_alt_bom_designator(v_index),
6152                                             p_alt_routing_designator => v_wlji_alt_routing_designator(v_index),
6153                                             p_priority => null,
6154                                             p_due_date => null,
6155                                             p_attribute_category => null,
6156                                             p_attribute1 => null,
6157                                             p_attribute2 => null,
6158                                             p_attribute3 => null,
6159                                             p_attribute4 => null,
6160                                             p_attribute5 => null,
6161                                             p_attribute6 => null,
6162                                             p_attribute7 => null,
6163                                             p_attribute8 => null,
6164                                             p_attribute9 => null,
6165                                             p_attribute10 => null,
6166                                             p_attribute11 => null,
6167                                             p_attribute12 => null,
6168                                             p_attribute13 => null,
6169                                             p_attribute14 => null,
6170                                             p_attribute15 => null,
6171                                             p_job_name => null,
6172                                             p_completion_subinventory => null,
6173                                             p_completion_locator_id => null,
6174                                             p_demand_class => null,
6175                                             p_project_id => null,
6176                                             p_task_id => null,
6177                                             p_schedule_group_id => null,
6178                                             p_build_sequence => null,
6179                                             p_line_id => null,
6180                                             p_kanban_card_id => null,
6181                                             p_overcompl_tol_type => null,
6182                                             p_overcompl_tol_value => null,
6183                                             p_end_item_unit_number => null,
6184                                             p_rtg_op_seq_num => null,
6185                                             p_src_client_server => 0,
6186                                             p_po_creation_time => WSMPLCVA.v_org(v_wlji_org(v_index)).PO_CREATION_TIME,
6187                                             p_error_code => l_error_code,
6188                                             p_error_msg => l_error_msg);
6189 
6190                                         if l_error_code <> 0 then
6191                                             raise update_job_exception;
6192                                         end if;
6193 
6194                                     exception
6195                                         when update_job_exception then
6196                                             handle_error(l_error_code, l_error_msg, l_stmt_num);
6197                                             l_error_count := l_error_count + 1;
6198                                             GOTO skip_resched_validations;
6199                                     end;
6200 
6201                                 end if;
6202                                 v_wlji_start_quantity(v_index):=temp_start_quantity;
6203                                 v_wlji_fusd(v_index):=temp_fusd;
6204                                 v_wlji_lucd(v_index):=temp_lucd;
6205                                 v_wlji_wip_supply_type(v_index):=temp_supply;
6206 
6207                             end if; -- old_status_type = 1
6208 
6209                         end if; -- job type = 3
6210 
6211 -- =============================================================================================
6212 -- UPDATE OF REFERENCES ENDS
6213 -- =============================================================================================
6214 
6215 
6216                         -- if the user wants to update only the references, the wo/wro/wor/woy updates are not needed
6217                         if (p_old_job_type = 3)
6218                            AND
6219                            (
6220                             (
6221                             (v_wlji_firm_planned_flag(v_index) is null) or
6222                             (v_wlji_firm_planned_flag(v_index) is not null and v_wlji_firm_planned_flag(v_index)=p_old_firm_planned_flag)
6223                             )
6224                             and
6225                             (
6226                             (v_wlji_status_type(v_index) is null) or
6227                             (v_wlji_status_type(v_index) is not null and v_wlji_status_type(v_index)=p_old_status_type)
6228                             )
6229                             and
6230                             (
6231                             (v_wlji_start_quantity(v_index) is null) or
6232                             (v_wlji_start_quantity(v_index) is not null and v_wlji_start_quantity(v_index)=p_old_quantity)
6233                             )
6234                             and
6235                             (
6236                             (v_wlji_net_quantity(v_index) is null) or
6237                             (v_wlji_net_quantity(v_index) is not null and v_wlji_net_quantity(v_index)=p_old_net_quantity)
6238                             )
6239                             and
6240                             (
6241                             (v_wlji_lucd(v_index) is null) or
6242                             (v_wlji_lucd(v_index) is not null and v_wlji_lucd(v_index)=p_scheduled_completion_date)
6243                             )
6244                             and
6245                             (
6246                             (v_wlji_fusd(v_index) is null) or
6247                             (v_wlji_fusd(v_index) is not null and v_wlji_fusd(v_index)=p_scheduled_start_date)
6248                             )
6249                             and
6250                             (
6251                             (v_wlji_coproducts_supply(v_index) is null) or
6252                             (v_wlji_coproducts_supply(v_index) is not null and v_wlji_coproducts_supply(v_index)=p_coproducts_supply)
6253                             )
6254                            ) then
6255                             p_skip_updt:= 1;
6256                         end if;
6257 
6258 
6259                         if lbji_debug = 'Y' then
6260                             if p_skip_updt = 1 then
6261                                 fnd_file.put_line(fnd_file.log, 'Planning to skip update of wo, wor, wro');
6262                             else
6263                                 fnd_file.put_line(fnd_file.log, 'No Plans to skip update of wo, wor, wro');
6264                             end if;
6265                         end if;
6266 
6267 
6268                         -- if the old firm_planned flag was 1, and the user populated null while updating the job,
6269                         -- no changes in quantity and date allowed. If the user changed the flag, this change is considered
6270                         -- "before" making a decision whether to allow update of qnty/date or not.
6271                         if v_wlji_firm_planned_flag(v_index) is NULL then
6272                             v_wlji_firm_planned_flag(v_index) := p_old_firm_planned_flag;
6273                         end if;
6274 
6275                         -- for non-std jobs, the firm flag is always 2. User cannot update it to 1.
6276                         if p_old_job_type = 3 then
6277                             if v_wlji_firm_planned_flag(v_index) is not null and
6278                                v_wlji_firm_planned_flag(v_index) <> 2 then
6279                                 l_aux_mesg := '';
6280                                 process_invalid_field('FIRM PLANNED FLAG',
6281                                                       l_aux_mesg,
6282                                                       l_stmt_num);
6283                                 l_error_code := -1;
6284                                 GOTO skip_resched_validations;
6285                             end if;
6286                         end if;
6287 
6288                         --validate status first
6289 l_stmt_num := 710;
6290 
6291                         IF v_wlji_status_type(v_index) IS NULL THEN
6292                             v_wlji_status_type(v_index) := p_old_status_type;
6293                             -- bugfix 2697295, update of released date only is not allowed
6294                             v_wlji_date_released(v_index) := p_old_date_released;
6295                         ELSIF v_wlji_status_type(v_index) = p_old_status_type THEN
6296                             -- bugfix 2697295, update of released date only is not allowed
6297                             v_wlji_date_released(v_index) := p_old_date_released;
6298                         ELSE
6299 
6300                         -- status type should be one of RELEASED, HOLD, CANCELLED, UNRELEASED
6301 
6302                             IF v_wlji_status_type(v_index) NOT IN (1,3,6,7) THEN
6303                                 l_aux_mesg := '';
6304                                 process_invalid_field('LOAD TYPE',
6305                                                       l_aux_mesg,
6306                                                       l_stmt_num);
6307                                 l_error_code := -1;
6308                                 GOTO skip_resched_validations;
6309                             ELSE
6310 
6311                                 if p_old_status_type = 7   then     -- cancelled
6312                                     l_error_code := -1;
6313                                     process_errorred_field('WSM',
6314                                                            'WSM_RESCHEDULE_CANCEL_JOB',
6315                                                            l_stmt_num);
6316                                     GOTO skip_resched_validations;
6317                                 end if;
6318 
6319                                 -- bugfix 2697295 begin
6320                                 -- if the job is being released from an unreleased state...
6321                                 if p_old_date_released is null and v_wlji_status_type(v_index) = 3 then
6322                                     if (v_wlji_date_released(v_index) is null ) then
6323                                         v_wlji_date_released(v_index) := sysdate;
6324                                     elsif (v_wlji_date_released(v_index) > sysdate ) then
6325                                         l_error_code := -1;
6326                                         process_errorred_field('WIP',
6327                                                                'WIP_INVALID_RELEASE_DATE',
6328                                                                l_stmt_num);
6329                                         GOTO skip_resched_validations;
6330                                     else
6331                                         -- BEGIN: BUG3126650
6332                                         --begin
6333                                         --    select 1
6334                                         --    into   l_dummy
6335                                         --    from   org_acct_periods
6336                                         --    where  organization_id = v_wlji_org(v_index)
6337                                         --    and    trunc(nvl(v_wlji_date_released(v_index),sysdate)) between PERIOD_START_DATE and SCHEDULE_CLOSE_DATE
6338                                         --    and    period_close_date is NULL;
6339                                         --exception
6340                                         --    when NO_DATA_FOUND then
6341                                         --        fnd_message.set_name('WIP', 'WIP_NO_ACCT_PERIOD');
6342                                         --        l_err_msg :=  fnd_message.get;
6343                                         --        l_error_code := -1;
6344                                         --        HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
6345                                         --        GOTO skip_resched_validations;
6346                                         --    when others then
6347                                         --        l_err_msg := SQLERRM;
6348                                         --        l_error_code := SQLCODE;
6349                                         --        HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
6350                                         --        GOTO skip_resched_validations;
6351                                         --end;
6352                                         l_dummy := WSMPUTIL.GET_INV_ACCT_PERIOD(
6353                                                     x_err_code         => l_error_code,
6354                                                     x_err_msg          => l_err_msg,
6355                                                     p_organization_id  => v_wlji_org(v_index),
6356                                                     p_date             => trunc(nvl(v_wlji_date_released(v_index),sysdate)));
6357                                         IF (l_error_code <> 0) THEN
6358                                             HANDLE_ERROR( l_error_code, l_error_msg, l_stmt_num);
6359                                             GOTO skip_resched_validations;
6360                                         END IF;
6361                                         -- END: BUG3126650
6362                                     end if;
6363                                 -- else if the job is being unreleased from a released state...
6364                                 elsif p_old_date_released is not null and v_wlji_status_type(v_index) = 1 then
6365                                     v_wlji_date_released(v_index) := null;
6366                                      -- ignore release date populated by user in any other condition...
6367                                 else
6368                                     v_wlji_date_released(v_index) := p_old_date_released;
6369                                 end if;
6370                                 -- bugfix 2697295 end
6371 
6372                                 if ((p_old_status_type = 3 and v_wlji_status_type(v_index) = 1) OR
6373                                    (p_old_status_type = 6 and  v_wlji_status_type(v_index) = 1)) then
6374 
6375                                     if (discrete_charges_exist(v_wlji_wip_entity_id(v_index), v_wlji_org(v_index),0)) then
6376                                         l_error_code := -1;
6377                                         process_errorred_field('WIP',
6378                                                                'WIP_UNRLS_JOB/SCHED',
6379                                                                l_stmt_num);
6380                                         GOTO skip_resched_validations;
6381 
6382                                     -- osp begin
6383                                     else
6384                                         if wip_osp.po_req_exists (
6385                                                     v_wlji_wip_entity_id(v_index),
6386                                                     null,
6387                                                     v_wlji_org(v_index),
6388                                                     null, 5) then
6389                                             fnd_message.set_name('WSM', 'WSM_JOB_PURCHASE_REQ');
6390                                             l_err_msg := fnd_message.get;
6391                                             l_warning_count := l_warning_count + 1;
6392                                             handle_warning(p_err_msg => l_err_msg,
6393                                                            p_header_id => v_wlji_header_id(v_index),
6394                                                            p_request_id => v_wlji_request_id(v_index),
6395                                                            p_program_id => v_wlji_program_id(v_index),
6396                                                            p_program_application_id => v_wlji_program_application_id(v_index));
6397                                         end if;
6398                                     -- osp end
6399                                     end if;
6400                                 end if;
6401 
6402 l_stmt_num := 712;
6403                                 -- abb H: optional scrap accounting
6404                                 -- if (p_old_status_type IN (1,6)) and (v_wlji_status_type(v_index) = 3) and
6405                                 --     WSMPLCVA.v_org(v_wlji_org(v_index)).ESTIMATED_SCRAP_ACCOUNTING = 1
6406                                 --     and p_old_job_type = 1 then
6407 
6408                                 if (p_old_status_type IN (1,6)) and (v_wlji_status_type(v_index) = 3) and
6409                                     wsmputil.WSM_ESA_ENABLED(p_wip_entity_id => v_wlji_wip_entity_id(v_index),
6410                                                              err_code => l_error_code,
6411                                                              err_msg => l_error_msg,
6412                                                              p_org_id => '',
6413                                                              p_job_type => '') = 1 then
6414 
6415                                     if v_wlji_class_code(v_index) is null then
6416                                         l_temp_cc := p_old_class_code;
6417                                     else
6418                                         l_temp_cc := v_wlji_class_code(v_index);
6419                                     end if;
6420 
6421                                     select est_scrap_account,
6422                                            est_scrap_var_account
6423                                     into   p_est_scrap_account,
6424                                            p_est_scrap_var_account
6425                                     from   wip_accounting_classes
6426                                     where  class_code = l_temp_cc
6427                                     and    organization_id = v_wlji_org(v_index);
6428 
6429                                     if p_est_scrap_account is null or p_est_scrap_var_account is null then
6430                                         v_wlji_process_status(v_index) := 3; --ERROR
6431                                         v_wlji_err_code(v_index) := -1;
6432                                         fnd_message.set_name('WSM','WSM_NO_WAC_SCRAP_ACC');
6433                                         fnd_message.set_token('CC', l_temp_cc);
6434                                         v_wlji_err_msg(v_index) := fnd_message.get;
6435                                         fnd_file.put_line(fnd_file.log, 'stmt_num: '|| l_stmt_num ||'  ' ||v_wlji_err_msg(v_index));
6436                                         fnd_file.new_line(fnd_file.log, 3);
6437                                         l_error_code := -1;
6438                                         GOTO skip_resched_validations;
6439                                     end if;
6440                                         if p_est_scrap_account is null or p_est_scrap_var_account is null then
6441                                         v_wlji_process_status(v_index) := 3; --ERROR
6442                                         v_wlji_err_code(v_index) := -1;
6443                                         fnd_message.set_name('WSM','WSM_NO_WAC_SCRAP_ACC');
6444                                         fnd_message.set_token('CC', l_temp_cc);
6445                                         v_wlji_err_msg(v_index) := fnd_message.get;
6446                                         fnd_file.put_line(fnd_file.log, 'stmt_num: '|| l_stmt_num ||'  ' ||v_wlji_err_msg(v_index));
6447                                         fnd_file.new_line(fnd_file.log, 3);
6448                                         l_error_code := -1;
6449                                         GOTO skip_resched_validations;
6450                                     end if;
6451                                 end if;
6452                             END IF;  -- status
6453                         END IF;
6454 
6455 l_stmt_num := 720;
6456                         --validate quantity
6457 
6458                         IF v_wlji_start_quantity(v_index) IS NULL THEN
6459                             v_wlji_start_quantity(v_index) := p_old_quantity;
6460                         ELSIF  v_wlji_start_quantity(v_index) = p_old_quantity THEN
6461                             NULL;
6462                         ELSIF v_wlji_firm_planned_flag(v_index) = 1 THEN
6463                             l_error_code := -1;
6464                             process_errorred_field('WSM',
6465                                                    'WSM_JOB_FIRM',
6466                                                    l_stmt_num);
6467                             GOTO skip_resched_validations;
6468                         ELSE
6469 
6470                             begin
6471                                 if (p_old_status_type IN (3 ,6)
6472                                    AND v_wlji_status_type(v_index) IN (1,3,6)) then
6473                                     if (discrete_charges_exist(v_wlji_wip_entity_id(v_index), v_wlji_org(v_index),0)) then
6474                                         raise invalid_qnty_error;
6475                                     end if;
6476                                 end if;
6477                             exception
6478                                 when invalid_qnty_error then
6479                                     l_error_code := -1;
6480                                     process_errorred_field('WSM',
6481                                                            'WSM_QNTY_NOCHANGE',
6482                                                            l_stmt_num);
6483                                     GOTO skip_resched_validations;
6484                             end;
6485 
6486                         END IF; -- qty change
6487 
6488                         -- osp begin
6489                         -- create requisitions/additional reuisitions under following conditions:
6490                         -- 1. user updates only status from unreleased to released, quantity unchanged
6491                         -- 2. user updates only quantity (increases) for a released job, status is unchanged
6492                         -- 3. user updates staus to released, and increases quantity.
6493 
6494                         if WSMPLCVA.v_org(v_wlji_org(v_index)).PO_CREATION_TIME <> WIP_CONSTANTS.MANUAL_CREATION then
6495 
6496                             if (v_wlji_status_type(v_index) = 3 and p_old_status_type = 1) then
6497                                 if wsmputil.check_osp_operation(v_wlji_wip_entity_id(v_index), l_osp_op_seq_num , v_wlji_org(v_index)) then
6498                                     l_atleast_one_osp_exists := l_atleast_one_osp_exists + 1;
6499                                     wip_osp.create_requisition(
6500                                             P_Wip_Entity_Id => v_wlji_wip_entity_id(v_index),
6501                                             P_Organization_Id => v_wlji_org(v_index),
6502                                             P_Repetitive_Schedule_Id => null,
6503                                             P_Operation_Seq_Num => l_osp_op_seq_num,
6504                                             P_Resource_Seq_Num => null,
6505                                             P_Run_ReqImport => WIP_CONSTANTS.NO);
6506                                 end if; -- check_osp_operation
6507                             end if;
6508 
6509                             if (v_wlji_start_quantity(v_index) > p_old_quantity) AND v_wlji_status_type(v_index) = 3 then
6510                                 wip_osp.create_additional_req(
6511                                             P_Wip_Entity_Id => v_wlji_wip_entity_id(v_index),
6512                                             P_Organization_id => v_wlji_org(v_index),
6513                                             P_Repetitive_Schedule_Id => null,
6514                                             P_Added_Quantity => (v_wlji_start_quantity(v_index) - p_old_quantity),
6515                                             P_Op_Seq => null);
6516                             end if;
6517 
6518                         end if; -- wip_constants.manual_creation
6519                         -- osp end
6520 
6521 
6522 l_stmt_num := 721;
6523                         -- validate net-quantity
6524 
6525                         if p_old_job_type = 3 then
6526                             if v_wlji_net_quantity(v_index) < 0 or
6527                                 v_wlji_net_quantity(v_index) > v_wlji_start_quantity(v_index) then
6528                                 l_aux_mesg := '';
6529                                 process_invalid_field('NET QUANTITY',
6530                                                       l_aux_mesg,
6531                                                       l_stmt_num);
6532                                 l_error_code := -1;
6533                                 GOTO skip_resched_validations;
6534                             end if;
6535                         end if; -- job type
6536 
6537                         if p_old_job_type = 1 then
6538                             if (v_wlji_net_quantity(v_index) is not null) and (v_wlji_net_quantity(v_index) <> p_old_quantity)
6539                                and (v_wlji_firm_planned_flag(v_index) = 1) then
6540                                 l_error_code := -1;
6541                                 process_errorred_field('WSM',
6542                                                        'WSM_JOB_FIRM',
6543                                                        l_stmt_num);
6544                                 GOTO skip_resched_validations;
6545                             end if;
6546 
6547                             if (v_wlji_net_quantity(v_index) is not null) and (v_wlji_start_quantity(v_index) is null)
6548                                and (v_wlji_net_quantity(v_index) > p_old_quantity) then
6549                                 l_aux_mesg := '';
6550                                 process_invalid_field('NET QUANTITY',
6551                                                       l_aux_mesg,
6552                                                       l_stmt_num);
6553                                 l_error_code := -1;
6554                                 GOTO skip_resched_validations;
6555                             end if;
6556 
6557 l_stmt_num := 722;
6558                             if v_wlji_net_quantity(v_index) is null then
6559                             begin
6560                                 select
6561                                        decode(wdj.primary_item_id, null, 0,
6562                                        decode(wdj.net_quantity,
6563                                        wdj.start_quantity, v_wlji_start_quantity(v_index),
6564                                        least(wdj.net_quantity,
6565                                        nvl(v_wlji_start_quantity(v_index), wdj.net_quantity))))
6566                                 into   v_wlji_net_quantity(v_index)
6567                                 from   wip_discrete_jobs wdj
6568                                 where  wdj.wip_entity_id  = v_wlji_wip_entity_id(v_index)
6569                                 and    wdj.organization_id  = v_wlji_org(v_index);
6570                             exception
6571                                 when others then
6572                                     l_error_code := SQLCODE;
6573                                     l_err_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
6574                                     handle_error(l_error_code, l_err_msg, l_stmt_num);
6575                                     GOTO skip_resched_validations;
6576                             end;
6577                             end if;
6578 
6579                         end if; -- job_type
6580 
6581 
6582 --validate dates
6583 l_stmt_num := 830;
6584 
6585                         if (
6586                             (v_wlji_firm_planned_flag(v_index) = 1)
6587                             AND
6588                             (
6589                             ((v_wlji_fusd(v_index) IS NOT NULL) AND (v_wlji_fusd(v_index) <> p_old_start_date))
6590                              OR
6591                              ((v_wlji_lucd(v_index) IS NOT NULL) AND (v_wlji_lucd(v_index) <> p_old_complete_date))
6592                             )
6593                         ) then
6594                             l_error_code := -1;
6595                              process_errorred_field('WSM',
6596                                                     'WSM_JOB_FIRM',
6597                                                     l_stmt_num);
6598                             GOTO skip_resched_validations;
6599                         end if;
6600 
6601                         IF (((v_wlji_fusd(v_index) IS NULL) AND (v_wlji_lucd(v_index) IS NULL)) OR
6602                             ((v_wlji_fusd(v_index) IS NOT NULL) AND (v_wlji_lucd(v_index) IS NOT NULL))) THEN
6603                             v_wlji_scheduling_method(v_index) := 3;
6604                         ELSE
6605                             v_wlji_scheduling_method(v_index) := 2;
6606                         END IF;
6607 
6608 
6609                         IF v_wlji_scheduling_method(v_index) = 3 THEN
6610                             IF (v_wlji_fusd(v_index) IS NULL) AND (v_wlji_lucd(v_index) IS NULL) THEN
6611                                 v_wlji_fusd(v_index) := p_old_start_date;
6612                                 v_wlji_lucd(v_index) := p_old_complete_date;
6613                             ELSIF ((v_wlji_fusd(v_index) > v_wlji_lucd(v_index)) OR
6614                                   ((v_wlji_fusd(v_index) <> p_old_start_date) AND
6615                                   discrete_charges_exist(v_wlji_wip_entity_id(v_index), v_wlji_org(v_index),1))) THEN
6616                                 l_aux_mesg := '';
6617                                 process_invalid_field('START DATE',
6618                                                       l_aux_mesg,
6619                                                       l_stmt_num);
6620                                 l_error_code := -1;
6621                                 GOTO skip_resched_validations;
6622                             END IF;
6623                         END IF;
6624 
6625                         IF v_wlji_scheduling_method(v_index) = 2 THEN
6626                             IF ((v_wlji_fusd(v_index) IS NOT NULL) AND (v_wlji_lucd(v_index) IS NULL)) THEN
6627                                 IF ((v_wlji_fusd(v_index) <> p_old_start_date) AND
6628                                    discrete_charges_exist(v_wlji_wip_entity_id(v_index), v_wlji_org(v_index),1)) THEN
6629                                     l_aux_mesg := '';
6630                                     process_invalid_field('START DATE',
6631                                                           l_aux_mesg,
6632                                                           l_stmt_num);
6633                                     l_error_code := -1;
6634                                     GOTO skip_resched_validations;
6635                                 ELSE
6636                                     v_wlji_lucd(v_index) := wsmputil.GET_SCHEDULED_DATE(
6637                                                             v_wlji_org(v_index),
6638                                                             v_wlji_item(v_index),
6639                                                             'F',
6640                                                             v_wlji_fusd(v_index),
6641                                                             --v_wlji_start_quantity(v_index),
6642                                                             l_error_code,
6643                                                             l_err_msg,
6644                                                             v_wlji_start_quantity(v_index));  --Fixed bug # 2313574
6645                                 END IF;
6646                             ELSIF ((v_wlji_fusd(v_index) IS NULL) AND (v_wlji_lucd(v_index) IS NOT NULL)) THEN
6647                                     v_wlji_fusd(v_index) := wsmputil.GET_SCHEDULED_DATE (
6648                                                             v_wlji_org(v_index),
6649                                                             v_wlji_item(v_index),
6650                                                             'B',
6651                                                             v_wlji_lucd(v_index),
6652                                                             --v_wlji_start_quantity(v_index),
6653                                                             l_error_code,
6654                                                             l_err_msg,
6655                                                             v_wlji_start_quantity(v_index));  --Fixed bug # 2313574
6656                             END IF;
6657                         END IF;
6658 
6659                         if l_error_code <> 0 OR l_err_msg IS NOT NULL then
6660                             HANDLE_ERROR( l_error_code, l_err_msg, l_stmt_num);
6661                             l_error_code := -1;
6662                             GOTO skip_resched_validations;
6663                         end if;
6664 
6665 
6666                         --validate coproducts
6667 l_stmt_num := 840;
6668 
6669                         if ((v_wlji_coproducts_supply(v_index) IS NOT NULL) and
6670                            (v_wlji_coproducts_supply(v_index) NOT IN (1,2))) then
6671                             l_aux_mesg := '';
6672                             process_invalid_field('COPRODUCTS SUPPLY',
6673                                                   l_aux_mesg,
6674                                                   l_stmt_num);
6675                             l_error_code := -1;
6676                             GOTO skip_resched_validations;
6677                         end if;
6678 
6679 << skip_resched_validations >>
6680 
6681                         if l_error_code <> 0 then
6682                             l_error_count := l_error_count + 1;
6683                             GOTO skip_other_steps;
6684                         end if;
6685 
6686 
6687                         /* -- commenting out Bug 2762029
6688                         -- setting the common routing and bill sequence id for update
6689 
6690                         if p_old_job_type = 1 then
6691                             p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6692                             p_common_bill_sequence_id := p_old_com_bom_seq_id;
6693                         end if;
6694                         */
6695 
6696                         if p_old_job_type = 3 then
6697                             if p_old_status_type = 3 then
6698                                 if p_change_bom_reference = 0 and p_change_routing_reference = 0 then
6699                                     p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6700                                     p_common_bill_sequence_id := p_old_com_bom_seq_id;
6701                                 end if;
6702                                 if p_change_bom_reference = 1 and p_change_routing_reference = 1 then
6703                                     p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6704                                     p_common_bill_sequence_id := p_old_com_bom_seq_id;
6705                                 end if;
6706                                 if p_change_bom_reference = 1 and p_change_routing_reference = 0 then
6707                                     p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6708                                     p_common_bill_sequence_id := p_old_com_bom_seq_id;
6709                                 end if;
6710                                 if p_change_bom_reference = 0 and p_change_routing_reference = 1 then
6711                                     p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6712                                     p_common_bill_sequence_id := p_old_com_bom_seq_id;
6713                                 end if;
6714                             end if;
6715 
6716                             if p_old_status_type = 1 then
6717                                 if p_change_bom_reference = 0 and p_change_routing_reference = 0 then
6718                                     p_common_routing_sequence_id := p_old_com_rtg_seq_id;
6719                                     p_common_bill_sequence_id := p_old_com_bom_seq_id;
6720                                 end if;
6721                                 if p_change_bom_reference = 1 and p_change_routing_reference = 1 then
6722                                     --p_common_routing_sequence_id := p_common_routing_sequence_id;
6723                                     p_common_bill_sequence_id := bom_seq_id;
6724                                 end if;
6725                                 if p_change_bom_reference = 1 and p_change_routing_reference = 0 then
6726                                     --p_common_routing_sequence_id := p_common_routing_sequence_id;
6727                                     p_common_bill_sequence_id := bom_seq_id;
6728                                 end if;
6729                                 if p_change_bom_reference = 0 and p_change_routing_reference = 1 then
6730                                     --p_common_routing_sequence_id := p_common_routing_sequence_id;
6731                                     p_common_bill_sequence_id := bom_seq_id;
6732                                 end if;
6733                             end if;
6734                         end if; -- job type=3
6735 
6736                     end if; --load_type 6
6737 
6738 --************************************************************************************************
6739 --****************************** Reschedule Job Validations End **********************************
6740 --************************************************************************************************
6741 
6742 
6743 
6744 
6745 -- ==============================================================================================
6746 -- VALIDATIONS END, WRITING INTO BASE TABLES BEGIN
6747 -- ==============================================================================================
6748 
6749 -- ==============================================================================================
6750 -- WRITING INTO BASE TABLES FOR JOB CREATION
6751 -- ==============================================================================================
6752 
6753                     if v_wlji_load_type(v_index) = 5 then
6754                     -- calling the build_lbji_info with p_rtg_op_seq_num as the rtg op_seq_num null...
6755                         build_lbji_info(
6756                             p_routing_seq_id => routing_seq_id,
6757                             p_common_bill_sequence_id => bom_seq_id,
6758                             p_explode_header_detail => null,
6759                             p_status_type => v_wlji_status_type(v_index),
6760                             p_class_code => v_wlji_class_code(v_index),
6761                             p_org => v_wlji_org(v_index),
6762                             p_wip_entity_id => v_wlji_wip_entity_id(v_index),
6763                             p_last_updt_date => v_wlji_last_updt_date(v_index),
6764                             p_last_updt_by => v_wlji_last_updt_by(v_index),
6765                             p_creation_date => v_wlji_creation_date(v_index),
6766                             p_created_by => v_wlji_created_by(v_index),
6767                             p_last_updt_login => v_wlji_last_updt_login(v_index),
6768                             p_request_id => v_wlji_request_id(v_index),
6769                             p_program_application_id => v_wlji_program_application_id(v_index),
6770                             p_program_id => v_wlji_program_id(v_index),
6771                             p_prog_updt_date => v_wlji_prog_updt_date(v_index),
6772                             p_source_line_id => v_wlji_source_line_id(v_index),
6773                             p_source_code =>  v_wlji_source_code(v_index),
6774                             p_description => v_wlji_description(v_index),
6775                             p_item => v_wlji_item(v_index),
6776                             p_job_type => v_wlji_job_type(v_index),
6777                             p_bom_reference_id =>  v_wlji_bom_reference_id(v_index),
6778                             p_routing_reference_id => v_wlji_routing_reference_id(v_index),
6779                             p_firm_planned_flag => v_wlji_firm_planned_flag(v_index),
6780                             p_wip_supply_type => v_wlji_wip_supply_type(v_index),
6781                             p_fusd => v_wlji_fusd(v_index),
6782                             p_lucd => v_wlji_lucd(v_index),
6783                             p_start_quantity => v_wlji_start_quantity(v_index),
6784                             p_net_quantity => v_wlji_net_quantity(v_index),
6785                             p_coproducts_supply => v_wlji_coproducts_supply(v_index),
6786                             p_bom_revision => v_wlji_bom_revision(v_index),
6787                             p_routing_revision => v_wlji_routing_revision(v_index),
6788                             p_bom_revision_date => v_wlji_bom_revision_date(v_index),
6789                             p_routing_revision_date => v_wlji_routing_revision_date(v_index),
6790                             p_lot_number => v_wlji_lot_number(v_index),
6791                             p_alt_bom_designator => v_wlji_alt_bom_designator(v_index),
6792                             p_alt_routing_designator => v_wlji_alt_routing_designator(v_index),
6793                             p_priority => v_wlji_priority(v_index),
6794                             p_due_date => v_wlji_due_date(v_index),
6795                             p_attribute_category => v_wlji_attribute_category(v_index),
6796                             p_attribute1 => v_wlji_attribute1(v_index),
6797                             p_attribute2 => v_wlji_attribute2(v_index),
6798                             p_attribute3 => v_wlji_attribute3(v_index),
6799                             p_attribute4 => v_wlji_attribute4(v_index),
6800                             p_attribute5 => v_wlji_attribute5(v_index),
6801                             p_attribute6 => v_wlji_attribute6(v_index),
6802                             p_attribute7 => v_wlji_attribute7(v_index),
6803                             p_attribute8 => v_wlji_attribute8(v_index),
6804                             p_attribute9 => v_wlji_attribute9(v_index),
6805                             p_attribute10 => v_wlji_attribute10(v_index),
6806                             p_attribute11 => v_wlji_attribute11(v_index),
6807                             p_attribute12 => v_wlji_attribute12(v_index),
6808                             p_attribute13 => v_wlji_attribute13(v_index),
6809                             p_attribute14 => v_wlji_attribute14(v_index),
6810                             p_attribute15 => v_wlji_attribute15(v_index),
6811                             p_job_name => v_wlji_job_name(v_index),
6812                             p_completion_subinventory => v_wlji_completion_subinventory(v_index),
6813                             p_completion_locator_id => v_wlji_completion_locator_id(v_index),
6814                             p_demand_class => v_wlji_demand_class(v_index),
6815                             p_project_id => v_wlji_project_id(v_index),
6816                             p_task_id => v_wlji_task_id(v_index),
6817                             p_schedule_group_id => v_wlji_schedule_group_id(v_index),
6818                             p_build_sequence => v_wlji_build_sequence(v_index),
6819                             p_line_id => v_wlji_line_id(v_index),
6820                             p_kanban_card_id => v_wlji_kanban_card_id(v_index),
6821                             p_overcompl_tol_type => v_wlji_overcompl_tol_type(v_index),
6822                             p_overcompl_tol_value => v_wlji_overcompl_tol_value(v_index),
6823                             p_end_item_unit_number => v_wlji_end_item_unit_number(v_index),
6824                             p_rtg_op_seq_num => null,
6825                             p_src_client_server => 0,
6826                             p_po_creation_time => WSMPLCVA.v_org(v_wlji_org(v_index)).PO_CREATION_TIME,
6827                             p_date_released => v_wlji_date_released(v_index),
6828                             p_error_code => l_error_code,
6829                             p_error_msg => l_error_msg);
6830 
6831                         if l_error_code <> 0 then
6832                             handle_error(l_error_code, l_error_msg,  l_stmt_num);
6833                             l_error_count := l_error_count + 1;
6834                             GOTO skip_other_steps;
6835                         end if;
6836 
6837                     end if; -- load_type 5
6838 
6839 
6840 -- ==============================================================================================
6841 -- WRITING INTO BASE TABLES FOR JOB UPDATE
6842 -- ==============================================================================================
6843 
6844 
6845                     if v_wlji_load_type(v_index) = 6 then
6846 
6847                         -- if the user wants to update only the references, the following updates are not needed
6848                         if p_skip_updt = 0 then
6849 
6850                             if discrete_charges_exist(v_wlji_wip_entity_id(v_index), v_wlji_org(v_index),1) then
6851                                 l_txnexist := 1;
6852                             else
6853                                 l_txnexist := 0;
6854                             end if;
6855 
6856 
6857                             if v_wlji_allow_explosion(v_index) = 'Y' and v_wlji_status_type(v_index) <> 7 then
6858                             Begin
6859 l_stmt_num := 1062;
6860                                 if v_wlji_start_quantity(v_index) <> p_old_quantity then
6861                                     l_qntydiff := 1;
6862                                 else
6863                                     l_qntydiff := 0;
6864                                 end if;
6865 
6866                                 UPDATE WIP_OPERATIONS
6867                                 SET
6868                                        FIRST_UNIT_START_DATE = decode(l_txnexist,
6869                                                                       0, NVL(v_wlji_fusd(v_index), FIRST_UNIT_START_DATE),  -- bug 3394520
6870                                                                       FIRST_UNIT_START_DATE),
6871                                        FIRST_UNIT_COMPLETION_DATE = decode(l_txnexist,
6872                                                                            0, NVL(v_wlji_lucd(v_index), FIRST_UNIT_COMPLETION_DATE), -- bug 3394520
6873                                                                            FIRST_UNIT_COMPLETION_DATE),
6874                                        LAST_UNIT_START_DATE = decode(l_txnexist,
6875                                                                      0, NVL(v_wlji_fusd(v_index), LAST_UNIT_START_DATE),  -- bug 3394520
6876                                                                      LAST_UNIT_START_DATE),
6877                                        LAST_UNIT_COMPLETION_DATE = decode(l_txnexist,
6878                                                                           0, NVL(v_wlji_lucd(v_index), LAST_UNIT_COMPLETION_DATE), -- bug 3394520
6879                                                                           LAST_UNIT_COMPLETION_DATE),
6880                                        SCHEDULED_QUANTITY = ROUND(v_wlji_start_quantity(v_index), WIP_CONSTANTS.MAX_DISPLAYED_PRECISION),
6881                                        QUANTITY_IN_QUEUE = decode(v_wlji_status_type(v_index),
6882                                             1, (decode(OPERATION_SEQ_NUM,10,0,QUANTITY_IN_QUEUE)),
6883                                             3, (decode(p_old_status_type,
6884                                                     1, decode(OPERATION_SEQ_NUM,10,ROUND(v_wlji_start_quantity(v_index),
6885                                                              WIP_CONSTANTS.MAX_DISPLAYED_PRECISION), QUANTITY_IN_QUEUE),
6886                                                     decode(l_qntydiff,
6887                                                     1, decode(OPERATION_SEQ_NUM,
6888                                                               10,ROUND(v_wlji_start_quantity(v_index),WIP_CONSTANTS.MAX_DISPLAYED_PRECISION),
6889                                                               QUANTITY_IN_QUEUE),
6890                                                     QUANTITY_IN_QUEUE))),
6891                                        QUANTITY_IN_QUEUE),
6892                                        LAST_UPDATED_BY = v_wlji_last_updt_by(v_index),
6893                                        LAST_UPDATE_DATE = SYSDATE,
6894                                        LAST_UPDATE_LOGIN = v_wlji_last_updt_login(v_index),
6895                                        PROGRAM_UPDATE_DATE = SYSDATE,
6896                                        REQUEST_ID = v_wlji_request_id(v_index),
6897                                        PROGRAM_APPLICATION_ID = v_wlji_program_application_id(v_index),
6898                                        PROGRAM_ID = v_wlji_program_id(v_index)
6899                                 WHERE  ORGANIZATION_ID = v_wlji_org(v_index)
6900                                 AND    WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index);
6901 
6902                                 if lbji_debug = 'Y' then
6903                                     fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into wo');
6904                                 end if;
6905 
6906 l_stmt_num := 1063;
6907                                 UPDATE WIP_OPERATION_RESOURCES
6908                                 SET    START_DATE = decode(l_txnexist,
6909                                                            0, NVL(v_wlji_fusd(v_index), START_DATE), -- bug 3394520
6910                                                            START_DATE),
6911                                        COMPLETION_DATE =  decode(l_txnexist,
6912                                                                  0, NVL(v_wlji_lucd(v_index), COMPLETION_DATE),
6913                                                                  COMPLETION_DATE),
6914                                        LAST_UPDATED_BY = v_wlji_last_updt_by(v_index),
6915                                        LAST_UPDATE_DATE = SYSDATE,
6916                                        LAST_UPDATE_LOGIN = v_wlji_last_updt_login(v_index),
6917                                        PROGRAM_UPDATE_DATE = SYSDATE,
6918                                        REQUEST_ID = v_wlji_request_id(v_index),
6919                                        PROGRAM_APPLICATION_ID = v_wlji_program_application_id(v_index),
6920                                        PROGRAM_ID = v_wlji_program_id(v_index)
6921                                 WHERE  ORGANIZATION_ID = v_wlji_org(v_index)
6922                                 AND    WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index);
6923 
6924                                 if lbji_debug = 'Y' then
6925                                     fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into wor');
6926                                 end if;
6927 
6928 l_stmt_num := 1064;
6929                                 --LBM enh: modified the expression on required_quantity
6930                                 UPDATE WIP_REQUIREMENT_OPERATIONS WRO
6931                                 SET    WRO.DATE_REQUIRED =
6932                                        (SELECT NVL(MIN(FIRST_UNIT_START_DATE), v_wlji_fusd(v_index))
6933                                         FROM   WIP_OPERATIONS
6934                                         WHERE  ORGANIZATION_ID = v_wlji_org(v_index)
6935                                         AND    WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index)
6936                                         AND    OPERATION_SEQ_NUM = ABS(WRO.OPERATION_SEQ_NUM)),
6937                                        LAST_UPDATED_BY = v_wlji_last_updt_by(v_index),
6938                                        LAST_UPDATE_DATE = SYSDATE,
6939                                        LAST_UPDATE_LOGIN = v_wlji_last_updt_login(v_index),
6940                                        REQUEST_ID = v_wlji_request_id(v_index),
6941                                        PROGRAM_UPDATE_DATE = SYSDATE,
6942                                        PROGRAM_ID = v_wlji_program_id(v_index),
6943                                        PROGRAM_APPLICATION_ID = v_wlji_program_application_id(v_index),
6944                                        REQUIRED_QUANTITY = (QUANTITY_PER_ASSEMBLY * decode(wro.basis_type, 2, 1, ROUND(v_wlji_start_quantity(v_index), 6)))
6945                                 WHERE  ORGANIZATION_ID = v_wlji_org(v_index)
6946                                 AND    WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index);
6947 
6948                                 if lbji_debug = 'Y' then
6949                                     fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into wro');
6950                                 end if;
6951 
6952 l_stmt_num := 1065;
6953                                 -- abb H: optional scrap accounting
6954 
6955                                 if (p_old_status_type IN (1,6) and v_wlji_status_type(v_index) = 3) and
6956                                     wsmputil.WSM_ESA_ENABLED(
6957                                             p_wip_entity_id => v_wlji_wip_entity_id(v_index),
6958                                             err_code => l_error_code,
6959                                             err_msg => l_error_msg,
6960                                             p_org_id => '',
6961                                             p_job_type => '') = 1 then
6962 
6963                                     select min(operation_seq_num)
6964                                     into   min_op_seq_num
6965                                     from   wip_operations
6966                                     where  wip_entity_id =  v_wlji_wip_entity_id(v_index);
6967 
6968                                     select bd.scrap_account, bd.est_absorption_account, wo.department_id
6969                                     into   l_scrap_account10, l_est_scrap_abs_account10, l_department_id
6970                                     from   bom_departments bd, wip_operations wo
6971                                     where  wo.wip_entity_id =  v_wlji_wip_entity_id(v_index)
6972                                     and    wo.operation_seq_num = min_op_seq_num
6973                                     and    bd.department_id = wo.department_id;
6974 
6975                                     if l_scrap_account10 is null or l_est_scrap_abs_account10 is null then
6976                                         v_wlji_process_status(v_index) := 3; --ERROR
6977                                         v_wlji_err_code(v_index) := -1;
6978                                         fnd_message.set_name('WSM','WSM_NO_SCRAP_ACC');
6979                                         fnd_message.set_token('DEPT_ID',to_char(l_department_id));
6980                                         v_wlji_err_msg(v_index) := fnd_message.get;
6981                                         fnd_file.put_line(fnd_file.log, 'stmt_num: '|| l_stmt_num ||'  '||v_wlji_err_msg(v_index));
6982                                         fnd_file.new_line(fnd_file.log, 3);
6983                                         l_error_code := -1;
6984                                         l_error_count := l_error_count + 1;
6985                                         GOTO skip_other_steps;
6986                                     end if;
6987 
6988                                     UPDATE WIP_OPERATION_YIELDS WOY
6989                                            SET SCRAP_ACCOUNT = nvl(l_scrap_account10, WOY.SCRAP_ACCOUNT),
6990                                            EST_SCRAP_ABSORB_ACCOUNT = nvl(l_est_scrap_abs_account10, WOY.EST_SCRAP_ABSORB_ACCOUNT)
6991                                     WHERE  WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index)
6992                                     and    operation_seq_num = min_op_seq_num;
6993 
6994                                     if lbji_debug = 'Y' then
6995                                         fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into woy');
6996                                     end if;
6997 
6998                                     select max(operation_seq_num)
6999                                     into   max_op_seq_num
7000                                     from   wip_operations
7001                                     where  wip_entity_id = v_wlji_wip_entity_id(v_index);
7002 
7003                                     select bd.scrap_account, bd.est_absorption_account,  wo.department_id
7004                                     into   l_scrap_account9999, l_est_scrap_abs_account9999, l_department_id
7005                                     from   bom_departments bd, wip_operations wo
7006                                     where  wo.wip_entity_id =  v_wlji_wip_entity_id(v_index)
7007                                     and    wo.operation_seq_num = max_op_seq_num
7008                                     and    bd.department_id = wo.department_id;
7009 
7010                                     if l_scrap_account9999 is null or l_est_scrap_abs_account9999 is null then
7011                                         v_wlji_process_status(v_index) := 3; --ERROR
7012                                         v_wlji_err_code(v_index) := -1;
7013                                         fnd_message.set_name('WSM','WSM_NO_SCRAP_ACC');
7014                                         fnd_message.set_token('DEPT_ID',to_char(l_department_id));
7015                                         v_wlji_err_msg(v_index) := fnd_message.get;
7016                                         fnd_file.put_line(fnd_file.log, 'stmt_num: '|| l_stmt_num ||'  '||v_wlji_err_msg(v_index));
7017                                         fnd_file.new_line(fnd_file.log, 3);
7018                                         l_error_code := -1;
7019                                         l_error_count := l_error_count + 1;
7020                                         GOTO skip_other_steps;
7021                                     end if;
7022 
7023                                     UPDATE WIP_OPERATION_YIELDS WOY
7024                                            SET SCRAP_ACCOUNT = nvl(l_scrap_account9999, WOY.SCRAP_ACCOUNT),
7025                                            EST_SCRAP_ABSORB_ACCOUNT = nvl(l_est_scrap_abs_account9999, WOY.EST_SCRAP_ABSORB_ACCOUNT)
7026                                     WHERE  WIP_ENTITY_ID = v_wlji_wip_entity_id(v_index)
7027                                     and    operation_seq_num = max_op_seq_num;
7028 
7029                                     if lbji_debug = 'Y' then
7030                                         fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into woy');
7031                                     end if;
7032 
7033                                 end if;
7034 
7035                             Exception
7036                                    when others then
7037                                    l_error_code := SQLCODE;
7038                                    l_error_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
7039                                    handle_error(l_error_code, l_error_msg,  l_stmt_num);
7040                                    l_error_count := l_error_count + 1;
7041                                    GOTO skip_other_steps;
7042                             End;
7043                             end if; -- allow_explosion
7044 
7045                         end if; --p_skip_updt
7046 l_stmt_num := 1071;
7047                         Begin
7048                             if p_old_status_type <> 1 AND v_wlji_status_type(v_index) = 1 then
7049                                 delete from wip_period_balances
7050                                 where  wip_entity_id = v_wlji_wip_entity_id(v_index)
7051                                 and    organization_id = v_wlji_org(v_index);
7052                                 if lbji_debug = 'Y' then
7053                                     fnd_file.put_line(fnd_file.log, 'Deleted '||SQL%ROWCOUNT||' rows from wpb');
7054                                 end if;
7055                             end if;
7056 
7057 l_stmt_num := 1072;
7058                             if v_wlji_status_type(v_index) = 7 then --cancelled
7059 
7060                                 -- osp begin
7061                                 if wip_osp.po_req_exists ( v_wlji_wip_entity_id(v_index),
7062                                                            null,
7063                                                            v_wlji_org(v_index),
7064                                                            null, 5) then
7065                                        fnd_message.set_name('WIP', 'WIP_CANCEL_JOB/SCHED_OPEN_PO');
7066                                        l_err_msg := fnd_message.get;
7067                                        l_warning_count := l_warning_count + 1;
7068                                        handle_warning( p_err_msg => l_err_msg,
7069                                                        p_header_id => v_wlji_header_id(v_index),
7070                                                        p_request_id => v_wlji_request_id(v_index),
7071                                                        p_program_id => v_wlji_program_id(v_index),
7072                                                        p_program_application_id => v_wlji_program_application_id(v_index));
7073                                 end if;
7074                                 -- osp end
7075 
7076                                 wip_picking_pvt.cancel_allocations(v_wlji_wip_entity_id(v_index),
7077                                                5,
7078                                                NULL,
7079                                                x_return_status,
7080                                                x_msg_data);
7081 
7082                                 if x_return_status <> FND_API.G_RET_STS_SUCCESS then
7083                                     handle_error(x_return_status, x_msg_data,  l_stmt_num);
7084                                     l_error_count := l_error_count + 1;
7085                                     GOTO skip_other_steps;
7086                                 else
7087                                     update wip_discrete_jobs wdj
7088                                     set    status_type = 7
7089                                     where  wdj.wip_entity_id = v_wlji_wip_entity_id(v_index);
7090                                     if lbji_debug = 'Y' then
7091                                         fnd_file.put_line(fnd_file.log, 'Updated status type to 7 in wdj');
7092                                     end if;
7093                     --
7094                         -- begin Bugfix 2820900 : Update the job name with sector lot extn. once canceled.
7095                     -- Note: Since status update for canceled jobs are not allowed currently, there's
7096                     -- no logic to remove the sector lot extn.
7097                     --
7098                             x_new_name := WSMPOPRN.update_job_name
7099                                         (p_wip_entity_id    => v_wlji_wip_entity_id(v_index),
7100                             p_subinventory      => v_wlji_completion_subinventory(v_index),
7101                             p_org_id        => v_wlji_org(v_index),
7102                                         p_txn_type      => 2,       -- COMPLETION
7103                                         p_update_flag       => TRUE,
7104                                         p_dup_job_name      => l_dup_job_name,
7105                                         x_error_code        => l_error_code,
7106                                         x_error_msg     => l_error_msg);
7107 
7108                    if l_error_code <> 0 then
7109                             handle_error(l_error_code, l_error_msg,  l_stmt_num);
7110                             l_error_count := l_error_count + 1;
7111                             GOTO skip_other_steps;
7112                    end if;
7113 
7114                    --
7115                    -- end bugfix 2820900
7116                    --
7117                                 end if;
7118 
7119                                 --abbKanban begin
7120                                 if v_wlji_kanban_card_id(v_index) is not null then
7121                                     inv_kanban_pvt.Update_Card_Supply_Status
7122                                             (X_Return_Status => l_returnStatus,
7123                                              p_Kanban_Card_Id => v_wlji_kanban_card_id(v_index),
7124                                              p_Supply_Status => inv_kanban_pvt.g_supply_status_Exception);
7125 
7126                                     if ( l_returnStatus <> fnd_api.g_ret_sts_success ) then
7127                                         l_error_code := -1;
7128                                         fnd_message.set_name('WSM', 'WSM_KNBN_CARD_STS_FAIL');
7129 
7130                                         select meaning
7131                                         into   translated_meaning
7132                                         from   mfg_lookups
7133                                         where  lookup_type = 'MTL_KANBAN_SUPPLY_STATUS'
7134                                         and    lookup_code = 7
7135                                         and    upper(enabled_flag) = 'Y';
7136 
7137                                         fnd_message.set_token('STATUS',translated_meaning);
7138                                         l_error_msg := fnd_message.get;
7139                                         handle_error(l_error_code, l_error_msg,  l_stmt_num);
7140                                         l_error_count := l_error_count + 1;
7141                                         GOTO skip_other_steps;
7142                                     end if;
7143 
7144                                     update wip_discrete_jobs
7145                                     set    kanban_card_id = null
7146                                     where  wip_entity_id =  v_wlji_wip_entity_id(v_index);
7147 
7148                                 end if;
7149                                 --abbKanban end
7150 
7151 
7152                             else
7153 l_stmt_num := 1073;
7154                                 -- bug 2762029 modification begin
7155                                 UPDATE      WIP_DISCRETE_JOBS WDJ
7156                                 set         last_updated_by = v_wlji_last_updt_by(v_index),
7157                                             last_update_login = v_wlji_last_updt_login(v_index),
7158                                             request_id = v_wlji_request_id(v_index),
7159                                             program_application_id = v_wlji_program_application_id(v_index),
7160                                             program_id = v_wlji_program_id(v_index),
7161                                             program_update_date = sysdate,
7162                                             last_update_date = sysdate,
7163                                             bom_reference_id = v_wlji_bom_reference_id(v_index),
7164                                             routing_reference_id = v_wlji_routing_reference_id(v_index),
7165                                             common_bom_sequence_id = p_common_bill_sequence_id,
7166                                             common_routing_sequence_id = p_common_routing_sequence_id,
7167                                             bom_revision = v_wlji_bom_revision(v_index),
7168                                             routing_revision = v_wlji_routing_revision(v_index),
7169                                             bom_revision_date = v_wlji_bom_revision_date(v_index),
7170                                             routing_revision_date = v_wlji_routing_revision_date(v_index),
7171                                             alternate_bom_designator = v_wlji_alt_bom_designator(v_index),
7172                                             alternate_routing_designator = v_wlji_alt_routing_designator(v_index),
7173                                             firm_planned_flag = v_wlji_firm_planned_flag(v_index),
7174                                             start_quantity = nvl(round(v_wlji_start_quantity(v_index), wip_constants.max_displayed_precision),
7175                                                         wdj.start_quantity),
7176                                             net_quantity = nvl(round(v_wlji_net_quantity(v_index), wip_constants.max_displayed_precision),
7177                                                         wdj.net_quantity),
7178                                             status_type = nvl(v_wlji_status_type(v_index),wdj.status_type),
7179                                             date_released = v_wlji_date_released(v_index), -- bug 2697295
7180                                             scheduled_start_date = decode(l_txnexist, 0,
7181                                                             trunc(v_wlji_fusd(v_index),'MI'), wdj.scheduled_start_date),
7182                                             scheduled_completion_date = trunc(v_wlji_lucd(v_index),'MI'),
7183                                             completion_locator_id = v_wlji_completion_locator_id(v_index),
7184                                             completion_subinventory = v_wlji_completion_subinventory(v_index),
7185                                             coproducts_supply = nvl(v_wlji_coproducts_supply(v_index), wdj.coproducts_supply),
7186                                             -- BA: BUG3272873
7187                                             source_code = nvl(v_wlji_source_code(v_index),wdj.source_code),
7188                                             source_line_id = nvl(v_wlji_source_line_id(v_index),wdj.source_line_id),
7189                                             overcompletion_tolerance_type = nvl(v_wlji_overcompl_tol_type(v_index),
7190                                                                 wdj.overcompletion_tolerance_type),
7191                                             overcompletion_tolerance_value = nvl(v_wlji_overcompl_tol_value(v_index),
7192                                                                 wdj.overcompletion_tolerance_value),
7193                                             priority = nvl(v_wlji_priority(v_index),wdj.priority),
7194                                             due_date = nvl(v_wlji_due_date(v_index),wdj.due_date),
7195                                             attribute_category = nvl(v_wlji_attribute_category(v_index),wdj.attribute_category),
7196                                             attribute1 = nvl(v_wlji_attribute1(v_index),wdj.attribute1),
7197                                             attribute2 = nvl(v_wlji_attribute2(v_index),wdj.attribute2),
7198                                             attribute3 = nvl(v_wlji_attribute3(v_index),wdj.attribute3),
7199                                             attribute4 = nvl(v_wlji_attribute4(v_index),wdj.attribute4),
7200                                             attribute5 = nvl(v_wlji_attribute5(v_index),wdj.attribute5),
7201                                             attribute6 = nvl(v_wlji_attribute6(v_index),wdj.attribute6),
7202                                             attribute7 = nvl(v_wlji_attribute7(v_index),wdj.attribute7),
7203                                             attribute8 = nvl(v_wlji_attribute8(v_index),wdj.attribute8),
7204                                             attribute9 = nvl(v_wlji_attribute9(v_index),wdj.attribute9),
7205                                             attribute10 = nvl(v_wlji_attribute10(v_index),wdj.attribute10),
7206                                             attribute11 = nvl(v_wlji_attribute11(v_index),wdj.attribute11),
7207                                             attribute12 = nvl(v_wlji_attribute12(v_index),wdj.attribute12),
7208                                             attribute13 = nvl(v_wlji_attribute13(v_index),wdj.attribute13),
7209                                             attribute14 = nvl(v_wlji_attribute14(v_index),wdj.attribute14),
7210                                             attribute15 = nvl(v_wlji_attribute15(v_index),wdj.attribute15),
7211                                             -- EA: BUG3272873
7212                                             est_scrap_account = nvl(p_est_scrap_account, wdj.est_scrap_account),
7213                                             est_scrap_var_account = nvl(p_est_scrap_var_account, wdj.est_scrap_var_account),
7214                                             description = nvl(RTRIM(v_wlji_description(v_index)), wdj.description)
7215                                             where wdj.wip_entity_id = v_wlji_wip_entity_id(v_index);
7216                                             --returning wdj.date_released into p_date_released;
7217                                 -- bug 2762029 modification end
7218                             end if; -- update jobs for which status is not cancelled
7219 
7220                             if lbji_debug = 'Y' then
7221                                 fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows of wdj');
7222                             end if;
7223 
7224 
7225 l_stmt_num := 1074;
7226                             UPDATE WIP_ENTITIES WE
7227                             set    description = nvl(v_wlji_description(v_index), we.description),
7228                                    last_updated_by = v_wlji_last_updt_by(v_index),
7229                                    last_update_login = v_wlji_last_updt_login(v_index),
7230                                    request_id = v_wlji_request_id(v_index),
7231                                    program_application_id = v_wlji_program_application_id(v_index),
7232                                    program_id = v_wlji_program_id(v_index),
7233                                    program_update_date = v_wlji_prog_updt_date(v_index),
7234                                    last_update_date = v_wlji_last_updt_date(v_index)
7235                             where  we.wip_entity_id = v_wlji_wip_entity_id(v_index);
7236 
7237                             if lbji_debug = 'Y' then
7238                                 fnd_file.put_line(fnd_file.log, 'Updated '||SQL%ROWCOUNT||' rows into we');
7239                             end if;
7240 
7241                         Exception
7242                            when others then
7243                            l_error_code := SQLCODE;
7244                            l_error_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
7245                            handle_error(l_error_code, l_error_msg,  l_stmt_num);
7246                            l_error_count := l_error_count + 1;
7247                            GOTO skip_other_steps;
7248                         End;
7249 
7250                     end if; -- load_type 6
7251 
7252 l_stmt_num := 1080;
7253 
7254                     if (
7255                        (v_wlji_load_type(v_index) = 6 AND
7256                         v_wlji_status_type(v_index) = WIP_CONSTANTS.RELEASED and
7257                         p_old_status_type = WIP_CONSTANTS.UNRELEASED)
7258                     ) then
7259 
7260                         if ((v_wlji_load_type(v_index) = 6) AND (v_wlji_class_code(v_index) is NULL)) then
7261                             v_wlji_class_code(v_index) := p_old_class_code;
7262                         end if;
7263                         fnd_file.put_line(fnd_file.log, 'date released ****: '||v_wlji_date_released(v_index));
7264                         insert_into_period_balances (
7265                                 p_wip_entity_id =>  v_wlji_wip_entity_id(v_index),
7266                                 p_organization_id =>  v_wlji_org(v_index),
7267                                 p_class_code =>   v_wlji_class_code(v_index),
7268                                 p_release_date => v_wlji_date_released(v_index), --p_date_released,
7269                                 p_error_code => l_error_code,
7270                                 p_err_msg => l_error_msg
7271                         );
7272 
7273                         if l_error_code <> 0 then
7274                             handle_error(l_error_code, l_error_msg,  l_stmt_num);
7275                             l_error_count := l_error_count + 1;
7276                             GOTO skip_other_steps;
7277                         end if;
7278                     end if;
7279 
7280 
7281 
7282 -- ==============================================================================================
7283 --  MATERIAL TRANSACTION FOR MODE 2 JOB CREATE
7284 -- ==============================================================================================
7285 
7286 l_stmt_num := 1100;
7287                     -- *** material transaction for mode 2 jobs begin ***
7288                     if v_wlji_mode_flag(v_index) = 2 then
7289 
7290                         IF WSMPLCVA.v_org(v_wlji_org(v_index)).MAX_ORG_ACC_PERIODS is null or
7291                            WSMPLCVA.v_org(v_wlji_org(v_index)).MAX_ORG_ACC_PERIODS = 0
7292                         then
7293                              l_error_code := -1;
7294                              process_errorred_field('WIP',
7295                                                     'WIP_NO_ACCT_PERIOD',
7296                                                      l_stmt_num);
7297                             GOTO skip_mat_trans;
7298                         end if;
7299 
7300                         if WSMPLCVA.v_org(v_wlji_org(v_index)).MAX_STK_LOC_CNTRL is null then
7301                             WSMPLCVA.v_org(v_wlji_org(v_index)).MAX_STK_LOC_CNTRL := 1;
7302                         end if;
7303 
7304 l_stmt_num := 1120;
7305                         /* commented out by BBK for DUAL usage reduction.
7306                         select mtl_material_transactions_s.nextval
7307                         into txn_tmp_header_id
7308                         from dual;
7309                         */
7310 
7311 l_stmt_num := 1140;
7312                         Begin  -- material transaction
7313 
7314                             insert into mtl_material_transactions_temp(
7315                                     last_update_date,
7316                                     creation_date,
7317                                     last_updated_by,
7318                                     created_by,
7319                                     last_update_login,
7320                                     transaction_header_id,
7321                                     transaction_source_id,
7322                                     inventory_item_id,
7323                                     organization_id,
7324                                     revision,
7325                                     subinventory_code,
7326                                     locator_id,
7327                                     transaction_quantity,
7328                                     primary_quantity,
7329                                     transaction_uom,
7330                                     transaction_type_id,
7331                                     transaction_action_id,
7332                                     transaction_source_type_id,
7333                                     transaction_date,
7334                                     acct_period_id,
7335                                     source_code,
7336                                     source_line_id,
7337                                     wip_entity_type,
7338                                     negative_req_flag,
7339                                     operation_seq_num,
7340                                     wip_supply_type,
7341                                     wip_commit_flag,
7342                                     process_flag,
7343                                     posting_flag,
7344                                     transaction_temp_id)
7345                             values (
7346                                     v_wlji_last_updt_date(v_index),
7347                                     v_wlji_creation_date(v_index),
7348                                     v_wlji_last_updt_by(v_index),
7349                                     v_wlji_created_by(v_index),
7350                                     v_wlji_last_updt_login(v_index),
7351                                     txn_header_id,                                            /* TRANSACTION_HEADER_ID */
7352                                     v_wlji_wip_entity_id(v_index),                            /* TRANSACTION_SOURCE_ID */
7353                                     v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id, /* INVENTORY_ITEM_ID */
7354                                     v_wlji_org(v_index),                                      /* ORGANIZATION_ID */
7355                                     v_wsli(v_wlji_source_line_id(v_index)).revision,          /* REVISION */
7356                                     v_wsli(v_wlji_source_line_id(v_index)).subinventory_code, /* SUBINVENTORY_CODE */
7357                                     v_wsli(v_wlji_source_line_id(v_index)).locator_id,
7358                                     -l_quantity_tobe_issued,
7359                                     ---1 * v_wsli(v_wlji_source_line_id(v_index)).quantity,   /* TRANSACTION_QUANTITY */
7360                                     ---1 * v_wsli(v_wlji_source_line_id(v_index)).quantity,   /* PRIMARY_QUANTITY */
7361                                     -l_quantity_tobe_issued,
7362                                     v_wsli(v_wlji_source_line_id(v_index)).primary_uom_code,  /* UNIT_OF_MEASURE */
7363                                     35,                                                       /* TRANSACTION_TYPE_ID */
7364                                     1,                                                        /* TRANSACTION_ACTION_ID */
7365                                     5,                                                        /* TRANSACTION_SOURCE_TYPE_ID */
7366                                     SYSDATE,                                                  /* TRANSACTION_DATE */
7367                                     WSMPLCVA.v_org(v_wlji_org(v_index)).MAX_ORG_ACC_PERIODS,  /*ACCT_PERIOD_ID */
7368                                     'WSM',
7369                                     to_char(v_wlji_source_line_id(v_index)),                  /* SOURCE_LINE_ID */
7370                                     5,                                                        /* WIP_ENTITY_TYPE */
7371                                     1,                                                        /* neg req flag */
7372                                     10,                                                       /* op seq */
7373                                     '',                                                       /* supply type */
7374                                     'N',                                                      /* WIP_COMMIT_FLAG */
7375                                     'Y',                                                      /* PROCESS_FLAG */
7376                                     'Y',                                                      /* POSTING_FLAG */
7377                                     -- txn_tmp_header_id                                      /* Transaction Temp Id */
7378                                     mtl_material_transactions_s.nextval                       /* Transaction Temp Id */
7379                                     ) RETURNING transaction_temp_id into txn_tmp_header_id;
7380 
7381                             if lbji_debug = 'Y' then
7382                                 fnd_file.put_line(fnd_file.log, 'Inserted '||SQL%ROWCOUNT||' rows into mmtt');
7383                             end if;
7384 
7385 l_stmt_num := 1160;
7386 
7387                             INSERT INTO MTL_TRANSACTION_LOTS_TEMP (
7388                                     transaction_temp_id,
7389                                     last_update_date,
7390                                     creation_date,
7391                                     last_updated_by,
7392                                     created_by,
7393                                     last_update_login,
7394                                     transaction_quantity,
7395                                     primary_quantity,
7396                                     lot_number)
7397                             values (
7398                             txn_tmp_header_id,
7399                                     v_wlji_last_updt_date(v_index),
7400                                     v_wlji_creation_date(v_index),
7401                                     v_wlji_last_updt_by(v_index),
7402                                     v_wlji_created_by(v_index),
7403                                     v_wlji_last_updt_login(v_index),
7404                                     -l_quantity_tobe_issued,
7405                                     ---1 * v_wsli(v_wlji_source_line_id(v_index)).quantity,
7406                                     ---1 * v_wsli(v_wlji_source_line_id(v_index)).quantity,
7407                                     -l_quantity_tobe_issued,
7408                                     v_wsli(v_wlji_source_line_id(v_index)).lot_number);
7409 
7410                             if lbji_debug = 'Y' then
7411                                 fnd_file.put_line(fnd_file.log, 'Inserted '||SQL%ROWCOUNT||' rows into mtlt');
7412                             end if;
7413 
7414 l_stmt_num := 1160;
7415                             UPDATE WIP_REQUIREMENT_OPERATIONS
7416                             set    wip_supply_type = 1
7417                             where  wip_entity_id = v_wlji_wip_entity_id(v_index)
7418                             and    operation_seq_num = 10
7419                             and    inventory_item_id = v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id;
7420 
7421 
7422                         Exception  -- material transaction
7423                             when others then
7424                                 l_error_code := SQLCODE;
7425                                 l_error_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
7426                                 handle_error(l_error_code, l_error_msg,  l_stmt_num);
7427                                 GOTO skip_mat_trans;
7428                         End; -- material transaction
7429 
7430 << skip_mat_trans >>
7431 
7432                         if l_error_code <> 0 then
7433                             l_error_count := l_error_count + 1;
7434                             GOTO skip_other_steps;
7435                         end if;
7436 
7437                         l_atleast_one_row_in_mmtt := l_atleast_one_row_in_mmtt + 1;
7438                         l_src_lot_number:=v_wsli(v_wlji_source_line_id(v_index)).lot_number;        -- LOTATTR
7439                         l_src_inv_item_id:=v_wsli(v_wlji_source_line_id(v_index)).inventory_item_id;    -- LOTATTR
7440 
7441                     end if; -- for mode 2
7442                     -- *** material transaction for mode 2 jobs end ***
7443 
7444                     /* LotAttr */
7445                     IF p_old_status_type in (0,1,3,6) THEN  -- Initialized Value,
7446                                 --Unreleased, released, Hold
7447 l_stmt_num := 1170;
7448                         IF (lbji_debug='Y') THEN
7449                             fnd_file.put_line(fnd_file.log, 'Before Calling WSM_LotAttr_PVT.create_update_lotattr');
7450                         END IF;
7451                         WSM_LotAttr_PVT.create_update_lotattr(
7452                                 x_err_code          => l_error_code,
7453                                 x_err_msg           => l_error_msg,
7454                                 p_wip_entity_id     => v_wlji_wip_entity_id(v_index),
7455                                 p_org_id            => v_wlji_org(v_index),
7456                                 p_intf_txn_id       => v_wlji_header_id(v_index),
7457                                 p_intf_src_code     => 'WSM',
7458                                 p_src_lot_number    => l_src_lot_number,
7459                                 p_src_inv_item_id   => l_src_inv_item_id);
7460                         IF (l_error_code <> 0) THEN
7461                             handle_error(l_error_code, l_error_msg,  l_stmt_num);
7462                             l_error_count := l_error_count + 1;
7463                             GOTO skip_other_steps;
7464                         END IF;
7465                         IF (lbji_debug='Y') THEN
7466                            fnd_file.put_line(fnd_file.log, 'WSM_LotAttr_PVT.create_update_lotattr returned Success');
7467                         END IF;
7468 l_stmt_num := 1180;
7469                     END IF; -- p_old_status_type in (1,3,6)
7470 
7471                 EXCEPTION -- main block
7472                     when others then
7473                         l_error_code := SQLCODE;
7474                         l_error_msg :=  'WSMLBJIB.launch_worker: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,1000);
7475                         handle_error(l_error_code, l_error_msg,  l_stmt_num);
7476                         l_error_count := l_error_count + 1;
7477 
7478                 END; -- main block
7479 
7480 <<skip_other_steps>>
7481 
7482 
7483                 -- *** write into output file ***
7484                 -- note that this is a rudimentary piece of commentary on the job created,
7485                 -- or failed to create because there's no customer requirement on this.
7486                 if v_wlji_load_type(v_index) = 5 then
7487                     fnd_file.put_line(fnd_file.output, '-------------------------------------------------------');
7488                     --bug 5051783:Replaced org_organization_definitions with mtl_parameters.
7489                     select organization_code
7490                     into   org_code
7491                     --from   ORG_ORGANIZATION_DEFINITIONS
7492                     from   mtl_parameters
7493                     where  organization_id = v_wlji_org(v_index);
7494 
7495                     fnd_file.put_line(fnd_file.output, 'Organization: '||org_code);
7496                     fnd_file.put_line(fnd_file.output, 'Job_name: '|| v_wlji_job_name(v_index));
7497                     select meaning
7498                     into   job_type_meaning
7499                     from   mfg_lookups
7500                     where  lookup_type = 'WIP_DISCRETE_JOB'
7501                     and    lookup_code = v_wlji_job_type(v_index);
7502                     fnd_file.put_line(fnd_file.output, 'Job Type: '|| job_type_meaning);
7503 
7504                     begin
7505                         select unique(concatenated_segments)
7506                         into   assembly_name
7507                         from   mtl_system_items_kfv
7508                         where  inventory_item_id = v_wlji_item(v_index)
7509                         and    organization_id = v_wlji_org(v_index);
7510                     exception
7511                         when others then
7512                             assembly_name := 'Unknown';
7513                     end;
7514                     fnd_file.put_line(fnd_file.output, 'Assembly: '|| assembly_name);
7515                     fnd_file.put_line(fnd_file.output, 'Quantity: '|| v_wlji_start_quantity(v_index));
7516                     fnd_file.put_line(fnd_file.output, 'Start Date: '|| v_wlji_fusd(v_index));
7517                     fnd_file.put_line(fnd_file.output, 'Completion Date: '|| v_wlji_lucd(v_index));
7518                     fnd_file.put_line(fnd_file.output, 'Kanban Card: '|| v_wlji_kanban_card_id(v_index));
7519                     if v_wlji_process_status(v_index) <> 3 then
7520                         status_name := 'Success';
7521                     else
7522                         status_name := 'Falied To Create';
7523                     end if;
7524                     fnd_file.put_line(fnd_file.output, 'Process Status: '|| Status_name);
7525                     if v_wlji_process_status(v_index) = 3 then
7526                     fnd_file.put_line(fnd_file.output, v_wlji_err_msg(v_index));
7527                     end if;
7528                     fnd_file.put_line(fnd_file.output, '-------------------------------------------------------');
7529                 end if; -- load type 5
7530                 -- *** write into output file end***
7531 
7532 
7533 
7534 
7535                 -- *** mark the rows without error to be deleted ***
7536 
7537                 if v_wlji_err_code(v_index) <> 0 then
7538                     rollback to row_skip;
7539                 end if;
7540 
7541                 if v_wlji_process_status(v_index) <> 3 then
7542                     v_wlji_process_status(v_index) := 5; -- 5 : complete without error
7543                     if lbji_debug = 'Y' then
7544                         fnd_file.put_line(fnd_file.log, 'Everything OK, changing the status of the row to 5..');
7545                     end if;
7546                 else
7547                     -- abbkanban begin
7548                     if v_wlji_kanban_card_id(v_index) is not null then
7549                         inv_kanban_pvt.Update_Card_Supply_Status(
7550                                 X_Return_Status => l_returnStatus,
7551                                 p_Kanban_Card_Id => v_wlji_kanban_card_id(v_index),
7552                                 p_Supply_Status => inv_kanban_pvt.g_supply_status_Exception);
7553 
7554                         if ( l_returnStatus <> fnd_api.g_ret_sts_success ) then
7555                             l_error_code := -1;
7556                             fnd_message.set_name('WSM', 'WSM_KNBN_CARD_STS_FAIL');
7557                             select meaning
7558                             into   translated_meaning
7559                             from   mfg_lookups
7560                             where  lookup_type = 'MTL_KANBAN_SUPPLY_STATUS'
7561                             and    lookup_code = 7
7562                             and    upper(enabled_flag) = 'Y';
7563 
7564                             fnd_message.set_token('STATUS',translated_meaning);
7565                             l_error_msg := fnd_message.get;
7566                             handle_error(l_error_code, l_error_msg,  l_stmt_num);
7567                             l_error_count := l_error_count + 1;
7568                         end if;
7569 
7570                         update wip_discrete_jobs
7571                         set    kanban_card_id = null
7572                         where  wip_entity_id =  v_wlji_wip_entity_id(v_index);
7573 
7574                     end if;
7575                     -- abbkanban end
7576 
7577                     dummy_err_code := 0;
7578                     dummy_err_msg := NULL;
7579                     wsmputil.WRITE_TO_WIE (
7580                         v_wlji_header_id(v_index),
7581                         substr(v_wlji_err_msg(v_index),1,2000),
7582                         v_wlji_request_id(v_index),
7583                         v_wlji_program_id(v_index),
7584                         v_wlji_program_application_id(v_index),
7585                         1,
7586                         dummy_err_code,
7587                         dummy_err_msg );
7588 
7589                     if dummy_err_code <> 0 then
7590                         fnd_file.put_line(fnd_file.log, '*** WARNING ***');
7591                         fnd_file.put_line(fnd_file.log, 'WSMPLBJI.launch_worker: '||dummy_err_msg);
7592                         l_error_count := l_error_count + 1;
7593                     end if;
7594                 end if;
7595 
7596                 v_index := v_wlji_header_id.next(v_index);
7597 
7598             end loop; -- inner loop
7599 
7600             if lbji_debug = 'Y' then
7601                 fnd_file.put_line(fnd_file.log, '                    ');
7602                 fnd_file.put_line(fnd_file.log, '                    ');
7603                 fnd_file.put_line(fnd_file.log, '                    ');
7604                 fnd_file.put_line(fnd_file.log, '                    ');
7605             end if;
7606 
7607             -- *** RETCODE return values ***
7608             --      0: success
7609             --      1: success with warning
7610             --      2: error
7611             -- *** RETCODE return values ***
7612 
7613             if l_warning_count <> 0 then
7614                 retcode := 1;
7615                 errbuf := 'The interface process produced atleast one warning message';
7616                 fnd_file.put_line(fnd_file.log,errbuf);
7617                 conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7618             end if;
7619 
7620             if l_error_count <> 0 then
7621                 retcode := 1;
7622                 errbuf := 'The interface process marked atleast one row as errored';
7623                 fnd_file.put_line(fnd_file.log,errbuf);
7624                 conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7625             end if;
7626 
7627             -- *** bulk update wsm_lot_job_interface ***
7628             forall i in v_wlji_process_status.first..v_wlji_process_status.last
7629             update  wsm_lot_job_interface
7630             set     process_status = v_wlji_process_status(i),
7631                     error_code = v_wlji_err_code(i),
7632                     error_msg = v_wlji_err_msg(i),
7633                     request_id = v_wlji_request_id(i),
7634                     program_id = v_wlji_program_id(i),
7635                     program_application_id = v_wlji_program_application_id(i)
7636             where   header_id = v_wlji_header_id(i);
7637 
7638             l_boolean_success := false;
7639 
7640             if l_atleast_one_row_in_mmtt <>0 THEN
7641                 fnd_file.put_line(fnd_file.log, 'Invoking Inventory Worker with header id: '||to_char(txn_header_id));
7642                 l_inv_worker_req_id := FND_REQUEST.submit_request (
7643                                     'INV', 'INCTCW', NULL, NULL, FALSE,
7644                                     --to_char(txn_header_id), '1', NULL, NULL); -- bug 3733798
7645                                     to_char(txn_header_id), '4', NULL, NULL);   -- bug 3733798
7646 
7647                 commit;
7648 
7649                 fnd_file.put_line(fnd_file.log,'Material Transaction temp_header_id is '
7650                             ||to_char(txn_header_id));
7651 
7652                 if l_inv_worker_req_id = 0 then
7653 
7654                     retcode := 1;
7655                     errbuf:= 'WSMPLBJI. Inventory worker returned failure '||
7656                              '(Transaction_header_id=' ||txn_header_id||') : '|| SUBSTRB(SQLERRM,1,1000);
7657                     fnd_file.put_line(fnd_file.log,errbuf);
7658                     conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7659                     update  wsm_lot_job_interface
7660                     set     process_status = 4,
7661                             error_code = -2,
7662                             error_msg = l_error_msg
7663                     where   mode_flag = 2;
7664 
7665                 else -- req_id <> 0
7666 
7667                     fnd_file.put_line(fnd_file.log,'Inventory Transaction Worker request_id is '
7668                             ||to_char(l_inv_worker_req_id));
7669                     req_wait := FND_CONCURRENT.WAIT_FOR_REQUEST
7670                             (request_id => l_inv_worker_req_id,
7671                              interval => 10, -- 10 seconds interval
7672                              max_wait => 36000, -- 10 Hours maximum wait.
7673                              phase => req_phase,
7674                              status => req_status,
7675                              dev_phase => req_devphase,
7676                              dev_status => req_devstatus,
7677                              message => req_message);
7678 
7679                     fnd_file.put_line(fnd_file.log, 'Inventory Transaction Worker status is '
7680                                                                                             ||req_status);
7681                     fnd_file.put_line(fnd_file.log, 'Inventory Transaction Worker Completion Message: '
7682                                                                                             ||req_message);
7683 
7684                     if  req_devphase <> 'COMPLETE' OR  req_devstatus <> 'NORMAL' THEN
7685                         retcode := 1;
7686                         errbuf:= 'WSMPLBJI. Inventory worker returned failure '||
7687                                  '(Transaction_header_id=' ||txn_header_id||') : '||
7688                                  SUBSTRB(SQLERRM,1,1000);
7689                         fnd_file.put_line(fnd_file.log,errbuf);
7690                         conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7691                     end if;
7692 
7693                     check_errored_mmtt_records(txn_header_id, l_error_code, l_error_msg);
7694 
7695                     if (l_error_code <> 0) or (l_error_msg is not null ) then
7696                         retcode := 1;
7697                         errbuf:= 'WSMPLBJI. Errored Records in mmtt ' ||
7698                                  '(Transaction_header_id=' ||txn_header_id||') : '|| SUBSTRB(SQLERRM,1,1000);
7699                         fnd_file.put_line(fnd_file.log,errbuf);
7700                         conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7701                     end if;
7702 
7703                 end if;  -- req_id
7704             end if; -- l_atleast_one_row_in_mmtt
7705 
7706 
7707             -- *** delete marked rows (without error rows) from wlji ***
7708             Begin
7709                 -- bug 3126758
7710                 l_del_int_prof_value := fnd_profile.value('WSM_INTERFACE_HISTORY_DAYS');
7711 
7712                 if l_atleast_one_row_in_mmtt <> 0 then
7713                     delete  from wsm_starting_lots_interface
7714                     where   header_id IN
7715                             (select wlji.source_line_id
7716                             from    wsm_lot_job_interface wlji
7717                             where   wlji.process_status = 5
7718                             --and     wlji.group_id = batch_group_id
7719                             and     NVL(transaction_date, creation_date)
7720                                         <= decode(l_del_int_prof_value,
7721                                                   null,
7722                                                   NVL(transaction_date, creation_date) -1,
7723                                                   SYSDATE-l_del_int_prof_value)
7724                             );
7725 
7726                     if lbji_debug = 'Y' then
7727                         fnd_file.put_line(fnd_file.log, 'Deleted '||SQL%ROWCOUNT||' rows from wsli');
7728                     end if;
7729                 end if;
7730 
7731                 delete  from wsm_lot_job_interface
7732                 where   process_status = 5
7733                 --and     group_id = batch_group_id
7734                 and     NVL(transaction_date, creation_date)
7735                             <= decode(l_del_int_prof_value,
7736                                       null,
7737                                       NVL(transaction_date, creation_date) -1,
7738                                       SYSDATE-l_del_int_prof_value);
7739 
7740                 if lbji_debug = 'Y' then
7741                     fnd_file.put_line(fnd_file.log, 'Deleted '||SQL%ROWCOUNT||' rows from wlji');
7742                 end if;
7743 
7744             Exception
7745                 when others then
7746                     retcode := 1;
7747                     errbuf := 'Deletion of successful rows from interface table(s) failed';
7748                     fnd_file.put_line(fnd_file.log,errbuf);
7749                     conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING',errbuf);
7750             End;
7751 
7752             commit;
7753 
7754         end if; -- if c_wlji_1%rowcount - prev_rowcount <> 0 then process data
7755 
7756         prev_rowcount := c_wlji_1%rowcount;
7757         exit when c_wlji_1%rowcount = alotted_rows;
7758 
7759     end loop; -- main loop
7760     close c_wlji_1;
7761 
7762     -- osp begin
7763     if l_atleast_one_osp_exists <> 0 then
7764         l_req_request_id := fnd_request.submit_request(
7765                 'PO', 'REQIMPORT', NULL, NULL, FALSE,'WIP', NULL, 'ITEM',
7766                 NULL ,'N', 'Y' , chr(0), 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                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7771                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7772                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7773                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7774                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
7775                 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
7776         ) ;
7777 
7778         fnd_file.put_line(fnd_file.log,'Concurrent Request for Requisition Inport Submitted');
7779         fnd_file.put_line(fnd_file.log,'Request_id: '||l_req_request_id);
7780     end if;
7781     -- osp end
7782 
7783     -- phantom project
7784     delete from bom_explosion_temp where group_id = wsmpwrot.explosion_group_id;
7785     wsmpwrot.explosion_group_id := null;
7786     wsmpwrot.use_phantom_routings := null;
7787 
7788     commit;
7789 
7790     if l_error_count = 0 then
7791         retcode := 0;
7792         errbuf := '';
7793         conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('SUCCESS',errbuf);
7794     end if;
7795 
7796 
7797 EXCEPTION  -- for launch_worker
7798     when abort_request 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     when others then
7805         rollback to back_to_square_one;
7806         retcode := 2;
7807         errbuf := 'WSMLBJIB.launch_worker_1159: stmt num= '||l_stmt_num||' '||SUBSTR(SQLERRM, 1,240);
7808         fnd_file.put_line(fnd_file.log,errbuf);
7809         conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR',errbuf);
7810 
7811 END launch_worker_1159;
7812 
7813 END WSMPLBJI;