I have pasted the codes below is the Stored Procedure and the values feed from the Front-end screen to the DB2 StroedProc and fetching the values from the DB2 tables,.The question is why do this query taking more than 30 minutes to display the result...the datas are also somewhat 50k records
SELECT
DISTINCT
sam.Place
, sam.NO_mode_name
, sam.NO_mob_name
, sam.NO_disp_name
, sam.NO_rate_type
, sam.ran_date
, sam.NO_pers_CNTL
FROM
cus_frt_tab sam,
Pen_tab ben
WHERE
(sam.NO_mob_name BETWEEN :WS-ALL-mob-LOW
AND :WS-ALL-mob-HIGH)
AND (sam.NO_mode_name BETWEEN :WS-ALL-mode-LOW
AND :WS-ALL-mode-HIGH)
AND (sam.NO_disp_name BETWEEN :WS-ALL-disp-LOW
AND :WS-ALL-disp-HIGH)
AND sam.NO_rate_type IN ( :LT-DEL ,
:LT-INS ,
:LT-UPD )
AND DATE (sam.ran_date)
BETWEEN :WS-START-DT
AND :WS-END-DT
AND
(
(:WS-ALL-DISTR = :LT-ALL) OR
( sam.PLACE IN (:DISTR01,
:DISTR02,
:DISTR03,
:DISTR04,
:DISTR05) )
)
AND
(
(:WS-ALL-CUS = :LT-ALL) OR
(BEN.CD_CONSUMER IN (:CONS01,
:CONS02,
:CONS03,
:CONS04,
:CONS05) )
)
AND sam.NO_mob_name = ben.NO_mob_name
AND sam.NO_mode_name = ben.NO_mode_name
AND sam.NO_disp_name = ben.NO_disp_name
AND sam.NO_pers_CNTL = ben.sam.NO_pers_CNTL
ORDER BY
sam.Place
,sam.NO_mode_name
,sam.NO_mob_name
,sam.NO_disp_name
,sam.NO_pers_CNTL
,sam.Phy_TYPE
,sam.DT_IN DESC
DISTINCT
sam.Place
, sam.NO_mode_name
, sam.NO_mob_name
, sam.NO_disp_name
, sam.NO_rate_type
, sam.ran_date
, sam.NO_pers_CNTL
FROM
cus_frt_tab sam,
Pen_tab ben
WHERE
(sam.NO_mob_name BETWEEN :WS-ALL-mob-LOW
AND :WS-ALL-mob-HIGH)
AND (sam.NO_mode_name BETWEEN :WS-ALL-mode-LOW
AND :WS-ALL-mode-HIGH)
AND (sam.NO_disp_name BETWEEN :WS-ALL-disp-LOW
AND :WS-ALL-disp-HIGH)
AND sam.NO_rate_type IN ( :LT-DEL ,
:LT-INS ,
:LT-UPD )
AND DATE (sam.ran_date)
BETWEEN :WS-START-DT
AND :WS-END-DT
AND
(
(:WS-ALL-DISTR = :LT-ALL) OR
( sam.PLACE IN (:DISTR01,
:DISTR02,
:DISTR03,
:DISTR04,
:DISTR05) )
)
AND
(
(:WS-ALL-CUS = :LT-ALL) OR
(BEN.CD_CONSUMER IN (:CONS01,
:CONS02,
:CONS03,
:CONS04,
:CONS05) )
)
AND sam.NO_mob_name = ben.NO_mob_name
AND sam.NO_mode_name = ben.NO_mode_name
AND sam.NO_disp_name = ben.NO_disp_name
AND sam.NO_pers_CNTL = ben.sam.NO_pers_CNTL
ORDER BY
sam.Place
,sam.NO_mode_name
,sam.NO_mob_name
,sam.NO_disp_name
,sam.NO_pers_CNTL
,sam.Phy_TYPE
,sam.DT_IN DESC
Cobol Declaration
05 WS-ALL-mob-LOW PIC X(09) VALUE SPACES.
05 WS-ALL-mob-HIGH PIC X(09) VALUE SPACES.
05 WS-ALL-mode-LOW PIC X(07) VALUE SPACES.
05 WS-ALL-mode-HIGH PIC X(07) VALUE SPACES.
05 WS-ALL-disp-LOW PIC X(08) VALUE SPACES.
05 WS-ALL-disp-HIGH PIC X(08) VALUE SPACES.
05 LT-DEL PIC X(06) VALUE "DELETE".
05 LT-INS PIC X(06) VALUE "INSERT".
05 LT-UPD PIC X(06) VALUE "UPDATE".
05 LT-ALL PIC X(01) VALUE "#".
05 WS-START-DT PIC X(10) VALUE SPACES.
05 WS-END-DT PIC X(10) VALUE SPACES.
05 WS-ALL-DISTR PIC X(01) VALUE SPACES.
05 WS-ALL-CUS PIC X(01) VALUE SPACES.
05 WS-DISTR-LIST.
10 DISTR01 PIC X(05) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 DISTR02 PIC X(05) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 DISTR03 PIC X(05) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 DISTR04 PIC X(05) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 DISTR05 PIC X(05) VALUE SPACES.
05 WS-CONS-CODES.
10 CONS01 PIC X(04) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 CONS02 PIC X(04) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 CONS03 PIC X(04) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 CONS04 PIC X(04) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 CONS05 PIC X(04) VALUE SPACES.
05 WS-ALL-mob-HIGH PIC X(09) VALUE SPACES.
05 WS-ALL-mode-LOW PIC X(07) VALUE SPACES.
05 WS-ALL-mode-HIGH PIC X(07) VALUE SPACES.
05 WS-ALL-disp-LOW PIC X(08) VALUE SPACES.
05 WS-ALL-disp-HIGH PIC X(08) VALUE SPACES.
05 LT-DEL PIC X(06) VALUE "DELETE".
05 LT-INS PIC X(06) VALUE "INSERT".
05 LT-UPD PIC X(06) VALUE "UPDATE".
05 LT-ALL PIC X(01) VALUE "#".
05 WS-START-DT PIC X(10) VALUE SPACES.
05 WS-END-DT PIC X(10) VALUE SPACES.
05 WS-ALL-DISTR PIC X(01) VALUE SPACES.
05 WS-ALL-CUS PIC X(01) VALUE SPACES.
05 WS-DISTR-LIST.
10 DISTR01 PIC X(05) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 DISTR02 PIC X(05) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 DISTR03 PIC X(05) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 DISTR04 PIC X(05) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 DISTR05 PIC X(05) VALUE SPACES.
05 WS-CONS-CODES.
10 CONS01 PIC X(04) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 CONS02 PIC X(04) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 CONS03 PIC X(04) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 CONS04 PIC X(04) VALUE SPACES.
10 FILLER PIC X(01) VALUE SPACES.
10 CONS05 PIC X(04) VALUE SPACES.
iN PROCEDURE DIVISION
;
;
MOVE LINK-DISTR-TEXT TO WS-DISTR-LIST
WS-ALL-DISTR
MOVE LINK-CONS-LIST TO WS-ALL-CONS
WS-CONS-CODES
IF WS-ALL-CONS = LT-ALL
MOVE SPACES TO WS-CONS-CODES
ELSE
UNSTRING
LINK-CONS-LIST
DELIMITED BY ','
INTO
CONS01,
CONS02,
CONS03,
CONS04,
CONS05
END-UNSTRING
END-IF
WS-ALL-DISTR
MOVE LINK-CONS-LIST TO WS-ALL-CONS
WS-CONS-CODES
IF WS-ALL-CONS = LT-ALL
MOVE SPACES TO WS-CONS-CODES
ELSE
UNSTRING
LINK-CONS-LIST
DELIMITED BY ','
INTO
CONS01,
CONS02,
CONS03,
CONS04,
CONS05
END-UNSTRING
END-IF
Please help me what are possibilites to reduce the Query running time....and let me know that, is delaying the running time if we used the BETWEEN and OR in the Query