You have a closer look at the console output of your ABAP class and detect that the carrier name is truncated. You also notice that something is wrong with the carrier ID and the connection ID that are displayed for cargo flights. You identify problematic type conversions as the source of these issues and correct your code accordingly.
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_ATS_SQL_TRACE 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_ATS_SQL_TRACE 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: Detect Problematic Type Conversions
Execute the class as console app. Inspect the console output, paying particular attention to the carrier name and the carrier ID and connection ID of cargo flights. Locate the code that prepares this output and trace the data back to the source - looking for potentially problematic type conversions. Use the EXACT expression to verify that there are type conversions with data losses.
Steps
Execute your ABAP class ZCL_##_SOLUTION as console app.
Open the class in the editor and press F9.
Inspect the console output.
Scroll down in the ABAP Console view.
Locate the last line starting with Carrier Name.
Scroll further down to the line starting with Found suitable cargo flight and inspect the next line.
Return to the source code of your ABAP class and analyze the implementation of method if_oo_adt_classrun~main.
Navigate into method get_output.
In method call carrier->get_output( ), place the cursor on the method name get_output and press F3. Alternatively, you can hold down the Ctrl key and choose the method name.
In the expression me->name, place the cursor on name and press F2 to display the code element information for attribute name.
Place the cursor on r_result and press F2 to display the code element information for attribute r_result.
In the code element information, choose tt_output to display the code element info for this type.
Choose t_output to navigate to code element info for the row type of the table type.
Change the row type of parameter r_output. Use a character-like row type of variable length.
From the toolbar at the bottom of the element info, choose Open in Editor. Alternatively, you can press F3 to navigate to the definition of type t_output.
In statement TYPES t_output TYPE c LENGTH 40., replace c_LENGTH 40 with string.
Return to the Global Class tab and navigate into method get_details of class lcl_cargo_flight.
In method call cargo_flight->get_description( ), place the cursor on the method name get_description and press F3. Alternatively, you can hold down the Ctrl key and choose the method name.
Use the Where-used list for attribute carrier_id to find the statement where it is filled.
Place the cursor on carrier_id and choose Get Where-used List from the Eclipse toolbar. Alternatively, you can press Ctrl + Shift + G.
On the Search view below the editor, double-click the row that starts with carrier_id =.
In statement carrier_id = i_carrier_id., place the cursor on i_carrier_id and press F2 to display the code element information for parameter i_carrier_id.
In the code element info, choose /dmo/carrier_id to display the technical type of that data element.
Repeat this to analyze the technical type of attribute carrier_id.
Use conversion expression EXACT to test if the type conversion leads to information loss. Activate the code and execute it as a console app.
In the value assignment, surround the source data object i_carrier_id with EXACT #( ... ) like this:
123
carrier_id = EXACT #( i_carrier_id ).
Press Ctrl + F3 to activate the class.
Press F9 to execute the class as a console app.
You should see a runtime error CONVT_NO_NUMBER.
Repeat this analysis for the assignment connection_id = i_connection_id..
Analyze the technical types of attribute connection_id and parameter i_connection_id as in the previous step.
Adjust the code as follows:
123
connection_id = EXACT #( i_connection_id ).
Press Ctrl + F3 to activate the class.
Press F9 to execute the class as a console app.
Correct the types of attributes carrier_id and connection_id and remove the redundant EXACT expression. Then activate and re-test your code.
In statement carrier_id = i_carrier_id., place the cursor on carrier_id and press F3 to navigate to the definition of that attribute. Alternatively, you can hold down the Ctrl key and choose the attribute name.
In statement DATA carrier_id TYPE /dmo/connection_id READ-ONLY., replace /dmo/connection_id with /dmo/carrier_id.
In statement DATA connection_id TYPE /dmo/carrier_id READ-ONLY., replace /dmo/carrier_id with /dmo/connection_id.
The declaration of the attributes should then look like this:
12345678
* wrong:
* DATA carrier_id TYPE /dmo/connection_id READ-ONLY.
* DATA connection_id TYPE /dmo/carrier_id READ-ONLY.
* correct:
DATA carrier_id TYPE /dmo/carrier_id READ-ONLY.
DATA connection_id TYPE /dmo/connection_id READ-ONLY.
Fix the syntax warnings Redundant conversion for type ... by removing the previously added EXACT expressions.
Press Ctrl + F3 to activate the class.
Press F9 to execute the class as a console app.