SAP ABAP Reading Internal Tables - SAP ABAP

How do we read internal tables? What is the criteria for reading the intrnal tables?

Whenever user wants to view data which is inserted in the table within the program, a specific syntax is followed i.e READ TABLE statement which is used to read the lines of a table. Here is the following syntax-

In this syntax, the <work_area_itab> expression represents a work area that is compared with the line type of the <internal_table> table. here, you can specify a search key, but a table key is not applicable, within the READ statement by using the WITH KEY clause, as shown in the following syntax −

Here, you can see the entire line in a table is specified with a search key. So, the content of the entire line of the table is compared with the content of the <internal_tab_field> field. If the values of the field don’t match with the line type of the table, these values are transferred according to the line type of the table. so, with the help of the search key you can find out the entries in an internal table. And it also tells us where it is a single field or an internal table type which implies unstructured line.

The following syntax of the READ statement is used to specify a work area or field symbol by using the COMPARING clause −

When the COMPARING clause is used, before the fields being transported to the work area, these specified table fields <F1>, <F2>....<Fn> of the structured line type are compared with the corresponding fields of the work area. To compare all the components the SAP system uses ALL FIELDS clause. So, when the SAP system confirms the entry with the specific key, the SY-SUBRC variable is set to value 0. If the SAP system does not find the entry then the value is set to 2 or 4. This is applicable when the contents in the field are not same. Despite the result of the comparison among the fields, as and when the SAP system finds an entry it copies the entry into the specified work area.


The above code produces the following output −

In the above example, my table is an internal table of the hashed table type, possessing Record1 as the work area and ColP as the unique key. Initially, my table is populated with six lines, where the ColP field contains the values of the SY-INDEX variable and the ColQ field contains (SY-INDEX + 5) values.

The Record1 work area is populated with CoIP and ColO fields which are coded with 4 and 12 values respectively. The READ statement then does its work by reading the line of the table by comparing the value of the ColP key field with the value in the Record1 work area by using the COMPARING clause and further copies the content of the read line in the work area. After completing the comparison and reading the lines of the fields it displays the value of the SY-SUBRC variable as 2 because when the value in the ColP field is 4, the value in the ColQ is not 12, but 9.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status