READ TABLE to read data records from internal table in SAP ABAP.

There are three ways to read records from the internal table.

  1. READ TABLE
  2. TABLE EXPRESSIONS
  3. LOOP AT

1.READ TABLE: – It is used to read only one record from the internal table.

2.TABLE EXPRESSIONS: – It is also used to read only one record from the internal table.

3.LOOP AT: – It is used to read more than one records from the internal table.

Contact IDNameAddress
101MikeStreet 10
102TomStreet 12
Database Table : ZTT_DB_TABLE1
  • WITH INDEX: –

Data lt_internal_table TYPE TABLE OF ztt_db_table1

SELECT *FROM ztt_db_table1 INTO TABLE lt_internal_table

READ TABLE lt_internal_table ASSIGNING FIELD_SYMBOL(<ls_record>) INDEX 1

The above READ TABLE statement reads the first record of the internal table.

  • WITH KEY: –

READ TABLE lt_internal_table ASSIGNING FIELD_SYMBOL (<ls_rec>) WITH KEY Contact_ID = 102.

The above READ TABLE statement reads the record with contact id = 102.

  • WITH TABLE KEY: –

If “WITH TABLE KEY” is used, then the internal table must be fully specified. The Definition is specified fully when the key fields are mentioned. If the internal table is not specified fully with keys. Then the Read Table with Table key must be specified fully with all keys. Otherwise it gives the following syntax error ‘The key must be specified in full’.

DATA lt_itab TYPE TABLE OF ztt_db_table2 WITH NON-UNIQUE KEY Contact_id.

SELECT * FROM ztt_db_table2 INTO TABLE lt_itab.

READ TABLE lt_itab ASSIGNING FIELD_SYMBOL(<ls_rec>) WITH TABLE KEY contact_id = 102.

  • TRANSPORTING NO FIELDS: –

Using the Transporting no fields option, we can check the existence of the record. No record is assigned to field symbols or work area.

READ TABLE lt_internal_table TRANSPORTING NO FIELDS WITH KEY contact_id = 102.

If the above record exists, then it returns sy_subrc = 0.