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

Using internal table & Loop VS. select & EndSelect

Former Member
0 Likes
1,874

Hi,

Please help me to know which selection is better:

option 1:

    SELECT MAX( LETZTZUG ) MAX( LETZTABG ) MAX( LETZTVER ) MAX( LETZTBEW )

    INTO   table lt_dates

    FROM   S032

    WHERE  VRSIO = '000'

      AND  matnr = lwa_output-IDNRK

      AND  werks = lwa_output-werks.

    loop at lt_dates into lwa_dates.

      IF lwa_dates_max-LETZTZUG < lwa_dates-LETZTZUG.

        lwa_dates_max-LETZTZUG = lwa_dates-LETZTZUG.

      ENDIF.

      IF lwa_dates_max-LETZTABG < lwa_dates-LETZTABG.

        lwa_dates_max-LETZTABG = lwa_dates-LETZTABG.

      ENDIF.

      IF lwa_dates_max-LETZTVER < lwa_dates-LETZTVER.

        lwa_dates_max-LETZTVER = lwa_dates-LETZTVER.

      ENDIF.

      IF lwa_dates_max-LETZTBEW < lwa_dates-LETZTBEW.

        lwa_dates_max-LETZTBEW = lwa_dates-LETZTBEW.

      ENDIF.

    ENDLOOP.

Option 2:

    SELECT MAX( LETZTZUG ) MAX( LETZTABG ) MAX( LETZTVER ) MAX( LETZTBEW )

    INTO (lwa_output-LETZTZUG , lwa_output-LETZTABG , lwa_output-LETZTVER , lwa_output-LETZTBEW )

    FROM   S032

    WHERE  VRSIO = '000'

      AND  matnr = lwa_output-IDNRK

      AND  werks = lwa_output-werks.

Thanks.

5 REPLIES 5
Read only

SharathYaralkattimath
Contributor
0 Likes
1,158

option 1

Read only

0 Likes
1,158

Hi Sharath

can you explain the reason please?

Read only

0 Likes
1,158

Please read ABAP documentation , this is basics that we should get the data at one go into table, & then you can process the internal table as per your needs.

Read only

former_member189631
Active Contributor
0 Likes
1,158

Hi Arieh,

The first option queries the table and get the data from db only once.

The second option queries the table and get the data from the db in multiple times.

In ABAP program we should try to reduce the db hits as much as possible to improve the performance of the application. In your case, the first option is more efficent than second option when there is more data on the table.

Ram

Read only

Clemenss
Active Contributor
0 Likes
1,158

The professional answer is:

It depends.

And I don't understand your code:

Option 1 with SELECT MAX... means to put the load on the database (which is almost always slower than the ABAP runtime processor). So why then loop at the table to determine max. values?

AND: Never use a LOOP INTO workarea, always use LOOP ASSIGNING <field-symbol> for the sake of performance.

SELECT ... ENDSELECT is better than people say. It saves you memory and the performance is enhanced by the system by reading blocks of data into invisible internal tables and processing them between SELECT and ENDSELECT.

If you don't write another SELECT between SELECT and ENDSELECT, then everything is fine.

Regards

Clemens