2008 Jun 06 5:16 PM
Can a local class of a global class use the global classes types?
I have types defined in the types tab of the class builder. I would like to reference some of those types in a local class (within my global class). When I do this I get a syntax error saying that the type is unknown. Is there a way for a local class to 'see' these types?
This is on a ECC6.0 systems.
Thank you in advance.
Can a local class of a global class use the global classes types?
I have types defined in the types tab of the class builder. I would like to reference some of those types in a local class (within my global class). When I do this I get a syntax error saying that the type is unknown. Is there a way for a local class to 'see' these types?
This is on a ECC6.0 systems.
Thank you in advance.
2008 Jun 06 5:18 PM
2008 Jun 10 2:22 PM
I tried the following commands without any success:
"... INHERITING FROM superclass", and
"CLASS class DEFINITION
LOCAL FRIENDS class1 class2 ...
intf1 intf2 ... .".
I know that if I define the type again in the "Local Types" section then that will work. Obviously this is not a preferred solution, having a type defined in 2 locations (and therefore having to maintain it twice).
I am also aware that I could create a type pool or create the type in the data dictionary. However, per the ABAP Objects book, these strategies are not recommended.
Any other ideas? Thank you very much.
One more thing that is frustrating. If you double click on the type in the local section, it will take you to that type definition in the global class.
2008 Jun 06 5:21 PM
Local and Global Classes
Classes in ABAP Objects can be declared either globally or locally. You define global classes and interfaces in the Class Builder (Transaction SE24) in the ABAP Workbench. They are stored centrally in class pools in the class library in the R/3 Repository. All of the ABAP programs in an R/3 System can access the global classes. Local classes are defined within an ABAP program. Local classes and interfaces can only be used in the program in which they are defined. When you use a class in an ABAP program, the system first searches for a local class with the specified name. If it does not find one, it then looks for a global class. Apart from the visibility question, there is no difference between using a global class and using a local class.
There is, however, a significant difference in the way that local and global classes are designed. If you are defining a local class that is only used in a single program, it is usually sufficient to define the outwardly visible components so that it fits into that program. Global classes, on the other hand, must be able to be used anywhere. This means that certain restrictions apply when you define the interface of a global class, since the system must be able to guarantee that any program using an object of a global class can recognize the data type of each interface parameter.
2008 Jun 11 6:02 AM
Hello Glenn
It is possible to access the protected and private type definition section of the global class but not the public section.
I created a global class (ZCL_SDN_GLOBAL_CLASS) and defined types for each section (public, protected, private).
Below you see the global class include for local class definitions. Instead of using the PROTECTED SECTION or PRIVATE SECTION statements I included the corresponding sections of the global class. However, it does not work with the PUBLIC SECTION of the global class (perhaps there is a workaround).
After the ENDCLASS statement I added the coding of the PROTECTED and PRIVATE SECTION of the global class.
Coding was developed on ECC 6.0.
*"* use this source file for any type declarations (class
*"* definitions, interfaces or data types) you need for method
*"* implementation or private method's signature
*----------------------------------------------------------------------*
* CLASS lcl_myclass DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_myclass DEFINITION.
** INCLUDE zcl_sdn_global_class==========cu. " public => syntax error
INCLUDE zcl_sdn_global_class==========co. " protected
data: md_local_invoice type ty_s_invoice.
INCLUDE zcl_sdn_global_class==========ci. " private
data: md_local_customer type ty_s_customer.
ENDCLASS. "lcl_myclass DEFINITION
** INCLUDE zcl_sdn_global_class==========co
*** "* protected components of class ZCL_SDN_GLOBAL_CLASS
*** "* do not include other source files here!!!
** protected section.
**
** types: BEGIN OF TY_S_INVOICE .
** include type vbrk.
** types: end of ty_s_invoice.
** INCLUDE zcl_sdn_global_class==========ci
*** "* private components of class ZCL_SDN_GLOBAL_CLASS
*** "* do not include other source files here!!!
** private section.
**
** types:
** BEGIN OF ty_s_customer.
** include type kna1.
** types: END OF ty_s_customer .
**
** data MS_KNA1 type TY_S_CUSTOMER .
Final remark: I am not sure if this make really sense but it works.
Regards
Uwe
2008 Jun 11 6:06 AM
Hello Glenn
I do not thing there is a workaround for including the PUBLIC SECTION of a global class. Why?
Have a look at its coding:
class ZCL_SDN_GLOBAL_CLASS definition
public
final
create public .
*"* public components of class ZCL_SDN_GLOBAL_CLASS
*"* do not include other source files here!!!
public section.
types: BEGIN OF TY_S_SALESORDER .
include type vbak.
types: END OF ty_s_salesorder.
The PROTECTED and PRIVATE section only have the type definition part whereas the PUBLIC SECTION contains the CLASS ... DEFINITION statement and the CREATE event. This cannot be included into another class.
Regards
Uwe
2008 Jun 12 10:21 AM
Hi,
U can use the following style in your local class definition:
CLASS lcl_class DEFINITION DEFERRED.
CLASS cl_global_class DEFINITION LOCAL FRIENDS lcl_class.
CLASS lcl_class DEFINITION.
. PUBLIC SECTION.
DATA: lr_global TYPE REF TO cl_global_class.
.
.
.
ENDCLASS.
CLASS lcl_class IMPLEMENTATION.
CREATE OBJECT lh_application.
.
.
.
ENDCLASS.Rewrd please, if it helps.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |