You realize that your code contains large internal tables of table kind Standard Table. You analyze the way these tables are accessed in the code and find that they are only accessed by key. To improve the performance, you change the definition of the internal tables to either Sorted Table or Hashed Table, depending on the way they are accessed.
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_ITS_FSYM 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_ITS_FSYM 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: Adjust CONNECTIONS_BUFFER
Use the Where-used list for static attribute connections_buffer of local class LCL_PASSENGER_FLIGHT. Change the definition of connections_buffer so that it best suites the way it is accessed.
Steps
Navigate to the definition of static attribute connections_buffer in local class LCL_PASSENGER_FLIGHT.
For example, expand the LCL_PASSENGER_FLIGHT node in the Outline view and choose CONNECTIONS_BUFFER.
Create the Where-used list for the connections_buffer attribute.
In the CLASS-DATA statement, right-click on connections_buffer and choose Get Where-Used List. Alternatively, you can place the cursor on connections_buffer and press Ctrl + Shift + G.
Analyze the list in the Search view below the editor view. Place the cursor over a finding to display the complete statement.
Adjust the definition of the connections_buffer attribute. Choose the table kind and key definition that best fits the read access.
Change the table kind to HASHED TABLE.
Change the key definition to a unique key with carrier_id and connection_id as the key fields.
Adjust the code as follows:
12
* CLASS-DATA connections_buffer TYPE TABLE OF st_connections_buffer.
Task 3: Adjust FLIGHTS_BUFFER
Use the Where-used list for static attribute flights_buffer of local class LCL_PASSENGER_FLIGHT. Change the definition of flights_buffer so that it best suites the way the attribute is accessed.
Steps
Navigate to the definition of static attribute flights_buffer in local class LCL_PASSENGER_FLIGHT.
For example, expand node LCL_PASSENGER_FLIGHT in the Outline view and choose FLIGHTS_BUFFER,
Create the Where-used list for the flights_buffer attribute.
In the CLASS-DATA statement, right-click on flights_buffer and choose Get Where-Used List. Alternatively, you can place the cursor on flights_buffer and press Ctrl + Shift + G.
Analyze the list in the Search view below the editor view. Place the cursor over a finding to display the complete statement.
Adjust the definition of attribute flights_buffer. Choose the table kind and key definition that best fits the read accesses.
Change the table kind to SORTED TABLE.
Change the key definition to a non-unique key with carrier_id, connection_id, and flight_date as the key fields.
Adjust the code as follows:
12
* CLASS-DATA: flights_buffer TYPE TABLE OF st_flights_buffer.
Analyze the syntax errors on the Problems view.
Analyze the Problems view below the Editor view.
Remove or comment the redundant SORT statement.
Adjust the code as follows:
123
* SORT flights_buffer BY carrier_id connection_id flight_date.
Activate and test your global class as console app.
Press Ctrl + F3.
Press F9.
Task 4: Quantify the Improvement
Using ABAP Profiling, quantify the performance improvement of the sorted table and hashed table.
Steps
Locate the template class /LRN/CL_S4D401_ITS_FSYM in the Project Explorer view.
Profile the template class /LRN/CL_S4D401_ITS_FSYM as an ABAP console app.
Locate the template class /LRN/CL_S4D401_ITS_FSYM in the Project Explorer view.
Right-click the name of the template class and choose Profile As → 2 ABAP Application (Console).
Wait until the Console view appears or is refreshed.
Return to your own class (ZCL_##_SOLUTION, where ## is your group number) and profile it in the same way.
Locate your own class in the Project Explorer view.
Right-click the name of your class and choose Profile As → 2 ABAP Application (Console).
Wait until the Console view appears or is refreshed.
Switch to the ABAP Profiling perspective and compare the two ABAP traces.
For example, choose Window → Perspective → Open Perspective → Other.... from the Eclipse menu, then choose ABAP Profiling and Open.
Alternatively, choose the ABAP Profiling shortcut in the upper right corner of the Eclipse toolbar.
In the ABAP Traces view at the bottom, expand the node that corresponds to your ABAP cloud project.
Press F5 to refresh the list of trace results. The first two trace results should be named like your own ABAP class and the template class.
Compare the values in column Runtime (s).
After the analysis, return to the ABAP perspective.
Switch the perspective as you have done before.