Application Development 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: 

Nested structures within ABAP

Former Member
0 Kudos

Hello,

I am working on an ABAP report where the output file will need to look something like:-

1 Material No, Description

2 EAN, ...

3 ..., ..., ...

3 ..., ..., ...

4 ..., ..., ...

4 ..., ...

Some of the record types will only have one line and others will have multiple.

I was hoping to create an internal table into which I could extract all of the relevant data.

To do this, I was thinking of setting up my internal table as a nested structure so I would define some types for each record type

e.g.

types: begin of rec_type_1

matnr like mara-matnr

...

...

end of rec_type_1

types: begin of rec_type_2

...

...

...

end of rec_type_2

and then I could declare my internal table something like:-

data: begin of itab

rec1 type rec_type_1

rec2 type rec_type_2

...

end of itab

I could then extract the relevant information for each material into the appropriate record types.

This will work OK for all the record types where this is only going to be 1 line per material but I am not sure how to extend this for the record structures for which there will be multiple lines per material.

I was thinking of declaring a table and then adding this as an element into the itan structure.

Will this work? And does anyone have any code samples of this sort of thing?

Thanks,

Ruby

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Ruby,

you can define an internal tabel table in an internal table.

Here a short example:

REPORT ZGRO_TEST1 MESSAGE-ID ZZ.

*

TABLES: MARA, MAKT.

*

TYPES: BEGIN OF ITABX,

ATWRT LIKE AUSP-ATWRT,

END OF ITABX.

*

DATA: WA_ITAB1 TYPE ITABX.

*

DATA: BEGIN OF ITAB OCCURS 0,

MATNR LIKE MARA-MATNR,

MAKTX LIKE MAKT-MAKTX,

ITAB1 TYPE TABLE OF ITABX,

END OF ITAB.

*

START-OF-SELECTION.

*

SELECT * FROM MARA UP TO 10 ROWS.

*

CLEAR: ITAB.

REFRESH: ITAB-ITAB1.

*

SELECT SINGLE * FROM MAKT WHERE MATNR = MARA-MATNR

AND SPRAS = SY-LANGU.

*

ITAB-MATNR = MARA-MATNR.

ITAB-MAKTX = MAKT-MAKTX.

  • Fill this like you want

WA_ITAB1-ATWRT = '100'.

APPEND WA_ITAB1 TO ITAB-ITAB1.

WA_ITAB1-ATWRT = '200'.

APPEND WA_ITAB1 TO ITAB-ITAB1.

WA_ITAB1-ATWRT = '300'.

APPEND WA_ITAB1 TO ITAB-ITAB1.

WA_ITAB1-ATWRT = '400'.

APPEND WA_ITAB1 TO ITAB-ITAB1.*

APPEND ITAB.

*

ENDSELECT.

*

LOOP AT ITAB.

WRITE: / ITAB-MATNR, ITAB-MAKTX.

LOOP AT ITAB-ITAB1 INTO WA_ITAB1.

WRITE: WA_ITAB1-ATWRT.

ENDLOOP.

ENDLOOP.

*

END-OF-SELECTION.

Hope it helps.

Regards, Dieter

4 REPLIES 4

Former Member
0 Kudos

U seem to be on the right track...

In your itab you can include a field called rectype, where you store the record type.ex..1, 2,3 etc.

During the output depending on the rectype you can print the particular fields from the internal table itab.

former_member181962
Active Contributor
0 Kudos

Hi Ruby,

Your approach looks OK atleast in theory.

the declartion can be something like this:

types: BEGIN OF MEEIN_PURCHASE_DOC_PRINT,

XEKKO LIKE EKKO,

XPEKKO LIKE PEKKO,

XEKPA like msgpa occurs 0,

XEKPO LIKE EKPO OCCURS 0,

XPEKPO LIKE PEKPO OCCURS 0,

XEKET LIKE EKET OCCURS 0,

Xekkn like ekkn occurs 0,

Xekek like ekek occurs 0,

Xekeh like ekeh occurs 0,

XAEND type meein_xaend occurs 0,

xtkomv type komv occurs 0,

END OF MEEIN_PURCHASE_DOC_PRINT.

Regards,

ravi

Former Member
0 Kudos

Hi

I think so but it should be better you structure was:

types: begin of rec_type_1

...

...

end of rec_type_1.

types: begin of rec_type_2

...

...

...

end of rec_type_2.

types: t_rec_type1 type standard table of rec_type_1,

t_rec_type2 type standard table of rec_type_2.

data: begin of itab occurs 0,

matnr type matnr,

rec1 type t_rec_type_1

rec2 type t_rec_type_2

...

end of itab.

data: wa1 type rec_type_1,

wa2 type rec_type_2.

SORT ITAB BY MATNR.

LOOP AT ITAB.

WRITE ITAB-MATNR.

SORT ITAB-REC1 BY ...

LOOP AT ITAB-REC1 INTO WA1.

WRITE WA1.

ENDLOOP.

SORT ITAB-REC2 BY ...

LOOP AT ITAB-REC2 INTO WA2.

WRITE WA2.

ENDLOOP.

ENDLOOP.

Max

Former Member
0 Kudos

Hi Ruby,

you can define an internal tabel table in an internal table.

Here a short example:

REPORT ZGRO_TEST1 MESSAGE-ID ZZ.

*

TABLES: MARA, MAKT.

*

TYPES: BEGIN OF ITABX,

ATWRT LIKE AUSP-ATWRT,

END OF ITABX.

*

DATA: WA_ITAB1 TYPE ITABX.

*

DATA: BEGIN OF ITAB OCCURS 0,

MATNR LIKE MARA-MATNR,

MAKTX LIKE MAKT-MAKTX,

ITAB1 TYPE TABLE OF ITABX,

END OF ITAB.

*

START-OF-SELECTION.

*

SELECT * FROM MARA UP TO 10 ROWS.

*

CLEAR: ITAB.

REFRESH: ITAB-ITAB1.

*

SELECT SINGLE * FROM MAKT WHERE MATNR = MARA-MATNR

AND SPRAS = SY-LANGU.

*

ITAB-MATNR = MARA-MATNR.

ITAB-MAKTX = MAKT-MAKTX.

  • Fill this like you want

WA_ITAB1-ATWRT = '100'.

APPEND WA_ITAB1 TO ITAB-ITAB1.

WA_ITAB1-ATWRT = '200'.

APPEND WA_ITAB1 TO ITAB-ITAB1.

WA_ITAB1-ATWRT = '300'.

APPEND WA_ITAB1 TO ITAB-ITAB1.

WA_ITAB1-ATWRT = '400'.

APPEND WA_ITAB1 TO ITAB-ITAB1.*

APPEND ITAB.

*

ENDSELECT.

*

LOOP AT ITAB.

WRITE: / ITAB-MATNR, ITAB-MAKTX.

LOOP AT ITAB-ITAB1 INTO WA_ITAB1.

WRITE: WA_ITAB1-ATWRT.

ENDLOOP.

ENDLOOP.

*

END-OF-SELECTION.

Hope it helps.

Regards, Dieter