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 definition

Former Member
0 Likes
807

Dear Experts,

I would like to know how can I create a TYPE with recursive structure. The main objective is to construct an internal table for my organization structure and then export it to XML using simple transformation. Currently, I can only export this XML by construct the XML document like a string composition which is harder to read and modify.

Regards,

Alex

1 REPLY 1
Read only

matt
Active Contributor
513

You want something like in java (from wikipedia article)

class List<E> {
    E value;
    List<E> next;
} 

That's only possible in ABAP using data references.

TYPES: BEGIN OF list,
         e  TYPE i,
         pn TYPE REF TO data,
       END OF list.

DATA: lp_data TYPE REF TO data.

FIELD-SYMBOLS: <ls_list> TYPE list.

CREATE DATA lp_data TYPE list.
ASSIGN lp_data->* TO <ls_list>.
* Add elements
DO 10 TIMES.
  <ls_list>-e = sy-index.
  CREATE DATA <ls_list>-pn TYPE list.
  ASSIGN <ls_list>-pn->* TO <ls_list>.
ENDDO.
<ls_list>-e = 11.

* Display elements
ASSIGN lp_data->* TO <ls_list>.
WRITE: / <ls_list>-e.
DO.
  IF <ls_list>-pn IS INITIAL.
    EXIT.
  ENDIF.
  ASSIGN <ls_list>-pn->* TO <ls_list>.
  WRITE: / <ls_list>-e.
ENDDO.

Don't know if that helps with your XML question.

matt