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

Help! Question on calling a function module

Former Member
0 Likes
1,205

Hi,everybody.

I have a problem about function module. I created a normal function module which would call itself when user double clicked some screen elements. But when I exit the function called in second time, the value of the global variants in function called in first time changed to the value in function called in second time. It seems that they shared the global variants. So is there any ease approach to recover the data to the original value?

Thanks for any help!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,104

Dan,

As the same function is being called twice, apparently its the latest values which are set when the function called second time, will be retained. I don't think the initial values can be recovered.

Is it must to implement a recusive function in your case?

Regards,

Ravi

Note : Please mark all the helpful answers

10 REPLIES 10
Read only

Former Member
0 Likes
1,105

Dan,

As the same function is being called twice, apparently its the latest values which are set when the function called second time, will be retained. I don't think the initial values can be recovered.

Is it must to implement a recusive function in your case?

Regards,

Ravi

Note : Please mark all the helpful answers

Read only

Former Member
0 Likes
1,104

Hi Dan,

Try not using global variants. Pass the value instead of using global.

Regards,

Sameena

Read only

Former Member
0 Likes
1,104

Hi Dan,

you can use field-symbols instead.

check the following code

IM_TEST is the importing parameter

EX_TEST is the exporting parameter

FUNCTION ZTEST_RECURSION.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(IM_TEST) TYPE  C
*"  EXPORTING
*"     REFERENCE(EX_TEST) TYPE  C
*"----------------------------------------------------------------------

field-symbols : <var> type c.
if im_test = 1.
assign im_test to <var>.
*<var> = 4.
elseif im_test = 3.
assign im_test to <var>.
endif.

if im_test = 1.
CALL FUNCTION 'ZTEST_RECURSION'
  EXPORTING
    IM_TEST       = '3'
          .

endif.

ex_test = <var>.
ENDFUNCTION.

i hope this will help you.

regards,

Kinshuk Saxena

PS reward points if you find the post helpful

Read only

Former Member
0 Likes
1,104

Hi,

in that case you need to export to memory before calling the Same FM. after calling the FM retrieve the same from memory. that way you can get back the old values.

Regards

vijay

Read only

0 Likes
1,104

Thanks for all

So I think I must add some codes for retrieve the original value as Vijay Babu Dudla said

Read only

0 Likes
1,104

Dan,

I don't think that is going to work, because the same EXPORT statement will FIRE when you CALL the FUNCTION for the SECOND TIME, right?

Declare a STATIS variable and EXPORT the values only of the variable is initial and after exporting, SET the field value to X.

Regards,

Ravi

Note : Please mark all the helpful answers

Read only

Former Member
0 Likes
1,104

Hello everybody,

Why are you complicating the problem?

A simple answer would be to use passby value mechanism in function module interface, as sameena said, if the value being spoke about is one of the parameters in the FM interface. If it a variable declared inside the function group (not a parameter), declare that locally instead of declaring it in the TOP include. In either case value changed in Call2 will not reflect back into Call1.

Let me know if you need more information on this.

Regards,

Nagaraju Chidurupalli.

Read only

Former Member
0 Likes
1,104

Nagaraju Chidurupalli,I need to transfer some values to screen, so defined some global variants. Is there any better way to do this?

Ravikumar Allampallam, I think I can export to the different ID KEY according to the different hierarchy of calling FM.

And another way I think it is maybe to use 'submit program' or 'call transaction' instead of 'call function', can it works?

Read only

0 Likes
1,104

Recursive calls are very tricky and I really can't think of a reason that it would need to be done in an ABAP program. They are useful in system functions like sorts, but rarely used in business functions. I think you could do what you want much more easily with say, while/endwhile coding.

However, if you must code recursively, look at your global variables after each call is returned. The test of any function is 'does it return the correct data?' Does yours?

If this doesn't help, perhaps you could post your code.

Rob

Read only

ferry_lianto
Active Contributor
0 Likes
1,104

Hi Dan,

I think you are better to use export to memory with different ID for different hierarchy and refresh once is done.

This way is clean and can be used globally as well.

Hope this will help.

Regards,

Ferry Lianto