01-27-2014 4:19 PM
Hallo.
I'm a newbie on ABAP.
I note a bad performance on the code:
SELECT COUNT(*)
FROM ltap AS a
INNER JOIN ltak AS b
ON a~lgnum EQ b~lgnum
AND a~tanum EQ b~tanum
INTO row_conf
WHERE a~lgnum EQ p_mag
AND a~pquit NE 'X'
AND a~nltyp EQ '916'
AND b~bdatu LE p_day.
How could I optimize it?
Could you give some suggest, please?
Thanks a lot for your help.
Mario
01-28-2014 7:46 AM
Hi Mario,
You are doing count on Item table and Header table using join. I think you need to break this query into two different part.
You can achive good performance using for all entries. Please try with sample code below
TYPES : begin of lty_ltak,
lgnum TYPE lgnum,
tanum TYPE tanum,
end of lty_ltak.
DATA : lt_ltak Type standard table of lty_ltak.
select lgnum
tanum
FROM ltak
INTO table lt_ltak
WHERE lgnum EQ p_mag
AND bdatu LE p_Day.
IF NOT lt_ltak is initial.
sort lt_ltak by lgnum tanum.
select count(*)
FROM ltap
INTO row_conf
for all entries in lt_ltak
where lgnum EQ lt_ltak-lgnum
and tanum EQ lt_ltak-tanum
and pquit NE 'X'
and nltyp EQ '916'.
ENDIF.
Or also you can go for fetch some records with key fields and count via Loop at item table.Also you can check the system variable SY-DBCNT ,may be your purpose solved by this.
Thanks
Deependra
01-28-2014 7:46 AM
Hi Mario,
You are doing count on Item table and Header table using join. I think you need to break this query into two different part.
You can achive good performance using for all entries. Please try with sample code below
TYPES : begin of lty_ltak,
lgnum TYPE lgnum,
tanum TYPE tanum,
end of lty_ltak.
DATA : lt_ltak Type standard table of lty_ltak.
select lgnum
tanum
FROM ltak
INTO table lt_ltak
WHERE lgnum EQ p_mag
AND bdatu LE p_Day.
IF NOT lt_ltak is initial.
sort lt_ltak by lgnum tanum.
select count(*)
FROM ltap
INTO row_conf
for all entries in lt_ltak
where lgnum EQ lt_ltak-lgnum
and tanum EQ lt_ltak-tanum
and pquit NE 'X'
and nltyp EQ '916'.
ENDIF.
Or also you can go for fetch some records with key fields and count via Loop at item table.Also you can check the system variable SY-DBCNT ,may be your purpose solved by this.
Thanks
Deependra