In this exercise, you will add documentation to your coding to make working with it easier.
Task 1: Copy Template (Optional)
Copy the template class /LRN/CL_S4D401_EXS_CLASS. If you finished the previous exercise, you can skip this task and continue editing your class ZCL_##_SOLUTION.
Steps
Copy class /LRN/CL_S4D401_EXS_CLASS to a class in your own package (suggested name: ZCL_##_SOLUTION, where ## stands for your group number).
In the Project Explorer, right-click class /LRN/CL_S4D401_EXS_CLASS to open the context menu.
From the context menu, choose Duplicate....
Enter the name of your package in the Package field. In the Name field, enter ZCL_##_SOLUTION, where ## stands for your group number.
Choose Next.
Confirm the transport request and choose Finish.
Activate the copy.
Press Ctrl + F3 to activate the class.
Task 2: Add Documentation
Add ABAP Doc documentation to local class LCL_CARRIER and factory method GET_INSTANCE.
Suggested Documentation Texts
| Type | Code Element | Documentation |
|---|
| Local Class | LCL_CARRIER | Flight Carrier - A factory logic ensures that there can only be one instance for each carrier ID. |
| Method | GET_INSTANCE | Factory method - returns an instance of this class. |
| Parameter | i_carrier_id | Three-character identification of the carrier. |
| Parameter | r_result | Reference to the instance - initial if instantiation failed. |
| Exception | ZCX_##_FAILED | Instantiation failed - evaluate the exception text for details. |
Steps
Use a quick fix to add ABAP Doc documentation to local class LCL_CARRIER.
In your global class, navigate to the definition of local class LCL_CARRIER.
In the CLASS … DEFINITION statement, place the cursor on lcl_carrier and press Ctrl + 1 to invoke the available quick fixes.
From the list of available quick fixes, choose Add ABAP Doc.
Result
The quick fix adjusts the code as follows:
12
CLASS lcl_carrier DEFINITION CREATE PRIVATE.
Maintain the documentation with the text from the table.
Hint
When you press Enter, the editor inserts a new row that starts with "!.
Adjust the code as follows:
123
CLASS lcl_carrier DEFINITION CREATE PRIVATE.
Display the ABAP Element Info for local class LCL_CARRIER to see the output.
In the CLASS … DEFINITION statement, place the cursor on lcl_carrier and press F2 to show the element info.
The ABAP Doc text is displayed under the heading Documentation.
Use a quick fix to add ABAP Doc documentation to static method GET_INSTANCE of local class LCL_CARRIER.
In the LCL_CARRIER class, navigate to the definition of method GET_INSTANCE.
In the CLASS-METHODS statement, place the cursor on get_instance and press Ctrl + 1 to invoke the available quick fixes.
From the list of available quick fixes, choose Add ABAP Doc.
Result
The quick fix adjusts the code as follows:
12345
CLASS-METHODS get_instance
Maintain the documentation for the method with the text from the table.
Adjust the code as follows:
12345
CLASS-METHODS get_instance
Maintain the documentation for the method parameters and for the exception with the texts from the table.
Adjust the code as follows:
12345
CLASS-METHODS get_instance
Display the ABAP Element Info for method GET_INSTANCE of local class LCL_CARRIER to see the output.
In the CLASS-METHODS statement, place the cursor on get_instance and press F2 to show the element info.
The ABAP Doc texts are displayed under the heading Documentation.
Task 3: Add Formatted Documentation
Add formatted ABAP Doc documentation for method FIND_PASSENGER_FLIGHT of local class LCL_CARRIER. Optionally, add a similar ABAP Doc documentation for method FIND_CARGO_FLIGHT.
Suggested Documentation Texts
| Type | Code Element | Documentation |
|---|
| Method | FIND_PASSENGER_FLIGHT | Search for a passenger flight between two airports that - lies on or after a given date and
- has a minimum number of available seats left
|
| Parameter | i_airport_from_id | Departure airport |
| Parameter | i_airport_to_id | Arrival airport |
| Parameter | i_from_date | First possible flight date |
| Parameter | i_seats | Minimum number of available seats |
| Parameter | e_flight | Found flight (object reference) |
| Parameter | e_days_later | Number of days after the requested date |
Steps
Use a quick fix to add ABAP Doc documentation to method FIND_PASSENGER_FLIGHT of local class LCL_CARRIER.
In the LCL_CARRIER class, navigate to the definition of method FIND_PASSENGER_FLIGHT.
In the METHODS statement, place the cursor on find_passenger_flight and press Ctrl + 1 to invoke the available quick fixes.
From the list of available quick fixes, choose Add ABAP Doc.
Result
The quick fix adjusts the code as follows:
12345678
METHODS find_passenger_flight
Maintain the documentation for the method with the text from the table. Make sure to format passenger flight as strong emphasized text and use an unsorted list for the flight properties.
Hint
You do not have to remember the format directives by heart. Press Ctrl + Space to insert a format directive through code completion.
Adjust the code as follows:
123456789101112
METHODS find_passenger_flight
Maintain the documentation for the method parameters with the texts from the table. Make sure to format Departure and Arrival as emphasized text.
Adjust the code as follows:
123456789101112
METHODS find_passenger_flight
Display the ABAP Element Info for method FIND_PASSENGER_FLIGHT of local class LCL_CARRIER to see the output.
In the METHODS statement, place the cursor on find_passenger_flight and press F2 to show the element info.
The ABAP Doc texts are displayed under the heading Documentation.
Optional: Add similar formatted ABAP Doc documentation for method FIND_CARGO_FLIGHT.
Hint
Copy and paste the ABAP Doc documentation for method FIND_PASSENGER_FLIGHT and adjust it to method FIND_CARGO_FLIGHT.
Adjust the code as follows:
123456789101112
METHODS find_cargo_flight
Task 4: Add Links
Add the following ABAP Doc documentation for local class LCL_FLIGHT:
Suggested Documentation Texts
| Type | Code Element | Documentation |
|---|
| Local Class | LCL_FLIGHT | Abstract superclass for classes lcl_passenger_flight and lcl_cargo_flight Every instance is uniquely identified by attributes carrier_id, connection_id, and flight_date. |
Add links to the documentation of local subclasses LCL_PASSENGER_FLIGHT and LCL_CARGO_FLIGHT and to the public attributes carrier_id, connection_id, and flight_date.
Steps
Use a quick fix to add ABAP Doc documentation to local class LCL_FLIGHT.
In your global class, navigate to the definition of local class LCL_FLIGHT.
In the CLASS … DEFINITION statement, place the cursor on lcl_flight and press Ctrl + 1 to invoke the available quick fixes.
From the list of available quick fixes, choose Add ABAP Doc.
Result
The quick fix adjusts the code as follows:
12
CLASS lcl_flight DEFINITION ABSTRACT.
Maintain the documentation with the text from the table.
Adjust the code as follows:
12345678
CLASS lcl_flight DEFINITION ABSTRACT.
Add a line break after lcl_cargo_flight.
Adjust the code as follows:
12345678
CLASS lcl_flight DEFINITION ABSTRACT.
Add a link to the documentation of local class LCL_PASSENGER_FLIGHT and a link to the documentation of local class LCL_CARGO_FLIGHT.
Note
Remember that this ABAP Doc documentation lies on global class level and not inside of local class LCL_FLIGHT. This means that a period sign at the beginning of a link addresses the global class. To address a local class in the same global class, you have to place a period sign in front of the class name.
Adjust the code as follows:
12345678
CLASS lcl_flight DEFINITION ABSTRACT.
Now add links to the attributes carrier_id, connection_id, and flight_date of local class LCL_FLIGHT.
Note
If you want to reference an attribute or other data object in a link, you must insert DATA: immediately before the object name.
Adjust the code as follows:
12345678
CLASS lcl_flight DEFINITION ABSTRACT.
Display the ABAP Element Info for local class LCL_FLIGHT to see the output. Choose the links to verify that they work.
In the CLASS … DEFINITION statement, place the cursor on lcl_flight and press F2 to show the element info.
The ABAP Doc text is displayed under the heading Documentation.
Finally, activate your code.
Press Ctrl + F3 to activate the code.