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

Question reg. select and read

Former Member
0 Likes
658

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
635

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..

4 REPLIES 4
Read only

Former Member
0 Likes
636

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..

Read only

Former Member
0 Likes
635

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

Read only

Former Member
0 Likes
635

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

Read only

Former Member
0 Likes
635

Hi,

This usually depends on the operating systems' behaviour. Usually it is First record. But may change sometimes.

Regards,

Vara