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

ABAP Stack : Subroutines

Former Member
0 Likes
1,387

Hi Everyone,

I was wondering how can you access the local variable of a subroutine using ABAP Stack.

E.g.

REPORT A.

...

PERFORM B.

....

FORM B

data : var2

.....

CALL FUNCTION C

ENDFORM

FUNCTION C.

<access var2 here>

ENDFUNCTION.

I only know that you can usually access variables via (PROGNAME)variable and assign it to an <FS>.

Thanks,

Patrick

6 REPLIES 6
Read only

mvoros
Active Contributor
0 Likes
1,123

Hi,

you can't. The local variables are usually created on stack so when you leave the routine all local variables are removed from stack. I am not 100% that ABAP AS allocates the local variables on stack (or at least subset of local variables) but the behavior is same. The local variables are not accessible from outside.

Cheers

Read only

Former Member
0 Likes
1,123

Hi,

Even if the call is still active? (e.g. there are many more statements after the CALL FUNCTION)?

Thanks,

Read only

0 Likes
1,123

It's still on the stack but still not accessible. Why don't you pass it as a parameter of function C?

Edited by: Martin Voros on May 31, 2011 1:25 PM

Read only

Wil_Wilstroth
Active Participant
0 Likes
1,123

Hi f0Xg3!,

ABAP stack if i am not mistaken is a way for you to navigate through the flow of objects like programs, screen and other objects in the event of run time.

For a variable which is "LOCALLY" declared in a subroutine and you want to see it in call function... it is not possible. If anyone says its possible please enlighten me too.

Now, when a variable is "LOCALLY" declared, the visibility of this variable is only in the scope of that subroutine.

Any variable that you want to see in a call function, it should be pass over through EXPORTING. Although you may wrote your CALL FUNCTION in that sub-routine... but the CALL FUNCTION is registered or declared in its own Function Group's scope... so the locally declared variable in a subroutine will not be visible.

Hence, I don't think it will work for your idea.

Just my opinion.

Regards,

W. Wilstroth

William Wilstroth
Read only

Former Member
0 Likes
1,123

I can't, I'm just implementing an exit. I know that the values are stored in a stack (and the calls are active when this exit is called), I might change values. But I realized that the data I'm trying to change is a local subroutine variable

Oh well, thanks for the help.

Read only

0 Likes
1,123

Probably implicit enhancement points can solve your problem. Overlay the standard routine with your custom code if you really think that it's necessary.

Cheers