When START-OF-SELECTION is Not
Required
Can you why the following program is not working. If I remove start-of-selection and what is the importance of start-of-selection...... how we come to know that we have to use start-of-selection here...if I put start-of-selection statement in any line apart from that line it shows error, why is it so? REPORT ZABAPOO . CLASS RAJ DEFINITION.
CLASS RAJ IMPLEMENTATION.
DATA: V1 TYPE I,
DATA: OBJ TYPE REF TO RAJ.
CREATE OBJECT OBJ.
CALL METHOD OBJ->SUM
WRITE: SUM. ----------------- This is just to elaborate on why START-OF-SELECTION is not required if CLASS IMPLEMENTATION is put at the end of the code. It is a very basic, yet interesting concept and not relevant to only Object Oriented ABAP. In an ABAP report, non declarative statements (means other
than data: or type stmts) that are not assigned to a processing block
are never executed. Only exception to this are the statements between the
REPORT or PROGRAM statement and the first processing block (say a subroutine).
These statements are assigned to the default event
For example see the follwoing code - REPORT ZTEST. * Statements between the REPORT or PROGRAM statement and
the first
* First processing block
* Statement not assigned to any processing block - NOT
ACCESSIBLE
In the above program the 2 nd WRITE statement after the
first processing block
There are 2 ways to avoid this syntax error - Method 1 : Assign the unaccessible statement to the START-OF-SELECTION block, by writing keyword START-OF-SELECTION just before it. Now START-OF-SELECTION block will contain (statements between the REPORT or PROGRAM statement and the first processing block) & (statements written after keyword START-OF-SELECTION) REPORT ZTEST. * Statements between the REPORT or PROGRAM statement and
the first
* First processing block
* Assign the unaccessible statement to START OF SELECTION
block
PERFORM proc_block1. Method 2 : Write the first processing block (FORM proc_block1) at the end i.e. after all statements not assigned to a processing block. So all those statements will now fall under the exception category (i.e. statements between the REPORT or PROGRAM statement and the first processing block) and can be accessed. REPORT ZTEST. * Statements between the REPORT or PROGRAM statement and
the first
WRITE / 'Learn ABAP'. PERFORM proc_block1. * First processing block put after all the statements
which are
Now this was a procedural program, thinking from ABAP
Objects perspective,
To avoid this error we can use 2 ways as discussed above - either assign the statement to a START-OF-SELECTION block or put the first processing block i.e. CLASS IMPLEMENTATION at the end of the code. *-- Ashwini Gangam
Related: ABAP Books ListABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books ABAP Menu:
Return to Index:-
(c) www.gotothings.com All material on this site is Copyright.
|