2006 Dec 06 7:40 PM
Reg. the statement 'select single' , does it always retrieve the first record from the table or just some random single record or the last record?
Also with the statement ' read table itab' for the internal table?
Thank you,
Krishen
2006 Dec 06 7:42 PM
Hi,
Yes...it always retrieve the first record from the table that satisfies the where clause condition.
Same for the internal table also..
Check this example for internal table.
DATA: BEGIN OF itab OCCURS 0,
matnr TYPE matnr,
date TYPE sydatum,
END OF itab.
itab-matnr = '123'.
itab-date = sy-datum.
APPEND itab.
CLEAR itab.
itab-matnr = '123'.
itab-date = sy-datum + 1.
APPEND itab.
CLEAR itab.
READ TABLE itab WITH KEY matnr = '123'.
IF sy-subrc = 0.
WRITE: / itab-date, ' Row no - ', sy-tabix.
ENDIF.
Thanks,
Naren..
2006 Dec 06 7:42 PM
Hi,
Yes...it always retrieve the first record from the table that satisfies the where clause condition.
Same for the internal table also..
Check this example for internal table.
DATA: BEGIN OF itab OCCURS 0,
matnr TYPE matnr,
date TYPE sydatum,
END OF itab.
itab-matnr = '123'.
itab-date = sy-datum.
APPEND itab.
CLEAR itab.
itab-matnr = '123'.
itab-date = sy-datum + 1.
APPEND itab.
CLEAR itab.
READ TABLE itab WITH KEY matnr = '123'.
IF sy-subrc = 0.
WRITE: / itab-date, ' Row no - ', sy-tabix.
ENDIF.
Thanks,
Naren..
2006 Dec 06 7:43 PM
Hi,
The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
This is applied as well to read table <internal table>.
Regards,
Ferry Lianto
2006 Dec 06 7:47 PM
Hi,
Actually, the purpose of the 'Select single' statement is to get the single record from the database table. For this you need to pass all the key fields to the database table. Otherwise it will give the first record that matches the selection criteria.
For the 'Read table itab' also, if there is only one match for the selection criteria, that record is read. If there are multiple records matches with the selection criteria,
we will get the first record.
Thanks,
Sreenivas
2006 Dec 06 8:06 PM
Hi,
This usually depends on the operating systems' behaviour. Usually it is First record. But may change sometimes.
Regards,
Vara