You add some documentation to your code to facilitate the support.
Task 1: Copy Template (Optional)
Copy the template 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 view, 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 the name ZCL_##_SOLUTION, where ## stands for your group number.
Adjust the description and 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 is only one instance for the same 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 quick fix.
From the list of available quick fixes, choose Add ABAP Doc.
The quick fix adjusts the code as follows:
1234
"!
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 code row that starts with "!
.Adjust the code as follows:
12345
"! Flight Carrier -
"! A factory logic ensures that there is only one instance for the same carrier ID.
CLASS lcl_carrier DEFINITION CREATE PRIVATE.
Display the Code Element Information 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 code element information.
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 your local 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 quick fix.
From the list of available quick fixes, choose Add ABAP Doc.
The quick fix adjusts the code as follows:
1234567
"!
"! @parameter i_carrier_id |
"! @parameter r_result |
"! @raising zcx_##_failed |
CLASS-METHODS get_instance
Maintain the documentation for the method with the text from the table.
Adjust the code as follows:
123456
"! Factory method - returns an instance of this class.
"! @parameter i_carrier_id |
"! @parameter r_result |
"! @raising zcx_##_failed |
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:
1234567
"! 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.
"! @raising zcx_##_failed | Instantiation failed - evaluate the exception text for details.
CLASS-METHODS get_instance
Display the Code Element Information for method GET_INSTANCE of local class LCL_CARRIER to see the output.
In the METHODS statement, place the cursor on get_instance and press F2 to show the code element information.
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. 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
- 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 your local 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 quick fix.
From the list of available quick fixes, choose Add ABAP Doc.
The quick fix adjusts the code as follows:
1234567891011
"!
"! @parameter i_airport_from_id |
"! @parameter i_airport_to_id |
"! @parameter i_from_date |
"! @parameter i_seats |
"! @parameter e_flight |
"! @parameter e_days_later |
METHODS find_passenger_flight
Maintain the documentation for the method with the text from the table. Make sure to add the formatting directives for passenger flight in bold type and for the unordered list.
Hint
You do not have to remember the format directives by heart. Press Ctrl + Space to insert a format directive though code-completion.Adjust the code as follows:
1234567891011121314
"! Search for a <strong>passenger flight</strong> between two airports that
"! <ul>
"! <li>lies on or after a given date and</li>
"! <li>has a minimum number of available seats left</li>
"!</ul>
"! @parameter i_airport_from_id |
"! @parameter i_airport_to_id |
"! @parameter i_from_date |
"! @parameter i_seats |
"! @parameter e_flight |
"! @parameter e_days_later |
METHODS find_passenger_flight
Maintain the documentation for the method parameters with the texts from the table. Make sure to add the formatting directives for Destination and Arrival in italic.
Adjust the code as follows:
1234567891011121314
"! Search for a <strong>passenger flight</strong> between two airports that
"! <ul>
"! <li>lies on or after a given date and</li>
"! <li>has a minimum number of available seats left</li>
"!</ul>
"! @parameter i_airport_from_id | <em>Departure</em> airport
"! @parameter i_airport_to_id | <em>Arrival</em> 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
METHODS find_passenger_flight
Display the Code Element Information 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 code element information.
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:
1234567891011121314
"! Search for a <strong>cargo flight</strong> between two airports that
"! <ul>
"! <li>lies on or after a given date and</li>
"! <li>has a minimum number of available capacity left</li>
"!</ul>
"! @parameter i_airport_from_id | <em>Departure</em> airport
"! @parameter i_airport_to_id | <em>Arrival</em> airport
"! @parameter i_from_date | First possible flight date
"! @parameter i_cargo | Minimum number of available capacity
"! @parameter e_flight | Found flight (object reference)
"! @parameter e_days_later | Number of days after the requested date
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 quick fix.
From the list of available quick fixes, choose Add ABAP Doc.
The quick fix adjusts the code as follows:
1234
"!
CLASS lcl_flight DEFINITION ABSTRACT.
Maintain the documentation with the text from the table.
Adjust the code as follows:
12345678
"! 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
CLASS lcl_flight DEFINITION ABSTRACT.
Add a line break after the first sentence.
Adjust the code as follows:
12345678910
"! Abstract superclass for classes
"! lcl_passenger_flight and
"! lcl_cargo_flight. <br/>
"! Every instance is uniquely identified by attributes
"! carrier_id,
"! connection_id, and
"! flight_date
CLASS lcl_flight DEFINITION ABSTRACT.
In the first sentence, 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:
12345678910
"! Abstract superclass for classes
"! {@link .lcl_passenger_flight and
"! {@link .lcl_cargo_flight. <br/>
"! Every instance is uniquely identified by attributes
"! carrier_id,
"! connection_id, and
"! flight_date
CLASS lcl_flight DEFINITION ABSTRACT.
In the second sentence, add links to the attributes of local class LCL_FLIGHT.
Note
Remember that if you want to address an attribute or any other data object, you have to insert DATA: immediately before the object name.Adjust the code as follows:
12345678910
"! Abstract superclass for classes
"! {@link .lcl_passenger_flight} and
"! {@link .lcl_cargo_flight}. <br/>
"! Every instance is uniquely identified by attributes
"! {@link .lcl_flight.DATA:carrier_id },
"! {@link .lcl_flight.DATA:connection_id }, and
"! {@link .lcl_flight.DATA:flight_date }.
CLASS lcl_flight DEFINITION ABSTRACT.
Display the Code Element Information 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 code element information.
The ABAP Doc text is displayed under the heading Documentation.
Finally, activate your code.
Press Ctrl + F3 to activate the code.