CD164_exercise123

5
 © 2012 by SAP AG. All rights reserved. SAP and the SAP logo are registered trademarks of SAP AG in Germany and other countries. Business Objects and the Business Objects logo are trademarks or registered trademarks of Business Objects Software Ltd. Business Objects is an SAP company. Sybase and the Sybase logo are registered trademarks of Sybase Inc. Sybase is an SAP company. Crossgate is a registered trademark of Crossgate AG in Germany and other countries. Crossgate is an SAP company.  MODERN ABAP WITH ABAP DEVELOPMENT TOOLS FOR ECLIPSE CD164 Exercises Las Vegas: Michael Gutfleisch, Holger Janz, Tobias Melcher / SAP AG Madrid: Christian Georgi, Holger Janz, Sebastian Wolf / SAP AG

description

cdddee 123

Transcript of CD164_exercise123

  • 2012 by SAP AG. All rights reserved. SAP and the SAP logo are registered trademarks of SAP AG in Germany and other countries. Business Objects and the Business Objects logo are trademarks or registered trademarks of Business Objects Software Ltd. Business Objects is an SAP company. Sybase and the Sybase logo are registered trademarks of Sybase Inc. Sybase is an SAP company. Crossgate is a registered trademark of Crossgate AG in Germany and other countries. Crossgate is an SAP company.

    MODERN ABAP WITH

    ABAP DEVELOPMENT TOOLS FOR ECLIPSE

    CD164

    Exercises Las Vegas: Michael Gutfleisch, Holger Janz, Tobias Melcher / SAP AG Madrid: Christian Georgi, Holger Janz, Sebastian Wolf / SAP AG

  • 2

    EXERCISE 1: EXPLORE THE EXISTING CODE BASE

    ## = Number of your group/notebook

    a) Open Project / Add Favorite Package

    1. Open ABAP Development Tools and switch to the ABAP perspective

    The shortcut to the ABAP Development Tools can be found in the Session (Local) folder directly on your desktop. After you have opened this Session (Local) folder, search for the subfolder CD164, open it and execute the shortcut ABAP Development Tools - CD164. You can also access the shortcut from the file system, just navigate to D:\Files\Session\CD164\.

    2. Create an ABAP project for system M50 client 800 with user CD164-## and password welcome. 3. Assign the package TEST_TECHED_CD164_## to your favourite packages. 4. Explore the content of this package by using the project explorer.

    b) Open ABAP Development Object (Ctrl-Shift-A)

    1. How many classes match the pattern Z*_##_VEHICLE? 2. How many lines of code has the interface ZIF_##_VEHICLE?

    c) Type Hierarchy (F4, Ctrl-T)

    1. How many levels has the type hierarchy of ZIF_##_VEHICLE? 2. How many classes are subtypes of ZIF_##_VEHICLE?

    d) Where-Used (Ctrl-Shift-G)

    1. How often is method GET_ELAPSED_SECONDS of class ZCL_##_CAR used? 2. In which development objects (reports, class-pools, etc.)? 3. What are the names of the test classes in which this method is tested?

    e) Outline (Ctrl-O)

    1. How many options (units of measure) do you have to create an instance of class ZCL_##_SPEED? 2. How many test methods contains the test class of ZCL_##_SPEED? 3. What is the type of the private attribute METERS?

  • 3

    EXERCISE 2: DO SOME MINOR CHANGES

    Extend the existing code base by doing some clean ups like removing compiler warnings and unused code, extend code coverage, trigger code formatter

    a) Quick Fixes (Ctrl-1)

    1. The class ZCL_##_SHIP has a syntax warning what is the issue? 2. Create the missing method implementation by using a quick fix.

    b) ABAP Unit (Ctrl-Shift-F10) / Coverage (Ctrl-Shift-F11)

    1. Execute the unit tests of class ZCL_##_SPEED, find out how many tests are being executed. 2. Which methods of class ZCL_##_SPEED are not covered by 100% statement coverage in unit test execution?

    3. Write a unit test to increase the coverage for method compare.

    4. Optional: Write a unit test to increase the coverage for the methods plus and minus.

    c) Occurrence Marking / Local Rename

    1. How often is the local variable S1 used in method DRIVE_AS_FAST_AS_YOU_CAN of class ZCL_##_CAR? 2. Use the quick fix Rename in source unit to change the name from S1 to SPEED1. 3. Do the same for S2 or undo the first quick fix.

    d) Clean-up Unused Variables (Alt-U, Alt-Shift-U)

    1. Try to figure out the unused variables inside method DRIVE_AS_FAST_AS_YOU_CAN of class ZCL_##_CAR. 2. Use the Clean-up feature for those unused variables. 3. Undo the changes by pressing Ctrl-Z

    e) Format / Pretty Print (Shift-F1) 1. Select the code of method DRIVE_AS_FAST_AS_YOU_CAN of class ZCL_##_CAR and format the code 2. Change Code Formatter (Pretty-Printer)-Settings 3. Format again

  • 4

    EXERCISE 3: IMPLEMENT A NEW FEATURE

    Currently the class ZCL_##_SPEED cannot be used for ships, because it is not able to deal with knots. Your task is to add the new functionality in a Test-First-Approach.

    Knot: nautical mile (1.852 km) per hour

    Agile (test driven) development

    1. Open class ZCL_##_SPEED, create the new test method knots_to_knots

    2. Create and implement method ZCL_##_SPEED=>CREATE_KNOTS method by using a quick fix from the test method

    3. Implement a new test assertion by using the assertEquals code template for method ZCL_##_SPEED-

    >KNOTS, verify that this method returns the same value as you have passed to the create_knots( ) method

    4. Optional: Write a second test method knots_to_mph in order to verify the correct conversion from knots to miles

    per hour.

  • 5

    EXERCISE 4: USE THE VEHICLE-API

    a) Code Completion / F2 Code Element Info

    1. Open report ZRP_##_VEHICLE_RACE, follow the instructions in the source code to complete its functionality

    b) Direct execution via F8

    1. Execute the report 2. Change the report (acceleration, max_speed, distance) and execute again