问题
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?
回答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.
回答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.
回答3:
types:
begin of typ_functions,
funcname type rs38l_fnam,
pname type pname,
fmode type fmode,
stext type rs38l_ftxt,
end of typ_functions,
typ_functions_t type standard table of typ_functions initial size 0.
data:
"Global Structure using structure type
gs_function type typ_functions,
"Global Table using table type typ_functions_t
gt_functions type typ_functions_t,
"Global Table using data dictionary structure
gt_exp type standard table of rsdsexpr initial size 0.
My personal preference is to use syntax as shown above, in TYPES, I've created the structure type and table type. Then in DATA, I'll create the actual table and structure. In the example, I declare a global structure and table. For just declaring a table from a data dictionary reference, I use the declaration shown as GT_EXP. The inline comments are only for this discussion, I dont use this format in a program per se.
来源:https://stackoverflow.com/questions/36282951/what-is-with-header-line-used-for-in-abap