ABAP Objects - Exercise 1 - Classes and Objects (Global)
ABAP Objects - Exercise 1 - Classes and Objects (Global)
Hit Enter.
3. Right
Click the name of the local package and navigate to the creation of a class (where XX is your group
number).
4. Fill
the pop-up as follows ZCL_VEHICLE_XX (where XX is your group number) and select Save.
5. Acknowledge
the following window without changes (select either Save or Local Object).
The same holds for all other development objects during this exercise.
6. Now
Here you can edit the class either in Form-Based mode (default) or in Source Code-Based mode. Use the
respective button to toggle between the modes.
7. Switch
METHODS stop.
METHODS show.
PROTECTED SECTION.
DATA: speed TYPE i,
max_speed TYPE i VALUE 50.
PRIVATE SECTION.
DATA id TYPE i .
CLASS-DATA object_count TYPE i.
ENDCLASS.
CLASS zcl_vehicle_xx IMPLEMENTATION.
METHOD constructor.
object_count = object_count + 1.
id = object_count.
ENDMETHOD.
METHOD show.
DATA msg TYPE string.
msg = `Vehicle ` && |{ id }| &&
`, Speed = ` && |{ speed }| &&
`, Max-Speed = ` && |{ max_speed }|.
MESSAGE msg TYPE 'I'.
ENDMETHOD.
METHOD speed_up.
speed = speed + step.
IF speed > max_speed.
speed = max_speed.
ENDIF.
ENDMETHOD.
METHOD stop.
speed = 0.
ENDMETHOD.
ENDCLASS.
Check
8. Switch
, Save
and Activate
2. Fill
3. Implement
Check
4. Select
, Save
and Activate
Now you can see the Ids and speed of the objects created.
Test the method again and play around with the ABAP Debugger.