Sie sind auf Seite 1von 5

PRINT FROM SAP HELP PORTAL

Document: Refactoring Assistant URL: http://help.sap.com/saphelp_nw73/helpdata/EN/44/2afce330063ecee10000000a1553f6/content.htm Date created: July 26, 2013

2013 SAP AG or an SAP affiliate company. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. National product specifications may vary. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries. Please see www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices.

Note This PDF document contains the selected topic and its subtopics (max. 150) in the selected structure. Subtopics from other structures are not included.

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 1 of 5

Refactoring Assistant
Purpose
In the context of software development, the term refactoring refers to the practice of changing the structure of a program without changing its behavior. Refactoring ranges from simple renaming of variables and classes to restructuring a class hierarchy by substituting inheritance with composition. Refactoring aims at improving the design of a system in terms of reusability, extensibility and so on. Unfortunately, the practice of refactoring also puts at risk the semantic integrity of a software system because the process is very prone to errors. The purpose of the Refactoring Assistant is to simplify and accelerate the process of refactoring ABAP source code.

Integration
The Refactoring Assistant is part of the ABAP Workbench and is integrated in the following tools: Class Builder Function Builder ABAP Editor.

Features
The Refactoring Assistant has the following features: Consistent renaming of local and global elements. For more information, see Consistent Renaming. Moving of elements (attributes from a method to the public section or from a function module to a top include) Generation of code templates.

Constraints
The following development objects cannot be refactored: Enhanced compilation units (for example, global classes, reports and so on). For more information, see Includes containing two or more distinct compilation units. See also: Extracting Source Code Segments Removing Unused Data Declarations Inserting GET and SET Methods Enhancement Framework.

Consistent Renaming
Purpose
You use this process to rename local and global elements consistently. Local elements are elements whose visibility is restricted to a single compilation unit - for example, local variables, local types, local classes and their components. Global elements are function modules and classes and their components.

Process Flow
Consistent renaming involves renaming an ABAP identifier and subsequently renaming all static usages of this identifier in order to ensure that the result is syntactically correct and semantically identical to the initial development object. The following elements can be renamed consistently: Local variables, types, classes and their components (methods, attributes, types and events) Functions modules and components of global classes (methods, attributes, types and events)

The process may involve changes in other development objects. With the help of the Refactoring Assistant, you can perform the following major tasks: Consistent renaming of local elements. For more information, see Renaming Local Elements. Renaming of global elements. For more information, see Renaming Global Elements. See also: Extracting Source Code Segments Removing Unused Data Declarations Inserting GET and SET Methods

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 2 of 5

Renaming Local Elements


Use
You use this procedure to rename local elements (for example, local variables, types, and classes and their components) by means of the Refactoring Assistant.

Procedure
1. In the Object Navigator (transaction SE80), navigate to your program. 2. In the source code, position the cursor on the name of the local element (for example, a local variable). In the context menu, choose Refactoring Rename. The Refactoring Assistant Wizard appears. 3. Choose Continue. 4. In the New Name field, enter the new name of the element and choose Continue. You are asked whether you want to perform the renaming. 5. Choose Complete. All occurrences of the local element in the compilation unit are renamed.

In the new ABAP Front-End Editor you can see bookmarks at the places where changes have been made. 6. In the context menu of the source code, choose Refactoring Display Preview to get an overview of all changes.

The preview shows the differences between the file saved in the repository and the current contents of the editor. Even if your renaming involves many different includes, the system applies no changes until you choose Save. You can revert all changes by choosing Undo.

Renaming Global Elements


Use
You use this procedure to rename globally visible elements (for example, function modules, global classes and interfaces and their components) by means of the Refactoring Assistant.

Procedure
Renaming Function Modules

Renaming global elements may affect other development objects. The renaming process is based on the global usages from the where-used list and there is no guarantee of completeness. We recommend that you verify manually all changes applied by the Refactoring Assistant. 1. In the Object Navigator (transaction SE80), navigate to the function module you want to edit. 2. In the context menu of the function module, choose Rename. The Rename Function Module screen appears. 3. In the New Function Name field, enter the new name of the function module and choose Continue. The system displays an overview of all the changes applied to the source code. All occurrences of the element in the system are renamed apart from external usages (particularly RFCs and dynamic calls).

We recommend that you check all changes that have been applied to other development objects before saving your changes. 4. In the context menu of the source code, choose Refactoring Display Preview to get an overview of all changes. 5. Choose Save.

Renaming Global Classes


1. In the Object Navigator (transaction SE80), navigate to the class you want to edit. 2. In the source code, position the cursor on the name of the method. In the context menu, choose Refactoring Rename. The Refactoring Assistant Wizard appears.

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 3 of 5

Make sure that the source code based editor of the Class Builder is started. To do that, choose Utilities Settings Class Builder Source Code Based Editor . 3. In the New Name field, enter the new name of the class and choose Continue. 4. You will be asked whether you want to perform the renaming. Choose Complete. All occurrences of the class in the system are renamed.

In the new ABAP Front-End Editor, you can see bookmarks at the places where changes have been made. 5. To get an overview of all changes, position the cursor anywhere in the source code. In the context menu, choose Refactoring Display Preview. If the method is implemented in multiple places, all of them are shown in the preview.

The preview shows the differences between the file saved in the repository and the current contents of the editor. 6. Choose Save.

Extracting Source Code Segments


Use
You use this procedure to transform source code segments into procedural units by means of the Refactoring Assistant.

Procedure
1. In the Object Navigator (transaction SE80), navigate to the class or function group you want to edit. 2. Select the code fragment you want to change. 3. Position the cursor anywhere in the source code. In the context menu, choose Refactoring Extract Source. The Refactoring Assistant Wizard appears 4. Choose Continue. 5. In the Method Name or Function Name field, enter the name of the new procedural unit and choose Continue. 6. Choose the type of method you need. The available options are: public, protected, and private. 7. Choose Continue. An overview screen appears with the data you have entered. 8. Choose Save.

This procedure is valid for both global and local classes. In a function group, the code is extracted by default into new functions, whereas in classes it is extracted into new methods having the appropriate level of visibility.

Removing Unused Data Declarations


Use
You use this procedure to remove unused data declarations by means of the Refactoring Assistant.

Procedure
1. In the Object Navigator (transaction SE80), navigate to your program. 2. Switch to change mode. 3. In the source code, open the context menu with the secondary mouse button and choose Refactoring Delete Unused Data Declarations. The Refactoring Assistant Wizard appears. 4. Choose Continue. An overview screen appears with the name of the program. 5. Choose Continue. The final screen of the Refactoring Assistant Wizard appears.

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 4 of 5

6. Choose Save.

Result
All unused data declarations in the code are deleted.

Inserting GET and SET Methods


Use
You use this procedure to add GET and SET methods to your classes by means of the Refactoring Assistant.

Procedure
1. In the Class Builder (transaction SE24), open the class you want to edit. 2. Switch to change mode. 3. Choose Utilities Refactoring Create GET/SET methods. The Create GET/SET Methods screen appears. 4. In the grid, choose the attribute for which you want to create GET and SET methods. 5. Choose Continue.

Result
A GET and a SET method for the selected attribute have been created.

PUBLIC 2013 SAP AG or an SAP affiliate company. All rights reserved.

Page 5 of 5

Das könnte Ihnen auch gefallen