2009 Oct 26 5:19 AM
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,
2009 Oct 26 9:21 AM
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
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |