ABAP_OBJECTS

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L1S31 { font-style: italic; color: #808080; } .L1S32 { color: #3399FF; } .L1S33 { color: #4DA619; } .L1S52 { color: #0000FF; } REPORTdemo_abap_objects.

*---------------------------------------------------------------------*
*GlobalSelectionScreen
*---------------------------------------------------------------------*

SELECTION-SCREENBEGINOFSCREEN100ASWINDOWTITLEtext-100.
PARAMETERS:button1RADIOBUTTONGROUPgrp,
button2RADIOBUTTONGROUPgrp,
button3RADIOBUTTONGROUPgrp,
button4RADIOBUTTONGROUPgrp.
SELECTION-SCREENENDOFSCREEN100.

*---------------------------------------------------------------------*
*INTERFACEstatus
*---------------------------------------------------------------------*
*Interfacedefinition*
*---------------------------------------------------------------------*
INTERFACEstatus.
METHODSwrite.
ENDINTERFACE.

*---------------------------------------------------------------------*
*CLASSvesselDEFINITION
*---------------------------------------------------------------------*
*Superclassdefinition*
*---------------------------------------------------------------------*
CLASSvesselDEFINITION.
PUBLICSECTION.
METHODS:constructor,
driveIMPORTINGspeed_upTYPEi,
get_idRETURNINGvalue(id)TYPEi.
PROTECTEDSECTION.
DATA:speedTYPEi,
max_speedTYPEiVALUE100.
PRIVATESECTION.
CLASS-DATAobject_countTYPEi.
DATAidTYPEi.
ENDCLASS.

*---------------------------------------------------------------------*
*CLASSvesselIMPLEMENTATION
*---------------------------------------------------------------------*
*Superclassimplementation*
*---------------------------------------------------------------------*
CLASSvesselIMPLEMENTATION.
METHODconstructor.
object_count=object_count+1.
id=object_count.
ENDMETHOD.
METHODdrive.
speed=speed+speed_up.
IFspeed>max_speed.
speed=max_speed.
ENDIF.
ENDMETHOD.
METHODget_id.
id=me->id.
ENDMETHOD.
ENDCLASS.

*---------------------------------------------------------------------*
*CLASSshipDEFINITION
*---------------------------------------------------------------------*
*Subclassdefinition*
*---------------------------------------------------------------------*
CLASSshipDEFINITIONINHERITINGFROMvessel.
PUBLICSECTION.
INTERFACESstatus.
DATAnameTYPEstringREAD-ONLY.
METHODS:constructorIMPORTINGnameTYPEstring,
driveREDEFINITION.
EVENTSemergency_call.
ENDCLASS.

*---------------------------------------------------------------------*
*CLASSshipIMPLEMENTATION
*---------------------------------------------------------------------*
*Subclassimplementation*
*---------------------------------------------------------------------*
CLASSshipIMPLEMENTATION.
METHODconstructor.
CALLMETHODsuper->constructor.
max_speed=30.
me->name=name.
ENDMETHOD.
METHODstatus~write.
DATAid.
id=me->get_id().
WRITE:/name,'isvessel',id,
'andhasspeed',speed.
ENDMETHOD.
METHODdrive.
speed=speed+speed_up.
IFspeed>max_speed.
max_speed=0.
speed=0.
RAISEEVENTemergency_call.
ENDIF.
ENDMETHOD.
ENDCLASS.

*---------------------------------------------------------------------*
*CLASScoast_guardDEFINITION
*---------------------------------------------------------------------*
*Eventhandlerdefinition*
*---------------------------------------------------------------------*
CLASScoast_guardDEFINITION.
PUBLICSECTION.
INTERFACESstatus.
METHODSreceiveFOREVENTemergency_callOFshipIMPORTINGsender.
ALIASESwriteFORstatus~write.
PRIVATESECTION.
DATAcallerTYPEstring.
ENDCLASS.

*---------------------------------------------------------------------*
*CLASScoast_guardIMPLEMENTATION
*---------------------------------------------------------------------*
*Eventhandlerimplementation*
*---------------------------------------------------------------------*
CLASScoast_guardIMPLEMENTATION.
METHODstatus~write.
IFcallerISINITIAL.
WRITE:/'Coastguardreceivednocall'.
ELSE.
WRITE:/'Coastguardreceivedacallfrom',caller.
ENDIF.
ENDMETHOD.
METHODreceive.
caller=sender->name.
CALLMETHODwrite.
ENDMETHOD.
ENDCLASS.

*---------------------------------------------------------------------*
*CLASSmainDEFINITION
*---------------------------------------------------------------------*
*Mainclassdefinition*
*---------------------------------------------------------------------*
CLASSmainDEFINITION.
PUBLICSECTION.
CLASS-METHODS:start,
objects,
inheritance,
interfaces,
events.
ENDCLASS.

*---------------------------------------------------------------------*
*CLASSmainIMPLEMENTATION
*---------------------------------------------------------------------*
*Mainclassimplementation*
*---------------------------------------------------------------------*
CLASSmainIMPLEMENTATION.

METHODstart.
CALLSELECTION-SCREEN100STARTINGAT103
ENDINGAT427.
IFsy-subrcNE0.
EXIT.
ELSEIFbutton1='X'.
CALLMETHODobjects.
ELSEIFbutton2='X'.
CALLMETHODinheritance.
ELSEIFbutton3='X'.
CALLMETHODinterfaces.
ELSEIFbutton4='X'.
CALLMETHODevents.
ENDIF.
ENDMETHOD.

METHODobjects.
DATA:vessel1TYPEREFTOvessel,
vessel2TYPEREFTOvessel.
DATA:vessel_idTYPEi.
CREATEOBJECT:vessel1TYPEvessel,
vessel2TYPEvessel.
CALLMETHOD:vessel1->drive(50),
vessel2->drive(80).
vessel_id=vessel1->get_id().
WRITE:/'VesselIDis',vessel_id.
vessel_id=vessel2->get_id().
WRITE:/'VesselIDis',vessel_id.
ENDMETHOD.

METHODinheritance.
DATA:vesselTYPEREFTOvessel,
shipTYPEREFTOship.
CREATEOBJECTshipTYPEshipEXPORTINGname='Titanic'.
CALLMETHODship->drive(20).
MOVEshipTOvessel.
CALLMETHODvessel->drive(10).
CALLMETHODship->status~write.
ENDMETHOD.

METHODinterfaces.
DATA:status_tabTYPETABLEOFREFTOstatus,
statusTYPEREFTOstatus.
DATA:shipTYPEREFTOship,
stationTYPEREFTOcoast_guard.
CREATEOBJECT:shipEXPORTINGname='Titanic'.
APPENDshipTOstatus_tab.
CREATEOBJECTstation.
APPENDstationTOstatus_tab.
LOOPATstatus_tabINTOstatus.
CALLMETHODstatus->write.
ENDLOOP.
ENDMETHOD.

METHODevents.
DATA:shipTYPEREFTOship,
stationTYPEREFTOcoast_guard.
CREATEOBJECT:shipEXPORTINGname='Titanic',
station.
SETHANDLERstation->receiveFORship.
DO5TIMES.
CALLMETHODship->drive(10).
ENDDO.
ENDMETHOD.

ENDCLASS.

*---------------------------------------------------------------------*
*SystemeventSTART-OF-SELECTION
*---------------------------------------------------------------------*
*TriggeredbytheABAPruntimeenvironmentautomatically*
*---------------------------------------------------------------------*

START-OF-SELECTION.
CALLMETHODmain=>start.

*---------------------------------------------------------------------*

你可能感兴趣的:(UP)