The-Droidster
The-Droidster

Reputation: 655

Syntax for creating internal table from existing database table?

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?

Upvotes: 8

Views: 11119

Answers (3)

Klaus Hopp
Klaus Hopp

Reputation: 41

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

Upvotes: 1

Jagger
Jagger

Reputation: 10524

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. :)

Upvotes: 5

vwegert
vwegert

Reputation: 18493

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.

Upvotes: 4

Related Questions