Skip to Content
author's profile photo Former Member
Former Member

Nested structures within ABAP

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 01:24 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 12:55 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 23, 2006 at 12:55 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 12:58 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.