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: 

abap same name local and global class

igdasabap
Discoverer

Hello;

in abap program ,

i have local class same named with global class.

Which way i can call global classes methods or attributes ?

Any code snippet ?

Thanks

1 ACCEPTED SOLUTION

chayo_x
Member
0 Kudos

It is what Horst says. Check this out.

*DATA LO_YOUROBJECT TYPE REF TO OBJECT.
*CREATE OBJECT LO_YOUROBJECT TYPE ('\CLASS=ZCL_YOURCLASS')
*  EXPORTING
*    IV_TABLE_NAME = 'ZSD_YOURTABLE'
*  .
*
*call method LO_YOUROBJECT->('YOUR_METHOD').
11 REPLIES 11

igdasabap
Discoverer
0 Kudos

Sorry , i need explain in details

the classes(local and global) same named and have static meths. and atts.

igdasabap
Discoverer
0 Kudos

i need to call local class method in some cases , other cases need global classes method.

matt
Active Contributor

Why on earth would you choose to give your global and local class the same name? Simple solution - change the local class name.

Tomas_Buryanek
Active Contributor

It is right to recommend renaming and I also do not know reason to name both classes same name.

But it is still valid question. Is it possible to call global class and how?

-- Tomas --

pokrakam
Active Contributor

"Why on earth would you choose to give your global and local class the same name?"

You're asking something/someone who doesn't give their name and repeats a fake one.

Tomas_Buryanek
Active Contributor
0 Kudos

But what if the local class has same name like global? Same name is possible and local class is prioritized by default.

-- Tomas --

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Yep, right ...

raymond_giuseppi
Active Contributor

Did you try to use some absolute name to identify the classes, trying some id such as '\PROGRAM=ZTEST\CLASS=CL_TEST' vs '\CLASS=CL_TEST' to use in some dynamic method call as (class_name)=>(meth_name) I'm not optimistic about this. (Also I never used same name for two classes, never required it, why did you do that?)

horst_keller
Product and Topic Expert
Product and Topic Expert

chayo_x
Member
0 Kudos

It is what Horst says. Check this out.

*DATA LO_YOUROBJECT TYPE REF TO OBJECT.
*CREATE OBJECT LO_YOUROBJECT TYPE ('\CLASS=ZCL_YOURCLASS')
*  EXPORTING
*    IV_TABLE_NAME = 'ZSD_YOURTABLE'
*  .
*
*call method LO_YOUROBJECT->('YOUR_METHOD').

igdasabap
Discoverer
0 Kudos

thanks to everyone;

acccesing global class meth: call method ('\class=zcl_samename')=global_meth

accesing local class meth: zcl_samename=>local_meth

why i don't give a different name to local class:

local class's definitons and implements are in different includes . And these includes are being used by to much progs , funcs vs.

Global class is in a purchased packet.

I also need two classes of methods in my program

Regards