Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

What are nested Internal tables

Former Member
0 Likes
7,634

Hi Guru's,

I am new to ABAP ...just trying to learn things.Can you please explain me what are nested internal tables and what is the purpose of nested internal table?where can it be used and why a header line is not written in a Nested Internal table...

Kindly explain it (scenario where nested internal tables are used) with an example it will be helpful.

Cheers,

Priyanka

1 ACCEPTED SOLUTION
Read only

Former Member
2,910

Hi,

When storing data in internal tables, you often use one internal table for each database you read.

Each one contains some or all columns of the relevant database table. It is up to you whether

you create an internal table with a flat structure for each database table or if you create, for

example, internal tables with nested structures. If you have several tables, each one with a flat

structure, you have to work with redundant key fields to link the tables. If, on the other hand, you

use nested internal tables, you can store the data from the database tables hierarchically.

Saving and processing very large amounts of data in internal tables has disadvantages. If you

divide up the data into different internal tables, processing it can be very runtime-intensive, since

the tables have to be processed individually. Furthermore, it requires a lot of storage space,

since internal tables are not stored in compressed form. The system may even need to store the

dataset outside of its working memory. This means that processing it takes even longer.

An example of nested internal table:

Assume the following program is linked to the logical database [Page 1163] F1S.

REPORT DEMO.

DATA: SUM TYPE I, CNT TYPE I.

NODES: SPFLI, SFLIGHT, SBOOK.

DATA: BEGIN OF WA_SBOOK,

BOOKID TYPE SBOOK-BOOKID,

SMOKER TYPE SBOOK-SMOKER,

CLASS TYPE SBOOK-CLASS,

LUGGWEIGHT TYPE SBOOK-LUGGWEIGHT,

WUNIT TYPE SBOOK-WUNIT,

END OF WA_SBOOK.

DATA: BEGIN OF WA_SFLIGHT,

FLDATE TYPE SFLIGHT-FLDATE,

SBOOK LIKE TABLE OF WA_SBOOK,

END OF WA_SFLIGHT.

DATA: BEGIN OF WA_SPFLI,

CARRID TYPE SPFLI-CARRID,

CONNID TYPE SPFLI-CONNID,

CITYFROM TYPE SPFLI-CITYFROM,

CITYTO TYPE SPFLI-CITYTO,

SFLIGHT LIKE TABLE OF WA_SFLIGHT,

END OF WA_SPFLI.

DATA TAB_SPFLI LIKE TABLE OF WA_SPFLI.

START-OF-SELECTION.

GET SPFLI.

REFRESH WA_SPFLI-SFLIGHT.

GET SFLIGHT.

REFRESH WA_SFLIGHT-SBOOK.

GET SBOOK.

MOVE-CORRESPONDING SBOOK TO WA_SBOOK.

APPEND WA_SBOOK TO WA_SFLIGHT-SBOOK.

GET SFLIGHT LATE.

MOVE-CORRESPONDING SFLIGHT TO WA_SFLIGHT.

APPEND WA_SFLIGHT TO WA_SPFLI-SFLIGHT.

GET SPFLI LATE.

MOVE-CORRESPONDING SPFLI TO WA_SPFLI.

APPEND WA_SPFLI TO TAB_SPFLI.

END-OF-SELECTION.

SORT TAB_SPFLI BY CITYFROM CITYTO CONNID.

LOOP AT TAB_SPFLI INTO WA_SPFLI.

SKIP.

WRITE: / WA_SPFLI-CARRID,

WA_SPFLI-CONNID,

'from', (15) WA_SPFLI-CITYFROM,

'to', (15) WA_SPFLI-CITYTO.

ULINE.

SORT WA_SPFLI-SFLIGHT BY FLDATE.

LOOP AT WA_SPFLI-SFLIGHT INTO WA_SFLIGHT.

SKIP.

WRITE: / 'Date:', WA_SFLIGHT-FLDATE.

