This is a test message to test the length of the message box.
Login
Tools My IDE Actions
Created by Software-Heroes

ADT - MIA Select Converter

642

For MIA, there is now a new action in the ABAP Development Tools that allows you to convert your old Open SQL statements to ABAP SQL and ABAP Cloud.



In this article, we'll look at an update to the Select Converter and discuss the new integration in MIA and how it was implemented.

 

Introduction

IDE Actions have been available on the ABAP Environment since release 2502, and we already provided the first action with MIA in an older article. With IDE Actions, you can extend the ABAP Development Tools at specific points and thus make ABAP-based extensions. This allows you to automate certain functions, replace code, or extract information.

 

ABAP Select Converter 

A while ago, we introduced the ABAP Select Converter together with the CDS Extractor. The focus was primarily on converting SELECT statements into the new world, away from traditional tables and toward Core Data Services. The extractor provides the foundation via Git and shows what the mapping looks like at the field level. The converter takes the SELECT statement and breaks it down into its components in order to then replace tables and fields.

 

The converter has now received an overhaul and now completely breaks down the statement in order to generate it as ABAP SQL in the new syntax. This not only replaces the table, but also modernizes the statement.

 

Hint: Since this is a complex action, errors or inaccuracies may still occur.

 

Action

You can now find the new IDE action in the MIA open source project, where the action is documented and can be installed together with the other actions.

 

Structure

This is a fairly simple IDE action that we have implemented here. We define a class for the action and that it can only be executed in a class.

 

To do this, we read the current code of the object in the action and determine the position of the selection or cursor. You can find further information in the documentation below.

DATA(resource) = CAST if_adt_context_src_based_obj( context->get_focused_resource( ) ).
DATA(sources) = resource->get_source_code( ).
DATA(position) = resource->get_position( ).

 

In the next step, we need to extract the entire SELECT statement from the source code. To do this, we use a small function that searches for the beginning and end and compresses the select statement onto one line.

DATA(extraction) = zcl_mia_strings=>extract_statement( statement = `SELECT`
                                                       sources   = sources
                                                       start     = position->pos-start ).

 

If the determination worked, we pass the SELECT to the API, which calls the Select Converter endpoint to convert the statement. We then receive the result back in our response structure.

DATA(conversion) = zcl_mia_core_factory=>create_swh_tools( )->convert_select_statement(
    request = VALUE #( statement  = extraction-statement
                       abap_cloud = abap_true ) ).

 

Finally, we pass the new statement to a Source-Change-Result, which then offers us the appropriate dialog so that you, as the developer, can check the result.

DATA(change_result) = cl_aia_result_factory=>create_source_change_result( ).
change_result->add_code_replacement_delta( content            = conversion-data-new_statement
                                           selection_position = position ).
result = change_result.

 

Execution

How do you now execute the actual action? To do this, you must select the SELECT statement you want to replace in your source code. Then start the IDE action with the keyboard shortcut CTRL + ALT + R and select the IDE action "Migrate SELECT Statement".

 

Finally, the source code comparison will be displayed, and you can decide whether you want to accept the changes. In principle, the action also works in deactivated or activatable source code. This allows you to convert a SELECT that comes from on-premise and that you have only copied into the ABAP environment.

 

GitHub

You can find the open source project on GitHub and use it freely. If you find any errors or have suggestions for improvements, simply open an issue on GitHub.

 

Conclusion

If all the building blocks are in place, integrating it as an IDE action is very easy to implement. Using the SAP documentation, results can also be achieved quickly.

 

Source:
SAP Help - Implementing a Code Insertion


Included topics:
ToolsADTEclipseIDE ActionsMIA
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ADT - My IDE Actions

Category - ABAP

Write your own functions in the ABAP Development Tools? No problem anymore with the standard IDE Actions and also without Java.

02/18/2025

ABAP Tools - Working with Eclipse (Storage)

Category - ABAP

How do you access deleted source code in the ABAP Development Tools even though you never transported it? More about how ADT uses the storage and how it works.

10/29/2024

ABAP Tools - Working with Eclipse (Multiple Debugging Sessions)

Category - ABAP

How are multiple debugging sessions managed in the ABAP Development Tools in Eclipse? More information here.

10/08/2024

ABAP Tools - Working with Eclipse (SAP GUI Language)

Category - ABAP

Do you have the wrong SAP GUI language when you start the GUI in the ABAP Development Tools? You can find the solution here.

09/10/2024

ABAP Tools - Working with Eclipse (CDS Templates)

Category - ABAP

Did you select the wrong CDS template when creating the view? Here's a little tip to correct the view in ABAP afterwards.

07/02/2024