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

Problem in select endselect

UmaArjunan
Active Participant
0 Likes
1,585

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

,lv_nodeid)

FROM /bi0/hdbduns_num

WHERE nodename = lv_tmp_node. "" comm_structure-dbduns_num.

IF lv_parentid = 1.

RESULT = lv_nodename.

  • EXIT.

ELSE.

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.

EXIT.

ELSE.

CLEAR lv_parentid.

lv_parentid = lv_parentid1.

CLEAR lv_parentid1.

  • CONTINUE.

ENDIF.

ENDSELECT.

ENDIF.

Thanks in advance

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,093

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.
    exit.
  endif.

  select parent_id
    from table
   where child_id eq p_child_id.
  endselect.
  if sy-subrc ne 0.
    p_stop = 'X'.
    exit.
  else.

*   Store found id in an internal table?
*   and continue to find the next parent
    perform recursive_select using parent_id
                             changing p_stop.

  endif.



ENDFORM.

4 REPLIES 4
Read only

Former Member
0 Likes
1,094

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.
    exit.
  endif.

  select parent_id
    from table
   where child_id eq p_child_id.
  endselect.
  if sy-subrc ne 0.
    p_stop = 'X'.
    exit.
  else.

*   Store found id in an internal table?
*   and continue to find the next parent
    perform recursive_select using parent_id
                             changing p_stop.

  endif.



ENDFORM.

Read only

0 Likes
1,093

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!!!

Read only

Former Member
0 Likes
1,093

Hi,

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.

Read only

0 Likes
1,093

Hi ankesh,

you are absolutely correct. the second time the select statement fetches the same value. How to solve this ? if you could provide your suggestion, it will be helpful .

Thanks in advance.