WRITE: 20 'Book-ID', 40 'Smoker', 50 'Class'.

ULINE.

SORT WA_SFLIGHT-SBOOK BY CLASS SMOKER BOOKID.

SUM = 0.

CNT = 0.

LOOP AT WA_SFLIGHT-SBOOK INTO WA_SBOOK.

WRITE: / WA_SBOOK-BOOKID UNDER 'Book-ID',

WA_SBOOK-SMOKER UNDER 'Smoker',

WA_SBOOK-CLASS UNDER 'Class'.

SUM = SUM + WA_SBOOK-LUGGWEIGHT.

CNT = CNT + 1.

ENDLOOP.

ULINE.

WRITE: 'Number of bookings: ', (3) CNT,

/ 'Total luggage weight:',

(3) SUM, WA_SBOOK-WUNIT.

ENDLOOP.

ENDLOOP.

Thanks.

Hi Guru's,

I am new to ABAP ...just trying to learn things.Can you please explain me what are nested internal tables and what is the purpose of nested internal table?where can it be used and why a header line is not written in a Nested Internal table...

Kindly explain it (scenario where nested internal tables are used) with an example it will be helpful.

Cheers,

Priyanka

3 REPLIES 3
Read only

Former Member
2,911

Hi,

When storing data in internal tables, you often use one internal table for each database you read.

Each one contains some or all columns of the relevant database table. It is up to you whether

you create an internal table with a flat structure for each database table or if you create, for

example, internal tables with nested structures. If you have several tables, each one with a flat

structure, you have to work with redundant key fields to link the tables. If, on the other hand, you

use nested internal tables, you can store the data from the database tables hierarchically.

Saving and processing very large amounts of data in internal tables has disadvantages. If you

divide up the data into different internal tables, processing it can be very runtime-intensive, since

the tables have to be processed individually. Furthermore, it requires a lot of storage space,

since internal tables are not stored in compressed form. The system may even need to store the

dataset outside of its working memory. This means that processing it takes even longer.

An example of nested internal table:

Assume the following program is linked to the logical database [Page 1163] F1S.

REPORT DEMO.

DATA: SUM TYPE I, CNT TYPE I.

NODES: SPFLI, SFLIGHT, SBOOK.

DATA: BEGIN OF WA_SBOOK,

BOOKID TYPE SBOOK-BOOKID,

SMOKER TYPE SBOOK-SMOKER,

CLASS TYPE SBOOK-CLASS,

LUGGWEIGHT TYPE SBOOK-LUGGWEIGHT,

WUNIT TYPE SBOOK-WUNIT,

END OF WA_SBOOK.

DATA: BEGIN OF WA_SFLIGHT,

FLDATE TYPE SFLIGHT-FLDATE,

SBOOK LIKE TABLE OF WA_SBOOK,

END OF WA_SFLIGHT.

DATA: BEGIN OF WA_SPFLI,

CARRID TYPE SPFLI-CARRID,

CONNID TYPE SPFLI-CONNID,

CITYFROM TYPE SPFLI-CITYFROM,

CITYTO TYPE SPFLI-CITYTO,

SFLIGHT LIKE TABLE OF WA_SFLIGHT,

END OF WA_SPFLI.

DATA TAB_SPFLI LIKE TABLE OF WA_SPFLI.

START-OF-SELECTION.

GET SPFLI.

REFRESH WA_SPFLI-SFLIGHT.

GET SFLIGHT.

REFRESH WA_SFLIGHT-SBOOK.

GET SBOOK.

MOVE-CORRESPONDING SBOOK TO WA_SBOOK.

APPEND WA_SBOOK TO WA_SFLIGHT-SBOOK.

GET SFLIGHT LATE.

MOVE-CORRESPONDING SFLIGHT TO WA_SFLIGHT.

APPEND WA_SFLIGHT TO WA_SPFLI-SFLIGHT.

GET SPFLI LATE.

