Skip to Content
-3

Recursion in form

Apr 24 at 05:15 PM

114

avatar image

Hello. My program build a tree of objects using loops. How to build a tree of objects using recursion. I know that I need to create a subroutine and perform this subroutine yourself, but I don't understand how to create new internal table and pass this table into perform. Help please.

report z_my_program.
DATA: n_level TYPE I,
n_count type i,
count type i.

TYPES: BEGIN OF ty_hrp1001,
objid type hrp1001-objid,
sobid type hrp1001-sobid,
stext type hrp1000-stext,
objid1 type hrp1001-objid,
END OF ty_hrp1001.
DATA : it_hrp1001 TYPE TABLE OF ty_hrp1001.
DATA : wa_hrp1001 TYPE ty_hrp1001.
FIELD-SYMBOLS: <fs1001> like line of it_hrp1001.

TYPES: BEGIN OF ty_hrp1002,
objid type hrp1001-objid,
sobid type hrp1001-sobid,
stext type hrp1000-stext,
objid1 type hrp1001-objid,
END OF ty_hrp1002.
DATA : it_hrp1002 TYPE TABLE OF ty_hrp1002.
DATA : wa_hrp1002 TYPE ty_hrp1002.
FIELD-SYMBOLS: <fs1002> like line of it_hrp1002.

TYPES: BEGIN OF ty_hrp1003,
objid type hrp1001-objid,
sobid type hrp1001-sobid,
objid1 type hrp1001-objid,
stext type hrp1000-stext,
END OF ty_hrp1003.
DATA : it_hrp1003 TYPE TABLE OF ty_hrp1003.
DATA : wa_hrp1003 TYPE ty_hrp1003.
FIELD-SYMBOLS: <fs1003> like line of it_hrp1003.

***Data Table decleration for FM RS_TREE_CONSTRUCT
DATA: IT_NODE TYPE STANDARD TABLE OF SNODETEXT,
WA_NODE TYPE SNODETEXT.
**Declare Constants for TREE
CONSTANTS:
C_COL_KEY TYPE C LENGTH 1 VALUE COL_KEY,
C_COL_FIELD TYPE C LENGTH 1 VALUE COL_NORMAL,
C_COL_OBJID TYPE C LENGTH 1 VALUE COL_KEY,
C_COL_SOBID TYPE C LENGTH 1 VALUE COL_POSITIVE.
**Selection Screen


select-options: s_objid for wa_hrp1001-objid.


START-OF-SELECTION.


**Get Data From Tables


SELECT OBJID SOBID FROM HRP1001 INTO TABLE IT_HRP1001 WHERE OBJID IN S_OBJID and SUBTY = 'B030'.
loop at it_hrp1001 assigning <fs1001>.
<fs1001>-objid1 = <fs1001>-sobid.
endloop.
SELECT OBJID SOBID FROM HRP1001 INTO TABLE IT_HRP1002 FOR ALL ENTRIES IN IT_HRP1001 WHERE OBJID = IT_HRP1001-OBJID1 and SUBTY = 'B030'.
loop at it_hrp1002 assigning <fs1002>.
<fs1002>-objid1 = <fs1002>-sobid.
endloop.
SELECT OBJID SOBID FROM HRP1001 INTO TABLE IT_HRP1003 FOR ALL ENTRIES IN IT_HRP1002 WHERE OBJID = IT_HRP1002-OBJID1 and SUBTY = 'B030'.
loop at it_hrp1003 assigning <fs1003>.
<fs1003>-objid1 = <fs1003>-sobid.
endloop.


"1-st node
WA_NODE-TLEVEL = 1.
WA_NODE-NAME = 'Catalogue'.
WA_NODE-NLENGTH = 20.
WA_NODE-COLOR = C_COL_KEY.
WA_NODE-TEXT = 'Texts'.
WA_NODE-TLENGTH = 50.
APPEND WA_NODE TO IT_NODE.


"2-nd node
LOOP AT IT_HRP1001 INTO WA_HRP1001.
CLEAR WA_NODE.
WA_NODE-TLEVEL = 2. 
WA_NODE-NAME = WA_HRP1001-SOBID.
WA_NODE-NLENGTH = 50.
WA_NODE-COLOR = C_COL_OBJID.
APPEND WA_NODE TO IT_NODE.


"3-rd node
LOOP AT IT_HRP1002 INTO WA_HRP1002 WHERE OBJID = WA_HRP1001-OBJID1.
CLEAR WA_NODE.
WA_NODE-TLEVEL = 3.
WA_NODE-NAME = WA_HRP1002-SOBID.
WA_NODE-NLENGTH = 50.
WA_NODE-COLOR = C_COL_SOBID.
APPEND WA_NODE TO IT_NODE.


"4-th node
LOOP AT IT_HRP1003 INTO WA_HRP1003 WHERE OBJID = WA_HRP1002-OBJID1.
CLEAR WA_NODE.
WA_NODE-TLEVEL = 4.
WA_NODE-NAME = WA_HRP1003-SOBID.
WA_NODE-NLENGTH = 50.
WA_NODE-COLOR = C_COL_SOBID.
APPEND WA_NODE TO IT_NODE.

ENDLOOP.
ENDLOOP.
ENDLOOP.


**Construct tree
CALL FUNCTION 'RS_TREE_CONSTRUCT'
* EXPORTING
* INSERT_ID = '000000'
* RELATIONSHIP = ' '
* LOG =
TABLES
NODETAB = IT_NODE
EXCEPTIONS
TREE_FAILURE = 1
ID_NOT_FOUND = 2
WRONG_RELATIONSHIP = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
WRITE 'Error in Tree Construction'.
ENDIF.

**Display tree
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
CALLBACK_PROGRAM = SY-REPID.


10 |10000 characters needed characters left characters exceeded

FORM is obsolete, use methods in objects. Think about how to realize a tree with appropriate objects. The web should be full of examples.

1

Hi, Horst,

Why FORM is obsolete ? Using FORM is suitable for some special(little) tasks.

0

Simply search FORM in the ABAP documentation.

1

Former Member Please let me know if you would like to make changes to the question. I'm afraid the way you tried to do it isn't allowed and doesn't add value to other community members.

0
* Please Login or Register to Answer, Follow or Comment.

0 Answers