What is WITH HEADER LINE used for in ABAP?

11,050

Solution 1

The question should be "What was WITH HEADER LINE used for in ABAP". You should see them only in legacy code. They are allowed only outside classes and are obsolete anyway.

Answering your question. It is both. It declares an internal table customer_tab[] and a structure customer_tab.

You could then do such "amazing" things like.

 LOOP AT customer_tab. "loops at tab CUSTOMER_TAB and stores current record in header line structure CUSTOMER_TAB. :]
   "do something with header line
 END LOOP.

or

 APPEND customer_tab.

As you see it is shorter and quite appealing to be used for its brevity. Though it is hardly readable and confusing, therefore marked as obsolete.

Oooops and one point more! You should also learn the difference between

CLEAR customer_tab.

and

REFRESH customer_tab.

Solution 2

Both of the declarations you are showing, create a table with a header line. The first declaration does not specifically state 'WITH HEADER LINE', but it does create a work area and a table just as if you used the 'WITH HEADER LINE' statement too. See this SAP Help for information on header lines. The documentation you are referencing is obsolete syntax. You will see it due to legacy code, so you need to understand it but avoid using this syntax.

Share:
11,050
Koray Tugay
Author by

Koray Tugay

Crappy software developer who does not like self-promoting profiles.

Updated on June 26, 2022

Comments

  • Koray Tugay
    Koray Tugay almost 2 years

    I have been studying this book and quoting from it:

    DATA: BEGIN OF CUSTOMER_TAB OCCURS 5,
             KUNNR TYPE KNA1-KUNNR,
             NAME1 TYPE KNA1-NAME1,
          END OF CUSTOMER_TAB.
    
    This declaration creates an internal table and a structure using the same name: CUSTOMER_TAB.
    

    And then in the following pages:

    Declaring Both an Internal Table and a Structure by Referring to a Structured 
    Local/Global TYPE or Local/Global Structure
    
    DATA <internal table name> {TYPE|LIKE} <structure name> OCCURS <number> WITH HEADER LINE.
    
    WITH HEADER LINE is a reserved key phrase. The addition of this phrase creates a structure.
    

    I am confused at this moment. Is the first example declaring only an Internal Table or an Internal Table and a Structure with the same name?