Application Development and Automation 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: 
Read only

regarding execution time

Former Member
0 Likes
1,382

when i am executing this code, it takes a lot of time. even though i hav checked temp[] whether it is initial. But do i need to check ltap[] because the data has been collected from temp to ltap.Also temp has data and since no record matches the for all entries fetches all the data from ltak.

IF NOT lt_temp[] IS INITIAL.

LOOP AT lt_temp INTO ls_temp.

COLLECT ls_temp INTO lt_ltap.

ENDLOOP.

FREE lt_temp.

SELECT lgnum "Warehouse Number

tanum "Transfer order number

FROM ltak

INTO TABLE lt_ltak1

FOR ALL ENTRIES IN lt_ltap

WHERE lgnum EQ lt_ltap-lgnum

AND tanum EQ lt_ltap-tanum

AND trart EQ 'A'

OR trart EQ 'X'.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,350

After the FREE statement, try:


SORT lt_ltap by lgnum tanum.
DELETE ADJACENT DUPLICATES FROM lt_ltap comparing lgnum tanum.

Then do the SELECT.

Rob

14 REPLIES 14
Read only

Former Member
0 Likes
1,351

After the FREE statement, try:


SORT lt_ltap by lgnum tanum.
DELETE ADJACENT DUPLICATES FROM lt_ltap comparing lgnum tanum.

Then do the SELECT.

Rob

Read only

0 Likes
1,350

it has been sorted afterwards.

do i need to check table ltap for initial since the select query doesnt match any condition and all the data from table ltak is being extracted which is taking a lot of time

Read only

0 Likes
1,350

You need to sort it before.

If there is data in the original table, there will be data in the final table.

Rob

Read only

0 Likes
1,350

but isnt it a rule that when u do for all entries for any table, that table has to be checked whether it is initial or not.

Read only

0 Likes
1,350

You have to know that there is data in the table. You checked the original table, so when you move data into the work table, there must be data there as well.

Rob

Read only

Former Member
0 Likes
1,350

Hi,

From the look of your code it seems that your internal table is being built from LTAP (Transfer Order Item) , and then you are reading LTAK (TO Header), could you do a JOIN between LTAP and LTAK?

Read only

Former Member
0 Likes
1,350

don'tdo like looping , collocting , free ..etc .

just write 2 select queries using FOR ALL ENTRIES it will take care of it see. i am using the sy-subrc .

*Select FOR ALL ENTRIES command
SELECT bukrs belnr gjahr bldat monat budat xblnr awtyp awkey
  UP TO 100 ROWS
  FROM bkpf
  INTO TABLE it_bkpf.

<b>IF sy-subrc EQ 0.</b>

* The FOR ALL ENTRIES comand only retrieves data which matches
* entries within a particular internal table.
  SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
         dmbtr mwart hwbas aufnr projk shkzg kokrs
    FROM bseg
    INTO TABLE it_bseg
    FOR ALL ENTRIES IN it_bkpf
    WHERE bukrs EQ it_bkpf-bukrs AND
          belnr EQ it_bkpf-belnr AND
          gjahr EQ it_bkpf-gjahr.

<b>ENDIF.</b>

reward points if it is usefull ...

Girish

Read only

Former Member
0 Likes
1,350

Besides all other points already mentioned here: Please keep in mind that the "FOR ALL ENTRIES IN" statement translates to the database as:

WHERE TANUM = '111123454566' OR

TANUM = '111123454567' OR

TANUM = '111123454568' OR

.....

This makes only sense if your internal table lt_ltap contains just a handful of records. You can even get a runtime error as the length of the SQL statement created is limited (depending on the DB)

Of course I don't know what your program is supposed to do, but it might be smarter to check only against LGNUM (which are most likely just a few records) and do the checking for the TANUM in memory.

Regards

Frank

Read only

0 Likes
1,350

Frank - I think this is is a problem for RANGES, not FOR ALL ENTRIES (at least in a DB2 or Oracle environment). I created a table with 500K entries and used it with FOR ALL ENTRIES and it didn't dump. I think the SAP kernel is better at translating FOR ALL ENTRIES for the database than it is for RANGES.

Rob

Read only

0 Likes
1,350

Hi Rob,

that's quite amazing. I once created an itab with just 8K entries and the FOR ALL ENTRIES statement dumped on me - and this was a DB2 on a z390.

Is the max length of an SQL statement a system setting ?

Regards

Frank

Read only

0 Likes
1,350

Frank - What was your error message?

Rob

Read only

Former Member
0 Likes
1,350

As this is a code sample, make sure that your ENDIF is after the select.

We have all assumed that the problem is with the select, BUT the problem may be with the COLLECT. Have the definition of the LT_LTAP table consist only of the fields lgnum, tanum and an interger field. This way you eliminate your duplicates, quickly.

MattG.

Read only

Former Member
0 Likes
1,350

Hi,

Here collect statements takes very much time. So remove this and use any other technique to get your desired result instead of collect.

Reward points if useful,

Aleem.

Read only

KjetilKilhavn
Active Contributor
0 Likes
1,350

First of all, please use the <b>Code</b> button when you paste code. It makes it much easier to read.

I think your problem is in your select statement.

SELECT lgnum "Warehouse Number
       tanum "Transfer order number
FROM ltak
INTO TABLE lt_ltak1
FOR ALL ENTRIES IN lt_ltap
WHERE lgnum EQ lt_ltap-lgnum
AND tanum EQ lt_ltap-tanum
AND trart EQ 'A'
OR trart EQ 'X'.

Should be changed to

SELECT lgnum "Warehouse Number
       tanum "Transfer order number
FROM ltak
INTO TABLE lt_ltak1
FOR ALL ENTRIES IN lt_ltap
WHERE lgnum EQ lt_ltap-lgnum AND
      tanum EQ lt_ltap-tanum AND
      (    trart EQ 'A'
        OR trart EQ 'X' ).

I always write ANDs at the right side and ORs at the left side of WHERE clauses to remind me that ORs start a new clause, while ANDs are a continuation of an existing clause - adding additional constraints.

Message was edited by Kjetil Kilhavn:

But then again, I could of course be wrong. Perhaps you intend to select all entries where TRART = 'X' irrespective of the LGNUM and TANUM values. I don't think so, but if you do this on purpose you must expect poor performance since TRART is not an indexed field.


Kjetil Kilhavn (Vettug AS) - ABAP developer since Feb 2000, but will probably never be a Rockstar developer