我一直在研究这个book并引用它:
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.
然后在接下来的几页中:
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.
此刻我很困惑。第一个示例是仅声明内部表或内部表和具有相同名称的结构吗?
答案 0 :(得分:5)
问题应该是&#34; ABAP&#34;中使用的WITH HEADER LINE是什么?您应该只在遗留代码中看到它们。它们只允许outside classes并且obsolete无论如何。
回答你的问题。这两者都是。它声明了一个内部表customer_tab[]
和一个结构customer_tab
。
然后你可以这样做&#34;惊人的&#34;比如。
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.
或
APPEND customer_tab.
如你所见,它更短,而且非常吸引人,因为它的简洁。虽然它几乎不易阅读和混淆,但因此标记为过时。
Oooops还有一点!您还应该了解
之间的区别CLEAR customer_tab.
和
REFRESH customer_tab.
答案 1 :(得分:3)
您正在显示的两个声明,创建一个带有标题行的表。第一个声明没有明确说明“带标题行”,但它确实创建了一个工作区和一个表,就像您使用了“带标题行”一样。声明也是。有关标题行的信息,请参阅此SAP Help。您引用的文档是过时的语法。由于遗留代码,您将看到它,因此您需要了解它,但避免使用此语法。
答案 2 :(得分:0)
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.
我个人喜欢使用如上所示的语法,在TYPES中,我创建了结构类型和表类型。然后在DATA中,我将创建实际的表和结构。在示例中,我声明了一个全局结构和表。为了从数据字典引用中声明一个表,我使用显示为GT_EXP的声明。内联注释仅适用于本次讨论,我不在程序中使用此格式。