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

recursive structure: compiler error

hubert_heitzer
Contributor
0 Likes
1,309

Hi,

I'd like to define a recursive structure like

TYPES:
  BEGIN OF st_assembly_element,
    matnr TYPE                   matnr,
    brkup TYPE                   c,
    state TYPE                   icon_d,
    " ...
    pords TYPE STANDARD TABLE OF ebeln               WITH DEFAULT KEY,
    elems TYPE STANDARD TABLE OF st_assembly_element WITH DEFAULT KEY,
  END OF st_assembly_element
.

Compiling this code leads to an "unknown type: st_assembly_element"-error.

Is there a way of forward declaration in ABAP (syntax required)?

How can I avoid this error (without using TYPE REF TO data)?

Regards,

Hubert

4 REPLIES 4
Read only

pokrakam
Active Contributor
1,111

Even if the compiler allowed it, I would not do it.

You couldn't read it properly without some kind of dynamic referencing. And if we're going to do that then a hierarchical list is much easier to code, understand, and debug. If you want recursion, use objects; much neater.

Read only

0 Likes
1,111

Of course can I read it properly without some kind of dynamic referencing.

I need this data structure only in this special case, so I try to avoid the overhead of OO.

Read only

pokrakam
Active Contributor
0 Likes
1,111

Sorry, bad phrasing. I meant dynamic processing or referencing. You will need some kind of looping or nested access methods.

I don't see OO as being significant overhead. Clarity / ease of use is a good tradeoff for a really minor performance hit. To me this screams out for OO 🙂

Read only

UweFetzer_se38
Active Contributor
0 Likes
1,111

The "elems" should be just STANDARD TABLE of matnr in my opinion because this i the key for the next layer.

(standard in Bill of Materials [BOM])