问题
I'm trying to create a local class (Z_MY_LOCAL_CLASS
) inside a global class (Z_MY_GLOBAL_CLASS
) by clicking "Local Definitions/Implementations" in transaction se24
.
Afterwards I copied the source code of another class from its source code-based view into the text area that showed up after I clicked the "local definitions" button.
*"* use this source file for the definition and implementation of
*"* local helper classes, interface definitions and type
*"* declarations
class Z_MY_LOCAL_CLASS definition
public
final
create public .
public section.
class-methods SOME_STATIC_METHOD
importing
!IS_IS type Z_SOME_TYPE
returning
value(RS_RETURN) type Z_SOME_TYPE .
protected section.
private section.
ENDCLASS.
CLASS Z_MY_LOCAL_CLASS IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Static Public Method Z_MY_LOCAL_CLASS=>SOME_STATIC_METHOD
* +-------------------------------------------------------------------------------------------------+
* | [--->] IS_IN TYPE Z_SOME_TYPE
* | [<-()] RS_RETURN TYPE Z_SOME_TYPE
* +--------------------------------------------------------------------------------------</SIGNATURE>
method SOME_STATIC_METHOD.
"" some coding
endmethod.
ENDCLASS.
When trying to activate the coding I get the following message:
The name of the PUBLIC class in the current CLASS POOL must be "Z_MY_GLOBAL_CLASS", not "Z_MY_LOCAL_CLASS".
or in German:
Der Name der PUBLIC-Klasse im aktuellen CLASS-POOL muß "Z_MY_GLOBAL_CLASS" statt "Z_MY_LOCAL_CLASS" lauten.
What does it mean?
回答1:
As often within SAP/ABAP the error message does not describe the actual error. In the definition of your local class change these lines
class Z_MY_LOCAL_CLASS definition
public
final
create public .
to this
class Z_MY_LOCAL_CLASS definition final create public.
and it should compile. So the problem is that only global classes are allowed to contain public. When copying/migrating source code from existing global classes to local classes you have to remove those lines.
来源:https://stackoverflow.com/questions/58056207/the-name-of-the-public-class-in-the-current-class-pool-must-be-not