Select Single and Select up to 1 rows

Select single and Select up to 1 rows, What is the difference between Select Single and Select up to 1 rows in SAP ABAP ?

+ -

These statements are the part of reading data from database table.
By using SELECT SINGLE and SELECT UPTO 1 ROWS we can able to read single record from a database table .

SELECT SINGLE SELECT UP TO 1 ROWS
Used to read exact record from database table.

Used to read appropriate record from database table.
To read exact record from database table we need to provide all key fields.

We can read appropriate record from database table, we may not need to provide all key fields.
This statement should be used only if all the key fields are available.

This statement should be used only if we have some key fields or no key fields.
Syntax :SELECT SINGLE * FROM DATABASETABLE INTO WA WHERE ALL KEY FIELDS 
Syntax: SELECT * FROM DATABASETABLE INTO WA UP TO 1 ROWS WHERE ALL KEY FIELDS/SOME FIELDS.
            ENDSELECT.
This is very fast when compared to SELECT UPTO
This is slow.

Example SELECT SINGLE

DATA : WA_MARA TYPE MARA. " Declare work area

SELECT SINGLE * FROM MARA INTO WA_MARA WHERE MATNR = '0001'. " Read exact record from MARA table

write : wa_mara-matnr, wa_mara-mtart, wa_mara-meins. " Print data to screen

Example SELECT UPTO

DATA : WA_MARA TYPE MARA. " Declare work area

SELECT * FROM MARA INTO WA_MARA UP TO 1 ROWS WHERE MTART = 'FERT'. " Read appropriate record from MARA table here MTART is not a keyfield

ENDSELECT.
We can read multiple records using SELECT UPTO
DATA : IT_MARA TYPE TABLE OF MARA. " Declare internal table
DATA : WA_MARA TYPE MARA. " Declare work area

SELECT * FROM MARA INTO WA_MARA UP TO 50 ROWS WHERE MTART = 'FERT'. " Read 50 appropriate records from MARA table here MTART is not a keyfield
ENDSELECT.
LOOP AT IT_MARA INTO WA_MARA.
write :/ wa_mara-matnr, wa_mara-mtart, wa_mara-meins. " Print data to screen
ENDLOOP.

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 92 People out of 97 think this lesson helpful


    Lesson Navigation

    Internal Tables and Work Areas← Previous Lesson
    Next Chapter →