1030: l_rpt_to_date:=TRUNC(FND_DATE.canonical_to_date(p_rpt_to_date)) + (86399/86400);
1031:
1032:
1033: -- Open Corsor for processing
1034: v_CursorID := DBMS_SQL.OPEN_CURSOR;
1035:
1036: --Bug # 4912772 Performance issue in the dynamic query resolved by restructuring the query
1037:
1038: v_select_clause:=NULL;
1133:
1134: v_final_query := v_select_clause || v_from_clause || v_where_clause || v_order_by;
1135:
1136: --Parse the query
1137: DBMS_SQL.PARSE(v_cursorID, v_final_query, DBMS_SQL.V7);
1138:
1139: -- Not needed as temporary table
1140: -- DELETE FROM CST_MGD_MSTR_BOOK_TEMP;
1141:
1139: -- Not needed as temporary table
1140: -- DELETE FROM CST_MGD_MSTR_BOOK_TEMP;
1141:
1142: --bind the input variables
1143: DBMS_SQL.BIND_VARIABLE(v_cursorID,':org_id',p_org_id);
1144: DBMS_SQL.BIND_VARIABLE(v_cursorID,':to_date',l_rpt_to_date);
1145: DBMS_SQL.BIND_VARIABLE(v_cursorID,':from_date',l_rpt_from_date);
1146:
1147: --for selection of items in a subinventory
1140: -- DELETE FROM CST_MGD_MSTR_BOOK_TEMP;
1141:
1142: --bind the input variables
1143: DBMS_SQL.BIND_VARIABLE(v_cursorID,':org_id',p_org_id);
1144: DBMS_SQL.BIND_VARIABLE(v_cursorID,':to_date',l_rpt_to_date);
1145: DBMS_SQL.BIND_VARIABLE(v_cursorID,':from_date',l_rpt_from_date);
1146:
1147: --for selection of items in a subinventory
1148: if p_subinv_from is not null then
1141:
1142: --bind the input variables
1143: DBMS_SQL.BIND_VARIABLE(v_cursorID,':org_id',p_org_id);
1144: DBMS_SQL.BIND_VARIABLE(v_cursorID,':to_date',l_rpt_to_date);
1145: DBMS_SQL.BIND_VARIABLE(v_cursorID,':from_date',l_rpt_from_date);
1146:
1147: --for selection of items in a subinventory
1148: if p_subinv_from is not null then
1149: DBMS_SQL.BIND_VARIABLE(v_cursorID,':subinv_from',p_subinv_from);
1145: DBMS_SQL.BIND_VARIABLE(v_cursorID,':from_date',l_rpt_from_date);
1146:
1147: --for selection of items in a subinventory
1148: if p_subinv_from is not null then
1149: DBMS_SQL.BIND_VARIABLE(v_cursorID,':subinv_from',p_subinv_from);
1150: subinv_from := p_subinv_from;
1151: else if p_subinv_to is not null then
1152: DBMS_SQL.BIND_VARIABLE(v_cursorID,':subinv_from',subinv_min);
1153: subinv_from := subinv_min;
1148: if p_subinv_from is not null then
1149: DBMS_SQL.BIND_VARIABLE(v_cursorID,':subinv_from',p_subinv_from);
1150: subinv_from := p_subinv_from;
1151: else if p_subinv_to is not null then
1152: DBMS_SQL.BIND_VARIABLE(v_cursorID,':subinv_from',subinv_min);
1153: subinv_from := subinv_min;
1154: end if;
1155: end if;
1156:
1154: end if;
1155: end if;
1156:
1157: if p_subinv_to is not null then
1158: DBMS_SQL.BIND_VARIABLE(v_cursorID,':subinv_to',p_subinv_to);
1159: subinv_to := p_subinv_to;
1160: else if p_subinv_from is not null then
1161: DBMS_SQL.BIND_VARIABLE(v_cursorID,':subinv_to',subinv_max);
1162: subinv_to := subinv_max;
1157: if p_subinv_to is not null then
1158: DBMS_SQL.BIND_VARIABLE(v_cursorID,':subinv_to',p_subinv_to);
1159: subinv_to := p_subinv_to;
1160: else if p_subinv_from is not null then
1161: DBMS_SQL.BIND_VARIABLE(v_cursorID,':subinv_to',subinv_max);
1162: subinv_to := subinv_max;
1163: end if;
1164: end if;
1165:
1165:
1166: --for selection of items in a category
1167: if p_category_from is NOT NULL and p_category_to is NOT NULL and p_category_set_id is NOT NULL
1168: then
1169: DBMS_SQL.BIND_VARIABLE(v_cursorID,':category_from',p_category_from);
1170: DBMS_SQL.BIND_VARIABLE(v_cursorID,':category_to',p_category_to);
1171: DBMS_SQL.BIND_VARIABLE(v_cursorID,':category_set_id',p_category_set_id);
1172: end if;
1173:
1166: --for selection of items in a category
1167: if p_category_from is NOT NULL and p_category_to is NOT NULL and p_category_set_id is NOT NULL
1168: then
1169: DBMS_SQL.BIND_VARIABLE(v_cursorID,':category_from',p_category_from);
1170: DBMS_SQL.BIND_VARIABLE(v_cursorID,':category_to',p_category_to);
1171: DBMS_SQL.BIND_VARIABLE(v_cursorID,':category_set_id',p_category_set_id);
1172: end if;
1173:
1174:
1167: if p_category_from is NOT NULL and p_category_to is NOT NULL and p_category_set_id is NOT NULL
1168: then
1169: DBMS_SQL.BIND_VARIABLE(v_cursorID,':category_from',p_category_from);
1170: DBMS_SQL.BIND_VARIABLE(v_cursorID,':category_to',p_category_to);
1171: DBMS_SQL.BIND_VARIABLE(v_cursorID,':category_set_id',p_category_set_id);
1172: end if;
1173:
1174:
1175: --for selection of items in a abc_class
1173:
1174:
1175: --for selection of items in a abc_class
1176: if p_abc_class_id is NOT NULL then
1177: DBMS_SQL.BIND_VARIABLE(v_cursorID,':abc_class_id',p_abc_class_id);
1178: end if;
1179:
1180: if p_abc_group_id is NOT NULL then
1181: DBMS_SQL.BIND_VARIABLE(v_cursorID,':abc_group_id',p_abc_group_id);
1177: DBMS_SQL.BIND_VARIABLE(v_cursorID,':abc_class_id',p_abc_class_id);
1178: end if;
1179:
1180: if p_abc_group_id is NOT NULL then
1181: DBMS_SQL.BIND_VARIABLE(v_cursorID,':abc_group_id',p_abc_group_id);
1182: end if;
1183:
1184: if p_item_from_code is NOT NULL and p_item_to_code IS NOT NULL then
1185: DBMS_SQL.BIND_VARIABLE(v_cursorID,':item_from_code',p_item_from_code);
1181: DBMS_SQL.BIND_VARIABLE(v_cursorID,':abc_group_id',p_abc_group_id);
1182: end if;
1183:
1184: if p_item_from_code is NOT NULL and p_item_to_code IS NOT NULL then
1185: DBMS_SQL.BIND_VARIABLE(v_cursorID,':item_from_code',p_item_from_code);
1186: DBMS_SQL.BIND_VARIABLE(v_cursorID,':item_to_code',p_item_to_code);
1187: end if;
1188:
1189: --define the output variables
1182: end if;
1183:
1184: if p_item_from_code is NOT NULL and p_item_to_code IS NOT NULL then
1185: DBMS_SQL.BIND_VARIABLE(v_cursorID,':item_from_code',p_item_from_code);
1186: DBMS_SQL.BIND_VARIABLE(v_cursorID,':item_to_code',p_item_to_code);
1187: end if;
1188:
1189: --define the output variables
1190: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 1, l_item_id);
1186: DBMS_SQL.BIND_VARIABLE(v_cursorID,':item_to_code',p_item_to_code);
1187: end if;
1188:
1189: --define the output variables
1190: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 1, l_item_id);
1191: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 2, l_uom_code,3);
1192: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 3, d_item_code,40);
1193: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 4, d_item_desc,240);
1194: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 5, d_org_name,240);
1187: end if;
1188:
1189: --define the output variables
1190: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 1, l_item_id);
1191: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 2, l_uom_code,3);
1192: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 3, d_item_code,40);
1193: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 4, d_item_desc,240);
1194: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 5, d_org_name,240);
1195: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 6, d_currency_code,15);
1188:
1189: --define the output variables
1190: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 1, l_item_id);
1191: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 2, l_uom_code,3);
1192: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 3, d_item_code,40);
1193: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 4, d_item_desc,240);
1194: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 5, d_org_name,240);
1195: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 6, d_currency_code,15);
1196:
1189: --define the output variables
1190: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 1, l_item_id);
1191: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 2, l_uom_code,3);
1192: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 3, d_item_code,40);
1193: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 4, d_item_desc,240);
1194: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 5, d_org_name,240);
1195: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 6, d_currency_code,15);
1196:
1197: --execute the sql statement we don't care about the return value
1190: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 1, l_item_id);
1191: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 2, l_uom_code,3);
1192: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 3, d_item_code,40);
1193: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 4, d_item_desc,240);
1194: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 5, d_org_name,240);
1195: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 6, d_currency_code,15);
1196:
1197: --execute the sql statement we don't care about the return value
1198: v_dummy := DBMS_SQL.EXECUTE(v_cursorID);
1191: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 2, l_uom_code,3);
1192: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 3, d_item_code,40);
1193: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 4, d_item_desc,240);
1194: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 5, d_org_name,240);
1195: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 6, d_currency_code,15);
1196:
1197: --execute the sql statement we don't care about the return value
1198: v_dummy := DBMS_SQL.EXECUTE(v_cursorID);
1199:
1194: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 5, d_org_name,240);
1195: DBMS_SQL.DEFINE_COLUMN(v_cursorID, 6, d_currency_code,15);
1196:
1197: --execute the sql statement we don't care about the return value
1198: v_dummy := DBMS_SQL.EXECUTE(v_cursorID);
1199:
1200:
1201: -- Not needed as the On Hand Qty Does not rely on the MTL_PER_CLOSE_DTLS table
1202: -- Get_Acct_Period_ID_invmbk
1219: LOOP
1220:
1221: -- fetch the rows and also check for exit condition
1222:
1223: IF DBMS_SQL.FETCH_ROWS(v_cursorID) = 0 THEN
1224: EXIT;
1225: END IF;
1226:
1227: --retrieve the rows from the buffer into PL/SQL variables
1224: EXIT;
1225: END IF;
1226:
1227: --retrieve the rows from the buffer into PL/SQL variables
1228: DBMS_SQL.COLUMN_VALUE(v_cursorID,1,l_item_id);
1229: DBMS_SQL.COLUMN_VALUE(v_cursorID,2,l_uom_code);
1230: DBMS_SQL.COLUMN_VALUE(v_cursorID,3,d_item_code);
1231: DBMS_SQL.COLUMN_VALUE(v_cursorID,4,d_item_desc);
1232: DBMS_SQL.COLUMN_VALUE(v_cursorID,5,d_org_name);
1225: END IF;
1226:
1227: --retrieve the rows from the buffer into PL/SQL variables
1228: DBMS_SQL.COLUMN_VALUE(v_cursorID,1,l_item_id);
1229: DBMS_SQL.COLUMN_VALUE(v_cursorID,2,l_uom_code);
1230: DBMS_SQL.COLUMN_VALUE(v_cursorID,3,d_item_code);
1231: DBMS_SQL.COLUMN_VALUE(v_cursorID,4,d_item_desc);
1232: DBMS_SQL.COLUMN_VALUE(v_cursorID,5,d_org_name);
1233: DBMS_SQL.COLUMN_VALUE(v_cursorID,6,d_currency_code);
1226:
1227: --retrieve the rows from the buffer into PL/SQL variables
1228: DBMS_SQL.COLUMN_VALUE(v_cursorID,1,l_item_id);
1229: DBMS_SQL.COLUMN_VALUE(v_cursorID,2,l_uom_code);
1230: DBMS_SQL.COLUMN_VALUE(v_cursorID,3,d_item_code);
1231: DBMS_SQL.COLUMN_VALUE(v_cursorID,4,d_item_desc);
1232: DBMS_SQL.COLUMN_VALUE(v_cursorID,5,d_org_name);
1233: DBMS_SQL.COLUMN_VALUE(v_cursorID,6,d_currency_code);
1234:
1227: --retrieve the rows from the buffer into PL/SQL variables
1228: DBMS_SQL.COLUMN_VALUE(v_cursorID,1,l_item_id);
1229: DBMS_SQL.COLUMN_VALUE(v_cursorID,2,l_uom_code);
1230: DBMS_SQL.COLUMN_VALUE(v_cursorID,3,d_item_code);
1231: DBMS_SQL.COLUMN_VALUE(v_cursorID,4,d_item_desc);
1232: DBMS_SQL.COLUMN_VALUE(v_cursorID,5,d_org_name);
1233: DBMS_SQL.COLUMN_VALUE(v_cursorID,6,d_currency_code);
1234:
1235: -- First re initialize local var
1228: DBMS_SQL.COLUMN_VALUE(v_cursorID,1,l_item_id);
1229: DBMS_SQL.COLUMN_VALUE(v_cursorID,2,l_uom_code);
1230: DBMS_SQL.COLUMN_VALUE(v_cursorID,3,d_item_code);
1231: DBMS_SQL.COLUMN_VALUE(v_cursorID,4,d_item_desc);
1232: DBMS_SQL.COLUMN_VALUE(v_cursorID,5,d_org_name);
1233: DBMS_SQL.COLUMN_VALUE(v_cursorID,6,d_currency_code);
1234:
1235: -- First re initialize local var
1236: l_item_ohq := 0 ;
1229: DBMS_SQL.COLUMN_VALUE(v_cursorID,2,l_uom_code);
1230: DBMS_SQL.COLUMN_VALUE(v_cursorID,3,d_item_code);
1231: DBMS_SQL.COLUMN_VALUE(v_cursorID,4,d_item_desc);
1232: DBMS_SQL.COLUMN_VALUE(v_cursorID,5,d_org_name);
1233: DBMS_SQL.COLUMN_VALUE(v_cursorID,6,d_currency_code);
1234:
1235: -- First re initialize local var
1236: l_item_ohq := 0 ;
1237: l_item_trx_qty := 0;