Skip to Content
author's profile photo Former Member
Former Member

Dynamic access of fields

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 12, 2006 at 06: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)"

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 12, 2006 at 06: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!

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 16, 2006 at 05: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

    abap" target="_blank">www.sdn.sap.com/irj/sdn/developerareas/abap?rid=/library/uuid/840ad679-0601-0010-cd8e-9989fd650822">abap FAQ

    Cheers,

    Phil.

    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.