10-12-2006 7:18 AM
Hi,
Can anyone tell me how I can dynamically access a field existing in a FM from another FM called from this FM without passing it through parameters.
Example.
FUNCTION LEVEL1_FUNCTION.
data: var1 type i.
var1 = 10.
CALL FUNCTION 'LEVEL2_FUNCTION'.
ENDFUNCTION.
FUNCTION LEVEL2_FUNCTION.
" Here I want to access var1 of LEVEL1_FUNCTION.
I don't have a way to pass var1 as a parameter.
ENDFUNCTION.
Is this possible, if so please let me know.
Give me your solutions for two possibilities:
1. If both FMs belongs to same Function group.
2. If both FMs belongs to different Function groups.
Pleae Note: I don't want to use IMPORT/EXPORT statements.
Thanks,
Surendra
10-12-2006 7:39 AM
1. If both FMs belongs to same Function group...
the only way in the same functiongroup is to define your variables in the globaldata or to move the values from FM1 to a variable you defined in the globaldata.
access to a local variable defined in the FM itself and not in the globaldata from another FM is impossible (whatever they are in the same group on not).
Export/import should not be used anymore (Abap object does not allowed that anymore btw).
So you can only move the local Vars to globaldata.
for a dynamic access you should use "assign(field)"
10-12-2006 7:48 AM
Howdy Surendra,
If your 2 function modules are in the same group, then all you should have to do is declare your shared variable in the top include of the function group.
go se80=>Function Group, type in your function group,
open up the 'includes' tree node and there'll be your LZXXXXXXXTOP include.
Then all FMs in there can share it.
Otherwise, if you don't want to use IMPORT/EXPORT, you could use table work areas, ie TABLES statement. Those table work areas are weird creatures who cross the bounds of memory and but i'm not sure exactly when they are visible or how they work (everything in the doco says DO NOT USE THIS PROGAMMING METHOD, but hey, sometimes you have to break the rules).
Or you could create a custom table as a drop off/pick up kind of thing.
As for two different Function Groups,
Just an idea, I've never tried this before though.
If you make a form in your top include which simply returns your value:
FORM getVar1 using p_var1.
p_var1 = var1 "of course var1 is global now
ENDFORM
Then you <i>might</i> be able to use the statement
perform getVar1 using myVar1 in program LZXXXXTOP
Hope this gives you something to go on.
NB - pretty much everything I've said is NOT RECOMMENDED at all in normal programming - passing parameters is the way to go. But I assume you have a good reason for not wanting to do it this way?
Cheers,
Phil
Typos everywhere!
10-16-2006 6:14 AM
Hi Surendra,
I don't know how I've never noticed this before, but if you navigate (via blue left bar) to Application Server >> ABAP, you will see on the right-hand side a link to an ABAP FAQ where there is an <b>exact answer</b> to your question. You couldn't hope for anything better. Check it out.
This link may work
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/developerareas/abap?rid=/library/uuid/840ad679-0601-0010-cd8e-9989fd650822">abap FAQ</a>
Cheers,
Phil.