Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Optimize inner join code on LTAP and LTAK

mario_bisonti2
Participant
0 Kudos

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

1 ACCEPTED SOLUTION

deependra_shekhawat3
Contributor
0 Kudos

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

1 REPLY 1

deependra_shekhawat3
Contributor
0 Kudos

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