Introduction to the Work Area of the header line of an ABAP internal table

Source: Internet
Author: User
Tags what header
Introduction to the Work Area of the header line of an ABAP internal table From http://zhouwubin.blogbus.com/logs/14351256.html

When I first learned ABAP and iternal table, I felt a mess.
I don't know what work area is, what header line is, and what occurs is.
I finally figured it out today (I am still too weak... BS)
So record it... save yourself and forget it later...

First, use the types keyword to define the type of a row as follows:
Types: Begin of line,
Field1 type I,
Field2 type I,
End of line.
The line here is equivalent to a custom type, indicating the field of a row ).
Here, one line has two fields: field1 and field2.

Then declare a work area:
Data WA type line.
My understanding of the concept of C ++ (which is the most popular with CPP ^) is,
Line is a class, while Wa is an object.

declare the internal table of line for each row:
data itab type line occurs 0.
currently, I have used occurs as a marker for distinguishing the workspace and internal tables.
occurs should have a deeper meaning, but I can only understand it now...
when we use the above method to declare an iternal table, we can choose whether there is a header line.
the above sentence does not contain the header line. change it to the following:
data itab type line occurs 0 with header line.
the difference between header line and header line is that header line can be used as a work area (refer to my previous log ).
there are two ways to operate itab:
1 ).
wa-field1 = 1.
wa-field2 = 2.
append wa to itab.
2 ).
itab-field1 = 1.
itab-field2 = 2.
append itab.
here, WA is the previously defined work area.
when there is a header line, either of these two methods can be used.
when no header line exists, only 1st types can be used.
in the 2nd cases, itab indicates a header line instead of an internal table.
because "Data itab type line occurs 0 with header line. "such declaration,
A header line with the same name as the internal table has been implicitly declared.
therefore, the occurs clause to declare an in-table may cause ambiguity (ambiguous ).
therefore, occurs is considered an old object. It is better to declare an internal table in the following way:
data itab type standard table of line.

There is also a way to declare an internal table:
Data: Begin of itab occurs 0,
Field1 type I,
Field2 type I,
End of itab.
In this way, the itab automatically has a header line with the same name.
It seems that there will be no such use as without header line or not with header line...
If there is no occurs 0, for example:
Data: Begin of itab,
Field1 type I,
Field2 type I,
End of itab.
This itab is not an inner table, but a structure that can be used as the work area of the itab.

The difference between the two keywords types and data.
Is there any difference between occurs.

This is easy to understand ~~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.