Skip to Content

Problem in select endselect

this requirement is : recursivley call the select statement based on the parent value .

lv_tmp_node = '419957600'.

based on the value 419957600 the parent id is retreived.

then next time parent id is passed to the data base table . until the value becomes 1.

When the parent id is 1. i have to get the value .

At the first time the parent id value is 00000017

example :

for 17 the parent value is again 16 ... for 16 the parent id is 15 ... it goes on until the parent id equals. one.

problem here is the select endselect statment is not working as expected.

The second time select endselect is not picking the correct parent value . Still it shows the value of the previous parent id

Please suggest wat might be the problem or any othe best option to do this.

SELECT SINGLE parentid nodename nodeid INTO (lv_parentid , lv_nodename


FROM /bi0/hdbduns_num

WHERE nodename = lv_tmp_node. "" comm_structure-dbduns_num.

IF lv_parentid = 1.

RESULT = lv_nodename.

  • EXIT.


SELECT parentid nodename INTO (lv_parentid1 , lv_nodename)

FROM /bi0/hdbduns_num WHERE nodeid = lv_parentid.

IF lv_parentid1 EQ '00000001' ."".parentid.

RESULT = lv_nodename.



CLEAR lv_parentid.

lv_parentid = lv_parentid1.

CLEAR lv_parentid1.





Thanks in advance

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 16, 2009 at 01:55 PM

    My guess is you should put your selection in a separate routine and do a recursive call to that routine. Basically, the routine will keep calling itself.

    Make sure to insert an escape or it might run for ever and ever and ever...

    To give you an idea:

    FORM recursive_select using p_child_id
    		      changing p_stop.
      if p_stop ne space.
      select parent_id
        from table
       where child_id eq p_child_id.
      if sy-subrc ne 0.
        p_stop = 'X'.
    *   Store found id in an internal table?
    *   and continue to find the next parent
        perform recursive_select using parent_id
                                 changing p_stop.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Maen Anachronos ,

      The idea works fine for my problem in select endselect. When i call the subroutine recursively,

      it fetches the correct parent id and there by i can get the correct node name.

      Thanks a lot

      Actually this code i am using it in the BI start routines. Now i have a problem in creating subroutine from a subroutine .. If you have any suggestions / idea plz....... let me know

      Thanks again!!!

  • author's profile photo Former Member
    Former Member
    Posted on Jan 16, 2009 at 02:01 PM


    You want to imply that value of lv_parentid changes second time in select/endselect loop but the SELECT statement returns the same values ???

    Otherwise your code seems to be ok.. revert.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.