8

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?

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

4 Comments

Yes, that seems to be the reason. I attached a debugger to the program today to see the type of 'mara'. It said 'flat structure' which is weird since mara is a table. But maybe that's how the SAP ABAP runtime works. Seems like it considers a table to be a array of fields(structure) when referenced by its name in declarations and definitions. The name then internally points to the underlying database table. Weird!
@The-Droidster Maybe not necessarily weird but by all means confusing, especially for a rookie in the ABAP field! Enjoy learning it!
@The-Droidster It becomes even funnier. Try the following program and see of what type the variable MARA is. Look that it is defined with TABLES keyword. REPORT ZZY. TABLES MARA. START-OF-SELECTION. SELECT * FROM MARA UP TO 10 ROWS. WRITE / MARA-MATNR. ENDSELECT. It shows also how the name MARA is overloaded in this case.
Yes, I checked every occurrence of mara in the program today. It said 'flat structure'(even when the statement explicitly says 'TABLES' :D). Note: I can't actually run the code right now since I can only practice at my training institute(which has really bad trainers btw :D).
4

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.

1 Comment

Hi, thanks for your comment on OCCURS. That gave me a hint. But I was more interested in why the runtime treats mara as a structure instead of a table in the first place. @Jaggers's answer seems to address that point.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.