Internal Table: With or Without Header Line
If you are familiar with programming, you might find that array is a powerful tool provided by various programming languages. ABAP offers Internal Table to fulfill the functionality of array.
The obvious difference between general array concept in other various programming language and internal table lies in the way of accessing it. Direct access to internal table content is not provided, instead we use work area that hold a single line of the internal table.
There are two types of Internal Table declaration that differ the way of processing it.
- Internal Table With Header Line
- Internal Table without Header Line
Look at the following example to differentiate both types.
TYPES : BEGIN OF x_personnel,
id(10) TYPE C,
name(25) TYPE C,
END OF x_personnel.
DATA: t_itab1 TYPE STANDARD TABLE OF x_personnel WITH HEADER LINE,
t_itab2 TYPE STANDARD TABLE OF x_personnel,
d_personnel TYPE x_personnel.
To access all contents of an internal table we use the following code.
LOOP AT t_itab1. WRITE: / t_itab1-name. ENDLOOP. LOOP AT t_itab2 INTO d_personnel. WRITE: / d_personnel-name. ENDLOOP.
Both codes will return the same result. Notice that using header line, we could directly use the table variable name to access the table contents, whilst without header line, contents are accessed via a working area.
To access a single content with certain key, use following statements
READ TABLE t_itab1 WITH KEY id = '1234'. WRITE : t_itab1-name. READ TABLE t_itab1 INTO d_personnel WITH KEY id = '1234'. WRITE : d_personnel-name.
t_itab1 and d_personnel contain the first record found that matches the criteria.
Using header line can cause ambiguity in code, for example CLEAR t_itab2 means that you cleared entire contents of table t_itab2, whilst the statement CLEAR t_itab1 will only clear the contents of t_itab1 header. To clear the entire contents of internal table with header line, use brackets after variable statement, ex: CLEAR t_itab1[].
Though it may seem more simple and easy to use header line, for some cases it might be best not to use it to avoid ambiguity and to improve the readability of the program.
References:
SAP Library – ABAP Programming : Internal Tables
sap.mis.cmich.edu
Thanks
You’re very much welcome
Very good example
very nice….