问题
I'm new to ABAP. Started learning about internal tables. I was reading on the ways to create internal tables.
I came across the following syntax to create an internal table from an existing database table:
data: it_mara type table of mara.
I'm confused since mara is a table and if both l.h.s and r.h.s are of the same type then shouldn't it be just:
data: it_mara type mara.
What is the need to convert mara into a table when it is already a table?
回答1:
MARA
is a transparent table which means that it functions at the same time as the structure type MARA
. This is the way SAP works. :)
回答2:
Historical reasons (always a good guess...).
The original and nowadays obsolete way to declare a table (with a header line was DATA it_mara TYPE mara OCCURS 10
. Without OCCURS
, you didn't declare a table, so it became a structure. My guess would be that in order to maintain backwards compatibility, that wasn't changed when TYPE TABLE OF
was introduced.
回答3:
SAP DDIC table (transparent table, pooled table, cluster table) function as a structure.
Internal table is a list of structure (= DDIC table) values.
In your example of SAP DDIC table MARA (General Material Data), we can define it as an internal table like
data: it_mara type STANDARD table of mara.
which creates an STANDARD internal table
data: it_mara type SORTED table of mara.
which creates an SORTED internal table
来源:https://stackoverflow.com/questions/37709936/abap-syntax-for-creating-internal-table-from-existing-database-table