MOVE-CORRESPONDING SPFLI TO WA_SPFLI.

APPEND WA_SPFLI TO TAB_SPFLI.

END-OF-SELECTION.

SORT TAB_SPFLI BY CITYFROM CITYTO CONNID.

LOOP AT TAB_SPFLI INTO WA_SPFLI.

SKIP.

WRITE: / WA_SPFLI-CARRID,

WA_SPFLI-CONNID,

'from', (15) WA_SPFLI-CITYFROM,

'to', (15) WA_SPFLI-CITYTO.

ULINE.

SORT WA_SPFLI-SFLIGHT BY FLDATE.

LOOP AT WA_SPFLI-SFLIGHT INTO WA_SFLIGHT.

SKIP.

WRITE: / 'Date:', WA_SFLIGHT-FLDATE.

WRITE: 20 'Book-ID', 40 'Smoker', 50 'Class'.

ULINE.

SORT WA_SFLIGHT-SBOOK BY CLASS SMOKER BOOKID.

SUM = 0.

CNT = 0.

LOOP AT WA_SFLIGHT-SBOOK INTO WA_SBOOK.

WRITE: / WA_SBOOK-BOOKID UNDER 'Book-ID',

WA_SBOOK-SMOKER UNDER 'Smoker',

WA_SBOOK-CLASS UNDER 'Class'.

SUM = SUM + WA_SBOOK-LUGGWEIGHT.

CNT = CNT + 1.

ENDLOOP.

ULINE.

WRITE: 'Number of bookings: ', (3) CNT,

/ 'Total luggage weight:',

(3) SUM, WA_SBOOK-WUNIT.

ENDLOOP.

ENDLOOP.

Thanks.

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
2,910

Hi,

Nested internal tables are when you make a field which is TYPED with a TABLE TYPE.

That is one of your strucutre field is a TABLE TYPE so when you create a INTENRAL TABLE of this Strucutre this internal table field containes one of its field as another INTERNAL table.

They are also concidered DEEP STRUCUTRES as we will not the size of the internal table at the decleration time.

For example

DATA: begin of NES_STRUCT,

field1(10) type C,

nested_tab type table of SPFLI,

end of NES_STRUCT.

Now NES_STRUCT is a strcutre which has an internal table in it.

Now

DATA: IT_NES_STRUCT LIKE TABLE OF NES_STRUCT.

Now IT_NES_STRUCT is an intenral table with each record of it having a field with name "nested_tab" which is an internal table itself.

Regards,

Sesh

.

Read only

Former Member
0 Likes
2,910

Hi

structures containing internal tables as components or

Internal table containing Structure as components are called Deep Internal table.

Please check this link for reading a deep structure.

Example:

TYPES: BEGIN OF TYPE_DEEP,

MATNR TYPE MATNR,

T_MARC TYPE MARC OCCURS 0,

END OF TYPE_DEEP.

DATA: T_DEEP TYPE STANDARD TABLE OF TYPE_DEEP.

DATA: WA_DEEP TYPE TYPE_DEEP.

DATA: T_MARC TYPE TABLE OF MARC.

DATA: S_MARC TYPE MARC.

  • Populating data.

WA_DEEP-MATNR = 'TEST'.

S_MARC-MATNR = 'TEST'.

S_MARC-WERKS = '9090'.

APPEND S_MARC TO T_MARC.

  • Append second level internal table.

WA_DEEP-T_MARC[] = T_MARC[].

  • Append.

APPEND WA_DEEP TO T_DEEP.

  • Process the internal table.

LOOP AT T_DEEP INTO WA_DEEP.

WRITE: / WA_DEEP-MATNR.

  • PROCESS the second level internal table.

LOOP AT WA_DEEP-T_MARC INTO S_MARC.

WRITE: S_MARC-WERKS.

ENDLOOP.

ENDLOOP.

Reward points for useful Answers

Regards

Anji