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

can anyone give simple Example for recursive function

Former Member
0 Likes
565

can anyone give simple Example program by recursive concept?

2 REPLIES 2
Read only

Former Member
0 Likes
498

Please use this recursive FM which i have created for the same requirement

FUNCTION ZBOM_GET_HIERARCHY.

*"----


""Global interface:

*" TABLES

*" BOM_RETURN STRUCTURE ZMBOMDATA

*"----


CLEAR HIER_TAB.

REFRESH HIER_TAB.

*Put contents of table sent to function(bom_return) into hier_tab

HIER_TAB[] = BOM_RETURN[].

*Clear out table to be returned from function, it will be built in

*hierarchy order

CLEAR BOM_RETURN.

REFRESH BOM_RETURN.

LEVEL = 1.

*Start at the top_level assembly

LOOP AT HIER_TAB

WHERE TOP_LEVEL = 'X'.

*Move fields to table to be returned

MOVE-CORRESPONDING HIER_TAB TO BOM_RETURN.

BOM_RETURN-BOM_LEVEL = LEVEL.

APPEND BOM_RETURN.

*Do not check any other type of item that is not stock

IF HIER_TAB-POSTP NE 'L'.

CONTINUE.

ENDIF.

*Check to see if the component is also a parent part

PERFORM GET_NEXT USING LEVEL

HIER_TAB-IDNRK.

ENDLOOP.

ENDFUNCTION.

&----


*& Form GET_NEXT

&----


*Checks to see if the component part is a parent part, if it is move *

*the fields to the table to be returned from the function

----


FORM GET_NEXT USING VALUE(LOCAL_LEVEL) LIKE LEVEL "BOM level

VALUE(LOCAL_IDNRK) LIKE HIER_TAB-IDNRK. "Component

*Check to see if the component is a parent

READ TABLE HIER_TAB

WITH KEY MATNR = LOCAL_IDNRK.

*If it is, increment the bom level and move the fields to the table to

*be returned from the function

IF SY-SUBRC = 0.

LOCAL_LEVEL = LOCAL_LEVEL + 1.

LOOP AT HIER_TAB

WHERE MATNR = LOCAL_IDNRK.

MOVE-CORRESPONDING HIER_TAB TO BOM_RETURN.

BOM_RETURN-BOM_LEVEL = LOCAL_LEVEL.

APPEND BOM_RETURN.

*Do not check any other type of item than stock

IF HIER_TAB-POSTP NE 'L'.

CONTINUE.

ENDIF.

*Check to see if the component part is a also a parent part

PERFORM GET_NEXT USING LOCAL_LEVEL

BOM_RETURN-IDNRK.

ENDLOOP.

ENDIF.

ENDFORM. " GET_NEXT

This code is working in production without any error.

Please give me reward point if it is useful.

Thanks

Murali Poli

Read only

Former Member
0 Likes
498

Hey Camila,

I was searching for programs with Recursive string and came up with hits:

SALV_DEMO_HIERSEQ_RECURSION

SALV_DEMO_TABLE_RECURSION

SALV_TEST_HIERSEQ_RECURSION

SALV_TEST_TABLE_RECURSION

Check if any of them are useful to you

Regards,

Vivek