‎2012 Dec 03 11:24 AM
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.
‎2012 Dec 03 12:28 PM
‎2012 Dec 03 1:32 PM
‎2012 Dec 04 5:19 AM
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.
‎2012 Dec 04 6:29 AM
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
‎2012 Dec 04 5:15 PM
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