cancel
Showing results for 
Search instead for 
Did you mean: 

Faster loop?

0 Kudos
1,304

Hello,

is there a way to make a loop faster or to replace it by something faster? I know of 'for all entries' but what if the two fields aren't compatible?

SELECT rqposname RQIDENT
INTO TABLE t_output
FROM tsp01
WHERE rqposname EQ lv_email.

LOOP AT t_output ASSIGNING FIELD-SYMBOL(<fs2>).
SELECT SINGLE jobname progname variant listident
INTO ( <fs2>-jobname, <fs2>-progname, <fs2>-variant, <fs2>-listident )
FROM tbtcp
WHERE listident EQ <fs2>-rqident
AND listident NE '0'.
ENDLOOP.

This takes a few minutes even though there are "only" 1300 rows in t_output.

Any Tips?

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

former_member182371
Active Contributor

maybe a JOIN like in the thread below?

Select Join problem

Best regards,

Pablo

0 Kudos

Yes I did try that

but unfortunaly listident and rqident are not the same type.

former_member182371
Active Contributor
0 Kudos

Hi,

instead of TSP01(Spool Requests) ,

would TBTC_SPOOLID(Background Processing Spool IDs Table) be a valid table?

(check report BTCAUX05)

BEst regards,

Pablo

Sandra_Rossi
Active Contributor

This works for me (ABAP >= 7.50 - CAST of type INT4 or NUMC):

DATA lv_email TYPE tsp01-rqposname.
SELECT s~rqident,                                       " <========== INT4
       j~listident,                                     " <========== NUMC (10)
       s~rqposname, j~jobname, j~progname, j~variant
    FROM tsp01 AS s
        INNER JOIN tbtcp AS j
            ON CAST( j~listident AS INT4 ) = s~rqident
    WHERE s~rqposname = @lv_email
      AND j~listident <> '0000000000'
INTO TABLE @DATA(t_output).
0 Kudos

I've just moved out my selects with an "for all entrys" that made it faster.

Answers (5)

Answers (5)

ascm
Explorer

Two CDS!

First:

define view ztbtcp 
  as select from tbtcp
{
  cast ( listident as abap.int4 ) as listident,
  variant,
  progname,
  jobname
}

Second:

define view zoutput
   as select from tsp01
    left outer join ztbtcp
    on tsp01.rqident = ztbtcp.listident 
{
rqposname,
listident,
variant,
progname,
jobname
}
where listident <> 0

If you need more fields in the output-structure, define them in the second CDS.

former_member1716
Active Contributor

Hello Nils Bla,

if not CDS views, you can use the below code as a solution. This should work fine.

TYPES: BEGIN OF ty_tsp01,
         rqposname TYPE tsp01-rqposname,
         rqident   TYPE tbtcp-listident,
       END OF ty_tsp01.

DATA: lv_email TYPE tsp01-rqposname,
      ls_tsp01 TYPE ty_tsp01,
      lt_tsp01 TYPE STANDARD TABLE OF ty_tsp01.

SELECT rqposname, rqident
FROM tsp01
WHERE rqposname EQ @lv_email
INTO TABLE @DATA(t_tsp01).
IF sy-subrc EQ 0.
  SORT t_tsp01 BY rqident.
  LOOP AT t_tsp01 INTO DATA(ls_temp).
    CLEAR: ls_tsp01.
    ls_tsp01-rqposname = ls_temp-rqposname.
    ls_tsp01-rqident   = ls_temp-rqident.
    APPEND ls_tsp01 TO lt_tsp01.
  ENDLOOP.
ENDIF.

SELECT jobname,
       progname,
       variant,
       listident
FROM tbtcp
FOR ALL ENTRIES IN @lt_tsp01
WHERE listident = @lt_tsp01-rqident AND
      listident NE 0
INTO TABLE @DATA(t_tbtcp).
IF sy-subrc EQ 0.
  SORT t_tbtcp BY listident.
ENDIF.

Regards!

matt
Active Contributor

I know of 'for all entries' but what if the two fields aren't compatible?

Why not type the internal table so they are compatible?

shakirali7
Participant
0 Kudos

Hi !

Do make a Database View joining both tables with your desire condition and then use it appropriatly in you programe.

Hope it helps,

best regards,

Shakir.

Tomas_Buryanek
Active Contributor
0 Kudos

SELECT inside LOOP is generally bad for performance! Always try to SELECT your data in one DB fetch if possible.

In this case I would suggest simple SELECT with JOIN of the two tables.

Yes I did try that

but unfortunaly listident and rqident are not the same type.

Tomas_Buryanek
Active Contributor
0 Kudos

teaman I see, in this case you can either create a table for FOR ALL ENTRIES or range table. And you will have to retype the rqident to listident.

But now I see another and bigger problem - your both conditions (only the one you are using) are not index nor key fields:

  • TBTCP-LISTIDENT
  • TSP01-RQPOSNAME