2009 Sep 02 8:12 AM
Why we need set the 'Create object xx' between 'class definition' and 'class implementation'??
If i set the 'CREATE OBJECT' under the 'Class implementation' in a report, the system will tell me that: 'Statement is not accessible'.
This is my code:
CLASS lcl_retal DEFINITION.
PUBLIC SECTION.
METHODS constructor.
PRIVATE SECTION.
DATA: lv_car(10) TYPE c VALUE 'CAR',
lv_truck(10) TYPE c VALUE 'TRUCK'.
ENDCLASS. "lcl_retal DEFINITION
CLASS lcl_retal IMPLEMENTATION.
METHOD constructor .
WRITE: lv_car, space, lv_truck.
ENDMETHOD. "print_detaile
ENDCLASS. "lcl_retal IMPLEMENTATION
DATA: lo_retal TYPE REF TO lcl_retal.
CREATE OBJECT lo_retal.
Edited by: YINYAN LU on Sep 2, 2009 9:14 AM
2009 Sep 02 8:35 AM
Class definition - class implementation is treated by system as declaration part. This is similary considered as DATA, TYPES section.
Every single statement which is not part of declaration/definition is part of program to execute (is automatically embraced to START-OF-SELECTION event). In regular program when you set DATA, TYPES it can both occur in declaration part and in execution part. On the other hand CLASS...ENDCLASS is considered purely as declaration/definition (not executable code itself) so can't be placed in START-OF-SELECTION.
Assuming above, when you place CREATE OBJECT b/w CLASS....DEFINITON - CLASS .... IMPLEMENTATION it is recognized as part of executable code, but is placed within the one not intended to be executed. System can't split this code to declaration/execution part. It must be explicitly pointed. So it must be of strcuture
"------------------------- DECLARATION/DEFINITION ---------------------
CLASS lcl_retal DEFINITION.
PUBLIC SECTION.
METHODS constructor.
PRIVATE SECTION.
DATA: lv_car(10) TYPE c VALUE 'CAR',
lv_truck(10) TYPE c VALUE 'TRUCK'.
ENDCLASS. "lcl_retal DEFINITION
"<- here still part of this block, so no executable statements allowed
CLASS lcl_retal IMPLEMENTATION.
METHOD constructor .
WRITE: lv_car, space, lv_truck.
ENDMETHOD. "print_detaile
ENDCLASS. "lcl_retal IMPLEMENTATION
"---------------------------- EXECUTABLE CODE HERE ---------------
DATA: lo_retal TYPE REF TO lcl_retal.
CREATE OBJECT lo_retal.
Hope now it is clear
Regards
Marcin
Why we need set the 'Create object xx' between 'class definition' and 'class implementation'??
If i set the 'CREATE OBJECT' under the 'Class implementation' in a report, the system will tell me that: 'Statement is not accessible'.
This is my code:
CLASS lcl_retal DEFINITION.
PUBLIC SECTION.
METHODS constructor.
PRIVATE SECTION.
DATA: lv_car(10) TYPE c VALUE 'CAR',
lv_truck(10) TYPE c VALUE 'TRUCK'.
ENDCLASS. "lcl_retal DEFINITION
CLASS lcl_retal IMPLEMENTATION.
METHOD constructor .
WRITE: lv_car, space, lv_truck.
ENDMETHOD. "print_detaile
ENDCLASS. "lcl_retal IMPLEMENTATION
DATA: lo_retal TYPE REF TO lcl_retal.
CREATE OBJECT lo_retal.
Edited by: YINYAN LU on Sep 2, 2009 9:14 AM
2009 Sep 02 8:35 AM
Class definition - class implementation is treated by system as declaration part. This is similary considered as DATA, TYPES section.
Every single statement which is not part of declaration/definition is part of program to execute (is automatically embraced to START-OF-SELECTION event). In regular program when you set DATA, TYPES it can both occur in declaration part and in execution part. On the other hand CLASS...ENDCLASS is considered purely as declaration/definition (not executable code itself) so can't be placed in START-OF-SELECTION.
Assuming above, when you place CREATE OBJECT b/w CLASS....DEFINITON - CLASS .... IMPLEMENTATION it is recognized as part of executable code, but is placed within the one not intended to be executed. System can't split this code to declaration/execution part. It must be explicitly pointed. So it must be of strcuture
"------------------------- DECLARATION/DEFINITION ---------------------
CLASS lcl_retal DEFINITION.
PUBLIC SECTION.
METHODS constructor.
PRIVATE SECTION.
DATA: lv_car(10) TYPE c VALUE 'CAR',
lv_truck(10) TYPE c VALUE 'TRUCK'.
ENDCLASS. "lcl_retal DEFINITION
"<- here still part of this block, so no executable statements allowed
CLASS lcl_retal IMPLEMENTATION.
METHOD constructor .
WRITE: lv_car, space, lv_truck.
ENDMETHOD. "print_detaile
ENDCLASS. "lcl_retal IMPLEMENTATION
"---------------------------- EXECUTABLE CODE HERE ---------------
DATA: lo_retal TYPE REF TO lcl_retal.
CREATE OBJECT lo_retal.
Hope now it is clear
Regards
Marcin
2009 Sep 02 8:58 AM
HI,
Thanks for your help. This is very useful for me.
Thanks and Best regards,
Yinyan Lu
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |