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

doubly linked list

Former Member
0 Likes
900

hello,

i want to write code for doubly linked list in sap abap. I have a problem in declaring the nodes with previous pointer and next pointer. Please help me in the code.

Thank you,

hello,

i want to write code for doubly linked list in sap abap. I have a problem in declaring the nodes with previous pointer and next pointer. Please help me in the code.

Thank you,

1 REPLY 1
Read only

hubert_heitzer
Contributor
0 Likes
549

Hi Aarti,

here I have an example for a double linked list:


TYPES:
  BEGIN OF lt_dllnode,
    value TYPE i,
    prev  TYPE REF TO data,
    next  TYPE REF TO data,
  END OF lt_dllnode
.

DATA:
  lr_root   TYPE REF TO lt_dllnode,
  lr_cursor TYPE REF TO lt_dllnode,
  lr_llelem TYPE REF TO lt_dllnode
.

* create a double linked list with 10 entries
CREATE DATA lr_root.
lr_root->value = 0.

lr_cursor = lr_root.
DO 9 TIMES.
  CREATE DATA lr_llelem.
  lr_llelem->value = sy-index.

  lr_cursor->next = lr_llelem.
  lr_llelem->prev = lr_cursor.
  lr_cursor = lr_llelem.
ENDDO.

* output of list values
lr_cursor = lr_root.
WHILE lr_cursor IS NOT INITIAL.

  WRITE: / lr_cursor->value.
  lr_cursor ?= lr_cursor->next.

ENDWHILE.

I think there is an ABAP keyword for recursive type definition to avoid downcast, but i dont remember.

Another alternative would be to work with ABAP objects.

Regards, Hubert