Application Development 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: 

Global data of a function group

Former Member
0 Kudos

Hi there,

Some body please resolve this

i created a function module with an import parameter say "result".

But global data of function group also contain the same "result" dataobj.

So i understand the scope of result in function module would be local only.so if i say "result" simply,i would be reffering to the import parameter.

My doubt is that in such a situation is there some way that i can refer to the "result" ,the global data..

thanks in advance

15 REPLIES 15

Former Member

Hi,

Your simply Overriding the global field with local field.

The scope the local field is limited to Function module and Where as Global variable(Function group variable) can be accessed across the whole function group. If you want to use the value of global variable create the local variable with some other name.

I feel that this is only the way u can acess the global variable data.

0 Kudos

Okay..so are u sure there is no other way?because in classees and all in other languages you can refer to global data in some way,although i cant remember it..

0 Kudos

Try this way


"inside FM
field-symbols <fs> type any.

assign ('(FUNCTION_GROUP_TOP_INCLUDE_NAME)global_data_objet_name') to <fs>.

Regards

Marcin

0 Kudos

Hi Marcin,

It looks like a very good idea.

But syntax is giving me some error.

is it like this

assign (( 'Fngrpnam')varname) to <fs>

0 Kudos

Hello Teenu

In order to use the technique described by Marcin have a look at the original posting:

[SAP User Exits and the People Who Love Them|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/208811b0-00b2-2910-c5ac-dd2c7c50c8e8]

Regards

Uwe

0 Kudos

hey Uwe,

thanks alot for the link..

Former Member
0 Kudos

Refer to the global data in or out with:

call function .........

exporting

result = result

or importing

result = result

is going to supply result to the function module or get it back from the function module, or supply it AND get it back....why can't we do that?

0 Kudos

Hi ShortDump,

am saying about usage with in FM not outside the FM.

Hi Teenu,

As per my understanding in Classes we can retrive local one(Private Variable) with the Class method and where as Global Variable(Public Variable) we can acess with the Class Object.

Edited by: subas Bose on Mar 25, 2010 5:41 PM

Edited by: subas Bose on Mar 25, 2010 5:43 PM

0 Kudos

sorry it was not in classes..i was referring to C++ language

there u can use the scope resolution operation ::

if thats used in front of a variable ur refferring to the global one..

i was doubting whether a similar thing is there in abap

0 Kudos

Teenu,

If you refer to variable "result" in your function, it refers to the parameter. If you do it in a subroutine or other functions etc, it refers to the global variable. rename them as gv_result and p_result.

If you don't want to rename them, try using field symbol. If you function group is Z001, then your main program is SAPLZ001.



field-symbols <fs_gv_result> type any.
assign (SAPLZ001)result to <fs_gv_result>.

Former Member
0 Kudos

If you want to make parameters global, in the FM, take the path:

Edit -> interface -> Globalize parameters.

Rob

0 Kudos

Hi Rob,

I understand that if we donot "Globalize Parameters" then the scope of the interface params is local.

So addressing 'result' (as mentioned by OP) will this address the local or global param ?

Cool trick Marcin 10 p*ints from me ....

BR,

Suhas

Edited by: Suhas Saha on Mar 25, 2010 10:37 PM

0 Kudos

It should make the parameters as declared available in the called forms of the FM, so the local declarations should be removed. I expect (but haven't tried this) that the parameters would be known ot the other FMs in the group.

Rob

uwe_schieferstein
Active Contributor
0 Kudos

Hello Teenu

Your true problem is a completely different one: Missing naming conventions.

Looking at the naming convention that I am sticking to

[Nomen est Omen - ABAP Naming Conventions|http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/15304] [original link is broken] [original link is broken] [original link is broken];

you will realize that I will never ever come across an ambiguous situation like you described:

(1) All global data of the function group start with G (= global)

(2) All parameters of the module interface start with either:

I = Importing

E = Exporting

C = Changing

X = "Changing" TABLES parameter

Regards

Uwe

0 Kudos

Hi Uwe,

thanks for the reply..

But situation is really not ambiguous for me and it has got nothing to do with the naming convention.I know clearly if you use two different names,problem is solved.I was experimenting whether if the names are same, and still if you could access them at the same time.

But thanks alot for the naming convention link..that would help me in future

Regards,

Teenu