How to improve Performace of this data.
Hi All,
We have ticket_master table with 200,000 currently and grows 2000 records per day. structure is
ticket_no VARCHAR2(20) PK,
trip_id VARCHAR2(20) RK refers to trip_master(trip_id),
passenger_name,fare,boarding etc...
second table is Ticket_cancellations currently 5000 records and daily it gets 50 records minimum.
Ticket_no RK references to TIcket_master(ticket_no),
cancellation_charges.... etc.
like if we need to see list of passengers for any trip we are querying like this
SELECT ticket_no,name_of_the_passenger.. FROM ticket_master WHERE ticket_no NOT IN (SELECT Ticket_no FROM ticket_cancellations) WHERE trip_id = my_trip_id;
it seems the performance is getting reduced with the growing size of both tables.
Is there any way we can improve this performace. we have indexes created on both tables.
Thanks in advance
I agree.
SELECT ticket_no,name_of_the_passenger..
FROM ticket_master
WHERE ticket_no NOT IN
(SELECT Ticket_no
FROM ticket_cancellations
WHERE trip_id = my_trip_id);
This involves creating a little temp table for each record in ticket_no. Then full scanning it.
Change it to
SELECT ticket_no,name_of_the_passenger..
FROM ticket_master B
WHERE ticket_no NOT EXISTS
(SELECT null
FROM ticket_cancellations A
WHERE A.ticket_no = B.ticket_no
AND trip_id = my_trip_id);
Then you get an index hit in both cases.
Similar Messages
-
How to improve performace for this program
Hi,
I want to improve performance for this program.Pls help me.Here is the code.
Thanks
kumar
--# SCCS: @(#)nscdprpt_rpt_fam_fweq_detail_aggr_dml.sql 2.1 08/17/05 12:16:11
--# Location: /appl/dpdm/src/sql/SCCS/s.nscdprpt_rpt_fam_fweq_detail_aggr_dml.sql
-- =============================================================================
-- Purpose:
-- DML Script to calculate aggregate rows from table NSCDPRPT.RPT_FAM_FWEQ_DETAIL
-- inserts one (1) monthly total row for each comparison type (6 of them)
-- Modification History
-- Date Version Who What
-- 28-Jun-05 V1.00 J. Myers Initial Version
-- 17-Aug-05 gzuerc Replaced UNION ALL code with INSERT's to avoid
-- Oracle error out of undo tablespace.
-- ============================================================================
-- NOTES:
-- This process pulls data from RPT_FAM_FWEQ_DETAIL table.
-- The target table RPT_FAM_FWEQ_DETAIL_AGGR is truncated by plan_ctry and loaded daily;
-- it is the data used in the Forecast Accuracy Measurements Report.
-- The input data is 'wide' (6 quantities), and this script outputs a single
-- row for each quantity as a 'thin' table (single column F1_QTY and F2_QTY shared by all quantities), and
-- with a ROW_TYPE = 'TOTAL'
-- Two (2) other scripts add additional rows to this table as follows:
-- 1) nscdprpt_rpt_fam_FWEQ_detail_aggr_sesn_avg_dml.sql => calculates the
-- total quantities F1_QTY, F2_QTY and AE for each LEVEL_VALUE
-- 2) nscdprpt_rpt_fam_FWEQ_detail_aggr_pct_swg_dml.sql => calculates the
-- percent swing in quantities between DISP_EVENTS for each grouping
-- of PLAN_CTRY, DIVISION, SEASON and TRG_EVENT_NUM for only LEVEL_TYPE = 'SUB_CAT'
-- =============================================================================
-- The result set from joining RPT_FAM_FWEQ_DETAIL rows with comparison types
-- is inserted into the table RPT_FAM_FWEQ_DETAIL_AGGR
INSERT INTO rpt_fam_FWEQ_detail_aggr
SELECT plan_ctry,
division,
season,
monthly_seq,
bucket_month_date,
tier_num,
level_num,
tier_volume,
trg_event_num,
disp_event_num,
max_event_num,
compare_name,
first_display_event_num,
level_type,
level_value,
'TOTAL' AS row_type,
material,
key_material,
sap_cat_cd,
sap_cat_desc,
sap_sub_cat_cd,
sap_sub_cat_desc,
sty_colr_sdesc,
sty_grp_nbr,
sty_grp_desc,
matl_typ,
sap_prod_typ_grp, -- 'Type Group' in Brio
typ_grp_desc, -- 'Type Group' in Brio
curr_prod_i2_life_cyc_cd,
NULL AS promo_ind, -- for future use
-- Each RPT_FAM_FWEQ_DETAIL row's eight (8) quantity columns are broken down
-- into F1_QTY from DISP_aaaa_QTY, F2_QTY from TRG_aaaa_QTY and
-- AE from aaaa_AE where 'aaaa' is equal to one of the COMPARE_TYPEs below:
-- F1_QTY
CASE WHEN compare_type = 'DELIVERY_PLAN' THEN
disp_dlvry_plan_qty
WHEN compare_type = 'NET' THEN
disp_net_qty
WHEN compare_type = 'NET_AO' THEN
disp_ao_qty
WHEN compare_type = 'NET_FTRS' THEN
disp_futr_qty
WHEN compare_type = 'NET_REPLENS' THEN
disp_replen_qty
WHEN compare_type = 'AUTH_FTRS' THEN
disp_auth_futr_qty
END as f1_qty,
-- F2_QTY
CASE WHEN compare_type = 'DELIVERY_PLAN' THEN
trg_dlvry_plan_qty
WHEN compare_type = 'NET' THEN
trg_net_qty
WHEN compare_type = 'NET_AO' THEN
trg_ao_qty
WHEN compare_type = 'NET_FTRS' THEN
trg_futr_qty
WHEN compare_type = 'NET_REPLENS' THEN
trg_replen_qty
WHEN compare_type = 'AUTH_FTRS' THEN
trg_auth_futures_qty
END as f2_qty,
-- AE
CASE WHEN compare_type = 'DELIVERY_PLAN' THEN
abs(disp_dlvry_plan_qty - trg_dlvry_plan_qty)
WHEN compare_type = 'NET' THEN
abs(disp_net_qty - trg_net_qty)
WHEN compare_type = 'NET_AO' THEN
abs(disp_ao_qty - trg_ao_qty)
WHEN compare_type = 'NET_FTRS' THEN
abs(disp_futr_qty - trg_futr_qty)
WHEN compare_type = 'NET_REPLENS' THEN
abs(disp_replen_qty - trg_replen_qty)
WHEN compare_type = 'AUTH_FTRS' THEN
abs(disp_auth_futr_qty - trg_auth_futures_qty)
END as ae,
SYSDATE AS zz_insert_tmst
FROM
-- The following in-line view provides three (3) result sets from the RPT_FAM_FWEQ_DETAIL table
-- This in-line view returns only LEVEL_NUM = 1 or LEVEL_TYPE = 'SUB_CAT' data
SELECT plan_ctry,
division,
season,
monthly_seq,
bucket_month_date,
tier_num,
level_num,
tier_volume,
trg_event_num,
trg_event_type,
disp_event_num,
max_event_num,
first_display_event_num,
level_type,
level_value,
-- The following NULL'd columns' values cannot be saved due to aggregation
NULL AS material,
NULL AS key_material,
sap_cat_cd,
sap_cat_desc,
sap_sub_cat_cd,
sap_sub_cat_desc,
NULL AS sty_colr_sdesc,
NULL AS sty_grp_nbr,
NULL AS sty_grp_desc,
NULL AS matl_typ,
sap_prod_typ_grp, -- 'Type Group' in Brio
typ_grp_desc, -- 'Type Group' in Brio
NULL AS curr_prod_i2_life_cyc_cd,
sum(disp_net_qty) AS disp_net_qty,
sum(trg_net_qty) AS trg_net_qty,
-- ABS(sum(trg_net_qty) - sum(disp_net_qty)) AS net_AE,
sum(disp_dlvry_plan_qty) AS disp_dlvry_plan_qty,
sum(trg_dlvry_plan_qty) AS trg_dlvry_plan_qty,
-- ABS(sum(trg_dlvry_plan_qty) - sum(disp_dlvry_plan_qty)) AS dlvry_plan_AE,
sum(disp_futr_qty) AS disp_futr_qty,
sum(trg_futr_qty) AS trg_futr_qty,
-- ABS(sum(trg_futr_qty) - sum(disp_futr_qty)) AS futr_AE,
sum(disp_ao_qty) AS disp_ao_qty,
sum(trg_ao_qty) AS trg_ao_qty,
-- ABS(sum(trg_ao_qty) - sum(disp_ao_qty)) AS ao_AE,
sum(disp_replen_qty) AS disp_replen_qty,
sum(trg_replen_qty) AS trg_replen_qty,
-- ABS(sum(trg_replen_qty) - sum(disp_replen_qty)) AS replen_AE,
sum(disp_futr_qty) AS disp_auth_futr_qty,
sum(trg_auth_futures_qty) AS trg_auth_futures_qty --,
-- ABS(sum(trg_auth_futures_qty) - sum(disp_futr_qty)) AS auth_futures_AE
FROM rpt_fam_FWEQ_detail
WHERE plan_ctry &where_plan_ctry
and level_num = 1 -- 'SUB-CAT'
-- AND (promo_ind <> 'Y' OR promo_ind IS null)
GROUP BY plan_ctry,
division,
season,
monthly_seq,
bucket_month_date,
tier_num,
level_num,
tier_volume,
trg_event_num,
trg_event_type,
disp_event_num,
max_event_num,
first_display_event_num,
level_type,
level_value,
sap_cat_cd,
sap_cat_desc,
sap_sub_cat_cd,
sap_sub_cat_desc,
sap_prod_typ_grp, -- 'Type Group' in Brio
typ_grp_desc -- 'Type Group' in Brio
) dtl,
-- The following in-line view returns all of the different combinations
-- of comparison types in the RPT_FAM_FWEQ_DETAIL table
-- This select returns the pairing of all forecast types
SELECT event_type, compare_type, compare_name
from
(SELECT event_type, compare_type, compare_type_description || ' to ' || compare_type_description AS compare_name
FROM rpt_fam_compare_types
WHERE event_type = 'FCST'
UNION
-- This select returns the pairing of all bookings types with forecast types
SELECT bkng.event_type, fcst.compare_type, bkng.compare_type_description || ' to ' || fcst.compare_type_description AS compare_name
FROM rpt_fam_compare_types fcst,
rpt_fam_compare_types bkng
WHERE fcst.event_type = 'FCST'
AND bkng.event_type = 'BKNG'
AND fcst.compare_type = bkng.compare_type
WHERE event_type || ' ' || compare_type <> 'FCST AUTH_FTRS'
AND compare_type NOT IN ('NET_SHIP', 'SHIP_NET_FTRS', 'NET_ETS', 'GROSS_FTRS')
) cmpr
-- The two (2) in-line views are joined by EVENT_TYPE (i.e. 'FCST' and 'BKNG')
-- to form a product of all RPT_FAM_FWEQ_DETAIL rows with comparison types
WHERE dtl.trg_event_type = cmpr.event_type
ORDER BY plan_ctry,
division,
season,
monthly_seq,
tier_num,
level_num,
tier_volume,
trg_event_num,
disp_event_num,
max_event_num,
first_display_event_num,
level_type,
level_value
COMMIT
INSERT INTO rpt_fam_FWEQ_detail_aggr
SELECT plan_ctry,
division,
season,
monthly_seq,
bucket_month_date,
tier_num,
level_num,
tier_volume,
trg_event_num,
disp_event_num,
max_event_num,
compare_name,
first_display_event_num,
level_type,
level_value,
'TOTAL' AS row_type,
material,
key_material,
sap_cat_cd,
sap_cat_desc,
sap_sub_cat_cd,
sap_sub_cat_desc,
sty_colr_sdesc,
sty_grp_nbr,
sty_grp_desc,
matl_typ,
sap_prod_typ_grp, -- 'Type Group' in Brio
typ_grp_desc, -- 'Type Group' in Brio
curr_prod_i2_life_cyc_cd,
NULL AS promo_ind, -- for future use
-- Each RPT_FAM_FWEQ_DETAIL row's eight (8) quantity columns are broken down
-- into F1_QTY from DISP_aaaa_QTY, F2_QTY from TRG_aaaa_QTY and
-- AE from aaaa_AE where 'aaaa' is equal to one of the COMPARE_TYPEs below:
-- F1_QTY
CASE WHEN compare_type = 'DELIVERY_PLAN' THEN
disp_dlvry_plan_qty
WHEN compare_type = 'NET' THEN
disp_net_qty
WHEN compare_type = 'NET_AO' THEN
disp_ao_qty
WHEN compare_type = 'NET_FTRS' THEN
disp_futr_qty
WHEN compare_type = 'NET_REPLENS' THEN
disp_replen_qty
WHEN compare_type = 'AUTH_FTRS' THEN
disp_auth_futr_qty
END as f1_qty,
-- F2_QTY
CASE WHEN compare_type = 'DELIVERY_PLAN' THEN
trg_dlvry_plan_qty
WHEN compare_type = 'NET' THEN
trg_net_qty
WHEN compare_type = 'NET_AO' THEN
trg_ao_qty
WHEN compare_type = 'NET_FTRS' THEN
trg_futr_qty
WHEN compare_type = 'NET_REPLENS' THEN
trg_replen_qty
WHEN compare_type = 'AUTH_FTRS' THEN
trg_auth_futures_qty
END as f2_qty,
-- AE
CASE WHEN compare_type = 'DELIVERY_PLAN' THEN
abs(disp_dlvry_plan_qty - trg_dlvry_plan_qty)
WHEN compare_type = 'NET' THEN
abs(disp_net_qty - trg_net_qty)
WHEN compare_type = 'NET_AO' THEN
abs(disp_ao_qty - trg_ao_qty)
WHEN compare_type = 'NET_FTRS' THEN
abs(disp_futr_qty - trg_futr_qty)
WHEN compare_type = 'NET_REPLENS' THEN
abs(disp_replen_qty - trg_replen_qty)
WHEN compare_type = 'AUTH_FTRS' THEN
abs(disp_auth_futr_qty - trg_auth_futures_qty)
END as ae,
SYSDATE AS zz_insert_tmst
FROM
-- This in-line view returns only LEVEL_NUM = 2 or LEVEL_TYPE = 'STYLE_GROUP' data
(SELECT plan_ctry,
division,
season,
monthly_seq,
bucket_month_date,
tier_num,
level_num,
tier_volume,
trg_event_num,
trg_event_type,
disp_event_num,
max_event_num,
first_display_event_num,
level_type,
level_value,
-- The following NULL'd columns' values cannot be saved due to aggregation
NULL AS material,
NULL AS key_material,
sap_cat_cd,
sap_cat_desc,
sap_sub_cat_cd,
sap_sub_cat_desc,
NULL AS sty_colr_sdesc,
sty_grp_nbr,
sty_grp_desc,
NULL AS matl_typ,
sap_prod_typ_grp, -- 'Type Group' in Brio
typ_grp_desc, -- 'Type Group' in Brio
NULL AS curr_prod_i2_life_cyc_cd,
sum(disp_net_qty) AS disp_net_qty,
sum(trg_net_qty) AS trg_net_qty,
-- ABS(sum(trg_net_qty) - sum(disp_net_qty)) AS net_AE,
sum(disp_dlvry_plan_qty) AS disp_dlvry_plan_qty,
sum(trg_dlvry_plan_qty) AS trg_dlvry_plan_qty,
-- ABS(sum(trg_dlvry_plan_qty) - sum(disp_dlvry_plan_qty)) AS dlvry_plan_AE,
sum(disp_futr_qty) AS disp_futr_qty,
sum(trg_futr_qty) AS trg_futr_qty,
-- ABS(sum(trg_futr_qty) - sum(disp_futr_qty)) AS futr_AE,
sum(disp_ao_qty) AS disp_ao_qty,
sum(trg_ao_qty) AS trg_ao_qty,
-- ABS(sum(trg_ao_qty) - sum(disp_ao_qty)) AS ao_AE,
sum(disp_replen_qty) AS disp_replen_qty,
sum(trg_replen_qty) AS trg_replen_qty,
-- ABS(sum(trg_replen_qty) - sum(disp_replen_qty)) AS replen_AE,
sum(disp_futr_qty) AS disp_auth_futr_qty,
sum(trg_auth_futures_qty) AS trg_auth_futures_qty --,
-- ABS(sum(trg_auth_futures_qty) - sum(disp_futr_qty)) AS auth_futures_AE
FROM rpt_fam_FWEQ_detail
WHERE plan_ctry &where_plan_ctry
and level_num = 2 -- 'STYLE-GRP' or 'STYLE'
-- AND (promo_ind <> 'Y' OR promo_ind IS null)
GROUP BY plan_ctry,
division,
season,
monthly_seq,
bucket_month_date,
tier_num,
level_num,
tier_volume,
trg_event_num,
trg_event_type,
disp_event_num,
max_event_num,
first_display_event_num,
level_type,
level_value,
sap_cat_cd,
sap_cat_desc,
sap_sub_cat_cd,
sap_sub_cat_desc,
sty_grp_nbr,
sty_grp_desc,
sap_prod_typ_grp, -- 'Type Group' in Brio
typ_grp_desc -- 'Type Group' in Brio
) dtl,
-- The following in-line view returns all of the different combinations
-- of comparison types in the RPT_FAM_FWEQ_DETAIL table
-- This select returns the pairing of all forecast types
SELECT event_type, compare_type, compare_name
from
(SELECT event_type, compare_type, compare_type_description || ' to ' || compare_type_description AS compare_name
FROM rpt_fam_compare_types
WHERE event_type = 'FCST'
UNION
-- This select returns the pairing of all bookings types with forecast types
SELECT bkng.event_type, fcst.compare_type, bkng.compare_type_description || ' to ' || fcst.compare_type_description AS compare_name
FROM rpt_fam_compare_types fcst,
rpt_fam_compare_types bkng
WHERE fcst.event_type = 'FCST'
AND bkng.event_type = 'BKNG'
AND fcst.compare_type = bkng.compare_type
WHERE event_type || ' ' || compare_type <> 'FCST AUTH_FTRS'
AND compare_type NOT IN ('NET_SHIP', 'SHIP_NET_FTRS', 'NET_ETS', 'GROSS_FTRS')
) cmpr
-- The two (2) in-line views are joined by EVENT_TYPE (i.e. 'FCST' and 'BKNG')
-- to form a product of all RPT_FAM_FWEQ_DETAIL rows with comparison types
WHERE dtl.trg_event_type = cmpr.event_type
ORDER BY plan_ctry,
division,
season,
monthly_seq,
tier_num,
level_num,
tier_volume,
trg_event_num,
disp_event_num,
max_event_num,
first_display_event_num,
level_type,
level_value
COMMIT
INSERT INTO rpt_fam_FWEQ_detail_aggr
SELECT plan_ctry,
division,
season,
monthly_seq,
bucket_month_date,
tier_num,
level_num,
tier_volume,
trg_event_num,
disp_event_num,
max_event_num,
compare_name,
first_display_event_num,
level_type,
level_value,
'TOTAL' AS row_type,
material,
key_material,
sap_cat_cd,
sap_cat_desc,
sap_sub_cat_cd,
sap_sub_cat_desc,
sty_colr_sdesc,
sty_grp_nbr,
sty_grp_desc,
matl_typ,
sap_prod_typ_grp, -- 'Type Group' in Brio
typ_grp_desc, -- 'Type Group' in Brio
curr_prod_i2_life_cyc_cd,
NULL AS promo_ind, -- for future use
-- Each RPT_FAM_FWEQ_DETAIL row's eight (8) quantity columns are broken down
-- into F1_QTY from DISP_aaaa_QTY, F2_QTY from TRG_aaaa_QTY and
-- AE from aaaa_AE where 'aaaa' is equal to one of the COMPARE_TYPEs below:
-- F1_QTY
CASE WHEN compare_type = 'DELIVERY_PLAN' THEN
disp_dlvry_plan_qty
WHEN compare_type = 'NET' THEN
disp_net_qty
WHEN compare_type = 'NET_AO' THEN
disp_ao_qty
WHEN compare_type = 'NET_FTRS' THEN
disp_futr_qty
WHEN compare_type = 'NET_REPLENS' THEN
disp_replen_qty
WHEN compare_type = 'AUTH_FTRS' THEN
disp_auth_futr_qty
END as f1_qty,
-- F2_QTY
CASE WHEN compare_type = 'DELIVERY_PLAN' THEN
trg_dlvry_plan_qty
WHEN compare_type = 'NET' THEN
trg_net_qty
WHEN compare_type = 'NET_AO' THEN
trg_ao_qty
WHEN compare_type = 'NET_FTRS' THEN
trg_futr_qty
WHEN compare_type = 'NET_REPLENS' THEN
trg_replen_qty
WHEN compare_type = 'AUTH_FTRS' THEN
trg_auth_futures_qty
END as f2_qty,
-- AE
CASE WHEN compare_type = 'DELIVERY_PLAN' THEN
abs(disp_dlvry_plan_qty - trg_dlvry_plan_qty)
WHEN compare_type = 'NET' THEN
abs(disp_net_qty - trg_net_qty)
WHEN compare_type = 'NET_AO' THEN
abs(disp_ao_qty - trg_ao_qty)
WHEN compare_type = 'NET_FTRS' THEN
abs(disp_futr_qty - trg_futr_qty)
WHEN compare_type = 'NET_REPLENS' THEN
abs(disp_replen_qty - trg_replen_qty)
WHEN compare_type = 'AUTH_FTRS' THEN
abs(disp_auth_futr_qty - trg_auth_futures_qty)
END as ae,
SYSDATE AS zz_insert_tmst
FROM
-- This in-line view returns only LEVEL_NUM = 3 or LEVEL_TYPE = 'MATL' data
(SELECT plan_ctry,
division,
season,
monthly_seq,
bucket_month_date,
tier_num,
level_num,
tier_volume,
trg_event_num,
trg_event_type,
disp_event_num,
max_event_num,
first_display_event_num,
level_type,
level_value,
material,
key_material,
sap_cat_cd,
sap_cat_desc,
sap_sub_cat_cd,
sap_sub_cat_desc,
sty_colr_sdesc,
sty_grp_nbr,
sty_grp_desc,
matl_typ,
sap_prod_typ_grp, -- 'Type Group' in Brio
typ_grp_desc, -- 'Type Group' in Brio
curr_prod_i2_life_cyc_cd,
sum(disp_net_qty) AS disp_net_qty,
sum(trg_net_qty) AS trg_net_qty,
-- ABS(sum(trg_net_qty) - sum(disp_net_qty)) AS net_AE,
sum(disp_dlvry_plan_qty) AS disp_dlvry_plan_qty,
sum(trg_dlvry_plan_qty) AS trg_dlvry_plan_qty,
-- ABS(sum(trg_dlvry_plan_qty) - sum(disp_dlvry_plan_qty)) AS dlvry_plan_AE,
sum(disp_futr_qty) AS disp_futr_qty,
sum(trg_futr_qty) AS trg_futr_qty,
-- ABS(sum(trg_futr_qty) - sum(disp_futr_qty)) AS futr_AE,
sum(disp_ao_qty) AS disp_ao_qty,
sum(trg_ao_qty) AS trg_ao_qty,
-- ABS(sum(trg_ao_qty) - sum(disp_ao_qty)) AS ao_AE,
sum(disp_replen_qty) AS disp_replen_qty,
sum(trg_replen_qty) AS trg_replen_qty,
-- ABS(sum(trg_replen_qty) - sum(disp_replen_qty)) AS replen_AE,
sum(disp_futr_qty) AS disp_auth_futr_qty,
sum(trg_auth_futures_qty) AS trg_auth_futures_qty --,
-- ABS(sum(trg_auth_futures_qty) - sum(disp_futr_qty)) AS auth_futures_AE
FROM rpt_fam_FWEQ_detail
WHERE plan_ctry &where_plan_ctry
and level_num = 3 -- 'MATERIAL'
-- AND promo_ind <> 'Y'
GROUP BY plan_ctry,
division,
season,
monthly_seq,
bucket_month_date,
tier_num,
level_num,
tier_volume,
trg_event_num,
trg_event_type,
disp_event_num,
max_event_num,
first_display_event_num,
level_type,
level_value,
material,
key_material,
sap_cat_cd,
sap_cat_desc,
sap_sub_cat_cd,
sap_sub_cat_desc,
sty_colr_sdesc,
sty_grp_nbr,
sty_grp_desc,
matl_typ,
sap_prod_typ_grp, -- 'Type Group' in Brio
typ_grp_desc, -- 'Type Group' in Brio
curr_prod_i2_life_cyc_cd
) dtl,
-- The following in-line view returns all of the different combinations
-- of comparison types in the RPT_FAM_FWEQ_DETAIL table
-- This select returns the pairing of all forecast types
SELECT event_type, compare_type, compare_name
from
(SELECT event_type, compare_type, compare_type_description || ' to ' || compare_type_description AS compare_name
FROM rpt_fam_compare_types
WHERE event_type = 'FCST'
UNION
-- This select returns the pairing of all bookings types with forecast types
SELECT bkng.event_type, fcst.compare_type, bkng.compare_type_description || ' to ' || fcst.compare_type_description AS compare_name
FROM rpt_fam_compare_types fcst,
rpt_fam_compare_types bkng
WHERE fcst.event_type = 'FCST'
AND bkng.event_type = 'BKNG'
AND fcst.compare_type = bkng.compare_type
WHERE event_type || ' ' || compare_type <> 'FCST AUTH_FTRS'
AND compare_type NOT IN ('NET_SHIP', 'SHIP_NET_FTRS', 'NET_ETS', 'GROSS_FTRS')
) cmpr
-- The two (2) in-line views are joined by EVENT_TYPE (i.e. 'FCST' and 'BKNG')
-- to form a product of all RPT_FAM_FWEQ_DETAIL rows with comparison types
WHERE dtl.trg_event_type = cmpr.event_type
ORDER BY plan_ctry,
division,
season,
monthly_seq,
tier_num,
level_num,
tier_volume,
trg_event_num,
disp_event_num,
max_event_num,
first_display_event_num,
level_type,
level_value
COMMIT
/I agree.
SELECT ticket_no,name_of_the_passenger..
FROM ticket_master
WHERE ticket_no NOT IN
(SELECT Ticket_no
FROM ticket_cancellations
WHERE trip_id = my_trip_id);
This involves creating a little temp table for each record in ticket_no. Then full scanning it.
Change it to
SELECT ticket_no,name_of_the_passenger..
FROM ticket_master B
WHERE ticket_no NOT EXISTS
(SELECT null
FROM ticket_cancellations A
WHERE A.ticket_no = B.ticket_no
AND trip_id = my_trip_id);
Then you get an index hit in both cases. -
Hi how to improve performence of this program
Hi all,
How to improve the performence of this program.....................
REPORT z03_gil010 NO STANDARD PAGE HEADING LINE-SIZE 130.
INCLUDE *
INCLUDE: z00_bci010. " Gestion des anomalies.
Déclaration des données *
Tables de la bases de données *
TABLES:
ekpo, " Poste document d'achat.
lfa1, " Base fournisseurs (généralités).
marc, " Données division de l'article.
z03_bw_cmp1,
eord, "Répertoire des sources appro. Achats
eina, "Fiche infos-achats - données générales
t024, "Groupes d'acheteurs
tvarv. "FAE17345+
Déclaration des données internes *
Déclaration de la table interne qui permet de recuperer les mois.
DATA: BEGIN OF itb_months OCCURS 12.
INCLUDE STRUCTURE t247.
DATA: END OF itb_months.
Table pour récupération d'infos sur les divisions
DATA: BEGIN OF itb_t001w OCCURS 0,
werks LIKE t001w-werks,
fabkl LIKE t001w-fabkl," Clé du calendrier d'entreprise
END OF itb_t001w.
Déclaration de la table interne contenant les infos sur l'adresse du
fournisseur.
DATA: BEGIN OF itb_adresse OCCURS 0,
lifnr LIKE lfa1-lifnr, " Numéro de compte fournisseur.
name1 LIKE lfa1-name1, " Nom 1.
name2 LIKE lfa1-name2, " Nom 2.
name3 LIKE lfa1-name3, " Nom 3.
name4 LIKE lfa1-name4, " Nom 4.
stras LIKE lfa1-stras, " N° de rue et nom de la rue.
pstlz LIKE lfa1-pstlz, " Code postal.
ort01 LIKE lfa1-ort01, " Localité.
pfach LIKE lfa1-pfach, " Boîte postale.
pstl2 LIKE lfa1-pstl2, " Code de la boîte postale.
land1 LIKE lfa1-land1, " Clé de pays.
landx LIKE t005t-landx, " Pays.
spras LIKE lfa1-spras, " Code langue
END OF itb_adresse.
Déclaration d'une table interne pour les informations sur les
prévisions de commande.
DATA: BEGIN OF itb_prev_cde OCCURS 0,
werks LIKE marc-werks, " Division
idnlf LIKE eina-idnlf, " ADDsde ref article frn
lifnr LIKE eord-lifnr, " N° fournisseur.
ekgrp LIKE marc-ekgrp, " Groupe d'acheteurs
dispo LIKE marc-dispo, " Code gestionnaire MRP
matnr LIKE eord-matnr, " Article.
maktx LIKE makt-maktx, " Désignation article.
bstmi LIKE marc-bstmi, " Quantité de commande.
men00 LIKE plaf-gsmng, " Quantité du mois en cours M.
men01 LIKE plaf-gsmng, " Quantité pour le mois M+1.
men02 LIKE plaf-gsmng, " Quantité pour le mois M+2.
men03 LIKE plaf-gsmng, " Quantité pour le mois M+3.
men04 LIKE plaf-gsmng, " Quantité pour le mois M+4.
men05 LIKE plaf-gsmng, " Quantité pour le mois M+5.
men06 LIKE plaf-gsmng. " Quantité pour le mois M+6.
DATA: END OF itb_prev_cde.
Structure de travail pour les commandes convernant les PFC
DATA str_pca_pfc LIKE itb_prev_cde.
*add sde
DATA str_eord_pfc LIKE itb_prev_cde.
Structure de travail pour les prévisons PFC
DATA str_prev_pfc LIKE itb_prev_cde.
Déclaration d'une table interne pour les informations sur le
portefeuille des commandes d'achat.
DATA: BEGIN OF itb_pca OCCURS 0,
werks LIKE ekpo-werks, " Division
idnlf LIKE eina-idnlf, " ADDsde ref article frn
lifnr LIKE eord-lifnr, " N° fournisseur.
ekgrp LIKE marc-ekgrp, " Groupe d'acheteurs
dispo LIKE marc-dispo, " Code gestionnaire MRP
matnr LIKE eord-matnr, " Article.
maktx LIKE makt-maktx, " Désignation article.
ebeln LIKE ekes-ebeln, " Numéro du document d'achat.
ebelp LIKE ekes-ebelp, " Numéro de poste du document d'achat.
slfdt LIKE eket-slfdt, " Date de livraison statistique
eindt LIKE ekes-eindt, " Date de livraison indiquée dans la
" confirmation de la cde.
menge LIKE ekes-menge, " Quantité indiquée dans la confirma-
" tion de la commande.
attdu LIKE eket-wemng, " Portefeuille fournisseur.
netpr LIKE ekpo-brtwr, " Prix net du document d'achat dans
" la devise du document.
rtard TYPE i, " Retard en jours ouvres.
wemng LIKE eket-wemng, " Quantité de l'entrée de marchandise.
bldat LIKE mkpf-bldat, " Date inscrite sur la pièce/sur le
" document.
qtran LIKE ekes-menge, " Quantité en transit.
dtran LIKE ekes-eindt. " Date du dernier avis de transit.
DATA: END OF itb_pca.
DATA: w_i TYPE i, "Compteur
w_i_char(1) TYPE c, "Texte pour récupérer compteur
w_nm_zone(20) TYPE c, "Nom zone pour assign au field-symbols
w_nb_j TYPE i, "Nb de jours ouvrés jusqu'à fin mois
w_nb_j_tot TYPE i. "Nb de jours ouvrés du mois
FIELD-SYMBOLS: TYPE ANY.
Déclaration d'une table contenant les fiches info achat.
DATA: BEGIN OF itb_eina OCCURS 0,
matnr LIKE eina-matnr,
lifnr LIKE eina-lifnr,
idfnl LIKE eina-idnlf.
DATA: END OF itb_eina.
Déclaration d'une table contenant les infos groupe acheteur.
*DATA: BEGIN OF itb_t024 OCCURS 0,
ekgrp LIKE t024-ekgrp,
eknam LIKE t024-eknam,
ektel LIKE t024-ektel,
telfx LIKE t024-telfx.
*DATA: END OF itb_t024.
Déclaration d'une table pour le transfert du fichier.
DATA: BEGIN OF itb_transfert OCCURS 0,
col00(8), "division
col00bis(20), "Reference article
col01(18), "No article
col02(45), "libelle article
col021(17), "Groupe acheteur
col022(13), "gestionnaire
col03(17), "qte commandée ou No de commande
col04(13), "Mois 1 ou No poste cde
col05(20), "Mois 2 ou délai initial
col06(33), "Mois 3 ou délai négocié
col07(13), "Mois 4 ou qté cdée
col08(13), "Mois 5 ou qté attendue
col09(13), "Mois 6 ou Montant attendu
col10(13), "Mois 7 ou retard
col11(13), "qte partielle livree
col12(13), "date livraison partielle
col13(13), "qté en transit
col14(13). "date
DATA: END OF itb_transfert.
Déclaration d'une table contenant la liste des fournisseurs.
DATA: BEGIN OF itb_lifnr OCCURS 0,
werks LIKE marc-werks,
idfnl LIKE eina-idnlf,
lifnr LIKE eord-lifnr,
ekgrp LIKE marc-ekgrp,
spras LIKE lfa1-spras,
eknam LIKE t024-eknam,
ektel LIKE t024-ektel,
telfx LIKE t024-telfx.
DATA: END OF itb_lifnr.
Déclaration d'une structure pour la selection dans la table MSEG.
DATA : BEGIN OF itb_mseg OCCURS 0,
mblnr LIKE mseg-mblnr,
mjahr LIKE mseg-mjahr,
ebeln LIKE mseg-ebeln,
ebelp LIKE mseg-ebelp,
END OF itb_mseg.
déclaration d'une structure pour la selection dans EKPO.
DATA : BEGIN OF itb_ekpo OCCURS 0,
lifnr LIKE ekko-lifnr,
ebeln LIKE ekpo-ebeln,
ebelp LIKE ekpo-ebelp,
menge LIKE ekpo-menge,
bpumz LIKE ekpo-bpumz,
bpumn LIKE ekpo-bpumn,
matnr LIKE ekpo-matnr,
werks LIKE ekpo-werks,
netpr LIKE ekpo-netpr,
peinh LIKE ekpo-peinh, "Base de prix FAE17345+
ekgrp LIKE ekko-ekgrp, "AFT++
dispo LIKE marc-dispo, "AFT++
END OF itb_ekpo.
déclaration d'une structure pour la selection dans EKPO.
DATA : BEGIN OF itb_ekko OCCURS 0,
ebeln LIKE ekko-ebeln,
lifnr LIKE ekko-lifnr,
spras LIKE ekko-spras,
END OF itb_ekko.
déclaration d'une structure pour la selection dans EKES.
DATA : BEGIN OF itb_ekes OCCURS 0,
ebeln LIKE eket-ebeln,
ebelp LIKE eket-ebelp,
ebtyp LIKE ekes-ebtyp,
eindt LIKE ekes-eindt,
menge LIKE ekes-menge,
dabmg LIKE ekes-dabmg,
etens LIKE ekes-etens,
END OF itb_ekes.
déclaration d'une structure pour la selection dans EKET
DATA : BEGIN OF itb_eket OCCURS 0,
ebeln LIKE eket-ebeln,
ebelp LIKE eket-ebelp,
menge LIKE eket-menge,
wemng LIKE eket-wemng,
eindt LIKE eket-eindt,
slfdt LIKE eket-slfdt,
END OF itb_eket.
déclaration d'une structure pour la selection dans MKPF.
DATA : BEGIN OF itb_mkpf OCCURS 0,
mblnr LIKE mkpf-mblnr,
mjahr LIKE mkpf-mjahr,
bldat LIKE mkpf-bldat,
END OF itb_mkpf.
Déclaration d'une structure pour la sélection dans EORD.
DATA : BEGIN OF itb_eord OCCURS 0,
matnr LIKE eord-matnr,
werks LIKE eord-werks,
lifnr LIKE eord-lifnr,
ekgrp LIKE marc-ekgrp,
dispo LIKE marc-dispo, "DE3K924352
disls LIKE marc-disls,
bstfe LIKE marc-bstfe,
bstrf LIKE marc-bstrf,
bstmi LIKE marc-bstmi,
bstma LIKE marc-bstma,
END OF itb_eord.
DATA : BEGIN OF itb_eordw OCCURS 0.
INCLUDE STRUCTURE itb_eord.
DATA : END OF itb_eordw.
Déclaration d'une structure pour la sélection dans MAKT.
DATA : BEGIN OF itb_makt OCCURS 0,
matnr LIKE makt-matnr,
spras LIKE makt-spras,
maktx LIKE makt-maktx,
END OF itb_makt.
Déclaration d'une structure pour la sélection dans EBAN.
DATA : BEGIN OF itb_eban OCCURS 0,
matnr LIKE eban-matnr,
werks LIKE eban-werks,
flief LIKE eban-flief,
lfdat LIKE eban-lfdat,
menge LIKE eban-menge,
bsmng LIKE eban-bsmng,
webaz LIKE eban-webaz,
ekgrp LIKE eban-ekgrp,
ebeln LIKE eban-ebeln,
banfn LIKE eban-banfn,
bnfpo LIKE eban-bnfpo, "DB3K900702+
END OF itb_eban.
Déclaration d'une structure pour la sélection dans PLAF.
DATA : BEGIN OF itb_plaf OCCURS 0,
plnum LIKE plaf-plnum, "DB3K900702+
matnr LIKE plaf-matnr,
plwrk LIKE plaf-plwrk,
flief LIKE plaf-flief,
pedtr LIKE plaf-pedtr,
gsmng LIKE plaf-gsmng,
webaz LIKE plaf-webaz,
END OF itb_plaf.
Déclaration d'une structure pour la sélection dans MARC.
DATA : BEGIN OF itb_marc OCCURS 0,
matnr LIKE marc-matnr,
werks LIKE marc-werks,
disls LIKE marc-disls,
bstrf LIKE marc-bstrf,
bstmi LIKE marc-bstmi,
bstma LIKE marc-bstma,
bstfe LIKE marc-bstfe,
ekgrp LIKE marc-ekgrp,
dispo LIKE marc-dispo,
END OF itb_marc.
DATA : BEGIN OF itb_marc_eord OCCURS 0,
matnr LIKE marc-matnr,
werks LIKE marc-werks,
strgr LIKE marc-strgr, "groupe de stratégie planif
END OF itb_marc_eord.
DATA : BEGIN OF itb_z03_bw_cmp1 OCCURS 0,
matnr LIKE z03_bw_cmp1-matnr,
werks LIKE z03_bw_cmp1-werks,
pdatu LIKE z03_bw_cmp1-pdatu,
plnmg LIKE z03_bw_cmp1-plnmg,
END OF itb_z03_bw_cmp1.
Begin change BNI <DE3K937051>
DATA : BEGIN OF itb_z03_bw_cmp2 OCCURS 0,
matnr LIKE z03_bw_cmp2-matnr,
werks LIKE z03_bw_cmp2-werks,
pdatu LIKE z03_bw_cmp2-pdatu,
plnmg LIKE z03_bw_cmp2-plnmg,
END OF itb_z03_bw_cmp2.
*End change BNI
DATA : BEGIN OF str_index1,
matnr LIKE eord-matnr,
werks LIKE eord-werks,
END OF str_index1.
DATA : BEGIN OF str_index2,
matnr LIKE eord-matnr,
werks LIKE eord-werks,
END OF str_index2.
DATA : BEGIN OF str_index3_eord,
matnr LIKE eord-matnr,
werks LIKE eord-werks,
END OF str_index3_eord.
DATA : BEGIN OF str_index4,
matnr LIKE eord-matnr,
werks LIKE eord-werks,
END OF str_index4.
DATA : BEGIN OF str_index5,
matnr LIKE eord-matnr,
werks LIKE eord-werks,
END OF str_index5.
DATA : BEGIN OF str_index6,
matnr LIKE eord-matnr,
werks LIKE eord-werks,
END OF str_index6.
DATA : BEGIN OF str_index7,
matnr LIKE eord-matnr,
werks LIKE eord-werks,
END OF str_index7.
Déclaration des variables de debut et de fin de mois.
DATA: w_debut_mois LIKE sy-datum,
w_debut_periode LIKE sy-datum,
w_fin_mois LIKE sy-datum,
w_fin_periode LIKE sy-datum.
Déclaration des variables pour les dates.
DATA: w_date0 LIKE sy-datum,
w_date1 LIKE sy-datum,
w_date2 LIKE sy-datum,
w_date3 LIKE sy-datum,
w_date4 LIKE sy-datum,
w_date5 LIKE sy-datum,
w_date6 LIKE sy-datum,
w_datejour LIKE sy-datum, "FAE15269
w_dat_da LIKE eban-lfdat,
w_dat_op LIKE plaf-pedtr,
w_mois0 LIKE t247-ltx,
w_mois1 LIKE t247-ltx,
w_mois2 LIKE t247-ltx,
w_mois3 LIKE t247-ltx,
w_mois4 LIKE t247-ltx,
w_mois5 LIKE t247-ltx,
w_mois6 LIKE t247-ltx,
w_lendemain LIKE sy-datum. "FAE17345+
Temoin d'un AR dans la commande d'achat.
DATA: w_temoin_ar.
Numéro de la confirmation de la commande
DATA : w_etens LIKE ekes-etens.
Déclaration des variables pour le nom des fichiers.
DATA: w_nom_fichier LIKE rlgrap-filename,
w_fichier LIKE rlgrap-filename,
w_racine LIKE rlgrap-filename,
w_file LIKE rlgrap-filename.
Déclaration d'une table interne pour le transfert.
DATA: BEGIN OF itb_trans OCCURS 0,
w_ligne(320).
DATA: END OF itb_trans.
Déclaration d'une variable pour rechercher les enregistrements vides.
DATA: w_compteur TYPE i,
w_compteur1 TYPE i,
w_compteur2 TYPE i,
w_retard TYPE i, " Retard en jours ouvres.
w_trouve_pfc TYPE c, "addsde
w_trouve_pfs TYPE c, "+DE3K937051
w_trouve TYPE c.
*Index pour les LOOP
DATA : w_index_ekpo LIKE sy-tabix,
w_index_ekes LIKE sy-tabix,
w_index_eket LIKE sy-tabix,
w_index_mseg LIKE sy-tabix,
w_index_eban LIKE sy-tabix,
w_index_plaf LIKE sy-tabix,
w_index_pca LIKE sy-tabix,
w_index_z03_bw_cmp1 LIKE sy-tabix,
w_index_z03_bw_cmp2 LIKE sy-tabix."+DE3K937051
RANGES : r_type_pfs FOR marc-strgr.
*fichier sur serveur +EDR231003
DATA : w_chemin LIKE filename-fileintern, "nom du fichier
w_date_fichier(12) TYPE c, "Date format DD_MM_AA
w_csv(307) TYPE c. "ligne du fichier format CSV
CONSTANTS: k_imputation_m LIKE eban-knttp VALUE 'M'. "FAE19001+
Description de l écran de sélection *
Paramètres "UTILISATION" *
Ouverture d'un block de sélection pour le(s) fournisseur(s).
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-bl1.
Sélection division(s)
SELECT-OPTIONS: s_werks FOR ekpo-werks.
Sélection fournisseur(s).
SELECT-OPTIONS: s_lifnr FOR lfa1-lifnr OBLIGATORY.
Sélection du Groupe d'acheteur
*SELECT-OPTIONS: s_ekgrp FOR marc-ekgrp. "-FAE26446
*SELECT-OPTIONS: s_dispo FOR marc-dispo. "-FAE26446
SELECTION-SCREEN END OF BLOCK block1.
FAE 26446 : ajout
SELECTION-SCREEN BEGIN OF BLOCK block3 WITH FRAME TITLE text-bl3.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETER p_ekgrp RADIOBUTTON GROUP g3.
SELECTION-SCREEN COMMENT 5(24) text-001 FOR FIELD p_ekgrp.
SELECT-OPTIONS: s_ekgrp FOR marc-ekgrp.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETER p_dispo RADIOBUTTON GROUP g3.
SELECTION-SCREEN COMMENT 5(24) text-002 FOR FIELD p_dispo.
SELECT-OPTIONS: s_dispo FOR marc-dispo.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK block3.
FAE 26446 : fin ajout
Paramètres "SYSTEME" *
Saut de 2 lignes.
SELECTION-SCREEN: SKIP 2.
Ouverture d'un block de sélection pour l'adresse physique du fichier.
SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME TITLE text-bl2.
PARAMETERS: p_pc RADIOBUTTON GROUP rad1 DEFAULT 'X', "+EDR231003
p_fic_pc LIKE rlgrap-filename. "+EDR231003
SELECTION-SCREEN SKIP. "+EDR231003
PARAMETERS : p_serve RADIOBUTTON GROUP rad1, "+EDR231003
p_fic_se LIKE filename-fileintern "+EDR231003
DEFAULT 'Z03_PREV_COMMANDES'. "+EDR231003
SELECTION-SCREEN END OF BLOCK block2.
Logique de traitement *
INITIALIZATION *
INITIALIZATION.
Date du jour
MOVE sy-datum TO w_datejour. "FAE15269
Gestion des anomalies.
MOVE text-lb1 TO w_lb_traitement.
PERFORM f930_init USING sy-cprog '30'.
Fin de la gestions des anomalies.
Récuperation des mois dans la table interne 'ITB_MONTHS'.
CALL FUNCTION 'MONTH_NAMES_GET'
EXPORTING
language = sy-langu
TABLES
month_names = itb_months
EXCEPTIONS
month_names_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Récupération des differentes periodes.
PERFORM f100_recuperation_date TABLES itb_months.
Récupération du debut du mois.
CONCATENATE sy-datlo(6) '01' INTO w_debut_mois.
MOVE: w_debut_mois TO w_debut_periode.
Récupération du dernier jour du mois.
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
day_in = sy-datlo
IMPORTING
last_day_of_month = w_fin_mois
EXCEPTIONS
day_in_no_date = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
TOP-OF-PAGE *
TOP-OF-PAGE.
CALL FUNCTION 'Z_00_BC_TOP_OF_PAGE'
EXPORTING
p_linsz = k_ligne
p_pagno = sy-pagno
p_prog = sy-cprog
p_projet = k_projet
p_societe = k_societe
p_sujet = sy-title.
END-OF-PAGE *
END-OF-PAGE.
AT SELECTION-SCREEN *
FAE 26446 : ajout
AT SELECTION-SCREEN ON BLOCK block3.
IF NOT ( s_ekgrp IS INITIAL )
AND NOT ( s_dispo IS INITIAL ).
MESSAGE e394(z03_mm).
ENDIF.
IF p_ekgrp = 'X'.
IF s_ekgrp IS INITIAL.
MESSAGE e395(z03_mm).
ENDIF.
ELSE.
IF s_dispo IS INITIAL.
MESSAGE e396(z03_mm).
ENDIF.
ENDIF.
fae26446 fin ajout
AT SELECTION-SCREEN ON BLOCK block2.
IF p_pc = 'X'.
IF p_fic_pc IS INITIAL.
*Attention, il n'y a aucune adresse de sauvegarde pour le(s) fichier(s)
MESSAGE e021(z03_mm).
ENDIF.
ELSE.
IF p_fic_se IS INITIAL.
*Attention, il n'y a aucune adresse de sauvegarde pour le(s) fichier(s)
MESSAGE e021(z03_mm).
ENDIF.
ENDIF.
Création du matchcode pour la selection du fichier local.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fic_pc.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = p_fic_pc
def_path = 'C:'
mask = text-ma1
mode = 'S'
title = text-sel
IMPORTING
filename = p_fic_pc
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc NE 0 AND sy-subrc NE 3.
MESSAGE e032(z03_mm).
ENDIF.
START-OF-SELECTION *
START-OF-SELECTION.
PERFORM select_donnees.
=================================================
Liste des ARTICLES impactés pour les prévisions *
=================================================
===================================
PORTEFEUILLE DE COMMANDES D'ACHAT *
===================================
Construction itb_pca à partir de EKKO/EKPO.
w_index_ekpo = 1.
w_index_ekes = 1.
w_index_eket = 1.
w_index_mseg = 1.
SORT itb_ekko BY ebeln. "-FAE26446
SORT itb_ekpo BY ebeln ebelp.
SORT itb_makt BY matnr spras.
SORT itb_eket BY ebeln ebelp.
SORT itb_ekes BY ebeln ebelp.
SORT itb_mseg BY ebeln ebelp.
SORT itb_mkpf BY mblnr mjahr.
SORT itb_marc BY matnr werks. "+FAE26446
FAE 26446 remplacement
LOOP AT itb_ekko.
LOOP AT itb_ekpo.
FROM w_index_ekpo.
IF itb_ekko-ebeln = itb_ekpo-ebeln.
LOOP AT itb_ekpo.
READ TABLE itb_marc WITH KEY
matnr = itb_ekpo-matnr
werks = itb_ekpo-werks BINARY SEARCH.
CHECK sy-subrc = 0.
FAE 26446 fin remplacement
itb_pca-ebeln = itb_ekpo-ebeln.
itb_pca-ebelp = itb_ekpo-ebelp.
itb_pca-lifnr = itb_ekko-lifnr. "-FAE26446
itb_pca-lifnr = itb_ekpo-lifnr. "+FAE26446
itb_pca-ekgrp = itb_ekpo-ekgrp. "+FAE26446
itb_pca-dispo = itb_ekpo-dispo. "+FAE26446
itb_pca-matnr = itb_ekpo-matnr.
itb_pca-werks = itb_ekpo-werks.
Recherche du libellé article
READ TABLE itb_makt
WITH KEY matnr = itb_ekpo-matnr
spras = text-fra
BINARY SEARCH.
IF sy-subrc = 0.
itb_pca-maktx = itb_makt-maktx.
ELSE.
READ TABLE itb_makt
WITH KEY matnr = itb_ekpo-matnr
spras = text-ang
BINARY SEARCH.
IF sy-subrc = 0.
itb_pca-maktx = itb_makt-maktx.
ENDIF.
ENDIF.
IF NOT itb_ekpo-bpumn IS INITIAL.
itb_pca-menge = itb_ekpo-menge * itb_ekpo-bpumz /
itb_ekpo-bpumn.
ENDIF.
Sélect° ds la table EKES des dates de livraisons et des qtés
en transit
CLEAR w_temoin_ar.
CLEAR w_etens.
LOOP AT itb_ekes
FROM w_index_ekes.
IF itb_ekes-ebeln = itb_ekpo-ebeln
AND itb_ekes-ebelp = itb_ekpo-ebelp.
IF itb_ekes-ebtyp = text-arn.
itb_pca-eindt = itb_ekes-eindt.
w_temoin_ar = 'X'.
ELSE.
Si c'est une qté en transit alors on recupere
la quantité et la date.
IF itb_ekes-dabmg < itb_ekes-menge.
itb_pca-qtran = itb_pca-qtran + itb_ekes-menge -
itb_ekes-dabmg.
ENDIF.
IF itb_ekes-etens > w_etens.
w_etens = itb_ekes-etens.
itb_pca-dtran = itb_ekes-eindt.
ENDIF.
ENDIF.
ELSEIF itb_ekes-ebeln > itb_ekpo-ebeln
OR ( itb_ekes-ebeln = itb_ekpo-ebeln
AND itb_ekes-ebelp > itb_ekpo-ebelp ).
w_index_ekes = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
S'il n'y a pas d'AR alors récupérat° de la date livraison dans EKET.
LOOP AT itb_eket
FROM w_index_eket.
IF itb_eket-ebeln = itb_ekpo-ebeln
AND itb_eket-ebelp = itb_ekpo-ebelp.
IF w_temoin_ar IS INITIAL.
itb_pca-eindt = itb_eket-eindt.
ENDIF.
itb_pca-slfdt = itb_eket-slfdt.
Calcul du portefeuille fournisseur à partir de la
qté commandée et la qté reçue
itb_pca-attdu = itb_pca-attdu + itb_eket-menge -
itb_eket-wemng.
Calcul du montant du poste
itb_pca-netpr = itb_ekpo-netpr * itb_pca-attdu.
IF itb_ekpo-peinh NE 0.
itb_pca-netpr = itb_pca-netpr / itb_ekpo-peinh.
ENDIF.
Calcul quantité réceptionnée.
itb_pca-wemng = itb_pca-wemng + itb_eket-wemng.
Calcul du retard en nombre de jours calendaires
Le calcul du retard ne doit pas prendre en compte
le jour de livraison
ADD 1 TO itb_eket-eindt.
IF NOT itb_pca-attdu IS INITIAL
AND itb_eket-eindt LT sy-datum.
Calcul du retard en nombre de jours ouvrés
CLEAR w_retard.
CALL FUNCTION 'Z_00_BC_WORKDAYS_PER_PERIOD'
EXPORTING
date_deb = itb_eket-eindt
date_fin = sy-datum
IMPORTING
jours = w_retard.
itb_pca-rtard = itb_pca-rtard + w_retard .
ENDIF.
ELSEIF itb_eket-ebeln > itb_ekpo-ebeln
OR ( itb_eket-ebeln = itb_ekpo-ebeln
AND itb_eket-ebelp > itb_ekpo-ebelp ).
w_index_eket = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
Recherche de la derniere date de livraison.
LOOP AT itb_mseg
FROM w_index_mseg.
IF itb_mseg-ebeln = itb_ekpo-ebeln
AND itb_mseg-ebelp = itb_ekpo-ebelp.
READ TABLE itb_mkpf
WITH KEY mblnr = itb_mseg-mblnr
mjahr = itb_mseg-mjahr
BINARY SEARCH.
IF sy-subrc = 0.
IF itb_mkpf-bldat > itb_pca-bldat.
itb_pca-bldat = itb_mkpf-bldat.
ENDIF.
ENDIF.
ELSEIF itb_mseg-ebeln > itb_ekpo-ebeln
OR ( itb_mseg-ebeln = itb_ekpo-ebeln
AND itb_mseg-ebelp > itb_ekpo-ebelp ).
w_index_mseg = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
APPEND itb_pca.
CLEAR itb_pca.
FAE26446 suppression parag. suivant
ELSEIF itb_ekpo-ebeln > itb_ekko-ebeln.
w_index_ekpo = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
Fin FAE26446
ENDLOOP.
=========================
PREVISIONS DE COMMANDES *
=========================
SORT itb_eord BY matnr werks lifnr ekgrp.
SORT itb_eban BY matnr werks flief ekgrp.
SORT itb_plaf BY matnr plwrk flief.
SORT itb_z03_bw_cmp1 BY matnr werks.
SORT itb_z03_bw_cmp2 BY matnr werks."+DE3K937051
SORT itb_pca BY matnr werks lifnr.
w_index_eban = 1.
w_index_plaf = 1.
w_index_z03_bw_cmp1 = 1.
w_index_pca = 1.
w_index_z03_bw_cmp2 = 1."+DE3K937051
Remplissage de la table des prévisions de commande.
LOOP AT itb_eord.
CLEAR: str_prev_pfc,
w_trouve.
MOVE-CORRESPONDING itb_eord TO str_index1.
MOVE-CORRESPONDING itb_eord TO str_index3_eord.
MOVE-CORRESPONDING itb_eord TO itb_prev_cde.
Recherche dans table division/article (MARC) afin de déterminer si
article PFS (prod fabriqué à stock) ou PFC (Prod fabriqué sur cde)
AT NEW werks.
READ TABLE itb_marc_eord
WITH KEY matnr = itb_eord-matnr
werks = itb_eord-werks
BINARY SEARCH.
IF sy-subrc NE 0.
CLEAR itb_marc_eord.
ENDIF.
ENDAT.
a - Prévisions pour les PFS : DA + OP *
*Calcul des quantités de commande.
IF itb_eord-disls = text-tl1.
itb_prev_cde-bstmi = itb_eord-bstfe.
ELSEIF itb_eord-disls = text-tl2
OR itb_eord-disls = text-tl3.
IF itb_eord-bstrf NE 0
AND itb_eord-bstmi = 0
AND itb_eord-bstma = 0.
itb_prev_cde-bstmi = itb_eord-bstrf.
ELSEIF itb_eord-bstrf NE 0
AND itb_eord-bstmi NE 0.
itb_prev_cde-bstmi = itb_eord-bstmi.
ELSEIF itb_eord-bstrf = itb_eord-bstma
AND itb_eord-bstrf NE 0
AND itb_eord-bstmi = 0.
itb_prev_cde-bstmi = itb_eord-bstma.
ENDIF.
ENDIF.
si article PFS (Prod fabriqué à stock) recherche des
demandes d'achat ou ordres planfiés
IF itb_marc_eord-strgr IN r_type_pfs.
Récupérat° calendrier de la division pour calcul correct lors de
l'ajout de eban-webaz ou plaf-webaz jours ouvrés
CLEAR w_trouve_pfs ."+DE3K937051
READ TABLE itb_t001w
WITH KEY werks = itb_eord-werks
BINARY SEARCH.
IF sy-subrc = 0.
LOOP AT itb_eban
FROM w_index_eban.
MOVE-CORRESPONDING itb_eban TO str_index2.
IF str_index1 = str_index2.
w_trouve_pfs = 'X'."+DE3K937051
si qte commandées pour la DA < quantité de la DA
IF itb_eban-bsmng < itb_eban-menge.
ajout de quantité de la DA - qte commandée pour la DA
PERFORM affect_da.
ENDIF.
ELSEIF str_index2 > str_index1.
w_index_eban = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
ajout des quantité des OP (ordres planifiés)
LOOP AT itb_plaf
FROM w_index_plaf.
MOVE-CORRESPONDING itb_plaf TO str_index4.
str_index4-werks = itb_plaf-plwrk.
str_index4-lifnr = itb_plaf-flief.
IF str_index4 = str_index3_eord.
Ajout de webaz jours ouvrés à pedtr
CALL FUNCTION 'Z_03_MM_ADD_TO_FACTORYDATE'
EXPORTING
i_date = itb_plaf-pedtr
i_calendar_id = itb_t001w-fabkl
i_nb_days = itb_plaf-webaz
IMPORTING
o_date = w_dat_op
EXCEPTIONS
conv_error = 1
OTHERS = 2.
IF sy-subrc
If forecasts found in Z03_BW_CMP2 for the article
IF w_trouve_pfs = 'X'."-DE3K937602
Recalculation prev month M in fct of Nb of wrought days of the month
IF NOT itb_prev_cde-men00 IS INITIAL.
one does not hold any more account of the day in progress
w_lendemain = w_date0 + 1.
CLEAR:w_nb_j,w_nb_j_tot. "DE3K938206+
CALL FUNCTION 'Z_00_BC_WORKDAYS_PER_PERIOD'
EXPORTING
date_deb = w_lendemain
date_fin = w_fin_mois
IMPORTING
jours = w_nb_j.
CALL FUNCTION 'Z_00_BC_WORKDAYS_PER_MONTH'
EXPORTING
date = w_lendemain
IMPORTING
jours = w_nb_j_tot.
itb_prev_cde-men00 = itb_prev_cde-men00 * w_nb_j / w_nb_j_tot
*CLA DE3K925301 FAE27197
*to round has the higher entirety
itb_prev_cde-men00 = ceil( itb_prev_cde-men00 ). "DE3K938206-
ENDIF.
ENDIF."-DE3K937602
*End change BNI
b - Prévisions pour les PFC (Z03_BW_CMP1 puis rééquilibrage) *
Recherche des previsions dans Z03_BW_CMP1
si article PFC (Prod fabriqué sur cde) recherche des prévisions
IF NOT itb_marc_eord-strgr IN r_type_pfs.
CLEAR str_prev_pfc.
MOVE-CORRESPONDING itb_eord TO str_prev_pfc.
CLEAR w_trouve_pfc .
LOOP AT itb_z03_bw_cmp1
FROM w_index_z03_bw_cmp1.
MOVE-CORRESPONDING itb_z03_bw_cmp1 TO str_index7.
MOVE-CORRESPONDING itb_eord TO str_index6.
IF str_index6 = str_index7.
si on trouve des prévisions dans z03_bw_cmp1 pour la source
d'appro eord alors c'est un article PFC
w_trouve_pfc = 'X'.
CASE itb_z03_bw_cmp1-pdatu+0(6).
WHEN w_date0+0(6).
str_prev_pfc-men00 = itb_z03_bw_cmp1-plnmg.
WHEN w_date1+0(6).
str_prev_pfc-men01 = itb_z03_bw_cmp1-plnmg.
WHEN w_date2+0(6).
str_prev_pfc-men02 = itb_z03_bw_cmp1-plnmg.
WHEN w_date3+0(6).
str_prev_pfc-men03 = itb_z03_bw_cmp1-plnmg.
WHEN w_date4+0(6).
str_prev_pfc-men04 = itb_z03_bw_cmp1-plnmg.
WHEN w_date5+0(6).
str_prev_pfc-men05 = itb_z03_bw_cmp1-plnmg.
WHEN w_date6+0(6).
str_prev_pfc-men06 = itb_z03_bw_cmp1-plnmg.
WHEN OTHERS.
ENDCASE.
ELSEIF str_index7 > str_index6.
w_index_z03_bw_cmp1 = sy-tabix.
EXIT.
ENDIF.
ENDLOOP.
*Begin change BNI
Si des prévisions trouvées dans Z03_BW_CMP1 pour l'article
IF w_trouve_pfc = 'X'.
Recalcul prev mois M en fct du nb de jours ouvrés du mois
IF NOT str_prev_pfc-men00 IS INITIAL.
on ne tient plus compte du jour en cours
w_lendemain = w_date0 + 1.
CLEAR:w_nb_j,w_nb_j_tot. "DE3K938206+
CALL FUNCTION 'Z_00_BC_WORKDAYS_PER_PERIOD'
EXPORTING
date_deb = w_lendemain
date_fin = w_fin_mois
IMPORTING
jours = w_nb_j.
CALL FUNCTION 'Z_00_BC_WORKDAYS_PER_MONTH'
EXPORTING
date = w_lendemain
IMPORTING
jours = w_nb_j_tot.
str_prev_pfc-men00 = str_prev_pfc-men00 * w_nb_j / w_nb_j_tot.
*CLA DE3K925301 FAE27197
*arrondir a l'entier supèrieur
str_prev_pfc-men00 = ceil( str_prev_pfc-men00 ).
ENDIF.
Equilibrage PFC : commande/prévision du mois
Recherche COMMANDES cumulées pour M à M+6
CLEAR str_pca_pfc.
LOOP AT itb_pca
FROM w_index_pca.
MOVE-CORRESPONDING itb_pca TO str_index5.
IF str_index5 = str_index3_eord.
IF NOT itb_pca-menge IS INITIAL.
CASE itb_pca-eindt+0(6).
WHEN w_date0+0(6).
IF itb_pca-eindt >= w_date0.
str_pca_pfc-men00 = str_pca_pfc-men00 + itb_pca-menge.
ENDIF.
WHEN w_date1+0(6).
str_pca_pfc-men01 = str_pca_pfc-men01 + itb_pca-menge.
WHEN w_date2+0(6).
str_pca_pfc-men02 = str_pca_pfc-men02 + itb_pca-menge.
WHEN w_date3+0(6).
str_pca_pfc-men03 = str_pca_pfc-men03 + itb_pca-menge.
WHEN w_date4+0(6).
str_pca_pfc-men04 = str_pca_pfc-men04 + itb_pca-menge.
WHEN w_date5+0(6).
str_pca_pfc-men05 = str_pca_pfc-men05 + itb_pca-menge.
WHEN w_date6+0(6).
str_pca_pfc-men06 = str_pca_pfc-men06 + itb_pca-menge.
ENDCASE.
ENDIF."NOT itb_pca-menge IS INITIAL
ELSEIF str_index5 > str_index3_eord.
w_index_pca = sy-tabix.
EXIT.
ENDIF.
ENDLOOP."itb_pca
*. Equilibrer commande / prévision des mois : diminuer la quantité de
prévision de chaque mois par le portefeuille de commande client du
mois*. Si ce solde est négatif alors lui donner la valeur 0.
w_i = 0.
Ajustement commandes/prévisions pour les mois M à M+6
WHILE w_i .
Pour un mois, SI Prévisions > Commandes en cours
IF .
Prévisions = Prévisions - Commandes en cours
= 0.
ENDIF.
On passe au mois suivant
w_i = w_i + 1.
ENDWHILE.
MOVE str_prev_pfc-men00 TO itb_prev_cde-men00.
MOVE str_prev_pfc-men01 TO itb_prev_cde-men01.
MOVE str_prev_pfc-men02 TO itb_prev_cde-men02.
MOVE str_prev_pfc-men03 TO itb_prev_cde-men03.
MOVE str_prev_pfc-men04 TO itb_prev_cde-men04.
MOVE str_prev_pfc-men05 TO itb_prev_cde-men05.
MOVE str_prev_pfc-men06 TO itb_prev_cde-men06.
ENDIF. "w_trouve_pfc = 'X'.
ENDIF.
*recherche du libellé articleHi,
see this link, useful tips, links and transactions for best performance, by Anji.
https://forums.sdn.sap.com/click.jspa?searchID=5967263&messageID=4260111
Regards -
How to improve profamance of this
Hi Gurus,
how to increase perfomance of this statement .
LOOP AT HEADCOUNT_TABLE.
SELECT COUNT(*) INTO HEADCOUNT_TABLE-ZSEXEMPT
FROM PA0000 INNER JOIN PA0001
ON PA0000PERNR = PA0001PERNR
WHERE PA0001~KOSTL = HEADCOUNT_TABLE-KOSTL
AND PA0001~BUKRS = HEADCOUNT_TABLE-BUKRS
AND PA0000~BEGDA <= PROCESS_DATE
AND PA0000~ENDDA >= PROCESS_DATE
AND PA0000~STAT1 = '3'
AND PA0001~BEGDA <= PROCESS_DATE
AND PA0001~ENDDA >= PROCESS_DATE
AND PA0001~PERSG IN ('O', 'X', 'E', 'Y', 'T', 'A', 'I', 'L','F',
'S','D').
SELECT COUNT(*) INTO HEADCOUNT_TABLE-ZSCONTRACTOR
FROM PA0000 INNER JOIN PA0001
ON PA0000PERNR = PA0001PERNR
WHERE PA0001~KOSTL = HEADCOUNT_TABLE-KOSTL
AND PA0001~BUKRS = HEADCOUNT_TABLE-BUKRS
AND PA0000~BEGDA <= PROCESS_DATE
AND PA0000~ENDDA >= PROCESS_DATE
AND PA0000~STAT1 = '3'
AND PA0001~BEGDA <= PROCESS_DATE
AND PA0001~ENDDA >= PROCESS_DATE
AND PA0001~PERSG IN ('7', '8', '9').
endloop.
Thanks,
KumarLet's all go back to the requirement of this guy.
Please correct me if I'm wrong kumar.
The requirement are for each combination of company code (BUKRS) and cost center (KOSTL), count the number of active 'ZSEXEMPT' personnel (persg in ('O', 'X', 'E', 'Y', 'T', 'A', 'I', 'L','F','S','D')) and the number of active 'ZSCONTRACTOR' personnel (PERSG IN ('7', '8', '9')) in a specific key date (PROCESS_DATE).
Rightfuly, combination of BUKRS and KOSTL should be unique in HEADCOUNT_TABLE if above is the requirement and in the specific key date, PERNR is the key for P0000 and P0001.
If HEADCOUNT_TABLE does not contain all combination of BUKRS and KOSTL, you have to use for all entries as below example.
if HEADCOUNT_TABLE[] is not initial.
Select PA0000~PERNR
PA0001~KOSTL
PA0001~BUKRS
into table itab_ZSEXEMPT
from PA0000 INNER JOIN PA0001
ON PA0000~PERNR = PA0001~PERNR
for all entries in headcount_table
WHERE PA0001~KOSTL = HEADCOUNT_TABLE-KOSTL
AND PA0001~BUKRS = HEADCOUNT_TABLE-BUKRS
AND PA0000~BEGDA <= PROCESS_DATE
AND PA0000~ENDDA >= PROCESS_DATE
AND PA0000~STAT1 = '3'
AND PA0001~BEGDA <= PROCESS_DATE
AND PA0001~ENDDA >= PROCESS_DATE
AND PA0001~PERSG IN ('O', 'X', 'E', 'Y', 'T', 'A', 'I', 'L','F',
'S','D').
Select PA0000~PERNR
PA0001~KOSTL
PA0001~BUKRS into table itab_ZSCONTRACTOR
from PA0000 INNER JOIN PA0001
ON PA0000~PERNR = PA0001~PERNR
for all entries in headcount_table
WHERE PA0001~KOSTL = HEADCOUNT_TABLE-KOSTL
AND PA0001~BUKRS = HEADCOUNT_TABLE-BUKRS
AND PA0000~BEGDA <= PROCESS_DATE
AND PA0000~ENDDA >= PROCESS_DATE
AND PA0000~STAT1 = '3'
AND PA0001~BEGDA <= PROCESS_DATE
AND PA0001~ENDDA >= PROCESS_DATE
AND PA0001~PERSG IN ('7', '8', '9').
endif.
sort itab_ZSEXEMPT by kostl bukrs.
sort itab_ZSCONTRACTOR by kostl bukrs.
refresh temp_itab.
loop at HEADCOUNT_TABLE assigning <FS_HEADCOUNT>.
temp_itab[] = itab_zsexempt[].
delete temp_itab where bukrs NE <FS_HEADCOUNT>-bukrs and
kostl NE <FS_HEADCOUNT>-kostl.
describe table temp_itab lines <FS_HEADCOUNT>-ZSEXEMPT.
refresh temp_itab.
temp_itab[] = itab_ZSCONTRACTOR [].
delete temp_itab where bukrs NE <FS_HEADCOUNT>-bukrs and
kostl NE <FS_HEADCOUNT>-kostl.
describe table temp_itab lines <FS_HEADCOUNT>-ZSCONTRACTOR .
refresh temp_itab.
endloop.
Try that and compare the performance.
Regards,
Abraham -
How to Improve perfomance of this query
Hi,
Please help me to improve this query performance. Objective of this query is to find out individual count who order the product in last two year and create a matrix with time period
Challenge is Both the table having more than 600 million record so it is taking to much time to execute
SELECT count(unique b.individual_id),
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955'))>= SYSDATE - 45 THEN 1 ELSE 0 END )) AS one_month ,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955'))>= SYSDATE - 105 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 45 THEN 1 ELSE 0 END )) AS Three_month,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 195 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 105 THEN 1 ELSE 0 END )) AS six_month,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 380 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 195 THEN 1 ELSE 0 END )) AS one_year,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 745 and NVL(ORDER_DT,TO_DATE('05-MAY-1955'))<= SYSDATE - 380 THEN 1 ELSE 0 END )) AS two_year
from ORDER b, address a
where b.individual_id = a.individual_id
and a.COUNTRY_CD ='US'
group by a.COUNTRY_CD ;
Thanks
Neeraj
Edited by: user4522368 on Aug 17, 2010 12:10 AMuser4522368 wrote:
Hi,
Please help me to improve this query performance. Objective of this query is to find out individual count who order the product in last two year and create a matrix with time period
Challenge is Both the table having more than 600 million record so it is taking to much time to execute Dombrooks has provided you with an excellent response.
In addition, you should mention how much time the query is currently taking and how much do you expect it to take, what is your database version etc.
One of the most important thing is to post your SQLs and EXPLAIN PLAN outcomes in readable format. You can do this by wrapping it within \ and \ tags.
Now, based on the limited details that you have provided, following are my questions/observations:
a) You claim that both tables have more than 600 million rows but your plan shows that optimizer is expecting to find only 46 million rows in ORDER table. You may want to confirm if statistics on both the tables are correct.
b) Your plan appears to suggest that the UNIQUE is not affecting the query results. Based on your knowledge of your data, do you need the COUNT(UNIQUE individual_id) or can it be just COUNT(individual_id)?
c) Finally, if you are interested in only last two years of data, you should probably have a WHERE predicate on your ORDER table which filters data based on ORDER_DT. Something like following:
SELECT count(unique b.individual_id),
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955'))>= SYSDATE - 45 THEN 1 ELSE 0 END )) AS one_month ,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955'))>= SYSDATE - 105 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 45 THEN 1 ELSE 0 END )) AS Three_month,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 195 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 105 THEN 1 ELSE 0 END )) AS six_month,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 380 and NVL(ORDER_DT,TO_DATE('05-MAY-1955')) <= SYSDATE - 195 THEN 1 ELSE 0 END )) AS one_year,
sum((CASE WHEN NVL(ORDER_DT,TO_DATE('05-MAY-1955')) >= SYSDATE - 745 and NVL(ORDER_DT,TO_DATE('05-MAY-1955'))<= SYSDATE - 380 THEN 1 ELSE 0 END )) AS two_year
from ORDER b, address a
where b.individual_id = a.individual_id
and a.COUNTRY_CD ='US'
and b.ORDER_DT <= (SYSDATE - 380)
group by a.COUNTRY_CD ; -
ROWNUM is indexed in the Fact table - How to optimize performace with this?
Hi,
I have a scenario where there is an index on the Rownum.
The main Fact table is partitioned based on the job number (Daily and monthly). As there can be multiple entries for a single jobID, the primary key is made up of the Job ID and the Rownum
This fact table in turn is joined with another fact table based on this job number and rownum. This second fact table is also partitioned on job ID.
I have few reference tables that are joined with the first fact table with btree index.
Though in a normal DW scenario we should use bitmap, here we can't do that as lot of other applications are accessing data (DML queries) where bitmap will be slow. So I am using STAR_TRANSFORMATION hint to use the normal index as bitmap index.
Till here it is fine. Problem is when I simply do a count for a specific partition from a reference table and a fact table, it is using all required indexes as bitmap with very low cost. But also it is using ROWNUM index that is of very very high cost.
I am relatively new to Oracle tuning. I am not able to understand what it is exactly doing. Could you please suggest if I can get rid of this ROWNUM to make my query performance faster? This index can not be dropped. Is there a way in the hint I can instruct not to use this primary key index?
Or Even by using is there a way that the performance will be faster?
I will highly appreciate any help in this regard.
Regards
...Just sending the portion having info on the partition and Primary index as the entire script is too big.
CREATE TABLE FACT_TABLE
JOBID VARCHAR2(10 BYTE) DEFAULT '00000000' NOT NULL,
RECID VARCHAR2(18 BYTE) DEFAULT '000000000000000000' NOT NULL,
REP_DATE VARCHAR2(8 BYTE) DEFAULT '00000000' NOT NULL,
LOCATION VARCHAR2(4 BYTE) DEFAULT ' ' NOT NULL,
FUNCTION VARCHAR2(6 BYTE) DEFAULT ' ' NOT NULL,
AMT.....................................................................................
TABLESPACE PSAPPOD
PCTUSED 0
PCTFREE 10
INITRANS 11
MAXTRANS 255
STORAGE (
INITIAL 32248K
LOGGING
PARTITION BY RANGE (JOBID)
PARTITION FACT_TABLE_1110500 VALUES LESS THAN ('01110600')
LOGGING
NOCOMPRESS
TABLESPACE PSAPFACTTABLED
PCTFREE 10
INITRANS 11
MAXTRANS 255
STORAGE (
INITIAL 32248K
MINEXTENTS 1
MAXEXTENTS 2147483645
BUFFER_POOL DEFAULT
PARTITION FACT_TABLE_1191800 VALUES LESS THAN ('0119190000')
LOGGING
NOCOMPRESS
TABLESPACE PSAPFACTTABLED
PCTFREE 10
INITRANS 11
MAXTRANS 255
CREATE UNIQUE INDEX "FACT_TABLE~0" ON FACT_TABLE
(JOBID, RECID)
TABLESPACE PSAPFACT_TABLEI
INITRANS 2
MAXTRANS 255
LOCAL (
PARTITION FACT_TABLE_11105
LOGGING
NOCOMPRESS
TABLESPACE PSAPFACT_TABLEI
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
BUFFER_POOL DEFAULT
...................................................... -
How to improve performance of this SQL query?
Hi,
I have a query that tries to build a string (RPATH) for use as a url parameter. The query is:
SELECT DISTINCT USERNAME, PASSWORD, ROLE, RIGHTS,
DECODE(GEO, ROLE, 'g='||NVL(GEO,'none'), NULL)||
DECODE(AREA, ROLE, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none'), NULL)||
DECODE(REGION, ROLE, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none'), NULL)||
DECODE(DISTRICT, ROLE, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none')||'&d='||NVL(DISTRICT,'none'), NULL)||
DECODE(OFFICE, ROLE, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none')||'&d='||NVL(DISTRICT,'none')||'&o='||NVL(OFFICE,'none')
, NULL) RPATH
FROM (SELECT U.*, L.*
FROM (SELECT * FROM T_USERS WHERE USERNAME='xxx' AND PASSWORD='yyy') U, T_LOC_SUB L
WHERE U.ROLE IN ('WW', L.GEO, L.AREA, L.REGION, L.DISTRICT, L.OFFICE))
GROUP BY USERNAME, PASSWORD, ROLE, RIGHTS, GEO, AREA, REGION, DISTRICT, OFFICE;
T_USERS is defined as
CREATE TABLE T_USERS (
username VARCHAR2(10) CONSTRAINT T_USERS_username_pk PRIMARY KEY,
password VARCHAR2(10),
role CONSTRAINT T_USERS_role_FK REFERENCES T_LOC_MAIN(loc),
rights VARCHAR2(3)
T_LOC_SUB is defined as
CREATE TABLE T_LOC_SUB (
geo CONSTRAINT T_LOC_SUB_geo_FK REFERENCES T_LOC_MAIN(loc),
area CONSTRAINT T_LOC_SUB_area_FK REFERENCES T_LOC_MAIN(loc),
region CONSTRAINT T_LOC_SUB_region_FK REFERENCES T_LOC_MAIN(loc),
district CONSTRAINT T_LOC_SUB_district_FK REFERENCES T_LOC_MAIN(loc),
office CONSTRAINT T_LOC_SUB_office_FK REFERENCES T_LOC_MAIN(loc)
T_LOC_MAIN is defined as
CREATE TABLE T_LOC_MAIN (
loc VARCHAR2(4) CONSTRAINT T_LOC_MAIN_loc_PK PRIMARY KEY,
label VARCHAR2(60),
rank NUMBER
REGION and DISTRICT columns in T_LOC_SUB may be NULL at times. How can I rewrite the SQL to make it run faster or more efficiently?
Please help.. Thank you..Hi,
I just realised I can simplify the query to:
SELECT DISTINCT USERNAME, PASSWORD, ROLE, RIGHTS,
DECODE(ROLE,
GEO, 'g='||NVL(GEO,'none'),
AREA, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none'),
REGION, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none'),
DISTRICT, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none')||'&d='||NVL(DISTRICT,'none'),
OFFICE, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none')||'&d='||NVL(DISTRICT,'none')||'&o='||NVL(OFFICE,'none'),
NULL) RPATH
FROM (SELECT U.*, L.*
FROM (SELECT * FROM T_USERS WHERE USERNAME='xxx' AND PASSWORD='yyy') U, T_LOC_SUB L
WHERE U.ROLE IN ('WW', L.GEO, L.AREA, L.REGION, L.DISTRICT, L.OFFICE))
GROUP BY USERNAME, PASSWORD, ROLE, RIGHTS, GEO, AREA, REGION, DISTRICT, OFFICE;
Anyone can offer a better and more efficient improvement?
Thanx! -
How to improve performance for this code
Hi,
LOOP AT lt_element INTO ls_element.
READ TABLE lt_element_ident INTO ls_element_ident
WITH KEY element_id = ls_element-element_id BINARY SEARCH.
IF sy-subrc EQ 0.
MOVE ls_element_ident-value TO lv_guid.
SELECT * FROM zcm_valuation_at
APPENDING CORRESPONDING FIELDS OF TABLE lt_caseattributes
WHERE case_guid = lv_guid.
ENDIF.
ENDLOOP.
LOOP AT lt_caseattributes INTO ls_caseattributes.
IF ls_caseattributes-ext_key IS INITIAL.
SELECT SINGLE ext_key
INTO CORRESPONDING FIELDS OF ls_caseattributes
FROM scmg_t_case_attr
WHERE case_guid = ls_caseattributes-case_guid.
ENDIF.
*To get the Status description of the Case
SELECT SINGLE stat_ordno_descr
INTO ls_caseattributes-status
FROM scmgstatprofst AS a
INNER JOIN scmg_t_case_attr AS b
ON aprofile_id = bprofile_id
AND astat_orderno = bstat_orderno
WHERE case_guid = ls_caseattributes-case_guid.
MODIFY lt_caseattributes FROM ls_caseattributes INDEX sy-tabix TRANSPORTING status ext_key.
ENDLOOP.
READ TABLE lt_caseattributes INTO ls_caseattributes INDEX 1.
Regards,
MarutiHi,
try this kind of code:
==================================
start new
DATA:
lt_scmgstatprofst LIKE scmgstatprofst OCCURS 0 WITH HEADER LINE,
wa_scmg_t_case_attr LIKE scmg_t_case_attr.
SELECT * FROM scmgstatprofst INTO TABLE lt_scmgstatprofst.
SORT lt_scmgstatprofst BY profile_id stat_orderno.
end new
LOOP AT lt_element INTO ls_element.
READ TABLE lt_element_ident INTO ls_element_ident
WITH KEY element_id = ls_element-element_id BINARY SEARCH.
IF sy-subrc EQ 0.
MOVE ls_element_ident-value TO lv_guid.
SELECT * FROM zcm_valuation_at
APPENDING CORRESPONDING FIELDS OF TABLE lt_caseattributes
WHERE case_guid = lv_guid.
ENDIF.
ENDLOOP.
LOOP AT lt_caseattributes INTO ls_caseattributes.
IF ls_caseattributes-ext_key IS INITIAL.
SELECT SINGLE ext_key
INTO CORRESPONDING FIELDS OF ls_caseattributes
FROM scmg_t_case_attr
WHERE case_guid = ls_caseattributes-case_guid.
ENDIF.
*To get the Status description of the Case
start deletion
SELECT SINGLE stat_ordno_descr
INTO ls_caseattributes-status
FROM scmgstatprofst AS a
INNER JOIN scmg_t_case_attr AS b
ON aprofile_id = bprofile_id
AND astat_orderno = bstat_orderno
WHERE case_guid = ls_caseattributes-case_guid.
end deletion
start new
CLEAR wa_scmg_t_case_attr.
SELECT SINGLE * FROM scmg_t_case_attr INTO wa_scmg_t_case_attr
WHERE case_guid = ls_caseattributes-case_guid.
READ TABLE lt_scmgstatprofst WITH KEY
profile_id = wa_scmg_t_case_attr-profile_id
stat_orderno = wa_scmg_t_case_attr-stat_orderno
BINARY SEARCH.
IF sy-subrc IS INITIAL.
ls_caseattributes-status = lt_scmgstatprofst-stat_ordno_descr.
ENDIF.
end new
MODIFY lt_caseattributes FROM ls_caseattributes INDEX sy-tabix
TRANSPORTING status ext_key.
ENDLOOP.
READ TABLE lt_caseattributes INTO ls_caseattributes INDEX 1.
==================================
Regards
Walter Habich
Edited by: Walter Habich on Jun 17, 2008 8:41 AM -
How to improve performance for bulk data load in Dynamics CRM 2013 Online
Hi all,
We need to bulk update (or create) contacts into Dynamics CRM 2013 online every night due to data updated from another external data source. The data size is around 100,000 and the data loading duration was around 6 hours.
We are already using ExecuteMultiple web services to handle the integration, however, the 6 hours integraton duration is still not acceptable and we are seeking for any advise for further improvement.
Any help is highly appreciated. Many thanks.
GaryI think Andrii's referring to running multiple threads in parallel (see
http://www.mscrmuk.blogspot.co.uk/2012/02/data-migration-performance-to-crm.html - it's a bit dated, but should still be relevant).
Microsoft do have some throttling limits applied in Crm Online, and it is worth contacting them to see if you can get those raised.
100 000 records per night seems a large number. Are all these records new or updated records, or are there some that are unchanged, in which case you could filter them out before uploading ? Or are there useful ways to summarise the data before loading
Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk -
How to improve performace?
Is there a way to improve the performance of mass run (e.g., FPY1, FPMA, FP04M)?
Is there a cookbook out there?
Thanks gurus!Hello,
To improve the performance, I would suggest to split the customers by creating variant for all the mass programs.
Coming to the cookbook, I do not think there is one... Here is the list of cookbooks available till now
Billing Cookbooks <ISU>
Abrechnung von Hinterschaltungen
Abrechnung von Leitungs- und Transformatorverlusten
Anlagengruppen
Billing Procedure in Brazil
Billing Procedure in Brazil
Billing Serial Switchings
Billing Transmission Losses and Power Transformer Losses
Dynamic Period Control
Dynamische Periodensteuerung
IS-U/CO-PA Integration
IS-U/CO-PA-Integration
Installation Groups
Master Agreements in Sales Process f. Comm. & Ind. Customers
Payment Scheme
Rahmenverträge im Verkaufsprozess f. Gewerbe u. Sonderkunden
Zahlungsschema
FICA cookbooks
Cookbook Settlement Control
Collective Bill
Sammelrechnung
Cookbook Verrechnungssteuerung
Präsentation Verrechungssteuerung
Forderungsabgabe an externe Inkassobüros
Submission of Receivables to External Collection Agencies
Reconnecting a Utility Installation (IS-U)
Wiederinbetriebnahme einer Versorgungsanlage (IS-U)
Some of them are in German Language to translate them to English.
Hope this helps
Rgds
Rajendra -
How can improve performace of iMac 24" for FCS?
Hi,
I just bought iMac Intel Core2Duo 24"
3.06GHz/ 2GB Ram/ 750GB HD/ 512 VRAM.
How can I improve or maximize its performance so it would run faster in FCP for Renders, Motion, Compressor and other pro apps?
I do understand that I need to add memory and that I'll add but aside from that,
what else do I need to do to make it faster?
Thanks,
ZiaYes you can: http://ftp.georgetek.com/George/FCPscatchdisk.png
Just keep in mind that read/write speeds to an external USB drive are less than half of what you are getting internally. Your best bet for an external editing drive would be FireWire 800.
rkaufmann87, no problem I do the same thing all the time.
George -
How to improve performance by pulling data instead of BSEG table?
Hi,
We are facing issue in which we have to pull material no for some non copa postings.
But if we use BSEG table then serious performance issues are coming up..
so are there any other tables / combination of tables that we can look for instead of BSEG?Hi,
BSEG is Cluster table, you can only select with key fields.
if you have a select:
select belnr budat wrbtr from bseg
into table it_bseg
where bukrs = bukrs
and belnr = belnr
and gjahr = gjahr
and bschl = 31.
it's much better to select of this way:
select belnr budat wrbtr from bseg
into table it_bseg
where bukrs = bukrs
and belnr = belnr
and gjahr = gjahr.
delete it_bseg where bschl ne '31'.
Regards,
Fernando -
How to Improve Performance of this query??
Hi experts,
Kindly suggest me some perfomance optimization on the below code.
SELECT * FROM vtrdi AS v
INTO TABLE six
FOR ALL ENTRIES IN r_vbeln
WHERE vbeln EQ r_vbeln-low
AND trsta IN s_trsta
AND vstel IN s_vstel
AND tddat IN s_tddat
AND vbtyp IN r_vbtyp
AND lstel IN s_lstel
AND route IN s_route
AND tragr IN s_tragr
AND vsbed IN s_vsbed
AND land1 IN s_land1
AND lzone IN s_lzone
AND wadat IN s_wadat
AND wbstk IN s_wbstk
AND lddat IN s_lddat
AND lfdat IN s_lfdat
AND kodat IN s_kodat
AND kunnr IN s_kunnr
AND spdnr IN s_spdnr
AND inco1 IN s_inco1
AND inco2 IN s_inco2
AND lprio IN s_lprio
AND EXISTS ( SELECT * FROM likp
WHERE vbeln EQ v~vbeln
AND lifnr IN s_lifnr
AND lgtor IN s_lgtor
AND lgnum IN s_lgnum
AND lfuhr IN s_lfuhr
AND aulwe IN s_aulwe
AND traty IN s_traty
AND traid IN s_traid
AND vsart IN s_vsart
AND trmtyp IN s_trmtyp
AND sdabw IN s_sdabw
AND cont_dg IN r_cont_dg ).
Thanks in Advance...
Santosh.Try to write 2 select
SELECT * FROM vtrdi AS v
INTO TABLE six
FOR ALL ENTRIES IN r_vbeln
WHERE vbeln EQ r_vbeln-low
AND trsta IN s_trsta
AND vstel IN s_vstel
AND tddat IN s_tddat
AND vbtyp IN r_vbtyp
AND lstel IN s_lstel
AND route IN s_route
AND tragr IN s_tragr
AND vsbed IN s_vsbed
AND land1 IN s_land1
AND lzone IN s_lzone
AND wadat IN s_wadat
AND wbstk IN s_wbstk
AND lddat IN s_lddat
AND lfdat IN s_lfdat
AND kodat IN s_kodat
AND kunnr IN s_kunnr
AND spdnr IN s_spdnr
AND inco1 IN s_inco1
AND inco2 IN s_inco2
AND lprio IN s_lprio.
SELECT * FROM likp into table itab
WHERE vbeln EQ v~vbeln
AND lifnr IN s_lifnr
AND lgtor IN s_lgtor
AND lgnum IN s_lgnum
AND lfuhr IN s_lfuhr
AND aulwe IN s_aulwe
AND traty IN s_traty
AND traid IN s_traid
AND vsart IN s_vsart
AND trmtyp IN s_trmtyp
AND sdabw IN s_sdabw
AND cont_dg IN r_cont_dg
loop at six
check whether entry is exists or not
if not remove from six interbal table.
endloop.
Thanks
Venkat -
How to improve speed of data acquisition? Help needed urgently.
I want to convert analog signals to digital signals and simultaneously perform some search on the data acquired and this whole process has to be done continuously for few hours.
So I tried writing two programs in Matlab, one acquires the analog data and converts it to digital and saves the data in small chunks on hard disk (like file1, file2, file3,...) continuously. The other program performs the search operation in those chunks of data continuously. I run both the programs at a time by opening two mat lab windows.
But the problem Iam facing is that the data acquisition is slow. As a result I get an error message in the second program saying that
"??? Error using ==> load
Unable to read file file4.mat: No such file or directory."
Iam unable to synchronize the two programs. I cannot use timers in search program because I cannot add any delays.
Iam using a NI PCI-6036E ,16 Bit Resolution ,200 KS/s Sampling Rate A/D board.
Should I switch to some other series such as M series having sampling rate of the order MS/s?
Can anyone please tell me how to improve the speed of data acquisition?
Thanks.Gayathri wrote:
I want to convert analog signals to digital signals and simultaneously perform some search on the data acquired and this whole process has to be done continuously for few hours.
So I tried writing two programs in Matlab, one acquires the analog data and converts it to digital and saves the data in small chunks on hard disk (like file1, file2, file3,...) continuously. The other program performs the search operation in those chunks of data continuously. I run both the programs at a time by opening two mat lab windows.
But the problem Iam facing is that the data acquisition is slow. As a result I get an error message in the second program saying that
"??? Error using ==> load
Unable to read file file4.mat: No such file or directory."
Iam unable to synchronize the two programs. I cannot use timers in search program because I cannot add any delays.
Iam using a NI PCI-6036E ,16 Bit Resolution ,200 KS/s Sampling Rate A/D board.
Should I switch to some other series such as M series having sampling rate of the order MS/s?
Can anyone please tell me how to improve the speed of data acquisition?
Thanks.
Hi gayathri,
well my email is [email protected]
if ur from india mail me back.
Regards
labview boy -
How can I transfer all my data including SMS to my mac/windows computer?
My friend has asked me to help her transfer all the data from her iPhone 3GS to a computer then to a hard drive. She has several folders with pictures in but image capture on mac is only picking up the one. I have an iPhone 4S and iPad 3 installed already on iTunes so don't want to accidentally erase her phone.
She also needs some of the SMS messages taking off of her phone and saving either as they are or in some form of text file so they are readable in the future.
How can I retrieve all this data including the messages without losing anything and can it be done for free?
If you need anymore info please just ask and I'll try and pass it on to the best of my (limited) knowledge.
Thanks in advance!http://www.iphonebackupextractor.com/
SHe can also do a backup of her phone and it will save the text message, but she won't be able to view the text unless she restores to the backup.
Maybe you are looking for
-
How can I delete a system message?
Hi, how can I delete a system message which I have created in the Integration Builder Configuration in the menue bar "tools--> send system message? Thanls for your help. Regards Stefan
-
How does non-US citizen use iTunesConnect to publish iBook?
I want to publish an iBook using the iTunesConnect service. But when signing up, it asks for my US Tax ID. As a non-US citizen, I obviously don't have one of these. Does this mean I can't use the service? Is there a way around this problem?
-
Problem with hidden objects when moving layers, groups or artboards
Hi there, I am using Illustrator CS5.5 on a Mac. Sometimes, after moving stuff around (groups, layers or artboards), I notice that hidden objects didn't move with everything else. Does somebody knows how this can be if no objects are locked ? I canno
-
I have to double click to read message and see pictures
I hit something and it change how I see my mail. Before the mail would come in and I'd click once. The mail was opened and stayed open. Same with sent mail. I could see the message or picture after I sent it. Now I just have columns of names where th
-
Is there any store that sell MBP with anti-glare display?
I googled, but I can't find any store which sell those version. Is those version sell only at Apple Store? My location is in Japan now.