Read Table and Describe Table


There are different kinds of fetching the records of internal table. One of these is READ TABLE statement. By using READ TABLE we can fetch only the first record from the table. Hence it can fetch a single record always. Read table statement can be used to any type of table to fetch the record. Now if the table is sorted then we can use BINARY SEARCH to fetch record. Now fetching records may take time but if we use BINARY SEARCH then the system performance will improve. Obviously if the table is sorted then the fetching operation will be faster.

We can describe an internal table as well. If the table stores 300 records then the system will inform us by the system field SY-TFILL. Here note that SY-TFILL will not work alone. We need to describe the table first then we can get data from SY-TFILL field.

DESCRIBE TABLE itab.
WRITE: / 'Number of table records: ', sy-tfill.
Here we are describing the internal table itab. After that we are getting records from SY-TFILL.

REPORT  zabap_gui.

* Declaring the local structure of internal table
TYPES:
      BEGIN OF ty_tab,
        item     TYPE char10,
        quantity TYPE i,
        price    TYPE i,
      END OF ty_tab.

* Declaring the Standard internal table with non unique key
DATA:
      itab TYPE STANDARD TABLE OF ty_tab,
      wtab TYPE ty_tab.

* Entering records to each field
wtab-item = 'Rice'. wtab-quantity = 2. wtab-price = 80.

* Now one single row has been fulfilled with data
* Next appending one single row data into the table
APPEND wtab TO itab.

wtab-item = 'Suger'. wtab-quantity = 1. wtab-price = 90.
APPEND wtab TO itab.

wtab-item = 'Tea'. wtab-quantity = 1. wtab-price = 100.
APPEND wtab TO itab.

wtab-item = 'Rice'. wtab-quantity = 3. wtab-price = 150.
APPEND wtab TO itab.

wtab-item = 'Horlicks'. wtab-quantity = 1. wtab-price = 200.
APPEND wtab TO itab.

wtab-item = 'Suger'. wtab-quantity = 2. wtab-price = 70.
APPEND wtab TO itab.
SORT itab BY item.

WRITE:  /3 'Item',
        13 'Quantity(KG)',
        28 'Price(Rs)'.
WRITE / '=========================================='.
SKIP" Skipping one single line

READ TABLE itab INTO wtab WITH KEY item = 'Rice'
                                    BINARY SEARCH.
IF sy-subrc = 0.
  WRITE:  /3 wtab-item,
          12 wtab-quantity,
          25 wtab-price.
ENDIF.

SKIP.
WRITE '=========================================='.

DESCRIBE TABLE itab.
WRITE: / 'Number of table records: ', sy-tfill.








Though the output is showing only one record the table still contains six records.

Share this

Related Posts