*******************************************************************
* Global Selection Screens
*******************************************************************
SELECTION-SCREEN BEGIN OF: SCREEN 100 TITLE TIT1, LINE.
PARAMETERS MEMBERS TYPE I DEFAULT 10.
SELECTION-SCREEN END OF: LINE, SCREEN 100.
*------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF SCREEN 200 TITLE TIT2.
PARAMETERS: DRIVE RADIOBUTTON GROUP ACTN,
STOP RADIOBUTTON GROUP ACTN,
GEARUP RADIOBUTTON GROUP ACTN,
GEARDOWN RADIOBUTTON GROUP ACTN.
SELECTION-SCREEN END OF SCREEN 200.
*******************************************************************
* Class Definitions
*******************************************************************
CLASS: C_BIKER DEFINITION DEFERRED,
C_BICYCLE DEFINITION DEFERRED.
*------------------------------------------------------------------
CLASS C_TEAM DEFINITION.
PUBLIC SECTION.
TYPES: BIKER_REF TYPE REF TO C_BIKER,
BIKER_REF_TAB TYPE STANDARD TABLE OF BIKER_REF
WITH DEFAULT KEY,
BEGIN OF STATUS_LINE_TYPE,
FLAG(1) TYPE C,
TEXT1(5) TYPE C,
ID TYPE I,
TEXT2(7) TYPE C,
TEXT3(6) TYPE C,
GEAR TYPE I,
TEXT4(7) TYPE C,
SPEED TYPE I,
END OF STATUS_LINE_TYPE.
CLASS-METHODS: CLASS_CONSTRUCTOR.
METHODS: CONSTRUCTOR,
CREATE_TEAM,
SELECTION,
EXECUTION.
PRIVATE SECTION.
CLASS-DATA: TEAM_MEMBERS TYPE I,
COUNTER TYPE I.
DATA: ID TYPE I,
STATUS_LINE TYPE STATUS_LINE_TYPE,
STATUS_LIST TYPE SORTED TABLE OF STATUS_LINE_TYPE
WITH UNIQUE KEY ID,
BIKER_TAB TYPE BIKER_REF_TAB,
BIKER_SELECTION LIKE BIKER_TAB,
BIKER LIKE LINE OF BIKER_TAB.
METHODS: WRITE_LIST.
ENDCLASS. "C_TEAM DEFINITION
*------------------------------------------------------------------
CLASS C_BIKER DEFINITION.
PUBLIC SECTION.
METHODS: CONSTRUCTOR IMPORTING TEAM_ID TYPE I MEMBERS TYPE I,
SELECT_ACTION,
STATUS_LINE EXPORTING LINE TYPE C_TEAM=>STATUS_LINE_TYPE.
PRIVATE SECTION.
CLASS-DATA COUNTER TYPE I.
DATA: ID TYPE I,
BIKE TYPE REF TO C_BICYCLE,
GEAR_STATUS TYPE I VALUE 1,
SPEED_STATUS TYPE I VALUE 0.
METHODS BIKER_ACTION IMPORTING ACTION TYPE I.
ENDCLASS. "C_BIKER DEFINITION
*------------------------------------------------------------------
CLASS C_BICYCLE DEFINITION.
PUBLIC SECTION.
METHODS: DRIVE EXPORTING VELOCITY TYPE I,
STOP EXPORTING VELOCITY TYPE I,
CHANGE_GEAR IMPORTING CHANGE TYPE I
RETURNING VALUE(GEAR) TYPE I
EXCEPTIONS GEAR_MIN GEAR_MAX.
PRIVATE SECTION.
DATA: SPEED TYPE I,
GEAR TYPE I VALUE 1.
CONSTANTS: MAX_GEAR TYPE I VALUE 18,
MIN_GEAR TYPE I VALUE 1.
ENDCLASS. "C_BICYCLE DEFINITION
*******************************************************************
*---------------------------------------------------------------------*
* CLASS C_TEAM IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS C_TEAM IMPLEMENTATION.
* CLASS_CONSTRUCTOR
METHOD CLASS_CONSTRUCTOR.
TIT1 = 'Team members ?'.
CALL SELECTION-SCREEN 100 STARTING AT 5 3.
IF SY-SUBRC NE 0.
LEAVE PROGRAM.
ELSE.
TEAM_MEMBERS = MEMBERS.
ENDIF.
ENDMETHOD. "C_TEAM
METHOD CONSTRUCTOR.
COUNTER = COUNTER + 1.
ID = COUNTER.
ENDMETHOD. "CONSTRUCTOR
METHOD CREATE_TEAM.
DO TEAM_MEMBERS TIMES.
CREATE OBJECT BIKER EXPORTING TEAM_ID = ID
MEMBERS = TEAM_MEMBERS.
APPEND BIKER TO BIKER_TAB.
CALL METHOD BIKER->STATUS_LINE
IMPORTING
LINE = STATUS_LINE.
APPEND STATUS_LINE TO STATUS_LIST.
ENDDO.
ENDMETHOD. "CREATE_TEAM
METHOD SELECTION.
CLEAR BIKER_SELECTION.
DO.
READ LINE SY-INDEX.
IF SY-SUBRC <> 0. EXIT. ENDIF.
IF SY-LISEL+0(1) = 'X'.
READ TABLE BIKER_TAB INTO BIKER INDEX SY-INDEX.
APPEND BIKER TO BIKER_SELECTION.
ENDIF.
ENDDO.
CALL METHOD WRITE_LIST.
ENDMETHOD. "SELECTION
METHOD EXECUTION.
CHECK NOT BIKER_SELECTION IS INITIAL.
LOOP AT BIKER_SELECTION INTO BIKER.
CALL METHOD BIKER->SELECT_ACTION.
CALL METHOD BIKER->STATUS_LINE
IMPORTING
LINE = STATUS_LINE.
MODIFY TABLE STATUS_LIST FROM STATUS_LINE.
ENDLOOP.
CALL METHOD WRITE_LIST.
ENDMETHOD. "EXECUTION
METHOD WRITE_LIST.
SET TITLEBAR 'TIT'.
SY-LSIND = 0.
SKIP TO LINE 1.
POSITION 1.
LOOP AT STATUS_LIST INTO STATUS_LINE.
WRITE: / STATUS_LINE-FLAG AS CHECKBOX,
STATUS_LINE-TEXT1,
STATUS_LINE-ID,
STATUS_LINE-TEXT2,
STATUS_LINE-TEXT3,
STATUS_LINE-GEAR,
STATUS_LINE-TEXT4,
STATUS_LINE-SPEED.
ENDLOOP.
ENDMETHOD. "WRITE_LIST
ENDCLASS. "C_TEAM IMPLEMENTATION
*---------------------------------------------------------------------*
* CLASS C_BIKER IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS C_BIKER IMPLEMENTATION.
METHOD CONSTRUCTOR.
COUNTER = COUNTER + 1.
ID = COUNTER - MEMBERS * ( TEAM_ID - 1 ).
CREATE OBJECT BIKE.
ENDMETHOD. "CONSTRUCTOR
METHOD SELECT_ACTION.
DATA ACTIVITY TYPE I.
TIT2 = 'Select action for BIKE'.
TIT2+24(3) = ID.
CALL SELECTION-SCREEN 200 STARTING AT 5 15.
CHECK NOT SY-SUBRC GT 0.
IF GEARUP = 'X' OR GEARDOWN = 'X'.
IF GEARUP = 'X'.
ACTIVITY = 1.
ELSEIF GEARDOWN = 'X'.
ACTIVITY = -1.
ENDIF.
ELSEIF DRIVE = 'X'.
ACTIVITY = 2.
ELSEIF STOP = 'X'.
ACTIVITY = 3.
ENDIF.
CALL METHOD BIKER_ACTION( ACTIVITY ).
ENDMETHOD. "SELECT_ACTION
METHOD BIKER_ACTION.
CASE ACTION.
WHEN -1 OR 1.
CALL METHOD BIKE->CHANGE_GEAR
EXPORTING
CHANGE = ACTION
RECEIVING
GEAR = GEAR_STATUS
EXCEPTIONS
GEAR_MAX = 1
GEAR_MIN = 2.
CASE SY-SUBRC.
WHEN 1.
MESSAGE I315(Z900) WITH 'BIKE' ID
' is already at maximal gear!'.
WHEN 2.
MESSAGE I315(Z900) WITH 'BIKE' ID
' is already at minimal gear!'.
ENDCASE.
WHEN 2.
CALL METHOD BIKE->DRIVE
IMPORTING
VELOCITY = SPEED_STATUS.
WHEN 3.
CALL METHOD BIKE->STOP
IMPORTING
VELOCITY = SPEED_STATUS.
ENDCASE.
ENDMETHOD. "BIKER_ACTION
METHOD STATUS_LINE.
LINE-FLAG = SPACE.
LINE-TEXT1 = 'Biker'.
LINE-ID = ID.
LINE-TEXT2 = 'Status:'.
LINE-TEXT3 = 'Gear = '.
LINE-GEAR = GEAR_STATUS.
LINE-TEXT4 = 'Speed = '.
LINE-SPEED = SPEED_STATUS.
ENDMETHOD. "STATUS_LINE
ENDCLASS. "C_BIKER IMPLEMENTATION
*---------------------------------------------------------------------*
* CLASS C_BICYCLE IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS C_BICYCLE IMPLEMENTATION.
METHOD DRIVE.
SPEED = SPEED + GEAR * 10.
VELOCITY = SPEED.
ENDMETHOD. "DRIVE
METHOD STOP.
SPEED = 0.
VELOCITY = SPEED.
ENDMETHOD. "STOP
METHOD CHANGE_GEAR.
GEAR = ME->GEAR.
GEAR = GEAR + CHANGE.
IF GEAR GT MAX_GEAR.
GEAR = MAX_GEAR.
RAISE GEAR_MAX.
ELSEIF GEAR LT MIN_GEAR.
GEAR = MIN_GEAR.
RAISE GEAR_MIN.
ENDIF.
ME->GEAR = GEAR.
ENDMETHOD. "CHANGE_GEAR
ENDCLASS. "C_BICYCLE IMPLEMENTATION
* Global Program Data
*******************************************************************
TYPES TEAM TYPE REF TO C_TEAM.
DATA: TEAM_BLUE TYPE TEAM,
TEAM_GREEN TYPE TEAM,
TEAM_RED TYPE TEAM.
DATA COLOR(5).
*******************************************************************
* Program events
*******************************************************************
START-OF-SELECTION.
CREATE OBJECT: TEAM_BLUE,
TEAM_GREEN,
TEAM_RED.
CALL METHOD: TEAM_BLUE->CREATE_TEAM,
TEAM_GREEN->CREATE_TEAM,
TEAM_RED->CREATE_TEAM.
SET PF-STATUS 'TEAMLIST'.
WRITE ' Select a team! ' COLOR = 2.
*------------------------------------------------------------------
AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'TEAM_BLUE'.
COLOR = 'BLUE'.
FORMAT COLOR = 1 INTENSIFIED ON INVERSE ON.
CALL METHOD TEAM_BLUE->SELECTION.
WHEN 'TEAM_GREEN'.
COLOR = 'GREEN'.
FORMAT COLOR = 5 INTENSIFIED ON INVERSE ON.
CALL METHOD TEAM_GREEN->SELECTION.
WHEN 'TEAM_RED'.
COLOR = 'RED'.
FORMAT COLOR = 6 INTENSIFIED ON INVERSE ON.
CALL METHOD TEAM_RED->SELECTION.
WHEN 'EXECUTION'.
CASE COLOR.
WHEN 'BLUE '.
FORMAT COLOR = 1 INTENSIFIED ON INVERSE ON.
CALL METHOD TEAM_BLUE->SELECTION.
CALL METHOD TEAM_BLUE->EXECUTION.
WHEN 'GREEN'.
FORMAT COLOR = 5 INTENSIFIED ON INVERSE ON.
CALL METHOD TEAM_GREEN->SELECTION.
CALL METHOD TEAM_GREEN->EXECUTION.
WHEN 'RED '.
FORMAT COLOR = 6 INTENSIFIED ON INVERSE ON.
CALL METHOD TEAM_RED->SELECTION.
CALL METHOD TEAM_RED->EXECUTION.
ENDCASE.
ENDCASE.