This book is not affiliated with, sponsored by, or approved by SAP AG. Any.. involve a small Beginner's Guide T SAP ABAP Advanced Cookbook. ABAP™ Cookbook . Introduction to the Hexadecimal Type in ABAP .. 73 .. Wrapping the SAPFTP Library in an ABAP Objects. Class. Hello everyone,Would anyone have the ABAP Cookbook?If you can http://help.

    Language:English, Spanish, Hindi
    Genre:Science & Research
    Published (Last):06.03.2016
    Distribution:Free* [*Sign up for free]
    Uploaded by: SHAREN

    59560 downloads 183984 Views 19.64MB PDF Size Report

    Sap Abap Cookbook Pdf

    Free PDF Books, Download Books, free Lectures Notes, Papers and eBooks related to programming, computer science, web design, ABAP Cookbook. PDF . With this book, get answers to typical ABAP development problems or tasks: PDF (58 MB), EPUB (20 MB), and MOBI file (38 MB) for download, DRM-free with . ABAP Cookbook provides free and high quality SAP ABAP Tutorials, Tips And Tricks, Interview Questions and the latest SAP news.

    The complexity of the "recipes" ranges from the simple starter plates to the complex main courses—and some sweet deserts, of course! Each chapter is a short tutorial in itself, all organized and consolidated into an easy-to-read format. Many code samples, screenshots, and different icons will help you to follow the best practices provided. Enjoy your ABAP meal! Find answers to common and complex programming problems in various tutorials Learn the classic and modern techniques for developing solutions in ABAP Explore detailed code samples throughout the book About the Book About the E-book pages, hardcover, 1. Including code downloads. Reference book format 6. Printed black and white on 60 offset paper from sustainable sources. Casebound for durability. Reader-friendly serif font Linotype Syntax 9.

    The know-how offered by SAP specialists combined with the expertise of the Galileo Press publishing house offers the reader expert books in the field. For further information, please visit our website:. By downloading this e-book, you have agreed to accept and adhere to the copyrights. You are entitled to use this e-book for personal purposes. You may print and copy it, too, but also only for personal use.

    Sharing an electronic or printed copy with others, however, is not permitted, neither as a whole nor in parts. Of course, making them available on the Internet or in a company network is illegal as well. For detailed and legally binding usage conditions, please refer to the section Legal Notes. We hope that you liked this e-book. Please share your feedback with us and read the Service Pages to find out how to contact us.

    Includes bibliographical references and index. ISBN alk. A12W66 Designing a Custom String Library Declare a parameter amount of type character and length We can increase the length for a larger amount, keeping provision for the commas.

    A write statement is then used to output the convert amount. We have used subgroups in conjunction with the preview condition. The preview condition inds all numbers that are followed by one or more sequence of three digits after it starting from the left.

    For example, we look for digits that are followed by three, six, or nine digits.

    Hm... Are You a Human?

    The negated preview condition ensures that only those numbers are matched, which have multiples of exactly three digit numbers after them. Suppose we choose as the input number, the irst zero is the matched digit and in this case the only match. This is replaced by the zero itself followed by a comma. The output of the program is shown in the following screenshot: If is entered, the condition does not meet, so no matches are found.

    That is why no commas are inserted in the amount at any position. Removing comments from program code In this recipe, we will see how we can use the replace statement in conjunction with a suitable regex in order to remove comments from a program. For the sake of this recipe, we assume that the program whose comments are to be removed is syntactically correct. Getting ready For this recipe, we will make a copy of the program created in Chapter 2, Dynamic Programming, that reads the source code of a program speciied by user input.

    In the previous program, we used two internal tables and used a loop at the irst table itab to delete comments. For this recipe, we will replace the loop with one replace statement and use only one table that is the irst internal table itab. The code of the original program is read in the table from which comments are removed.

    For adjusting the program, proceed as follows: The main part of the new portion is a replace statement. A delete statement is then used for deleting all blank rows from the internal table. There are three subgroups used in this recipe. An OR condition is used for separating the irst subgroup from the other two. Let us consider the two subgroups.

    The match found is stored in subgroup register 1. This pattern tries to divide a given program line into two parts, the irst with set of characters without a double quote " followed by the part that begins with a inverted comma ".

    Only the second subgroup register has been used in the replace statement. This trims the comments from the code. If a line having some code and then comments starting with inverted comma is reached, we only pick up the code part. We inally call the delete statement in order to remove any blank lines from the program's internal table.

    For simplicity's sake, we have speciied three subgroups with parenthesis, the third parentheses subgroup may be omitted also, without affecting the functioning of the code. We will create a program that will read an HTML stream in a string and will display the tag names along with the content of the tags. The FIND and replace statements are used together with a do loop. For creating a program for interpreting HTML code, follow the steps shown in the following steps: Declare three strings by the name htmlstream, tagcontents, and tagname.

    We then assign a suitable HTML code to the htmlstream variable. The tag name and tag contents are printed. Once all the tags are processed, the exit statement is executed. We have used ignoring case since the tag names may start with upper or lowercase such as H1 or h1. The content of a particular tag is read into the submatch variable tagcontents. The find statement inds all the tags. On the next do loop pass, the next tag is matched and contents are read. The output is shown in the following screenshot: Once all the tags are processed, the sy-subrc condition of being not equal to zero is met and the loop is exited.

    However, we will see some useful and important techniques, as well as some new tools and concepts that are important for developers for program optimization. We will see useful recipes related to both the optimization of database statements as well as internal tables.

    We will start with some general rules necessary for optimization. We will start with a recipe showing the usage of transaction SAT for measuring performance of report programs.

    Then, we will see in detail the steps required in creating secondary indexes for database tables in order to boost performance of queries used in the concerned program. We will then see how hints may be used in programs within SELECT statements, so that a particular index may be used by the system. The usage of hashed internal tables as well as the new concept of secondary indexes for internal tables will be discussed in separate recipes.

    For the better understanding of the information in this chapter, the reader should know which database would be used in his or her project and know some tricks speciic to the database.

    Before starting with the recipes, let us see some rules for program optimization: It means not to select unnecessary columns from database. Rather use subqueries or inner joins. Otherwise, all records in the underlying table will be accessed that will drastically affect the performance. For more examples of the previously discussed items, see the Tips and Tricks screen of transaction SAT.

    For doing so, you need to call transaction SAT. Then press the button on the toolbar. Using transaction SAT to ind problem areas In this recipe, we will see the steps required to analyze the execution of any report, transaction, or function module using the transaction SAT.

    The program selection screen contains a number of ields. We will execute the program on the order number aufnr and see the behavior. For carrying out runtime analysis using transaction SAT, proceed as follows: Call transaction SAT. The screen appears as shown: This will take you to the Variant creation screen. Then, click on the Statements tab.

    Save your variant. Come back to the main screen of SAT. Then click the button. The screen of the program appears as shown.

    We will enter an order number range and execute the program. Once the program output is generated, click on the Back key to come back to program selection screen. Click on the Back key once again to generate the evaluation results. We carried out the execution of the program through the transaction SAT and the evaluation results were generated.

    These are like a summary report of the entire measurement of the program. They are listed in descending order of the Net time in microseconds and the percentage of the total time.

    From the Hit List window, double-clicking a particular item will take us to the relevant line in the program code. We have carried out analysis with Aggregation switched on. The switching on of Aggregation shows one single entry for a multiple calls of a particular line of code.

    Because of this, the results are less detailed and easier to read, since the hit list and the call hierarchy in the results are much more simpliied. Also within the results, by default, the names of the internal table used are not shown. In order for the internal table names to appear in the evaluation result, the Determine Names checkbox of Internal tables indicator is checked. As a general recommendation, the runtime analysis should be carried out several times for best results.

    The reason being that the DB-measurement time could be dependent on a variety of factors, such as system load, network performance, and so on. Creation of secondary indexes in database tables Very often, the cause of a long running report is full-scan of a database table speciied within the code, mainly because no suitable index exists. In this recipe, we will see the steps required in creating a new secondary index in database table for performance improvement.

    Creating indexes lets you optimize standard reports as well as your own reports. For creating a secondary index, proceed as follows: Then click the Display button. This will take you to the Display Table screen. Next, choose the menu path Goto Indexes. This will display all indexes that currently exist for the table. Click the Create button and then choose the option Create Extension Index. The dialog box appears. Enter a three-digit name for the index. Then, press Enter.

    This will take you to the extension index maintenance screen. On the top part, enter the short description in the Short Description ield provided. We will create a non-unique index so the Non-unique index radio button is selected on the middle part of the screen. On the lower part of the screen, specify the ield names to be used in the index. The index will be created in the database with appropriate message of creation shown below Status.

    This will create the index on the database. Since we created an extension index, the index will not be overwritten by SAP during an upgrade.

    PDF SAP BW and ABAP Good Programming in SAP BW incl HANA Focus On Book 1 Free Books

    It is recommended by SAP that the index be irst created in development system and then transport to quality, and to the production system. Secondary indexes are not automatically generated on target systems after being transported. We should check the status on the Activation Log in the target systems, and use the Database Utility to manually activate the index in question.

    A secondary index, preferably, must have ields that are not common or as much as uncommon as possible with other indexes. Too many redundant secondary indexes that is, too many common ields across several indexes on a table has a negative impact on performance. For instance, a table with 10 secondary indexes is sharing more than three ields. In addition, tables that are rarely modiied and very often read are the ideal candidates for secondary indexes.

    From SAP Release 4. Next, a data variable myvbeln is deined.

    Other books: SAP BAPI PDF

    It is a very simple addition. There is a special syntax used for specifying the name of the database index to be used for the particular SELECT statement. The syntax should be proper because other than the database name check, the syntax checker does not check the index name.

    Therefore, if a wrong index is used, the corresponding query will not give a syntax error but the desired results will not be achieved.

    The code pertaining to the HINT parameter of one database may differ from that of another. Note the database name added along with the changed format for index speciication.

    This lets you optimize your programs when accessing data residing within an internal table. Getting ready In this recipe, we will create a program that will store all data of table VBAK into an internal table. Then we will use the secondary key in order to fetch a record pertaining to a given order number, aufnr. The primary emphasis of this recipe is on the deinition and usage of a secondary key for internal tables. For creating a program using secondary index in internal tables, follow the steps below: We create two keys for this table type.

    The irst is a non-unique primary key having vbeln as the key ield. It is always better in terms of performance to use ield symbols rather than work areas. In this example, for simplicity's sake and since the performance gain is minimal, work areas have been used. In the table type deinition, we speciied a non-unique sorted secondary key based on aufnr along with the primary key. A faster binary search is used since it is a sorted index.

    The vbeln ield is then printed. Hashed table for single read access In this recipe, we will create a program that will use a hashed table and a standard table for accessing and displaying employee data from two tables PA and PA There may be many solutions to this requirement. Getting ready In this recipe, we create a program that will take as input personnel number and then print the last payroll run date of the employee from PA and the permanent residence address subtype 1 stored in the STRAS ield of the table PA For simplicity's sake, only one data ield of each table has been shown.

    For creating the program, proceed as follows: We deine select-options for taking input of personnel number. A structure and a hashed table based on this type are also deined. The hashed table has a unique key pernr. We then write two select statements. The irst reads PA for all personnel numbers speciied and the date of last payroll run abrdt.

    Within the loop, the personnel number, abrdt date, and the address ield stras are displayed. We have used ield symbols instead of work areas, in conjunction with loop and read statements for better performance. We need to print each employee number and the corresponding data from each of the two tables.

    All the values that we need are there within the loop after the read statement. These values are then outputted using a write statement. The ranges maybe used to improve performance. This two-table example is just for illustrative purpose and comparison. You may apply the concepts to other tables and ields. You may or may not further reine this based on your requirement. We will create a simple program that uses the for all entries addition in the select statement for the two tables cobk and coep.

    We also make sure that the for all entries table is not empty. In this recipe, we will see how we can improve the performance of the code by replacing the for all entries construct with a range of document numbers. For this, we need to add some additional code before the second select statement. The steps for writing the additional code for forming ranges are shown as follows: Let us now see how the additional code works.

    The document numbers are passed to the function module. This technique works best when the document numbers passed to the function modules are close together, so that less rows exists in the ranges table.

    The eficiency of the Ranges code may be easily demonstrated. We use the GET RUNTIME statement to ind out the relative runtime of other various program segments such as original select statement part, the function module call, and the select statement using the Ranges table.

    The following are the runtimes in microseconds displayed on the screen: It can be clearly seen that the time taken by the select statement with for all entries in clause is 1. The function module consumes 0. Hence, the combined time for our replacement code is 0. This is faster than the 1. Selection screens are used for taking input from the user. They are formed by using ABAP statements without the screen painter.

    A selection screen may comprise of input ields, checkboxes, radio buttons, tabstrips, and list boxes. This chapter explores useful recipes that will help you in building better selection screens for your programs as well as allow the addition of certain features for improving the user experience. We will start with the irst recipe that will show how to add toolbar buttons to your program's selection screen. Then, we will see how tabstrips and list boxes may be added on screens.

    Next, a recipe that will show how radio button inputs may be used to hide or unhide other screen ields. We will also see how standard function modules may be used to provide a browsing facility to the user and take as input names of folder and iles residing on his or her desktop.

    Finally, we will have a recipe detailing the steps required to create search help exits. Also, the familiarity with the screen table is recommended.

    This may be done using a few ABAP statements. In this recipe, we will see how tabstrips and listboxes may be added to selection screens. We will create a program that will contain a tabstrip containing two tabs, each containing a listbox representing country names. By default, we will have USA displayed on the irst tab and Canada on the second.

    For creating tabstrips and listboxes, follow the following steps: We create two Text Symbols, and , that are to be used in the subsequent steps. First, we deine a selection screen as the subscreen. Within the subscreen we deine a block that contains a listbox. On the subscreen, we will create a listbox for country that will, by default, show US USA as the country. The subscreen will be shown in the irst tab of the tabstrip that we will be deined in a later step.

    Similarly, we deine another subscreen , within which we create another parameter input displayed as a listbox having length The default value we have for this listbox is CA, that is Canada. The user command code, COU2, is deined for this listbox. Finally, the tabstrip tabbed block containing two tabs is deined. The two tabs are assigned to the subscreens and deined earlier. For the two tabs, the system creates character ields with the same names, that is, tab1 and tab2.

    Within the initialization event, the tab1 and tab2 ields are assigned the texts, Tab1 and Tab2, using the text and text text symbols deined earlier. The coding creates a tabstrip having two tabs with the text Tab1 and Tab2 respectively.

    Each tab page is assigned a subscreen that contains a listbox having country as the input ield. When the user clicks on a particular tab title, the elements in that subscreen become active and are displayed. We speciied US as the default value for the listbox on the irst tab.

    The text for US, that is United States, is displayed in the irst tab. For the second tab, the country Canada is displayed by default. The user may choose the country of his choice. In this recipe, we will create a program that will display a selection screen having three toolbar buttons, each of which when clicked, takes us to a different transaction.

    For adding buttons on your selection screen toolbar, proceed as follows: First, declare the dictionary structure, sscrfields. Here we deine buttons with function keys 1, 2, and 3 using the selection-screen statement.

    Also, an integer abc is deined. Next, within the at selection-screen event, we check the value of the ield sscrfields-ucomm. We will now see how the coding works in displaying the toolbar buttons along with the necessary button text, and how the respective transactions are called after button-click events.

    When any of the buttons are pressed, the at selection-screen event is called. The value of the ield sscrfields-ucomm is checked. After checking the value, the relevant transaction code is called via the call transaction statement and the user is taken to the appropriate transaction. We will create a program having a selection screen containing a group of two radio buttons and an integer ield.

    We will then add the code that will hide or display the integer ield based on which a radio button is selected. These are assigned to the radio button group g1.

    The user command, INT1, is assigned. Next, an integer is deined with the addition, modif id INT. A loop is run at the screen table. Within the loop, the group1 of each screen element is checked for INT.

    In addition, if show is equal to X, the active ield is set as 1 active. Finally, the modify screen statement is used to set the values in the screen table. The code that we wrote displays three radio buttons and an integer ield on the screen. When the Hide Integer Field radio button is selected, the integer ield disappears. The Hide Integer Field radio button or Make Integer Field Uneditable radio button selection triggers the at selection screen output event.

    A loop is then run on each screen element, but we are only interested in the one that has the group1 ield assigned the value INT as we assigned INT for the integer ield using the modify id addition. If the Hide Integer Field radio button is on, the integer ield is set as inactive and thus made invisible. If the Make Integer Field Uneditable radio button is set, the input ield is set as 0, that is, the input is not allowed, thus making the ield uneditable for the user.

    When the user selects the Show Integer Field radio button, the integer ield is set as active and displayed again to the user. Taking desktop folder and ilename as input In this recipe, we will create a small program that will take as input a folder name and ilename s from the user.

    Both standard function modules, as well as classes, may be used for this purpose. In addition to the browsing capability, the user may also create a new folder while entering a folder.

    The ile's function module lets you select multiple iles from your local directory. The There's more For taking input of folder and iles, proceed as follows: First, two parameter input ields are declared for the folder and filename, having a length of 80 and 50 characters respectively.

    Then, we will write the code within the at selection-screen on value- request event for the folder. The window title parameter is passed to the relevant text, Choose the folder of your choice.

    We will pass a suitable window title to the function module. The importing parameter, rc, returns the number of iles selected by the user. The parameter multiselection is used for controlling whether multiple iles may be speciied by the user.

    We will keep this as '' meaning only one ile may be speciied. As the user will provide one ilename, we use a read table statement in order to read the irst record, that is the ilename and path speciied by the user. When the program is run, two input value ields for folder and filename are displayed. When the folder input help is selected, the folder dialog box is displayed.

    The user speciied a folder name from his or her desktop. Alternatively, a new folder may be created and speciied. The folder complete path is returned in the variable folder, which may be later used in the program.

    Likewise, when the filename input help is called, the relevant function module is called and the dialog box is displayed. The user selects the ile of his or her choice.

    Only one ile may be selected. The function module's call for the iles may be slightly altered in order to take input multiple ilenames from the desktop of the user.

    Then the multiselection parameter of the function may be passed the value X in order to allow multiple iles to be selected.

    The relevant coding is shown in the following screenshot: Coding search help exits for creating better F4 helps In this recipe, we will see how search help and help exits will help you meet the user requirements when providing the input values of a particular selection screen's input ield. We will create a search help in this recipe and will assign it to an input ield.

    The requirement is to provide a personnel number ield with input help that shows all the employees whose birthdays fall in the current month. This means, if the program is run in March, all the employees whose birthdays are in March will be shown in the input help.

    Getting ready We will create a search help for personnel number. For deining search help exit function module, proceed as follows: Within the function module, we will add the following code under the step DISP. This is the part where the iltering of employee data for birthdays falling in the current month takes place. The function module is then activated. We will now assign the newly created function module in the Search help exit ield of the search help.

    The search help is then activated. The logic we used in this example is that we irst fetched all records of the employees from PA, irrespective of their dates of birth, using the search help. Then, within the Search help exit, we removed all the employees whose dates of birth does not fall in the month the program is run. When the user takes the F4 help, the search help is called. Next, the search help exit is called. Prior to writing the code, we used the debugger to ind out the exact positions of the date of birth GBDAT ield.

    The step DISP is called just before the hit list is about to be displayed. We will use this to remove any records we do not want. The delete statement removes all the records where the month does not match the month of the system date sy-datum. The ones that remain are the ones having birthdays in the current month. For example, when the report is run in March, the input help is shown as in the following screenshot: We will start with a simple recipe that will allow you to change the text editor of the Smart Form to Microsoft Word.

    Then we will see how page protection for a number of text lines may be applied using folders in order to ensure that certain lines are printed together on one page.

    ABAP Cookbook. Programming Recipes for Everyday Soluti - by SAP PRESS

    We will also see how to set an image as background of a form page for only preview and also for print. The procedure for generating multiple form outputs in a single spool request will be discussed in an upcoming recipe. We will also see how the preview and the print dialog may be suppressed, and the output directly converted to PDF. Finally we will see the recipe for calculating subtotals using sorting criterion at the Smart Form level. We assume that the reader has basic Smart Forms knowledge.

    In addition, the familiarity with the structure of the form-calling program is needed. Follow these steps: Then execute the program. The selection screen of the program is shown as follows: Make sure the Smart Forms checkbox is checked. Then, click the Activate button. For switching off the Microsoft Word editor for Smart Forms, uncheck the Smart Forms indicator and then click the Activate button on the toolbar.

    Depending on the settings saved for Smart Form, the editor changes. If the Smart Form checkbox was on, the text editor appears as Microsoft Word.

    Otherwise, the normal Smart Form text editor appears. We will now set the graphic as the form background. Double-click the relevant node in the left-hand pane of the page for which the background image is to be set. In the right-hand pane, three tabs will appear for the page. The third is Background Picture. On this tab, enter the name of the uploaded graphic. Within the Output Mode list, select Print Preview from the listbox.

    The main window is placed on top of the background graphic. When the Smart Form is called using a calling program , the background graphic is displayed along with the line of text in the Print Preview mode. However, when the form is printed, no background image appears only the line of text created appears. This setting is very useful when a pre-printed paper having the appropriate background graphic is used for printing, and should not be printed in the form output since the paper already has the graphic in it.

    The user, however, needs to see the background graphic when the form preview is taken on the screen. If the background graphic appears blurred or the pixel artefacts are visible, we may need to use a high-resolution graphic.

    One option may be that we use a high quality high-resolution graphic. Also, we may try to control this using the resolution setting through the Resolution ield in the Output Attributes screen. Instead of keeping it blank, we may enter a value of The higher the resolution, the clearer will be the graphic however, the size of the graphic may decrease as the resolution increases.

    We may also slightly change the image's output mode in order to make the image work as a watermark when printed on paper. Instead of the Print preview and no print option for the Output Mode, we can choose the Print preview and print option. This will print the image on both the Print option and the Print Preview option and when printed on paper, it will make the image appear as a watermark on top of which text and data will appear.

    If the space within a page is not enough for printing all the lines, the entire text block is printed on the subsequent page, that is, page protected. For deining a folder with page protection, follow these steps: Right-click on the MAIN window. Then, from the context menu that appears, choose the option Create and then select Folder, as shown in the following screenshot: Next, enter a suitable folder name.

    In the right-hand pane, on the Output Options tab of the created folder, check the Page Protection indicator. Then add a text under the given folder. Add three lines to the text. Save and activate your Smart Form. When the form output is generated, irrespective of the number of lines printed above our three-line text, a page protection is applied. If the space on the page is not enough so that all three lines may be printed, a page break is automatically triggered and the lines are printed on a fresh new page.

    Otherwise, the same page is utilized. In no case will the three lines be broken into two pages. We will create a number of form pages comprising employees data. Each page will contain one employee's salary information. The recipe will focus on the important parts of the program related to Smart Form processing. The form name is passed to the function module. Then appropriate variables are deined for the Smart Form control structure and output options based on dictionary structures.

    In addition, the tdnewid ield of the output options structure is assigned 'X'. The function module of the Smart Form is then called and necessary data of the employee provided along with control parameters and output option structures. After executing the program, multiple pages of the forms are generated. For each employee, a separate page appears along with the necessary information. The tdnewid assigned to 'X' creates a new spool request.

    The function module of the Smart Form is called in the loop and generates the necessary output of each employee. In this case, when we program that on the irst employee, the spool job is opened and when we program that on the last employee, the spool job is closed. The dynamic call of the Smart Form function module is then carried out. Appropriate variables are then deined. The OTF parameter passes the value of the ield otfdata of the myoutput structure.

    This ensures that the form output is suppressed but the form generated is returned to the program in otf format. The call to the Smart Form function module stored in the variable myfunction returns to the program the otf format in the otfdata ield of the myoutput structure.

    In this recipe, we will use an example of employees and their allowances and amounts. We deine a table type also based on this structure, as shown in the following screenshot: A table is then created on the Smart Form layout. The loop of the table is shown as follows: Appropriate texts are created within the cells in order to print the employee number, allowance, and amount values passed.

    A program is then created and the Smart Form is called. A tabular output is generated. In this recipe, we will see how sorting along with totaling may be so that the total of each employee's allowance is printed at the end of each employee's details.

    For subtotaling and sorting, proceed as follows: Double-click the deined table node in the left-hand pane. We deine a subtotal variable in the global deinition. This is a temporary storage variable for totals of each employee's allowances. On the Calculations tab of the table, we enter the values shown in the following screenshot: Use the same line type used for the rows of the table containing three cells.

    The inal state will look like the one shown in following screenshot: The settings we did in the Smart Form will output the subtotal of the allowances of each employee as shown. At the end of each employee, the total allowances are calculated and printed. This chapter explores useful recipes related to SQL trace. We will see in this chapter how the SQL trace may be used in order to optimize a program by pinpointing the exact "problem areas" in database-related code.

    Also, we will use the SQL trace to ind out the underlying data source table name and ield name of a particular screen ield. We assume that the reader has basic selects and optimization knowledge. We will start with a brief explanation of the steps required in carrying out an SQL trace. In the subsequent recipe, we will see how the performance trace results may be interpreted.

    Also, we will see how we can access the various menu and toolbar functions of the list display. Our other recipes will be tips and tricks for inding out quickly the data source of screen ields and their F4 helps. We will now carry out the following steps: In one SAP session, open the transaction that is to be traced.

    We enter on transaction SE38 the program name in the ield provided, and execute the program in order to display the selection screen.

    We will not execute the program, yet we will enter the input values on the selection screen. Then, open another session and call transaction ST The screen appears, as shown in the following screenshot: Make sure the SQL trace checkbox is on. Click the Activate Trace button on the toolbar. Make sure that before doing this, the message in the lower part of the screen reads, All Traces are Switched Off…. Now return to the irst SAP session and execute the report with the relevant input values, as shown in the following screenshot: Once the output is displayed, go back to the SQL trace session and click on the Deactivate Trace button.

    Then, click on the Display Trace button to generate the results. The Activate Trace button switches on the database trace. This may be displayed using the Display Trace button. For carrying out a trace, you may even stop a program in the debugger in one session and then switch on the trace in another session. In addition, you may enter data on a SAP entry screen and just before pressing the Save button, switch on the SQL trace, and then switch off the trace after Save is pressed and the success message appears.

    In this case, all database statements are executed between the time the Save button is pressed and the message display are recorded. It is recommended that you run only the concerned program transaction and stop any other activity.

    Otherwise, many irrelevant entries will also be included in the trace result, making it very large and dificult to read. The next recipe will cover how the trace results may be displayed. Generating and interpreting the trace result In this recipe, we will generate the results of the trace carried in the previous recipe, Carrying out SQL trace.

    The mentioned recipe should be completed in order to proceed with this one. We will then interpret the results in order to get a better idea of the various tables and their access times involved. From the main screen of the transaction ST05, click on the Display Trace button. This will take you to the screen, as shown in the following screenshot: The User name ield and the Date and Time ields appear by default. You may change the Date and Time ields, and also enter data in the other ields if desired.

    Then press F8. This will display the Performance Trace. When the Display Trace option is chosen, the performance trace is displayed. All the database activities database access and database update statements that were recorded during the time between the trace on and off duration are displayed, as shown in the following screenshot: In this example, since we had a report that only reads data from the database, no database update statements are involved.

    There are various useful columns in the displayed performance trace. The trace results contain the table name Object name that refers to the table from which data is read. Most importantly, the number of records fetched from the database as a result of the FETCH operation is also shown. The statement is not assigned the parameter values for which the data is to be read that is, the WHERE clause speciication.

    The data access method execution plan is determined at this point. The records fulilling the selection criteria are read from the database table using the relevant execution plan involving either a sequential or an index search.

    Until here, the records are at the database level. Finally, the FETCH operation transfers the record s matching the criteria speciied to the application server.

    The various records read are shown in the Records column.

    You may see them in the following screenshot: In addition, in this case, the Records column will show the number of records updated in the database table rather than the records read. At the end of the list is the total of the number of fetched records and the total execution time. For inding out the exact location, in the ABAP program, of the corresponding statement shown in the Trace List, keep the cursor on a line showing an OPEN operation, and then click the icon from the toolbar.

    This will take you to the exact line in the program that generated the entry in the trace list. In addition, for viewing the execution plan of a particular statement, select the FETCH operation line and click the toolbar button Explain. The details about the index used or whether the search within the table was sequential are shown.

    After clicking the Explain button, the screen looks like the one shown in the following screenshot for a MS SQL server database.

    In this recipe, we will see how a trace may be carried out on other users along with additional imposed restrictions. Problem areas may be dificult to ind at irst. We may then run a "restricted" trace focusing only on the particular program or user. We may run a time-consuming report of Finance FI module in one session, and at the same time, want to trace an HR transaction code, say PA30, in another session.

    We can then specify the transaction code of HR in the restriction criteria of a restricted trace. In this way, the trace records of the FI report that is running or any other activity in any session will not be included in our trace results. For carrying out a trace that is restricted, call transaction ST On the main screen, click the Activate Trace with Filter button.

    The Set Restrictions for Writing Trace dialog appears. Enter the User Name in the ield provided. In the Transaction Name ield, we enter the transaction code PA In addition, if we know the Process Number of the process, we can simply enter the three digit Process Number in the ield provided.

    This will only trace the process number in question. Press Enter when all entries are done. The trace is on. When we like to switch off the trace, the same Deactivate Trace button is used. The trace ile will therefore look like the following screenshot: It is recommended that for performance optimization, we irst run a trace without restrictions. We can then ilter the results according to the various criteria of the selection ields or the Display Trace screen. We will see how this is done in the next recipe.

    Filtering unwanted trace result entries SQL performance trace iles may be very huge and searching for tables may be a time-consuming task. In this recipe, we will see how we can ilter irrelevant values from the SQL trace list. We assume that an unrestricted trace like the one shown in the irst recipe, Carrying out SQL Trace has already been done. After a trace has been carried out from the transaction ST05 screen, press the Display Trace button.

    The portion of the screen that appears is shown in the following screenshot: The User name appears as default. You may enter one or more operations in the Executed Operation ield.

    Also, we can enter a value for execution time with a greater-than GT operator. Instead of the huge trace list, only the values that pertain to the values entered on the Display Trace screen are shown. Also, if we enter the EXEC operation, only this operation's entries will be displayed. Similarly, the Execution Time is taken into account. For inding the slowest statements, the Execution Time ield is very important.

    We can enter a value greater than the particular time duration. This will list all costly statements that we need to optimize. Summarizing a SQL list and viewing table-related information For each SQL statement in the program, the trace list shows a number of lines corresponding to the various operations, thus making the list very huge in size.

    We can see a summarized view , and also apply table-related functions on the list values. In this recipe, we will see how to apply these functions. For displaying summarized information, carry out the following steps: In order to see a list of all identical selects within the trace, choose the menu option Display Identical Selects.

    The summarized table view generates a shorter list, as shown in the following screenshot. If there are multiple accesses to a particular table, each access is shown in the list along in the following screenshot with the time at which the access was made: For each table accesses, there is a single line shown in this list, as shown in the following screenshot: We also have a percentage column that will show the table whose access takes the most percentage of the runtime.

    If the appropriate path is chosen, a list of identical selects may also be generated. Quickly inding the data source of a screen ield In this recipe, we will see a quick method that will enable us to ind the database table and ield in which the data of a particular SAP screen ield is stored. Getting ready We will use PA30 and its Infotype in this example transaction. We assume that we are not sure which table name and ield stores the irst name of an employee.

    Call transaction PA Enter an employee number in the ield provided. Also enter personal data in the Infotype ield, and then click on the Change button.

    Once you are in the Change Screen, change the First Name of the employee in the relevant ield. Do not press the Save button. In another session, switch on the SQL trace. Go back to the transaction PA30 and save the data. Once the save message appears, go back to the SQL trace transaction and click the Display Trace button.

    We used a small trick to ind out the data source of a screen ield. In order to avoid searching through a lot of table names by using display of data, we only focused on the relevant ield and used a change operation. Since we changed a record, the corresponding ield must be updated in the database. Also the operation name must begin with EXEC. So, we generated a list and searched for only EXEC operations.

    From this, we found out the name of the table PA shown in the list. When we look at this closely, we see that the value we entered in the irst name ield was passed for update in the ield VORNA. Finding the data source of a ield's hit list In this recipe, we will use the SQL trace in order to ind out the data source of the F4 help of a screen ield.

    The aim of this recipe is to devise a strategy that will make the procedure for inding the data source quicker and easier. Getting ready We will use the transaction SE24 as an example. We assume that we are not sure of the various tables in which the class names and descriptions reside.

    We may take the Class Field input help for names starting with any letter. For our example, we view a list of all classes with names starting from y. In one session, call transaction SE In another session, call transaction ST05 and switch on the trace using the Activate Trace button.

    Now go back to the transaction SE24 and press F4 while keeping the cursor on the Object type ield. The list of values will appear. Now go back to the ST05 screen, switch off the trace, and take the display of the trace. When we pressed F4, the classes whose names start with Y appear as shown in the following screenshot: In our system, we get 39 hits. This igure is very important and will be used later. Then, we take the Combined Table Accesses to see which table access shows 39 records fetched.

    Another method for arriving at the text table can be used. For the list shown in our system for classes beginning with Y, we have only four descriptions shown with the rest being blanks. It also allows you to search for patterns of ABAP statements or tokens within a program.

    The variable-naming convention adherence may also be veriied. It only checks the syntax, and some times, depending on the checks selected, refers to the dictionary attributes of the table s involved.

    Some of the categories of checks are shown as follows: However, you do not have control over the checks carried out through this Menu option. Moreover, only one program at a time may be inspected through the Menu option.

    This chapter explores useful recipes related to the Code Inspector. We will start with the simplest method for running inspections on one program or a small number of programs.

    Then, a full-ledged inspection with further options such as inspection saving and background execution will be discussed. Next, we will focus on the performance checks and the various cases they generate messages in the inspection results.

    Similar articles

    Copyright © 2019