Skip to content Skip to sidebar Skip to footer

Convert Select-endselect In For All Entries With More Table

I would like to convert this SELECT-ENDSELECT into FOR ALL ENTRIES to have better performance. LOOP AT it_zgd_check_smc into wa_zgd_check_smc. SELECT * FROM ever I

Solution 1:

To get rid of the SELECT - ENDSELECT you can simply use INTO TABLE and loop over it afterwards. This is usually faster and you can do it (almost) every time.

    data: lt_ever liketableof wa_ever.
    LOOP AT it_zgd_check_smc into wa_zgd_check_smc.
      SELECT*FROM ever
        INTOTABLE lt_ever
        WHERE anlage  EQ wa_euiinstln-anlage
        AND   einzdat <= wa_zgd_check_smc_st-data_inizio
        AND   auszdat >= wa_zgd_check_smc_st-data_inizio.
     LOOP AT lt_ever INTO wa_ever.
       "Put here what was in the SELECT - ENDSELECT previously.
     ENDLOOP.
   ENDLOOP.

Then you could use FOR ALL ENTRIES to get rid of one of the outer loops. If you use this, you can simply replace the workarea with the table. But you should make sure, that the table you're using is not empty. Otherwise the WHERE statement will act like an empty range (in other words, it will be ignored), so it gives you all entries from the database. So it would give you something like this:

    data: lt_ever liketableof wa_ever.
    
    IF it_zgd_check_smc_st ISNOT INITIAL.
      SELECT*FROM ever
        INTOTABLE lt_ever
        FORALL ENTRIES IN it_zgd_check_smc_st
        WHERE anlage  EQ wa_euiinstln-anlage
        AND   einzdat <= it_zgd_check_smc_st-data_inizio
        AND   auszdat >= it_zgd_check_smc_st-data_inizio.
     loop at lt_ever into wa_ever.
       "Put here what was in the SELECT - ENDSELECT previously.
     endloop.
   ENDIF.

You can't use a second table with for all entries, but you could build a range for the ANLAGE - field. Just make sure you don't use an emtpy range again.

DATA: lt_ever LIKETABLEOF wa_ever.
DATA: lr_anlage TYPE RANGEOF anlage.
DATA: lrs_anlage LIKE LINE OF lr_anlage.

lrs_anlage-sign ='I'.
lrs_anlage-option ='EQ'.
LOOP AT euiinstln INTO wa_euiinstln.
  lrs_anlage-low = wa_euiinstln-anlage.
  APPEND lrs_anlage TO lr_anlage.
ENDLOOP.


IF it_zgd_check_smc_st ISNOTINITIALAND
   lr_anlage ISNOT INITIAL.
  SELECT*FROM ever
    INTOTABLE lt_ever
    FORALL ENTRIES IN it_zgd_check_smc_st
    WHERE anlage  IN lr_anlage
    AND   einzdat <= it_zgd_check_smc_st-data_inizio
    AND   auszdat >= it_zgd_check_smc_st-data_inizio.
  LOOP AT lt_ever INTO wa_ever.
    "Put here what was in the SELECT - ENDSELECT previously.
  ENDLOOP.
ENDIF.

I don't know what the code is supposed to do, so I don't know how much of this is actually usefull for you. Not builing the range and looping over the euiinstln - table should be just as fast, since the EVER - Database should have an Index on the anlage - field anyways.

Post a Comment for "Convert Select-endselect In For All Entries With More Table"